[llvm] r197303 - [block-freq] Teach branch probability how to return the edge weight in between a BasicBlock and one of its successors.
Michael Gottesman
mgottesman at apple.com
Fri Dec 13 18:24:26 PST 2013
Author: mgottesman
Date: Fri Dec 13 20:24:25 2013
New Revision: 197303
URL: http://llvm.org/viewvc/llvm-project?rev=197303&view=rev
Log:
[block-freq] Teach branch probability how to return the edge weight in between a BasicBlock and one of its successors.
IMHO At some point BasicBlock should be refactored along the lines of
MachineBasicBlock so that successors/weights are actually embedded within the
block. Now is not that time though.
Modified:
llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h
llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h?rev=197303&r1=197302&r2=197303&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/BranchProbabilityInfo.h Fri Dec 13 20:24:25 2013
@@ -16,6 +16,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/CFG.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/BranchProbability.h"
@@ -98,6 +99,9 @@ public:
/// It is guaranteed to fall between 1 and UINT32_MAX.
uint32_t getEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst) const;
+ uint32_t getEdgeWeight(const BasicBlock *Src,
+ succ_const_iterator Dst) const;
+
/// \brief Set the raw edge weight for a given edge.
///
/// This allows a pass to explicitly set the edge weight for an edge. It can
Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=197303&r1=197302&r2=197303&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Fri Dec 13 20:24:25 2013
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "branch-prob"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -483,6 +484,8 @@ void BranchProbabilityInfo::getAnalysisU
}
bool BranchProbabilityInfo::runOnFunction(Function &F) {
+ DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName()
+ << " ----\n\n");
LastF = &F; // Store the last function we ran on for printing.
LI = &getAnalysis<LoopInfo>();
assert(PostDominatedByUnreachable.empty());
@@ -591,6 +594,13 @@ getEdgeWeight(const BasicBlock *Src, uns
return DEFAULT_WEIGHT;
}
+uint32_t
+BranchProbabilityInfo::
+getEdgeWeight(const BasicBlock *Src, succ_const_iterator Dst) const {
+ size_t index = std::distance(succ_begin(Src), Dst);
+ return getEdgeWeight(Src, index);
+}
+
/// Get the raw edge weight calculated for the block pair. This returns the sum
/// of all raw edge weights from Src to Dst.
uint32_t BranchProbabilityInfo::
More information about the llvm-commits
mailing list