[llvm] [CodeGen][NewPM] Port `machine-loops` to new pass manager (PR #97793)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 23:43:23 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-pgo

Author: None (paperchalice)

<details>
<summary>Changes</summary>

- Add `MachineLoopAnalysis`.
- Add `MachineLoopPrinterPass`.
- Convert to `MachineLoopInfoWrapperPass` in legacy pass manager.

---

Patch is 85.48 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/97793.diff


58 Files Affected:

- (modified) llvm/include/llvm/CodeGen/MachineLoopInfo.h (+42-67) 
- (modified) llvm/include/llvm/InitializePasses.h (+1-1) 
- (modified) llvm/include/llvm/Passes/MachinePassRegistry.def (+2) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+3-2) 
- (modified) llvm/lib/CodeGen/BranchFolding.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGen.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/EarlyIfConversion.cpp (+6-6) 
- (modified) llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp (+4-3) 
- (modified) llvm/lib/CodeGen/MIRSampleProfile.cpp (+5-4) 
- (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/MachineBasicBlock.cpp (+6-5) 
- (modified) llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/MachineBlockPlacement.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/MachineCombiner.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/MachineLICM.cpp (+5-5) 
- (modified) llvm/lib/CodeGen/MachineLoopInfo.cpp (+40-12) 
- (modified) llvm/lib/CodeGen/MachinePipeliner.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/MachineScheduler.cpp (+6-6) 
- (modified) llvm/lib/CodeGen/MachineSink.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MachineTraceMetrics.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/ModuloSchedule.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/PHIElimination.cpp (+4-2) 
- (modified) llvm/lib/CodeGen/PeepholeOptimizer.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/PostRASchedulerList.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/PrologEpilogInserter.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/RegAllocBasic.cpp (+5-4) 
- (modified) llvm/lib/CodeGen/RegAllocGreedy.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/RegAllocPBQP.cpp (+6-5) 
- (modified) llvm/lib/CodeGen/RegisterCoalescer.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/ShrinkWrap.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/StackSlotColoring.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/UnreachableBlockElim.cpp (+4-2) 
- (modified) llvm/lib/CodeGen/XRayInstrumentation.cpp (+5-4) 
- (modified) llvm/lib/Passes/PassBuilder.cpp (+1) 
- (modified) llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp (+3-3) 
- (modified) llvm/lib/Target/AArch64/AArch64FalkorHWPFFix.cpp (+3-3) 
- (modified) llvm/lib/Target/AArch64/AArch64MIPeepholeOpt.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/R600MachineCFGStructurizer.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/R600OptimizeVectorRegisters.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/R600Packetizer.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/SIOptimizeVGPRLiveRange.cpp (+4-4) 
- (modified) llvm/lib/Target/ARM/ARMBlockPlacement.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/MVETPAndVPTOptimisationsPass.cpp (+4-4) 
- (modified) llvm/lib/Target/Hexagon/HexagonEarlyIfConv.cpp (+2-2) 
- (modified) llvm/lib/Target/Hexagon/HexagonHardwareLoops.cpp (+3-3) 
- (modified) llvm/lib/Target/Hexagon/HexagonSplitDouble.cpp (+3-3) 
- (modified) llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp (+4-4) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCCTRLoops.cpp (+3-3) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCFGSort.cpp (+3-3) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp (+3-3) 
- (modified) llvm/lib/Target/X86/X86CmovConversion.cpp (+5-5) 
- (modified) llvm/lib/Target/X86/X86LoadValueInjectionLoadHardening.cpp (+3-3) 
- (modified) llvm/lib/Target/X86/X86PreTileConfig.cpp (+3-3) 
- (added) llvm/test/CodeGen/X86/machine-loops.ll (+43) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/MachineLoopInfo.h b/llvm/include/llvm/CodeGen/MachineLoopInfo.h
index 967c4a70ca4699..80f3a713009fcd 100644
--- a/llvm/include/llvm/CodeGen/MachineLoopInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineLoopInfo.h
@@ -31,6 +31,7 @@
 
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachinePassManager.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/DebugLoc.h"
 #include "llvm/Support/GenericLoopInfo.h"
@@ -101,23 +102,20 @@ class MachineLoop : public LoopBase<MachineBasicBlock, MachineLoop> {
 // Implementation in LoopInfoImpl.h
 extern template class LoopInfoBase<MachineBasicBlock, MachineLoop>;
 
-class MachineLoopInfo : public MachineFunctionPass {
+class MachineLoopInfo : public LoopInfoBase<MachineBasicBlock, MachineLoop> {
   friend class LoopBase<MachineBasicBlock, MachineLoop>;
 
-  LoopInfoBase<MachineBasicBlock, MachineLoop> LI;
-
 public:
-  static char ID; // Pass identification, replacement for typeid
-
-  MachineLoopInfo();
-  explicit MachineLoopInfo(MachineDominatorTree &MDT)
-      : MachineFunctionPass(ID) {
-    calculate(MDT);
-  }
+  MachineLoopInfo() = default;
+  explicit MachineLoopInfo(MachineDominatorTree &MDT) { calculate(MDT); }
+  MachineLoopInfo(MachineLoopInfo &&) = default;
+  MachineLoopInfo &operator=(MachineLoopInfo &&RHS) = default;
   MachineLoopInfo(const MachineLoopInfo &) = delete;
   MachineLoopInfo &operator=(const MachineLoopInfo &) = delete;
 
-  LoopInfoBase<MachineBasicBlock, MachineLoop>& getBase() { return LI; }
+  /// Handle invalidation explicitly.
+  bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
+                  MachineFunctionAnalysisManager::Invalidator &);
 
   /// Find the block that either is the loop preheader, or could
   /// speculatively be used as the preheader. This is e.g. useful to place
@@ -130,69 +128,46 @@ class MachineLoopInfo : public MachineFunctionPass {
   findLoopPreheader(MachineLoop *L, bool SpeculativePreheader = false,
                     bool FindMultiLoopPreheader = false) const;
 
-  /// The iterator interface to the top-level loops in the current function.
-  using iterator = LoopInfoBase<MachineBasicBlock, MachineLoop>::iterator;
-  inline iterator begin() const { return LI.begin(); }
-  inline iterator end() const { return LI.end(); }
-  bool empty() const { return LI.empty(); }
-
-  /// Return the innermost loop that BB lives in. If a basic block is in no loop
-  /// (for example the entry node), null is returned.
-  inline MachineLoop *getLoopFor(const MachineBasicBlock *BB) const {
-    return LI.getLoopFor(BB);
-  }
-
-  /// Same as getLoopFor.
-  inline const MachineLoop *operator[](const MachineBasicBlock *BB) const {
-    return LI.getLoopFor(BB);
-  }
-
-  /// Return the loop nesting level of the specified block.
-  inline unsigned getLoopDepth(const MachineBasicBlock *BB) const {
-    return LI.getLoopDepth(BB);
-  }
-
-  /// True if the block is a loop header node.
-  inline bool isLoopHeader(const MachineBasicBlock *BB) const {
-    return LI.isLoopHeader(BB);
-  }
-
   /// Calculate the natural loop information.
-  bool runOnMachineFunction(MachineFunction &F) override;
   void calculate(MachineDominatorTree &MDT);
+};
+
+/// Analysis pass that exposes the \c MachineLoopInfo for a machine function.
+class MachineLoopAnalysis : public AnalysisInfoMixin<MachineLoopAnalysis> {
+  friend AnalysisInfoMixin<MachineLoopAnalysis>;
+  static AnalysisKey Key;
+
+public:
+  using Result = MachineLoopInfo;
+  Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
+};
+
+/// Printer pass for the \c LoopAnalysis results.
+class MachineLoopPrinterPass : public PassInfoMixin<MachineLoopPrinterPass> {
+  raw_ostream &OS;
+
+public:
+  explicit MachineLoopPrinterPass(raw_ostream &OS) : OS(OS) {}
+  PreservedAnalyses run(MachineFunction &MF,
+                        MachineFunctionAnalysisManager &MFAM);
+  static bool isRequired() { return true; }
+};
+
+class MachineLoopInfoWrapperPass : public MachineFunctionPass {
+  MachineLoopInfo LI;
+
+public:
+  static char ID; // Pass identification, replacement for typeid
+
+  MachineLoopInfoWrapperPass();
+
+  bool runOnMachineFunction(MachineFunction &F) override;
 
   void releaseMemory() override { LI.releaseMemory(); }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override;
 
-  /// This removes the specified top-level loop from this loop info object. The
-  /// loop is not deleted, as it will presumably be inserted into another loop.
-  inline MachineLoop *removeLoop(iterator I) { return LI.removeLoop(I); }
-
-  /// Change the top-level loop that contains BB to the specified loop. This
-  /// should be used by transformations that restructure the loop hierarchy
-  /// tree.
-  inline void changeLoopFor(MachineBasicBlock *BB, MachineLoop *L) {
-    LI.changeLoopFor(BB, L);
-  }
-
-  /// Replace the specified loop in the top-level loops list with the indicated
-  /// loop.
-  inline void changeTopLevelLoop(MachineLoop *OldLoop, MachineLoop *NewLoop) {
-    LI.changeTopLevelLoop(OldLoop, NewLoop);
-  }
-
-  /// This adds the specified loop to the collection of top-level loops.
-  inline void addTopLevelLoop(MachineLoop *New) {
-    LI.addTopLevelLoop(New);
-  }
-
-  /// This method completely removes BB from all data structures, including all
-  /// of the Loop objects it is nested in and our mapping from
-  /// MachineBasicBlocks to loops.
-  void removeBlock(MachineBasicBlock *BB) {
-    LI.removeBlock(BB);
-  }
+  MachineLoopInfo &getLI() { return LI; }
 };
 
 // Allow clients to walk the list of nested loops...
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 421c09ada7a194..9d96e0f25ec1ea 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -195,7 +195,7 @@ void initializeMachineFunctionPrinterPassPass(PassRegistry&);
 void initializeMachineFunctionSplitterPass(PassRegistry &);
 void initializeMachineLateInstrsCleanupPass(PassRegistry&);
 void initializeMachineLICMPass(PassRegistry&);
-void initializeMachineLoopInfoPass(PassRegistry&);
+void initializeMachineLoopInfoWrapperPassPass(PassRegistry &);
 void initializeMachineModuleInfoWrapperPassPass(PassRegistry &);
 void initializeMachineOptimizationRemarkEmitterPassPass(PassRegistry&);
 void initializeMachineOutlinerPass(PassRegistry&);
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index b1542ab1392865..95c618f743d2a0 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -92,6 +92,7 @@ LOOP_PASS("loop-reduce", LoopStrengthReducePass())
 MACHINE_FUNCTION_ANALYSIS("machine-branch-prob",
                           MachineBranchProbabilityAnalysis())
 MACHINE_FUNCTION_ANALYSIS("machine-dom-tree", MachineDominatorTreeAnalysis())
+MACHINE_FUNCTION_ANALYSIS("machine-loops", MachineLoopAnalysis())
 MACHINE_FUNCTION_ANALYSIS("machine-post-dom-tree",
                           MachinePostDominatorTreeAnalysis())
 MACHINE_FUNCTION_ANALYSIS("pass-instrumentation", PassInstrumentationAnalysis(PIC))
@@ -136,6 +137,7 @@ MACHINE_FUNCTION_PASS("print<machine-branch-prob>",
                       MachineBranchProbabilityPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print<machine-dom-tree>",
                       MachineDominatorTreePrinterPass(dbgs()))
+MACHINE_FUNCTION_PASS("print<machine-loops>", MachineLoopPrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("print<machine-post-dom-tree>",
                       MachinePostDominatorTreePrinterPass(dbgs()))
 MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index c52cbff689dc5d..f8efd5843c6bbd 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1704,10 +1704,11 @@ void AsmPrinter::emitFunctionBody() {
     }
 
     // Get MachineLoopInfo or compute it on the fly if it's unavailable
-    MLI = getAnalysisIfAvailable<MachineLoopInfo>();
+    auto *MLIWrapper = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
+    MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
     if (!MLI) {
       OwnedMLI = std::make_unique<MachineLoopInfo>();
-      OwnedMLI->getBase().analyze(MDT->getBase());
+      OwnedMLI->analyze(MDT->getBase());
       MLI = OwnedMLI.get();
     }
   }
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 1b6a6ee2bbc728..afe797014095d0 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -415,7 +415,7 @@ MachineBasicBlock *BranchFolder::SplitMBBAt(MachineBasicBlock &CurMBB,
   // NewMBB belongs to the same loop as CurMBB.
   if (MLI)
     if (MachineLoop *ML = MLI->getLoopFor(&CurMBB))
-      ML->addBasicBlockToLoop(NewMBB, MLI->getBase());
+      ML->addBasicBlockToLoop(NewMBB, *MLI);
 
   // NewMBB inherits CurMBB's block frequency.
   MBBFreqInfo.setBlockFreq(NewMBB, MBBFreqInfo.getBlockFreq(&CurMBB));
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 7dcb0ea5d903c5..35e27519378f25 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -84,7 +84,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
   initializeMachineFunctionPrinterPassPass(Registry);
   initializeMachineLateInstrsCleanupPass(Registry);
   initializeMachineLICMPass(Registry);
-  initializeMachineLoopInfoPass(Registry);
+  initializeMachineLoopInfoWrapperPassPass(Registry);
   initializeMachineModuleInfoWrapperPassPass(Registry);
   initializeMachineOptimizationRemarkEmitterPassPass(Registry);
   initializeMachineOutlinerPass(Registry);
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 5f3e85077cb563..a5c99498921dbb 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -797,8 +797,8 @@ void EarlyIfConverter::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
   AU.addRequired<MachineDominatorTreeWrapperPass>();
   AU.addPreserved<MachineDominatorTreeWrapperPass>();
-  AU.addRequired<MachineLoopInfo>();
-  AU.addPreserved<MachineLoopInfo>();
+  AU.addRequired<MachineLoopInfoWrapperPass>();
+  AU.addPreserved<MachineLoopInfoWrapperPass>();
   AU.addRequired<MachineTraceMetrics>();
   AU.addPreserved<MachineTraceMetrics>();
   MachineFunctionPass::getAnalysisUsage(AU);
@@ -1087,7 +1087,7 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = STI.getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
-  Loops = &getAnalysis<MachineLoopInfo>();
+  Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
   Traces = &getAnalysis<MachineTraceMetrics>();
   MinInstr = nullptr;
 
@@ -1150,8 +1150,8 @@ void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
   AU.addRequired<MachineDominatorTreeWrapperPass>();
   AU.addPreserved<MachineDominatorTreeWrapperPass>();
-  AU.addRequired<MachineLoopInfo>();
-  AU.addPreserved<MachineLoopInfo>();
+  AU.addRequired<MachineLoopInfoWrapperPass>();
+  AU.addPreserved<MachineLoopInfoWrapperPass>();
   MachineFunctionPass::getAnalysisUsage(AU);
 }
 
@@ -1221,7 +1221,7 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
   MRI = &MF.getRegInfo();
   SchedModel.init(&STI);
   DomTree = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
-  Loops = &getAnalysis<MachineLoopInfo>();
+  Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
   MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
 
   bool Changed = false;
diff --git a/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp
index 83b16fc883e8b6..0cf01edbff6c87 100644
--- a/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp
@@ -24,7 +24,7 @@ using namespace llvm;
 INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
                       "Lazy Machine Block Frequency Analysis", true, true)
 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
+INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
 INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
                     "Lazy Machine Block Frequency Analysis", true, true)
 
@@ -63,7 +63,8 @@ LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
   }
 
   auto &MBPI = getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
