aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-01-27 23:20:32 +0000
committerSteve Naroff <snaroff@apple.com>2009-01-27 23:20:32 +0000
commitc0ac4923f08b25ae973a8ee7942cf3eb89da57b7 (patch)
treeb6b9ce974fc742f015b06cab38436c181c6ebd7c
parentdb64728e69a45b89870ede13944a934d3c2ed12a (diff)
Finish making AST BumpPtrAllocation runtime configurable (based on -disable-free).
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
-rw-r--r--include/clang/AST/ASTContext.h26
-rw-r--r--lib/AST/ASTContext.cpp8
-rw-r--r--lib/AST/Decl.cpp5
-rw-r--r--lib/AST/DeclCXX.cpp2
-rw-r--r--lib/AST/DeclGroup.cpp4
-rw-r--r--lib/AST/Expr.cpp7
-rw-r--r--lib/Sema/ParseAST.cpp3
7 files changed, 30 insertions, 25 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 9cf11b8578..bf585b6d9e 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -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
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 7cc67e03d4..5e22691059 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -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);
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index c8b7fc2dcf..25317dbeb1 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -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);
}
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index ee242c5dff..39ca878791 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -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);
}
diff --git a/lib/AST/DeclGroup.cpp b/lib/AST/DeclGroup.cpp
index c7af7cd89e..e7f84e1f46 100644
--- a/lib/AST/DeclGroup.cpp
+++ b/lib/AST/DeclGroup.cpp
@@ -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);
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 63484d1b87..8e43f99b67 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -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,
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index ff6de25c1d..67af285315 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -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);