[clang] 0b44885 - [OpenCL] Add cl_khr_subgroup_extended_types to TableGen BIFs

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 01:33:00 PST 2021


Author: Sven van Haastregt
Date: 2021-02-11T09:32:42Z
New Revision: 0b448854daffd57869254089ebb1bf69e8449823

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

LOG: [OpenCL] Add cl_khr_subgroup_extended_types to TableGen BIFs

Add the builtin functions brought by the
cl_khr_subgroup_extended_types extension to
`-fdeclare-opencl-builtins`.

Differential Revision: https://reviews.llvm.org/D96279

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 0e10722eee34..b78a1812748b 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -53,6 +53,7 @@ class FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
 // FunctionExtension definitions.
 def FuncExtNone                          : FunctionExtension<"">;
 def FuncExtKhrSubgroups                  : FunctionExtension<"cl_khr_subgroups">;
+def FuncExtKhrSubgroupExtendedTypes      : FunctionExtension<"cl_khr_subgroup_extended_types">;
 def FuncExtKhrSubgroupNonUniformVote     : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
 def FuncExtKhrSubgroupBallot             : FunctionExtension<"cl_khr_subgroup_ballot">;
 def FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">;
@@ -367,6 +368,9 @@ def UGenTypeN              : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScal
 def FGenTypeN              : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
 // (u)int, (u)long, and all floats
 def IntLongFloatGenType1   : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
+// (u)char and (u)short
+def CharShortGenType1      : GenericType<"CharShortGenType1",
+                                 TypeList<[Char, UChar, Short, UShort]>, Vec1>;
 
 // GenType definitions for every single base type (e.g. fp32 only).
 // Names are like: GenTypeFloatVecAndScalar.
@@ -1496,7 +1500,19 @@ let Extension = FuncExtKhrSubgroups in {
 // OpenCL Extension v3.0 s38 - Extended Subgroup Functions
 
 // Section 38.4.1 - cl_khr_subgroup_extended_types
-// TODO
+let Extension = FuncExtKhrSubgroupExtendedTypes in {
+  // For sub_group_broadcast, add scalar char, uchar, short, and ushort support,
+  def : Builtin<"sub_group_broadcast", [CharShortGenType1, CharShortGenType1, UInt], Attr.Convergent>;
+  // gentype may additionally be one of the supported built-in vector data types.
+  def : Builtin<"sub_group_broadcast", [AGenTypeNNoScalar, AGenTypeNNoScalar, UInt], Attr.Convergent>;
+
+  foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
+                  "sub_group_scan_inclusive_"] in {
+    foreach op = ["add", "min", "max"] in {
+      def : Builtin<name # op, [CharShortGenType1, CharShortGenType1], Attr.Convergent>;
+    }
+  }
+}
 
 // Section 38.5.1 - cl_khr_subgroup_non_uniform_vote
 let Extension = FuncExtKhrSubgroupNonUniformVote in {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 6b9be37eadaf..6fa428125ce1 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -36,6 +36,7 @@ typedef long long2 __attribute__((ext_vector_type(2)));
 
 // Enable extensions that are enabled in opencl-c-base.h.
 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+#define cl_khr_subgroup_extended_types 1
 #define cl_khr_subgroup_ballot 1
 #define cl_khr_subgroup_non_uniform_arithmetic 1
 #define cl_khr_subgroup_clustered_reduce 1
@@ -142,15 +143,18 @@ kernel void basic_subgroup(global uint *out) {
 #endif
 }
 
-kernel void extended_subgroup(global uint4 *out, global int *scalar) {
+kernel void extended_subgroup(global uint4 *out, global int *scalar, global char2 *c2) {
   out[0] = get_sub_group_eq_mask();
   scalar[0] = sub_group_non_uniform_scan_inclusive_or(3);
   scalar[1] = sub_group_clustered_reduce_logical_xor(2, 4);
+  *c2 = sub_group_broadcast(*c2, 2);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(__OPENCL_CPP_VERSION__)
-  // expected-error at -4{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}}
-  // expected-error at -5{{implicit conversion changes signedness}}
-  // expected-error at -5{{implicit declaration of function 'sub_group_non_uniform_scan_inclusive_or' is invalid in OpenCL}}
-  // expected-error at -5{{implicit declaration of function 'sub_group_clustered_reduce_logical_xor' is invalid in OpenCL}}
+  // expected-error at -5{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}}
+  // expected-error at -6{{implicit conversion changes signedness}}
+  // expected-error at -6{{implicit declaration of function 'sub_group_non_uniform_scan_inclusive_or' is invalid in OpenCL}}
+  // expected-error at -6{{implicit declaration of function 'sub_group_clustered_reduce_logical_xor' is invalid in OpenCL}}
+  // expected-error at -6{{implicit declaration of function 'sub_group_broadcast' is invalid in OpenCL}}
+  // expected-error at -7{{implicit conversion loses integer precision}}
 #endif
 }
 


        


More information about the cfe-commits mailing list