-  auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
+  auto *MLIWrapper = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
+  auto *MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
   auto *MDTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
   auto *MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
   LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
@@ -83,7 +84,7 @@ LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
 
     // Generate LoopInfo from it.
     OwnedMLI = std::make_unique<MachineLoopInfo>();
-    OwnedMLI->getBase().analyze(MDT->getBase());
+    OwnedMLI->analyze(MDT->getBase());
     MLI = OwnedMLI.get();
   }
 
diff --git a/llvm/lib/CodeGen/MIRSampleProfile.cpp b/llvm/lib/CodeGen/MIRSampleProfile.cpp
index 84e6c612a33439..b77d8aabe029ae 100644
--- a/llvm/lib/CodeGen/MIRSampleProfile.cpp
+++ b/llvm/lib/CodeGen/MIRSampleProfile.cpp
@@ -72,7 +72,7 @@ INITIALIZE_PASS_BEGIN(MIRProfileLoaderPass, DEBUG_TYPE,
 INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfo)
 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTreeWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
+INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
 INITIALIZE_PASS_END(MIRProfileLoaderPass, DEBUG_TYPE, "Load MIR Sample Profile",
                     /* cfg = */ false, /* is_analysis = */ false)
@@ -367,7 +367,7 @@ bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) {
   MIRSampleLoader->setInitVals(
       &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree(),
       &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree(),
-      &getAnalysis<MachineLoopInfo>(), MBFI,
+      &getAnalysis<MachineLoopInfoWrapperPass>().getLI(), MBFI,
       &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE());
 
   MF.RenumberBlocks();
@@ -379,7 +379,8 @@ bool MIRProfileLoaderPass::runOnMachineFunction(MachineFunction &MF) {
 
   bool Changed = MIRSampleLoader->runOnFunction(MF);
   if (Changed)
-    MBFI->calculate(MF, *MBFI->getMBPI(), *&getAnalysis<MachineLoopInfo>());
+    MBFI->calculate(MF, *MBFI->getMBPI(),
+                    *&getAnalysis<MachineLoopInfoWrapperPass>().getLI());
 
   if (ViewBFIAfter && ViewBlockLayoutWithBFI != GVDT_None &&
       (ViewBlockFreqFuncName.empty() ||
@@ -403,7 +404,7 @@ void MIRProfileLoaderPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<MachineBlockFrequencyInfo>();
   AU.addRequired<MachineDominatorTreeWrapperPass>();
   AU.addRequired<MachinePostDominatorTreeWrapperPass>();
-  AU.addRequiredTransitive<MachineLoopInfo>();
+  AU.addRequiredTransitive<MachineLoopInfoWrapperPass>();
   AU.addRequired<MachineOptimizationRemarkEmitterPass>();
   MachineFunctionPass::getAnalysisUsage(AU);
 }
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 5698f6d6fea005..7f90457d720b48 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -389,7 +389,7 @@ class ReleaseModeEvictionAdvisorAnalysis final
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<MachineBlockFrequencyInfo>();
-    AU.addRequired<MachineLoopInfo>();
+    AU.addRequired<MachineLoopInfoWrapperPass>();
     RegAllocEvictionAdvisorAnalysis::getAnalysisUsage(AU);
   }
 
@@ -407,7 +407,7 @@ class ReleaseModeEvictionAdvisorAnalysis final
     }
     return std::make_unique<MLEvictAdvisor>(
         MF, RA, Runner.get(), getAnalysis<MachineBlockFrequencyInfo>(),
-        getAnalysis<MachineLoopInfo>());
+        getAnalysis<MachineLoopInfoWrapperPass>().getLI());
   }
   std::unique_ptr<MLModelRunner> Runner;
 };
