[PATCH] D51296: [Sema] Traverse vector types for ocl extensions support
vmaksimo created this revision. vmaksimo added reviewers: bader, Anastasia, AlexeySotkin. vmaksimo created this object with edit policy "Only User: vmaksimo (Viktoria Maximova)". Herald added a subscriber: cfe-commits. Given the following kernel: __kernel void foo() { double d; double4 dd; } and `cl_khr_fp64` disabled, the compilation would fail due to the presence of 'double d', but when removed, it passes. The expectation is that extended vector types of unsupported types will also be unsupported. This patch adds this check for this scenario. Repository: rC Clang https://reviews.llvm.org/D51296 Files: lib/Sema/Sema.cpp test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -70,6 +70,13 @@ // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} #endif + typedef double double4 __attribute__((ext_vector_type(4))); + double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; +#ifdef NOFP64 +// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} +// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}} +#endif + (void) 1.0; #ifdef NOFP64 Index: lib/Sema/Sema.cpp === --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -39,6 +39,7 @@ #include "clang/Sema/TemplateDeduction.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" + using namespace clang; using namespace sema; @@ -1852,6 +1853,14 @@ if (auto TagT = dyn_cast(QT.getCanonicalType().getTypePtr())) Decl = TagT->getDecl(); auto Loc = DS.getTypeSpecTypeLoc(); + + // Check extensions for vector types. + // e.g. double4 is not allowed when cl_khr_fp64 is absent. + if (QT->isExtVectorType()) { +auto TypePtr = QT->castAs()->getElementType().getTypePtr(); +return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap); + } + if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap)) return true; Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -70,6 +70,13 @@ // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} #endif + typedef double double4 __attribute__((ext_vector_type(4))); + double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; +#ifdef NOFP64 +// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} +// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}} +#endif + (void) 1.0; #ifdef NOFP64 Index: lib/Sema/Sema.cpp === --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -39,6 +39,7 @@ #include "clang/Sema/TemplateDeduction.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" + using namespace clang; using namespace sema; @@ -1852,6 +1853,14 @@ if (auto TagT = dyn_cast(QT.getCanonicalType().getTypePtr())) Decl = TagT->getDecl(); auto Loc = DS.getTypeSpecTypeLoc(); + + // Check extensions for vector types. + // e.g. double4 is not allowed when cl_khr_fp64 is absent. + if (QT->isExtVectorType()) { +auto TypePtr = QT->castAs()->getElementType().getTypePtr(); +return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap); + } + if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap)) return true; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51296: [OpenCL] Traverse vector types for ocl extensions support
vmaksimo updated this revision to Diff 163287. vmaksimo retitled this revision from "[Sema] Traverse vector types for ocl extensions support" to "[OpenCL] Traverse vector types for ocl extensions support". vmaksimo edited the summary of this revision. Repository: rC Clang https://reviews.llvm.org/D51296 Files: lib/Sema/Sema.cpp test/SemaOpenCL/extensions.cl Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -70,6 +70,13 @@ // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} #endif + typedef double double4 __attribute__((ext_vector_type(4))); + double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; +#ifdef NOFP64 +// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} +// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}} +#endif + (void) 1.0; #ifdef NOFP64 Index: lib/Sema/Sema.cpp === --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -1852,6 +1853,14 @@ if (auto TagT = dyn_cast(QT.getCanonicalType().getTypePtr())) Decl = TagT->getDecl(); auto Loc = DS.getTypeSpecTypeLoc(); + + // Check extensions for vector types. + // e.g. double4 is not allowed when cl_khr_fp64 is absent. + if (QT->isExtVectorType()) { +auto TypePtr = QT->castAs()->getElementType().getTypePtr(); +return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap); + } + if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap)) return true; Index: test/SemaOpenCL/extensions.cl === --- test/SemaOpenCL/extensions.cl +++ test/SemaOpenCL/extensions.cl @@ -70,6 +70,13 @@ // expected-error@-2{{use of type 'double' requires cl_khr_fp64 extension to be enabled}} #endif + typedef double double4 __attribute__((ext_vector_type(4))); + double4 d4 = {0.0f, 2.0f, 3.0f, 1.0f}; +#ifdef NOFP64 +// expected-error@-3 {{use of type 'double' requires cl_khr_fp64 extension to be enabled}} +// expected-error@-3 {{use of type 'double4' (vector of 4 'double' values) requires cl_khr_fp64 extension to be enabled}} +#endif + (void) 1.0; #ifdef NOFP64 Index: lib/Sema/Sema.cpp === --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -1852,6 +1853,14 @@ if (auto TagT = dyn_cast(QT.getCanonicalType().getTypePtr())) Decl = TagT->getDecl(); auto Loc = DS.getTypeSpecTypeLoc(); + + // Check extensions for vector types. + // e.g. double4 is not allowed when cl_khr_fp64 is absent. + if (QT->isExtVectorType()) { +auto TypePtr = QT->castAs()->getElementType().getTypePtr(); +return checkOpenCLDisabledTypeOrDecl(TypePtr, Loc, QT, OpenCLTypeExtMap); + } + if (checkOpenCLDisabledTypeOrDecl(Decl, Loc, QT, OpenCLDeclExtMap)) return true; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D53809: Fix invalid address space generation for clk_event_t
vmaksimo created this revision. vmaksimo added reviewers: Anastasia, yaxunl, AlexeySotkin. Herald added a subscriber: cfe-commits. Addrspace(32) was generated when putting 0 in clk_event_t * event_ret parameter for enqueue_kernel function. Repository: rC Clang https://reviews.llvm.org/D53809 Files: lib/CodeGen/CGBuiltin.cpp test/CodeGenOpenCL/cl20-device-side-enqueue.cl Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl === --- test/CodeGenOpenCL/cl20-device-side-enqueue.cl +++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl @@ -106,6 +106,13 @@ a[i] = b[i]; }); + // COMMON-LABEL: call i32 @__enqueue_kernel_basic_events + // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}}, i32 {{%[0-9]+}}, %struct.ndrange_t* {{.*}}, i32 1, %opencl.clk_event_t{{.*}}* addrspace(4)* {{%[0-9]+}}, %opencl.clk_event_t{{.*}}* addrspace(4)* null, + enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, 0, + ^(void) { + return; + }); + // Emits global block literal [[BLG1]] and block kernel [[INVGK1]]. // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags @@ -390,7 +397,7 @@ // COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) // COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*) #{{[0-9]+}} { // COMMON: entry: -// COMMON: call void @__device_side_enqueue_block_invoke_8(i8 addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) +// COMMON: call void @__device_side_enqueue_block_invoke_9(i8 addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) // COMMON: ret void // COMMON: } // COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) Index: lib/CodeGen/CGBuiltin.cpp === --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -3460,7 +3460,9 @@ llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5)); // Convert to generic address space. EventList = Builder.CreatePointerCast(EventList, EventPtrTy); - ClkEvent = Builder.CreatePointerCast(ClkEvent, EventPtrTy); + ClkEvent = ClkEvent->getType()->isIntegerTy() + ? Builder.CreateBitOrPointerCast(ClkEvent, EventPtrTy) + : Builder.CreatePointerCast(ClkEvent, EventPtrTy); auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(6)); llvm::Value *Kernel = Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl === --- test/CodeGenOpenCL/cl20-device-side-enqueue.cl +++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl @@ -106,6 +106,13 @@ a[i] = b[i]; }); + // COMMON-LABEL: call i32 @__enqueue_kernel_basic_events + // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}}, i32 {{%[0-9]+}}, %struct.ndrange_t* {{.*}}, i32 1, %opencl.clk_event_t{{.*}}* addrspace(4)* {{%[0-9]+}}, %opencl.clk_event_t{{.*}}* addrspace(4)* null, + enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, 0, + ^(void) { + return; + }); + // Emits global block literal [[BLG1]] and block kernel [[INVGK1]]. // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags @@ -390,7 +397,7 @@ // COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) // COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*) #{{[0-9]+}} { // COMMON: entry: -// COMMON: call void @__device_side_enqueue_block_invoke_8(i8 addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) +// COMMON: call void @__device_side_enqueue_block_invoke_9(i8 addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) // COMMON: ret void // COMMON: } // COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}) Index: lib/CodeGen/CGBuiltin.cpp === --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -3460,7 +3460,9 @@ llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5)); // Convert to generic address space. EventList = Builder.CreatePointerCast(EventList, EventPtrTy); - ClkEvent = Builder.CreatePointerCast(ClkEvent, EventPtrTy); + ClkEvent = ClkEvent->getType()->isIntegerTy() + ? Builder.CreateBitO