llvm.org GIT mirror llvm / 44eb49c
Introduce BlockFrequency analysis for BasicBlocks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133766 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Staszak 9 years ago
6 changed file(s) with 46 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
3838 // Get sum of the block successors' weights.
3939 uint32_t getSumForBlock(BasicBlock *BB) const;
4040
41 // Get sum of the edge weights going to the BB block.
42 uint32_t getBackSumForBlock(BasicBlock *BB) const;
43
4144 public:
4245 static char ID;
4346
7073 // only iff SRC block has only one successor.
7174 BranchProbability getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const;
7275
76 // Return a probability of getting to the DST block through SRC->DST edge.
77 // Returned value is a fraction between 0 (0% probability) and
78 // 1 (100% probability), however the value is never equal to 0, and can be 1
79 // only iff DST block has only one predecesor.
80 BranchProbability getBackEdgeProbability(BasicBlock *Src,
81 BasicBlock *Dst) const;
82
7383 // Print value between 0 (0% probability) and 1 (100% probability),
7484 // however the value is never equal to 0, and can be 1 only iff SRC block
7585 // has only one successor.
6464 void initializeBasicAliasAnalysisPass(PassRegistry&);
6565 void initializeBasicCallGraphPass(PassRegistry&);
6666 void initializeBlockExtractorPassPass(PassRegistry&);
67 void initializeBlockFrequencyPass(PassRegistry&);
6768 void initializeBlockPlacementPass(PassRegistry&);
6869 void initializeBranchProbabilityInfoPass(PassRegistry&);
6970 void initializeBreakCriticalEdgesPass(PassRegistry&);
1717
1818 namespace llvm {
1919
20 class raw_ostream;
20 template
21 class BlockFrequencyImpl;
2122 class BranchProbabilityInfo;
2223 class MachineBranchProbabilityInfo;
2324 class MachineBasicBlock;
25 class raw_ostream;
2426
2527 // This class represents Branch Probability as a non-negative fraction.
2628 class BranchProbability {
29 template
30 friend class BlockFrequencyImpl;
2731 friend class BranchProbabilityInfo;
2832 friend class MachineBranchProbabilityInfo;
2933 friend class MachineBasicBlock;
3741 BranchProbability(uint32_t n, uint32_t d);
3842
3943 public:
44
45 uint32_t getNumerator() const { return N; }
46 uint32_t getDenominator() const { return D; }
47
4048 raw_ostream &print(raw_ostream &OS) const;
4149
4250 void dump() const;
2222 initializeAliasSetPrinterPass(Registry);
2323 initializeNoAAPass(Registry);
2424 initializeBasicAliasAnalysisPass(Registry);
25 initializeBlockFrequencyPass(Registry);
2526 initializeBranchProbabilityInfoPass(Registry);
2627 initializeCFGViewerPass(Registry);
2728 initializeCFGPrinterPass(Registry);
278278 return Sum;
279279 }
280280
281 uint32_t BranchProbabilityInfo::getBackSumForBlock(BasicBlock *BB) const {
282 uint32_t Sum = 0;
283
284 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
285 BasicBlock *Pred = *I;
286 uint32_t Weight = getEdgeWeight(Pred, BB);
287 uint32_t PrevSum = Sum;
288
289 Sum += Weight;
290 assert(Sum > PrevSum); (void) PrevSum;
291 }
292
293 return Sum;
294 }
295
281296 bool BranchProbabilityInfo::isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const {
282297 // Hot probability is at least 4/5 = 80%
283298 uint32_t Weight = getEdgeWeight(Src, Dst);
344359 return BranchProbability(N, D);
345360 }
346361
362 BranchProbability BranchProbabilityInfo::
363 getBackEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const {
364
365 uint32_t N = getEdgeWeight(Src, Dst);
366 uint32_t D = getBackSumForBlock(Dst);
367
368 return BranchProbability(N, D);
369 }
370
347371 raw_ostream &
348372 BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS, BasicBlock *Src,
349373 BasicBlock *Dst) const {
55 AliasSetTracker.cpp
66 Analysis.cpp
77 BasicAliasAnalysis.cpp
8 BlockFrequency.cpp
89 BranchProbabilityInfo.cpp
910 CFGPrinter.cpp
1011 CaptureTracking.cpp