diff options
| author | Xinliang David Li <davidxl@google.com> | 2017-01-27 19:06:25 +0000 |
|---|---|---|
| committer | Xinliang David Li <davidxl@google.com> | 2017-01-27 19:06:25 +0000 |
| commit | d289e4541f586741b9e4eeb784b931a61ead3a00 (patch) | |
| tree | cac8139620c056347bcea08f1627cb900b4c041d /llvm/lib | |
| parent | c91e28af4b7b68b6a117f23eaeaa42eff3f103fa (diff) | |
| download | bcm5719-llvm-d289e4541f586741b9e4eeb784b931a61ead3a00.tar.gz bcm5719-llvm-d289e4541f586741b9e4eeb784b931a61ead3a00.zip | |
[PGO] add debug option to view raw count after prof use annotation
Differential Revision: https://reviews.llvm.org/D29045
llvm-svn: 293325
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 05cecc8e050..b31d27151fc 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -60,8 +60,8 @@ #include "llvm/Analysis/IndirectCallSiteVisitor.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/CallSite.h" -#include "llvm/IR/Dominators.h" #include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/Dominators.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstIterator.h" @@ -73,7 +73,9 @@ #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/ProfileData/ProfileCommon.h" #include "llvm/Support/BranchProbability.h" +#include "llvm/Support/DOTGraphTraits.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/GraphWriter.h" #include "llvm/Support/JamCRC.h" #include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -153,6 +155,10 @@ static cl::opt<std::string> "the name of the function " "whose CFG will be displayed.")); +// Command line option to turn on CFG dot dump of raw profile counts +static cl::opt<bool> PGOViewRawCounts("pgo-view-raw-counts", cl::init(false), + cl::Hidden); + // Command line option to turn on CFG dot dump after profile annotation. extern cl::opt<bool> PGOViewCounts; @@ -690,6 +696,8 @@ public: return FuncInfo.findBBInfo(BB); } + Function &getFunc() const { return F; } + private: Function &F; Module *M; @@ -1227,6 +1235,13 @@ static bool annotateAllFunctions( NewBFI->view(); } #endif + if (PGOViewRawCounts && + (PGOViewFunction.empty() || F.getName().equals(PGOViewFunction))) { + if (PGOViewFunction.empty()) + WriteGraph(&Func, Twine("PGORawCounts_") + Func.getFunc().getName()); + else + ViewGraph(&Func, Twine("PGORawCounts_") + Func.getFunc().getName()); + } } M.setProfileSummary(PGOReader->getSummary().getMD(M.getContext())); // Set function hotness attribute from the profile. @@ -1282,3 +1297,46 @@ bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) { return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI); } + +namespace llvm { +template <> struct GraphTraits<PGOUseFunc *> { + typedef const BasicBlock *NodeRef; + typedef succ_const_iterator ChildIteratorType; + typedef pointer_iterator<Function::const_iterator> nodes_iterator; + + static NodeRef getEntryNode(const PGOUseFunc *G) { + return &G->getFunc().front(); + } + static ChildIteratorType child_begin(const NodeRef N) { + return succ_begin(N); + } + static ChildIteratorType child_end(const NodeRef N) { return succ_end(N); } + static nodes_iterator nodes_begin(const PGOUseFunc *G) { + return nodes_iterator(G->getFunc().begin()); + } + static nodes_iterator nodes_end(const PGOUseFunc *G) { + return nodes_iterator(G->getFunc().end()); + } +}; + +template <> struct DOTGraphTraits<PGOUseFunc *> : DefaultDOTGraphTraits { + explicit DOTGraphTraits(bool isSimple = false) + : DefaultDOTGraphTraits(isSimple) {} + + static std::string getGraphName(const PGOUseFunc *G) { + return G->getFunc().getName(); + } + + std::string getNodeLabel(const BasicBlock *Node, const PGOUseFunc *Graph) { + std::string Result; + raw_string_ostream OS(Result); + OS << Node->getName().str() << " : "; + UseBBInfo *BI = Graph->findBBInfo(Node); + if (BI && BI->CountValid) + OS << BI->CountValue; + else + OS << "Unknown"; + return Result; + } +}; +} |

