This is an archive of the discontinued LLVM Phabricator instance.

[CSSPGO][llvm-profgen] Use profile summary based threshold for context trimming and merging
ClosedPublic

Authored by wenlei on Mar 18 2021, 10:23 PM.

Details

Summary

Switch to use cold threshold from profile summary for cold context merging and trimming, instead of relying on hard coded values. Minor refactoring included for switch names, etc.

Diff Detail

Event Timeline

wenlei created this revision.Mar 18 2021, 10:23 PM
wenlei requested review of this revision.Mar 18 2021, 10:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2021, 10:23 PM
wenlei added inline comments.Mar 18 2021, 10:25 PM
llvm/tools/llvm-profgen/ProfileGenerator.cpp
206

We need profile name otherwise UseContextLessSummary won't work as the merge of context profile needs name key.

wenlei updated this revision to Diff 331765.Mar 18 2021, 10:28 PM

undo bad linter

hoy added inline comments.Mar 19 2021, 12:35 PM
llvm/tools/llvm-profgen/ProfileGenerator.cpp
47

I'm wondering if the original switches can be moved into a common place, such as ProfileSummaryBuilder.cpp, so that they can be reused here. Some code in CSProfileGenerator::computeSummaryAndThreshold may also be sharable.

wmi added inline comments.Mar 19 2021, 1:53 PM
llvm/tools/llvm-profgen/ProfileGenerator.cpp
399–408

Similar as Hongtao's question. Can ProfileSummaryInfo::computeThresholds be used to set the hot/cold threshold?

wenlei added inline comments.Mar 19 2021, 4:19 PM
llvm/tools/llvm-profgen/ProfileGenerator.cpp
47

That would be nice, however for normal path of ProfileSummaryInfo, the actual summary is retrieved from module metadata which is read from binary profile directly instead of being built from ProfileSummaryBuilder on the spot.

I think it probably makes sense to just use ProfileSummaryInfo here, as Wei suggested. However, looks like the switches from ProfileSummaryInfo.cpp doesn't get exposed that way.. I guess that's because ProfileData is linked into llvm-profogen, instead of being part of the tool?

399–408

Sounds good, changed to use PSI directly here, so we don't need keep thresholds separately.

wenlei updated this revision to Diff 332027.Mar 19 2021, 4:20 PM

Use PSI directly.

hoy added a comment.Mar 20 2021, 4:24 PM

Using PSI looks good, thanks. Can you please add a test for -csprof-merge-cold-context? Otherwise lgtm.

wenlei updated this revision to Diff 332144.Mar 20 2021, 8:46 PM

Add test coverage for --csprof-merge-cold-context.

hoy accepted this revision.Mar 20 2021, 10:31 PM
This revision is now accepted and ready to land.Mar 20 2021, 10:31 PM
wmi accepted this revision.Mar 21 2021, 10:29 PM

LGTM.

wlei added inline comments.Mar 21 2021, 10:30 PM
llvm/test/tools/llvm-profgen/merge-cold-profile.test
54

How about we add:

; CHECK-UNMERGED-NOT: [fa]
; CHECK-UNMERGED-NOT: [fb]

to make sure the merging not happen.

llvm/tools/llvm-profgen/ProfileGenerator.cpp
239

There is two places to call this function: for probe and non-probe.
How about to move this to CSProfileGenerator::write(...) so that we only keep one call for this?

wenlei added inline comments.Mar 22 2021, 8:42 AM
llvm/test/tools/llvm-profgen/merge-cold-profile.test
54

Sounds good, added.

llvm/tools/llvm-profgen/ProfileGenerator.cpp
239

I think it doesn't belong to writing, though moving there may save one call from the code. The thresholds will be needed for estimating inlining, which I will send up next, so I'd like to keep it this way for now if it's ok, and try to refactor in the upcoming change.

wenlei updated this revision to Diff 332301.Mar 22 2021, 8:42 AM

Address Lei's comment.

wlei accepted this revision.Mar 22 2021, 8:55 AM

LGTM, thanks!

llvm/tools/llvm-profgen/ProfileGenerator.cpp
239

Sounds good, thanks for the clarification.

This revision was landed with ongoing or failed builds.Mar 22 2021, 9:07 AM
This revision was automatically updated to reflect the committed changes.