This is the mail archive of the 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 add __builtin_printf("string\n") ->puts("string")

>>>>> "Kaveh" == Kaveh R Ghazi <> 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.
All done.

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         
CodeSourcery, LLC     

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