15ca98fd9SDimitry Andric //===- MachineBlockFrequencyInfo.cpp - MBB Frequency Analysis -------------===//
230815c53SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
630815c53SDimitry Andric //
730815c53SDimitry Andric //===----------------------------------------------------------------------===//
830815c53SDimitry Andric //
930815c53SDimitry Andric // Loops should be simplified before this analysis.
1030815c53SDimitry Andric //
1130815c53SDimitry Andric //===----------------------------------------------------------------------===//
1230815c53SDimitry Andric
1330815c53SDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
14044eb2f6SDimitry Andric #include "llvm/ADT/DenseMap.h"
15044eb2f6SDimitry Andric #include "llvm/ADT/iterator.h"
165ca98fd9SDimitry Andric #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
17044eb2f6SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h"
1830815c53SDimitry Andric #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
195ca98fd9SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
205ca98fd9SDimitry Andric #include "llvm/CodeGen/MachineLoopInfo.h"
21706b4fc4SDimitry Andric #include "llvm/InitializePasses.h"
22044eb2f6SDimitry Andric #include "llvm/Pass.h"
235ca98fd9SDimitry Andric #include "llvm/Support/CommandLine.h"
245ca98fd9SDimitry Andric #include "llvm/Support/GraphWriter.h"
25e3b55780SDimitry Andric #include <optional>
26044eb2f6SDimitry Andric #include <string>
2730815c53SDimitry Andric
2830815c53SDimitry Andric using namespace llvm;
2930815c53SDimitry Andric
30ab44ce3dSDimitry Andric #define DEBUG_TYPE "machine-block-freq"
315ca98fd9SDimitry Andric
32344a3780SDimitry Andric namespace llvm {
3301095a5dSDimitry Andric static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
3401095a5dSDimitry Andric "view-machine-block-freq-propagation-dags", cl::Hidden,
355ca98fd9SDimitry Andric cl::desc("Pop up a window to show a dag displaying how machine block "
365ca98fd9SDimitry Andric "frequencies propagate through the CFG."),
3701095a5dSDimitry Andric cl::values(clEnumValN(GVDT_None, "none", "do not display graphs."),
3801095a5dSDimitry Andric clEnumValN(GVDT_Fraction, "fraction",
3901095a5dSDimitry Andric "display a graph using the "
405ca98fd9SDimitry Andric "fractional block frequency representation."),
4101095a5dSDimitry Andric clEnumValN(GVDT_Integer, "integer",
4201095a5dSDimitry Andric "display a graph using the raw "
435ca98fd9SDimitry Andric "integer fractional block frequency representation."),
4401095a5dSDimitry Andric clEnumValN(GVDT_Count, "count", "display a graph using the real "
45b915e9e0SDimitry Andric "profile count if available.")));
46044eb2f6SDimitry Andric
4771d5a254SDimitry Andric // Similar option above, but used to control BFI display only after MBP pass
4871d5a254SDimitry Andric cl::opt<GVDAGType> ViewBlockLayoutWithBFI(
4971d5a254SDimitry Andric "view-block-layout-with-bfi", cl::Hidden,
5071d5a254SDimitry Andric cl::desc(
5171d5a254SDimitry Andric "Pop up a window to show a dag displaying MBP layout and associated "
5271d5a254SDimitry Andric "block frequencies of the CFG."),
5371d5a254SDimitry Andric cl::values(clEnumValN(GVDT_None, "none", "do not display graphs."),
5471d5a254SDimitry Andric clEnumValN(GVDT_Fraction, "fraction",
5571d5a254SDimitry Andric "display a graph using the "
5671d5a254SDimitry Andric "fractional block frequency representation."),
5771d5a254SDimitry Andric clEnumValN(GVDT_Integer, "integer",
5871d5a254SDimitry Andric "display a graph using the raw "
5971d5a254SDimitry Andric "integer fractional block frequency representation."),
6071d5a254SDimitry Andric clEnumValN(GVDT_Count, "count",
6171d5a254SDimitry Andric "display a graph using the real "
6271d5a254SDimitry Andric "profile count if available.")));
635ca98fd9SDimitry Andric
6471d5a254SDimitry Andric // Command line option to specify the name of the function for CFG dump
6571d5a254SDimitry Andric // Defined in Analysis/BlockFrequencyInfo.cpp: -view-bfi-func-name=
6601095a5dSDimitry Andric extern cl::opt<std::string> ViewBlockFreqFuncName;
67044eb2f6SDimitry Andric
6871d5a254SDimitry Andric // Command line option to specify hot frequency threshold.
6971d5a254SDimitry Andric // Defined in Analysis/BlockFrequencyInfo.cpp: -view-hot-freq-perc=
7001095a5dSDimitry Andric extern cl::opt<unsigned> ViewHotFreqPercent;
7101095a5dSDimitry Andric
72044eb2f6SDimitry Andric static cl::opt<bool> PrintMachineBlockFreq(
73044eb2f6SDimitry Andric "print-machine-bfi", cl::init(false), cl::Hidden,
74044eb2f6SDimitry Andric cl::desc("Print the machine block frequency info."));
75044eb2f6SDimitry Andric
76044eb2f6SDimitry Andric // Command line option to specify the name of the function for block frequency
77044eb2f6SDimitry Andric // dump. Defined in Analysis/BlockFrequencyInfo.cpp.
78b1c73532SDimitry Andric extern cl::opt<std::string> PrintBFIFuncName;
79344a3780SDimitry Andric } // namespace llvm
80044eb2f6SDimitry Andric
getGVDT()8171d5a254SDimitry Andric static GVDAGType getGVDT() {
8271d5a254SDimitry Andric if (ViewBlockLayoutWithBFI != GVDT_None)
8371d5a254SDimitry Andric return ViewBlockLayoutWithBFI;
8471d5a254SDimitry Andric
8571d5a254SDimitry Andric return ViewMachineBlockFreqPropagationDAG;
8671d5a254SDimitry Andric }
8771d5a254SDimitry Andric
885ca98fd9SDimitry Andric namespace llvm {
895ca98fd9SDimitry Andric
9001095a5dSDimitry Andric template <> struct GraphTraits<MachineBlockFrequencyInfo *> {
91044eb2f6SDimitry Andric using NodeRef = const MachineBasicBlock *;
92044eb2f6SDimitry Andric using ChildIteratorType = MachineBasicBlock::const_succ_iterator;
93044eb2f6SDimitry Andric using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
945ca98fd9SDimitry Andric
getEntryNodellvm::GraphTraits95b915e9e0SDimitry Andric static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) {
96dd58ef01SDimitry Andric return &G->getFunction()->front();
975ca98fd9SDimitry Andric }
985ca98fd9SDimitry Andric
child_beginllvm::GraphTraits99b915e9e0SDimitry Andric static ChildIteratorType child_begin(const NodeRef N) {
1005ca98fd9SDimitry Andric return N->succ_begin();
1015ca98fd9SDimitry Andric }
1025ca98fd9SDimitry Andric
child_endllvm::GraphTraits103b915e9e0SDimitry Andric static ChildIteratorType child_end(const NodeRef N) { return N->succ_end(); }
1045ca98fd9SDimitry Andric
nodes_beginllvm::GraphTraits1055ca98fd9SDimitry Andric static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G) {
106b915e9e0SDimitry Andric return nodes_iterator(G->getFunction()->begin());
1075ca98fd9SDimitry Andric }
1085ca98fd9SDimitry Andric
nodes_endllvm::GraphTraits1095ca98fd9SDimitry Andric static nodes_iterator nodes_end(const MachineBlockFrequencyInfo *G) {
110b915e9e0SDimitry Andric return nodes_iterator(G->getFunction()->end());
1115ca98fd9SDimitry Andric }
1125ca98fd9SDimitry Andric };
1135ca98fd9SDimitry Andric
114044eb2f6SDimitry Andric using MBFIDOTGraphTraitsBase =
115044eb2f6SDimitry Andric BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
116044eb2f6SDimitry Andric MachineBranchProbabilityInfo>;
117044eb2f6SDimitry Andric
1185ca98fd9SDimitry Andric template <>
11901095a5dSDimitry Andric struct DOTGraphTraits<MachineBlockFrequencyInfo *>
12001095a5dSDimitry Andric : public MBFIDOTGraphTraitsBase {
121044eb2f6SDimitry Andric const MachineFunction *CurFunc = nullptr;
12271d5a254SDimitry Andric DenseMap<const MachineBasicBlock *, int> LayoutOrderMap;
1235ca98fd9SDimitry Andric
DOTGraphTraitsllvm::DOTGraphTraits124044eb2f6SDimitry Andric explicit DOTGraphTraits(bool isSimple = false)
125044eb2f6SDimitry Andric : MBFIDOTGraphTraitsBase(isSimple) {}
126044eb2f6SDimitry Andric
getNodeLabelllvm::DOTGraphTraits1275ca98fd9SDimitry Andric std::string getNodeLabel(const MachineBasicBlock *Node,
1285ca98fd9SDimitry Andric const MachineBlockFrequencyInfo *Graph) {
12971d5a254SDimitry Andric int layout_order = -1;
13071d5a254SDimitry Andric // Attach additional ordering information if 'isSimple' is false.
13171d5a254SDimitry Andric if (!isSimple()) {
13271d5a254SDimitry Andric const MachineFunction *F = Node->getParent();
13371d5a254SDimitry Andric if (!CurFunc || F != CurFunc) {
13471d5a254SDimitry Andric if (CurFunc)
13571d5a254SDimitry Andric LayoutOrderMap.clear();
13671d5a254SDimitry Andric
13771d5a254SDimitry Andric CurFunc = F;
13871d5a254SDimitry Andric int O = 0;
13971d5a254SDimitry Andric for (auto MBI = F->begin(); MBI != F->end(); ++MBI, ++O) {
14071d5a254SDimitry Andric LayoutOrderMap[&*MBI] = O;
14171d5a254SDimitry Andric }
14271d5a254SDimitry Andric }
14371d5a254SDimitry Andric layout_order = LayoutOrderMap[Node];
14471d5a254SDimitry Andric }
14571d5a254SDimitry Andric return MBFIDOTGraphTraitsBase::getNodeLabel(Node, Graph, getGVDT(),
14671d5a254SDimitry Andric layout_order);
1475ca98fd9SDimitry Andric }
1485ca98fd9SDimitry Andric
getNodeAttributesllvm::DOTGraphTraits14901095a5dSDimitry Andric std::string getNodeAttributes(const MachineBasicBlock *Node,
15001095a5dSDimitry Andric const MachineBlockFrequencyInfo *Graph) {
15101095a5dSDimitry Andric return MBFIDOTGraphTraitsBase::getNodeAttributes(Node, Graph,
15201095a5dSDimitry Andric ViewHotFreqPercent);
15301095a5dSDimitry Andric }
15401095a5dSDimitry Andric
getEdgeAttributesllvm::DOTGraphTraits15501095a5dSDimitry Andric std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI,
15601095a5dSDimitry Andric const MachineBlockFrequencyInfo *MBFI) {
15701095a5dSDimitry Andric return MBFIDOTGraphTraitsBase::getEdgeAttributes(
15801095a5dSDimitry Andric Node, EI, MBFI, MBFI->getMBPI(), ViewHotFreqPercent);
1595ca98fd9SDimitry Andric }
1605ca98fd9SDimitry Andric };
1615ca98fd9SDimitry Andric
1625ca98fd9SDimitry Andric } // end namespace llvm
1635ca98fd9SDimitry Andric
164ac9a064cSDimitry Andric AnalysisKey MachineBlockFrequencyAnalysis::Key;
16530815c53SDimitry Andric
166ac9a064cSDimitry Andric MachineBlockFrequencyAnalysis::Result
run(MachineFunction & MF,MachineFunctionAnalysisManager & MFAM)167ac9a064cSDimitry Andric MachineBlockFrequencyAnalysis::run(MachineFunction &MF,
168ac9a064cSDimitry Andric MachineFunctionAnalysisManager &MFAM) {
169ac9a064cSDimitry Andric auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
170ac9a064cSDimitry Andric auto &MLI = MFAM.getResult<MachineLoopAnalysis>(MF);
171ac9a064cSDimitry Andric return Result(MF, MBPI, MLI);
17230815c53SDimitry Andric }
17330815c53SDimitry Andric
174ac9a064cSDimitry Andric PreservedAnalyses
run(MachineFunction & MF,MachineFunctionAnalysisManager & MFAM)175ac9a064cSDimitry Andric MachineBlockFrequencyPrinterPass::run(MachineFunction &MF,
176ac9a064cSDimitry Andric MachineFunctionAnalysisManager &MFAM) {
177ac9a064cSDimitry Andric auto &MBFI = MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
178ac9a064cSDimitry Andric OS << "Machine block frequency for machine function: " << MF.getName()
179ac9a064cSDimitry Andric << '\n';
180ac9a064cSDimitry Andric MBFI.print(OS);
181ac9a064cSDimitry Andric return PreservedAnalyses::all();
182ac9a064cSDimitry Andric }
183ac9a064cSDimitry Andric
184ac9a064cSDimitry Andric INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfoWrapperPass, DEBUG_TYPE,
185ac9a064cSDimitry Andric "Machine Block Frequency Analysis", true, true)
186ac9a064cSDimitry Andric INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
187ac9a064cSDimitry Andric INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
188ac9a064cSDimitry Andric INITIALIZE_PASS_END(MachineBlockFrequencyInfoWrapperPass, DEBUG_TYPE,
189ac9a064cSDimitry Andric "Machine Block Frequency Analysis", true, true)
190ac9a064cSDimitry Andric
191ac9a064cSDimitry Andric char MachineBlockFrequencyInfoWrapperPass::ID = 0;
192ac9a064cSDimitry Andric
MachineBlockFrequencyInfoWrapperPass()193ac9a064cSDimitry Andric MachineBlockFrequencyInfoWrapperPass::MachineBlockFrequencyInfoWrapperPass()
194ac9a064cSDimitry Andric : MachineFunctionPass(ID) {
195ac9a064cSDimitry Andric initializeMachineBlockFrequencyInfoWrapperPassPass(
196ac9a064cSDimitry Andric *PassRegistry::getPassRegistry());
197ac9a064cSDimitry Andric }
198ac9a064cSDimitry Andric
199ac9a064cSDimitry Andric MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() = default;
200ac9a064cSDimitry Andric
201706b4fc4SDimitry Andric MachineBlockFrequencyInfo::MachineBlockFrequencyInfo(
202ac9a064cSDimitry Andric MachineBlockFrequencyInfo &&) = default;
203ac9a064cSDimitry Andric
MachineBlockFrequencyInfo(MachineFunction & F,MachineBranchProbabilityInfo & MBPI,MachineLoopInfo & MLI)204ac9a064cSDimitry Andric MachineBlockFrequencyInfo::MachineBlockFrequencyInfo(
205ac9a064cSDimitry Andric MachineFunction &F, MachineBranchProbabilityInfo &MBPI,
206ac9a064cSDimitry Andric MachineLoopInfo &MLI) {
207706b4fc4SDimitry Andric calculate(F, MBPI, MLI);
208706b4fc4SDimitry Andric }
209706b4fc4SDimitry Andric
210044eb2f6SDimitry Andric MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default;
21130815c53SDimitry Andric
invalidate(MachineFunction & MF,const PreservedAnalyses & PA,MachineFunctionAnalysisManager::Invalidator &)212ac9a064cSDimitry Andric bool MachineBlockFrequencyInfo::invalidate(
213ac9a064cSDimitry Andric MachineFunction &MF, const PreservedAnalyses &PA,
214ac9a064cSDimitry Andric MachineFunctionAnalysisManager::Invalidator &) {
215ac9a064cSDimitry Andric // Check whether the analysis, all analyses on machine functions, or the
216ac9a064cSDimitry Andric // machine function's CFG have been preserved.
217ac9a064cSDimitry Andric auto PAC = PA.getChecker<MachineBlockFrequencyAnalysis>();
218ac9a064cSDimitry Andric return !PAC.preserved() &&
219ac9a064cSDimitry Andric !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() &&
220ac9a064cSDimitry Andric !PAC.preservedSet<CFGAnalyses>();
221ac9a064cSDimitry Andric }
222ac9a064cSDimitry Andric
getAnalysisUsage(AnalysisUsage & AU) const223ac9a064cSDimitry Andric void MachineBlockFrequencyInfoWrapperPass::getAnalysisUsage(
224ac9a064cSDimitry Andric AnalysisUsage &AU) const {
225ac9a064cSDimitry Andric AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
226ac9a064cSDimitry Andric AU.addRequired<MachineLoopInfoWrapperPass>();
22730815c53SDimitry Andric AU.setPreservesAll();
22830815c53SDimitry Andric MachineFunctionPass::getAnalysisUsage(AU);
22930815c53SDimitry Andric }
23030815c53SDimitry Andric
calculate(const MachineFunction & F,const MachineBranchProbabilityInfo & MBPI,const MachineLoopInfo & MLI)23171d5a254SDimitry Andric void MachineBlockFrequencyInfo::calculate(
23271d5a254SDimitry Andric const MachineFunction &F, const MachineBranchProbabilityInfo &MBPI,
23371d5a254SDimitry Andric const MachineLoopInfo &MLI) {
23471d5a254SDimitry Andric if (!MBFI)
23571d5a254SDimitry Andric MBFI.reset(new ImplType);
23671d5a254SDimitry Andric MBFI->calculate(F, MBPI, MLI);
23771d5a254SDimitry Andric if (ViewMachineBlockFreqPropagationDAG != GVDT_None &&
238ac9a064cSDimitry Andric (ViewBlockFreqFuncName.empty() || F.getName() == ViewBlockFreqFuncName)) {
23971d5a254SDimitry Andric view("MachineBlockFrequencyDAGS." + F.getName());
24071d5a254SDimitry Andric }
241044eb2f6SDimitry Andric if (PrintMachineBlockFreq &&
242ac9a064cSDimitry Andric (PrintBFIFuncName.empty() || F.getName() == PrintBFIFuncName)) {
243044eb2f6SDimitry Andric MBFI->print(dbgs());
244044eb2f6SDimitry Andric }
24571d5a254SDimitry Andric }
24671d5a254SDimitry Andric
runOnMachineFunction(MachineFunction & F)247ac9a064cSDimitry Andric bool MachineBlockFrequencyInfoWrapperPass::runOnMachineFunction(
248ac9a064cSDimitry Andric MachineFunction &F) {
2495ca98fd9SDimitry Andric MachineBranchProbabilityInfo &MBPI =
250ac9a064cSDimitry Andric getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
251ac9a064cSDimitry Andric MachineLoopInfo &MLI = getAnalysis<MachineLoopInfoWrapperPass>().getLI();
252ac9a064cSDimitry Andric MBFI.calculate(F, MBPI, MLI);
25330815c53SDimitry Andric return false;
25430815c53SDimitry Andric }
25530815c53SDimitry Andric
print(raw_ostream & OS)256ac9a064cSDimitry Andric void MachineBlockFrequencyInfo::print(raw_ostream &OS) { MBFI->print(OS); }
257ac9a064cSDimitry Andric
releaseMemory()2585ca98fd9SDimitry Andric void MachineBlockFrequencyInfo::releaseMemory() { MBFI.reset(); }
2595ca98fd9SDimitry Andric
2605ca98fd9SDimitry Andric /// Pop up a ghostview window with the current block frequency propagation
2615ca98fd9SDimitry Andric /// rendered using dot.
view(const Twine & Name,bool isSimple) const26271d5a254SDimitry Andric void MachineBlockFrequencyInfo::view(const Twine &Name, bool isSimple) const {
2635ca98fd9SDimitry Andric // This code is only for debugging.
26471d5a254SDimitry Andric ViewGraph(const_cast<MachineBlockFrequencyInfo *>(this), Name, isSimple);
2655ca98fd9SDimitry Andric }
2665ca98fd9SDimitry Andric
26701095a5dSDimitry Andric BlockFrequency
getBlockFreq(const MachineBasicBlock * MBB) const26801095a5dSDimitry Andric MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const {
269b1c73532SDimitry Andric return MBFI ? MBFI->getBlockFreq(MBB) : BlockFrequency(0);
2705ca98fd9SDimitry Andric }
2715ca98fd9SDimitry Andric
getBlockProfileCount(const MachineBasicBlock * MBB) const272e3b55780SDimitry Andric std::optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
27301095a5dSDimitry Andric const MachineBasicBlock *MBB) const {
274344a3780SDimitry Andric if (!MBFI)
275e3b55780SDimitry Andric return std::nullopt;
276344a3780SDimitry Andric
277044eb2f6SDimitry Andric const Function &F = MBFI->getFunction()->getFunction();
278344a3780SDimitry Andric return MBFI->getBlockProfileCount(F, MBB);
27901095a5dSDimitry Andric }
28001095a5dSDimitry Andric
281e3b55780SDimitry Andric std::optional<uint64_t>
getProfileCountFromFreq(BlockFrequency Freq) const282b1c73532SDimitry Andric MachineBlockFrequencyInfo::getProfileCountFromFreq(BlockFrequency Freq) const {
283344a3780SDimitry Andric if (!MBFI)
284e3b55780SDimitry Andric return std::nullopt;
285344a3780SDimitry Andric
286044eb2f6SDimitry Andric const Function &F = MBFI->getFunction()->getFunction();
287344a3780SDimitry Andric return MBFI->getProfileCountFromFreq(F, Freq);
288044eb2f6SDimitry Andric }
289044eb2f6SDimitry Andric
isIrrLoopHeader(const MachineBasicBlock * MBB) const290b60736ecSDimitry Andric bool MachineBlockFrequencyInfo::isIrrLoopHeader(
291b60736ecSDimitry Andric const MachineBasicBlock *MBB) const {
292044eb2f6SDimitry Andric assert(MBFI && "Expected analysis to be available");
293044eb2f6SDimitry Andric return MBFI->isIrrLoopHeader(MBB);
294b915e9e0SDimitry Andric }
295b915e9e0SDimitry Andric
onEdgeSplit(const MachineBasicBlock & NewPredecessor,const MachineBasicBlock & NewSuccessor,const MachineBranchProbabilityInfo & MBPI)296b60736ecSDimitry Andric void MachineBlockFrequencyInfo::onEdgeSplit(
297b60736ecSDimitry Andric const MachineBasicBlock &NewPredecessor,
298b60736ecSDimitry Andric const MachineBasicBlock &NewSuccessor,
299b60736ecSDimitry Andric const MachineBranchProbabilityInfo &MBPI) {
300cfca06d7SDimitry Andric assert(MBFI && "Expected analysis to be available");
301b60736ecSDimitry Andric auto NewSuccFreq = MBFI->getBlockFreq(&NewPredecessor) *
302b60736ecSDimitry Andric MBPI.getEdgeProbability(&NewPredecessor, &NewSuccessor);
303b60736ecSDimitry Andric
304b1c73532SDimitry Andric MBFI->setBlockFreq(&NewSuccessor, NewSuccFreq);
305cfca06d7SDimitry Andric }
306cfca06d7SDimitry Andric
getFunction() const3075ca98fd9SDimitry Andric const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {
3085ca98fd9SDimitry Andric return MBFI ? MBFI->getFunction() : nullptr;
3095ca98fd9SDimitry Andric }
3105ca98fd9SDimitry Andric
getMBPI() const31101095a5dSDimitry Andric const MachineBranchProbabilityInfo *MachineBlockFrequencyInfo::getMBPI() const {
31201095a5dSDimitry Andric return MBFI ? &MBFI->getBPI() : nullptr;
31301095a5dSDimitry Andric }
31401095a5dSDimitry Andric
getEntryFreq() const315b1c73532SDimitry Andric BlockFrequency MachineBlockFrequencyInfo::getEntryFreq() const {
316b1c73532SDimitry Andric return MBFI ? MBFI->getEntryFreq() : BlockFrequency(0);
3175ca98fd9SDimitry Andric }
3185ca98fd9SDimitry Andric
printBlockFreq(const MachineBlockFrequencyInfo & MBFI,BlockFrequency Freq)319b1c73532SDimitry Andric Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
320b1c73532SDimitry Andric BlockFrequency Freq) {
321b1c73532SDimitry Andric return Printable([&MBFI, Freq](raw_ostream &OS) {
322ac9a064cSDimitry Andric printRelativeBlockFreq(OS, MBFI.getEntryFreq(), Freq);
323b1c73532SDimitry Andric });
3245ca98fd9SDimitry Andric }
3255ca98fd9SDimitry Andric
printBlockFreq(const MachineBlockFrequencyInfo & MBFI,const MachineBasicBlock & MBB)326b1c73532SDimitry Andric Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
327b1c73532SDimitry Andric const MachineBasicBlock &MBB) {
328b1c73532SDimitry Andric return printBlockFreq(MBFI, MBFI.getBlockFreq(&MBB));
32930815c53SDimitry Andric }
330