]> granicus.if.org Git - clang/commitdiff
CGDebugInfo: Factor out a getOrCreateStandaloneType() method.
authorAdrian Prantl <aprantl@apple.com>
Thu, 27 Aug 2015 21:21:19 +0000 (21:21 +0000)
committerAdrian Prantl <aprantl@apple.com>
Thu, 27 Aug 2015 21:21:19 +0000 (21:21 +0000)
Usually debug info is created on the fly while during codegen.
With this API it becomes possible to create standalone debug info
for types that are not referenced by any code, such as emitting debug info
for a clang module or for implementing something like -gfull.
Because on-the-fly debug info generation may still insert retained types
on top of them, all RetainedTypes are uniqued in CGDebugInfo::finalize().

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246210 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h

index dd3f783cf4ee51f5534cf4f75e90a975c86a7bd9..109829aa490783768dc1f850e0853ca664cb5cae 100644 (file)
@@ -1398,8 +1398,15 @@ llvm::DIType *CGDebugInfo::getOrCreateRecordType(QualType RTy,
 
 llvm::DIType *CGDebugInfo::getOrCreateInterfaceType(QualType D,
                                                     SourceLocation Loc) {
+  return getOrCreateStandaloneType(D, Loc);
+}
+
+llvm::DIType *CGDebugInfo::getOrCreateStandaloneType(QualType D,
+                                                     SourceLocation Loc) {
   assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
+  assert(!D.isNull() && "null type");
   llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
+  assert(T && "could not create debug info for type");
   RetainedTypes.push_back(D.getAsOpaquePtr());
   return T;
 }
@@ -3360,9 +3367,14 @@ void CGDebugInfo::finalize() {
 
   // We keep our own list of retained types, because we need to look
   // up the final type in the type cache.
-  for (std::vector<void *>::const_iterator RI = RetainedTypes.begin(),
-         RE = RetainedTypes.end(); RI != RE; ++RI)
-    DBuilder.retainType(cast<llvm::DIType>(TypeCache[*RI]));
+  llvm::DenseSet<void *> UniqueTypes;
+  UniqueTypes.resize(RetainedTypes.size() * 2);
+  for (auto &RT : RetainedTypes) {
+    if (!UniqueTypes.insert(RT).second)
+      continue;
+    if (auto MD = TypeCache[RT])
+      DBuilder.retainType(cast<llvm::DIType>(MD));
+  }
 
   DBuilder.finalize();
 }
index 2ebd2cde71c41dd6fcff10c83030c68324ebe18d..1880335cc0bdd642dbb45aeb807058126d020f55 100644 (file)
@@ -344,6 +344,9 @@ public:
   /// Emit an Objective-C interface type standalone debug info.
   llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
 
+  /// Emit standalone debug info for a type.
+  llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
+
   void completeType(const EnumDecl *ED);
   void completeType(const RecordDecl *RD);
   void completeRequiredType(const RecordDecl *RD);