[PATCH] D101064: [WIP] improve debug-info in stack-slot-coloring
Markus Lavin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 28 02:28:16 PDT 2021
markus updated this revision to Diff 341102.
markus edited the summary of this revision.
markus added a comment.
Prototype of the 'terminate debug-info for slots when they go out of liveness, before being merged' idea in the TR.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101064/new/
https://reviews.llvm.org/D101064
Files:
llvm/lib/CodeGen/StackSlotColoring.cpp
Index: llvm/lib/CodeGen/StackSlotColoring.cpp
===================================================================
--- llvm/lib/CodeGen/StackSlotColoring.cpp
+++ llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -60,6 +60,7 @@
class StackSlotColoring : public MachineFunctionPass {
LiveStacks* LS;
+ SlotIndexes *Indexes;
MachineFrameInfo *MFI;
const TargetInstrInfo *TII;
const MachineBlockFrequencyInfo *MBFI;
@@ -72,6 +73,8 @@
// to be careful that renames like [FI0, FI1] -> [FI1, FI2] do not
// become FI0 -> FI1 -> FI2.
SmallVector<SmallVector<MachineMemOperand *, 8>, 16> SSRefs;
+ DenseMap<unsigned, SmallVector<MachineInstr *, 8>> SS2DbgValues;
+ DenseMap<unsigned, LiveInterval *> SS2LI;
// OrigAlignments - Alignments of stack objects before coloring.
SmallVector<Align, 16> OrigAlignments;
@@ -123,6 +126,7 @@
void RewriteInstruction(MachineInstr &MI, SmallVectorImpl<int> &SlotMapping,
MachineFunction &MF);
bool RemoveDeadStores(MachineBasicBlock* MBB);
+ void TerminateDbgForSlot(unsigned FI, LiveInterval *LI);
};
} // end anonymous namespace
@@ -303,6 +307,9 @@
Assignments[Color].push_back(li);
LLVM_DEBUG(dbgs() << "Assigning fi#" << FI << " to fi#" << Color << "\n");
+ if (FI != Color)
+ TerminateDbgForSlot(Color, SS2LI[Color]);
+
// Change size and alignment of the allocated slot. If there are multiple
// objects sharing the same slot, then make sure the size and alignment
// are large enough for all.
@@ -476,6 +483,24 @@
return changed;
}
+/// Terminate the DBG_VALUE(s) of variables residing in stack-slot with
+/// frame-index FI at the Segment.end points of LI.
+void StackSlotColoring::TerminateDbgForSlot(unsigned FI, LiveInterval *LI) {
+ for (auto &Seg : *LI) {
+ if (auto *SegEndMI = Indexes->getInstructionFromIndex(Seg.end)) {
+ for (auto *DbgValue : SS2DbgValues[FI]) {
+ auto ItMI = SegEndMI->getIterator();
+ BuildMI(*SegEndMI->getParent(), ItMI, DbgValue->getDebugLoc(),
+ TII->get(TargetOpcode::DBG_VALUE))
+ .addReg(0) // $noreg
+ .add(DbgValue->getOperand(1))
+ .add(DbgValue->getOperand(2))
+ .add(DbgValue->getOperand(3));
+ }
+ }
+ }
+}
+
bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
LLVM_DEBUG({
dbgs() << "********** Stack Slot Coloring **********\n"
@@ -489,6 +514,7 @@
TII = MF.getSubtarget().getInstrInfo();
LS = &getAnalysis<LiveStacks>();
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
+ Indexes = &getAnalysis<SlotIndexes>();
bool Changed = false;
@@ -507,6 +533,24 @@
// Gather spill slot references
ScanForSpillSlotRefs(MF);
InitializeSlots();
+
+ // Create mapping of SS -> LiveInterval.
+ for (unsigned i = 0; i < SSIntervals.size(); i++) {
+ LiveInterval *li = SSIntervals[i];
+ int SS = Register::stackSlot2Index(li->reg());
+ SS2LI[SS] = li;
+ }
+
+ // Create mapping of SS -> DBG_VALUE(s).
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : MBB) {
+ if (MI.isDebugValue() && MI.getOperand(0).isFI()) {
+ auto SS = MI.getOperand(0).getIndex();
+ SS2DbgValues[SS].push_back(&MI);
+ }
+ }
+ }
+
Changed = ColorSlots(MF);
for (int &Next : NextColors)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101064.341102.patch
Type: text/x-patch
Size: 3357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210428/cf84a2dc/attachment.bin>
More information about the llvm-commits
mailing list