[cfe-dev] Explicit instantiation declarations/definitions and optimizations

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Sat Sep 19 23:31:01 PDT 2015


On Sat, Sep 19, 2015 at 8:33 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Sat, Sep 19, 2015 at 8:15 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On Sat, Sep 19, 2015 at 6:15 PM, David Blaikie via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> I was just thinking through the possible advice of encouraging users to
>>> use explicit template instantiation declarations/definitions to reduce
>>> object size.
>>>
>>> It seems this may hurt performance in non-LTO builds by causing what
>>> were inlinable functions to no longer be available for inlining.
>>>
>>> Should we consider emitting available_externally definitions of such
>>> entities (possibly under specific/higher optimization levels)?
>>>
>>
>> We should, and we already do: http://goo.gl/V8G5kU
>>
>> Do you have a case where we fail to do so? It's possible there's a bug in
>> this determination.
>>
>
> Sorry, yes, should've included my test case, which boiled down to:
>
> template <typename T> void f() {}
> extern template void f<int>(); void g() { f<int>(); }
>
> The difference being the absence of the "inline" keyword on f's
> definition. I wonder if that's the right tradeoff (I can understand using
> the inline keyword to hint the inliner a little more strongly - but this
> seems like a much stronger dependence on the keyword than I'd expect).
> Perhaps it is.
>

The C++ standard doesn't permit us to instantiate f<int> in this case; per
[temp.explicit]/10,

"Except for inline functions, declarations with types deduced from their
initializer or return value (7.1.6.4), const variables of literal types,
variables of reference types, and class template specializations, explicit
instantiation declarations have the effect of suppressing the implicit
instantiation of the entity to which they refer."

So whether or not this is the right tradeoff, it's not our call to make. We
emit function definitions available_externally in (more or less) all the
cases that C++ lets us do so.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150919/60b61429/attachment.html>


More information about the cfe-dev mailing list