<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 27, 2015 at 2:35 PM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Aug 27, 2015, at 2:25 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 27, 2015 at 2:21 PM, Adrian Prantl via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Thu Aug 27 16:21:19 2015<br>
New Revision: 246210<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D246210-26view-3Drev&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=aJRwlazZQeqQe80mCWYKzjxquHaBvqmkRAL1J7k0HoE&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=246210&view=rev</a><br>
Log:<br>
CGDebugInfo: Factor out a getOrCreateStandaloneType() method.<br>
<br>
Usually debug info is created on the fly while during codegen.<br>
With this API it becomes possible to create standalone debug info<br>
for types that are not referenced by any code, such as emitting debug info<br>
for a clang module or for implementing something like -gfull.<br>
Because on-the-fly debug info generation may still insert retained types<br>
on top of them, all RetainedTypes are uniqued in CGDebugInfo::finalize().<br></blockquote><div><br></div><div>I don't quite understand why the new uniquing code is required - what is it about this new codepath that necessitates that?</div></div></div></div></div></blockquote><div><br></div></span><div>getOrCreateStandaloneType() invokes getOrCreateType() and adds the DIType to RetainedTypes so it doesn’t get lost. If getOrCreateType() was in fact a cache hit, it is possible that the type was already retained when it was initially created. Thinking of it, it is probably better to make getOrCreateStandalaoneType() replicate getOrCreateType()’s logic and have it only retain the type if it was a cache miss. I’ll fix that.</div></div></div></blockquote><div><br></div><div>Why are both functions checking the cache, though? (or does getOrCreateType only retain types that use DIRefs? & then you need to retain the other ones too?)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- adrian</div></font></span><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CGDebugInfo.cpp-3Frev-3D246210-26r1-3D246209-26r2-3D246210-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=tu3fprD1M6lqLHkpJc-IasxvMhIesAykH_SLNHiYl8g&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=246210&r1=246209&r2=246210&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 27 16:21:19 2015<br>
@@ -1398,8 +1398,15 @@ llvm::DIType *CGDebugInfo::getOrCreateRe<br>
<br>
 llvm::DIType *CGDebugInfo::getOrCreateInterfaceType(QualType D,<br>
                                                     SourceLocation Loc) {<br>
+  return getOrCreateStandaloneType(D, Loc);<br>
+}<br>
+<br>
+llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D,<br>
+                                                     SourceLocation Loc) {<br>
   assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);<br>
+  assert(!D.isNull() && "null type");<br>
   llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));<br>
+  assert(T && "could not create debug info for type");<br>
   RetainedTypes.push_back(D.getAsOpaquePtr());<br>
   return T;<br>
 }<br>
@@ -3360,9 +3367,14 @@ void CGDebugInfo::finalize() {<br>
<br>
   // We keep our own list of retained types, because we need to look<br>
   // up the final type in the type cache.<br>
-  for (std::vector<void *>::const_iterator RI = RetainedTypes.begin(),<br>
-         RE = RetainedTypes.end(); RI != RE; ++RI)<br>
-    DBuilder.retainType(cast<llvm::DIType>(TypeCache[*RI]));<br>
+  llvm::DenseSet<void *> UniqueTypes;<br>
+  UniqueTypes.resize(RetainedTypes.size() * 2);<br>
+  for (auto &RT : RetainedTypes) {<br>
+    if (!UniqueTypes.insert(RT).second)<br>
+      continue;<br>
+    if (auto MD = TypeCache[RT])<br>
+      DBuilder.retainType(cast<llvm::DIType>(MD));<br>
+  }<br>
<br>
   DBuilder.finalize();<br>
 }<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CGDebugInfo.h-3Frev-3D246210-26r1-3D246209-26r2-3D246210-26view-3Ddiff&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=wP5t1N1vlukZeQ4hJZIPNg3aK6A2hiDY3de2dsFzjzQ&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=246210&r1=246209&r2=246210&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Aug 27 16:21:19 2015<br>
@@ -344,6 +344,9 @@ public:<br>
   /// Emit an Objective-C interface type standalone debug info.<br>
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);<br>
<br>
+  /// Emit standalone debug info for a type.<br>
+  llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);<br>
+<br>
   void completeType(const EnumDecl *ED);<br>
   void completeType(const RecordDecl *RD);<br>
   void completeRequiredType(const RecordDecl *RD);<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits&d=BQMFaQ&c=eEvniauFctOgLOKGJOplqw&r=cTx6f1tAfqPeajYunFWp7_8ot79RnHyNteqzig4fXmA&m=Sj8qkz7sVxvG7N0vgi_JQdPVjDsDVL7hEAG9mK6e4_c&s=KP-TI2iE4gchlGzoSv2inSkjBdaf_Vm8z5phvDG_pyk&e=" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>
</div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>