1212// ===----------------------------------------------------------------------===//
1313
1414#include " llvm/CodeGen/MachineSizeOpts.h"
15+ #include " llvm/CodeGen/MBFIWrapper.h"
1516#include " llvm/Analysis/ProfileSummaryInfo.h"
1617#include " llvm/CodeGen/MachineBlockFrequencyInfo.h"
1718
@@ -33,6 +34,13 @@ bool isColdBlock(const MachineBasicBlock *MBB,
3334 return Count && PSI->isColdCount (*Count);
3435}
3536
37+ bool isColdBlock (BlockFrequency BlockFreq,
38+ ProfileSummaryInfo *PSI,
39+ const MachineBlockFrequencyInfo *MBFI) {
40+ auto Count = MBFI->getProfileCountFromFreq (BlockFreq.getFrequency ());
41+ return Count && PSI->isColdCount (*Count);
42+ }
43+
3644// / Like ProfileSummaryInfo::isHotBlockNthPercentile but for MachineBasicBlock.
3745static bool isHotBlockNthPercentile (int PercentileCutoff,
3846 const MachineBasicBlock *MBB,
@@ -42,6 +50,14 @@ static bool isHotBlockNthPercentile(int PercentileCutoff,
4250 return Count && PSI->isHotCountNthPercentile (PercentileCutoff, *Count);
4351}
4452
53+ static bool isHotBlockNthPercentile (int PercentileCutoff,
54+ BlockFrequency BlockFreq,
55+ ProfileSummaryInfo *PSI,
56+ const MachineBlockFrequencyInfo *MBFI) {
57+ auto Count = MBFI->getProfileCountFromFreq (BlockFreq.getFrequency ());
58+ return Count && PSI->isHotCountNthPercentile (PercentileCutoff, *Count);
59+ }
60+
4561// / Like ProfileSummaryInfo::isFunctionColdInCallGraph but for
4662// / MachineFunction.
4763bool isFunctionColdInCallGraph (
@@ -95,13 +111,25 @@ struct MachineBasicBlockBFIAdapter {
95111 const MachineBlockFrequencyInfo *MBFI) {
96112 return machine_size_opts_detail::isColdBlock (MBB, PSI, MBFI);
97113 }
114+ static bool isColdBlock (BlockFrequency BlockFreq,
115+ ProfileSummaryInfo *PSI,
116+ const MachineBlockFrequencyInfo *MBFI) {
117+ return machine_size_opts_detail::isColdBlock (BlockFreq, PSI, MBFI);
118+ }
98119 static bool isHotBlockNthPercentile (int CutOff,
99120 const MachineBasicBlock *MBB,
100121 ProfileSummaryInfo *PSI,
101122 const MachineBlockFrequencyInfo *MBFI) {
102123 return machine_size_opts_detail::isHotBlockNthPercentile (
103124 CutOff, MBB, PSI, MBFI);
104125 }
126+ static bool isHotBlockNthPercentile (int CutOff,
127+ BlockFrequency BlockFreq,
128+ ProfileSummaryInfo *PSI,
129+ const MachineBlockFrequencyInfo *MBFI) {
130+ return machine_size_opts_detail::isHotBlockNthPercentile (
131+ CutOff, BlockFreq, PSI, MBFI);
132+ }
105133};
106134} // end anonymous namespace
107135
@@ -117,6 +145,19 @@ bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
117145 ProfileSummaryInfo *PSI,
118146 const MachineBlockFrequencyInfo *MBFI,
119147 PGSOQueryType QueryType) {
148+ assert (MBB);
120149 return shouldOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>(
121150 MBB, PSI, MBFI, QueryType);
122151}
152+
153+ bool llvm::shouldOptimizeForSize (const MachineBasicBlock *MBB,
154+ ProfileSummaryInfo *PSI,
155+ MBFIWrapper *MBFIW,
156+ PGSOQueryType QueryType) {
157+ assert (MBB);
158+ if (!PSI || !MBFIW)
159+ return false ;
160+ BlockFrequency BlockFreq = MBFIW->getBlockFreq (MBB);
161+ return shouldOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>(
162+ BlockFreq, PSI, &MBFIW->getMBFI (), QueryType);
163+ }
0 commit comments