[cfe-commits] r82321 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Daniel Dunbar daniel at zuster.org
Sat Sep 19 12:27:24 PDT 2009


Author: ddunbar
Date: Sat Sep 19 14:27:24 2009
New Revision: 82321

URL: http://llvm.org/viewvc/llvm-project?rev=82321&view=rev
Log:
Switch CGDebugInfo type cache to using an AssertingVH.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=82321&r1=82320&r2=82321&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Sat Sep 19 14:27:24 2009
@@ -443,7 +443,7 @@
 
   // 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 @@
     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 @@
 
   // 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 @@
                                      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 @@
   if (Ty.isNull())
     return llvm::DIType();
 
-  // Lookup the cache slot.
-  llvm::DIType &Slot = TypeCache[Ty.getAsOpaquePtr()];
-
-  // Create the type if necessary.
-  if (Slot.isNull())
-    Slot = CreateTypeNode(Ty, Unit);
-
-  return Slot;
+  // 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);
+
+  // 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);

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=82321&r1=82320&r2=82321&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Sat Sep 19 14:27:24 2009
@@ -18,10 +18,15 @@
 #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 @@
 
   /// 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;





More information about the cfe-commits mailing list