r309567 - [OpenCL] Add extension Sema check for subgroup builtins
Joey Gouly via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 31 08:15:59 PDT 2017
Author: joey
Date: Mon Jul 31 08:15:59 2017
New Revision: 309567
URL: http://llvm.org/viewvc/llvm-project?rev=309567&view=rev
Log:
[OpenCL] Add extension Sema check for subgroup builtins
Check the subgroup extension is enabled, before doing other Sema checks.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=309567&r1=309566&r2=309567&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Jul 31 08:15:59 2017
@@ -299,6 +299,15 @@ static bool checkOpenCLBlockArgs(Sema &S
return IllegalParams;
}
+static bool checkOpenCLSubgroupExt(Sema &S, CallExpr *Call) {
+ if (!S.getOpenCLOptions().isEnabled("cl_khr_subgroups")) {
+ S.Diag(Call->getLocStart(), diag::err_opencl_requires_extension)
+ << 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+ return true;
+ }
+ return false;
+}
+
/// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
/// get_kernel_work_group_size
/// and get_kernel_preferred_work_group_size_multiple builtin functions.
@@ -1048,9 +1057,17 @@ Sema::CheckBuiltinFunctionCall(FunctionD
case Builtin::BIreserve_write_pipe:
case Builtin::BIwork_group_reserve_read_pipe:
case Builtin::BIwork_group_reserve_write_pipe:
+ if (SemaBuiltinReserveRWPipe(*this, TheCall))
+ return ExprError();
+ // Since return type of reserve_read/write_pipe built-in function is
+ // reserve_id_t, which is not defined in the builtin def file , we used int
+ // as return type and need to override the return type of these functions.
+ TheCall->setType(Context.OCLReserveIDTy);
+ break;
case Builtin::BIsub_group_reserve_read_pipe:
case Builtin::BIsub_group_reserve_write_pipe:
- if (SemaBuiltinReserveRWPipe(*this, TheCall))
+ if (checkOpenCLSubgroupExt(*this, TheCall) ||
+ SemaBuiltinReserveRWPipe(*this, TheCall))
return ExprError();
// Since return type of reserve_read/write_pipe built-in function is
// reserve_id_t, which is not defined in the builtin def file , we used int
@@ -1061,9 +1078,13 @@ Sema::CheckBuiltinFunctionCall(FunctionD
case Builtin::BIcommit_write_pipe:
case Builtin::BIwork_group_commit_read_pipe:
case Builtin::BIwork_group_commit_write_pipe:
+ if (SemaBuiltinCommitRWPipe(*this, TheCall))
+ return ExprError();
+ break;
case Builtin::BIsub_group_commit_read_pipe:
case Builtin::BIsub_group_commit_write_pipe:
- if (SemaBuiltinCommitRWPipe(*this, TheCall))
+ if (checkOpenCLSubgroupExt(*this, TheCall) ||
+ SemaBuiltinCommitRWPipe(*this, TheCall))
return ExprError();
break;
case Builtin::BIget_pipe_num_packets:
Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=309567&r1=309566&r2=309567&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Mon Jul 31 08:15:59 2017
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32
// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64
+#pragma OPENCL EXTENSION cl_khr_subgroups : enable
+
typedef void (^bl_t)(local void *);
typedef struct {int a;} ndrange_t;
Modified: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl?rev=309567&r1=309566&r2=309567&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl Mon Jul 31 08:15:59 2017
@@ -3,6 +3,8 @@
// CHECK: %opencl.pipe_t = type opaque
// CHECK: %opencl.reserve_id_t = type opaque
+#pragma OPENCL EXTENSION cl_khr_subgroups : enable
+
void test1(read_only pipe int p, global int *ptr) {
// CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 4, i32 4)
read_pipe(p, ptr);
Modified: cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl?rev=309567&r1=309566&r2=309567&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl Mon Jul 31 08:15:59 2017
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+#pragma OPENCL EXTENSION cl_khr_subgroups : enable
+
void test1(read_only pipe int p, global int* ptr){
int tmp;
reserve_id_t rid;
More information about the cfe-commits
mailing list