| 
21 | 21 | #include "llvm/ADT/StringExtras.h"  | 
22 | 22 | #include "llvm/CodeGen/MachineBasicBlock.h"  | 
23 | 23 | #include "llvm/CodeGen/MachineFunctionPass.h"  | 
 | 24 | +#include "llvm/CodeGen/MachinePassManager.h"  | 
24 | 25 | #include "llvm/IR/DiagnosticInfo.h"  | 
25 | 26 | #include "llvm/IR/MemoryModelRelaxationAnnotations.h"  | 
 | 27 | +#include "llvm/IR/PassManager.h"  | 
26 | 28 | #include "llvm/Support/AtomicOrdering.h"  | 
27 | 29 | #include "llvm/TargetParser/TargetParser.h"  | 
28 | 30 | 
 
  | 
@@ -625,9 +627,9 @@ class SIGfx12CacheControl : public SIGfx11CacheControl {  | 
625 | 627 |  }  | 
626 | 628 | };  | 
627 | 629 | 
 
  | 
628 |  | -class SIMemoryLegalizer final : public MachineFunctionPass {  | 
 | 630 | +class SIMemoryLegalizer final {  | 
629 | 631 | private:  | 
630 |  | - | 
 | 632 | + const MachineModuleInfo &MMI;  | 
631 | 633 |  /// Cache Control.  | 
632 | 634 |  std::unique_ptr<SICacheControl> CC = nullptr;  | 
633 | 635 | 
 
  | 
@@ -661,10 +663,16 @@ class SIMemoryLegalizer final : public MachineFunctionPass {  | 
661 | 663 |  bool expandAtomicCmpxchgOrRmw(const SIMemOpInfo &MOI,  | 
662 | 664 |  MachineBasicBlock::iterator &MI);  | 
663 | 665 | 
 
  | 
 | 666 | +public:  | 
 | 667 | + SIMemoryLegalizer(const MachineModuleInfo &MMI) : MMI(MMI) {};  | 
 | 668 | + bool run(MachineFunction &MF);  | 
 | 669 | +};  | 
 | 670 | + | 
 | 671 | +class SIMemoryLegalizerLegacy final : public MachineFunctionPass {  | 
664 | 672 | public:  | 
665 | 673 |  static char ID;  | 
666 | 674 | 
 
  | 
667 |  | - SIMemoryLegalizer() : MachineFunctionPass(ID) {}  | 
 | 675 | + SIMemoryLegalizerLegacy() : MachineFunctionPass(ID) {}  | 
668 | 676 | 
 
  | 
669 | 677 |  void getAnalysisUsage(AnalysisUsage &AU) const override {  | 
670 | 678 |  AU.setPreservesCFG();  | 
@@ -2767,11 +2775,26 @@ bool SIMemoryLegalizer::expandAtomicCmpxchgOrRmw(const SIMemOpInfo &MOI,  | 
2767 | 2775 |  return Changed;  | 
2768 | 2776 | }  | 
2769 | 2777 | 
 
  | 
2770 |  | -bool SIMemoryLegalizer::runOnMachineFunction(MachineFunction &MF) {  | 
2771 |  | - bool Changed = false;  | 
2772 |  | - | 
 | 2778 | +bool SIMemoryLegalizerLegacy::runOnMachineFunction(MachineFunction &MF) {  | 
2773 | 2779 |  const MachineModuleInfo &MMI =  | 
2774 | 2780 |  getAnalysis<MachineModuleInfoWrapperPass>().getMMI();  | 
 | 2781 | + return SIMemoryLegalizer(MMI).run(MF);  | 
 | 2782 | +}  | 
 | 2783 | + | 
 | 2784 | +PreservedAnalyses  | 
 | 2785 | +SIMemoryLegalizerPass::run(MachineFunction &MF,  | 
 | 2786 | + MachineFunctionAnalysisManager &MFAM) {  | 
 | 2787 | + auto *MMI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF)  | 
 | 2788 | + .getCachedResult<MachineModuleAnalysis>(  | 
 | 2789 | + *MF.getFunction().getParent());  | 
 | 2790 | + assert(MMI && "MachineModuleAnalysis must be available");  | 
 | 2791 | + if (!SIMemoryLegalizer(MMI->getMMI()).run(MF))  | 
 | 2792 | + return PreservedAnalyses::all();  | 
 | 2793 | + return getMachineFunctionPassPreservedAnalyses().preserveSet<CFGAnalyses>();  | 
 | 2794 | +}  | 
 | 2795 | + | 
 | 2796 | +bool SIMemoryLegalizer::run(MachineFunction &MF) {  | 
 | 2797 | + bool Changed = false;  | 
2775 | 2798 | 
 
  | 
2776 | 2799 |  SIMemOpAccess MOA(MMI.getObjFileInfo<AMDGPUMachineModuleInfo>());  | 
2777 | 2800 |  CC = SICacheControl::create(MF.getSubtarget<GCNSubtarget>());  | 
@@ -2812,11 +2835,11 @@ bool SIMemoryLegalizer::runOnMachineFunction(MachineFunction &MF) {  | 
2812 | 2835 |  return Changed;  | 
2813 | 2836 | }  | 
2814 | 2837 | 
 
  | 
2815 |  | -INITIALIZE_PASS(SIMemoryLegalizer, DEBUG_TYPE, PASS_NAME, false, false)  | 
 | 2838 | +INITIALIZE_PASS(SIMemoryLegalizerLegacy, DEBUG_TYPE, PASS_NAME, false, false)  | 
2816 | 2839 | 
 
  | 
2817 |  | -char SIMemoryLegalizer::ID = 0;  | 
2818 |  | -char &llvm::SIMemoryLegalizerID = SIMemoryLegalizer::ID;  | 
 | 2840 | +char SIMemoryLegalizerLegacy::ID = 0;  | 
 | 2841 | +char &llvm::SIMemoryLegalizerID = SIMemoryLegalizerLegacy::ID;  | 
2819 | 2842 | 
 
  | 
2820 | 2843 | FunctionPass *llvm::createSIMemoryLegalizerPass() {  | 
2821 |  | - return new SIMemoryLegalizer();  | 
 | 2844 | + return new SIMemoryLegalizerLegacy();  | 
2822 | 2845 | }  | 
0 commit comments