This is the mail archive of the gcc-patches@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]

Re: [PATCH] Speed-up get_identifier("main") (take 2)


On Thu, Aug 07, 2003 at 07:38:26AM -0600, Roger Sayle wrote:
> 
> On Wed, 6 Aug 2003, Zack Weinberg wrote:
> > I like the general idea.  I'm wondering if it makes sense to make
> > get_identifier itself be this macro; the definition of get_identifier
> > is functionally identical to the macro, and it would avoid having to
> > change most of the uses of get_identifier.  However, it might hurt
> > code size.  Could you experiment, please?
> 
> Ok here's the patch I came up with.  The warts this time are that we
> have to ensure the arguments to get_identifier are free from
> side-effects, otherwise the behaviour changes.  I'm sure we could
> do something clever to avoid re-evaluation, but I suspect it would
> be either non-portable or defeat the purpose of getting strlen,
> a constant string literal.
> 
> The text size of cc1 increases from 4241925 to 4243589 (1664 bytes),
> the size of cc1plus increases from 5173765 to 5180021 (6256 bytes)
> and the text size of jc1 increases from 4343280 to 4347504 (4224 bytes).
> I think I can decrease these a bit by judicious use of temporary
> variables in a few places.
> 
> 
> I also like the proposed __builtin_constant_p solution.  Unfortunately,
> GCC doesn't currently use __builtin_constant_p during stage1 and I'd be
> completely unable to implement the necessary configure checks myself.

Why do you need any configure checks?
Simple
#if GCC_VERSION >= 3000
# define get_identifier(str) \
  (__builtin_constant_p (str)						\
   ? get_identifier_with_length ((str), (unsigned) strlen (str))	\
   : get_identifier (str))
#endif

should do the job and you don't have to worry about side-effects.
There is already a precedent, in genconditions.c __builtin_constant_p
is surrounded by:

#if (GCC_VERSION >= 3001) || ((GCC_VERSION == 3000) && !__OPTIMIZE__)

but in that case it is because gcc 3.0 did not handle __builtin_constant_p
in initializers.

	Jakub


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