Skip to content

Commit 708cbda

Browse files
committed
[DebugInfo][InstrRef] Honour too-much-debug-info cutouts
This reapplies 54a61c9, its follow up in 547b712, which were reverted 95fe61e. Original commit message: VarLoc based LiveDebugValues will abandon variable location propagation if there are too many blocks and variable assignments in the function. If it didn't, and we had (say) 1000 blocks and 1000 variables in scope, we'd end up with 1 million DBG_VALUEs just at the start of blocks. Instruction-referencing LiveDebugValues should honour this limitation too (because the same limitation applies to it). Hoist the relevant command line options into LiveDebugValues.cpp and pass it down into the implementation classes as an argument to ExtendRanges. I've duplicated all the run-lines in live-debug-values-cutoffs.mir to have an instruction-referencing flavour. Differential Revision: https://reviews.llvm.org/D107823
1 parent 895ed64 commit 708cbda

File tree

5 files changed

+79
-36
lines changed

5 files changed

+79
-36
lines changed

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,8 @@ class InstrRefBasedLDV : public LDVImpl {
16841684
/// RPOT block ordering.
16851685
void initialSetup(MachineFunction &MF);
16861686

1687-
bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) override;
1687+
bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC,
1688+
unsigned InputBBLimit, unsigned InputDbgValLimit) override;
16881689

16891690
public:
16901691
/// Default construct and initialize the pass.
@@ -3523,8 +3524,9 @@ void InstrRefBasedLDV::initialSetup(MachineFunction &MF) {
35233524

35243525
/// Calculate the liveness information for the given machine function and
35253526
/// extend ranges across basic blocks.
3526-
bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
3527-
TargetPassConfig *TPC) {
3527+
bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC,
3528+
unsigned InputBBLimit,
3529+
unsigned InputDbgValLimit) {
35283530
// No subprogram means this function contains no debuginfo.
35293531
if (!MF.getFunction().getSubprogram())
35303532
return false;
@@ -3626,6 +3628,7 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
36263628

36273629
// To mirror old LiveDebugValues, enumerate variables in RPOT order. Otherwise
36283630
// the order is unimportant, it just has to be stable.
3631+
unsigned VarAssignCount = 0;
36293632
for (unsigned int I = 0; I < OrderToBB.size(); ++I) {
36303633
auto *MBB = OrderToBB[I];
36313634
auto *VTracker = &vlocs[MBB->getNumber()];
@@ -3643,34 +3646,49 @@ bool InstrRefBasedLDV::ExtendRanges(MachineFunction &MF,
36433646
ScopeToVars[Scope].insert(Var);
36443647
ScopeToBlocks[Scope].insert(VTracker->MBB);
36453648
ScopeToDILocation[Scope] = ScopeLoc;
3649+
++VarAssignCount;
36463650
}
36473651
}
36483652

3649-
// OK. Iterate over scopes: there might be something to be said for
3650-
// ordering them by size/locality, but that's for the future. For each scope,
3651-
// solve the variable value problem, producing a map of variables to values
3652-
// in SavedLiveIns.
3653-
for (auto &P : ScopeToVars) {
3654-
vlocDataflow(P.first, ScopeToDILocation[P.first], P.second,
3655-
ScopeToBlocks[P.first], SavedLiveIns, MOutLocs, MInLocs,
3656-
vlocs);
3657-
}
3653+
bool Changed = false;
3654+
3655+
// If we have an extremely large number of variable assignments and blocks,
3656+
// bail out at this point. We've burnt some time doing analysis already,
3657+
// however we should cut our losses.
3658+
if ((unsigned)MaxNumBlocks > InputBBLimit &&
3659+
VarAssignCount > InputDbgValLimit) {
3660+
LLVM_DEBUG(dbgs() << "Disabling InstrRefBasedLDV: " << MF.getName()
3661+
<< " has " << MaxNumBlocks << " basic blocks and "
3662+
<< VarAssignCount
3663+
<< " variable assignments, exceeding limits.\n");
3664+
} else {
3665+
// Compute the extended ranges, iterating over scopes. There might be
3666+
// something to be said for ordering them by size/locality, but that's for
3667+
// the future. For each scope, solve the variable value problem, producing
3668+
// a map of variables to values in SavedLiveIns.
3669+
for (auto &P : ScopeToVars) {
3670+
vlocDataflow(P.first, ScopeToDILocation[P.first], P.second,
3671+
ScopeToBlocks[P.first], SavedLiveIns, MOutLocs, MInLocs,
3672+
vlocs);
3673+
}
3674+
3675+
// Using the computed value locations and variable values for each block,
3676+
// create the DBG_VALUE instructions representing the extended variable
3677+
// locations.
3678+
emitLocations(MF, SavedLiveIns, MOutLocs, MInLocs, AllVarsNumbering, *TPC);
36583679

3659-
// Using the computed value locations and variable values for each block,
3660-
// create the DBG_VALUE instructions representing the extended variable
3661-
// locations.
3662-
emitLocations(MF, SavedLiveIns, MOutLocs, MInLocs, AllVarsNumbering, *TPC);
3680+
// Did we actually make any changes? If we created any DBG_VALUEs, then yes.
3681+
Changed = TTracker->Transfers.size() != 0;
3682+
}
36633683

3684+
// Common clean-up of memory.
36643685
for (int Idx = 0; Idx < MaxNumBlocks; ++Idx) {
36653686
delete[] MOutLocs[Idx];
36663687
delete[] MInLocs[Idx];
36673688
}
36683689
delete[] MOutLocs;
36693690
delete[] MInLocs;
36703691

3671-
// Did we actually make any changes? If we created any DBG_VALUEs, then yes.
3672-
bool Changed = TTracker->Transfers.size() != 0;
3673-
36743692
delete MTracker;
36753693
delete TTracker;
36763694
MTracker = nullptr;

llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ static cl::opt<bool>
4040
"normal DBG_VALUE inputs"),
4141
cl::init(false));
4242

43+
// Options to prevent pathological compile-time behavior. If InputBBLimit and
44+
// InputDbgValueLimit are both exceeded, range extension is disabled.
45+
static cl::opt<unsigned> InputBBLimit(
46+
"livedebugvalues-input-bb-limit",
47+
cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
48+
cl::init(10000), cl::Hidden);
49+
static cl::opt<unsigned> InputDbgValueLimit(
50+
"livedebugvalues-input-dbg-value-limit",
51+
cl::desc(
52+
"Maximum input DBG_VALUE insts supported by debug range extension"),
53+
cl::init(50000), cl::Hidden);
54+
4355
/// Generic LiveDebugValues pass. Calls through to VarLocBasedLDV or
4456
/// InstrRefBasedLDV to perform location propagation, via the LDVImpl
4557
/// base class.
@@ -103,5 +115,5 @@ bool LiveDebugValues::runOnMachineFunction(MachineFunction &MF) {
103115
TheImpl = llvm::makeVarLocBasedLiveDebugValues();
104116
}
105117

106-
return TheImpl->ExtendRanges(MF, TPC);
118+
return TheImpl->ExtendRanges(MF, TPC, InputBBLimit, InputDbgValueLimit);
107119
}

llvm/lib/CodeGen/LiveDebugValues/LiveDebugValues.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ inline namespace SharedLiveDebugValues {
2323
// implementation.
2424
class LDVImpl {
2525
public:
26-
virtual bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) = 0;
26+
virtual bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC,
27+
unsigned InputBBLimit,
28+
unsigned InputDbgValLimit) = 0;
2729
virtual ~LDVImpl() {}
2830
};
2931

llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,6 @@ using namespace llvm;
166166

167167
STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
168168

