Skip to content

Commit c426f39

Browse files
committed
[NFC][StackColoring] Use block numbers instead of maps
1 parent 61fb22b commit c426f39

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ class StackColoring {
396396

397397
/// Which slots are marked as LIVE_OUT, coming out of each basic block.
398398
BitVector LiveOut;
399+
400+
bool isEmpty() { return Begin.empty(); }
399401
};
400402

401-
/// Maps active slots (per bit) for each basic block.
402-
using LivenessMap = DenseMap<const MachineBasicBlock *, BlockLifetimeInfo>;
403-
LivenessMap BlockLiveness;
403+
SmallVector<BlockLifetimeInfo, 0> BlockLiveness;
404404

405405
/// Maps basic blocks to a serial number.
406406
SmallVector<const MachineBasicBlock *, 8> BasicBlockNumbering;
@@ -438,9 +438,6 @@ class StackColoring {
438438
bool run(MachineFunction &Func);
439439

440440
private:
441-
/// Used in collectMarkers
442-
using BlockBitVecMap = DenseMap<const MachineBasicBlock *, BitVector>;
443-
444441
/// Debug.
445442
void dump() const;
446443
void dumpIntervals() const;
@@ -538,9 +535,7 @@ LLVM_DUMP_METHOD void StackColoring::dumpBV(const char *tag,
538535
}
539536

540537
LLVM_DUMP_METHOD void StackColoring::dumpBB(MachineBasicBlock *MBB) const {
541-
LivenessMap::const_iterator BI = BlockLiveness.find(MBB);
542-
assert(BI != BlockLiveness.end() && "Block not found");
543-
const BlockLifetimeInfo &BlockInfo = BI->second;
538+
const BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB->getNumber()];
544539

545540
dumpBV("BEGIN", BlockInfo.Begin);
546541
dumpBV("END", BlockInfo.End);
@@ -624,7 +619,7 @@ bool StackColoring::isLifetimeStartOrEnd(const MachineInstr &MI,
624619

625620
unsigned StackColoring::collectMarkers(unsigned NumSlot) {
626621
unsigned MarkersFound = 0;
627-
BlockBitVecMap SeenStartMap;
622+
SmallVector<BitVector> SeenStartMap;
628623
InterestingSlots.clear();
629624
InterestingSlots.resize(NumSlot);
630625
ConservativeSlots.clear();
@@ -634,6 +629,8 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
634629
SmallVector<int, 8> NumStartLifetimes(NumSlot, 0);
635630
SmallVector<int, 8> NumEndLifetimes(NumSlot, 0);
636631

632+
SeenStartMap.resize(MF->getNumBlockIDs());
633+
637634
// Step 1: collect markers and populate the "InterestingSlots"
638635
// and "ConservativeSlots" sets.
639636
for (MachineBasicBlock *MBB : depth_first(MF)) {
@@ -642,10 +639,11 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
642639
// to this bb).
643640
BitVector BetweenStartEnd;
644641
BetweenStartEnd.resize(NumSlot);
642+
SeenStartMap[MBB->getNumber()].resize(NumSlot);
645643
for (const MachineBasicBlock *Pred : MBB->predecessors()) {
646-
BlockBitVecMap::const_iterator I = SeenStartMap.find(Pred);
647-
if (I != SeenStartMap.end()) {
648-
BetweenStartEnd |= I->second;
644+
BitVector &PredSet = SeenStartMap[Pred->getNumber()];
645+
if (!PredSet.empty()) {
646+
BetweenStartEnd |= PredSet;
649647
}
650648
}
651649

@@ -691,7 +689,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
691689
}
692690
}
693691
}
694-
BitVector &SeenStart = SeenStartMap[MBB];
692+
BitVector &SeenStart = SeenStartMap[MBB->getNumber()];
695693
SeenStart |= BetweenStartEnd;
696694
}
697695
if (!MarkersFound) {
@@ -718,6 +716,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
718716

719717
LLVM_DEBUG(dumpBV("Conservative slots", ConservativeSlots));
720718

719+
BlockLiveness.resize(MF->getNumBlockIDs());
721720
// Step 2: compute begin/end sets for each block
722721

723722
// NOTE: We use a depth-first iteration to ensure that we obtain a
@@ -727,7 +726,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
727726
BasicBlockNumbering.push_back(MBB);
728727

729728
// Keep a reference to avoid repeated lookups.
730-
BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB];
729+
BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB->getNumber()];
731730

732731
BlockInfo.Begin.resize(NumSlot);
733732
BlockInfo.End.resize(NumSlot);
@@ -784,19 +783,19 @@ void StackColoring::calculateLocalLiveness() {
784783

785784
for (const MachineBasicBlock *BB : BasicBlockNumbering) {
786785
// Use an iterator to avoid repeated lookups.
787-
LivenessMap::iterator BI = BlockLiveness.find(BB);
788-
assert(BI != BlockLiveness.end() && "Block not found");
789-
BlockLifetimeInfo &BlockInfo = BI->second;
786+
BlockLifetimeInfo &BlockInfo = BlockLiveness[BB->getNumber()];
787+
if (BlockInfo.isEmpty())
788+
continue;
790789

791790
// Compute LiveIn by unioning together the LiveOut sets of all preds.
792791
LocalLiveIn.clear();
793792
for (MachineBasicBlock *Pred : BB->predecessors()) {
794-
LivenessMap::const_iterator I = BlockLiveness.find(Pred);
793+
BlockLifetimeInfo &PrefInfo = BlockLiveness[Pred->getNumber()];
795794
// PR37130: transformations prior to stack coloring can
796795
// sometimes leave behind statically unreachable blocks; these
797796
// can be safely skipped here.
798-
if (I != BlockLiveness.end())
799-
LocalLiveIn |= I->second.LiveOut;
797+
if (!PrefInfo.isEmpty())
798+
LocalLiveIn |= PrefInfo.LiveOut;
800799
}
801800

802801
// Compute LiveOut by subtracting out lifetimes that end in this
@@ -840,7 +839,7 @@ void StackColoring::calculateLiveIntervals(unsigned NumSlots) {
840839
DefinitelyInUse.resize(NumSlots);
841840

842841
// Start the interval of the slots that we previously found to be 'in-use'.
843-
BlockLifetimeInfo &MBBLiveness = BlockLiveness[&MBB];
842+
BlockLifetimeInfo &MBBLiveness = BlockLiveness[MBB.getNumber()];
844843
for (int pos = MBBLiveness.LiveIn.find_first(); pos != -1;
845844
pos = MBBLiveness.LiveIn.find_next(pos)) {
846845
Starts[pos] = Indexes->getMBBStartIdx(&MBB);

0 commit comments

Comments
 (0)