@@ -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
@@ -693,7 +691,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
693
691
}
694
692
}
695
693
}
696
- BitVector &SeenStart = SeenStartMap[MBB];
694
+ BitVector &SeenStart = SeenStartMap[MBB-> getNumber () ];
697
695
SeenStart |= BetweenStartEnd;
698
696
}
699
697
if (!MarkersFound) {
@@ -720,6 +718,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
720
718
721
719
LLVM_DEBUG (dumpBV (" Conservative slots" , ConservativeSlots));
722
720
721
+ BlockLiveness.resize (MF->getNumBlockIDs ());
723
722
// Step 2: compute begin/end sets for each block
724
723
725
724
// NOTE: We use a depth-first iteration to ensure that we obtain a
@@ -729,7 +728,7 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
729
728
BasicBlockNumbering.push_back (MBB);
730
729
731
730
// Keep a reference to avoid repeated lookups.
732
- BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB];
731
+ BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB-> getNumber () ];
733
732
734
733
BlockInfo.Begin .resize (NumSlot);
735
734
BlockInfo.End .resize (NumSlot);
@@ -786,19 +785,19 @@ void StackColoring::calculateLocalLiveness() {
786
785
787
786
for (const MachineBasicBlock *BB : BasicBlockNumbering) {
788
787
// Use an iterator to avoid repeated lookups.
789
- LivenessMap::iterator BI = BlockLiveness. find (BB) ;
790
- assert (BI != BlockLiveness. end () && " Block not found " );
791
- BlockLifetimeInfo &BlockInfo = BI-> second ;
788
+ BlockLifetimeInfo &BlockInfo = BlockLiveness[BB-> getNumber ()] ;
789
+ if (BlockInfo. isEmpty ())
790
+ continue ;
792
791
793
792
// Compute LiveIn by unioning together the LiveOut sets of all preds.
794
793
LocalLiveIn.clear ();
795
794
for (MachineBasicBlock *Pred : BB->predecessors ()) {
796
- LivenessMap::const_iterator I = BlockLiveness. find ( Pred) ;
795
+ BlockLifetimeInfo &PrefInfo = BlockLiveness[ Pred-> getNumber ()] ;
797
796
// PR37130: transformations prior to stack coloring can
798
797
// sometimes leave behind statically unreachable blocks; these
799
798
// can be safely skipped here.
800
- if (I != BlockLiveness. end ())
801
- LocalLiveIn |= I-> second .LiveOut ;
799
+ if (!PrefInfo. isEmpty ())
800
+ LocalLiveIn |= PrefInfo .LiveOut ;
802
801
}
803
802
804
803
// Compute LiveOut by subtracting out lifetimes that end in this
@@ -842,7 +841,7 @@ void StackColoring::calculateLiveIntervals(unsigned NumSlots) {
842
841
DefinitelyInUse.resize (NumSlots);
843
842
844
843
// Start the interval of the slots that we previously found to be 'in-use'.
845
- BlockLifetimeInfo &MBBLiveness = BlockLiveness[& MBB];
844
+ BlockLifetimeInfo &MBBLiveness = BlockLiveness[MBB. getNumber () ];
846
845
for (int pos = MBBLiveness.LiveIn .find_first (); pos != -1 ;
847
846
pos = MBBLiveness.LiveIn .find_next (pos)) {
848
847
Starts[pos] = Indexes->getMBBStartIdx (&MBB);
@@ -899,15 +898,14 @@ bool StackColoring::removeAllMarkers() {
899
898
Markers.clear ();
900
899
901
900
for (MachineBasicBlock &MBB : *MF) {
902
- if (BlockLiveness.contains (& MBB))
903
- continue ;
904
- for (MachineInstr &MI : make_early_inc_range (MBB)) {
905
- if ( MI.getOpcode () == TargetOpcode::LIFETIME_START ||
906
- MI. getOpcode () == TargetOpcode::LIFETIME_END) {
907
- Count++ ;
908
- MI. eraseFromParent ();
901
+ if (BlockLiveness.empty () || BlockLiveness[ MBB. getNumber ()]. isEmpty ( ))
902
+ for (MachineInstr &MI : make_early_inc_range (MBB)) {
903
+ if (MI. getOpcode () == TargetOpcode::LIFETIME_START ||
904
+ MI.getOpcode () == TargetOpcode::LIFETIME_END) {
905
+ Count++;
906
+ MI. eraseFromParent () ;
907
+ }
909
908
}
910
- }
911
909
}
912
910
913
911
LLVM_DEBUG (dbgs () << " Removed " << Count << " markers.\n " );
0 commit comments