[cfe-commits] r39306 - in /cfe/cfe/trunk: AST/ASTContext.cpp include/clang/AST/Decl.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:42:49 PDT 2007


Author: sabre
Date: Wed Jul 11 11:42:49 2007
New Revision: 39306

URL: http://llvm.org/viewvc/llvm-project?rev=39306&view=rev
Log:
TagDecl now holds a cache for the type corresponding to it.  This speeds up
ASTContext::getTagDeclType by not having to do a linear search.  With this,
parse time for carbon.h drops from 21.8s to 16.0s and # slow lookups drop from
83K to 63K.

Modified:
    cfe/cfe/trunk/AST/ASTContext.cpp
    cfe/cfe/trunk/include/clang/AST/Decl.h

Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39306&r1=39305&r2=39306&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:42:49 2007
@@ -276,17 +276,10 @@
 /// getTagDeclType - Return the unique reference to the type for the
 /// specified TagDecl (struct/union/class/enum) decl.
 TypeRef ASTContext::getTagDeclType(TagDecl *Decl) {
-  // FIXME: This is obviously braindead!
-  // Unique TypeDecl, to guarantee there is only one TaggedType.
-  ++NumSlowLookups;
-  for (unsigned i = 0, e = Types.size(); i != e; ++i)
-    if (TaggedType *Ty = dyn_cast<TaggedType>(Types[i]))
-      if (Ty->getDecl() == Decl)
-        return Types[i];
+  // The decl stores the type cache.
+  if (Decl->TypeForDecl) return Decl->TypeForDecl;
   
-  // FIXME: does this lose qualifiers from the typedef??
-  
-  Types.push_back(new TaggedType(Decl, 0));
+  Types.push_back(Decl->TypeForDecl = new TaggedType(Decl, 0));
   return Types.back();
 }
 

Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39306&r1=39305&r2=39306&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:42:49 2007
@@ -224,11 +224,17 @@
 
 /// TagDecl - Represents the declaration of a struct/union/class/enum.
 class TagDecl : public Decl {
+  /// TypeForDecl - This indicates the Type object that represents this TagDecl.
+  /// It is a cache maintained by ASTContext::getTagDeclType.
+  Type *TypeForDecl;
+  friend class ASTContext;
+  
   /// IsDefinition - True if this is a definition ("struct foo {};"), false if
   /// it is a declaration ("struct foo;").
   bool IsDefinition : 1;
 protected:
   TagDecl(Kind DK, SourceLocation L, IdentifierInfo *Id) : Decl(DK, L, Id) {
+    TypeForDecl = 0;
     IsDefinition = false;
   }
 public:





More information about the cfe-commits mailing list