LLVM  14.0.0git
MachineBlockFrequencyInfo.h
Go to the documentation of this file.
1 //===- MachineBlockFrequencyInfo.h - MBB Frequency Analysis -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Loops should be simplified before this analysis.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
14 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
15 
16 #include "llvm/ADT/Optional.h"
19 #include <cstdint>
20 #include <memory>
21 
22 namespace llvm {
23 
24 template <class BlockT> class BlockFrequencyInfoImpl;
25 class MachineBasicBlock;
26 class MachineBranchProbabilityInfo;
27 class MachineFunction;
28 class MachineLoopInfo;
29 class raw_ostream;
30 
31 /// MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation
32 /// to estimate machine basic block frequencies.
35  std::unique_ptr<ImplType> MBFI;
36 
37 public:
38  static char ID;
39 
43  MachineLoopInfo &MLI);
44  ~MachineBlockFrequencyInfo() override;
45 
46  void getAnalysisUsage(AnalysisUsage &AU) const override;
47 
48  bool runOnMachineFunction(MachineFunction &F) override;
49 
50  /// calculate - compute block frequency info for the given function.
51  void calculate(const MachineFunction &F,
52  const MachineBranchProbabilityInfo &MBPI,
53  const MachineLoopInfo &MLI);
54 
55  void releaseMemory() override;
56 
57  /// getblockFreq - Return block frequency. Return 0 if we don't have the
58  /// information. Please note that initial frequency is equal to 1024. It means
59  /// that we should not rely on the value itself, but only on the comparison to
60  /// the other block frequencies. We do this to avoid using of floating points.
61  /// For example, to get the frequency of a block relative to the entry block,
62  /// divide the integral value returned by this function (the
63  /// BlockFrequency::getFrequency() value) by getEntryFreq().
65 
66  /// Compute the frequency of the block, relative to the entry block.
67  /// This API assumes getEntryFreq() is non-zero.
69  return getBlockFreq(MBB).getFrequency() * (1.0f / getEntryFreq());
70  }
71 
73  Optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const;
74 
75  bool isIrrLoopHeader(const MachineBasicBlock *MBB) const;
76 
77  /// incrementally calculate block frequencies when we split edges, to avoid
78  /// full CFG traversal.
79  void onEdgeSplit(const MachineBasicBlock &NewPredecessor,
80  const MachineBasicBlock &NewSuccessor,
81  const MachineBranchProbabilityInfo &MBPI);
82 
83  const MachineFunction *getFunction() const;
85 
86  /// Pop up a ghostview window with the current block frequency propagation
87  /// rendered using dot.
88  void view(const Twine &Name, bool isSimple = true) const;
89 
90  // Print the block frequency Freq to OS using the current functions entry
91  // frequency to convert freq into a relative decimal form.
92  raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
93 
94  // Convenience method that attempts to look up the frequency associated with
95  // BB and print it to OS.
97  const MachineBasicBlock *MBB) const;
98 
99  /// Divide a block's BlockFrequency::getFrequency() value by this value to
100  /// obtain the entry block - relative frequency of said block.
101  uint64_t getEntryFreq() const;
102 };
103 
104 } // end namespace llvm
105 
106 #endif // LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Optional.h
llvm::MachineBlockFrequencyInfo::getBlockProfileCount
Optional< uint64_t > getBlockProfileCount(const MachineBasicBlock *MBB) const
Definition: MachineBlockFrequencyInfo.cpp:234
llvm::MachineBlockFrequencyInfo::getProfileCountFromFreq
Optional< uint64_t > getProfileCountFromFreq(uint64_t Freq) const
Definition: MachineBlockFrequencyInfo.cpp:244
llvm::MachineBlockFrequencyInfo::getBlockFreqRelativeToEntryBlock
float getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const
Compute the frequency of the block, relative to the entry block.
Definition: MachineBlockFrequencyInfo.h:68
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineBlockFrequencyInfo::view
void view(const Twine &Name, bool isSimple=true) const
Pop up a ghostview window with the current block frequency propagation rendered using dot.
Definition: MachineBlockFrequencyInfo.cpp:224
BlockFrequency.h
llvm::Optional< uint64_t >
llvm::MachineBlockFrequencyInfo::getBlockFreq
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
Definition: MachineBlockFrequencyInfo.cpp:230
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:90
llvm::MachineBlockFrequencyInfo
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Definition: MachineBlockFrequencyInfo.h:33
llvm::MachineBranchProbabilityInfo
Definition: MachineBranchProbabilityInfo.h:24
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineBlockFrequencyInfo::calculate
void calculate(const MachineFunction &F, const MachineBranchProbabilityInfo &MBPI, const MachineLoopInfo &MLI)
calculate - compute block frequency info for the given function.
Definition: MachineBlockFrequencyInfo.cpp:194
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MachineBlockFrequencyInfo::ID
static char ID
Definition: MachineBlockFrequencyInfo.h:38
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineBlockFrequencyInfo::releaseMemory
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: MachineBlockFrequencyInfo.cpp:220
llvm::MachineBlockFrequencyInfo::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: MachineBlockFrequencyInfo.cpp:187
llvm::BlockFrequency
Definition: BlockFrequency.h:24
llvm::MachineBlockFrequencyInfo::onEdgeSplit
void onEdgeSplit(const MachineBasicBlock &NewPredecessor, const MachineBasicBlock &NewSuccessor, const MachineBranchProbabilityInfo &MBPI)
incrementally calculate block frequencies when we split edges, to avoid full CFG traversal.
Definition: MachineBlockFrequencyInfo.cpp:258
llvm::BlockFrequency::getFrequency
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Definition: BlockFrequency.h:35
llvm::MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo
~MachineBlockFrequencyInfo() override
MachineFunctionPass.h
llvm::MachineBlockFrequencyInfo::getFunction
const MachineFunction * getFunction() const
Definition: MachineBlockFrequencyInfo.cpp:269
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::MachineBlockFrequencyInfo::MachineBlockFrequencyInfo
MachineBlockFrequencyInfo()
Definition: MachineBlockFrequencyInfo.cpp:173
llvm::MachineBlockFrequencyInfo::printBlockFreq
raw_ostream & printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const
Definition: MachineBlockFrequencyInfo.cpp:278
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
isSimple
static bool isSimple(Instruction *I)
Definition: SLPVectorizer.cpp:528
llvm::MachineBlockFrequencyInfo::getMBPI
const MachineBranchProbabilityInfo * getMBPI() const
Definition: MachineBlockFrequencyInfo.cpp:273
llvm::BlockFrequencyInfoImpl
Shared implementation for block frequency analysis.
Definition: BlockFrequencyInfo.h:31
llvm::MachineBlockFrequencyInfo::isIrrLoopHeader
bool isIrrLoopHeader(const MachineBasicBlock *MBB) const
Definition: MachineBlockFrequencyInfo.cpp:252
llvm::MachineBlockFrequencyInfo::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: MachineBlockFrequencyInfo.cpp:212
llvm::MachineBlockFrequencyInfo::getEntryFreq
uint64_t getEntryFreq() const
Divide a block's BlockFrequency::getFrequency() value by this value to obtain the entry block - relat...
Definition: MachineBlockFrequencyInfo.cpp:289