[cfe-commits] r61042 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/PPDirectives.cpp lib/Lex/PPMacroExpansion.cpp lib/Lex/Preprocessor.cpp
Chris Lattner
clattner at apple.com
Wed Dec 17 21:06:25 PST 2008
On Dec 15, 2008, at 11:56 AM, Ted Kremenek wrote:
> Author: kremenek
> Date: Mon Dec 15 13:56:42 2008
> New Revision: 61042
>
> URL: http://llvm.org/viewvc/llvm-project?rev=61042&view=rev
> Log:
> 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%.
Very nice! This also substantially sped us up on INPUTS/
macro_pounder_*.c. We're now faster than GCC on _fn and within 2x of
it on _obj:
(min of three runs for each):
$ time ~/llvm/Release-Asserts/bin/clang INPUTS/macro_pounder_fn.c -E
> /dev/null
1.834u 0.005s 0:01.84 99.4% 0+0k 0+0io 0pf+0w
$ time gcc -E INPUTS/macro_pounder_fn.c > /dev/null
2.043u 0.151s 0:02.19 100.0% 0+0k 0+0io 0pf+0w
$ time ~/llvm/Release-Asserts/bin/clang INPUTS/macro_pounder_obj.c -E
> /dev/null
0.415u 0.003s 0:00.42 97.6% 0+0k 0+0io 0pf+0w
$ time gcc -E INPUTS/macro_pounder_obj.c > /dev/null
0.267u 0.040s 0:00.31 96.7% 0+0k 0+0io 0pf+0w
We used to be substantially slower at both of these, largely do to
alloc/dealloc of macro info.
> +++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Dec 15 13:56:42 2008
> @@ -95,9 +95,9 @@
> // Free any macro definitions.
> for (llvm::DenseMap<IdentifierInfo*, MacroInfo*>::iterator I =
> Macros.begin(), E = Macros.end(); I != E; ++I) {
> - // Free the macro definition.
> - delete I->second;
> - I->second = 0;
> + // We don't need to free the MacroInfo objects directly. These
> + // will be released when the BumpPtrAllocator 'BP' object gets
> + // destroyed.
> I->first->setHasMacroDefinition(false);
> }
Please make sure that the code runs the MacroInfo destructor at the
appropriate times. The ReplacementTokens member has a dtor that must
be run to avoid leaking memory.
Thanks Ted,
-Chris
More information about the cfe-commits
mailing list