Skip to content

Commit dc21436

Browse files
committed
[CodeGen] Preserved additional analyses in StackSlotColoring pass.
The pass pipeline of some architecture splits register allocation phase based on different register classes. As some analyses need to be computed at the beginning of the register allocation and kept alive till all values are assigned to some physical registers. This poses challenge with objective of introducing StackSlotColoring after partial virtual registers are assigned to physical registers, in order to optimize stack slots usage.As this pass doesn't preserve few analysis yet to be needed by the register allocation of the remaining virtual registers, necessiating them to be kept preserved.
1 parent 2655897 commit dc21436

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

llvm/lib/CodeGen/StackSlotColoring.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/BitVector.h"
1414
#include "llvm/ADT/SmallVector.h"
1515
#include "llvm/ADT/Statistic.h"
16+
#include "llvm/CodeGen/LiveDebugVariables.h"
1617
#include "llvm/CodeGen/LiveInterval.h"
1718
#include "llvm/CodeGen/LiveIntervalUnion.h"
1819
#include "llvm/CodeGen/LiveIntervals.h"
@@ -64,6 +65,7 @@ namespace {
6465
MachineFrameInfo *MFI = nullptr;
6566
const TargetInstrInfo *TII = nullptr;
6667
const MachineBlockFrequencyInfo *MBFI = nullptr;
68+
SlotIndexes *Indexes = nullptr;
6769

6870
// SSIntervals - Spill slot intervals.
6971
std::vector<LiveInterval*> SSIntervals;
@@ -152,6 +154,14 @@ namespace {
152154
AU.addRequired<MachineBlockFrequencyInfo>();
153155
AU.addPreserved<MachineBlockFrequencyInfo>();
154156
AU.addPreservedID(MachineDominatorsID);
157+
158+
// As in some Target's pipeline, register allocation (RA) might be
159+
// splitted into multiple phases based on register class. So, this pass
160+
// may be invoked multiple times requiring it to save these analyses to be
161+
// used by RA later.
162+
AU.addPreserved<LiveIntervals>();
163+
AU.addPreserved<LiveDebugVariables>();
164+
155165
MachineFunctionPass::getAnalysisUsage(AU);
156166
}
157167

@@ -496,8 +506,10 @@ bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
496506
++I;
497507
}
498508

499-
for (MachineInstr *MI : toErase)
509+
for (MachineInstr *MI : toErase) {
500510
MI->eraseFromParent();
511+
Indexes->removeMachineInstrFromMaps(*MI);
512+
}
501513

502514
return changed;
503515
}
@@ -515,6 +527,7 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
515527
TII = MF.getSubtarget().getInstrInfo();
516528
LS = &getAnalysis<LiveStacks>();
517529
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
530+
Indexes = &getAnalysis<SlotIndexes>();
518531

519532
bool Changed = false;
520533

0 commit comments

Comments
 (0)