<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="http://llvm.org/viewvc/llvm-project?rev=246210&view=rev" 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><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="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=246210&r1=246209&r2=246210&view=diff" 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="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=246210&r1=246209&r2=246210&view=diff" 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">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>