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

John McCall rjmccall at apple.com
Fri Jun 11 04:07:21 PDT 2010


Author: rjmccall
Date: Fri Jun 11 06:07:21 2010
New Revision: 105820

URL: http://llvm.org/viewvc/llvm-project?rev=105820&view=rev
Log:
Don't store ASTContext references in the TST nodes just to support profiling.


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

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=105820&r1=105819&r2=105820&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jun 11 06:07:21 2010
@@ -75,6 +75,8 @@
 /// ASTContext - This class holds long-lived AST nodes (such as types and
 /// decls) that can be referred to throughout the semantic analysis of a file.
 class ASTContext {
+  ASTContext &this_() { return *this; }
+
   std::vector<Type*> Types;
   llvm::FoldingSet<ExtQuals> ExtQualNodes;
   llvm::FoldingSet<ComplexType> ComplexTypes;
@@ -95,10 +97,11 @@
   llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
   llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
   llvm::FoldingSet<SubstTemplateTypeParmType> SubstTemplateTypeParmTypes;
-  llvm::FoldingSet<TemplateSpecializationType> TemplateSpecializationTypes;
+  llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
+    TemplateSpecializationTypes;
   llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
   llvm::FoldingSet<DependentNameType> DependentNameTypes;
-  llvm::FoldingSet<DependentTemplateSpecializationType>
+  llvm::ContextualFoldingSet<DependentTemplateSpecializationType, ASTContext&>
     DependentTemplateSpecializationTypes;
   llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
   llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=105820&r1=105819&r2=105820&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jun 11 06:07:21 2010
@@ -2420,11 +2420,8 @@
 class TemplateSpecializationType
   : public Type, public llvm::FoldingSetNode {
 
-  // The ASTContext is currently needed in order to profile expressions.
-  // FIXME: avoid this.
-  //
   // The bool is whether this is a current instantiation.
-  llvm::PointerIntPair<ASTContext*, 1, bool> ContextAndCurrentInstantiation;
+  bool IsCurrentInstantiation;
 
   /// \brief The name of the template being specialized.
   TemplateName Template;
@@ -2433,8 +2430,7 @@
   /// template specialization.
   unsigned NumArgs;
 
-  TemplateSpecializationType(ASTContext &Context,
-                             TemplateName T,
+  TemplateSpecializationType(TemplateName T,
                              bool IsCurrentInstantiation,
                              const TemplateArgument *Args,
                              unsigned NumArgs, QualType Canon);
@@ -2470,7 +2466,7 @@
   /// True if this template specialization type matches a current
   /// instantiation in the context in which it is found.
   bool isCurrentInstantiation() const {
-    return ContextAndCurrentInstantiation.getInt();
+    return IsCurrentInstantiation;
   }
 
   typedef const TemplateArgument * iterator;
@@ -2498,9 +2494,8 @@
   }
   QualType desugar() const { return getCanonicalTypeInternal(); }
 
-  void Profile(llvm::FoldingSetNodeID &ID) {
-    Profile(ID, Template, isCurrentInstantiation(), getArgs(), NumArgs,
-            *ContextAndCurrentInstantiation.getPointer());
+  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Ctx) {
+    Profile(ID, Template, isCurrentInstantiation(), getArgs(), NumArgs, Ctx);
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
@@ -2782,10 +2777,6 @@
 class DependentTemplateSpecializationType :
   public TypeWithKeyword, public llvm::FoldingSetNode {
 
-  /// The AST context.  Unfortunately required in order to profile
-  /// template arguments.
-  ASTContext &Context;
-
   /// \brief The nested name specifier containing the qualifier.
   NestedNameSpecifier *NNS;
 
@@ -2803,8 +2794,7 @@
     return reinterpret_cast<TemplateArgument*>(this+1);
   }
 
-  DependentTemplateSpecializationType(ASTContext &Context,
-                                      ElaboratedTypeKeyword Keyword,
+  DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
                                       NestedNameSpecifier *NNS,
                                       const IdentifierInfo *Name,
                                       unsigned NumArgs,
@@ -2838,7 +2828,7 @@
   bool isSugared() const { return false; }
   QualType desugar() const { return QualType(this, 0); }
 
-  void Profile(llvm::FoldingSetNodeID &ID) {
+  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) {
     Profile(ID, Context, getKeyword(), NNS, Name, NumArgs, getArgs());
   }
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=105820&r1=105819&r2=105820&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jun 11 06:07:21 2010
@@ -40,6 +40,8 @@
                        IdentifierTable &idents, SelectorTable &sels,
                        Builtin::Context &builtins,
                        bool FreeMem, unsigned size_reserve) :
+  TemplateSpecializationTypes(this_()),
+  DependentTemplateSpecializationTypes(this_()),
   GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0),
   NSConstantStringTypeDecl(0),
   ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0),
@@ -1824,7 +1826,7 @@
       void *Mem = Allocate((sizeof(TemplateSpecializationType) +
                             sizeof(TemplateArgument) * NumArgs),
                            TypeAlignment);
-      Spec = new (Mem) TemplateSpecializationType(*this, CanonTemplate, false,
+      Spec = new (Mem) TemplateSpecializationType(CanonTemplate, false,
                                                   CanonArgs.data(), NumArgs,
                                                   Canon);
       Types.push_back(Spec);
@@ -1844,7 +1846,7 @@
                         sizeof(TemplateArgument) * NumArgs),
                        TypeAlignment);
   TemplateSpecializationType *Spec
