Turn check macros into functions. (issue6188088)

Richard Guenther richard.guenther@gmail.com
Wed May 16 13:46:00 GMT 2012


On Wed, May 16, 2012 at 3:40 PM, Diego Novillo <dnovillo@google.com> wrote:
> On 12-05-16 09:27 , Richard Guenther wrote:
>
>>> There's less typing if you use the template variant.  Not sure why
>>> you say there is less type safety with templates.
>>
>>
>> Because it accepts any type as tree argument?
>
>
> Yes and no.  It accepts any type that responds to tree
> operations and has the same fields.
>
>
>>> No, templated functions must always stay in the header file.
>>> There is no changing that.
>>
>>
>> If they ain't templates they are not templates.  And thus do not
>> need to stay in the header.  Not sure what you are after here ;)
>
>
> I think we are talking past each other.  I simply stated that function
> templates must stay in headers.  There's no export template, after all.
>
> I'm not defending the choice of using templates for these particular
> functions.  That's something for Lawrence to argue.
>
> I am simply curious as to how using the template variant produces
> slightly smaller code.
>
>
>>> Two bootstrapped compilers built exactly the same, except one was
>>> using the template version, the other using the straight inline
>>> functions with const_tree parameters and CONST_CAST_TREE in return
>>> values.
>>
>>
>> That's of course not exactly the same.  The checking fns should be
>> able to unconditionally use const_tree anyway.
>
>
> Sorry, I don't know what you are after.  I was comparing two compilers
> that only differ in how they implement the tree checking functions.  One
> uses templates, the other uses inline functions taking const_tree (not even
> static inline, just inline).
>
> They are bootstrapped compilers, so -fkeep-inline-functions is not used.
> What do you think I should have compared?

Sounds like it should come out equally sized then.  Possibly an instantiated
template leads to different code from the frontend?  Possibly we do not inline
all calls in either case?  Possibly because only instantiated templates count
towards initial unit size (but all, even unused(?), inline functions
count towards
it)?

Would be interesting to see preprocessed source for both cases for a
single object files where the size difference appears.  It might be
artificial, too,
caused by UID perturbations and random codegen difference due to that.

Non-templates should use less memory (with templates you at least have
a single instantiation and thus copy of the functions, with functions you
just have one).

That said - I see no technical reasons to use templates here and we should
not use C++ just because we can ... (and not scare people off here if the
technical reason is minor, such as an unknown size advantage).

Richard.

>
> Diego.



More information about the Gcc-patches mailing list