Skip to content

Commit 6a69b4d

Browse files
committed
[CodeGen] Preserve LiveStack analysis in StackSlotColoring pass
For some target architectures, stack slot coloring pass may be invoked multiple times. It can occur due to the split of RA pass, opening up the opportunity to optimize stack slots usage at each RA invocation. In order to achieve that if we could keep stack analysis alive uptil the invocation of the RA pass for the last time, it will save up the overhead of recomputing live stack analysis after each RA. This requires it to be preserved at stack slot coloring pass which basically optimizes stack slots, but not makes the needed updates in live stack results. This has been achieved here.
1 parent cb1a727 commit 6a69b4d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ namespace {
149149
AU.addRequired<SlotIndexes>();
150150
AU.addPreserved<SlotIndexes>();
151151
AU.addRequired<LiveStacks>();
152+
AU.addPreserved<LiveStacks>();
152153
AU.addRequired<MachineBlockFrequencyInfo>();
153154
AU.addPreserved<MachineBlockFrequencyInfo>();
154155
AU.addPreservedID(MachineDominatorsID);
@@ -411,6 +412,23 @@ bool StackSlotColoring::ColorSlots(MachineFunction &MF) {
411412
}
412413
}
413414

415+
// In order to preserve LiveStack analysis, the live ranges for dead spill
416+
// stack slots would be merged with the live range of those stack slots that
417+
// now share the spill object of the mentioned dead stack slot.
418+
for (unsigned SS = 0, SE = SlotMapping.size(); SS != SE; ++SS) {
419+
int NewFI = SlotMapping[SS];
420+
if (SlotMapping[SS] == -1 || (NewFI == (int)SS)) {
421+
continue;
422+
}
423+
424+
LiveRange &lrToUpdateInto =
425+
static_cast<LiveRange &>(LS->getInterval(NewFI));
426+
const LiveRange &lrToUpdateFrom =
427+
static_cast<LiveRange &>(LS->getInterval((int)SS));
428+
lrToUpdateInto.MergeSegmentsInAsValue(lrToUpdateFrom,
429+
lrToUpdateInto.getValNumInfo(0));
430+
}
431+
414432
return true;
415433
}
416434

0 commit comments

Comments
 (0)