This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Subject: Removing the arg_index field from cpp_hashnode


Large compiles generate lots of IDENTIFIER_NODEs, each of which
has many fields, most of which are little used.  We can save a
lot of space by being a little more careful.

I suggest we start out by getting rid of the arg_index field of
cpp_hashnode, which is embedded in all IDENTIFIER_NODE for C/C++/ObjC.
Getting rid of arg_index directly saves 16 bits; on 32-bit machines it
saves a whole 4 bytes due to alignment.

As far as I can tell, the arg_index field is only used during
the processing of a #define, to determine which identifiers in
the macro expansion are macro parameters, and to catch duplicate
macro parameter names.

A simple replacement is to add a new flag:
#define NODE_MACROARG   (1 << 6)  /* Parameter in current macro def. */
When a macro parameter is seen, the NODE_MACROARG bit is set in the
flags field of the cpp_hashnode.  The bit is cleared at the end of the
macro definition, just as we currently clear arg_index.  Testing for
duplicate parameter names is trivial:  Just check the bit.

Harder is modifying lex_expansion_token, when we need to set the
arg_no of the CPP_MACROARG token.  An easy fix is to search the
argument list linearly looking for a match.  This causes O(M*N)
behavior, when M is the number of parameters, and N is the number
of references in the macro definition.  In practice both are likely
to be small, but on general principles we to avoid quadratic
algorithms.  And it is easy to avoid it.

The solution is to stash the arg_index in the cpp_hashnode, but
only during definition processing - i.e. only when the NODE_MACROARG
bit is set.  So we can stash the arg_index anywhere in the cpp_hashnode
that is not used during definition processing.  We need to save the
old value somewhere, and then restore it when we're done with the
define.  We can use the rid_code field for example - except that it
is only 8 bits (and I'd like to remove that field too).

My preferred choice would be to add an arg_index variant to the
'value' union.  Then setting CPP_MACROARG would also save the
entire union in a buffer, and _cpp_create_definition would
restore the entire union from the buffer.  But I don't know
if any of the fields are used using define processing.  Zack?

I'll implement and test this, assuming people think it is worthwhile.
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]