diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2020-03-03 09:53:07 -0800 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2020-03-05 09:54:54 -0800 |
commit | 76b9901fb15372a13b77def4299c7facb6b7f926 (patch) | |
tree | 9319f2daea8d78b017c6350dfcb229dd056118a7 /llvm/lib/CodeGen/MachineSizeOpts.cpp | |
parent | c140810ea158074c97bff4d3bd66c0e06aed6d93 (diff) | |
download | llvm-76b9901fb15372a13b77def4299c7facb6b7f926.zip llvm-76b9901fb15372a13b77def4299c7facb6b7f926.tar.gz llvm-76b9901fb15372a13b77def4299c7facb6b7f926.tar.bz2 |
[PGO][PGSO] Use IsColdXNthPercentile for sample PGO.
Summary:
This performs better for sample PGO.
NFC as PGSOColdCodeOnlyForSamplePGO is still true.
Reviewers: davidxl
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75550
Diffstat (limited to 'llvm/lib/CodeGen/MachineSizeOpts.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineSizeOpts.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineSizeOpts.cpp b/llvm/lib/CodeGen/MachineSizeOpts.cpp index 29aabf1..584d43b 100644 --- a/llvm/lib/CodeGen/MachineSizeOpts.cpp +++ b/llvm/lib/CodeGen/MachineSizeOpts.cpp @@ -59,6 +59,22 @@ static bool isHotBlockNthPercentile(int PercentileCutoff, return Count && PSI->isHotCountNthPercentile(PercentileCutoff, *Count); } +static bool isColdBlockNthPercentile(int PercentileCutoff, + const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + auto Count = MBFI->getBlockProfileCount(MBB); + return Count && PSI->isColdCountNthPercentile(PercentileCutoff, *Count); +} + +static bool isColdBlockNthPercentile(int PercentileCutoff, + BlockFrequency BlockFreq, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + auto Count = MBFI->getProfileCountFromFreq(BlockFreq.getFrequency()); + return Count && PSI->isColdCountNthPercentile(PercentileCutoff, *Count); +} + /// Like ProfileSummaryInfo::isFunctionColdInCallGraph but for /// MachineFunction. bool isFunctionColdInCallGraph( @@ -90,6 +106,19 @@ bool isFunctionHotInCallGraphNthPercentile( return true; return false; } + +bool isFunctionColdInCallGraphNthPercentile( + int PercentileCutoff, const MachineFunction *MF, ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + if (auto FunctionCount = MF->getFunction().getEntryCount()) + if (!PSI->isColdCountNthPercentile(PercentileCutoff, + FunctionCount.getCount())) + return false; + for (const auto &MBB : *MF) + if (!isColdBlockNthPercentile(PercentileCutoff, &MBB, PSI, &MBFI)) + return false; + return true; +} } // namespace machine_size_opts_detail struct MachineBasicBlockBFIAdapter { @@ -106,6 +135,12 @@ struct MachineBasicBlockBFIAdapter { return machine_size_opts_detail::isFunctionHotInCallGraphNthPercentile( CutOff, MF, PSI, MBFI); } + static bool isFunctionColdInCallGraphNthPercentile( + int CutOff, const MachineFunction *MF, ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + return machine_size_opts_detail::isFunctionColdInCallGraphNthPercentile( + CutOff, MF, PSI, MBFI); + } static bool isColdBlock(const MachineBasicBlock *MBB, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *MBFI) { @@ -130,6 +165,18 @@ struct MachineBasicBlockBFIAdapter { return machine_size_opts_detail::isHotBlockNthPercentile( CutOff, BlockFreq, PSI, MBFI); } + static bool isColdBlockNthPercentile(int CutOff, const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + return machine_size_opts_detail::isColdBlockNthPercentile(CutOff, MBB, PSI, + MBFI); + } + static bool isColdBlockNthPercentile(int CutOff, BlockFrequency BlockFreq, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + return machine_size_opts_detail::isColdBlockNthPercentile(CutOff, BlockFreq, + PSI, MBFI); + } }; } // end anonymous namespace |