diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-05 22:27:05 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-05 22:27:05 +0000 |
commit | 64af53c364bcc20d18210432dbaa6d94186858ff (patch) | |
tree | 2c03835cca08077dd592fc50b0849a5042be05ca /clang/lib/AST | |
parent | f740db31e20e18c02ef29e02f1a61900f2be8403 (diff) | |
download | bcm5719-llvm-64af53c364bcc20d18210432dbaa6d94186858ff.tar.gz bcm5719-llvm-64af53c364bcc20d18210432dbaa6d94186858ff.zip |
When we deserialize a declaration from a module file, allocate extra
storage for the global declaration ID. Declarations that are parsed
(rather than deserialized) are unaffected, so the number of
declarations that pay this cost tends to be relatively small (since
relatively few declarations are ever deserialized).
This replaces a largish DenseMap within the AST reader. It's not
strictly a win in terms of memory use---not every declaration was
added to that DenseMap in the first place---but it's cleaner to have
this information available for every deserialized declaration, so that
future clients can rely on it.
llvm-svn: 147617
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 55484188c86..f4e5d43ee6c 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -44,7 +44,20 @@ static bool StatSwitch = false; void *Decl::AllocateDeserializedDecl(const ASTContext &Context, unsigned ID, unsigned Size) { - return Context.Allocate(Size); + // Allocate an extra pointer's worth of storage, which ensures that + // (1) We have enough storage to stash the global declaration ID, and + // (2) We maintain pointer alignment. + // + // Note that this wastes 4 bytes on x86-64, which we'll undoubtedly end up + // finding a use for later. + void *Start = Context.Allocate(Size + sizeof(void*)); + void *Result = (char*)Start + sizeof(void*); + + // Store the global declaration ID + unsigned *IDPtr = (unsigned*)Result - 1; + *IDPtr = ID; + + return Result; } const char *Decl::getDeclKindName() const { |