Skip to content

Commit c44d528

Browse files
[StackColoring] Declare BitVector outside the loop (#95688)
The StackColoring pass creates two instances of BitVector per basic block until the fixed point is reached. Each instance may involve a heap allocation depending on its size. This patch declares them outside the loop, saving 1.40% of heap allocations during the compilation of CGBuiltin.cpp.ii, a preprocessed version of CGBuiltin.cpp.
1 parent a74a86c commit c44d528

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/CodeGen/StackColoring.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,10 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
773773
void StackColoring::calculateLocalLiveness() {
774774
unsigned NumIters = 0;
775775
bool changed = true;
776+
// Create BitVector outside the loop and reuse them to avoid repeated heap
777+
// allocations.
778+
BitVector LocalLiveIn;
779+
BitVector LocalLiveOut;
776780
while (changed) {
777781
changed = false;
778782
++NumIters;
@@ -784,7 +788,7 @@ void StackColoring::calculateLocalLiveness() {
784788
BlockLifetimeInfo &BlockInfo = BI->second;
785789

786790
// Compute LiveIn by unioning together the LiveOut sets of all preds.
787-
BitVector LocalLiveIn;
791+
LocalLiveIn.clear();
788792
for (MachineBasicBlock *Pred : BB->predecessors()) {
789793
LivenessMap::const_iterator I = BlockLiveness.find(Pred);
790794
// PR37130: transformations prior to stack coloring can
@@ -801,7 +805,7 @@ void StackColoring::calculateLocalLiveness() {
801805
// because we already handle the case where the BEGIN comes
802806
// before the END when collecting the markers (and building the
803807
// BEGIN/END vectors).
804-
BitVector LocalLiveOut = LocalLiveIn;
808+
LocalLiveOut = LocalLiveIn;
805809
LocalLiveOut.reset(BlockInfo.End);
806810
LocalLiveOut |= BlockInfo.Begin;
807811

0 commit comments

Comments
 (0)