<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 29, 2016 at 8:11 PM Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 29, 2016 at 7:43 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Tue, Mar 29, 2016 at 7:31 PM Peter Collingbourne <<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Thanks for sharing this. Mostly seems like a reasonable plan to me. A few comments below.</div><div class="gmail_quote"><br></div></div></div></blockquote><div><br></div></span><div>Thanks Peter!</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"></div><div class="gmail_quote"></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 29, 2016 at 6:00 PM, Eric Christopher via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Hi All,</div><div><br></div><div>This is something that's been talked about for some time and it's probably time to propose it.</div><div><br></div><div>The "We" in this document is everyone on the cc line plus me.</div><div><br></div><div>Please go ahead and take a look.</div><div><br></div><div>Thanks!</div><div><br></div><div>-eric</div><div><br></div><div><br></div><div>Objective (and TL;DR)<br></div><div>=================</div><div><br></div><div>Migrate debug type information generation from the backends to the front end.</div><div><br></div><div>This will enable:</div><div>1. Separation of concerns and maintainability: LLVM shouldn’t have to know about C preprocessor macros, Obj-C properties, or extensive details about debug information binary formats.</div><div>2. Performance: Skipping a serialization should speed up normal compilations.</div><div>3. Memory usage: The DI metadata structures are smaller than they were, but are still fairly large and pointer heavy.</div><div><br></div><div>Motivation</div><div>========</div><div><br></div><div>Currently, types in LLVM debug info are described by the DIType class hierarchy. This hierarchy evolved organically from a more flexible sea-of-nodes representation into what it is today - a large, only somewhat format neutral representation of debug types. Making this more format neutral will only increase the memory use - and for no reason as type information is static (or nearly so). Debug formats already have a memory efficient serialization, their own binary format so we should support a front end emitting type information with sufficient representation to allow the backend to emit debug information based on the more normal IR features: functions, scopes, variables, etc.</div><div><br></div><div>Scope/Impact</div><div>===========</div><div><br></div><div>This is going to involve large scale changes across both LLVM and clang. This will also affect any out-of-tree front ends, however, we expect the impact to be on the order of a large API change rather than needing massive infrastructure changes.</div><div><br></div><div>Related work</div><div>==========</div><div><br></div><div>This is related to the efforts to support CodeView in LLVM and clang as well as efforts to reduce overall memory consumption when compiling with debug information enabled;  in particular efforts to prune LTO memory usage.</div><div><br></div><div><br></div><div>Concerns</div><div>========</div><div><br></div><div><br></div><div>We need a good story for transitioning all the debug info testcases in the backend without giving up coverage and/or readability. David believes he has a plan here.</div><div><br></div><div>Proposal</div><div>=======</div><div><br></div><div>Short version</div><div>-----------------</div><div><br></div><div>1. Split the DIBuilder API into Types (+Macros, Imports, …) and Line Table.</div><div>2. Split the clang CGDebugInfo API into Types and Line Table to match.</div><div>3. Add a LLVM DWARF emission library similar to the existing CodeView one.</div><div>4. Migrate the Types API into a clang internal API taking clang AST structures and use the LLVM binary emission libraries to produce type information.</div><div>5. Remove the old binary emission out of LLVM.</div><div><br></div><div><br></div><div>Questions/Thoughts/Elaboration</div><div>-------------------------------------------</div><div><br></div><div>Splitting the DIBuilder API</div><div>~~~~~~~~~~~~~~~~~~~~</div><div>Will DISubprogram be part of both?</div><div>   * We should split it in two: Full declarations with type and a slimmed down version with an abstract origin.</div><div><br></div><div>How will we reference types in the DWARF blob?</div><div>   * ODR types can be referenced by name</div><div>   * Non-odr types by full DWARF hash</div><div>   * Each type can be a pair(tuple) of identifier (DITypeRef today) and blob.</div><div>   * For < DWARF4 we can emit each type as a unit, but not a DWARF Type Unit and use references and module relocations for the offsets. (See below)</div><div><br></div><div>How will we handle references in DWARF2 or global relocations for non-type template parameters?</div><div>   * We can use a “relocation” metadata as part of the format.</div><div>   * Representable as a tuple that has the DIType and the offset within the DIBlob as where to write the final relocation/offset for the reference at emission time.</div><div><br></div><div>Why break up the types at all?</div><div>   * To enable non-debug format aware linking and type uniquing for LTO that won’t be huge in size. We break up the types so we don’t need to parse debug information to link two modules together efficiently.</div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>How do you plan to handle abbreviations? You wouldn't necessarily be able to embed them directly in the blob, as when doing LTO each compilation unit would have its own set of abbreviations. I suppose you could do something like treat them as a special sort of reference to an abbreviation table entry, or maybe pre-allocate in the frontend (but would complicate cross-frontend LTO) but curious what you have in mind.</div></div></div></div></blockquote><div><br></div></div></div><div>Thanks for reminding me, I knew I was forgetting something I'd talked about when writing all of this down. :)</div><div><br></div><div>Basically to handle abbreviations you can do them the similarly to types by creating a blob with an index/hash/etc and then reference that as part of the type tuple, e.g.:</div><div><br></div><div>$1 = { DIAbbrev: 0x1234, DIBlob: <blah> }</div><div>$2 = { DIType: <ID>, DIAbbrev: $1, DIBlob: <blah> }</div><div><br></div><div>and keep them uniqued during emission and remember to merge these as well during module merge time.</div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Makes sense, but wouldn't you need multiple abbreviations for each DIType, in order to represent DITypes formed of multiple DIEs (e.g. enums, records)?</div><div><br></div><div>Maybe something like this would work:</div><div><div><br></div><div>$1 = { DIAbbrev: 0x1234, DIBlob: DW_TAG_enumeration_type<blah> }</div><div>$2 = { DIAbbrev: 0x5678, DIBlob: DW_TAG_enumerator<blah> }</div></div><div><div>$3 = { DIType: <ID>, DIAbbrev: [(0, $1), (8, $2), (16, $2)], DIBlob: <8 bytes of DW_TAG_enumeration_type attrs><8 bytes of DW_TAG_enumerator attrs><8 bytes of DW_TAG_enumerator attrs><0> }</div></div><div><br></div><div>?</div></div></div></div></blockquote><div><br></div><div>*nod* That (or something similar) will work.</div><div><br></div><div>-eric</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Any other concerns there?</div><div>   * Debug information without type units might be slightly larger in this scheme due to parents being duplicated (declarations and abstract origin, not full parents). It may be possible to extend dsymutil/etc to merge all siblings into a common parent. Open question for better ways to solve this.</div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>When we were thinking about teaching the backend to produce blobs from IR metadata we were thinking about cases where the debug info emitter would discover special member functions during IR traversal. I guess since we're moving all of that to the frontend we can just ask the frontend directly which special members are needed on the class. That solves the problem for a single translation unit. But what do you plan to do in the multiple translation unit case where two TUs declare different special members on a class? Would it be fine to just emit the two definitions and let the debugger sort it out? I guess this is the type of thing that debuggers normally deal with in the non-LTO case, so I suppose so?</div></div></div></div></blockquote><div><br></div></span><div>Pretty much. This is one area where I have... disagreements with the DWARF committee and I don't think there's anything else we can do here. TBH right now I think we'd have issues with type units and special member functions since we're using ODR-ness to unique.</div><span><font color="#888888"><div><br></div><div>-eric</div></font></span><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>How should we handle DWARF5/Apple Accelerator Tables?</div><div>   * Thoughts:</div><div>   * We can parse the dwarf in the back end and generate them.</div><div>   * We can emit in the front end for the base case of non-LTO (with help from the backend for relocation aspects).</div><div>   * We can use dsymutil on LTO debug information to generate them.</div><div><br></div><div>Why isn’t this a more detailed spec?</div><div>   * Mostly because we’ve thought about the issues, but we can’t plan for everything during implementation.</div><div><br></div><div><br></div><div>Future work</div><div>----------------</div><div><br></div><div>Not contained as part of this, but an obvious future direction is that the Module linker could grow support for debug aware linking. Then we can have all of the type information for a single translation unit in a single blob and use the debug aware linking to handle merging types.</div></div>
<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">-- <div>Peter</div></div></div>
</div></div></blockquote></span></div></div>
</blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr">-- <div>Peter</div></div></div>
</div></div></blockquote></div></div>