From 748bc4973cbfe2bac372bd83fb814618e4fc3d9c Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Fri, 3 Feb 2017 21:57:51 +0000 Subject: [PATCH] [PGO] Add select instr profile in graph dump Differential Revision: http://reviews.llvm.org/D29474 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294055 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/PGOInstrumentation.cpp | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index a146eaf04492..b81bb1b49555 100644 --- a/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -1331,6 +1331,16 @@ template <> struct GraphTraits { } }; +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 : DefaultDOTGraphTraits { explicit DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {} @@ -1342,12 +1352,31 @@ template <> struct DOTGraphTraits : 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(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; } };