diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-15 19:56:42 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-15 19:56:42 +0000 |
commit | 0ea76727ae91bca918a8414ed85b530eddcfedeb (patch) | |
tree | 7a572aa8d11e2f4c95caabe869f41c5b0ca44b13 /include/clang/Lex/Preprocessor.h | |
parent | 55f7bcbda37964d3c0e8928d0e50a6e1692b7dce (diff) |
Preprocessor: Allocate MacroInfo objects using a BumpPtrAllocator instead using new/delete. This speeds up -Eonly on Cocoa.h using the regular lexer by 1.8% and the PTHLexer by 3%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61042 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex/Preprocessor.h')
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 77136688aa..efe057e334 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -24,6 +24,7 @@ #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/OwningPtr.h" +#include "llvm/Support/Allocator.h" namespace clang { @@ -55,6 +56,10 @@ class Preprocessor { /// PTH - An optional PTHManager object used for getting tokens from /// a token cache rather than lexing the original source file. llvm::OwningPtr<PTHManager> PTH; + + /// BP - A BumpPtrAllocator object used to quickly allocate and release + /// objects internal to the Preprocessor. + llvm::BumpPtrAllocator BP; /// Identifiers for builtin macros and other builtins. IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__ @@ -145,6 +150,10 @@ class Preprocessor { /// to the actual definition of the macro. llvm::DenseMap<IdentifierInfo*, MacroInfo*> Macros; + /// MICache - A "freelist" of MacroInfo objects that can be reused for quick + /// allocation. + std::vector<MacroInfo*> MICache; + // Various statistics we track for performance analysis. unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma; unsigned NumIf, NumElse, NumEndif; @@ -530,6 +539,16 @@ private: IncludeMacroStack.pop_back(); } + /// AllocateMacroInfo - Allocate a new MacroInfo object with the provide + /// SourceLocation. + MacroInfo* AllocateMacroInfo(SourceLocation L); + + /// ReleaseMacroInfo - Release the specified MacroInfo. This memory will + /// be reused for allocating new MacroInfo objects. + void ReleaseMacroInfo(MacroInfo* MI) { + MICache.push_back(MI); + } + /// isInPrimaryFile - Return true if we're in the top-level file, not in a /// #include. bool isInPrimaryFile() const; |