aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/LiveDebugValues.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2020-05-27 13:22:10 -0700
committerVedant Kumar <vsk@apple.com>2020-05-28 13:53:40 -0700
commitd11155d273af00f75c2b40a5ca3007463f9808c1 (patch)
tree6b885a04e2169c970a46657cc425623e504b6726 /llvm/lib/CodeGen/LiveDebugValues.cpp
parent4855534d10cea3dd93d33da13ceb3381b0c588e6 (diff)
downloadllvm-d11155d273af00f75c2b40a5ca3007463f9808c1.zip
llvm-d11155d273af00f75c2b40a5ca3007463f9808c1.tar.gz
llvm-d11155d273af00f75c2b40a5ca3007463f9808c1.tar.bz2
[LiveDebugValues] Add cutoffs to avoid pathological behavior
Summary: We received a report of LiveDebugValues consuming 25GB+ of RAM when compiling code generated by Unity's IL2CPP scripting backend. There's an initial 5GB spike due to repeatedly copying cached lists of MachineBasicBlocks within the UserValueScopes members of VarLocs. But the larger scaling issue arises due to the fact that prior to range extension, there are 81K basic blocks and 156K DBG_VALUEs: given enough memory, LiveDebugValues would insert 101 million MIs (I counted this by incrementing a counter inside of VarLoc::BuildDbgValue). It seems like LiveDebugValues would have to be rearchitected to support this kind of input (we'd need some new represntation for DBG_VALUEs that get inserted into ~every block via flushPendingLocs). OTOH, large globs of auto-generated code are typically not debugged interactively. So: add cutoffs to disable range extension when the input is too big. I chose the cutoffs experimentally, erring on the conservative side. When compiling a large collection of Apple software, range extension never got disabled. rdar://63418929 Reviewers: aprantl, friss, jmorse, Orlando Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80662
Diffstat (limited to 'llvm/lib/CodeGen/LiveDebugValues.cpp')
-rw-r--r--llvm/lib/CodeGen/LiveDebugValues.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/LiveDebugValues.cpp b/llvm/lib/CodeGen/LiveDebugValues.cpp
index 00a6149a..2d11a23 100644
--- a/llvm/lib/CodeGen/LiveDebugValues.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues.cpp
@@ -81,6 +81,18 @@ using namespace llvm;
STATISTIC(NumInserted, "Number of DBG_VALUE instructions inserted");
STATISTIC(NumRemoved, "Number of DBG_VALUE instructions removed");
+// Options to prevent pathological compile-time behavior. If InputBBLimit and
+// InputDbgValueLimit are both exceeded, range extension is disabled.
+static cl::opt<unsigned> InputBBLimit(
+ "livedebugvalues-input-bb-limit",
+ cl::desc("Maximum input basic blocks before DBG_VALUE limit applies"),
+ cl::init(10000), cl::Hidden);
+static cl::opt<unsigned> InputDbgValueLimit(
+ "livedebugvalues-input-dbg-value-limit",
+ cl::desc(
+ "Maximum input DBG_VALUE insts supported by debug range extension"),
+ cl::init(50000), cl::Hidden);
+
// If @MI is a DBG_VALUE with debug value described by a defined
// register, returns the number of this register. In the other case, returns 0.
static Register isDbgValueDescribedByReg(const MachineInstr &MI) {
@@ -1753,6 +1765,22 @@ bool LiveDebugValues::ExtendRanges(MachineFunction &MF) {
Worklist.push(RPONumber);
++RPONumber;
}
+
+ if (RPONumber > InputBBLimit) {
+ unsigned NumInputDbgValues = 0;
+ for (auto &MBB : MF)
+ for (auto &MI : MBB)
+ if (MI.isDebugValue())
+ ++NumInputDbgValues;
+ if (NumInputDbgValues > InputDbgValueLimit) {
+ LLVM_DEBUG(dbgs() << "Disabling LiveDebugValues: " << MF.getName()
+ << " has " << RPONumber << " basic blocks and "
+ << NumInputDbgValues
+ << " input DBG_VALUEs, exceeding limits.\n");
+ return false;
+ }
+ }
+
// This is a standard "union of predecessor outs" dataflow problem.
// To solve it, we perform join() and process() using the two worklist method
// until the ranges converge.