Skip to content

Commit a0cfc97

Browse files
sarnexYilin Li
authored and
Yilin Li
committed
[clang][OpenMP][SPIR-V] Fix addrspace of global constants (llvm#134399)
SPIR-V has strict address space rules, constant globals cannot be in the default address space. The OMPIRBuilder change was required for lit tests to pass, we were missing an addrspacecast. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent f0c16b6 commit a0cfc97

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clang/lib/Basic/Targets/SPIR.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo {
374374
const llvm::omp::GV &getGridValue() const override {
375375
return llvm::omp::SPIRVGridValues;
376376
}
377+
378+
std::optional<LangAS> getConstantAddressSpace() const override {
379+
return ConstantAS;
380+
}
381+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
382+
BaseSPIRVTargetInfo::adjust(Diags, Opts);
383+
// opencl_constant will map to UniformConstant in SPIR-V
384+
if (Opts.OpenCL)
385+
ConstantAS = LangAS::opencl_constant;
386+
}
387+
388+
private:
389+
// opencl_global will map to CrossWorkgroup in SPIR-V
390+
LangAS ConstantAS = LangAS::opencl_global;
377391
};
378392

379393
class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6360,6 +6360,12 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
63606360
: ConstantExpr::getAddrSpaceCast(KernelEnvironmentGV,
63616361
KernelEnvironmentPtr);
63626362
Value *KernelLaunchEnvironment = DebugKernelWrapper->getArg(0);
6363+
Type *KernelLaunchEnvParamTy = Fn->getFunctionType()->getParamType(1);
6364+
KernelLaunchEnvironment =
6365+
KernelLaunchEnvironment->getType() == KernelLaunchEnvParamTy
6366+
? KernelLaunchEnvironment
6367+
: Builder.CreateAddrSpaceCast(KernelLaunchEnvironment,
6368+
KernelLaunchEnvParamTy);
63636369
CallInst *ThreadKind =
63646370
Builder.CreateCall(Fn, {KernelEnvironment, KernelLaunchEnvironment});
63656371

0 commit comments

Comments
 (0)