aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-06-22 16:04:51 +0000
committerXinliang David Li <davidxl@google.com>2016-06-22 16:04:51 +0000
commit69317f2ec2eba8c1a0f79e4688217f6fab262b8a (patch)
tree39eb3b5edfea57d06a78471591f341f0cb0b1095 /llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
parent1a7a6957c00298489fcbbd32d286d1ff4503b68f (diff)
downloadllvm-69317f2ec2eba8c1a0f79e4688217f6fab262b8a.zip
llvm-69317f2ec2eba8c1a0f79e4688217f6fab262b8a.tar.gz
llvm-69317f2ec2eba8c1a0f79e4688217f6fab262b8a.tar.bz2
[MBFI]: show branch probability in DOT graph
Differential Revision: http://reviews.llvm.org/D21596 llvm-svn: 273430
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index 8843136..f83e7ff 100644
--- a/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -20,7 +20,9 @@
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/Format.h"
#include "llvm/Support/GraphWriter.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -80,6 +82,7 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo *>
explicit DOTGraphTraits(bool isSimple = false)
: DefaultDOTGraphTraits(isSimple) {}
+ typedef MachineBasicBlock::const_succ_iterator EdgeIter;
static std::string getGraphName(const MachineBlockFrequencyInfo *G) {
return G->getFunction()->getName();
}
@@ -104,6 +107,21 @@ struct DOTGraphTraits<MachineBlockFrequencyInfo *>
return Result;
}
+ static std::string getEdgeAttributes(const MachineBasicBlock *Node,
+ EdgeIter EI,
+ const MachineBlockFrequencyInfo *MBFI) {
+ MachineBranchProbabilityInfo &MBPI =
+ MBFI->getAnalysis<MachineBranchProbabilityInfo>();
+ BranchProbability BP = MBPI.getEdgeProbability(Node, EI);
+ uint32_t N = BP.getNumerator();
+ uint32_t D = BP.getDenominator();
+ double Percent = 100.0 * N / D;
+ std::string Str;
+ raw_string_ostream OS(Str);
+ OS << format("label=\"%.1f%%\"", Percent);
+ OS.flush();
+ return Str;
+ }
};
} // end namespace llvm