Skip to content

[clang][OpenMP][SPIR-V] Fix addrspace of global constants #134399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public BaseSPIRVTargetInfo {
const llvm::omp::GV &getGridValue() const override {
return llvm::omp::SPIRVGridValues;
}

std::optional<LangAS> getConstantAddressSpace() const override {
return ConstantAS;
}
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
BaseSPIRVTargetInfo::adjust(Diags, Opts);
// opencl_constant will map to UniformConstant in SPIR-V
if (Opts.OpenCL)
ConstantAS = LangAS::opencl_constant;
}

private:
// opencl_global will map to CrossWorkgroup in SPIR-V
LangAS ConstantAS = LangAS::opencl_global;
};

class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6295,6 +6295,12 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createTargetInit(
: ConstantExpr::getAddrSpaceCast(KernelEnvironmentGV,
KernelEnvironmentPtr);
Value *KernelLaunchEnvironment = DebugKernelWrapper->getArg(0);
Type *KernelLaunchEnvParamTy = Fn->getFunctionType()->getParamType(1);
KernelLaunchEnvironment =
KernelLaunchEnvironment->getType() == KernelLaunchEnvParamTy
? KernelLaunchEnvironment
: Builder.CreateAddrSpaceCast(KernelLaunchEnvironment,
KernelLaunchEnvParamTy);
CallInst *ThreadKind =
Builder.CreateCall(Fn, {KernelEnvironment, KernelLaunchEnvironment});

Expand Down
Loading