[cfe-dev] Varying per function optimisation based on include path?

John McFarlane via cfe-dev cfe-dev at lists.llvm.org
Sun Aug 25 11:33:06 PDT 2019


On Sun, 25 Aug 2019 at 18:35, Arthur O'Dwyer <arthur.j.odwyer at gmail.com>
wrote:

> (Did you drop the list intentionally?)
>

Oops. Thanks.

>
> On Sun, Aug 25, 2019 at 11:43 AM John McFarlane <john at mcfarlane.name>
> wrote:
>
>>
>> It's been mentioned before that the decision to inline here is comparable
>> to a conditional `__forceinline` or `always_inline` directive where the
>> predicate it is what is under question.
>>
>> My formula:
>>
>>     __forceinline(included_via_isystem(callee)) auto find_if(....) { ....
>> }
>>
>> Your formula (perhaps?):
>>
>>
>> __forceinline(included_via_isystem(callee)&&included_via_isystem(caller))
>> auto find_if(....) { .... }
>>
>
> Yes, that's essentially it.
> However, I repeat that the primitive operation with inlining is
> "collapsing an *edge* of the call graph." We do not inline a *function
> definition*; we inline a specific *call* (from caller to callee).  So I
> would say that the compiler's algorithm for inlining currently looks like
>
>     bool ShouldInline(Func caller, Func callee) { // and we might add
> "SourceLocation callsite", which is unused here
>         bool heuristic = (callee.is_small() ||
> callee.has_forceinline_attribute());
>         return heuristic && (-O2 or greater);
>     }
>
> and that we want it to instead look like
>
>     bool ShouldInline(Func caller, Func callee) {
>         bool heuristic = (callee.is_small() ||
> callee.has_forceinline_attribute());
>         bool is_system_to_system = (callee.is_from_system_header() &&
> caller.is_from_system_header());
>         return heuristic && (
>             (-O2 or greater) || (-Og && is_system_to_system)
>         );
>     }
>
> I would stay away from trying to frame the solution as "adding attributes
> to certain function definitions," because the intended behavior is not a
> property of function definitions (*nodes* in the call graph) — it's a
> property of *calls* (*edges* in the call graph). Namely, the property is,
> do we want to inline that call or not.
>

The attribute in question is conditional otherwise wouldn't forceinline be
all we need? So kind of like `noexcept(predicate)` but dependent on
caller/callee -- rather than `T`. So I think the above predicate is a
helpful thought experiment.

Again, for all the arguments I gave previously, I think that `find_if` and
`operator==` in our example should be inlined. Your `is_system_to_system`
test would fail for those.

John

>
> –Arthur
>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190825/2a8433cf/attachment.html>


More information about the cfe-dev mailing list