Contrary to the old LiveDebugVariables pass LiveDebugValues currently doesn't look at the lexical scopes before inserting a DBG_VALUE intrinsic. This means that we often propagate DBG_VALUEs much further down than necessary. This is especially noticeable in large C++ functions with many inlined method calls that all use the same "this"-pointer.
For example, in the following code it makes no sense to propagate the inlined variable a from the first inlined call to f() into any of the subsequent basic blocks, because the variable will always be out of scope:
void sink(int a); void __attribute((always_inline)) f(int a) { sink(a); } void foo(int i) { f(i); if (i) f(i); f(i); }
This patch reuses the LexicalScopes infrastructure we have for LiveDebugVariables to take this into account. (I will commit a separate patch to rip out the now dead use of LexicalScopes from LiveDebugVariables.)
The effect on compile time and memory consumption is quite noticeable :-)
I have a benchmark that is a large C++ source with an enormous amount of inlined "this"-pointers that would previously eat >24GiB (most of them for DBG_VALUE intrinsics) and whose compile time was dominated by LiveDebugValues. With this patch applied the memory consumption is 1GiB and 1.7% of the time is spent in LiveDebugValues.
Note that this is N^2 as called in a bunch of cases, because each dominates call will iterate over all instructions in the mbb (at least, it looks like it is calling bool LexicalScopes::dominates(const DILocation *DL, MachineBasicBlock *MBB). If not, ignore this)
This is fixable, however:
(or LRU cache any of the above if you are concerned about space cost).