#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/iterator.h"
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/GraphWriter.h"
#include <optional>
#include <string>
usingnamespacellvm;
#define DEBUG_TYPE …
namespace llvm {
static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
"view-machine-block-freq-propagation-dags", cl::Hidden,
cl::desc("Pop up a window to show a dag displaying how machine block "
"frequencies propagate through the CFG."),
cl::values(clEnumValN(GVDT_None, "none", "do not display graphs."),
clEnumValN(GVDT_Fraction, "fraction",
"display a graph using the "
"fractional block frequency representation."),
clEnumValN(GVDT_Integer, "integer",
"display a graph using the raw "
"integer fractional block frequency representation."),
clEnumValN(GVDT_Count, "count", "display a graph using the real "
"profile count if available.")));
cl::opt<GVDAGType> ViewBlockLayoutWithBFI(
"view-block-layout-with-bfi", cl::Hidden,
cl::desc(
"Pop up a window to show a dag displaying MBP layout and associated "
"block frequencies of the CFG."),
cl::values(clEnumValN(GVDT_None, "none", "do not display graphs."),
clEnumValN(GVDT_Fraction, "fraction",
"display a graph using the "
"fractional block frequency representation."),
clEnumValN(GVDT_Integer, "integer",
"display a graph using the raw "
"integer fractional block frequency representation."),
clEnumValN(GVDT_Count, "count",
"display a graph using the real "
"profile count if available.")));
extern cl::opt<std::string> ViewBlockFreqFuncName;
extern cl::opt<unsigned> ViewHotFreqPercent;
static cl::opt<bool> PrintMachineBlockFreq(
"print-machine-bfi", cl::init(false), cl::Hidden,
cl::desc("Print the machine block frequency info."));
extern cl::opt<std::string> PrintBFIFuncName;
}
static GVDAGType getGVDT() { … }
namespace llvm {
template <> struct GraphTraits<MachineBlockFrequencyInfo *> { … };
MBFIDOTGraphTraitsBase;
template <>
struct DOTGraphTraits<MachineBlockFrequencyInfo *>
: public MBFIDOTGraphTraitsBase { … };
}
AnalysisKey MachineBlockFrequencyAnalysis::Key;
MachineBlockFrequencyAnalysis::Result
MachineBlockFrequencyAnalysis::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) { … }
PreservedAnalyses
MachineBlockFrequencyPrinterPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) { … }
INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfoWrapperPass, DEBUG_TYPE,
"Machine Block Frequency Analysis", true, true)
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
INITIALIZE_PASS_END(MachineBlockFrequencyInfoWrapperPass, DEBUG_TYPE,
"Machine Block Frequency Analysis", true, true)
char MachineBlockFrequencyInfoWrapperPass::ID = …;
MachineBlockFrequencyInfoWrapperPass::MachineBlockFrequencyInfoWrapperPass()
: … { … }
MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() = default;
MachineBlockFrequencyInfo::MachineBlockFrequencyInfo(
MachineBlockFrequencyInfo &&) = default;
MachineBlockFrequencyInfo::MachineBlockFrequencyInfo(
MachineFunction &F, MachineBranchProbabilityInfo &MBPI,
MachineLoopInfo &MLI) { … }
MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default;
bool MachineBlockFrequencyInfo::invalidate(
MachineFunction &MF, const PreservedAnalyses &PA,
MachineFunctionAnalysisManager::Invalidator &) { … }
void MachineBlockFrequencyInfoWrapperPass::getAnalysisUsage(
AnalysisUsage &AU) const { … }
void MachineBlockFrequencyInfo::calculate(
const MachineFunction &F, const MachineBranchProbabilityInfo &MBPI,
const MachineLoopInfo &MLI) { … }
bool MachineBlockFrequencyInfoWrapperPass::runOnMachineFunction(
MachineFunction &F) { … }
void MachineBlockFrequencyInfo::print(raw_ostream &OS) { … }
void MachineBlockFrequencyInfo::releaseMemory() { … }
void MachineBlockFrequencyInfo::view(const Twine &Name, bool isSimple) const { … }
BlockFrequency
MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const { … }
std::optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
const MachineBasicBlock *MBB) const { … }
std::optional<uint64_t>
MachineBlockFrequencyInfo::getProfileCountFromFreq(BlockFrequency Freq) const { … }
bool MachineBlockFrequencyInfo::isIrrLoopHeader(
const MachineBasicBlock *MBB) const { … }
void MachineBlockFrequencyInfo::onEdgeSplit(
const MachineBasicBlock &NewPredecessor,
const MachineBasicBlock &NewSuccessor,
const MachineBranchProbabilityInfo &MBPI) { … }
const MachineFunction *MachineBlockFrequencyInfo::getFunction() const { … }
const MachineBranchProbabilityInfo *MachineBlockFrequencyInfo::getMBPI() const { … }
BlockFrequency MachineBlockFrequencyInfo::getEntryFreq() const { … }
Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
BlockFrequency Freq) { … }
Printable llvm::printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
const MachineBasicBlock &MBB) { … }