@@ -496,7 +496,7 @@ class DevelopmentModeEvictionAdvisorAnalysis final
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<MachineBlockFrequencyInfo>();
-    AU.addRequired<MachineLoopInfo>();
+    AU.addRequired<MachineLoopInfoWrapperPass>();
     RegAllocEvictionAdvisorAnalysis::getAnalysisUsage(AU);
   }
 
@@ -545,7 +545,7 @@ class DevelopmentModeEvictionAdvisorAnalysis final
       Log->switchContext(MF.getName());
     return std::make_unique<DevelopmentModeEvictAdvisor>(
         MF, RA, Runner.get(), getAnalysis<MachineBlockFrequencyInfo>(),
-        getAnalysis<MachineLoopInfo>(), Log.get());
+        getAnalysis<MachineLoopInfoWrapperPass>().getLI(), Log.get());
   }
 
   std::unique_ptr<MLModelRunner> Runner;
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 533ab7cccaeb71..b5c3e1625f1aca 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1340,20 +1340,21 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
           P.getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>())
     MDTWrapper->getDomTree().recordSplitCriticalEdge(this, Succ, NMBB);
 
-  if (MachineLoopInfo *MLI = P.getAnalysisIfAvailable<MachineLoopInfo>())
+  auto *MLIWrapper = P.getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
+  if (MachineLoopInfo *MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr)
     if (MachineLoop *TIL = MLI->getLoopFor(this)) {
       // If one or the other blocks were not in a loop, the new block is not
       // either, and thus LI doesn't need to be updated.
       if (MachineLoop *DestLoop = MLI->getLoopFor(Succ)) {
         if (TIL == DestLoop) {
           // Both in the same loop, the NMBB joins loop.
-          DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase());
+          DestLoop->addBasicBlockToLoop(NMBB, *MLI);
         } else if (TIL->contains(DestLoop)) {
           // Edge from an outer loop to an inner loop.  Add to the outer loop.
-          TIL->addBasicBlockToLoop(NMBB, MLI->getBase());
+          TIL->addBasicBlockToLoop(NMBB, *MLI);
         } else if (DestLoop->contains(TIL)) {
           // Edge from an inner loop to an outer loop.  Add to the outer loop.
-          DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase());
+          DestLoop->addBasicBlockToLoop(NMBB, *MLI);
         } else {
           // Edge from two loops with no containment relation.  Because these
           // are natural loops, we know that the destination block must be the
@@ -1362,7 +1363,7 @@ MachineBasicBlock *MachineBasicBlock::SplitCriticalEdge(
           assert(DestLoop->getHeader() == Succ &&
                  "Should not create irreducible loops!");
           if (MachineLoop *P = DestLoop->getParentLoop())
-            P->addBasicBlockToLoop(NMBB, MLI->getBase());
+            P->addBasicBlockToLoop(NMBB, *MLI);
         }
       }
     }
diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index 2a68f18d9bc764..5c053a4f1cdb81 100644
--- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -164,7 +164,7 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo *>
 INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfo, DEBUG_TYPE,
                       "Machine Block Frequency Analysis", true, true)
 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
+INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
 INITIALIZE_PASS_END(MachineBlockFrequencyInfo, DEBUG_TYPE,
                     "Machine Block Frequency Analysis...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/97793


More information about the llvm-commits mailing list