[llvm-commits] [llvm] r133766 - in /llvm/trunk: include/llvm/Analysis/BranchProbabilityInfo.h include/llvm/InitializePasses.h include/llvm/Support/BranchProbability.h lib/Analysis/Analysis.cpp lib/Analysis/BranchProbabilityInfo.cpp lib/Analysis/CMakeLists.txt
Jakub Staszak
jstaszak at apple.com
Thu Jun 23 14:45:20 PDT 2011
Author: kuba
Date: Thu Jun 23 16:45:20 2011
New Revision: 133766
URL: http://llvm.org/viewvc/llvm-project?rev=133766&view=rev
Log:
Introduce BlockFrequency analysis for BasicBlocks.
Modified:
llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/include/llvm/Support/BranchProbability.h
llvm/trunk/lib/Analysis/Analysis.cpp
llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
llvm/trunk/lib/Analysis/CMakeLists.txt
Modified: llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h Thu Jun 23 16:45:20 2011
@@ -39,6 +39,9 @@
// Get sum of the block successors' weights.
uint32_t getSumForBlock(BasicBlock *BB) const;
+ // Get sum of the edge weights going to the BB block.
+ uint32_t getBackSumForBlock(BasicBlock *BB) const;
+
public:
static char ID;
@@ -71,6 +74,13 @@
// only iff SRC block has only one successor.
BranchProbability getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const;
+ // Return a probability of getting to the DST block through SRC->DST edge.
+ // Returned value is a fraction between 0 (0% probability) and
+ // 1 (100% probability), however the value is never equal to 0, and can be 1
+ // only iff DST block has only one predecesor.
+ BranchProbability getBackEdgeProbability(BasicBlock *Src,
+ BasicBlock *Dst) const;
+
// Print value between 0 (0% probability) and 1 (100% probability),
// however the value is never equal to 0, and can be 1 only iff SRC block
// has only one successor.
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Thu Jun 23 16:45:20 2011
@@ -65,6 +65,7 @@
void initializeBasicAliasAnalysisPass(PassRegistry&);
void initializeBasicCallGraphPass(PassRegistry&);
void initializeBlockExtractorPassPass(PassRegistry&);
+void initializeBlockFrequencyPass(PassRegistry&);
void initializeBlockPlacementPass(PassRegistry&);
void initializeBranchProbabilityInfoPass(PassRegistry&);
void initializeBreakCriticalEdgesPass(PassRegistry&);
Modified: llvm/trunk/include/llvm/Support/BranchProbability.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/BranchProbability.h?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/BranchProbability.h (original)
+++ llvm/trunk/include/llvm/Support/BranchProbability.h Thu Jun 23 16:45:20 2011
@@ -18,13 +18,17 @@
namespace llvm {
-class raw_ostream;
+template<class BlockT, class FunctionT, class BranchProbInfoT>
+class BlockFrequencyImpl;
class BranchProbabilityInfo;
class MachineBranchProbabilityInfo;
class MachineBasicBlock;
+class raw_ostream;
// This class represents Branch Probability as a non-negative fraction.
class BranchProbability {
+ template<class BlockT, class FunctionT, class BranchProbInfoT>
+ friend class BlockFrequencyImpl;
friend class BranchProbabilityInfo;
friend class MachineBranchProbabilityInfo;
friend class MachineBasicBlock;
@@ -38,6 +42,10 @@
BranchProbability(uint32_t n, uint32_t d);
public:
+
+ uint32_t getNumerator() const { return N; }
+ uint32_t getDenominator() const { return D; }
+
raw_ostream &print(raw_ostream &OS) const;
void dump() const;
Modified: llvm/trunk/lib/Analysis/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)
+++ llvm/trunk/lib/Analysis/Analysis.cpp Thu Jun 23 16:45:20 2011
@@ -23,6 +23,7 @@
initializeAliasSetPrinterPass(Registry);
initializeNoAAPass(Registry);
initializeBasicAliasAnalysisPass(Registry);
+ initializeBlockFrequencyPass(Registry);
initializeBranchProbabilityInfoPass(Registry);
initializeCFGViewerPass(Registry);
initializeCFGPrinterPass(Registry);
Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Thu Jun 23 16:45:20 2011
@@ -279,6 +279,21 @@
return Sum;
}
+uint32_t BranchProbabilityInfo::getBackSumForBlock(BasicBlock *BB) const {
+ uint32_t Sum = 0;
+
+ for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
+ BasicBlock *Pred = *I;
+ uint32_t Weight = getEdgeWeight(Pred, BB);
+ uint32_t PrevSum = Sum;
+
+ Sum += Weight;
+ assert(Sum > PrevSum); (void) PrevSum;
+ }
+
+ return Sum;
+}
+
bool BranchProbabilityInfo::isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const {
// Hot probability is at least 4/5 = 80%
uint32_t Weight = getEdgeWeight(Src, Dst);
@@ -345,6 +360,15 @@
return BranchProbability(N, D);
}
+BranchProbability BranchProbabilityInfo::
+getBackEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const {
+
+ uint32_t N = getEdgeWeight(Src, Dst);
+ uint32_t D = getBackSumForBlock(Dst);
+
+ return BranchProbability(N, D);
+}
+
raw_ostream &
BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS, BasicBlock *Src,
BasicBlock *Dst) const {
Modified: llvm/trunk/lib/Analysis/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CMakeLists.txt?rev=133766&r1=133765&r2=133766&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CMakeLists.txt (original)
+++ llvm/trunk/lib/Analysis/CMakeLists.txt Thu Jun 23 16:45:20 2011
@@ -6,6 +6,7 @@
AliasSetTracker.cpp
Analysis.cpp
BasicAliasAnalysis.cpp
+ BlockFrequency.cpp
BranchProbabilityInfo.cpp
CFGPrinter.cpp
CaptureTracking.cpp
More information about the llvm-commits
mailing list