]> granicus.if.org Git - clang/commitdiff
Switch CGDebugInfo type cache to using an AssertingVH.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 19 Sep 2009 19:27:24 +0000 (19:27 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 19 Sep 2009 19:27:24 +0000 (19:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82321 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4d80d02b555e9a8b6fab842f0ec249090d7cb8e1..e1dca0e483fa6ef3a5e137153ff51d6cd08db94d 100644 (file)
@@ -443,7 +443,7 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
 
   // Otherwise, insert it into the TypeCache so that recursive uses will find
   // it.
-  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl;
+  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
 
   // Convert all the elements.
   llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
@@ -511,12 +511,13 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
     DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
                                      Align, 0, 0, llvm::DIType(), Elements);
 
+  // Update TypeCache.
+  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
+
   // Now that we have a real decl for the struct, replace anything using the
   // old decl with the new one.  This will recursively update the debug info.
   FwdDecl.replaceAllUsesWith(RealDecl);
 
-  // Update TypeCache.
-  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl;
   return RealDecl;
 }
 
@@ -555,7 +556,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
 
   // Otherwise, insert it into the TypeCache so that recursive uses will find
   // it.
-  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl;
+  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
 
   // Convert all the elements.
   llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
@@ -637,12 +638,13 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
                                      Align, 0, 0, llvm::DIType(), Elements,
                                      RuntimeLang);
 
+  // Update TypeCache.
+  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
+
   // Now that we have a real decl for the struct, replace anything using the
   // old decl with the new one.  This will recursively update the debug info.
   FwdDecl.replaceAllUsesWith(RealDecl);
 
-  // Update TypeCache.
-  TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl;
   return RealDecl;
 }
 
@@ -749,25 +751,22 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
   if (Ty.isNull())
     return llvm::DIType();
 
-  // Lookup the cache slot.
-  llvm::DIType &Slot = TypeCache[Ty.getAsOpaquePtr()];
+  // Check for existing entry.
+  std::map<void *, llvm::AssertingVH<llvm::MDNode> >::iterator it =
+    TypeCache.find(Ty.getAsOpaquePtr());
+  if (it != TypeCache.end())
+    return llvm::DIType(it->second);
 
-  // Create the type if necessary.
-  if (Slot.isNull())
-    Slot = CreateTypeNode(Ty, Unit);
-
-  return Slot;
+  // Otherwise create the type.
+  llvm::DIType Res = CreateTypeNode(Ty, Unit);
+  TypeCache.insert(std::make_pair(Ty.getAsOpaquePtr(), Res.getNode()));
+  return Res;
 }
 
 /// getOrCreateTypeNode - Get the type metadata node from the cache or create a
 /// new one if necessary.
 llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty,
                                          llvm::DICompileUnit Unit) {
-  // Make sure the type cache has a null entry, to deal with recursion.
-  assert(TypeCache.count(Ty.getAsOpaquePtr()) &&
-         TypeCache[Ty.getAsOpaquePtr()].isNull() &&
-         "Invalid CreateTypeNode call!");
-
   // Handle CVR qualifiers, which recursively handles what they refer to.
   if (Ty.getCVRQualifiers())
     return CreateCVRType(Ty, Unit);
index 3308a6b952cf8d81575502ef82815d1b02999f6d..d0f0731d6b2f5fd6ec1b4b1fa74c5faa151c10b7 100644 (file)
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Analysis/DebugInfo.h"
+#include "llvm/Support/ValueHandle.h"
 #include <map>
 
 #include "CGBuilder.h"
 
+namespace llvm {
+  class MDNode;
+}
+
 namespace clang {
   class VarDecl;
   class ObjCInterfaceDecl;
@@ -44,7 +49,7 @@ class CGDebugInfo {
 
   /// TypeCache - Cache of previously constructed Types.
   // FIXME: Eliminate this map.  Be careful of iterator invalidation.
-  std::map<void *, llvm::DIType> TypeCache;
+  std::map<void *, llvm::AssertingVH<llvm::MDNode> > TypeCache;
 
   bool BlockLiteralGenericSet;
   llvm::DIType BlockLiteralGeneric;