This is the mail archive of the
mailing list for the GCC project.
Re: Patch to add __builtin_printf("string\n") ->puts("string")
- To: ghazi at caip dot rutgers dot edu
- Subject: Re: Patch to add __builtin_printf("string\n") ->puts("string")
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Fri, 22 Sep 2000 08:54:26 -0700
- Cc: gdr at codesourcery dot com, gcc-patches at gcc dot gnu dot org, harinath at cs dot umn dot edu
- Organization: CodeSourcery, LLC
- References: <200009221345.JAA25378@caip.rutgers.edu>
>>>>> "Kaveh" == Kaveh R Ghazi <firstname.lastname@example.org> writes:
Kaveh> I suppose you could argue that the second string would
Kaveh> waste space but so far, in the sample code I manually
Kaveh> checked, these duplicates don't occur. In fact code size
Kaveh> went down due to all the string size reductions. So should
Kaveh> some pathological case arise, it will be mitigated by the
Kaveh> many more string space reductions.
That would be my expectation as well.
Note that doing this stuff in tree-land should be very, very easy.
Look at cp/optimize.c. Now, just call walk_tree, looking for
CALL_EXPRs calling `::printf' with a STRING_CST, and mutate the tree.
The trickiest bit here is figuring out which printf is the real
printf. I think you can use DECL_ASSEMBLER_NAME for this, but it
would probably be wise to hide things behind one layer of abstraction
in case that doesn't turn out to be the right thing. In other words,
make an enumeral for builtin-functions and a predicate that says
whether or not a particular FUNCTION_DECL is a particular function.
The issue is that when -fno-honor-std is on, `::printf' is the right
one, but when -fhonor-std is on, `std::printf' is the right one.
(This applies more generally than to printf, of course.) It would be
rude to optimize a user-function that isn't actually the printf
function. Also, in a free-standing environment, `printf' may not do
what we might thing and/or `fwrite' might not exist, etc.
Mark Mitchell email@example.com
CodeSourcery, LLC http://www.codesourcery.com