summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-05-10 20:40:08 +0000
committerTed Kremenek <kremenek@apple.com>2010-05-10 20:40:08 +0000
commit6aead3a051a4d7c43e74b96ec25dbbf983f62d4e (patch)
tree1af29e55f9bf62d88460337bec4f725dbfa75062 /clang
parent103d4b43e9c19baab8db0388f72aa86bf013ec9e (diff)
downloadbcm5719-llvm-6aead3a051a4d7c43e74b96ec25dbbf983f62d4e.tar.gz
bcm5719-llvm-6aead3a051a4d7c43e74b96ec25dbbf983f62d4e.zip
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. llvm-svn: 103426
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTContext.h1
-rw-r--r--clang/include/clang/AST/DeclarationName.h8
-rw-r--r--clang/lib/AST/ASTContext.cpp7
-rw-r--r--clang/lib/AST/DeclarationName.cpp14
4 files changed, 23 insertions, 7 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index f8a8f179ae5..eed1dfd5970 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1294,6 +1294,7 @@ private:
// 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();
};
diff --git a/clang/include/clang/AST/DeclarationName.h b/clang/include/clang/AST/DeclarationName.h
index 94017865d4c..6e8316014e8 100644
--- a/clang/include/clang/AST/DeclarationName.h
+++ b/clang/include/clang/AST/DeclarationName.h
@@ -316,15 +316,19 @@ inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
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) {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 141f1b9bf93..3a8084833e4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -46,7 +46,9 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
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 @@ ASTContext::~ASTContext() {
if (GlobalNestedNameSpecifier)
GlobalNestedNameSpecifier->Destroy(*this);
+ // Deallocate the memory associated with the DeclarationNameTable.
+ DeclarationNames.DoDestroy(*this);
+
TUDecl->Destroy(*this);
}
diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp
index 4f85fca5386..06232833852 100644
--- a/clang/lib/AST/DeclarationName.cpp
+++ b/clang/lib/AST/DeclarationName.cpp
@@ -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 @@ void DeclarationName::dump() const {
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 @@ DeclarationNameTable::~DeclarationNameTable() {
delete SpecialNames;
delete LiteralNames;
- delete [] CXXOperatorNames;
+}
+
+void DeclarationNameTable::DoDestroy(ASTContext &C) {
+ if (C.FreeMemory) {
+ C.Deallocate(CXXOperatorNames);
+ }
}
DeclarationName
OpenPOWER on IntegriCloud