<div dir="ltr">+pcc, who had some other ideas/patch out for improving memory usage of debug info<br>+Reid, who's responsible for the windows/CodeView/PDB debug info which is motivating some of the ideas about changes to type emission<br><br>So how does this relate, or not, to Peter's (pcc) work trying to reduce the DIE overhead during code gen? Are you folks chasing different memory bottlenecks? Are they both relevant (perhaps in different scenarios)?<br><br>Baking into the IR more about types as units has pretty direct overlap with Reid/CodeView/etc - so, yeah, that'll takes ome discussion (but, as you say, it's not in your immediate plan anyway, so we can come back to that - but would be good for whoever gets there first to discuss it with the others)</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 22, 2016 at 7:28 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have some ideas to allow the BitcodeReader to lazy-load debug info<br>
metadata, and wanted to air this on llvm-dev before getting too deep<br>
into the code.<br>
<br>
Motivation<br>
==========<br>
<br>
Based on some analysis Mehdi ran (ping him for details), there are three<br>
(related) compile-time bottlenecks we're seeing with `-flto=thin -g`:<br>
<br>
a) Reading the large number of Metadata bitcode records in the global<br>
metadata block. I'm talking about raw `BitStreamer` calls here.<br>
<br>
b) Creating unnecessary `DI*` instances (that aren't relevant to code).<br>
<br>
c) Emitting unnecessary `DI*` instances (that aren't relevant to code).<br>
<br>
Here is my recollection of some peak memory stats on a small testcase<br>
during thin-LTO, which should be a decent indicator of (b):<br>
<br>
- ~150MB: DILocation<br>
- ~100MB: DISubprogram<br>
- ~70MB: DILocalVariable<br>
- ~50MB: (cumulative) DIType descendents<br>
<br>
It looks, suprisingly, like types are not the primary bottleneck.<br>
<br>
There are caveats:<br>
<br>
- `DISubprogram` declarations -- member function descriptors -- are<br>
part of the type hierarchy.<br>
- Most of the type hierarchy gets uniqued at parse time.<br>
- As a result, these data are a poor indicator for (a).<br>
<br>
Even so, non-types are substantial.<br>
<br>
Related work<br>
============<br>
<br>
Teresa has some post-processing in-place/in-review to avoid importing<br>
metadata unnecessarily, but IIUC: it won't address (a) and (b), only<br>
(c) (maybe I'm wrong?); and it only helps -flto=thin, not other<br>
lazy-loaders.<br>
<br>
I heard a rumour that Eric has a grand plan to factor away the type<br>
hierarchy -- awesome if true -- but I think most of this is worthwhile<br>
regardless.<br>
<br>
Proposal<br>
========<br>
<br>
Short version<br>
-------------<br>
<br>
1. Serialize metadata in Function blocks where possible.<br>
2. Reverse the `DISubprogram`/`DICompileUnit` link.<br>
3. Create a `METADATA_SUBPROGRAM_BLOCK`.<br>
<br>
Type-related work Eric will make unnecessary if he's fast:<br>
<br>
4. Remove `DICompositeType`s from `retainedTypes:`, similar to (2).<br>
5. Create a `METADATA_COMPOSITE_TYPE_BLOCK`, similar to (3).<br>
<br>
Long version<br>
------------<br>
<br>
1. If a piece of metadata is referenced from only a single `Function`,<br>
serialize that metadata in the function's metadata block instead of<br>
the global metadata block.<br>
<br>
This addresses problems (a) and (b), primarily targeting<br>
`DILocation`s. It should pick up lots of other stuff, depending on<br>
how much inlining has happened.<br>
<br>
(I have a draft of the writer side, still working on the reader.)<br>
<br>
2. Reverse the `DISubprogram`/`DICompileUnit` link (David and I have<br>
talked about this in the past in barely-related threads). The<br>
direct effect is that subprograms that are not pointed at by any<br>
code (!dbg attachments or @llvm.dbg.value intrinsics) get dropped.<br>
<br>
This addresses problem (c). If a consumer is only linking/loading a<br>
subset of a module's functions, this naturally filters subprograms<br>
to the relevant ones. Also, with limited inlining (and assuming<br>
(1)), it addresses problems (a) and (b), too.<br>
<br>
Adrian volunteered to implement this and is apparently almost ready<br>
to post a patch (still working on testcase update script logic I<br>
believe (probably other details, don't let me oversell it)).<br>
<br>
3. Create a special `METADATA_SUBPROGRAM_BLOCK` for each `DISubprogram`<br>
in the global metadata block. Store the relevant `DISubprogram` and<br>
all of the subprogram's `DILexicalBlock`s and `DILocalVariable`s.<br>
The block can be lazy-loaded on an all-or-nothing basis.<br>
<br>
In combination with (2), this addresses (a) and (b) in cases that<br>
(1) doesn't catch. A lazy-loading module will only load the<br>
subprogram blocks that get referenced.<br>
<br>
(I have a basic design for this that accounts for references into<br>
the middle of block; I'll see what happens when I flesh it out.)<br>
<br>
I think this will solve the non-type bottlenecks.<br>
<br>
If Eric hasn't solved types by then, we can do similar things to the IR<br>
for the debug info type hierarchy.<br>
<br>
4. Implement my proposal to remove the `DICompositeType` name map from<br>
`retainedTypes:`.<br>
<br>
<a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160125/327936.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160125/327936.html</a><br>
<br>
Similar to (2) above, this will naturally filter the types that get<br>
linked in to the ones actually used by the code being linked.<br>
<br>
It should also allow the reader to skip records for types that have<br>
already been loaded in the main module.<br>
<br>
5. Create a special `METADATA_COMPOSITE_TYPE_BLOCK`, similar to (3) but<br>
for composite types and their members. This avoids the raw bitcode<br>
reading overhead. (This is totally undesigned at this point.)<br>
<br>
<br>
</blockquote></div><br></div>