[DWARF] Add cuttoff guarding quadratic validThroughout behaviour
authorJeremy Morse <jeremy.morse@sony.com>
Wed, 8 Jul 2020 09:01:14 +0000 (10:01 +0100)
committerJeremy Morse <jeremy.morse@sony.com>
Wed, 8 Jul 2020 09:30:09 +0000 (10:30 +0100)
commitb9d977b0ca60c54f11615ca9d144c9f08b29fd85
treea39b6941cfdb4d2ca877ceccfe0eadb6a88ecd04
parenta39c7ab9c355670510341191a802f3799265e9ef
[DWARF] Add cuttoff guarding quadratic validThroughout behaviour

Occasionally we see absolutely massive basic blocks, typically in global
constructors that are vulnerable to heavy inlining. When these blocks are
dense with DBG_VALUE instructions, we can hit near quadratic complexity in
DwarfDebug's validThroughout function. The problem is caused by:

  * validThroughout having to step through all instructions in the block to
    examine their lexical scope,
  * and a high proportion of instructions in that block being DBG_VALUEs
    for a unique variable fragment,

Leading to us stepping through every instruction in the block, for (nearly)
each instruction in the block.

By adding this guard, we force variables in large blocks to use a location
list rather than a single-location expression, as shown in the added test.
This shouldn't change the meaning of the output DWARF at all: instead we
use a less efficient DWARF encoding to avoid a poor-performance code path.

Differential Revision: https://reviews.llvm.org/D83236
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/test/DebugInfo/MIR/X86/singlelocation-cutoffs.mir [new file with mode: 0644]