[llvm] 68ee56d - [clang][OpenMP][SPIR-V] Fix addrspace of global constants (#134399)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 08:41:57 PDT 2025
Author: Nick Sarnie
Date: 2025-04-09T15:41:53Z
New Revision: 68ee56d15020b4fa7f3c5443b4be6504481957d4
URL: https://github.com/llvm/llvm-project/commit/68ee56d15020b4fa7f3c5443b4be6504481957d4
DIFF: https://github.com/llvm/llvm-project/commit/68ee56d15020b4fa7f3c5443b4be6504481957d4.diff
LOG: [clang][OpenMP][SPIR-V] Fix addrspace of global constants (#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 <nick.sarnie at intel.com>
Added:
Modified:
clang/lib/Basic/Targets/SPIR.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index 78505d66d6f2f..3b67e8ca55ae7 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -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
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 4b3f9c614514e..13b727d226738 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6360,6 +6360,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});
More information about the llvm-commits
mailing list