[llvm] r273430 - [MBFI]: show branch probability in DOT graph
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 22 09:04:51 PDT 2016
Author: davidxl
Date: Wed Jun 22 11:04:51 2016
New Revision: 273430
URL: http://llvm.org/viewvc/llvm-project?rev=273430&view=rev
Log:
[MBFI]: show branch probability in DOT graph
Differential Revision: http://reviews.llvm.org/D21596
Modified:
llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
Modified: llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp?rev=273430&r1=273429&r2=273430&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockFrequencyInfo.cpp Wed Jun 22 11:04:51 2016
@@ -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<MachineBlockFreque
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<MachineBlockFreque
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
More information about the llvm-commits
mailing list