[PATCH] D152758: [NFC] Refactor MBB hotness/coldness into templated PSI functions
Han Shen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 23 15:15:57 PDT 2023
shenhan marked an inline comment as done.
shenhan 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,
----------------
wenlei wrote:
> 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)
> ```
Thanks. Good hint.
Removed "AdapterT" template-parameter from "shouldOptimizeForSizeImpl" and "shouldFuncOptimizeForSizeImpl".
This also leads to the removal of "MachineBasicBlockBFIAdapter" class. Now MachineSizeOpts.cpp looks neat.
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