[cfe-commits] r66025 - in /cfe/trunk: include/clang/Lex/Preprocessor.h include/clang/Lex/TokenLexer.h lib/Lex/TokenLexer.cpp
Chris Lattner
sabre at nondot.org
Tue Mar 3 22:50:57 PST 2009
Author: lattner
Date: Wed Mar 4 00:50:57 2009
New Revision: 66025
URL: http://llvm.org/viewvc/llvm-project?rev=66025&view=rev
Log:
make the token lexer allocate its temporary token buffers for
preexpanded macro arguments from the preprocessor's bump pointer.
This reduces # mallocs from 12444 to 11792.
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Lex/TokenLexer.h
cfe/trunk/lib/Lex/TokenLexer.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=66025&r1=66024&r2=66025&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Mar 4 00:50:57 2009
@@ -205,6 +205,8 @@
IdentifierTable &getIdentifierTable() { return Identifiers; }
SelectorTable &getSelectorTable() { return Selectors; }
+ llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
+
void setPTHManager(PTHManager* pm);
Modified: cfe/trunk/include/clang/Lex/TokenLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenLexer.h?rev=66025&r1=66024&r2=66025&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/TokenLexer.h (original)
+++ cfe/trunk/include/clang/Lex/TokenLexer.h Wed Mar 4 00:50:57 2009
@@ -42,7 +42,10 @@
/// Tokens - This is the pointer to an array of tokens that the macro is
/// defined to, with arguments expanded for function-like macros. If this is
- /// a token stream, these are the tokens we are returning.
+ /// a token stream, these are the tokens we are returning. This points into
+ /// the macro definition we are lexing from, a scratch buffer allocated from
+ /// the preprocessor's bump pointer allocator, or some other buffer that we
+ /// may or may not own (depending on OwnsTokens).
const Token *Tokens;
/// NumTokens - This is the length of the Tokens array.
Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=66025&r1=66024&r2=66025&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Wed Mar 4 00:50:57 2009
@@ -88,6 +88,7 @@
if (OwnsTokens) {
delete [] Tokens;
Tokens = 0;
+ OwnsTokens = false;
}
// TokenLexer owns its formal arguments.
@@ -264,13 +265,19 @@
// If anything changed, install this as the new Tokens list.
if (MadeChange) {
+ assert(!OwnsTokens && "This would leak if we already own the token list");
// This is deleted in the dtor.
NumTokens = ResultToks.size();
- Token *Res = new Token[ResultToks.size()];
+ llvm::BumpPtrAllocator &Alloc = PP.getPreprocessorAllocator();
+ Token *Res =
+ static_cast<Token *>(Alloc.Allocate(sizeof(Token)*ResultToks.size(),
+ llvm::alignof<Token>()));
if (NumTokens)
memcpy(Res, &ResultToks[0], NumTokens*sizeof(Token));
Tokens = Res;
- OwnsTokens = true;
+
+ // The preprocessor bump pointer owns these tokens, not us.
+ OwnsTokens = false;
}
}
More information about the cfe-commits
mailing list