[cfe-commits] r109375 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/AST/DeclarationName.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp
Douglas Gregor
dgregor at apple.com
Sun Jul 25 10:53:34 PDT 2010
Author: dgregor
Date: Sun Jul 25 12:53:33 2010
New Revision: 109375
URL: http://llvm.org/viewvc/llvm-project?rev=109375&view=rev
Log:
Make ASTContext always use the BumpPtrAllocator.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclarationName.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=109375&r1=109374&r2=109375&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Jul 25 12:53:33 2010
@@ -275,9 +275,10 @@
/// this ASTContext object.
LangOptions LangOpts;
- /// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
- bool FreeMemory;
- llvm::MallocAllocator MallocAlloc;
+ /// \brief The allocator used to create AST objects.
+ ///
+ /// AST objects are never destructed; rather, all memory associated with the
+ /// AST objects will be released when the ASTContext itself is destroyed.
llvm::BumpPtrAllocator BumpAlloc;
/// \brief Allocator for partial diagnostics.
@@ -301,13 +302,9 @@
SourceManager& getSourceManager() { return SourceMgr; }
const SourceManager& getSourceManager() const { return SourceMgr; }
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);
+ return BumpAlloc.Allocate(Size, Align);
}
+ void Deallocate(void *Ptr) { }
PartialDiagnostic::StorageAllocator &getDiagAllocator() {
return DiagAllocator;
@@ -393,7 +390,7 @@
ASTContext(const LangOptions& LOpts, SourceManager &SM, const TargetInfo &t,
IdentifierTable &idents, SelectorTable &sels,
Builtin::Context &builtins,
- bool FreeMemory = true, unsigned size_reserve=0);
+ unsigned size_reserve);
~ASTContext();
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=109375&r1=109374&r2=109375&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Jul 25 12:53:33 2010
@@ -138,7 +138,7 @@
const TargetInfo &t,
IdentifierTable &idents, SelectorTable &sels,
Builtin::Context &builtins,
- bool FreeMem, unsigned size_reserve) :
+ unsigned size_reserve) :
TemplateSpecializationTypes(this_()),
DependentTemplateSpecializationTypes(this_()),
GlobalNestedNameSpecifier(0), IsInt128Installed(false),
@@ -146,7 +146,7 @@
ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0),
sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0),
NullTypeSourceInfo(QualType()),
- SourceMgr(SM), LangOpts(LOpts), FreeMemory(FreeMem), Target(t),
+ SourceMgr(SM), LangOpts(LOpts), Target(t),
Idents(idents), Selectors(sels),
BuiltinInfo(builtins),
DeclarationNames(*this),
@@ -155,7 +155,7 @@
UniqueBlockByRefTypeID(0), UniqueBlockParmTypeID(0) {
ObjCIdRedefinitionType = QualType();
ObjCClassRedefinitionType = QualType();
- ObjCSelRedefinitionType = QualType();
+ ObjCSelRedefinitionType = QualType();
if (size_reserve > 0) Types.reserve(size_reserve);
TUDecl = TranslationUnitDecl::Create(*this);
InitBuiltinTypes();
@@ -166,11 +166,9 @@
// FIXME: Is this the ideal solution?
ReleaseDeclContextMaps();
- if (!FreeMemory) {
- // Call all of the deallocation functions.
- for (unsigned I = 0, N = Deallocations.size(); I != N; ++I)
- Deallocations[I].first(Deallocations[I].second);
- }
+ // Call all of the deallocation functions.
+ for (unsigned I = 0, N = Deallocations.size(); I != N; ++I)
+ Deallocations[I].first(Deallocations[I].second);
// Release all of the memory associated with overridden C++ methods.
for (llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::iterator
@@ -178,53 +176,23 @@
OM != OMEnd; ++OM)
OM->second.Destroy();
- if (FreeMemory) {
- // Deallocate all the types.
- while (!Types.empty()) {
- Types.back()->Destroy(*this);
- Types.pop_back();
- }
-
- for (llvm::FoldingSet<ExtQuals>::iterator
- I = ExtQualNodes.begin(), E = ExtQualNodes.end(); I != E; ) {
- // Increment in loop to prevent using deallocated memory.
- Deallocate(&*I++);
- }
-
- for (llvm::DenseMap<const ObjCContainerDecl*,
- const ASTRecordLayout*>::iterator
- I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) {
- // Increment in loop to prevent using deallocated memory.
- if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second))
- R->Destroy(*this);
- }
- }
-
// ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
- // even when using the BumpPtrAllocator because they can contain
- // DenseMaps.
+ // because they can contain DenseMaps.
+ for (llvm::DenseMap<const ObjCContainerDecl*,
+ const ASTRecordLayout*>::iterator
+ I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; )
+ // Increment in loop to prevent using deallocated memory.
+ if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second))
+ R->Destroy(*this);
+
for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
// Increment in loop to prevent using deallocated memory.
if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second))
R->Destroy(*this);
}
-
- // Destroy nested-name-specifiers.
- for (llvm::FoldingSet<NestedNameSpecifier>::iterator
- NNS = NestedNameSpecifiers.begin(),
- NNSEnd = NestedNameSpecifiers.end();
- NNS != NNSEnd; ) {
- // Increment in loop to prevent using deallocated memory.
- (*NNS++).Destroy(*this);
}
- if (GlobalNestedNameSpecifier)
- GlobalNestedNameSpecifier->Destroy(*this);
-
- TUDecl->Destroy(*this);
-}
-
void ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) {
Deallocations.push_back(std::make_pair(Callback, Data));
}
@@ -275,16 +243,12 @@
fprintf(stderr, " %u/%u implicit destructors created\n",
NumImplicitDestructorsDeclared, NumImplicitDestructors);
- if (!FreeMemory)
- BumpAlloc.PrintStats();
-
if (ExternalSource.get()) {
fprintf(stderr, "\n");
ExternalSource->PrintStats();
}
- if (!FreeMemory)
- BumpAlloc.PrintStats();
+ BumpAlloc.PrintStats();
}
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=109375&r1=109374&r2=109375&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Sun Jul 25 12:53:33 2010
@@ -404,26 +404,6 @@
= static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
(CXXLiteralOperatorNames);
- if (Ctx.FreeMemory) {
- llvm::FoldingSetIterator<CXXSpecialName>
- SI = SpecialNames->begin(), SE = SpecialNames->end();
-
- while (SI != SE) {
- CXXSpecialName *n = &*SI++;
- Ctx.Deallocate(n);
- }
-
- llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
- LI = LiteralNames->begin(), LE = LiteralNames->end();
-
- while (LI != LE) {
- CXXLiteralOperatorIdName *n = &*LI++;
- Ctx.Deallocate(n);
- }
-
- Ctx.Deallocate(CXXOperatorNames);
- }
-
delete SpecialNames;
delete LiteralNames;
}
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=109375&r1=109374&r2=109375&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sun Jul 25 12:53:33 2010
@@ -255,7 +255,6 @@
PP.getIdentifierTable(),
PP.getSelectorTable(),
PP.getBuiltinInfo(),
- /* FreeMemory = */ false,
/* size_reserve = */0));
ASTContext &Context = *AST->Ctx.get();
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=109375&r1=109374&r2=109375&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sun Jul 25 12:53:33 2010
@@ -245,7 +245,6 @@
Context.reset(new ASTContext(getLangOpts(), PP.getSourceManager(),
getTarget(), PP.getIdentifierTable(),
PP.getSelectorTable(), PP.getBuiltinInfo(),
- /*FreeMemory=*/ !getFrontendOpts().DisableFree,
/*size_reserve=*/ 0));
}
More information about the cfe-commits
mailing list