[cfe-commits] r103426 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/DeclarationName.h lib/AST/ASTContext.cpp lib/AST/DeclarationName.cpp
Ted Kremenek
kremenek at apple.com
Mon May 10 13:40:08 PDT 2010
Author: kremenek
Date: Mon May 10 15:40:08 2010
New Revision: 103426
URL: http://llvm.org/viewvc/llvm-project?rev=103426&view=rev
Log:
Start converting pieces of DeclarationNameTable to be allocated using ASTContext's allocator.
While DeclarationNameTable doesn't leak, it uses 'malloc' too often. Start with having
'CXXLiteralOperatorNames' allocated using ASTContext's allocator and add a 'DoDestroy()' method
to DeclarationNameTable that is called by ~ASTContext.
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/DeclarationName.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclarationName.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=103426&r1=103425&r2=103426&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon May 10 15:40:08 2010
@@ -1294,6 +1294,7 @@
// but we include it here so that ASTContext can quickly deallocate them.
llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
friend class DeclContext;
+ friend class DeclarationNameTable;
void ReleaseDeclContextMaps();
};
Modified: cfe/trunk/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=103426&r1=103425&r2=103426&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Mon May 10 15:40:08 2010
@@ -316,15 +316,19 @@
class DeclarationNameTable {
void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
CXXOperatorIdName *CXXOperatorNames; // Operator names
- void *CXXLiteralOperatorNames; // Actually a FoldingSet<...> *
+ void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
DeclarationNameTable(const DeclarationNameTable&); // NONCOPYABLE
DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE
public:
- DeclarationNameTable();
+ DeclarationNameTable(ASTContext &C);
~DeclarationNameTable();
+ /// Free all memory allocated associated with this DeclarationTable that
+ // is used allocated using the specified ASTContext object.
+ void DoDestroy(ASTContext &C);
+
/// getIdentifier - Create a declaration name that is a simple
/// identifier.
DeclarationName getIdentifier(const IdentifierInfo *ID) {
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=103426&r1=103425&r2=103426&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon May 10 15:40:08 2010
@@ -46,7 +46,9 @@
sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0),
SourceMgr(SM), LangOpts(LOpts), FreeMemory(FreeMem), Target(t),
Idents(idents), Selectors(sels),
- BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts),
+ BuiltinInfo(builtins),
+ DeclarationNames(*this),
+ ExternalSource(0), PrintingPolicy(LOpts),
LastSDM(0, 0) {
ObjCIdRedefinitionType = QualType();
ObjCClassRedefinitionType = QualType();
@@ -108,6 +110,9 @@
if (GlobalNestedNameSpecifier)
GlobalNestedNameSpecifier->Destroy(*this);
+ // Deallocate the memory associated with the DeclarationNameTable.
+ DeclarationNames.DoDestroy(*this);
+
TUDecl->Destroy(*this);
}
Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=103426&r1=103425&r2=103426&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Mon May 10 15:40:08 2010
@@ -11,10 +11,11 @@
// classes.
//
//===----------------------------------------------------------------------===//
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeOrdering.h"
-#include "clang/AST/Decl.h"
#include "clang/Basic/IdentifierTable.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
@@ -383,12 +384,12 @@
llvm::errs() << '\n';
}
-DeclarationNameTable::DeclarationNameTable() {
+DeclarationNameTable::DeclarationNameTable(ASTContext &C) {
CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
// Initialize the overloaded operator names.
- CXXOperatorNames = new CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
+ CXXOperatorNames = new (C) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
CXXOperatorNames[Op].ExtraKindOrNumArgs
= Op + DeclarationNameExtra::CXXConversionFunction;
@@ -421,7 +422,12 @@
delete SpecialNames;
delete LiteralNames;
- delete [] CXXOperatorNames;
+}
+
+void DeclarationNameTable::DoDestroy(ASTContext &C) {
+ if (C.FreeMemory) {
+ C.Deallocate(CXXOperatorNames);
+ }
}
DeclarationName
More information about the cfe-commits
mailing list