]> granicus.if.org Git - clang/commitdiff
Finish making AST BumpPtrAllocation runtime configurable (based on -disable-free).
authorSteve Naroff <snaroff@apple.com>
Tue, 27 Jan 2009 23:20:32 +0000 (23:20 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 27 Jan 2009 23:20:32 +0000 (23:20 +0000)
snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m
0.179u 0.051s 0:00.23 95.6% 0+0k 0+0io 0pf+0w
snaroff% time ../../Release-Asserts/bin/clang INPUTS/Cocoa_h.m -disable-free
0.169u 0.052s 0:00.22 95.4% 0+0k 0+0io 0pf+0w

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63153 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/AST/Decl.cpp
lib/AST/DeclCXX.cpp
lib/AST/DeclGroup.cpp
lib/AST/Expr.cpp
lib/Sema/ParseAST.cpp

index 9cf11b85784d2f8898ab345aa787ec78787eee3f..bf585b6d9e76b8e8d934b22f31c0d942a021a7f3 100644 (file)
@@ -118,9 +118,10 @@ class ASTContext {
   ///  this ASTContext object.
   LangOptions LangOpts;
 
-  /// Allocator - The allocator object used to create AST objects.
-  llvm::MallocAllocator Allocator;
-
+  /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
+  bool FreeMemory;
+  llvm::MallocAllocator MallocAlloc;
+  llvm::BumpPtrAllocator BumpAlloc;
 public:
   TargetInfo &Target;
   IdentifierTable &Idents;
@@ -128,9 +129,14 @@ public:
   DeclarationNameTable DeclarationNames;
 
   SourceManager& getSourceManager() { return SourceMgr; }
-  llvm::MallocAllocator &getAllocator() { return Allocator; }  
-  void Deallocate(void *Ptr) { Allocator.Deallocate(Ptr); }
-  
+  void *Allocate(unsigned Size, unsigned Align = 8) {
+    return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
+                        BumpAlloc.Allocate(Size, Align);
+  }
+  void Deallocate(void *Ptr) { 
+    if (FreeMemory)
+      MallocAlloc.Deallocate(Ptr); 
+  }
   const LangOptions& getLangOptions() const { return LangOpts; }
   
   FullSourceLoc getFullLoc(SourceLocation Loc) const { 
@@ -159,8 +165,8 @@ public:
   QualType DependentTy;
 
   ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
-             IdentifierTable &idents, SelectorTable &sels,
-             unsigned size_reserve=0);
+             IdentifierTable &idents, SelectorTable &sels, 
+             bool FreeMemory = true, unsigned size_reserve=0);
 
   ~ASTContext();
   
@@ -600,7 +606,7 @@ private:
 /// @return The allocated memory. Could be NULL.
 inline void *operator new(size_t Bytes, clang::ASTContext &C,
                           size_t Alignment = 16) throw () {
-  return C.getAllocator().Allocate(Bytes, Alignment);
+  return C.Allocate(Bytes, Alignment);
 }
 /// @brief Placement delete companion to the new above.
 ///
@@ -610,7 +616,7 @@ inline void *operator new(size_t Bytes, clang::ASTContext &C,
 /// the ASTContext throws in the object constructor.
 inline void operator delete(void *Ptr, clang::ASTContext &C)
               throw () {
-  C.getAllocator().Deallocate(Ptr);
+  C.Deallocate(Ptr);
 }
 
 #endif
index 7cc67e03d493ae0042c369b570d2de11447a6157..5e2269105992b9d0f9e4a02ee98f2fa383a0d9a1 100644 (file)
@@ -31,9 +31,9 @@ enum FloatingRank {
 ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
                        TargetInfo &t,
                        IdentifierTable &idents, SelectorTable &sels,
-                       unsigned size_reserve) : 
+                       bool FreeMem, unsigned size_reserve) : 
   CFConstantStringTypeDecl(0), ObjCFastEnumerationStateTypeDecl(0),
-  SourceMgr(SM), LangOpts(LOpts), Target(t), 
+  SourceMgr(SM), LangOpts(LOpts), FreeMemory(FreeMem), Target(t), 
   Idents(idents), Selectors(sels)
 {  
   if (size_reserve > 0) Types.reserve(size_reserve);    
@@ -1126,8 +1126,8 @@ QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray,
   // FunctionTypeProto objects are allocated with extra bytes after them
   // for a variable size array (for parameter types) at the end of them.
   FunctionTypeProto *FTP = 
-    (FunctionTypeProto*)Allocator.Allocate(sizeof(FunctionTypeProto) + 
-                                           NumArgs*sizeof(QualType), 8);
+    (FunctionTypeProto*)Allocate(sizeof(FunctionTypeProto) + 
+                                 NumArgs*sizeof(QualType), 8);
   new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic,
                               TypeQuals, Canonical);
   Types.push_back(FTP);
index c8b7fc2dcf982f696a13174f3a784a6f66957dc8..25317dbeb1094a969bbc37fe5f9962f77adf10c7 100644 (file)
@@ -118,8 +118,7 @@ TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
 EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                            IdentifierInfo *Id,
                            EnumDecl *PrevDecl) {
-  void *Mem = C.getAllocator().Allocate<EnumDecl>();
-  EnumDecl *Enum = new (Mem) EnumDecl(DC, L, Id);
+  EnumDecl *Enum = new (C) EnumDecl(DC, L, Id);
   C.getTypeDeclType(Enum, PrevDecl);
   return Enum;
 }
