summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2011-06-11 01:05:22 +0000
committerAndrew Trick <atrick@apple.com>2011-06-11 01:05:22 +0000
commitf289df2d9544bd3a0934651daa20e589544413ba (patch)
tree7301c85f67fa32083f0ffbfd7908bc79002bd0bd /include
parentb5923db192d2aa938ff3c12aaac87d80ab649625 (diff)
downloadllvm-f289df2d9544bd3a0934651daa20e589544413ba.tar.gz
llvm-f289df2d9544bd3a0934651daa20e589544413ba.tar.bz2
llvm-f289df2d9544bd3a0934651daa20e589544413ba.tar.xz
Branch profiling: floating-point avoidance.
Patch by: Jakub Staszak! Introduces BranchProbability. Changes unsigned to uint32_t all over and uint64_t only when overflow is expected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132867 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/BranchProbabilityInfo.h26
-rw-r--r--include/llvm/Support/BranchProbability.h50
2 files changed, 68 insertions, 8 deletions
diff --git a/include/llvm/Analysis/BranchProbabilityInfo.h b/include/llvm/Analysis/BranchProbabilityInfo.h
index bf2a6a765f..91f289da7c 100644
--- a/include/llvm/Analysis/BranchProbabilityInfo.h
+++ b/include/llvm/Analysis/BranchProbabilityInfo.h
@@ -15,19 +15,24 @@
#define LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H
#include "llvm/InitializePasses.h"
+#include "llvm/Support/BranchProbability.h"
#include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Support/Debug.h"
namespace llvm {
+class raw_ostream;
+
class BranchProbabilityInfo : public FunctionPass {
// Default weight value. Used when we don't have information about the edge.
- static const unsigned int DEFAULT_WEIGHT = 16;
+ static const uint32_t DEFAULT_WEIGHT = 16;
typedef std::pair<BasicBlock *, BasicBlock *> Edge;
- DenseMap<Edge, unsigned> Weights;
+ DenseMap<Edge, uint32_t> Weights;
+
+ // Get sum of the block successors' weights.
+ uint32_t getSumForBlock(BasicBlock *BB) const;
public:
static char ID;
@@ -43,12 +48,12 @@ public:
bool runOnFunction(Function &F);
- // Returned value is between 1 and UINT_MAX. Look at BranchProbabilityInfo.cpp
- // for details.
- unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
+ // Returned value is between 1 and UINT32_MAX. Look at
+ // BranchProbabilityInfo.cpp for details.
+ uint32_t getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
// Look at BranchProbabilityInfo.cpp for details. Use it with caution!
- void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, unsigned Weight);
+ void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, uint32_t Weight);
// A 'Hot' edge is an edge which probability is >= 80%.
bool isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const;
@@ -56,11 +61,16 @@ public:
// Return a hot successor for the block BB or null if there isn't one.
BasicBlock *getHotSucc(BasicBlock *BB) const;
+ // Return a probability as a fraction 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.
+ BranchProbability getEdgeProbability(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.
raw_ostream &printEdgeProbability(raw_ostream &OS, BasicBlock *Src,
- BasicBlock *Dst) const;
+ BasicBlock *Dst) const;
};
}
diff --git a/include/llvm/Support/BranchProbability.h b/include/llvm/Support/BranchProbability.h
new file mode 100644
index 0000000000..7ba649133b
--- /dev/null
+++ b/include/llvm/Support/BranchProbability.h
@@ -0,0 +1,50 @@
+//===- BranchProbability.h - Branch Probability Analysis --------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Definition of BranchProbability shared by IR and Machine Instructions.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H
+#define LLVM_SUPPORT_BRANCHPROBABILITY_H
+
+#include "llvm/Support/DataTypes.h"
+
+namespace llvm {
+
+class raw_ostream;
+class BranchProbabilityInfo;
+class MachineBranchProbabilityInfo;
+class MachineBasicBlock;
+
+// This class represents Branch Probability as a non-negative fraction.
+class BranchProbability {
+ friend class BranchProbabilityInfo;
+ friend class MachineBranchProbabilityInfo;
+ friend class MachineBasicBlock;
+
+ // Numerator
+ uint32_t N;
+
+ // Denominator
+ uint32_t D;
+
+ BranchProbability(uint32_t n, uint32_t d);
+
+public:
+ raw_ostream &print(raw_ostream &OS) const;
+
+ void dump() const;
+};
+
+raw_ostream &operator<<(raw_ostream &OS, const BranchProbability &Prob);
+
+}
+
+#endif