Skip to content

Commit 41206b6

Browse files
committed
[DebugInfo] Re-instate LiveDebugVariables scope trimming
This patch reverts part of r362750 / D62650, which stopped LiveDebugVariables from trimming leading variable location ranges down to only covering those instructions that are in scope. I've observed some circumstances where the number of DBG_VALUEs in a function can be amplified in an un-necessary way, to cover more instructions that are out of scope, leading to very slow compile times. Trimming the range of instructions that the variables cover solves the slow compile times. The specific problem that r362750 tries to fix is addressed by the assignment to RStart that I've added. Any variable location that begins at the first instruction of a block will now be considered to begin at the start of the block. While these sound the same, the have different SlotIndexes, and the register allocator may shoehorn additional instructions in between the two. The test added in the past (wrong_debug_loc_after_regalloc.ll) still works with this modification. live-debug-variables.ll has a range trimmed to not cover the prologue of the function, while dbg-addr-dse.ll has a DBG_VALUE sink past one instruction with no DebugLoc, which is expected behaviour. Differential Revision: https://reviews.llvm.org/D73691
1 parent 65b3b6c commit 41206b6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

llvm/lib/CodeGen/LiveDebugVariables.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ class UserValue {
166166
/// Map of slot indices where this value is live.
167167
LocMap locInts;
168168

169+
/// Set of interval start indexes that have been trimmed to the
170+
/// lexical scope.
171+
SmallSet<SlotIndex, 2> trimmedDefs;
172+
169173
/// Insert a DBG_VALUE into MBB at Idx for LocNo.
170174
void insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx,
171175
SlotIndex StopIdx, DbgValueLocation Loc, bool Spilled,
@@ -910,6 +914,11 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
910914
SlotIndex RStart = LIS.getInstructionIndex(*Range.first);
911915
SlotIndex REnd = LIS.getInstructionIndex(*Range.second);
912916

917+
// Variable locations at the first instruction of a block should be
918+
// based on the block's SlotIndex, not the first instruction's index.
919+
if (Range.first == Range.first->getParent()->begin())
920+
RStart = LIS.getSlotIndexes()->getIndexBefore(*Range.first);
921+
913922
// At the start of each iteration I has been advanced so that
914923
// I.stop() >= PrevEnd. Check for overlap.
915924
if (PrevEnd && I.start() < PrevEnd) {
@@ -922,7 +931,8 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
922931
++I;
923932

924933
// If the interval also overlaps the start of the "next" (i.e.
925-
// current) range create a new interval for the remainder
934+
// current) range create a new interval for the remainder (which
935+
// may be further trimmed).
926936
if (RStart < IStop)
927937
I.insert(RStart, IStop, Loc);
928938
}
@@ -932,6 +942,13 @@ void UserValue::computeIntervals(MachineRegisterInfo &MRI,
932942
if (!I.valid())
933943
return;
934944

945+
if (I.start() < RStart) {
946+
// Interval start overlaps range - trim to the scope range.
947+
I.setStartUnchecked(RStart);
948+
// Remember that this interval was trimmed.
949+
trimmedDefs.insert(RStart);
950+
}
951+
935952
// The end of a lexical scope range is the last instruction in the
936953
// range. To convert to an interval we need the index of the
937954
// instruction after it.
@@ -1345,6 +1362,12 @@ void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
13451362
bool Spilled = SpillIt != SpillOffsets.end();
13461363
unsigned SpillOffset = Spilled ? SpillIt->second : 0;
13471364

1365+
// If the interval start was trimmed to the lexical scope insert the
1366+
// DBG_VALUE at the previous index (otherwise it appears after the
1367+
// first instruction in the range).
1368+
if (trimmedDefs.count(Start))
1369+
Start = Start.getPrevIndex();
1370+
13481371
LLVM_DEBUG(dbgs() << "\t[" << Start << ';' << Stop << "):" << Loc.locNo());
13491372
MachineFunction::iterator MBB = LIS.getMBBFromIndex(Start)->getIterator();
13501373
SlotIndex MBBEnd = LIS.getMBBEndIdx(&*MBB);

llvm/test/DebugInfo/X86/dbg-addr-dse.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ entry:
5050
}
5151

5252
; ASM-LABEL: f: # @f
53-
; ASM: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X:[0-9]+]], DW_OP_deref] $rsp
54-
; ASM: movl %ecx, [[OFF_X]](%rsp)
53+
; ASM: movl %ecx, [[OFF_X:[0-9]+]](%rsp)
54+
; ASM: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]], DW_OP_deref] $rsp
5555
; ASM: callq escape
5656
; ASM: #DEBUG_VALUE: f:x <- 1
5757
; ASM: movl $1, global(%rip)

llvm/test/DebugInfo/X86/live-debug-variables.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
; CHECK: .debug_loc contents:
2626
; CHECK-NEXT: 0x00000000:
2727
; We currently emit an entry for the function prologue, too, which could be optimized away.
28-
; CHECK: (0x0000000000000010, 0x0000000000000072): DW_OP_reg3 RBX
28+
; CHECK: (0x0000000000000018, 0x0000000000000072): DW_OP_reg3 RBX
2929
; We should only have one entry inside the function.
3030
; CHECK-NOT: :
3131

0 commit comments

Comments
 (0)