forked from OSchip/llvm-project
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:
parent
c1410dc1e6
commit
7a4af3b73d
|
@ -26,12 +26,12 @@ using namespace clang;
|
||||||
|
|
||||||
/// MacroArgs ctor function - This destroys the vector passed in.
|
/// MacroArgs ctor function - This destroys the vector passed in.
|
||||||
MacroArgs *MacroArgs::create(const MacroInfo *MI,
|
MacroArgs *MacroArgs::create(const MacroInfo *MI,
|
||||||
const std::vector<LexerToken> &UnexpArgTokens) {
|
const LexerToken *UnexpArgTokens,
|
||||||
|
unsigned NumToks) {
|
||||||
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.
|
||||||
unsigned NumToks = UnexpArgTokens.size();
|
|
||||||
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
|
MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
|
||||||
NumToks*sizeof(LexerToken));
|
NumToks*sizeof(LexerToken));
|
||||||
// Construct the macroargs object.
|
// 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.
|
// Copy the actual unexpanded tokens to immediately after the result ptr.
|
||||||
if (NumToks)
|
if (NumToks)
|
||||||
memcpy(const_cast<LexerToken*>(Result->getUnexpArgument(0)),
|
memcpy(const_cast<LexerToken*>(Result->getUnexpArgument(0)),
|
||||||
&UnexpArgTokens[0], NumToks*sizeof(LexerToken));
|
UnexpArgTokens, NumToks*sizeof(LexerToken));
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "clang/Basic/Diagnostic.h"
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/Basic/FileManager.h"
|
#include "clang/Basic/FileManager.h"
|
||||||
#include "clang/Basic/SourceManager.h"
|
#include "clang/Basic/SourceManager.h"
|
||||||
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
@ -709,8 +710,9 @@ MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(LexerToken &MacroName,
|
||||||
--NumFixedArgsLeft; // Start reading the first arg.
|
--NumFixedArgsLeft; // Start reading the first arg.
|
||||||
|
|
||||||
// ArgTokens - Build up a list of tokens that make up each argument. Each
|
// ArgTokens - Build up a list of tokens that make up each argument. Each
|
||||||
// argument is separated by an EOF token.
|
// argument is separated by an EOF token. Use a SmallVector so we can avoid
|
||||||
std::vector<LexerToken> ArgTokens;
|
// heap allocations in the common case.
|
||||||
|
SmallVector<LexerToken, 64> ArgTokens;
|
||||||
|
|
||||||
unsigned NumActuals = 0;
|
unsigned NumActuals = 0;
|
||||||
while (Tok.getKind() == tok::comma) {
|
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
|
/// ComputeDATE_TIME - Compute the current time, enter it into the specified
|
||||||
|
|
|
@ -47,7 +47,8 @@ public:
|
||||||
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
|
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
|
||||||
/// macro and argument info.
|
/// macro and argument info.
|
||||||
static MacroArgs *create(const MacroInfo *MI,
|
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.
|
/// destroy - Destroy and deallocate the memory for this object.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue