[PATCH] D152758: [NFC] Refactor MBB hotness/coldness into templated PSI functions
Wenlei He via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 10:51:18 PDT 2023
wenlei added inline comments.
================
Comment at: llvm/lib/CodeGen/MachineSizeOpts.cpp:28
namespace {
-namespace machine_size_opts_detail {
-
-/// Like ProfileSummaryInfo::isColdBlock but for MachineBasicBlock.
-bool isColdBlock(const MachineBasicBlock *MBB,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo *MBFI) {
- auto Count = MBFI->getBlockProfileCount(MBB);
- return Count && PSI->isColdCount(*Count);
-}
-
-bool isColdBlock(BlockFrequency BlockFreq,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo *MBFI) {
- auto Count = MBFI->getProfileCountFromFreq(BlockFreq.getFrequency());
- return Count && PSI->isColdCount(*Count);
-}
-
-/// Like ProfileSummaryInfo::isHotBlockNthPercentile but for MachineBasicBlock.
-static bool isHotBlockNthPercentile(int PercentileCutoff,
- const MachineBasicBlock *MBB,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo *MBFI) {
- auto Count = MBFI->getBlockProfileCount(MBB);
- return Count && PSI->isHotCountNthPercentile(PercentileCutoff, *Count);
-}
-
-static bool isHotBlockNthPercentile(int PercentileCutoff,
- BlockFrequency BlockFreq,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo *MBFI) {
- auto Count = MBFI->getProfileCountFromFreq(BlockFreq.getFrequency());
- 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(
- const MachineFunction *MF,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo &MBFI) {
- if (auto FunctionCount = MF->getFunction().getEntryCount())
- if (!PSI->isColdCount(FunctionCount->getCount()))
- return false;
- for (const auto &MBB : *MF)
- if (!isColdBlock(&MBB, PSI, &MBFI))
- return false;
- return true;
-}
-
-/// Like ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile but for
-/// MachineFunction.
-bool isFunctionHotInCallGraphNthPercentile(
- int PercentileCutoff,
- const MachineFunction *MF,
- ProfileSummaryInfo *PSI,
- const MachineBlockFrequencyInfo &MBFI) {
- if (auto FunctionCount = MF->getFunction().getEntryCount())
- if (PSI->isHotCountNthPercentile(PercentileCutoff,
- FunctionCount->getCount()))
- return true;
- for (const auto &MBB : *MF)
- if (isHotBlockNthPercentile(PercentileCutoff, &MBB, PSI, &MBFI))
- 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 {
static bool isFunctionColdInCallGraph(const MachineFunction *MF,
----------------
Now with PSI directly supporting IR and MIR, do we still need MachineBasicBlockBFIAdapter?
This function below (main use of adapter) can now interface with templated PSI APIs (isHotBlockNthPercentile/isColdBlockNthPercentile/isColdBlock) directly without going through adapter.
```
template<typename AdapterT, typename BlockTOrBlockFreq, typename BFIT>
bool shouldOptimizeForSizeImpl(BlockTOrBlockFreq BBOrBlockFreq, ProfileSummaryInfo *PSI,
BFIT *BFI, PGSOQueryType QueryType)
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152758/new/
https://reviews.llvm.org/D152758
More information about the llvm-commits
mailing list