169-
// Options to prevent pathological compile-time behavior. If InputBBLimit and
170-
// InputDbgValueLimit are both exceeded, range extension is disabled.
171-
static cl::opt<unsigned> InputBBLimit(
172-
"livedebugvalues-input-bb-limit",
173-
cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
174-
cl::init(10000), cl::Hidden);
175-
static cl::opt<unsigned> InputDbgValueLimit(
176-
"livedebugvalues-input-dbg-value-limit",
177-
cl::desc(
178-
"Maximum input DBG_VALUE insts supported by debug range extension"),
179-
cl::init(50000), cl::Hidden);
180-
181169
/// If \p Op is a stack or frame register return true, otherwise return false.
182170
/// This is used to avoid basing the debug entry values on the registers, since
183171
/// we do not support it at the moment.
@@ -1007,7 +995,8 @@ class VarLocBasedLDV : public LDVImpl {
1007995
/// had their instruction creation deferred.
1008996
void flushPendingLocs(VarLocInMBB &PendingInLocs, VarLocMap &VarLocIDs);
1009997

1010-
bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) override;
998+
bool ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC,
999+
unsigned InputBBLimit, unsigned InputDbgValLimit) override;
10111000

10121001
public:
10131002
/// Default construct and initialize the pass.
@@ -2048,7 +2037,9 @@ void VarLocBasedLDV::recordEntryValue(const MachineInstr &MI,
20482037

20492038
/// Calculate the liveness information for the given machine function and
20502039
/// extend ranges across basic blocks.
2051-
bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) {
2040+
bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC,
2041+
unsigned InputBBLimit,
2042+
unsigned InputDbgValLimit) {
20522043
LLVM_DEBUG(dbgs() << "\nDebug Range Extension\n");
20532044

20542045
if (!MF.getFunction().getSubprogram())
@@ -2141,7 +2132,7 @@ bool VarLocBasedLDV::ExtendRanges(MachineFunction &MF, TargetPassConfig *TPC) {
21412132
for (auto &MI : MBB)
21422133
if (MI.isDebugValue())
21432134
++NumInputDbgValues;
2144-
if (NumInputDbgValues > InputDbgValueLimit) {
2135+
if (NumInputDbgValues > InputDbgValLimit) {
21452136
LLVM_DEBUG(dbgs() << "Disabling VarLocBasedLDV: " << MF.getName()
21462137
<< " has " << RPONumber << " basic blocks and "
21472138
<< NumInputDbgValues

llvm/test/DebugInfo/MIR/X86/live-debug-values-cutoffs.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@
55
# RUN: -livedebugvalues-input-bb-limit=1 \
66
# RUN: -livedebugvalues-input-dbg-value-limit=1 \
77
# RUN: | FileCheck %s -check-prefix=LDV-DISABLED
8+
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
9+
# RUN: -experimental-debug-variable-locations \
10+
# RUN: -livedebugvalues-input-bb-limit=1 \
11+
# RUN: -livedebugvalues-input-dbg-value-limit=1 \
12+
# RUN: | FileCheck %s -check-prefix=LDV-DISABLED
813

914
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
1015
# RUN: -livedebugvalues-input-bb-limit=1 \
1116
# RUN: -livedebugvalues-input-dbg-value-limit=10 \
1217
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
18+
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
19+
# RUN: -experimental-debug-variable-locations \
20+
# RUN: -livedebugvalues-input-bb-limit=1 \
21+
# RUN: -livedebugvalues-input-dbg-value-limit=10 \
22+
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
1323

1424
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
1525
# RUN: -livedebugvalues-input-bb-limit=10 \
1626
# RUN: -livedebugvalues-input-dbg-value-limit=1 \
1727
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
28+
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
29+
# RUN: -experimental-debug-variable-locations \
30+
# RUN: -livedebugvalues-input-bb-limit=10 \
31+
# RUN: -livedebugvalues-input-dbg-value-limit=1 \
32+
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
1833

1934
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
2035
# RUN: -livedebugvalues-input-bb-limit=10 \
2136
# RUN: -livedebugvalues-input-dbg-value-limit=10 \
2237
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
38+
# RUN: llc %s -o - -run-pass=livedebugvalues -mtriple=x86_64-unknown-unknown \
39+
# RUN: -experimental-debug-variable-locations \
40+
# RUN: -livedebugvalues-input-bb-limit=10 \
41+
# RUN: -livedebugvalues-input-dbg-value-limit=10 \
42+
# RUN: | FileCheck %s -check-prefix=LDV-ENABLED
2343

2444
# LDV-DISABLED-LABEL: bb.1.exit
2545
# LDV-DISABLED-NEXT: $edi = MOV32rm

0 commit comments

Comments
 (0)