Skip to content

Commit 9e45a7a

Browse files
authored
[clang][OpenMP] Fix __llvm_omp_indirect_call_lookup signature for targets with non-default program AS (#192470)
The argument and return value for `__llvm_omp_indirect_call_lookup` are function pointers so make sure they are in the correct address space. Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
1 parent ffde06f commit 9e45a7a

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7082,14 +7082,15 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
70827082

70837083
const auto *VD = DRE ? dyn_cast<VarDecl>(DRE->getDecl()) : nullptr;
70847084
if (VD && VD->hasAttr<OMPTargetIndirectCallAttr>()) {
7085-
auto *PtrTy = CGM.VoidPtrTy;
7086-
llvm::Type *RtlFnArgs[] = {PtrTy};
7085+
auto *FuncPtrTy = llvm::PointerType::get(
7086+
CGM.getLLVMContext(), CGM.getDataLayout().getProgramAddressSpace());
7087+
llvm::Type *RtlFnArgs[] = {FuncPtrTy};
70877088
llvm::FunctionCallee DeviceRtlFn = CGM.CreateRuntimeFunction(
7088-
llvm::FunctionType::get(PtrTy, RtlFnArgs, false),
7089+
llvm::FunctionType::get(FuncPtrTy, RtlFnArgs, false),
70897090
"__llvm_omp_indirect_call_lookup");
70907091
llvm::Value *Func = Callee.getFunctionPointer();
70917092
llvm::Type *BackupTy = Func->getType();
7092-
Func = Builder.CreatePointerBitCastOrAddrSpaceCast(Func, PtrTy);
7093+
Func = Builder.CreatePointerBitCastOrAddrSpaceCast(Func, FuncPtrTy);
70937094
Func = EmitRuntimeCall(DeviceRtlFn, {Func});
70947095
Func = Builder.CreatePointerBitCastOrAddrSpaceCast(Func, BackupTy);
70957096
Callee.setFunctionPointer(Func);

clang/test/OpenMP/target_indirect_codegen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
// 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
88
// 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
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,SPIRV
1010
// 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
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,SPIRV
1212

1313
// expected-no-diagnostics
1414
#ifndef HEADER
@@ -86,6 +86,7 @@ int main() {
8686
#endif
8787
// DEVICE-LABEL: define {{.*}}void @__omp_offloading_{{.+}}_main_l{{[0-9]+}}(
8888
// DEVICE: call {{.*}}@__llvm_omp_indirect_call_lookup(
89+
// SPIRV-SAME: ptr addrspace(9)
8990
// DEVICE: call {{.*}}void %{{.+}}()
9091
// DEVICE: call {{.*}}@__llvm_omp_indirect_call_lookup(
9192
// DEVICE: call {{.*}}void %{{.+}}()

0 commit comments

Comments
 (0)