[OpenCL] Support vec_step in C++ for OpenCL mode
authorSven van Haastregt <sven.vanhaastregt@arm.com>
Thu, 5 Nov 2020 12:02:59 +0000 (12:02 +0000)
committerSven van Haastregt <sven.vanhaastregt@arm.com>
Thu, 5 Nov 2020 12:02:59 +0000 (12:02 +0000)
Enable the vec_step builtin in C++ for OpenCL mode for compatibility
with OpenCL C.

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

clang/include/clang/Basic/TokenKinds.def
clang/test/CodeGenOpenCLCXX/constexpr.cl

index 7664269..d8a2016 100644 (file)
@@ -586,7 +586,7 @@ ALIAS("write_only", __write_only    , KEYOPENCLC | KEYOPENCLCXX)
 ALIAS("read_write", __read_write    , KEYOPENCLC | KEYOPENCLCXX)
 // OpenCL builtins
 KEYWORD(__builtin_astype            , KEYOPENCLC | KEYOPENCLCXX)
-UNARY_EXPR_OR_TYPE_TRAIT(vec_step, VecStep, KEYOPENCLC | KEYALTIVEC | KEYZVECTOR)
+UNARY_EXPR_OR_TYPE_TRAIT(vec_step, VecStep, KEYOPENCLC | KEYOPENCLCXX | KEYALTIVEC | KEYZVECTOR)
 #define GENERIC_IMAGE_TYPE(ImgType, Id) KEYWORD(ImgType##_t, KEYOPENCLC | KEYOPENCLCXX)
 #include "clang/Basic/OpenCLImageTypes.def"
 KEYWORD(pipe                        , KEYOPENCLC | KEYOPENCLCXX)
index 8c3fad0..8eb9218 100644 (file)
@@ -52,3 +52,13 @@ const int2 fromConstexprFunc = addOne(int2(2));
 kernel void vecEval2(global int2 *x) {
   *x = fromConstexprFunc;
 }
+
+// Test evaluation of vec_step
+// CHECK-LABEL: define spir_kernel void @vec_step_test
+// CHECK: store i32 6
+constexpr int vsize1 = vec_step(fromConstexprFunc);
+constexpr int vsize2 = vec_step(int4);
+
+kernel void vec_step_test(global int *x) {
+  *x = vsize1 + vsize2;
+}