Index: llvm/lib/Target/AMDGPU/AMDGPUMachineModuleInfo.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUMachineModuleInfo.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//===--- AMDGPUMachineModuleInfo.cpp ----------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -/// \file -/// AMDGPU Machine Module Info. -/// -// -//===----------------------------------------------------------------------===// - -#include "AMDGPUMachineModuleInfo.h" - -namespace llvm { - -AMDGPUMachineModuleInfo::AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI) - : MachineModuleInfoELF(MMI) { - LLVMContext &CTX = MMI.getModule()->getContext(); - AgentSSID = CTX.getOrInsertSyncScopeID("agent"); - WorkgroupSSID = CTX.getOrInsertSyncScopeID("workgroup"); - WavefrontSSID = CTX.getOrInsertSyncScopeID("wavefront"); - SystemOneAddressSpaceSSID = - CTX.getOrInsertSyncScopeID("one-as"); - AgentOneAddressSpaceSSID = - CTX.getOrInsertSyncScopeID("agent-one-as"); - WorkgroupOneAddressSpaceSSID = - CTX.getOrInsertSyncScopeID("workgroup-one-as"); - WavefrontOneAddressSpaceSSID = - CTX.getOrInsertSyncScopeID("wavefront-one-as"); - SingleThreadOneAddressSpaceSSID = - CTX.getOrInsertSyncScopeID("singlethread-one-as"); -} - -} // end namespace llvm Index: llvm/lib/Target/AMDGPU/AMDGPUModuleInfo.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUModuleInfo.h +++ llvm/lib/Target/AMDGPU/AMDGPUModuleInfo.h @@ -1,4 +1,4 @@ -//===--- AMDGPUMachineModuleInfo.h ------------------------------*- C++ -*-===// +//===-- AMDGPUModuleInfo.h ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,22 +6,22 @@ // //===----------------------------------------------------------------------===// // -/// \file -/// AMDGPU Machine Module Info. -/// +/// \file This pass holds AMDGPU module specific information. // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H -#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H +#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUMODULEINFO_H +#define LLVM_LIB_TARGET_AMDGPU_AMDGPUMODULEINFO_H -#include "llvm/CodeGen/MachineModuleInfoImpls.h" +#include "llvm/IR/LLVMContext.h" namespace llvm { -class AMDGPUMachineModuleInfo final : public MachineModuleInfoELF { -private: +class ModulePass; +class PassRegistry; +class AMDGPUModuleInfo { + Module *M = nullptr; // All supported memory/synchronization scopes can be found here: // http://llvm.org/docs/AMDGPUUsage.html#memory-scopes @@ -79,7 +79,9 @@ } public: - AMDGPUMachineModuleInfo(const MachineModuleInfo &MMI); + void initializeModuleInfo(Module *M); + + void resetModule() { M = nullptr; } /// \returns Agent synchronization scope ID (cross address space). SyncScope::ID getAgentSSID() const { @@ -136,6 +138,9 @@ } }; -} // end namespace llvm +void initializeAMDGPUModuleInfoPassPass(PassRegistry &); +ModulePass *createAMDGPUModuleInfoPass(AMDGPUModuleInfo *Info); + +} // End namespace llvm -#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMACHINEMODULEINFO_H +#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUMODULEINFO_H Index: llvm/lib/Target/AMDGPU/AMDGPUModuleInfo.cpp =================================================================== --- /dev/null +++ llvm/lib/Target/AMDGPU/AMDGPUModuleInfo.cpp @@ -0,0 +1,72 @@ +//===-- AMDGPUModuleInfo.cpp ----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file This pass holds AMDGPU module specific information. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUModuleInfo.h" +#include "llvm/IR/Module.h" +#include "llvm/Pass.h" + +using namespace llvm; + +namespace { + +class AMDGPUModuleInfoPass : public ModulePass { + AMDGPUModuleInfo *Info; + +public: + static char ID; + + AMDGPUModuleInfoPass(AMDGPUModuleInfo *Info = nullptr) : + ModulePass(ID), Info(Info) { } + + bool runOnModule(Module &M) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + } +}; + +} // End anonymous namespace + +INITIALIZE_PASS(AMDGPUModuleInfoPass, "amdgpu-module-info", + "AMDGPU Module Information", false, false) + +char AMDGPUModuleInfoPass::ID = 0; + +ModulePass *llvm::createAMDGPUModuleInfoPass(AMDGPUModuleInfo *Info) { + return new AMDGPUModuleInfoPass(Info); +} + +bool AMDGPUModuleInfoPass::runOnModule(Module &M) { + Info->resetModule(); + return false; +} + +void AMDGPUModuleInfo::initializeModuleInfo(Module *M) { + if (this->M == M) + return; + + this->M = M; + LLVMContext &CTX = M->getContext(); + AgentSSID = CTX.getOrInsertSyncScopeID("agent"); + WorkgroupSSID = CTX.getOrInsertSyncScopeID("workgroup"); + WavefrontSSID = CTX.getOrInsertSyncScopeID("wavefront"); + SystemOneAddressSpaceSSID = + CTX.getOrInsertSyncScopeID("one-as"); + AgentOneAddressSpaceSSID = + CTX.getOrInsertSyncScopeID("agent-one-as"); + WorkgroupOneAddressSpaceSSID = + CTX.getOrInsertSyncScopeID("workgroup-one-as"); + WavefrontOneAddressSpaceSSID = + CTX.getOrInsertSyncScopeID("wavefront-one-as"); + SingleThreadOneAddressSpaceSSID = + CTX.getOrInsertSyncScopeID("singlethread-one-as"); +} Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -14,6 +14,7 @@ #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H #define LLVM_LIB_TARGET_AMDGPU_AMDGPUTARGETMACHINE_H +#include "AMDGPUModuleInfo.h" #include "GCNSubtarget.h" #include "R600Subtarget.h" #include "llvm/Target/TargetMachine.h" @@ -28,10 +29,13 @@ protected: std::unique_ptr TLOF; + mutable AMDGPUModuleInfo ModuleInfo; + StringRef getGPUName(const Function &F) const; StringRef getFeatureString(const Function &F) const; public: + static bool EnableLateStructurizeCFG; static bool EnableFunctionCalls; static bool EnableFixedFunctionABI; @@ -61,6 +65,10 @@ bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override; unsigned getAssumedAddrSpace(const Value *V) const override; + + AMDGPUModuleInfo *getModuleInfoPtr() const { return &ModuleInfo; } + + const AMDGPUModuleInfo &getModuleInfo(Module *M) const; }; //===----------------------------------------------------------------------===// Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -17,6 +17,7 @@ #include "AMDGPUAliasAnalysis.h" #include "AMDGPUExportClustering.h" #include "AMDGPUMacroFusion.h" +#include "AMDGPUModuleInfo.h" #include "AMDGPUTargetObjectFile.h" #include "AMDGPUTargetTransformInfo.h" #include "GCNIterativeScheduler.h" @@ -225,6 +226,7 @@ initializeAMDGPULowerKernelArgumentsPass(*PR); initializeAMDGPULowerKernelAttributesPass(*PR); initializeAMDGPULowerIntrinsicsPass(*PR); + initializeAMDGPUModuleInfoPassPass(*PR); initializeAMDGPUOpenCLEnqueuedBlockLoweringPass(*PR); initializeAMDGPUPostLegalizerCombinerPass(*PR); initializeAMDGPUPreLegalizerCombinerPass(*PR); @@ -408,6 +410,11 @@ : getTargetFeatureString(); } +const AMDGPUModuleInfo &AMDGPUTargetMachine::getModuleInfo(Module *M) const { + ModuleInfo.initializeModuleInfo(M); + return ModuleInfo; +}; + /// Predicate for Internalize pass. static bool mustPreserveGV(const GlobalValue &GV) { if (const Function *F = dyn_cast(&GV)) @@ -853,6 +860,9 @@ disablePass(&FuncletLayoutID); disablePass(&PatchableFunctionID); + addPass(createAMDGPUModuleInfoPass(getAMDGPUTargetMachine() + .getModuleInfoPtr())); + addPass(createAMDGPUPrintfRuntimeBinding()); // This must occur before inlining, as the inliner will not look through Index: llvm/lib/Target/AMDGPU/CMakeLists.txt =================================================================== --- llvm/lib/Target/AMDGPU/CMakeLists.txt +++ llvm/lib/Target/AMDGPU/CMakeLists.txt @@ -69,7 +69,7 @@ AMDGPULowerKernelAttributes.cpp AMDGPUMachineCFGStructurizer.cpp AMDGPUMachineFunction.cpp - AMDGPUMachineModuleInfo.cpp + AMDGPUModuleInfo.cpp AMDGPUMacroFusion.cpp AMDGPUMCInstLower.cpp AMDGPUMIRFormatter.cpp Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -11950,8 +11950,11 @@ if (Subtarget->hasGFX90AInsts()) { auto SSID = RMW->getSyncScopeID(); + Module *M = RMW->getParent()->getParent()->getParent(); + const GCNTargetMachine &TM = + static_cast(getTargetMachine()); if (SSID == SyncScope::System || - SSID == RMW->getContext().getOrInsertSyncScopeID("one-as")) + SSID == TM.getModuleInfo(M).getSystemOneAddressSpaceSSID()) return AtomicExpansionKind::CmpXChg; return (Ty->isFloatTy() && AS == AMDGPUAS::FLAT_ADDRESS) ? Index: llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp +++ llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp @@ -14,7 +14,8 @@ //===----------------------------------------------------------------------===// #include "AMDGPU.h" -#include "AMDGPUMachineModuleInfo.h" +#include "AMDGPUModuleInfo.h" +#include "AMDGPUTargetMachine.h" #include "GCNSubtarget.h" #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "llvm/ADT/BitmaskEnum.h" @@ -227,7 +228,7 @@ class SIMemOpAccess final { private: - AMDGPUMachineModuleInfo *MMI = nullptr; + const AMDGPUModuleInfo *MMI = nullptr; /// Reports unsupported message \p Msg for \p MI to LLVM context. void reportUnsupported(const MachineBasicBlock::iterator &MI, @@ -638,7 +639,9 @@ } SIMemOpAccess::SIMemOpAccess(MachineFunction &MF) { - MMI = &MF.getMMI().getObjFileInfo(); + const AMDGPUTargetMachine& TM = (const AMDGPUTargetMachine&)MF.getTarget(); + Module *M = MF.getFunction().getParent(); + MMI = &TM.getModuleInfo(M); } Optional SIMemOpAccess::constructFromMIWithMMO(