]> granicus.if.org Git - clang/commitdiff
[OpenCL] Add image query builtin functions
authorSven van Haastregt <sven.vanhaastregt@arm.com>
Wed, 25 Sep 2019 09:12:59 +0000 (09:12 +0000)
committerSven van Haastregt <sven.vanhaastregt@arm.com>
Wed, 25 Sep 2019 09:12:59 +0000 (09:12 +0000)
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
test/SemaOpenCL/fdeclare-opencl-builtins.cl

index 20b574e0a57d0cb5e2989699aa8aab05ee76df1c..2986140594675ccf10e9cda577f8c34e5c4ba18c 100644 (file)
@@ -593,6 +593,31 @@ foreach aQual = ["WO", "RW"] in {
   def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, 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<name, [Int, ImageType<imgTy, aQual>]>;
+    }
+  }
+  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
+                   Image2dArrayDepth] in {
+    def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
+  }
+  def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
+  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
+                   Image2dArrayDepth] in {
+    def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
+  }
+  def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
+  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
+    def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
+  }
+}
+
 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
 // --- Table 8 ---
 foreach aQual = ["RO"] in {
index 6c32e1257120996609c48f393fefe18c5ee00aeb..d8d37938414882825e63dd38889beb80ba910529 100644 (file)
@@ -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