<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jun 20, 2013, at 5:18 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Thu, Jun 20, 2013 at 5:13 PM, Manman Ren <<a href="mailto:mren@apple.com">mren@apple.com</a>> wrote:<br><blockquote type="cite"><br>On Jun 20, 2013, at 4:52 PM, David Blaikie wrote:<br><br><blockquote type="cite">On Thu, Jun 20, 2013 at 4:45 PM, Manman Ren <<a href="mailto:mren@apple.com">mren@apple.com</a>> wrote:<br><blockquote type="cite"><br>On Jun 20, 2013, at 3:55 PM, Manman Ren <<a href="mailto:mren@apple.com">mren@apple.com</a>> wrote:<br><br><br>On Jun 20, 2013, at 2:58 PM, Eric Christopher wrote:<br><br>Hi Manman,<br><br>On Thu, Jun 20, 2013 at 2:51 PM, Manman Ren <<a href="mailto:mren@apple.com">mren@apple.com</a>> wrote:<br><br><br>The intent of this proposal is to speedup compilation of "-flto -g" for c++<br>programs.<br>This is based on discussions with Adrian, David and Eric.<br><br><br>Thanks for bringing this back to the list. The original thread was<br>getting quite long.<br><br>---------------------------<br>Problem:<br>A single class can be used in multiple source files and the DI (Debug Info)<br>class is included in multiple bc files. The duplication of<br>class definitions causes blow-up in # of MDNodes, # of DIEs, leading to<br>large memory requirement.<br><br>As an example, SPEC xalancbmk requires 7GB of memory when compiled with<br>-flto -g.<br>With a preliminary implementation of type uniquing, the memory usage will be<br>down to 2GB.<br><br>In order to unique types, we have to break cycles in the MDNodes.<br><br>A simple struct definition<br>struct Base {<br>int a;<br>};<br>can cause cycles in MDNodes:<br>!12 = metadata !{i32 786451, metadata !13, null, metadata !"Base", i32 1,<br>i64 32, i64 32, i32 0, i32 0, null, metadata !14, i32 0, null, null} ; [<br>DW_TAG_structure_type ] [Base] [line 1, size 32, align 32, offset 0] [from ]<br>!14 = metadata !{metadata !15, metadata !16}<br>!15 = metadata !{i32 786445, metadata !13, metadata !12, metadata !"a", i32<br>2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line<br>2, size 32, align 32, offset 0] [from int]<br>!16 = metadata !{i32 786478, metadata !13, metadata !12, metadata !"Base",<br>metadata !"Base", metadata !"", i32 1, metadata !17, i1 false, i1 false, i32<br>0, i32 0, null, i32 320, i1 false, null, null, i32 0, metadata !20, i32 1} ;<br>[ DW_TAG_subprogram ] [line 1] [Base]<br><br>Cycles: !12 -- !14 -- !15 -- !12<br>        !12 -- !14 -- !16 -- !12<br><br>These cycles make it hard to unique the same struct used in two bc files.<br><br>---------------------------<br>How to fix:<br><br>We attach a hash value to types to help type uniquing and we also replace<br>references to types with their hash values.<br>For the above struct "Base", we now have the following MDNodes:<br>!4 = metadata !{i32 786451, metadata !5, null, metadata !"Base", i32 1, i64<br>32, i64 32, i32 0, i32 0, null, metadata !6, i32 0, i32 0, null, i32<br>915398439} ; [ DW_TAG_structure_type ] [Base] [line 1, size 32, align 32,<br>offset 0] [from ]<br>!6 = metadata !{metadata !7, metadata !9}<br>!7 = metadata !{i32 786445, metadata !5, i32 915398439, metadata !"a", i32<br>2, i64 32, i64 32, i64 0, i32 0, metadata !8} ; [ DW_TAG_member ] [a] [line<br>2, size 32, align 32, offset 0] [from int]<br>!9 = metadata !{i32 786478, metadata !5, i32 915398439, metadata !"Base",<br>metadata !"Base", metadata !"", i32 1, metadata !10, i1 false, i1 false, i32<br>0, i32 0, null, i32 320, i1 false, null, null, i32 0, metadata !13, i32 1} ;<br>[ DW_TAG_subprogram ] [line 1] [Base]<br><br>Note that the cycles are gone and !4 has a hash value of 915398439, and the<br>references to !4 are replaced with 915398439.<br>Thanks Eric for suggesting replacing MD reference with a hash value.<br><br><br>In particular I recommended this:<br><br>a) For C++ odr replace it with the "hash" that's just a string<br>representing the type name.<br>b) For Internal C++ types and all C types replace it with a string<br>that's a concatenation of the type name and the name of the compile<br>unit.<br><br>Yes, that is what we agreed on over email.<br><br><br><br>There are a few issues:<br>1> How to generate the hash for a given type?<br>With C++'s ODR, it should be enough by using the context and the name for<br>non-internal c++ types.<br>For internal c++ types and types of other languages, hash will not be used.<br><br><br>Explain this?<br><br><br>For a while, I am going to support both hash and MD reference, once<br>everything is working with hash,<br>I will update all debug info testing cases, turn -gtype-uniquing on, and<br>remove the other path.<br><br>For internal c++ types, initially they will follow the path of using MD<br>references without a hash.<br><br><br>My current implementation is to add a few static member functions in MDNode<br>to profile DI nodes differently.<br>+ /// If the array of Vals is for debug info, profile it specially and<br>return true.<br>+ /// If the DI node has a hash value, generate the profile using only the<br>hash value and the declaration flag.<br>+  static bool profileDebugInfoNode(ArrayRef<Value*> Vals, FoldingSetNodeID<br>&ID);<br><br>+ /// If the MDNode is for debug info, profile it specially and return true.<br>+ /// If the DI node has a hash value, generate the profile using only the<br>hash value and the declaration flag.<br>+  static bool profileDebugInfoNode(const MDNode *M, FoldingSetNodeID &ID);<br><br>+ /// Given a hash value and a flag, generate the profile for later lookup.<br>+  static bool profileDebugInfoNode(unsigned Hash, bool Declaration,<br>FoldingSetNodeID &ID);<br><br>These static functions are called in Metadata.cpp:<br>void MDNode::Profile(FoldingSetNodeID &ID) const {<br>+  if (profileDebugInfoNode(this, ID))<br>+    return;<br>+<br><br>There are other examples of these in MDNode for handling of specific<br>metadata.<br>/// Methods for metadata merging.<br>static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);<br>static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);<br>static MDNode *getMostGenericRange(MDNode *A, MDNode *B);<br><br>Comments are welcome on whether this violates any layering rule.<br><br><br>As I've said many times in email, I don't think this is a good idea<br>and would prefer either a or b below. a) is a much simpler solution.<br><br>Any reason that why it is not a good idea?<br><br><br>Other choices are:<br>a> Keep a map in DwarfDebug<br>Keep in mind that the map is used at many stages, and it has to be in sync<br>with MDNodeSet.<br>b> Generalize MDNode to be aware of hash (David can provide more details)<br>c> Extend MDNode to DINode and modify streamers (bitcode reader|writer, ll<br>reader|writer) to be aware of DINode<br>We can provide DINode::get(…) to create a DINode. DINode can have its own<br>Profile function.<br>Other suggestions are welcome.<br><br><br>a or b please.<br><br>Option a> will require a DwarfDebug pointer in every stage of the compiler,<br>and passing the map to the DI classes.<br>A rough estimation is around 100 places.<br>Is it reasonable to pass a DwarfDebug pointer to DIBuilder and llvm linker?<br>Also the map needs to be in sync with MDNodeSet, maybe using ValueHandle can<br>solve the problem.<br><br><br>What about putting the map in LLVMContextImpl?<br>It already has a few things specifically for debug info:<br>std::vector<DebugRecVH> ScopeRecords;<br>DenseMap<std::pair<MDNode*, MDNode*>, int> ScopeInlinedAt;<br>…<br><br>I remember David mentioned it once and I forgot about the conclusion.<br></blockquote><br>I mentioned it only as speculation as to how you were implementing it<br>already (but you were doing the profile-changing stuff).<br><br>I don't think it should be necessary to have the map (in option (a))<br>in such a central location as LLVMContext. It should be usable just<br>from DwarfDebug for generation, and DIBuilder can have its own,<br>separate map to do similar things during DI building.<br></blockquote><br>We also need the map during llvm linking since linking will create new MDNodes.<br></blockquote><br>I don't understand what you mean by this. IR linking shouldn't need to<br>do anything debug-info-specific, it should just be the normal IR<br>approach.<br><br>The declaration-v-definition resolution can be done at codegen-time.<br>We'll have to walk all the lists of retained types anyway to build the<br>map, so we can do declaration-v-definition (keep definitions over<br>declarations when we see both) at that point.<br></div></blockquote><div><br></div><div>Yes, you are right that at codegen-time, we can generate the map from the lists</div><div>of retained types.</div><div><br></div><div>But dumping the linked ll file requires the map when outputting comments of the MDNode :]</div><div><br></div><div>Thanks,</div><div>Manman</div><div><br></div><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br><blockquote type="cite">So any other opinion on putting it in LLVMContext other than it being central?<br><br>Thanks,<br>Manman<br><br><blockquote type="cite"><br><blockquote type="cite"><br>Thanks,<br>Manman<br><br><br>More details for option b from David<br><br>< The alternative I have in mind is a more complete version of what<br>< you're proposing - a full MD feature, not an MD feature that's just<br>< barely enough to support the needs of debug info. What we could do is<br>< allow the insertion of these MDHash things you spoke about but take it<br>< a step further and have MDNode::getOperand walk through the hash &<br>< give the value (in this way, DebugInfo wouldn't have to change at all<br>< to handle hashes - if the Metadata APIs are going to be aware of the<br>< hashes anyway, they might as well provide this convenience<br>< functionality) the metadata feature would also have to have some<br>< blessed top-level named metadata that would have a list of hash+MDNode<br>< to keep those MDNodes alive (so you wouldn't have to stuff all the<br>< types in the retained types list - metadata would provide the full<br>< support, not just half of it).<br><br><br><br>Transition from current DI Metadata:<br>To have a smooth transition, I will add a flag "-gtype-hashing" for the type<br>uniquing work and turn it on by default when we are ready.<br><br><br>I'd prefer just make the change to have the front end emit the "hash"<br>(it's not really a hash, it's just a string).<br><br>Are you saying no transition period? A single patch to have correct handling<br>of "hash" and to update all existing testing cases?<br><br><br>-----------------------------<br>Patches:<br>Expect the following patches:<br>1> add flag -gtype-hashing<br>2> add hash field to DI types<br>3> modify DIBuilder to use hash instead of MD reference<br>4> related to issue 3<br><br><br>These can all be a single patch since it shouldn't be very large if we<br>go with a) above. If we go with b) then the MDNode work should be done<br>in isolation first and then the debug info on top of it.<br><br>What is wrong with smaller patches?<br>My estimation for all the above with a) is about 30K + testing cases.<br><br><br>5> backend change (in DwarfDebug|CompileUnit) to support types shared among<br>compile units<br>requires gdwarf-2 gdwarf-3 gdwarf-4 support for issues related to ref_addr<br><br><br>#5 can and should be done before the rest of them.<br><br>I prefer to submit patches according to the flow of the compiler, starting<br>from the frontend, then IR, then backend.<br>The testing cases will be added for front end, llvm-link and backend.<br>Any reason why #5 should be done first?<br><br><br>All changes should be local to debug info classes except patch #4.<br><br><br>What's patch #4?<br><br>Patch #4 above: related to issue 3 (changes corresponding to how to solve<br>issue #3)<br><br>-Manman<br><br><br>-eric<br><br><br><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br><br><br><br>_______________________________________________<br>llvm-commits mailing list<br>llvm-commits@cs.uiuc.edu<br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</blockquote></blockquote></blockquote></div></blockquote></div><br></body></html>