eagerly resolve the spelling locations of macro argument preexpansions.
This reduces fsyntax-only time on c99-intconst-1.c from 2.43s down to 2.01s (20%), reducing the number of fileid lookups from 2529040 linear and 64771121 binary to 5625902 linear and 4151182 binary. This knocks getFileID down to only 4.6% of compile time on this testcase. At this point, malloc/free is over 35% of compile time, primarily allocating MacroArgs objects and their argument preexpansion vectors. I don't feel like malloc avoiding right now, so I'm just going to call this good. llvm-svn: 62994
This commit is contained in:
parent
5a5d67101b
commit
ad13cf4e7a
|
@ -23,7 +23,7 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
|
||||||
unsigned NumToks, bool VarargsElided) {
|
unsigned NumToks, bool VarargsElided) {
|
||||||
assert(MI->isFunctionLike() &&
|
assert(MI->isFunctionLike() &&
|
||||||
"Can't have args for an object-like macro!");
|
"Can't have args for an object-like macro!");
|
||||||
|
|
||||||
// Allocate memory for the MacroArgs object with the lexer tokens at the end.
|
// Allocate memory for the MacroArgs object with the lexer tokens at the end.
|
||||||
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
|
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
|
||||||
NumToks*sizeof(Token));
|
NumToks*sizeof(Token));
|
||||||
|
@ -118,7 +118,14 @@ MacroArgs::getPreExpArgument(unsigned Arg, Preprocessor &PP) {
|
||||||
// Lex all of the macro-expanded tokens into Result.
|
// Lex all of the macro-expanded tokens into Result.
|
||||||
do {
|
do {
|
||||||
Result.push_back(Token());
|
Result.push_back(Token());
|
||||||
PP.Lex(Result.back());
|
Token &Tok = Result.back();
|
||||||
|
PP.Lex(Tok);
|
||||||
|
|
||||||
|
// Eagerly resolve instantiation ID's to their spelling location. This
|
||||||
|
// makes it so we only have to get the spelling loc once per macro argument
|
||||||
|
// preexpansion instead of once per each time the token is expanded.
|
||||||
|
if (!Tok.getLocation().isFileID())
|
||||||
|
Tok.setLocation(PP.getSourceManager().getSpellingLoc(Tok.getLocation()));
|
||||||
} while (Result.back().isNot(tok::eof));
|
} while (Result.back().isNot(tok::eof));
|
||||||
|
|
||||||
// Pop the token stream off the top of the stack. We know that the internal
|
// Pop the token stream off the top of the stack. We know that the internal
|
||||||
|
|
|
@ -359,7 +359,7 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(Token &MacroName,
|
||||||
Token EOFTok;
|
Token EOFTok;
|
||||||
EOFTok.startToken();
|
EOFTok.startToken();
|
||||||
EOFTok.setKind(tok::eof);
|
EOFTok.setKind(tok::eof);
|
||||||
EOFTok.setLocation(Tok.getLocation());
|
EOFTok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
|
||||||
EOFTok.setLength(0);
|
EOFTok.setLength(0);
|
||||||
ArgTokens.push_back(EOFTok);
|
ArgTokens.push_back(EOFTok);
|
||||||
++NumActuals;
|
++NumActuals;
|
||||||
|
|
Loading…
Reference in New Issue