Skip to content

Commit e56b592

Browse files
authored
[clang][OMPIRBuilder] Fix two missed function pointer type issues (llvm#162914)
Two small issues, when storing function pointers we need to use the program address space. With this change there are no asserts if I run all OpenMP tests with the offload target manually changed to SPIR-V, so we are getting somewhere. About 10 test fails though. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 01a87f2 commit e56b592

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,8 +1762,11 @@ void CGOpenMPRuntime::emitDeclareTargetFunction(const FunctionDecl *FD,
17621762
// access its value.
17631763
llvm::GlobalValue *Addr = GV;
17641764
if (CGM.getLangOpts().OpenMPIsTargetDevice) {
1765+
llvm::PointerType *FnPtrTy = llvm::PointerType::get(
1766+
CGM.getLLVMContext(),
1767+
CGM.getModule().getDataLayout().getProgramAddressSpace());
17651768
Addr = new llvm::GlobalVariable(
1766-
CGM.getModule(), CGM.VoidPtrTy,
1769+
CGM.getModule(), FnPtrTy,
17671770
/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, GV, Name,
17681771
nullptr, llvm::GlobalValue::NotThreadLocal,
17691772
CGM.getModule().getDataLayout().getDefaultGlobalsAddressSpace());

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
//
99
// This provides a generalized class for OpenMP runtime code generation
10-
// specialized by GPU targets NVPTX and AMDGCN.
10+
// specialized by GPU targets NVPTX, AMDGCN and SPIR-V.
1111
//
1212
//===----------------------------------------------------------------------===//
1313

@@ -1242,12 +1242,13 @@ void CGOpenMPRuntimeGPU::emitParallelCall(
12421242
CGBuilderTy &Bld = CGF.Builder;
12431243
llvm::Value *NumThreadsVal = NumThreads;
12441244
llvm::Function *WFn = WrapperFunctionsMap[OutlinedFn];
1245-
llvm::Value *ID = llvm::ConstantPointerNull::get(CGM.Int8PtrTy);
1246-
if (WFn)
1247-
ID = Bld.CreateBitOrPointerCast(WFn, CGM.Int8PtrTy);
1248-
llvm::Type *FnPtrTy = llvm::PointerType::get(
1245+
llvm::PointerType *FnPtrTy = llvm::PointerType::get(
12491246
CGF.getLLVMContext(), CGM.getDataLayout().getProgramAddressSpace());
12501247

1248+
llvm::Value *ID = llvm::ConstantPointerNull::get(FnPtrTy);
1249+
if (WFn)
1250+
ID = Bld.CreateBitOrPointerCast(WFn, FnPtrTy);
1251+
12511252
llvm::Value *FnPtr = Bld.CreateBitOrPointerCast(OutlinedFn, FnPtrTy);
12521253

12531254
// Create a private scope that will globalize the arguments

clang/test/OpenMP/target_indirect_codegen.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple amdgcn-amd-amdhsa %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-host.bc -emit-pch -o %t
55
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-host.bc -include-pch %t -o - | FileCheck %s --check-prefix=DEVICE
66

7+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST
8+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-spirv-host.bc
9+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-spirv-host.bc -o - | FileCheck %s --check-prefix=DEVICE
10+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple spirv64-intel %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-spirv-host.bc -emit-pch -o %t
11+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -x c++ -triple spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fvisibility=protected -fopenmp-host-ir-file-path %t-spirv-host.bc -include-pch %t -o - | FileCheck %s --check-prefix=DEVICE
12+
713
// expected-no-diagnostics
814
#ifndef HEADER
915
#define HEADER
@@ -19,10 +25,10 @@
1925
// HOST: @[[BAR_ENTRY_NAME:.+]] = internal unnamed_addr constant [{{[0-9]+}} x i8] c"[[BAR_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_bar_l[0-9]+]]\00"
2026
// HOST: @.offloading.entry.[[BAR_NAME]] = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 8, ptr @_ZL3barv, ptr @[[BAR_ENTRY_NAME]], i64 8, i64 0, ptr null }
2127
//.
22-
// DEVICE: @[[FOO_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_foo_l[0-9]+]] = protected addrspace(1) constant ptr @_Z3foov
23-
// DEVICE: @[[BAZ_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_baz_l[0-9]+]] = protected addrspace(1) constant ptr @_Z3bazv
28+
// DEVICE: @[[FOO_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_foo_l[0-9]+]] = protected addrspace(1) constant {{ptr|ptr addrspace\(9\)}} @_Z3foov
29+
// DEVICE: @[[BAZ_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_baz_l[0-9]+]] = protected addrspace(1) constant {{ptr|ptr addrspace\(9\)}} @_Z3bazv
2430
// DEVICE: @var = protected addrspace(1) global i8 0, align 1
25-
// DEVICE: @[[BAR_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_bar_l[0-9]+]] = protected addrspace(1) constant ptr @_ZL3barv
31+
// DEVICE: @[[BAR_NAME:__omp_offloading_[0-9a-z]+_[0-9a-z]+_bar_l[0-9]+]] = protected addrspace(1) constant {{ptr|ptr addrspace\(9\)}} @_ZL3barv
2632
//.
2733
void foo() { }
2834
#pragma omp declare target to(foo) indirect

clang/test/OpenMP/amdgcn_parallel_num_threads_strict_messages.cpp renamed to clang/test/OpenMP/target_parallel_num_threads_strict_messages.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// RUN: %clang_cc1 -DF3 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-ppc.bc
66
// RUN: %clang_cc1 -DF3 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-ppc.bc -o /dev/null
77

8+
// RUN: %clang_cc1 -DF1 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-spirv-ppc-host-ppc.bc
9+
// RUN: %clang_cc1 -DF1 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple spirv64-intel -fopenmp-targets=spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-spirv-ppc-host-ppc.bc -o /dev/null
10+
// RUN: %clang_cc1 -DF2 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-spirv-ppc-host-ppc.bc
11+
// RUN: %clang_cc1 -DF2 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple spirv64-intel -fopenmp-targets=spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-spirv-ppc-host-ppc.bc -o /dev/null
12+
// RUN: %clang_cc1 -DF3 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-spirv-ppc-host-ppc.bc
13+
// RUN: %clang_cc1 -DF3 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple spirv64-intel -fopenmp-targets=spirv64-intel -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-spirv-ppc-host-ppc.bc -o /dev/null
14+
815
#ifndef TARGET
916
// expected-no-diagnostics
1017
#endif

llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ __OMP_RTL(__kmpc_target_init, false, Int32, KernelEnvironmentPtr, KernelLaunchEn
472472
__OMP_RTL(__kmpc_target_deinit, false, Void,)
473473
__OMP_RTL(__kmpc_kernel_prepare_parallel, false, Void, VoidPtr)
474474
__OMP_RTL(__kmpc_parallel_51, false, Void, IdentPtr, Int32, Int32, Int32, Int32,
475-
FuncPtrTy, VoidPtr, VoidPtrPtr, SizeTy)
475+
FuncPtrTy, FuncPtrTy, VoidPtrPtr, SizeTy)
476476
__OMP_RTL(__kmpc_for_static_loop_4, false, Void, IdentPtr, VoidPtr, VoidPtr, Int32, Int32, Int32, Int8)
477477
__OMP_RTL(__kmpc_for_static_loop_4u, false, Void, IdentPtr, VoidPtr, VoidPtr, Int32, Int32, Int32, Int8)
478478
__OMP_RTL(__kmpc_for_static_loop_8, false, Void, IdentPtr, VoidPtr, VoidPtr, Int64, Int64, Int64, Int8)

0 commit comments

Comments
 (0)