[llvm] 745e577 - [SlotIndexes] Use analysis block numbers (NFC) (#215171)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 10:50:43 PDT 2026


Author: Alex MacLean
Date: 2026-08-14T10:50:38-07:00
New Revision: 745e577934311d7006a207105697c8f3379ca4fa

URL: https://github.com/llvm/llvm-project/commit/745e577934311d7006a207105697c8f3379ca4fa
DIFF: https://github.com/llvm/llvm-project/commit/745e577934311d7006a207105697c8f3379ca4fa.diff

LOG: [SlotIndexes] Use analysis block numbers (NFC) (#215171)

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/SlotIndexes.h
    llvm/lib/CodeGen/InterferenceCache.cpp
    llvm/lib/CodeGen/LiveRangeCalc.cpp
    llvm/lib/CodeGen/RegAllocGreedy.cpp
    llvm/lib/CodeGen/SlotIndexes.cpp
    llvm/lib/CodeGen/SplitKit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/SlotIndexes.h b/llvm/include/llvm/CodeGen/SlotIndexes.h
index 5b40bd26a991c..cc5143b028e88 100644
--- a/llvm/include/llvm/CodeGen/SlotIndexes.h
+++ b/llvm/include/llvm/CodeGen/SlotIndexes.h
@@ -307,7 +307,7 @@ class raw_ostream;
     using Mi2IndexMap = DenseMap<const MachineInstr *, SlotIndex>;
     Mi2IndexMap mi2iMap;
 
-    /// MBBRanges - Map MBB number to (start, stop) indexes.
+    /// MBBRanges - Map analysis block number to (start, stop) indexes.
     SmallVector<std::pair<SlotIndex, SlotIndex>, 8> MBBRanges;
 
     /// Idx2MBBMap - Sorted list of pairs of index of first instruction
@@ -442,21 +442,10 @@ class raw_ostream;
       }
     }
 
-    /// Return the (start,end) range of the given basic block number.
-    const std::pair<SlotIndex, SlotIndex> &
-    getMBBRange(unsigned Num) const {
-      return MBBRanges[Num];
-    }
-
     /// Return the (start,end) range of the given basic block.
     const std::pair<SlotIndex, SlotIndex> &
     getMBBRange(const MachineBasicBlock *MBB) const {
-      return getMBBRange(MBB->getNumber());
-    }
-
-    /// Returns the first index in the given basic block number.
-    SlotIndex getMBBStartIdx(unsigned Num) const {
-      return getMBBRange(Num).first;
+      return MBBRanges[MBB->getAnalysisNumber()];
     }
 
     /// Returns the first index in the given basic block.
@@ -464,11 +453,6 @@ class raw_ostream;
       return getMBBRange(mbb).first;
     }
 
