summaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineBlockFrequencyInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/MachineBlockFrequencyInfo.cpp')
-rw-r--r--lib/CodeGen/MachineBlockFrequencyInfo.cpp65
1 files changed, 43 insertions, 22 deletions
diff --git a/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/lib/CodeGen/MachineBlockFrequencyInfo.cpp
index 4d1ec11df46c..3459a9f71a73 100644
--- a/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ b/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -12,23 +12,23 @@
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/iterator.h"
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
-#include "llvm/CodeGen/Passes.h"
-#include "llvm/InitializePasses.h"
+#include "llvm/Pass.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"
+#include <string>
using namespace llvm;
#define DEBUG_TYPE "machine-block-freq"
-
static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
"view-machine-block-freq-propagation-dags", cl::Hidden,
cl::desc("Pop up a window to show a dag displaying how machine block "
@@ -42,6 +42,7 @@ static cl::opt<GVDAGType> ViewMachineBlockFreqPropagationDAG(
"integer fractional block frequency representation."),
clEnumValN(GVDT_Count, "count", "display a graph using the real "
"profile count if available.")));
+
// Similar option above, but used to control BFI display only after MBP pass
cl::opt<GVDAGType> ViewBlockLayoutWithBFI(
"view-block-layout-with-bfi", cl::Hidden,
@@ -62,10 +63,19 @@ cl::opt<GVDAGType> ViewBlockLayoutWithBFI(
// Command line option to specify the name of the function for CFG dump
// Defined in Analysis/BlockFrequencyInfo.cpp: -view-bfi-func-name=
extern cl::opt<std::string> ViewBlockFreqFuncName;
+
// Command line option to specify hot frequency threshold.
// Defined in Analysis/BlockFrequencyInfo.cpp: -view-hot-freq-perc=
extern cl::opt<unsigned> ViewHotFreqPercent;
+static cl::opt<bool> PrintMachineBlockFreq(
+ "print-machine-bfi", cl::init(false), cl::Hidden,
+ cl::desc("Print the machine block frequency info."));
+
+// Command line option to specify the name of the function for block frequency
+// dump. Defined in Analysis/BlockFrequencyInfo.cpp.
+extern cl::opt<std::string> PrintBlockFreqFuncName;
+
static GVDAGType getGVDT() {
if (ViewBlockLayoutWithBFI != GVDT_None)
return ViewBlockLayoutWithBFI;
@@ -76,9 +86,9 @@ static GVDAGType getGVDT() {
namespace llvm {
template <> struct GraphTraits<MachineBlockFrequencyInfo *> {
- typedef const MachineBasicBlock *NodeRef;
- typedef MachineBasicBlock::const_succ_iterator ChildIteratorType;
- typedef pointer_iterator<MachineFunction::const_iterator> nodes_iterator;
+ using NodeRef = const MachineBasicBlock *;
+ using ChildIteratorType = MachineBasicBlock::const_succ_iterator;
+ using nodes_iterator = pointer_iterator<MachineFunction::const_iterator>;
static NodeRef getEntryNode(const MachineBlockFrequencyInfo *G) {
return &G->getFunction()->front();
@@ -99,21 +109,21 @@ template <> struct GraphTraits<MachineBlockFrequencyInfo *> {
}
};
-typedef BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
- MachineBranchProbabilityInfo>
- MBFIDOTGraphTraitsBase;
+using MBFIDOTGraphTraitsBase =
+ BFIDOTGraphTraitsBase<MachineBlockFrequencyInfo,
+ MachineBranchProbabilityInfo>;
+
template <>
struct DOTGraphTraits<MachineBlockFrequencyInfo *>
: public MBFIDOTGraphTraitsBase {
- explicit DOTGraphTraits(bool isSimple = false)
- : MBFIDOTGraphTraitsBase(isSimple), CurFunc(nullptr), LayoutOrderMap() {}
-
- const MachineFunction *CurFunc;
+ const MachineFunction *CurFunc = nullptr;
DenseMap<const MachineBasicBlock *, int> LayoutOrderMap;
+ explicit DOTGraphTraits(bool isSimple = false)
+ : MBFIDOTGraphTraitsBase(isSimple) {}
+
std::string getNodeLabel(const MachineBasicBlock *Node,
const MachineBlockFrequencyInfo *Graph) {
-
int layout_order = -1;
// Attach additional ordering information if 'isSimple' is false.
if (!isSimple()) {
@@ -163,7 +173,7 @@ MachineBlockFrequencyInfo::MachineBlockFrequencyInfo()
initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
}
-MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {}
+MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default;
void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineBranchProbabilityInfo>();
@@ -183,6 +193,11 @@ void MachineBlockFrequencyInfo::calculate(
F.getName().equals(ViewBlockFreqFuncName))) {
view("MachineBlockFrequencyDAGS." + F.getName());
}
+ if (PrintMachineBlockFreq &&
+ (PrintBlockFreqFuncName.empty() ||
+ F.getName().equals(PrintBlockFreqFuncName))) {
+ MBFI->print(dbgs());
+ }
}
bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
@@ -209,14 +224,20 @@ MachineBlockFrequencyInfo::getBlockFreq(const MachineBasicBlock *MBB) const {
Optional<uint64_t> MachineBlockFrequencyInfo::getBlockProfileCount(
const MachineBasicBlock *MBB) const {
- const Function *F = MBFI->getFunction()->getFunction();
- return MBFI ? MBFI->getBlockProfileCount(*F, MBB) : None;
+ const Function &F = MBFI->getFunction()->getFunction();
+ return MBFI ? MBFI->getBlockProfileCount(F, MBB) : None;
}
Optional<uint64_t>
MachineBlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const {
- const Function *F = MBFI->getFunction()->getFunction();
- return MBFI ? MBFI->getProfileCountFromFreq(*F, Freq) : None;
+ const Function &F = MBFI->getFunction()->getFunction();
+ return MBFI ? MBFI->getProfileCountFromFreq(F, Freq) : None;
+}
+
+bool
+MachineBlockFrequencyInfo::isIrrLoopHeader(const MachineBasicBlock *MBB) {
+ assert(MBFI && "Expected analysis to be available");
+ return MBFI->isIrrLoopHeader(MBB);
}
const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {