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

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:43:03 PDT 2007


Author: sabre
Date: Wed Jul 11 11:43:03 2007
New Revision: 39320

URL: http://llvm.org/viewvc/llvm-project?rev=39320&view=rev
Log:
Eliminate the last of the slow lookups, by making non-prototyped function types
use the folding set.  This eliminates 359 slow lookups from carbon.h (the
rest) but doesn't substantially speed up parse.

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

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

==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:43:03 2007
@@ -20,7 +20,6 @@
 
 ASTContext::ASTContext(Preprocessor &pp)
   : PP(pp), Target(pp.getTargetInfo()) {
-  NumSlowLookups = 0;
   InitBuiltinTypes();
 }
 
@@ -85,7 +84,6 @@
   fprintf(stderr, "      %d union types\n", NumTagUnion);
   fprintf(stderr, "      %d class types\n", NumTagClass);
   fprintf(stderr, "      %d enum types\n", NumTagEnum);
-  fprintf(stderr, "  %d slow type lookups\n", NumSlowLookups);
 }
 
 
@@ -194,21 +192,30 @@
 /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'.
 ///
 TypeRef ASTContext::getFunctionTypeNoProto(TypeRef ResultTy) {
-  // FIXME: This is obviously braindead!
   // Unique functions, to guarantee there is only one function of a particular
   // structure.
-  ++NumSlowLookups;
-  for (unsigned i = 0, e = Types.size(); i != e; ++i)
-    if (FunctionTypeNoProto *FTy = dyn_cast<FunctionTypeNoProto>(Types[i]))
-      if (FTy->getResultType() == ResultTy)
-        return Types[i];
-
+  FoldingSetNodeID ID;
+  FunctionTypeNoProto::Profile(ID, ResultTy);
+  
+  void *InsertPos = 0;
+  if (FunctionTypeNoProto *FT = 
+        FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos))
+    return FT;
+  
   Type *Canonical = 0;
-  if (!ResultTy->isCanonical())
+  if (!ResultTy->isCanonical()) {
     Canonical =getFunctionTypeNoProto(ResultTy.getCanonicalType()).getTypePtr();
+    
+    // Get the new insert position for the node we care about.
+    FunctionTypeNoProto *NewIP =
+      FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos);
+    assert(NewIP == 0 && "Shouldn't be in the map!");
+  }
   
-  Types.push_back(new FunctionTypeNoProto(ResultTy, Canonical));
-  return Types.back();
+  FunctionTypeNoProto *New = new FunctionTypeNoProto(ResultTy, Canonical);
+  Types.push_back(New);
+  FunctionTypeProtos.InsertNode(New, InsertPos);
+  return New;
 }
 
 /// getFunctionType - Return a normal function type with a typed argument

Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39320&r1=39319&r2=39320&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:43:03 2007
@@ -75,17 +75,6 @@
   }
 }
 
-void PointerType::Profile(FoldingSetNodeID &ID, TypeRef Pointee) {
-  ID.AddPointer(Pointee.getAsOpaquePtr());
-}
-
-void ArrayType::Profile(FoldingSetNodeID &ID, ArraySizeModifier SizeModifier,
-                        unsigned IndexTypeQuals, TypeRef ElementType) {
-  ID.AddInteger(SizeModifier);
-  ID.AddInteger(IndexTypeQuals);
-  ID.AddPointer(ElementType.getAsOpaquePtr());
-}
-
 void FunctionTypeProto::Profile(FoldingSetNodeID &ID, TypeRef Result,
                                 TypeRef* ArgTys,
                                 unsigned NumArgs, bool isVariadic) {

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/cfe/trunk/include/clang/AST/ASTContext.h Wed Jul 11 11:43:03 2007
@@ -26,9 +26,9 @@
 /// decls) that can be referred to throughout the semantic analysis of a file.
 class ASTContext {
   std::vector<Type*> Types;
-  unsigned NumSlowLookups;
   FoldingSet<PointerType> PointerTypes;
   FoldingSet<ArrayType> ArrayTypes;
+  FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
   FoldingSet<FunctionTypeProto> FunctionTypeProtos;
 public:
   Preprocessor &PP;

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:43:03 2007
@@ -238,7 +238,9 @@
   void Profile(FoldingSetNodeID &ID) {
     Profile(ID, getPointeeType());
   }
-  static void Profile(FoldingSetNodeID &ID, TypeRef Pointee);
+  static void Profile(FoldingSetNodeID &ID, TypeRef Pointee) {
+    ID.AddPointer(Pointee.getAsOpaquePtr());
+  }
   
   static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
   static bool classof(const PointerType *) { return true; }
@@ -284,7 +286,11 @@
     Profile(ID, getSizeModifier(), getIndexTypeQualifier(), getElementType());
   }
   static void Profile(FoldingSetNodeID &ID, ArraySizeModifier SizeModifier,
-                      unsigned IndexTypeQuals, TypeRef ElementType);
+                      unsigned IndexTypeQuals, TypeRef ElementType) {
+    ID.AddInteger(SizeModifier);
+    ID.AddInteger(IndexTypeQuals);
+    ID.AddPointer(ElementType.getAsOpaquePtr());
+  }
   
   static bool classof(const Type *T) { return T->getTypeClass() == Array; }
   static bool classof(const ArrayType *) { return true; }
@@ -318,7 +324,7 @@
 
 /// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has
 /// no information available about its arguments.
-class FunctionTypeNoProto : public FunctionType {
+class FunctionTypeNoProto : public FunctionType, public FoldingSetNode {
   FunctionTypeNoProto(TypeRef Result, Type *Canonical)
     : FunctionType(FunctionNoProto, Result, false, Canonical) {}
   friend class ASTContext;  // ASTContext creates these.
@@ -327,6 +333,13 @@
   
   virtual void getAsString(std::string &InnerString) const;
 
+  void Profile(FoldingSetNodeID &ID) {
+    Profile(ID, getResultType());
+  }
+  static void Profile(FoldingSetNodeID &ID, TypeRef ResultType) {
+    ID.AddPointer(ResultType.getAsOpaquePtr());
+  }
+  
   static bool classof(const Type *T) {
     return T->getTypeClass() == FunctionNoProto;
   }





More information about the cfe-commits mailing list