-    /// Returns the index past the last valid index in the given basic block.
-    SlotIndex getMBBEndIdx(unsigned Num) const {
-      return getMBBRange(Num).second;
-    }
-
     /// Returns the index past the last valid index in the given basic block.
     SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const {
       return getMBBRange(mbb).second;
@@ -630,9 +614,9 @@ class raw_ostream;
       SlotIndex startIdx(startEntry, SlotIndex::Slot_Block);
       SlotIndex endIdx(endEntry, SlotIndex::Slot_Block);
 
-      MBBRanges[prevMBB->getNumber()].second = startIdx;
+      MBBRanges[prevMBB->getAnalysisNumber()].second = startIdx;
 
-      assert(unsigned(mbb->getNumber()) == MBBRanges.size() &&
+      assert(unsigned(mbb->getAnalysisNumber()) == MBBRanges.size() &&
              "Blocks must be added in order");
       MBBRanges.push_back(std::make_pair(startIdx, endIdx));
       idx2MBBMap.push_back(IdxMBBPair(startIdx, mbb));

diff  --git a/llvm/lib/CodeGen/InterferenceCache.cpp b/llvm/lib/CodeGen/InterferenceCache.cpp
index 466070b312b2d..0a4e4c36504e5 100644
--- a/llvm/lib/CodeGen/InterferenceCache.cpp
+++ b/llvm/lib/CodeGen/InterferenceCache.cpp
@@ -129,8 +129,9 @@ bool InterferenceCache::Entry::valid(LiveIntervalUnion *LIUArray,
 }
 
 void InterferenceCache::Entry::update(unsigned MBBNum) {
+  MachineBasicBlock *MBB = MF->getBlockNumbered(MBBNum);
   SlotIndex Start, Stop;
-  std::tie(Start, Stop) = Indexes->getMBBRange(MBBNum);
+  std::tie(Start, Stop) = Indexes->getMBBRange(MBB);
 
   // Use advanceTo only when possible.
   if (PrevPos != Start) {
@@ -149,8 +150,7 @@ void InterferenceCache::Entry::update(unsigned MBBNum) {
     PrevPos = Start;
   }
 
-  MachineFunction::const_iterator MFI =
-      MF->getBlockNumbered(MBBNum)->getIterator();
+  MachineFunction::const_iterator MFI = MBB->getIterator();
   BlockInterference *BI = &Blocks[MBBNum];
   ArrayRef<SlotIndex> RegMaskSlots;
   ArrayRef<const uint32_t*> RegMaskBits;
@@ -206,7 +206,7 @@ void InterferenceCache::Entry::update(unsigned MBBNum) {
     BI = &Blocks[MBBNum];
     if (BI->Tag == Tag)
       return;
-    std::tie(Start, Stop) = Indexes->getMBBRange(MBBNum);
+    std::tie(Start, Stop) = Indexes->getMBBRange(&*MFI);
   }
 
   // Check for last interference in block.

diff  --git a/llvm/lib/CodeGen/LiveRangeCalc.cpp b/llvm/lib/CodeGen/LiveRangeCalc.cpp
index 0260ee2e75aa5..8ac4c261962fe 100644
--- a/llvm/lib/CodeGen/LiveRangeCalc.cpp
+++ b/llvm/lib/CodeGen/LiveRangeCalc.cpp
@@ -283,13 +283,14 @@ bool LiveRangeCalc::findReachingDefs(LiveRange &LR, MachineBasicBlock &UseMBB,
     assert(TheVNI != nullptr && TheVNI != &UndefVNI);
     LiveRangeUpdater Updater(&LR);
     for (unsigned BN : WorkList) {
+      MachineBasicBlock *MBB = MF->getBlockNumbered(BN);
       SlotIndex Start, End;
-      std::tie(Start, End) = Indexes->getMBBRange(BN);
+      std::tie(Start, End) = Indexes->getMBBRange(MBB);
       // Trim the live range in UseMBB.
       if (BN == UseMBBNum && Use.isValid())
         End = Use;
       else
-        Map[MF->getBlockNumbered(BN)] = LiveOutPair(TheVNI, nullptr);
+        Map[MBB] = LiveOutPair(TheVNI, nullptr);
       Updater.add(Start, End, TheVNI);
     }
     return true;

diff  --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index ef23468b1e752..fc28b229dcddc 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -764,7 +764,7 @@ bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf,
 
     // Interference for the live-in value.
     if (BI.LiveIn) {
-      if (Intf.first() <= Indexes->getMBBStartIdx(BC.Number)) {
+      if (Intf.first() <= Indexes->getMBBStartIdx(BI.MBB)) {
         BC.Entry = SpillPlacement::MustSpill;
         ++Ins;
       } else if (Intf.first() < BI.FirstInstr) {
@@ -844,9 +844,9 @@ bool RAGreedy::addThroughConstraints(InterferenceCache::Cursor Intf,
     Register Reg = SA->getParent().reg();
     auto InsertPt = MBB->SkipPHIsLabelsAndDebug(MBB->begin(), Reg);
     SlotIndex InsertIdx = InsertPt == MBB->end()
-                              ? Indexes->getMBBEndIdx(Number)
+                              ? Indexes->getMBBEndIdx(MBB)
                               : LIS->getInstructionIndex(*InsertPt);
-    if (Intf.first() <= Indexes->getMBBStartIdx(Number) ||
+    if (Intf.first() <= Indexes->getMBBStartIdx(MBB) ||
         SlotIndex::isEarlierInstr(Intf.first(), InsertIdx))
       BCS[B].Entry = SpillPlacement::MustSpill;
     else

diff  --git a/llvm/lib/CodeGen/SlotIndexes.cpp b/llvm/lib/CodeGen/SlotIndexes.cpp
index 6861c6f0e9b02..2fcc15744ab6e 100644
--- a/llvm/lib/CodeGen/SlotIndexes.cpp
+++ b/llvm/lib/CodeGen/SlotIndexes.cpp
@@ -85,7 +85,7 @@ void SlotIndexes::analyze(MachineFunction &fn) {
          "MachineInstr -> Index mapping non-empty at initial numbering?");
 
   unsigned index = 0;
-  MBBRanges.resize(mf->getNumBlockIDs());
+  MBBRanges.resize(mf->getMaxAnalysisBlockNumber());
   idx2MBBMap.reserve(mf->size());
 
   indexList.push_back(*createEntry(nullptr, index));
@@ -110,9 +110,9 @@ void SlotIndexes::analyze(MachineFunction &fn) {
     // We insert one blank instructions between basic blocks.
     indexList.push_back(*createEntry(nullptr, index += SlotIndex::InstrDist));
 
-    MBBRanges[MBB.getNumber()].first = blockStartIndex;
-    MBBRanges[MBB.getNumber()].second = SlotIndex(&indexList.back(),
-                                                   SlotIndex::Slot_Block);
+    MBBRanges[MBB.getAnalysisNumber()].first = blockStartIndex;
+    MBBRanges[MBB.getAnalysisNumber()].second =
+        SlotIndex(&indexList.back(), SlotIndex::Slot_Block);
     idx2MBBMap.push_back(IdxMBBPair(blockStartIndex, &MBB));
   }
 
@@ -280,9 +280,9 @@ void SlotIndexes::print(raw_ostream &OS) const {
       OS << '\n';
   }
 
-  for (unsigned i = 0, e = MBBRanges.size(); i != e; ++i)
-    OS << "%bb." << i << "\t[" << MBBRanges[i].first << ';'
-       << MBBRanges[i].second << ")\n";
+  for (const MachineBasicBlock &MBB : *mf)
+    OS << printMBBReference(MBB) << "\t[" << getMBBStartIdx(&MBB) << ';'
+       << getMBBEndIdx(&MBB) << ")\n";
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

diff  --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp
index 7dbd9b5f31d56..404cfe43289d6 100644
--- a/llvm/lib/CodeGen/SplitKit.cpp
+++ b/llvm/lib/CodeGen/SplitKit.cpp
@@ -1676,8 +1676,9 @@ void SplitEditor::splitSingleBlock(const SplitAnalysis::BlockInfo &BI) {
 void SplitEditor::splitLiveThroughBlock(unsigned MBBNum,
                                         unsigned IntvIn, SlotIndex LeaveBefore,
                                         unsigned IntvOut, SlotIndex EnterAfter){
+  MachineBasicBlock *MBB = VRM.getMachineFunction().getBlockNumbered(MBBNum);
   SlotIndex Start, Stop;
-  std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(MBBNum);
+  std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(MBB);
 
   LLVM_DEBUG(dbgs() << "%bb." << MBBNum << " [" << Start << ';' << Stop
                     << ") intf " << LeaveBefore << '-' << EnterAfter
@@ -1689,8 +1690,6 @@ void SplitEditor::splitLiveThroughBlock(unsigned MBBNum,
   assert((!IntvIn || !LeaveBefore || LeaveBefore > Start) && "Impossible intf");
   assert((!EnterAfter || EnterAfter >= Start) && "Interference before block");
 
-  MachineBasicBlock *MBB = VRM.getMachineFunction().getBlockNumbered(MBBNum);
-
   if (!IntvOut) {
     LLVM_DEBUG(dbgs() << ", spill on entry.\n");
     //


        


More information about the llvm-commits mailing list