@@ -229,7 +228,7 @@ void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
   
   // Zero params -> null pointer.
   if (NumParams) {
-    void *Mem = C.getAllocator().Allocate<ParmVarDecl*>(NumParams);
+    void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
     ParamInfo = new (Mem) ParmVarDecl*[NumParams];
     memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
   }
index ee242c5dffcb993f4f84362b11c6f269f47c98a4..39ca8787914eabde95ea9e7c9af4a084baf96807 100644 (file)
@@ -47,7 +47,7 @@ TemplateParameterList::Create(ASTContext &C, Decl **Params,
   // FIXME: how do I pass in Size to ASTContext::new?
   unsigned Size = sizeof(TemplateParameterList) + sizeof(Decl *) * NumParams;
   unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment;
-  void *Mem = C.getAllocator().Allocate(Size, Align);
+  void *Mem = C.Allocate(Size, Align);
   return new (Mem) TemplateParameterList(Params, NumParams);
 }
 
index c7af7cd89ea332022aff242d145a690e542b44a1..e7f84e1f46c8fd1fcba78263e95a087a11104e39 100644 (file)
@@ -24,7 +24,7 @@ DeclGroup* DeclGroup::Create(ASTContext& C, unsigned numdecls, Decl** decls) {
   assert (numdecls > 0);
   unsigned size = sizeof(DeclGroup) + sizeof(Decl*) * numdecls;
   unsigned alignment = llvm::AlignOf<DeclGroup>::Alignment;  
-  void* mem = C.getAllocator().Allocate(size, alignment);
+  void* mem = C.Allocate(size, alignment);
   new (mem) DeclGroup(numdecls, decls);
   return static_cast<DeclGroup*>(mem);
 }
@@ -40,7 +40,7 @@ DeclGroup* DeclGroup::Create(llvm::Deserializer& D, ASTContext& C) {
   unsigned NumDecls = (unsigned) D.ReadInt();
   unsigned size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls;
   unsigned alignment = llvm::AlignOf<DeclGroup>::Alignment;  
-  DeclGroup* DG = (DeclGroup*) C.getAllocator().Allocate(size, alignment);
+  DeclGroup* DG = (DeclGroup*) C.Allocate(size, alignment);
   new (DG) DeclGroup();
   DG->NumDecls = NumDecls;
   D.BatchReadOwnedPtrs(NumDecls, &(*DG)[0], C);
index 63484d1b87dc0bf9b0bed1403c72bc54ec3ac5bd..8e43f99b67298dde0138dce845718a5c587a273a 100644 (file)
@@ -1387,10 +1387,9 @@ DesignatedInitExpr::Create(ASTContext &C, Designator *Designators,
                            Expr **IndexExprs, unsigned NumIndexExprs,
                            SourceLocation ColonOrEqualLoc,
                            bool UsesColonSyntax, Expr *Init) {
-  void *Mem = C.getAllocator().Allocate(sizeof(DesignatedInitExpr) +
-                                        sizeof(Designator) * NumDesignators +
-                                        sizeof(Stmt *) * (NumIndexExprs + 1),
-                                        8);
+  void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
+                         sizeof(Designator) * NumDesignators +
+                         sizeof(Stmt *) * (NumIndexExprs + 1), 8);
   DesignatedInitExpr *DIE 
     = new (Mem) DesignatedInitExpr(C.VoidTy, NumDesignators,
                                    ColonOrEqualLoc, UsesColonSyntax,
index ff6de25c1dc239a7ec9d612203420260932c8744..67af285315016dd5374b7c70a698012c6503fc6a 100644 (file)
@@ -39,7 +39,8 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
   ASTContext *Context = 
     new ASTContext(PP.getLangOptions(), PP.getSourceManager(),
                    PP.getTargetInfo(),
-                   PP.getIdentifierTable(), PP.getSelectorTable());
+                   PP.getIdentifierTable(), PP.getSelectorTable(),
+                   FreeMemory);
   TranslationUnit *TU = new TranslationUnit(*Context);
   Sema S(PP, *Context, *Consumer);
   Parser P(PP, S);