| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H |
| 14 |
#define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H |
| 15 |
|
| 16 |
#include "llvm/ADT/Optional.h" |
| 17 |
#include "llvm/CodeGen/MachineFunctionPass.h" |
| 18 |
#include "llvm/Support/BlockFrequency.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 |
|
| 32 |
|
| 33 |
class MachineBlockFrequencyInfo : public MachineFunctionPass { |
| 34 |
using ImplType = BlockFrequencyInfoImpl<MachineBasicBlock>; |
| 35 |
std::unique_ptr<ImplType> MBFI; |
| 36 |
|
| 37 |
public: |
| 38 |
static char ID; |
| 39 |
|
| 40 |
MachineBlockFrequencyInfo(); |
| 41 |
explicit MachineBlockFrequencyInfo(MachineFunction &F, |
| 42 |
MachineBranchProbabilityInfo &MBPI, |
| 43 |
MachineLoopInfo &MLI); |
| 44 |
~MachineBlockFrequencyInfo() override; |
| 45 |
|
| 46 |
void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 47 |
|
| 48 |
bool runOnMachineFunction(MachineFunction &F) override; |
| 49 |
|
| 50 |
|
| 51 |
void calculate(const MachineFunction &F, |
| 52 |
const MachineBranchProbabilityInfo &MBPI, |
| 53 |
const MachineLoopInfo &MLI); |
| 54 |
|
| 55 |
void releaseMemory() override; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
float getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const { |
| 69 |
return getBlockFreq(MBB).getFrequency() * (1.0f / getEntryFreq()); |
| 70 |
} |
| 71 |
|
| 72 |
Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const; |
| 73 |
Optional<uint64_t> getProfileCountFromFreq(uint64_t Freq) const; |
| 74 |
|
| 75 |
bool isIrrLoopHeader(const MachineBasicBlock *MBB) const; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void onEdgeSplit(const MachineBasicBlock &NewPredecessor, |
| 80 |
const MachineBasicBlock &NewSuccessor, |
| 81 |
const MachineBranchProbabilityInfo &MBPI); |
| 82 |
|
| 83 |
const MachineFunction *getFunction() const; |
| 84 |
const MachineBranchProbabilityInfo *getMBPI() const; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
void view(const Twine &Name, bool isSimple = true) const; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
raw_ostream &printBlockFreq(raw_ostream &OS, |
| 97 |
const MachineBasicBlock *MBB) const; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
uint64_t getEntryFreq() const; |
| 102 |
}; |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
#endif |