Go to the documentation of this file.
33 #define DEBUG_TYPE "block-freq"
36 "view-block-freq-propagation-dags",
cl::Hidden,
37 cl::desc(
"Pop up a window to show a dag displaying how block "
38 "frequencies propagation through the CFG."),
41 "display a graph using the "
42 "fractional block frequency representation."),
44 "display a graph using the raw "
45 "integer fractional block frequency representation."),
47 "profile count if available.")));
53 "the name of the function "
54 "whose CFG will be displayed."));
58 cl::desc(
"An integer in percent used to specify "
59 "the hot blocks/edges to be displayed "
60 "in red: a block or edge whose frequency "
61 "is no less than the max frequency of the "
62 "function multiplied by this percent."));
67 cl::desc(
"A boolean option to show CFG dag or text with "
68 "block profile counts and branch probabilities "
69 "right after PGO profile annotation step. The "
70 "profile counts are computed using branch "
71 "probabilities from the runtime profile data and "
72 "block frequency propagation algorithm. To view "
73 "the raw counts from the profile, use option "
74 "-pgo-view-raw-counts instead. To limit graph "
75 "display to only one function, use filtering option "
76 "-view-bfi-func-name."),
83 cl::desc(
"Print the block frequency info."));
87 cl::desc(
"The option to specify the name of the function "
88 "whose block frequency info is printed."));
106 return &
G->getFunction()->front();
190 BFI->calculate(
F, BPI, LI);
204 return BFI ?
BFI->getBlockFreq(
BB) : 0;
209 bool AllowSynthetic)
const {
224 assert(
BFI &&
"Expected analysis to be available");
225 return BFI->isIrrLoopHeader(
BB);
229 assert(
BFI &&
"Expected analysis to be available");
230 BFI->setBlockFreq(
BB, Freq);
236 assert(
BFI &&
"Expected analysis to be available");
238 APInt NewFreq(128, Freq);
239 APInt OldFreq(128,
BFI->getBlockFreq(ReferenceBB).getFrequency());
240 APInt BBFreq(128, 0);
241 for (
auto *
BB : BlocksToScale) {
242 BBFreq =
BFI->getBlockFreq(
BB).getFrequency();
249 BBFreq = BBFreq.
udiv(OldFreq);
252 BFI->setBlockFreq(ReferenceBB, Freq);
262 return BFI ?
BFI->getFunction() :
nullptr;
266 return BFI ? &
BFI->getBPI() :
nullptr;
271 return BFI ?
BFI->printBlockFreq(OS, Freq) : OS;
277 return BFI ?
BFI->printBlockFreq(OS,
BB) : OS;
281 return BFI ?
BFI->getEntryFreq() : 0;
297 "Block Frequency Analysis",
true,
true)
327 getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
328 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
329 BFI.calculate(
F, BPI, LI);
344 OS <<
"Printing analysis results of BFI for function "
345 <<
"'" <<
F.getName() <<
"':"
A set of analyses that are preserved following a run of a transformation pass.
we get the following basic block
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< unsigned > ViewHotFreqPercent("view-hot-freq-percent", cl::init(10), cl::Hidden, cl::desc("An integer in percent used to specify " "the hot blocks/edges to be displayed " "in red: a block or edge whose frequency " "is no less than the max frequency of the " "function multiplied by this percent."))
std::string getNodeLabel(const BasicBlock *Node, const BlockFrequencyInfo *Graph)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
void print(raw_ostream &OS) const
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Interval::succ_iterator succ_end(Interval *I)
Legacy analysis pass which computes BlockFrequencyInfo.
static ChildIteratorType child_begin(const NodeRef N)
block Block Frequency true
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
void view(StringRef="BlockFrequencyDAGs") const
Pop up a ghostview window with the current block frequency propagation rendered using dot.
static NodeRef getEntryNode(const BlockFrequencyInfo *G)
The legacy pass manager's analysis pass to compute loop information.
~BlockFrequencyInfoWrapperPass() override
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
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.
LLVM Basic Block Representation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
std::string getNodeLabel(NodeRef Node, const BlockFrequencyInfoT *Graph, GVDAGType GType, int layout_order=-1)
uint64_t getEntryFreq() const
Analysis pass which computes BranchProbabilityInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Legacy analysis pass which computes BranchProbabilityInfo.
Optional< uint64_t > getProfileCountFromFreq(uint64_t Freq) const
Returns the estimated profile count of Freq.
Analysis providing branch probability information.
Represent the analysis usage information of a pass.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
void setBlockFreq(const BasicBlock *BB, uint64_t Freq)
This class implements an extremely fast bulk output stream that can only output to a stream.
cl::opt< std::string > PrintBlockFreqFuncName("print-bfi-func-name", cl::Hidden, cl::desc("The option to specify the name of the function " "whose block frequency info is printed."))
std::string getEdgeAttributes(NodeRef Node, EdgeIter EI, const BlockFrequencyInfoT *BFI, const BranchProbabilityInfoT *BPI, unsigned HotPercentThreshold=0)
API to communicate dependencies between analyses during invalidation.
raw_ostream & printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const
Analysis pass which computes BlockFrequencyInfo.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
cl::opt< PGOViewCountsType > PGOViewCounts("pgo-view-counts", cl::Hidden, cl::desc("A boolean option to show CFG dag or text with " "block profile counts and branch probabilities " "right after PGO profile annotation step. The " "profile counts are computed using branch " "probabilities from the runtime profile data and " "block frequency propagation algorithm. To view " "the raw counts from the profile, use option " "-pgo-view-raw-counts instead. To limit graph " "display to only one function, use filtering option " "-view-bfi-func-name."), cl::values(clEnumValN(PGOVCT_None, "none", "do not show."), clEnumValN(PGOVCT_Graph, "graph", "show a graph."), clEnumValN(PGOVCT_Text, "text", "show in text.")))
INITIALIZE_PASS_BEGIN(BlockFrequencyInfoWrapperPass, "block-freq", "Block Frequency Analysis", true, true) INITIALIZE_PASS_END(BlockFrequencyInfoWrapperPass
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
A special type used by analysis passes to provide an address that identifies that particular analysis...
static cl::opt< GVDAGType > ViewBlockFreqPropagationDAG("view-block-freq-propagation-dags", cl::Hidden, cl::desc("Pop up a window to show a dag displaying how block " "frequencies propagation 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.")))
static cl::opt< bool > PrintBlockFreq("print-bfi", cl::init(false), cl::Hidden, cl::desc("Print the block frequency info."))
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
initializer< Ty > init(const Ty &Val)
BlockFrequencyInfo & operator=(const BlockFrequencyInfo &)=delete
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
typename GTraits::ChildIteratorType EdgeIter
bool isIrrLoopHeader(const BasicBlock *BB)
Returns true if BB is an irreducible loop header block.
A Module instance is used to store all the information related to an LLVM module.
Class for arbitrary precision integers.
std::string getNodeAttributes(NodeRef Node, const BlockFrequencyInfoT *Graph, unsigned HotPercentThreshold=0)
void calculate(const Function &F, const BranchProbabilityInfo &BPI, const LoopInfo &LI)
calculate - compute block frequency info for the given function.
StringRef - Represent a constant reference to a string, i.e.
Represents analyses that only rely on functions' control flow.
static ChildIteratorType child_end(const NodeRef N)
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
APInt udiv(const APInt &RHS) const
Unsigned division operation.
block Block Frequency Analysis
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, uint64_t Freq, SmallPtrSetImpl< BasicBlock * > &BlocksToScale)
Set the frequency of ReferenceBB to Freq and scale the frequencies of the blocks in BlocksToScale suc...
std::string getNodeAttributes(const BasicBlock *Node, const BlockFrequencyInfo *Graph)
void setPreservesAll()
Set by analyses that do not transform their input at all.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
DOTGraphTraits(bool isSimple=false)
Result run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce BFI.
static nodes_iterator nodes_begin(const BlockFrequencyInfo *G)
std::string getEdgeAttributes(const BasicBlock *Node, EdgeIter EI, const BlockFrequencyInfo *BFI)
const BranchProbabilityInfo * getBPI() const
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
static bool isSimple(Instruction *I)
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
static GVDAGType getGVDT()
const Function * getFunction() const
Optional< uint64_t > getBlockProfileCount(const BasicBlock *BB, bool AllowSynthetic=false) const
Returns the estimated profile count of BB.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void verifyMatch(BlockFrequencyInfo &Other) const
Shared implementation for block frequency analysis.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
A container for analyses that lazily runs them and caches their results.
FunctionPass class - This class is used to implement most global optimizations.
static nodes_iterator nodes_end(const BlockFrequencyInfo *G)
void initializeBlockFrequencyInfoWrapperPassPass(PassRegistry &)
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
cl::opt< std::string > ViewBlockFreqFuncName("view-bfi-func-name", cl::Hidden, cl::desc("The option to specify " "the name of the function " "whose CFG will be displayed."))
AnalysisUsage & addRequired()
SuccIterator< const Instruction, const BasicBlock > const_succ_iterator
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Analysis pass that exposes the LoopInfo for a function.
Optional< std::vector< StOtherPiece > > Other