[clang] 9ae99a0 - [OpenCL] Add cl_khr_subgroup_non_uniform_arithmetic to TableGen BIFs

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 10 01:45:21 PST 2021


Author: Sven van Haastregt
Date: 2021-02-10T09:44:39Z
New Revision: 9ae99a0de8c79799df6fc0ff69ac3f73b7f4600f

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

LOG: [OpenCL] Add cl_khr_subgroup_non_uniform_arithmetic to TableGen BIFs

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

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

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 bd8049a04b99..1a58747c4017 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -55,6 +55,7 @@ def FuncExtNone                          : FunctionExtension<"">;
 def FuncExtKhrSubgroups                  : FunctionExtension<"cl_khr_subgroups">;
 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">;
 def FuncExtKhrSubgroupShuffle            : FunctionExtension<"cl_khr_subgroup_shuffle">;
 def FuncExtKhrSubgroupShuffleRelative    : FunctionExtension<"cl_khr_subgroup_shuffle_relative">;
 def FuncExtKhrGlobalInt32BaseAtomics     : FunctionExtension<"cl_khr_global_int32_base_atomics">;
@@ -1523,7 +1524,19 @@ let Extension = FuncExtKhrSubgroupBallot in {
 }
 
 // Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic
-// TODO
+let Extension = FuncExtKhrSubgroupNonUniformArithmetic in {
+  foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in {
+    foreach op = ["add", "min", "max", "mul"] in {
+      def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, AGenType1]>;
+    }
+    foreach op = ["and", "or", "xor"] in {
+      def : Builtin<"sub_group_non_uniform_" # name # op, [AIGenType1, AIGenType1]>;
+    }
+    foreach op = ["and", "or", "xor"] in {
+      def : Builtin<"sub_group_non_uniform_" # name # "logical_" # op, [Int, Int]>;
+    }
+  }
+}
 
 // Section 38.8.1 - cl_khr_subgroup_shuffle
 let Extension = FuncExtKhrSubgroupShuffle in {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 7f9f0cb19f91..93dd6fcc0a0d 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -37,6 +37,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_ballot 1
+#define cl_khr_subgroup_non_uniform_arithmetic 1
 #endif
 #endif
 
@@ -140,11 +141,13 @@ kernel void basic_subgroup(global uint *out) {
 #endif
 }
 
-kernel void extended_subgroup(global uint4 *out) {
+kernel void extended_subgroup(global uint4 *out, global int *scalar) {
   out[0] = get_sub_group_eq_mask();
+  scalar[0] = sub_group_non_uniform_scan_inclusive_or(3);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(__OPENCL_CPP_VERSION__)
-  // expected-error at -2{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}}
-  // expected-error at -3{{implicit conversion changes signedness}}
+  // expected-error at -3{{implicit declaration of function 'get_sub_group_eq_mask' is invalid in OpenCL}}
+  // expected-error at -4{{implicit conversion changes signedness}}
+  // expected-error at -4{{implicit declaration of function 'sub_group_non_uniform_scan_inclusive_or' is invalid in OpenCL}}
 #endif
 }
 


        


More information about the cfe-commits mailing list