LLVM: lib/CodeGen/MachineBlockFrequencyInfo.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

25#include

26#include

27

28using namespace llvm;

29

30#define DEBUG_TYPE "machine-block-freq"

31

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.")));

45

46namespace llvm {

47

49 "view-block-layout-with-bfi", cl::Hidden,

51 "Pop up a window to show a dag displaying MBP layout and associated "

52 "block frequencies of the CFG."),

55 "display a graph using the "

56 "fractional block frequency representation."),

58 "display a graph using the raw "

59 "integer fractional block frequency representation."),

61 "display a graph using the real "

62 "profile count if available.")));

63

64

65

67

68

69

71

72

73

75}

76

79 cl::desc("Print the machine block frequency info."));

80

87

92

94 return &G->getFunction()->front();

95 }

96

98 return N->succ_begin();

99 }

100

102

106

110};

111

115

116template <>

121

124

127 int layout_order = -1;

128

134

136 int O = 0;

137 for (auto MBI = F->begin(); MBI != F->end(); ++MBI, ++O) {

139 }

140 }

142 }

144 layout_order);

145 }

146

152

158};

159

160AnalysisKey MachineBlockFrequencyAnalysis::Key;

161

167 return Result(MF, MBPI, MLI);

168}

169

174 OS << "Machine block frequency for machine function: " << MF.getName()

175 << '\n';

176 MBFI.print(OS);

178}

179

181 "Machine Block Frequency Analysis", true, true)

185 "Machine Block Frequency Analysis", true, true)

186

188

194

196

199

205

207

210 MachineFunctionAnalysisManager::Invalidator &) {

211

212

214 return !PAC.preserved() &&

217}

218

226

230 if (!MBFI)

231 MBFI.reset(new ImplType);

232 MBFI->calculate(F, MBPI, MLI);

235 view("MachineBlockFrequencyDAGS." + F.getName());

236 }

239 MBFI->print(dbgs());

240 }

241}

242

251

253

255

256

257

262

267

270 if (!MBFI)

271 return std::nullopt;

272

273 const Function &F = MBFI->getFunction()->getFunction();

274 return MBFI->getBlockProfileCount(F, MBB);

275}

276

277std::optional<uint64_t>

279 if (!MBFI)

280 return std::nullopt;

281

282 const Function &F = MBFI->getFunction()->getFunction();

283 return MBFI->getProfileCountFromFreq(F, Freq);

284}

285

288 assert(MBFI && "Expected analysis to be available");

289 return MBFI->isIrrLoopHeader(MBB);

290}

291

296 assert(MBFI && "Expected analysis to be available");

297 auto NewSuccFreq = MBFI->getBlockFreq(&NewPredecessor) *

299

300 MBFI->setBlockFreq(&NewSuccessor, NewSuccFreq);

301}

302

306

308 return MBFI ? &MBFI->getBPI() : nullptr;

309}

310

314

321

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

#define clEnumValN(ENUMVAL, FLAGNAME, DESC)

This file defines the DenseMap class.

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.")))

BFIDOTGraphTraitsBase< MachineBlockFrequencyInfo, MachineBranchProbabilityInfo > MBFIDOTGraphTraitsBase

Definition MachineBlockFrequencyInfo.cpp:112

static cl::opt< bool > PrintMachineBlockFreq("print-machine-bfi", cl::init(false), cl::Hidden, cl::desc("Print the machine block frequency info."))

#define INITIALIZE_PASS_DEPENDENCY(depName)

#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)

static bool isSimple(Instruction *I)

This templated class represents "all analyses that operate over " (e....

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

void setPreservesAll()

Set by analyses that do not transform their input at all.

Represents analyses that only rely on functions' control flow.

SmallVectorImpl< MachineBasicBlock * >::const_iterator const_succ_iterator

MachineBlockFrequencyInfo Result

LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

Definition MachineBlockFrequencyInfo.cpp:163

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

Definition MachineBlockFrequencyInfo.cpp:219

bool runOnMachineFunction(MachineFunction &F) override

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...

Definition MachineBlockFrequencyInfo.cpp:243

MachineBlockFrequencyInfoWrapperPass()

Definition MachineBlockFrequencyInfo.cpp:189

MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...

LLVM_ABI 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:258

LLVM_ABI void print(raw_ostream &OS)

Definition MachineBlockFrequencyInfo.cpp:252

LLVM_ABI bool isIrrLoopHeader(const MachineBasicBlock *MBB) const

Definition MachineBlockFrequencyInfo.cpp:286

LLVM_ABI const MachineBranchProbabilityInfo * getMBPI() const

Definition MachineBlockFrequencyInfo.cpp:307

LLVM_ABI BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const

getblockFreq - Return block frequency.

Definition MachineBlockFrequencyInfo.cpp:264

LLVM_ABI 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:292

LLVM_ABI void calculate(const MachineFunction &F, const MachineBranchProbabilityInfo &MBPI, const MachineLoopInfo &MLI)

calculate - compute block frequency info for the given function.

Definition MachineBlockFrequencyInfo.cpp:227

LLVM_ABI void releaseMemory()

Definition MachineBlockFrequencyInfo.cpp:254

LLVM_ABI const MachineFunction * getFunction() const

Definition MachineBlockFrequencyInfo.cpp:303

LLVM_ABI std::optional< uint64_t > getProfileCountFromFreq(BlockFrequency Freq) const

Definition MachineBlockFrequencyInfo.cpp:278

LLVM_ABI bool invalidate(MachineFunction &F, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)

Handle invalidation explicitly.

Definition MachineBlockFrequencyInfo.cpp:208

LLVM_ABI BlockFrequency getEntryFreq() const

Divide a block's BlockFrequency::getFrequency() value by this value to obtain the entry block - relat...

Definition MachineBlockFrequencyInfo.cpp:311

LLVM_ABI ~MachineBlockFrequencyInfo()

LLVM_ABI std::optional< uint64_t > getBlockProfileCount(const MachineBasicBlock *MBB) const

Definition MachineBlockFrequencyInfo.cpp:268

LLVM_ABI MachineBlockFrequencyInfo()

LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)

Definition MachineBlockFrequencyInfo.cpp:171

BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const

MachineFunctionPass(char &ID)

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

StringRef getName() const

getName - Return the name of the corresponding LLVM function.

Function & getFunction()

Return the LLVM function that this machine code represents.

Analysis pass that exposes the MachineLoopInfo for a machine function.

LLVM_ABI void calculate(MachineDominatorTree &MDT)

Calculate the natural loop information.

static LLVM_ABI PassRegistry * getPassRegistry()

getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...

AnalysisType & getAnalysis() const

getAnalysis() - This function is used by subclasses to get to the analysis information ...

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalysisChecker getChecker() const

Build a checker for this PreservedAnalyses and the specified analysis type.

Simple wrapper around std::function<void(raw_ostream&)>.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

This class implements an extremely fast bulk output stream that can only output to a stream.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

ValuesClass values(OptsTy... Options)

Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

static GVDAGType getGVDT()

cl::opt< std::string > PrintBFIFuncName("print-bfi-func-name", cl::Hidden, cl::desc("The option to specify the name of the function " "whose block frequency info is printed."))

Definition MachineBlockFrequencyInfo.cpp:74

AnalysisManager< MachineFunction > MachineFunctionAnalysisManager

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."))

Definition MachineBlockFrequencyInfo.cpp:70

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."))

Definition MachineBlockFrequencyInfo.cpp:66

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

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.")))

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_ABI void printRelativeBlockFreq(raw_ostream &OS, BlockFrequency EntryFreq, BlockFrequency Freq)

LLVM_ABI Printable printBlockFreq(const BlockFrequencyInfo &BFI, BlockFrequency Freq)

Print the block frequency Freq relative to the current functions entry frequency.

LLVM_ABI void initializeMachineBlockFrequencyInfoWrapperPassPass(PassRegistry &)

A special type used by analysis passes to provide an address that identifies that particular analysis...

std::string getNodeAttributes(NodeRef Node, const MachineBlockFrequencyInfo *Graph, unsigned HotPercentThreshold=0)

typename GTraits::ChildIteratorType EdgeIter

std::string getNodeLabel(NodeRef Node, const MachineBlockFrequencyInfo *Graph, GVDAGType GType, int layout_order=-1)

std::string getEdgeAttributes(NodeRef Node, EdgeIter EI, const MachineBlockFrequencyInfo *BFI, const MachineBranchProbabilityInfo *BPI, unsigned HotPercentThreshold=0)

std::string getEdgeAttributes(const MachineBasicBlock *Node, EdgeIter EI, const MachineBlockFrequencyInfo *MBFI)

Definition MachineBlockFrequencyInfo.cpp:153

DOTGraphTraits(bool isSimple=false)

Definition MachineBlockFrequencyInfo.cpp:122

std::string getNodeAttributes(const MachineBasicBlock *Node, const MachineBlockFrequencyInfo *Graph)

Definition MachineBlockFrequencyInfo.cpp:147

const MachineFunction * CurFunc

Definition MachineBlockFrequencyInfo.cpp:119

DenseMap< const MachineBasicBlock *, int > LayoutOrderMap

Definition MachineBlockFrequencyInfo.cpp:120

std::string getNodeLabel(const MachineBasicBlock *Node, const MachineBlockFrequencyInfo *Graph)

Definition MachineBlockFrequencyInfo.cpp:125

DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...

static ChildIteratorType child_begin(const NodeRef N)

Definition MachineBlockFrequencyInfo.cpp:97

static ChildIteratorType child_end(const NodeRef N)

Definition MachineBlockFrequencyInfo.cpp:101

static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G)

Definition MachineBlockFrequencyInfo.cpp:93

const MachineBasicBlock * NodeRef

Definition MachineBlockFrequencyInfo.cpp:89

static nodes_iterator nodes_begin(const MachineBlockFrequencyInfo *G)

Definition MachineBlockFrequencyInfo.cpp:103

MachineBasicBlock::const_succ_iterator ChildIteratorType

Definition MachineBlockFrequencyInfo.cpp:90

pointer_iterator< MachineFunction::const_iterator > nodes_iterator

Definition MachineBlockFrequencyInfo.cpp:91

static nodes_iterator nodes_end(const MachineBlockFrequencyInfo *G)

Definition MachineBlockFrequencyInfo.cpp:107