set up the machinery for a MacroArgs cache hanging off Preprocessor.
We creating and free thousands of MacroArgs objects (and the related std::vectors hanging off them) for the testcase in PR5610 even though there are only ~20 live at a time. This doesn't actually use the cache yet. llvm-svn: 91391
This commit is contained in:
parent
45430bbfaa
commit
d19564b109
|
@ -177,8 +177,14 @@ class Preprocessor {
|
||||||
|
|
||||||
/// MICache - A "freelist" of MacroInfo objects that can be reused for quick
|
/// MICache - A "freelist" of MacroInfo objects that can be reused for quick
|
||||||
/// allocation.
|
/// allocation.
|
||||||
|
/// FIXME: why not use a singly linked list?
|
||||||
std::vector<MacroInfo*> MICache;
|
std::vector<MacroInfo*> MICache;
|
||||||
|
|
||||||
|
/// MacroArgCache - This is a "freelist" of MacroArg objects that can be
|
||||||
|
/// reused for quick allocation.
|
||||||
|
MacroArgs *MacroArgCache;
|
||||||
|
friend class MacroArgs;
|
||||||
|
|
||||||
// Various statistics we track for performance analysis.
|
// Various statistics we track for performance analysis.
|
||||||
unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma;
|
unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma;
|
||||||
unsigned NumIf, NumElse, NumEndif;
|
unsigned NumIf, NumElse, NumEndif;
|
||||||
|
|
|
@ -48,6 +48,19 @@ void MacroArgs::destroy(Preprocessor &PP) {
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// deallocate - This should only be called by the Preprocessor when managing
|
||||||
|
/// its freelist.
|
||||||
|
MacroArgs *MacroArgs::deallocate() {
|
||||||
|
MacroArgs *Next = ArgCache;
|
||||||
|
|
||||||
|
// Run the dtor to deallocate the vectors.
|
||||||
|
this->~MacroArgs();
|
||||||
|
// Release the memory for the object.
|
||||||
|
free(this);
|
||||||
|
|
||||||
|
return Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// getArgLength - Given a pointer to an expanded or unexpanded argument,
|
/// getArgLength - Given a pointer to an expanded or unexpanded argument,
|
||||||
/// return the number of tokens, not counting the EOF, that make up the
|
/// return the number of tokens, not counting the EOF, that make up the
|
||||||
|
|
|
@ -46,8 +46,12 @@ class MacroArgs {
|
||||||
/// stringified form of an argument has not yet been computed, this is empty.
|
/// stringified form of an argument has not yet been computed, this is empty.
|
||||||
std::vector<Token> StringifiedArgs;
|
std::vector<Token> StringifiedArgs;
|
||||||
|
|
||||||
|
/// ArgCache - This is a linked list of MacroArgs objects that the
|
||||||
|
/// Preprocessor owns which we use to avoid thrashing malloc/free.
|
||||||
|
MacroArgs *ArgCache;
|
||||||
|
|
||||||
MacroArgs(unsigned NumToks, bool varargsElided)
|
MacroArgs(unsigned NumToks, bool varargsElided)
|
||||||
: NumUnexpArgTokens(NumToks), VarargsElided(varargsElided) {}
|
: NumUnexpArgTokens(NumToks), VarargsElided(varargsElided), ArgCache(0) {}
|
||||||
~MacroArgs() {}
|
~MacroArgs() {}
|
||||||
public:
|
public:
|
||||||
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
|
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
|
||||||
|
@ -103,6 +107,11 @@ public:
|
||||||
///
|
///
|
||||||
static Token StringifyArgument(const Token *ArgToks,
|
static Token StringifyArgument(const Token *ArgToks,
|
||||||
Preprocessor &PP, bool Charify = false);
|
Preprocessor &PP, bool Charify = false);
|
||||||
|
|
||||||
|
|
||||||
|
/// deallocate - This should only be called by the Preprocessor when managing
|
||||||
|
/// its freelist.
|
||||||
|
MacroArgs *deallocate();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "clang/Lex/Preprocessor.h"
|
#include "clang/Lex/Preprocessor.h"
|
||||||
|
#include "MacroArgs.h"
|
||||||
#include "clang/Lex/HeaderSearch.h"
|
#include "clang/Lex/HeaderSearch.h"
|
||||||
#include "clang/Lex/MacroInfo.h"
|
#include "clang/Lex/MacroInfo.h"
|
||||||
#include "clang/Lex/Pragma.h"
|
#include "clang/Lex/Pragma.h"
|
||||||
|
@ -51,7 +52,7 @@ Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts,
|
||||||
: Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()),
|
: Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()),
|
||||||
SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup),
|
SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup),
|
||||||
BuiltinInfo(Target), CodeCompletionFile(0), CurPPLexer(0), CurDirLookup(0),
|
BuiltinInfo(Target), CodeCompletionFile(0), CurPPLexer(0), CurDirLookup(0),
|
||||||
Callbacks(0) {
|
Callbacks(0), MacroArgCache(0) {
|
||||||
ScratchBuf = new ScratchBuffer(SourceMgr);
|
ScratchBuf = new ScratchBuffer(SourceMgr);
|
||||||
CounterValue = 0; // __COUNTER__ starts at 0.
|
CounterValue = 0; // __COUNTER__ starts at 0.
|
||||||
OwnsHeaderSearch = OwnsHeaders;
|
OwnsHeaderSearch = OwnsHeaders;
|
||||||
|
@ -112,6 +113,10 @@ Preprocessor::~Preprocessor() {
|
||||||
for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i)
|
for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i)
|
||||||
delete TokenLexerCache[i];
|
delete TokenLexerCache[i];
|
||||||
|
|
||||||
|
// Free any cached MacroArgs.
|
||||||
|
for (MacroArgs *ArgList = MacroArgCache; ArgList; )
|
||||||
|
ArgList = ArgList->deallocate();
|
||||||
|
|
||||||
// Release pragma information.
|
// Release pragma information.
|
||||||
delete PragmaHandlers;
|
delete PragmaHandlers;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue