From 65cc880b9468296dbccd1ad771e4c9e427c1cd84 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Wed, 25 Sep 2019 09:12:59 +0000 Subject: [PATCH] [OpenCL] Add image query builtin functions Add the image query builtin functions from the OpenCL C specification. Patch by Pierre Gondois and Sven van Haastregt. Differential Revision: https://reviews.llvm.org/D67713 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372833 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/OpenCLBuiltins.td | 25 +++++++++++++++++++++ test/SemaOpenCL/fdeclare-opencl-builtins.cl | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/lib/Sema/OpenCLBuiltins.td b/lib/Sema/OpenCLBuiltins.td index 20b574e0a5..2986140594 100644 --- a/lib/Sema/OpenCLBuiltins.td +++ b/lib/Sema/OpenCLBuiltins.td @@ -593,6 +593,31 @@ foreach aQual = ["WO", "RW"] in { def : Builtin<"write_imagef", [Void, ImageType, VectorType, Float]>; } +// --- Table 25: Image Query Functions --- +foreach aQual = ["RO", "WO", "RW"] in { + foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d, + Image1dArray, Image2dArray, Image2dDepth, + Image2dArrayDepth] in { + foreach name = ["get_image_width", "get_image_channel_data_type", + "get_image_channel_order"] in { + def : Builtin]>; + } + } + foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth, + Image2dArrayDepth] in { + def : Builtin<"get_image_height", [Int, ImageType]>; + } + def : Builtin<"get_image_depth", [Int, ImageType]>; + foreach imgTy = [Image2d, Image2dArray, Image2dDepth, + Image2dArrayDepth] in { + def : Builtin<"get_image_dim", [VectorType, ImageType]>; + } + def : Builtin<"get_image_dim", [VectorType, ImageType]>; + foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in { + def : Builtin<"get_image_array_size", [Size, ImageType]>; + } +} + // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions // --- Table 8 --- foreach aQual = ["RO"] in { diff --git a/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/test/SemaOpenCL/fdeclare-opencl-builtins.cl index 6c32e12571..d8d3793841 100644 --- a/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -71,6 +71,8 @@ kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) { resf = read_imagef(image_read_only_image2d, i2); res = read_imageh(image_read_only_image2d, i2); res = read_imageh(image_read_only_image2d, sampler, i2); + + int imgWidth = get_image_width(image_read_only_image2d); } #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 @@ -79,6 +81,8 @@ kernel void basic_image_readwrite(read_write image3d_t image_read_write_image3d) int4 i4; write_imageh(image_read_write_image3d, i4, h4); + + int imgDepth = get_image_depth(image_read_write_image3d); } #endif // __OPENCL_C_VERSION__ >= CL_VERSION_2_0 -- 2.40.0