File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -5384,6 +5384,11 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
5384
5384
LangAS AS;
5385
5385
if (OpenMPRuntime->hasAllocateAttributeForGlobalVar (D, AS))
5386
5386
return AS;
5387
+ if (LangOpts.OpenMPIsTargetDevice && getTriple ().isSPIRV ())
5388
+ // SPIR-V globals should map to CrossWorkGroup instead of default
5389
+ // AS, as generic/no address space is invalid. This is similar
5390
+ // to what is done for HIPSPV.
5391
+ return LangAS::opencl_global;
5387
5392
}
5388
5393
return getTargetCodeGenInfo ().getGlobalVarAddressSpace (*this , D);
5389
5394
}
@@ -5402,6 +5407,10 @@ LangAS CodeGenModule::GetGlobalConstantAddressSpace() const {
5402
5407
// UniformConstant storage class is not viable as pointers to it may not be
5403
5408
// casted to Generic pointers which are used to model HIP's "flat" pointers.
5404
5409
return LangAS::cuda_device;
5410
+ if (LangOpts.OpenMPIsTargetDevice && getTriple ().isSPIRV ())
5411
+ // OpenMP SPIR-V global constants should map to UniformConstant, different
5412
+ // from the HIPSPV case above.
5413
+ return LangAS::opencl_constant;
5405
5414
if (auto AS = getTarget ().getConstantAddressSpace ())
5406
5415
return *AS;
5407
5416
return LangAS::Default;
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=spirv64 -emit-llvm-bc %s -o %t-host.bc
2
+ // RUN: %clang_cc1 -O0 -fopenmp -fopenmp-targets=spirv64 -fopenmp-is-target-device -triple spirv64 -fopenmp-host-ir-file-path %t-host.bc -emit-llvm %s -o - | FileCheck %s
3
+
4
+ extern int printf (char []);
5
+
6
+ #pragma omp declare target
7
+ // CHECK: @global = addrspace(1) global i32 0, align 4
8
+ // CHECK: @.str = private unnamed_addr addrspace(2) constant [4 x i8] c"foo\00", align 1
9
+ int global = 0 ;
10
+ #pragma omp end declare target
11
+ int main () {
12
+ // CHECK: = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @__omp_offloading_{{.*}}_kernel_environment to ptr), ptr %{{.*}})
13
+ #pragma omp target
14
+ {
15
+ for (int i = 0 ; i < 5 ; i ++ )
16
+ global ++ ;
17
+ printf ("foo" );
18
+ }
19
+
20
+
21
+ return global ;
22
+ }
Original file line number Diff line number Diff line change @@ -6295,6 +6295,12 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
6295
6295
: ConstantExpr::getAddrSpaceCast (KernelEnvironmentGV,
6296
6296
KernelEnvironmentPtr);
6297
6297
Value *KernelLaunchEnvironment = DebugKernelWrapper->getArg (0 );
6298
+ Type *KernelLaunchEnvParamTy = Fn->getFunctionType ()->getParamType (1 );
6299
+ KernelLaunchEnvironment =
6300
+ KernelLaunchEnvironment->getType () == KernelLaunchEnvParamTy
6301
+ ? KernelLaunchEnvironment
6302
+ : Builder.CreateAddrSpaceCast (KernelLaunchEnvironment,
6303
+ KernelLaunchEnvParamTy);
6298
6304
CallInst *ThreadKind =
6299
6305
Builder.CreateCall (Fn, {KernelEnvironment, KernelLaunchEnvironment});
6300
6306
You can’t perform that action at this time.
0 commit comments