PATCH: don't mark pure derived method odr because of a qualified call to base method

John McCall rjmccall at apple.com
Wed Feb 13 17:45:12 PST 2013


On Feb 13, 2013, at 5:02 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Wed, Feb 13, 2013 at 4:38 PM, John McCall <rjmccall at apple.com> wrote:
> On Feb 13, 2013, at 4:27 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>> On Wed, Feb 13, 2013 at 4:16 PM, John McCall <rjmccall at apple.com> wrote:
>> On Feb 13, 2013, at 3:40 PM, Nick Lewycky <nlewycky at google.com> wrote:
>>> On 13 February 2013 10:53, John McCall <rjmccall at apple.com> wrote:
>>> On Feb 13, 2013, at 12:53 AM, Nick Lewycky <nlewycky at google.com> wrote:
>>> > Thinking about this issue more, I'd like to retract this patch. Consider the case where we're implementing the rule that all ODR-used inline functions must have a definition. If Derived::fn is marked inline, we'll see a fictitious use of it and reject a valid translation unit.
>>> >
>>> > My next plan is to remove this code from Sema entirely and do the equivalent work inside codegen proper. No reason it can't keep track of probable virtual function targets when writing out a virtual dispatch.
>>> 
>>> Ugh.  I am not thrilled by the idea of emitting massive amounts of code because something *might* devirtualize to it.
>>> 
>>> Also, this potentially requires template instantiation.
>>> 
>>> Me neither. However, Sema and CodeGen are already colluding to do this. See SemaExpr.cpp:11168 (MarkExprReferenced), which may trigger instantiation, and CGExprCXX.cpp:200 (EmitCXXMemberCallExpr) which assumes the potential callee was already instantiated.
>> 
>> If we're willing to break some of the majestic beauty of the frontend-isolated optimizer, we could queue up a late module pass which
>> 1) recognizes that we've emitted a reference to something that we're required to define in every translation unit that references it (easy to do with metadata),
>> 2) goes back to Sema and IR-gen to produce that code, and
>> 3) restarts the optimizer on the new functions.
>> Repeat until hopefully-rapid convergence.
>> 
>> That sounds like a path to optimization-dependent diagnostics, which we have previously gone to lengths to avoid. This case seems less severe, since it is likely that the diagnostics will be produced in *some* translation unit, but I still find it concerning.
> 
> Do we really want to instantiate basically every virtual function in the translation unit even at -O0 just so that we can have a stable set of diagnostics?
> 
> Do you have any estimates at all about how much extra code you'll be generating in an average translation unit?
> 
> I'm not proposing that we make /any/ changes, and IIUC Nick is only looking at cases where CodeGen can see statically which function will actually be called.
> 
> If we want to instantiate and emit more functions to allow further devirtualization as you're suggesting, we will need to consider the impact on the end-user experience, as well as the costs of having the optimizer call back into the frontend. Virtual functions in templates are not overwhelmingly common, and we would not need to instantiate them unless both (1) we're emitting a vtable containing the function as available_externally, and (2) a base class function which that function overrides is used.

Probably the sensible thing to do is to disable devirtualization (by not emitting an available_externally vtable) when one or more functions is inline but uninstantiated.  If we can actually track use of the specific function slot, great, but I'm not sure how feasible that is.

This still leaves us generating a ton of inline functions to enable a largely theoretical optimization (at least, it's not at all dense in the set of virtual call sites), which is where most of my compile-time concern comes from.

Anyhow, we can punt on this conversation.

John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130213/4b01c265/attachment.html>


More information about the cfe-commits mailing list