Lazy __FUNCTION__ processing.

Zack Weinberg zackw@Stanford.EDU
Fri Apr 20 09:15:00 GMT 2001

On Fri, Apr 20, 2001 at 03:44:32PM +0100, Nathan Sidwell wrote:
> Hi,
> here's a patch which implements lazy processing of __FUNCTION__,
> __PRETTY_FUNCTION__ and __func__. The current implementation instantiates
> these VAR_DECLS at the start of every function, and then takes steps
> to remove them if they were unused. This implementation makes them
> keywords which can either be intercepted in the lexer (to generate
> string constants), or in the parser (to generate a VAR_DECL).

> The savings are not just the string values, but also the number of
> array types and var_decls. (The var decls will be gc'd, but the
> others not so.)
> So a saving of around 6% in memory. The one number that went up is
> the number of block trees, I'm not sure why that is.

prune_unused_decls used to eliminate BLOCK nodes that contained no
decls.  Instead of putting it back, we should try to figure out where
the unnecessary BLOCKs are coming from, and not generate them in the
first place.

The patch looks good to me, I have one question: in, is it still necessary to have this chunk of

      /* A user-invisible read-only initialized variable
         should be replaced by its value.
         We handle only strings since that's the only case used in C.  */
      else if (TREE_CODE (decl) == VAR_DECL
               && DECL_IGNORED_P (decl)
               && TREE_READONLY (decl)
               && DECL_INITIAL (decl) != 0
               && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
          tree stringval = DECL_INITIAL (decl);

          /* Copy the string value so that we won't clobber anything
             if we put something in the TREE_CHAIN of this one.  */
          yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
                                       TREE_STRING_POINTER (stringval));
          return STRING;

And you can/should return yycode from the if (C_IS_RESERVED_WORD)
block immediately above, instead of looking it up twice.  I might 
also rearrange the code such that the normal case, i.e. not
STRING_FUNC_NAME, is straight line.


More information about the Gcc-patches mailing list