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]
Other format: [Raw text]

Re: Is it possible to make gcc detect whether printf prints floating point numbers?


On Tue, Jun 12, 2012 at 4:23 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Fri, 8 Jun 2012, Bin.Cheng wrote:
>
>> For example, most c programs call printf to format output data, that
>> means floating point code get linked even the program only want to
>> output non-floating point numbers. Currently, we rely on end-user to
>> call iprintf if the program does not want floating point.
>
> The name "iprintf" is in the user's namespace, not the implementation
> namespace, so it wouldn't be a particularly good idea for the compiler to
> generate calls to it (certainly not in standards modes; cf. bug 46926).
> But as I understand it you're suggesting something more complicated than
> generating a call to a special function.
Yes, I also think rewriting printf to iprintf is not good.

>
>> I noticed that GCC now can check format string of printf functions, so
>> I am wondering if it is possible to take advantage of this utility, by
>> making gcc detect whether printf prints floating point number and then
>> generate assembly directive in backend to pull in floating point
>> functions only if necessary.
>
> Obviously this won't help if the program is using functions such as
> vprintf to print things with variable format strings....
One method is to analyze the type of arguments when format strings are
varying. Though this method might fail when user trying to output a
"long long" type int with conversion specifier "%f", I think it's not
a big deal.

>
>> The problem is:
>> The check is done in front end, so how should I expose the check
>> result to back-end. Is there any hook utility?
>
> The front end should generate appropriate GIMPLE describing semantics of
> the translation unit. ?If you are simply calling some system-defined
> __iprintf this is a matter of rewriting function calls (given an
> appropriate C-family target hook to do the rewriting). ?But if you want
> e.g. an assembler directive causing a relocation against some magic symbol
> to cause certain code to be linked in, you could probably generate a call
> to __builtin_<arch>_printf_needs_float (for example), again given a
> suitable hook, and then have the back end handle such a call by generating
> a directive rather than code.
Thanks very much, this is what I want to do.
I have done the library part work and only need one directive in
assembly code to pull in floating point output functions.

-- 
Best Regards.


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