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]

Re: patch to suggest putc/fputs over printf("string") or printf("\n")


 > From: Jeffrey A Law <law@hurl.cygnus.com>
 > 
 >   >     I suppose we need to know the stdout expansion for changing
 >   > printf() -> fputs(, stdout) and also for fprintf(stdout, "%s\n",) -> put$
 > I don't think that's sufficient.
 >
 > Consider that cpp would have to tell the compiler, hey, "stdout" looks like
 > this "&__iob[0]" or whatever.  The compiler would then have to build a
 > special node for the stdout node which could be substituted in during the
 > conversion.
 >
 > This is a case where clean separation of cpp, the parser, tree generation
 > makes life difficult.
 > jeff

 
        Would it help to emit the following code in each module subject
to this optimization?
 
 > #ifdef __OPTIMIZE__
 > #include <stdio.h> 
 > static FILE * __gcc_stdout __attribute__ ((__unused__)) = stdout;
 > static inline int __gcc_putc(char c, FILE* stream)
 > { return putc(c, stream); }
 > #endif /* __OPTIMIZE__ */  
 
        This allows us to always deal with __gcc_stdout as a variable
and __gcc_putc() as a function.  So the following:
  
 > printf ("\n");
 
becomes:
 
 > gcc_putc ('\n', __gcc_stdout);
 
When we substitute __gcc_putc() for a *printf() call, the optimizer's
inlining routines should expand it to putc().  And if putc() is a macro,
then even better cause that macro will have been expanded inside 
__gcc_putc() so inlining that function will be as fast as having used 
the putc() macro in the first place.
 
        I think emiting this code snippet would have to be done in cpp
which means we still have to make both cpp and cc1 cooperate for this 
optimization.

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Icon CMT Corp.


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