This is an archive of the discontinued LLVM Phabricator instance.

[CSSPGO] Load context profile for external functions in PreLink and populate ThinLTO import list
ClosedPublic

Authored by wenlei on Mar 13 2021, 2:17 PM.

Details

Summary

For ThinLTO's prelink compilation, we need to put external inline candidates into an import list attached to function's entry count metadata. This enables ThinLink to treat such cross module callee as hot in summary index, and later helps postlink to import them for profile guided cross module inlining.

For AutoFDO, the import list is retrieved by traversing the nested inlinee functions. For CSSPGO, since profile is flatterned, a few things need to happen for it to work:

  • When loading input profile in extended binary format, we need to load all child context profile whose parent is in current module, so context trie for current module includes potential cross module inlinee.
  • In order to make the above happen, we need to know whether input profile is CSSPGO profile before start reading function profile, hence a flag for profile summary section is added.
  • When searching for cross module inline candidate, we need to walk through the context trie instead of nested inlinee profile (callsite sample of AutoFDO profile).
  • Now that we have more accurate counts with CSSPGO, we swtiched to use entry count instead of total count to decided if an external callee is potentially beneficial to inline. This make it consistent with how we determine whether call tagert is potential inline candidate.

Diff Detail

Event Timeline

wenlei created this revision.Mar 13 2021, 2:17 PM
wenlei requested review of this revision.Mar 13 2021, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2021, 2:17 PM
wmi added inline comments.Mar 14 2021, 12:57 PM
llvm/lib/ProfileData/SampleProfReader.cpp
730

Better use: It = OrderedNames.erase(It);

llvm/lib/Transforms/IPO/SampleProfile.cpp
976

The hotness of CalleeNode is not checked before it is inserted into CalleeList. Will it add unnecessary imports?

wenlei added inline comments.Mar 15 2021, 9:28 AM
llvm/lib/ProfileData/SampleProfReader.cpp
730

good point, changed.

llvm/lib/Transforms/IPO/SampleProfile.cpp
976

That is an oversight, good catch! The code was partially following findInlinedFunctions, but since there's no recursion, the hotness check on function entry won't apply to lower callees.

wenlei updated this revision to Diff 330692.Mar 15 2021, 9:29 AM

address Wei's comment.

hoy added inline comments.Mar 15 2021, 10:39 AM
llvm/test/Transforms/SampleProfile/csspgo-import-list.ll
3

Add a test that consumes text format profile?

wenlei added inline comments.Mar 15 2021, 11:00 AM
llvm/test/Transforms/SampleProfile/csspgo-import-list.ll
3

Oops, I missed the binary profile. Good catch!

wenlei updated this revision to Diff 330732.Mar 15 2021, 11:00 AM

address Hongtao's feedback

hoy accepted this revision.Mar 15 2021, 11:37 AM

LGTM, thanks.

This revision is now accepted and ready to land.Mar 15 2021, 11:37 AM
wmi accepted this revision.Mar 15 2021, 11:56 AM

LGTM. Thanks!

This revision was landed with ongoing or failed builds.Mar 15 2021, 12:22 PM
This revision was automatically updated to reflect the committed changes.