[AutoFDO] Use flattened profiles for profile staleness metrics
authorwlei <wlei@fb.com>
Mon, 20 Mar 2023 05:37:01 +0000 (22:37 -0700)
committerwlei <wlei@fb.com>
Thu, 30 Mar 2023 18:05:10 +0000 (11:05 -0700)
commit339b8a0019658746217870215abca77291ad75b3
tree0eabe353f2b5c78a283ccbd718740dabcd5fa319
parent1fab236e6e4575d5af4f4722216df4dd6a872795
[AutoFDO] Use flattened profiles for profile staleness metrics

For profile staleness report, before it only counts for the top-level function samples in the nested profile, the samples in the inlinees are ignored. This could affect the quality of the metrics when there are heavily inlined functions. This change adds a feature to flatten the nested profile and we're changing to use flatten profile as the input for stale profile detection and matching.
Example for profile flattening:

```
Original profile:
_Z3bazi:20301:1000
 1: 1000
 3: 2000
 5: inline1:1600
   1: 600
   3: inline2:500
     1: 500

Flattened profile:
_Z3bazi:18701:1000
 1: 1000
 3: 2000
 5: 600 inline1:600
inline1:1100:600
 1: 600
 3: 500 inline2: 500
inline2:500:500
 1: 500
```
This feature could be useful for offline analysis, like understanding the hotness of each individual function. So I'm adding the support to `llvm-profdata merge` under `--gen-flattened-profile`.

Reviewed By: hoy, wenlei

Differential Revision: https://reviews.llvm.org/D146452
16 files changed:
llvm/docs/CommandGuide/llvm-profdata.rst
llvm/include/llvm/ProfileData/SampleProf.h
llvm/lib/ProfileData/SampleProf.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/test/Transforms/SampleProfile/Inputs/profile-mismatch-cs.prof [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/Inputs/profile-mismatch.prof
llvm/test/Transforms/SampleProfile/csspgo-inline.ll
llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
llvm/test/Transforms/SampleProfile/profile-mismatch-flattened-profile.ll [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/profile-mismatch.ll
llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile-cs.proftext [new file with mode: 0644]
llvm/test/tools/llvm-profdata/Inputs/sample-flatten-profile.proftext [new file with mode: 0644]
llvm/test/tools/llvm-profdata/cs-sample-nested-profile.test
llvm/test/tools/llvm-profdata/sample-flatten-profile.test [new file with mode: 0644]
llvm/tools/llvm-profdata/llvm-profdata.cpp
llvm/tools/llvm-profgen/ProfileGenerator.cpp