29 #define DEBUG_TYPE "machine-block-freq"
33 "view-machine-block-freq-propagation-dags",
cl::Hidden,
34 cl::desc(
"Pop up a window to show a dag displaying how machine block "
35 "frequencies propagate through the CFG."),
38 "display a graph using the "
39 "fractional block frequency representation."),
41 "display a graph using the raw "
42 "integer fractional block frequency representation."),
44 "profile count if available.")));
49 "Pop up a window to show a dag displaying MBP layout and associated "
50 "block frequencies of the CFG."),
53 "display a graph using the "
54 "fractional block frequency representation."),
56 "display a graph using the raw "
57 "integer fractional block frequency representation."),
59 "display a graph using the real "
60 "profile count if available.")));
117 int layout_order = -1;
121 if (!CurFunc || F != CurFunc) {
123 LayoutOrderMap.
clear();
127 for (
auto MBI = F->
begin(); MBI != F->
end(); ++MBI, ++O) {
128 LayoutOrderMap[&*MBI] = O;
131 layout_order = LayoutOrderMap[Node];
153 "Machine Block Frequency Analysis",
true,
true)
159 char MachineBlockFrequencyInfo::
ID = 0;
161 MachineBlockFrequencyInfo::MachineBlockFrequencyInfo()
180 MBFI->calculate(F, MBPI, MLI);
190 getAnalysis<MachineBranchProbabilityInfo>();
202 ViewGraph(const_cast<MachineBlockFrequencyInfo *>(
this), Name, isSimple);
207 return MBFI ? MBFI->getBlockFreq(MBB) : 0;
212 const Function *
F = MBFI->getFunction()->getFunction();
213 return MBFI ? MBFI->getBlockProfileCount(*F, MBB) :
None;
218 const Function *
F = MBFI->getFunction()->getFunction();
219 return MBFI ? MBFI->getProfileCountFromFreq(*F, Freq) :
None;
223 return MBFI ? MBFI->getFunction() :
nullptr;
227 return MBFI ? &MBFI->getBPI() :
nullptr;
233 return MBFI ? MBFI->printBlockFreq(OS, Freq) : OS;
239 return MBFI ? MBFI->printBlockFreq(OS, MBB) : OS;
243 return MBFI ? MBFI->getEntryFreq() : 0;
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
std::string getNodeAttributes(const MachineBasicBlock *Node, const MachineBlockFrequencyInfo *Graph)
cl::opt< unsigned > ViewHotFreqPercent
const MachineBasicBlock * NodeRef
static ChildIteratorType child_end(const NodeRef N)
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
static GVDAGType getGVDT()
const MachineFunction * CurFunc
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
static ChildIteratorType child_begin(const NodeRef N)
Machine Block Frequency Analysis
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
uint64_t getEntryFreq() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
std::string getNodeLabel(const MachineBasicBlock *Node, const MachineBlockFrequencyInfo *Graph)
std::string getNodeLabel(NodeRef Node, const BlockFrequencyInfoT *Graph, GVDAGType GType, int layout_order=-1)
pointer_iterator< MachineFunction::const_iterator > nodes_iterator
static bool isSimple(Instruction *I)
const MachineBasicBlock & front() const
BFIDOTGraphTraitsBase< MachineBlockFrequencyInfo, MachineBranchProbabilityInfo > MBFIDOTGraphTraitsBase
DOTGraphTraits(bool isSimple=false)
~MachineBlockFrequencyInfo() override
std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI, const MachineBlockFrequencyInfo *MBFI)
static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G)
static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G)
ValuesClass values(OptsTy...Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
raw_ostream & printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
DenseMap< const MachineBasicBlock *, int > LayoutOrderMap
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.
Optional< uint64_t > getProfileCountFromFreq(uint64_t Freq) const
succ_iterator succ_begin()
std::string getEdgeAttributes(NodeRef Node, EdgeIter EI, const BlockFrequencyInfoT *BFI, const BranchProbabilityInfoT *BPI, unsigned HotPercentThreshold=0)
void view(const Twine &Name, bool isSimple=true) const
Pop up a ghostview window with the current block frequency propagation rendered using dot...
void initializeMachineBlockFrequencyInfoPass(PassRegistry &)
Optional< uint64_t > getBlockProfileCount(const MachineBasicBlock *MBB) const
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
std::string getNodeAttributes(NodeRef Node, const BlockFrequencyInfoT *Graph, unsigned HotPercentThreshold=0)
MachineBasicBlock::const_succ_iterator ChildIteratorType
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const MachineBranchProbabilityInfo * getMBPI() const
GTraits::ChildIteratorType EdgeIter
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.")))
void setPreservesAll()
Set by analyses that do not transform their input at all.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
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.")))
static nodes_iterator nodes_end(const MachineBlockFrequencyInfo *G)
cl::opt< std::string > ViewBlockFreqFuncName
This class implements an extremely fast bulk output stream that can only output to a stream...
void calculate(const MachineFunction &F, const MachineBranchProbabilityInfo &MBPI, const MachineLoopInfo &MLI)
calculate - compute block frequency info for the given function.
Shared implementation for block frequency analysis.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Machine Block Frequency true
INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfo, DEBUG_TYPE,"Machine Block Frequency Analysis", true, true) INITIALIZE_PASS_END(MachineBlockFrequencyInfo
const MachineFunction * getFunction() const