[clang] e54c83e - [OpenCL] Add work-group and miscellaneous vector builtin functions

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 02:45:26 PST 2019


Author: Sven van Haastregt
Date: 2019-11-26T10:44:49Z
New Revision: e54c83ec4dd493f2c6a483be2f6f3fc93624d10a

URL: https://github.com/llvm/llvm-project/commit/e54c83ec4dd493f2c6a483be2f6f3fc93624d10a
DIFF: https://github.com/llvm/llvm-project/commit/e54c83ec4dd493f2c6a483be2f6f3fc93624d10a.diff

LOG: [OpenCL] Add work-group and miscellaneous vector builtin functions

Add the work-group and miscellaneous vector builtin functions from the
OpenCL C specification.

Patch by Pierre Gondois and Sven van Haastregt.

Added: 
    

Modified: 
    clang/lib/Sema/OpenCLBuiltins.td
    clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 0bd4c51a04c2..353e0c1d8c8d 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -274,14 +274,21 @@ def Event             : Type<"Event", QualType<"OCLEventTy">>;
 def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
 def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
 def Vec1        : IntList<"Vec1", [1]>;
+def Vec2        : IntList<"Vec2", [2]>;
+def Vec4        : IntList<"Vec4", [4]>;
+def Vec8        : IntList<"Vec8", [8]>;
+def Vec16       : IntList<"Vec16", [16]>;
 def Vec1234     : IntList<"Vec1234", [1, 2, 3, 4]>;
 
 // Type lists.
-def TLAll   : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
+def TLAll         : TypeList<"TLAll", [Char,  UChar, Short,  UShort, Int,  UInt, Long,  ULong, Float, Double, Half]>;
+def TLAllUnsigned : TypeList<"TLAllUnsigned", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt,  ULong,  UShort]>;
 def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
 def TLSignedInts   : TypeList<"TLSignedInts", [Char, Short, Int, Long]>;
 def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>;
 
+def TLIntLongFloats : TypeList<"TLIntLongFloats", [Int, UInt, Long, ULong, Float, Double, Half]>;
+
 // All unsigned integer types twice, to facilitate unsigned return types for e.g.
 // uchar abs(char) and
 // uchar abs(uchar).
@@ -306,6 +313,8 @@ def SGenTypeN              : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar
 def UGenTypeN              : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
 // Float
 def FGenTypeN              : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
+// (u)int, (u)long, and all floats
+def IntLongFloatGenType1   : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
 
 // GenType definitions for every single base type (e.g. fp32 only).
 // Names are like: GenTypeFloatVecAndScalar.
@@ -867,6 +876,31 @@ foreach Type = [Int, UInt] in {
   }
 }
 
+//--------------------------------------------------------------------
+// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
+// --- Table 19 ---
+foreach name = ["shuffle"] in {
+  foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
+    foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
+      def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
+                           GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
+                           GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
+                          Attr.Const>;
+    }
+  }
+}
+foreach name = ["shuffle2"] in {
+  foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
+    foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
+      def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
+                           GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
+                           GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
+                           GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
+                          Attr.Const>;
+    }
+  }
+}
+
 //--------------------------------------------------------------------
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
 // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
@@ -1020,6 +1054,27 @@ foreach aQual = ["WO", "RW"] in {
 }
 
 
+//--------------------------------------------------------------------
+// OpenCL v2.0 s6.13.15 - Work-group Functions
+// --- Table 26 ---
+let MinVersion = CL20 in {
+  foreach name = ["work_group_all", "work_group_any"] in {
+    def : Builtin<name, [Int, Int], Attr.Convergent>;
+  }
+  foreach name = ["work_group_broadcast"] in {
+    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
+    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
+    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
+  }
+  foreach op = ["add", "min", "max"] in {
+    foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
+                    "work_group_scan_inclusive_"] in {
+      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
+    }
+  }
+}
+
+
 // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
 let MinVersion = CL20 in {
   let Extension = "cl_khr_subgroups" in {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 97a01a1fe931..589d04c64e82 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -32,6 +32,7 @@ typedef float float4 __attribute__((ext_vector_type(4)));
 typedef half half4 __attribute__((ext_vector_type(4)));
 typedef int int2 __attribute__((ext_vector_type(2)));
 typedef int int4 __attribute__((ext_vector_type(4)));
+typedef uint uint4 __attribute__((ext_vector_type(4)));
 typedef long long2 __attribute__((ext_vector_type(2)));
 #endif
 
@@ -67,6 +68,13 @@ char4 test_int(char c, char4 c4) {
   return max(c4, c);
 }
 
+kernel void basic_vector_misc(float4 a) {
+  float4 res;
+  uint4 mask = (uint4)(1, 2, 3, 4);
+
+  res = shuffle(a, mask);
+}
+
 kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) {
   int2 i2;
   sampler_t sampler;


        


More information about the cfe-commits mailing list