From 80155cbf0be1744953edf68b9729c24bd0de79c4 Mon Sep 17 00:00:00 2001 From: Han Shen Date: Wed, 28 Jun 2023 22:18:53 -0700 Subject: [Analysis] Refactor MBB hotness/coldness into templated PSI functions. Currently, to use PSI->isFunctionHotInCallGraph, we first need to calculate BPI->BFI, which is expensive. Instead, we can implement this directly with MBFI. Also as @wenlei mentioned in another patch review, that MachineSizeOpts already has isFunctionColdInCallGraph, isFunctionHotInCallGraphNthPercentile, etc implemented. These can be refactored and so they can be reused across MachineFunctionSplitting and MachineSizeOpts passes. This CL does this - it refactors out those internal static functions into PSI as templated functions, so they can be accessed easily. Differential Revision: https://reviews.llvm.org/D153927 --- llvm/lib/CodeGen/MachineFunction.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/CodeGen/MachineFunction.cpp') diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 0f72e4b..a934a5c 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -1496,6 +1497,17 @@ void MachineConstantPool::print(raw_ostream &OS) const { } } +//===----------------------------------------------------------------------===// +// Template specialization for MachineFunction implementation of +// ProfileSummaryInfo::getEntryCount(). +//===----------------------------------------------------------------------===// +template <> +std::optional +ProfileSummaryInfo::getEntryCount( + const llvm::MachineFunction *F) const { + return F->getFunction().getEntryCount(); +} + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MachineConstantPool::dump() const { print(dbgs()); } #endif -- cgit v1.1