This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Update combined index for SamplePGO indirect calls to locals
ClosedPublic

Authored by tejohnson on Sep 23 2021, 5:35 PM.

Details

Summary

In ThinLTO for locals we normally compute the GUID from the name after
prepending the source path to get a unique global id. SamplePGO indirect
call profiles contain the target GUID without this uniquification,
however (unless compiling with -funique-internal-linkage-names).

In order to correctly handle the call edges added to the combined index
for these indirect calls, during importing and bitcode writing we
consult a map of original to full GUID to identify the actual callee.
However, for a large application this was consuming a lot of compile
time as we need to do this repeatedly (especially during importing where
we may traverse call edges multiple times).

To fix this implement a suggestion in one of the FIXME comments, and
actually modify the call edges during a single traversal after the index
is built to perform the fixups once. I combined this fixup with the dead
code analysis performed on the index in order to avoid adding an
additional walk of the index. The dead code analysis is the first
analysis performed on the index.

This reduced the time required for a large thin link with SamplePGO by
about 20%.

No new test added, but I confirmed that there are existing tests that
will fail when no fixup is performed.

Diff Detail

Event Timeline

tejohnson created this revision.Sep 23 2021, 5:35 PM
tejohnson requested review of this revision.Sep 23 2021, 5:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 23 2021, 5:35 PM
wmi added inline comments.Sep 23 2021, 9:11 PM
llvm/include/llvm/IR/ModuleSummaryIndex.h
703

mutable_calls() const?

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
4210–4211

Optional is not needed anymore?

tejohnson added inline comments.Sep 24 2021, 8:33 AM
llvm/include/llvm/IR/ModuleSummaryIndex.h
703

Can't be const since it is returning a non-const reference.

I did fix the clang-tidy warning here and change it to mutableCalls to match the coding style.

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
4210–4211

The invoked IndexBitcodeWriter::getValueId does return Optional.

tejohnson updated this revision to Diff 374856.Sep 24 2021, 8:34 AM

Fix coding style issue

wmi accepted this revision.Sep 24 2021, 9:00 AM

LGTM.

This revision is now accepted and ready to land.Sep 24 2021, 9:00 AM
This revision was landed with ongoing or failed builds.Sep 24 2021, 12:30 PM
This revision was automatically updated to reflect the committed changes.