Change Preprocessor::ReadFunctionLikeMacroArgs to use a SmallVector to lex

argument tokens into instead of a real vector.  This avoids some malloc
traffic in common cases.  In an "abusive macro expansion" testcase, this
reduced -Eonly time by 25%.

llvm-svn: 38757
This commit is contained in:
Chris Lattner 2006-07-26 06:26:52 +00:00
parent c1410dc1e6
commit 7a4af3b73d
3 changed files with 10 additions and 7 deletions

View File

@ -26,12 +26,12 @@ using namespace clang;
/// MacroArgs ctor function - This destroys the vector passed in.
MacroArgs *MacroArgs::create(const MacroInfo *MI,
const std::vector<LexerToken> &UnexpArgTokens) {
const LexerToken *UnexpArgTokens,
unsigned NumToks) {
assert(MI->isFunctionLike() &&
"Can't have args for an object-like macro!");
// Allocate memory for the MacroArgs object with the lexer tokens at the end.
unsigned NumToks = UnexpArgTokens.size();
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
NumToks*sizeof(LexerToken));
// Construct the macroargs object.
@ -40,7 +40,7 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
// Copy the actual unexpanded tokens to immediately after the result ptr.
if (NumToks)
memcpy(const_cast<LexerToken*>(Result->getUnexpArgument(0)),
&UnexpArgTokens[0], NumToks*sizeof(LexerToken));
UnexpArgTokens, NumToks*sizeof(LexerToken));
return Result;
}

View File

@ -33,6 +33,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/SmallVector.h"
#include <iostream>
using namespace llvm;
using namespace clang;
@ -709,8 +710,9 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
--NumFixedArgsLeft; // Start reading the first arg.
// ArgTokens - Build up a list of tokens that make up each argument. Each
// argument is separated by an EOF token.
std::vector<LexerToken> ArgTokens;
// argument is separated by an EOF token. Use a SmallVector so we can avoid
// heap allocations in the common case.
SmallVector<LexerToken, 64> ArgTokens;
unsigned NumActuals = 0;
while (Tok.getKind() == tok::comma) {
@ -808,7 +810,7 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
}
}
return MacroArgs::create(MI, ArgTokens);
return MacroArgs::create(MI, &ArgTokens[0], ArgTokens.size());
}
/// ComputeDATE_TIME - Compute the current time, enter it into the specified

View File

@ -47,7 +47,8 @@ public:
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
/// macro and argument info.
static MacroArgs *create(const MacroInfo *MI,
const std::vector<LexerToken> &UnexpArgTokens);
const LexerToken *UnexpArgTokens,
unsigned NumArgTokens);
/// destroy - Destroy and deallocate the memory for this object.
///