@@ -396,11 +396,11 @@ class StackColoring {
396
396
397
397
// / Which slots are marked as LIVE_OUT, coming out of each basic block.
398
398
BitVector LiveOut;
399
+
400
+ bool isEmpty () { return Begin.empty (); }
399
401
};
400
402
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;
404
404
405
405
// / Maps basic blocks to a serial number.
406
406
SmallVector<const MachineBasicBlock *, 8 > BasicBlockNumbering;
@@ -438,9 +438,6 @@ class StackColoring {
438
438
bool run (MachineFunction &Func);
439
439
440
440
private:
441
- // / Used in collectMarkers
442
- using BlockBitVecMap = DenseMap<const MachineBasicBlock *, BitVector>;
443
-
444
441
// / Debug.
445
442
void dump () const ;
446
443
void dumpIntervals () const ;
@@ -538,9 +535,7 @@ LLVM_DUMP_METHOD void StackColoring::dumpBV(const char *tag,
538
535
}
539
536
540
537
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 ()];
544
539
545
540
dumpBV (" BEGIN" , BlockInfo.Begin );
546
541
dumpBV (" END" , BlockInfo.End );
@@ -624,7 +619,7 @@ bool StackColoring::isLifetimeStartOrEnd(const MachineInstr &MI,
624
619
625
620
unsigned StackColoring::collectMarkers (unsigned NumSlot) {
626
621
unsigned MarkersFound = 0 ;
627
- BlockBitVecMap SeenStartMap;
622
+ SmallVector<BitVector> SeenStartMap;
628
623
InterestingSlots.clear ();
629
624
InterestingSlots.resize (NumSlot);
630
625
ConservativeSlots.clear ();
@@ -634,6 +629,8 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
634
629
SmallVector<int , 8 > NumStartLifetimes (NumSlot, 0 );
635
630
SmallVector<int , 8 > NumEndLifetimes (NumSlot, 0 );
636
631
632
+ SeenStartMap.resize (MF->getNumBlockIDs ());
633
+
637
634
// Step 1: collect markers and populate the "InterestingSlots"
638
635
// and "ConservativeSlots" sets.
639
636
for (MachineBasicBlock *MBB : depth_first (MF)) {
@@ -642,10 +639,11 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
642
639
// to this bb).
643
640
BitVector BetweenStartEnd;
644
641
BetweenStartEnd.resize (NumSlot);
642
+ SeenStartMap[MBB->getNumber ()].resize (NumSlot);
645
643
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 ;
649
647
}
650
648
}
651
649
@@ -691,7 +689,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
691
689
}
692
690
}
693
691
}
694
- BitVector &SeenStart = SeenStartMap[MBB];
692
+ BitVector &SeenStart = SeenStartMap[MBB-> getNumber () ];
695
693
SeenStart |= BetweenStartEnd;
696
694
}
697
695
if (!MarkersFound) {
@@ -718,6 +716,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
718
716
719
717
LLVM_DEBUG (dumpBV (" Conservative slots" , ConservativeSlots));
720
718
719
+ BlockLiveness.resize (MF->getNumBlockIDs ());
721
720
// Step 2: compute begin/end sets for each block
722
721
723
722
// NOTE: We use a depth-first iteration to ensure that we obtain a
@@ -727,7 +726,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
727
726
BasicBlockNumbering.push_back (MBB);
728
727
729
728
// Keep a reference to avoid repeated lookups.
730
- BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB];
729
+ BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB-> getNumber () ];
731
730
732
731
BlockInfo.Begin .resize (NumSlot);
733
732
BlockInfo.End .resize (NumSlot);
@@ -784,19 +783,19 @@ void StackColoring::calculateLocalLiveness() {
784
783
785
784
for (const MachineBasicBlock *BB : BasicBlockNumbering) {
786
785
// 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 ;
790
789
791
790
// Compute LiveIn by unioning together the LiveOut sets of all preds.
792
791
LocalLiveIn.clear ();
793
792
for (MachineBasicBlock *Pred : BB->predecessors ()) {
794
- LivenessMap::const_iterator I = BlockLiveness. find ( Pred) ;
793
+ BlockLifetimeInfo &PrefInfo = BlockLiveness[ Pred-> getNumber ()] ;
795
794
// PR37130: transformations prior to stack coloring can
796
795
// sometimes leave behind statically unreachable blocks; these
797
796
// can be safely skipped here.
798
- if (I != BlockLiveness. end ())
799
- LocalLiveIn |= I-> second .LiveOut ;
797
+ if (!PrefInfo. isEmpty ())
798
+ LocalLiveIn |= PrefInfo .LiveOut ;
800
799
}
801
800
802
801
// Compute LiveOut by subtracting out lifetimes that end in this
@@ -840,7 +839,7 @@ void StackColoring::calculateLiveIntervals(unsigned NumSlots) {
840
839
DefinitelyInUse.resize (NumSlots);
841
840
842
841
// 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 () ];
844
843
for (int pos = MBBLiveness.LiveIn .find_first (); pos != -1 ;
845
844
pos = MBBLiveness.LiveIn .find_next (pos)) {
846
845
Starts[pos] = Indexes->getMBBStartIdx (&MBB);
0 commit comments