aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineFunction.cpp
diff options
context:
space:
mode:
authorHan Shen <shenhan@google.com>2023-06-28 22:18:53 -0700
committerHan Shen <shenhan@google.com>2023-06-28 22:32:52 -0700
commit80155cbf0be1744953edf68b9729c24bd0de79c4 (patch)
tree5e9a5151fb8f2e6fd58d443bd6d664f4f81a5b0b /llvm/lib/CodeGen/MachineFunction.cpp
parent548e08c3f635f72519d3bcadcc71cca7d31d1e6d (diff)
downloadllvm-80155cbf0be1744953edf68b9729c24bd0de79c4.zip
llvm-80155cbf0be1744953edf68b9729c24bd0de79c4.tar.gz
llvm-80155cbf0be1744953edf68b9729c24bd0de79c4.tar.bz2
[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
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineFunction.cpp12
1 files changed, 12 insertions, 0 deletions
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<Function::ProfileCount>
+ProfileSummaryInfo::getEntryCount<llvm::MachineFunction>(
+ 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