Skip to content

Commit

Permalink
[PGO] Add select instr profile in graph dump
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D29474



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294055 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
david-xl committed Feb 3, 2017
1 parent 25fbb20 commit 748bc49
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,16 @@ template <> struct GraphTraits<PGOUseFunc *> {
}
};

static std::string getSimpleNodeName(const BasicBlock *Node) {
if (!Node->getName().empty())
return Node->getName();

std::string SimpleNodeName;
raw_string_ostream OS(SimpleNodeName);
Node->printAsOperand(OS, false);
return OS.str();
}

template <> struct DOTGraphTraits<PGOUseFunc *> : DefaultDOTGraphTraits {
explicit DOTGraphTraits(bool isSimple = false)
: DefaultDOTGraphTraits(isSimple) {}
Expand All @@ -1342,12 +1352,31 @@ template <> struct DOTGraphTraits<PGOUseFunc *> : DefaultDOTGraphTraits {
std::string getNodeLabel(const BasicBlock *Node, const PGOUseFunc *Graph) {
std::string Result;
raw_string_ostream OS(Result);
OS << Node->getName().str() << " : ";

OS << getSimpleNodeName(Node) << ":\\l";
UseBBInfo *BI = Graph->findBBInfo(Node);
OS << "Count : ";
if (BI && BI->CountValid)
OS << BI->CountValue;
OS << BI->CountValue << "\\l";
else
OS << "Unknown";
OS << "Unknown\\l";

if (!PGOInstrSelect)
return Result;

for (auto BI = Node->begin(); BI != Node->end(); ++BI) {
auto *I = &*BI;
if (!isa<SelectInst>(I))
continue;
// Display scaled counts for SELECT instruction:
OS << "SELECT : { T = ";
uint64_t TC, FC;
bool hasProf = I->extractProfMetadata(TC, FC);
if (!hasProf)
OS << "Unknown, F = Unknown }\\l";
else
OS << TC << ", F = " << FC << " }\\l";
}
return Result;
}
};
Expand Down

0 comments on commit 748bc49

Please sign in to comment.