This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] Use flattening sample profile in profile supplementation
ClosedPublic

Authored by xur on Nov 28 2022, 9:27 PM.

Details

Summary

We need to flatten the SampleFDO profile in profile supplementation
because the InstrFDO profile does not have inlined callsite counters.
Without flattening profile, FDO optimizations are not stable:
we will not supplement the second generation profile when the modified
functions are all inlined.

This patch fixes this issue: we will flatten the profile for functions
that appears in FDO profile.

Note that we only need to find the hot/warm functions in SampleFDO
profile, so we will not perform a full flatten. We will use
a DFS traversal to compute the accumulated entry count and max bodycount.
This is much cheaper than full flattening.

Diff Detail

Event Timeline

xur created this revision.Nov 28 2022, 9:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 9:27 PM
xur requested review of this revision.Nov 28 2022, 9:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 9:27 PM
xur updated this revision to Diff 478453.Nov 28 2022, 9:40 PM

Simplified the patch a bit by refactoring the existing interface.

davidxl added inline comments.Nov 28 2022, 9:57 PM
llvm/include/llvm/ProfileData/SampleProf.h
928–929

The comment needs to be updated to reflect the new behavior.

llvm/test/tools/llvm-profdata/suppl-instr-with-sample-flatten.test
5

The test only sets bar.cc::bar's counter, not goo's?

llvm/tools/llvm-profdata/llvm-profdata.cpp
637

pre-inlined, do you mean early-inlined?

641

Perhaps describe with a short example.

663

There is no need for the nested lambda.

xur added inline comments.Nov 28 2022, 10:10 PM
llvm/include/llvm/ProfileData/SampleProf.h
928–929

Ack.

llvm/test/tools/llvm-profdata/suppl-instr-with-sample-flatten.test
5

Yes. That's a typo. I meant "bar.cc:bar". Function "goo" is considered preinlined in FDO -- as it's not appear in FDO profile. We should not supplement goo.

llvm/tools/llvm-profdata/llvm-profdata.cpp
637

I think we call "early-inline" pre-inliner in llvm.

641

I will use the test case as the example. To be updated.

663

I think I need to use two level lambda if we want to use lamda. I can do with a member function but I need to pass many things around.

xur updated this revision to Diff 478469.Nov 28 2022, 11:25 PM

Addressed David's review comments.

xur updated this revision to Diff 478470.Nov 28 2022, 11:45 PM

Removed lambda updateSampleMap() -- it was from the early version and now it was no longer needed as we just had one caller.

davidxl added inline comments.Nov 29 2022, 1:24 PM
llvm/tools/llvm-profdata/llvm-profdata.cpp
691

I am not sure if RootName parameter is actually needed here. In the code below, it is either be overwritten (with newroot), or used in cases we don't care -- i.e., function not found in instr profile.

xur added inline comments.Nov 29 2022, 2:29 PM
llvm/tools/llvm-profdata/llvm-profdata.cpp
691

It's used in line 696 (set as the default value) of NewRootName.
If we find the Name is in InstrProfile, it will be overwriteen.

If we don't find the Name, we don't care this function (we treat it as inline function), but we still interested in the max body count and we will update the RootName entry from the parameter.

In the example, when get the goo's FS, it's max count will used to update bar.c:bar() (this is the RootName).

davidxl accepted this revision.Nov 29 2022, 2:48 PM

lgtm

This revision is now accepted and ready to land.Nov 29 2022, 2:48 PM
This revision was landed with ongoing or failed builds.Nov 29 2022, 10:36 PM
This revision was automatically updated to reflect the committed changes.