[SampleFDO] For functions without profiles, provide an option to put
authorWei Mi <wmi@google.com>
Tue, 5 May 2020 00:17:34 +0000 (17:17 -0700)
committerWei Mi <wmi@google.com>
Fri, 8 May 2020 18:18:09 +0000 (11:18 -0700)
commitaa2ddfc73d6e4a3369b7992aecaf107987c505b6
treec804b71ba5e95c393ff18d2b2f6df0fb92759a74
parent538208f6c0cb5c95d5ea8f4805f3abf8aaf418f9
[SampleFDO] For functions without profiles, provide an option to put
them in a special text section.

For sampleFDO, because the optimized build uses profile generated from
previous release, previously we couldn't tell a function without profile
was truely cold or just newly created so we had to treat them conservatively
and put them in .text section instead of .text.unlikely. The result was when
we persuing the best performance by locking .text.hot and .text in memory,
we wasted a lot of memory to keep cold functions inside.

In https://reviews.llvm.org/D66374, we introduced profile symbol list to
discriminate functions being cold versus functions being newly added.
This mechanism works quite well for regular use cases in AutoFDO. However,
in some case, we can only have a partial profile when optimizing a target.
The partial profile may be an aggregated profile collected from many targets.
The profile symbol list method used for regular sampleFDO profile is not
applicable to partial profile use case because it may be too large and
introduce many false positives.

To solve the problem for partial profile use case, we provide an option called
--profile-unknown-in-special-section. For functions without profile, we will
still treat them conservatively in compiler optimizations -- for example,
treat them as warm instead of cold in inliner. When we use profile info to
add section prefix for functions, we will discriminate functions known to be
not cold versus functions without profile (being unknown), and we will put
functions being unknown in a special text section called .text.unknown.
Runtime system will have the flexibility to decide where to put the special
section in order to achieve a balance between performance and memory saving.

Differential Revision: https://reviews.llvm.org/D62540
llvm/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/lib/Analysis/ProfileSummaryInfo.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll