[PATCH] Indirect call target profiling related profile reader/writer changes
Ivan Baev
ibaev at codeaurora.org
Wed Apr 22 23:12:20 PDT 2015
>> Ok, let's start from the basics. For profile guided devirtualization,
>> you're constructing a cache from (something) to function pointer and
>> using that cache lookup to enable inlining of the hot target. You have
>> two standard choices on what to use as your cache key: the result of the
>> virtual lookup and the inputs to the virtual lookup.
>>
>> Option 1 - Inputs to virtual lookup
>> if ((receiver, vtable index) == what I predicted)
>> tartget_I_predicted(); // inline me!!
>> else {
>> target = full virtual dispatch();
>> target();
>> }
>>
>> Option 2 - result of virtual lookup
>> target = full virtual dispatch();
>> if ('target' == what I predicted)
>> tartget_I_predicted(); // inline me!!
>> else {
>> target();
>> }
>>
>> You seem to be proposing option 2. I'm saying that I'm used to seeing
>> option 1 used. Both approaches have their appeal, I'm just asking you
>> to explain *why* you've chosen the one you apparently have.
>
> Not all indirect calls occur from C++ like codes. We're profiling and
> optimizing out indirect calls from C codes as well. We're seeing up to 8%
> gains on individual benchmarks in spec. This was measured on our platform.
>
Our initial motivation was to handle standard indirect calls, that is,
if ('target' == what I predicted)
target_I_predicted(); // inline me!!
else {
target();
}
At the start of the indirect call promotion pass we see a virtual call as
an indirect call so we can say we handle virtual calls through option 2.
target = full virtual dispatch();
if ('target' == what I predicted)
target_I_predicted(); // inline me!!
else {
target();
}
Now assuming that full virtual dispatch() is something like
{ vtable = load [receiver + #VToffset];
target = load [vtable + index]; }
under certain conditions we might be able to enhance option 2 above to
vtable = load [receiver + #VToffset];
if (vtable == vtable_of_what I predicted)
target_I_predicted(); // inline me!!
else {
target = load [vtable + index];
target();
}
Ivan
More information about the llvm-commits
mailing list