diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -18,6 +18,7 @@ #include "AMDGPUMachineFunction.h" #include "GCNSubtarget.h" #include "SIMachineFunctionInfo.h" +#include "Utils/AMDGPULDSUtils.h" #include "llvm/CodeGen/Analysis.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/IntrinsicsAMDGPU.h" @@ -1306,7 +1307,7 @@ if (G->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS || G->getAddressSpace() == AMDGPUAS::REGION_ADDRESS) { if (!MFI->isModuleEntryFunction() && - !GV->getName().equals("llvm.amdgcn.module.lds")) { + !GV->getName().equals(MODULE_LDS_NAME)) { SDLoc DL(Op); const Function &Fn = DAG.getMachineFunction().getFunction(); DiagnosticInfoUnsupported BadLDSDecl( diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp @@ -19,6 +19,7 @@ #include "AMDGPUTargetMachine.h" #include "SIMachineFunctionInfo.h" #include "Utils/AMDGPUBaseInfo.h" +#include "Utils/AMDGPULDSUtils.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/CodeGen/GlobalISel/LegalizerHelper.h" @@ -2287,7 +2288,7 @@ if (AS == AMDGPUAS::LOCAL_ADDRESS || AS == AMDGPUAS::REGION_ADDRESS) { if (!MFI->isModuleEntryFunction() && - !GV->getName().equals("llvm.amdgcn.module.lds")) { + !GV->getName().equals(MODULE_LDS_NAME)) { const Function &Fn = MF.getFunction(); DiagnosticInfoUnsupported BadLDSDecl( Fn, "local memory global used by non-kernel function", MI.getDebugLoc(), diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp @@ -207,15 +207,16 @@ LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes), [](const GlobalVariable *V) -> Type * { return V->getValueType(); }); - StructType *LDSTy = StructType::create( - Ctx, LocalVarTypes, llvm::StringRef("llvm.amdgcn.module.lds.t")); + std::string LDSTyName = std::string(MODULE_LDS_NAME) + std::string(".t"); + StructType *LDSTy = + StructType::create(Ctx, LocalVarTypes, llvm::StringRef(LDSTyName)); Align MaxAlign = AMDGPU::getAlign(DL, LocalVars[0]); // was sorted on alignment GlobalVariable *SGV = new GlobalVariable( M, LDSTy, false, GlobalValue::InternalLinkage, UndefValue::get(LDSTy), - "llvm.amdgcn.module.lds", nullptr, GlobalValue::NotThreadLocal, + MODULE_LDS_NAME, nullptr, GlobalValue::NotThreadLocal, AMDGPUAS::LOCAL_ADDRESS, false); SGV->setAlignment(MaxAlign); appendToCompilerUsed( diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUMachineFunction.cpp @@ -9,6 +9,7 @@ #include "AMDGPUMachineFunction.h" #include "AMDGPUPerfHintAnalysis.h" #include "AMDGPUSubtarget.h" +#include "Utils/AMDGPULDSUtils.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/Target/TargetMachine.h" @@ -64,7 +65,7 @@ void AMDGPUMachineFunction::allocateModuleLDSGlobal(const Module *M) { if (isModuleEntryFunction()) { - const GlobalVariable *GV = M->getNamedGlobal("llvm.amdgcn.module.lds"); + const GlobalVariable *GV = AMDGPU::getModuleLDSGlobal(M); if (GV) { unsigned Offset = allocateLDSGlobal(M->getDataLayout(), *GV); (void)Offset; diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.h --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.h +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.h @@ -15,6 +15,8 @@ #include "AMDGPU.h" +#define MODULE_LDS_NAME "llvm.amdgcn.module.lds" + namespace llvm { namespace AMDGPU { @@ -31,6 +33,8 @@ SmallPtrSet getUsedList(Module &M); +const GlobalVariable *getModuleLDSGlobal(const Module *M); + } // end namespace AMDGPU } // end namespace llvm diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp @@ -122,6 +122,10 @@ return UsedList; } +const GlobalVariable *getModuleLDSGlobal(const Module *M) { + return M->getNamedGlobal(MODULE_LDS_NAME); +} + } // end namespace AMDGPU } // end namespace llvm