-    = new (Mem) TemplateSpecializationType(*this, Template,
+    = new (Mem) TemplateSpecializationType(Template,
                                            IsCurrentInstantiation,
                                            Args, NumArgs,
                                            Canon);
@@ -1970,7 +1972,7 @@
   void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) +
                         sizeof(TemplateArgument) * NumArgs),
                        TypeAlignment);
-  T = new (Mem) DependentTemplateSpecializationType(*this, Keyword, NNS,
+  T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS,
                                                     Name, NumArgs, Args, Canon);
   Types.push_back(T);
   DependentTemplateSpecializationTypes.InsertNode(T, InsertPos);

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=105820&r1=105819&r2=105820&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Jun 11 06:07:21 2010
@@ -871,12 +871,12 @@
 }
 
 DependentTemplateSpecializationType::DependentTemplateSpecializationType(
-                         ASTContext &Context, ElaboratedTypeKeyword Keyword,
+                         ElaboratedTypeKeyword Keyword,
                          NestedNameSpecifier *NNS, const IdentifierInfo *Name,
                          unsigned NumArgs, const TemplateArgument *Args,
                          QualType Canon)
   : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true),
-    Context(Context), NNS(NNS), Name(Name), NumArgs(NumArgs) {
+    NNS(NNS), Name(Name), NumArgs(NumArgs) {
   assert(NNS && NNS->isDependent() &&
          "DependentTemplateSpecializatonType requires dependent qualifier");
   for (unsigned I = 0; I != NumArgs; ++I)
@@ -1130,14 +1130,14 @@
 }
 
 TemplateSpecializationType::
-TemplateSpecializationType(ASTContext &Context, TemplateName T,
+TemplateSpecializationType(TemplateName T,
                            bool IsCurrentInstantiation,
                            const TemplateArgument *Args,
                            unsigned NumArgs, QualType Canon)
   : Type(TemplateSpecialization,
          Canon.isNull()? QualType(this, 0) : Canon,
          T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)),
-    ContextAndCurrentInstantiation(&Context, IsCurrentInstantiation),
+    IsCurrentInstantiation(IsCurrentInstantiation),
     Template(T), NumArgs(NumArgs) {
   assert((!Canon.isNull() ||
           T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) &&





More information about the cfe-commits mailing list