This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpplib: Identity macro optimisation
- To: gcc-patches at gcc dot gnu dot org
- Subject: cpplib: Identity macro optimisation
- From: Neil Booth <NeilB at earthling dot net>
- Date: Sun, 29 Oct 2000 10:57:53 +0000
[Oops, the previous post was the wrong diff file].
With the new macro code, the optimisation of a macro defined to
itself is trivial.
Neil.
* cppmacro.c (_cpp_create_definition): Optimize the case of
a macro defined to itself.
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cppmacro.c,v
retrieving revision 1.13
diff -u -p -r1.13 cppmacro.c
--- cppmacro.c 2000/10/28 17:59:06 1.13
+++ cppmacro.c 2000/10/29 10:39:59
@@ -1403,7 +1403,6 @@ _cpp_create_definition (pfile, node)
macro->paramc = 0;
macro->fun_like = 0;
macro->var_args = 0;
- macro->disabled = 0;
macro->count = 0;
macro->expansion = (cpp_token *) POOL_FRONT (&pfile->macro_pool);
@@ -1484,6 +1483,11 @@ _cpp_create_definition (pfile, node)
/* Clear the whitespace flag from the leading token. */
macro->expansion[0].flags &= ~PREV_WHITE;
+
+ /* Implement the macro-defined-to-itself optimisation. */
+ macro->disabled = (macro->count == 1 && !macro->fun_like
+ && macro->expansion[0].type == CPP_NAME
+ && macro->expansion[0].val.node == node);
/* Commit the memory. */
POOL_COMMIT (&pfile->macro_pool, macro->count * sizeof (cpp_token));