[PATCH] D133782: LiveIntervals: Allow constructing standalone without a PassManager

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 08:53:30 PDT 2022


arsenm created this revision.
arsenm added reviewers: qcolombet, MatzeB.
Herald added subscribers: arphaman, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

The verifier is semi-reliant on LiveIntervals in a weird way. The
verifier has its own liveness analysis, which misses some things
caught with LiveIntervals. As a consequence, llvm-reduce's use of the
verifier fails to filter out some invalid MIR. Allow constructing
LiveIntervals independently of a PassManager, so that llvm-reduce can
use this directly in its passless verify calls. Additionally, some
reductions should directly inspect the LiveIntervals.


https://reviews.llvm.org/D133782

Files:
  llvm/include/llvm/CodeGen/LiveIntervals.h
  llvm/include/llvm/CodeGen/SlotIndexes.h
  llvm/lib/CodeGen/LiveIntervals.cpp
  llvm/lib/CodeGen/SlotIndexes.cpp


Index: llvm/lib/CodeGen/SlotIndexes.cpp
===================================================================
--- llvm/lib/CodeGen/SlotIndexes.cpp
+++ llvm/lib/CodeGen/SlotIndexes.cpp
@@ -47,8 +47,7 @@
   ileAllocator.Reset();
 }
 
-bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
-
+void SlotIndexes::calculate(MachineFunction &fn) {
   // Compute numbering as follows:
   // Grab an iterator to the start of the index list.
   // Iterate over all MBBs, and within each MBB all MIs, keeping the MI
@@ -105,7 +104,10 @@
 
   // Sort the Idx2MBBMap
   llvm::sort(idx2MBBMap, less_first());
+}
 
+bool SlotIndexes::runOnMachineFunction(MachineFunction &fn) {
+  calculate(fn);
   LLVM_DEBUG(mf->print(dbgs(), this));
 
   // And we're done!
Index: llvm/lib/CodeGen/LiveIntervals.cpp
===================================================================
--- llvm/lib/CodeGen/LiveIntervals.cpp
+++ llvm/lib/CodeGen/LiveIntervals.cpp
@@ -117,13 +117,14 @@
   VNInfoAllocator.Reset();
 }
 
-bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
-  MF = &fn;
+void LiveIntervals::init(MachineFunction &MF_, SlotIndexes *Indexes_,
+                         MachineDominatorTree *DT_) {
+  MF = &MF_;
+  Indexes = Indexes_;
+  DomTree = DT_;
   MRI = &MF->getRegInfo();
   TRI = MF->getSubtarget().getRegisterInfo();
   TII = MF->getSubtarget().getInstrInfo();
-  Indexes = &getAnalysis<SlotIndexes>();
-  DomTree = &getAnalysis<MachineDominatorTree>();
 
   if (!LICalc)
     LICalc = new LiveIntervalCalc();
@@ -141,6 +142,10 @@
     for (unsigned i = 0, e = TRI->getNumRegUnits(); i != e; ++i)
       getRegUnit(i);
   }
+}
+
+bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
+  init(fn, &getAnalysis<SlotIndexes>(), &getAnalysis<MachineDominatorTree>());
   LLVM_DEBUG(dump());
   return false;
 }
Index: llvm/include/llvm/CodeGen/SlotIndexes.h
===================================================================
--- llvm/include/llvm/CodeGen/SlotIndexes.h
+++ llvm/include/llvm/CodeGen/SlotIndexes.h
@@ -357,6 +357,7 @@
     void getAnalysisUsage(AnalysisUsage &au) const override;
     void releaseMemory() override;
 
+    void calculate(MachineFunction &fn);
     bool runOnMachineFunction(MachineFunction &fn) override;
 
     /// Dump the indexes.
Index: llvm/include/llvm/CodeGen/LiveIntervals.h
===================================================================
--- llvm/include/llvm/CodeGen/LiveIntervals.h
+++ llvm/include/llvm/CodeGen/LiveIntervals.h
@@ -93,6 +93,9 @@
     /// interference.
     SmallVector<LiveRange*, 0> RegUnitRanges;
 
+    void init(MachineFunction &MF, SlotIndexes *Indexes,
+              MachineDominatorTree *DT);
+
   public:
     static char ID;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133782.459769.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220913/241ab806/attachment.bin>


More information about the llvm-commits mailing list