[PATCH] D118601: [DebugInfo][InstrRef] Add a max-stack-slots-to-track limitation / cut-out

Jeremy Morse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 31 05:32:00 PST 2022


jmorse created this revision.
jmorse added reviewers: StephenTozer, Orlando, TWeaver.
Herald added subscribers: hiraditya, qcolombet.
jmorse requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Over in D116821 <https://reviews.llvm.org/D116821>, there's a reproducer that stimulates an interesting scenario in InstrRefBasedLDV: with thousands of local variables and asan enabled, the max working set (i.e. maximum number of values live at the same time) is very large, and get forced onto the stack. InstrRefBasedLDV tries to track all those variable locations, allocates some massive tables of values, and can then run out of memory (think ~6k values across 15k blocks -> massive allocations). This is undesirable.

I believe this kind of input is rare, because it's very unlikely that a developer is able to reason about thousands of live, named variables, concurrently while writing their software. Much more likely is that the input is autogenerated, or affected by some kind of instrumentation. In that scenario we should fail gracefully, by ceasing to track stack slots past a certain number: which is what this patch does. That puts an upper bound on the maximum working set that we try to track, and avoids un-necessarily crashing. The downside is that we might un-necessarily drop some variable locations, but the developer is probably happy with something rather than nothing.

This can certainly be improved so that the quality of data tracked degrades gracefully, however this is a starting point that avoids excessive consumption.

In terms of the patch, this adds a cl::opt for max number of stack slots to track, and has the stack-slot-numbering code optionally return None. That then filters through a number of code paths, which can then chose to not track a spill / restore if it touches an untracked spill slot. The added test checks that we drop variable locations that are on the stack, if we set the limit to zero.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118601

Files:
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
  llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
  llvm/test/DebugInfo/MIR/InstrRef/spill-slot-limits.mir
  llvm/unittests/CodeGen/InstrRefLDVTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118601.404491.patch
Type: text/x-patch
Size: 18679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220131/e0a6bef7/attachment.bin>


More information about the llvm-commits mailing list