LCOV - code coverage report
Current view: top level - lib/Analysis - CallPrinter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 2 22 9.1 %
Date: 2017-09-14 15:23:50 Functions: 4 13 30.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- CallPrinter.cpp - DOT printer for call graph -----------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file defines '-dot-callgraph', which emit a callgraph.<fnname>.dot
      11             : // containing the call graph of a module.
      12             : //
      13             : // There is also a pass available to directly call dotty ('-view-callgraph').
      14             : //
      15             : //===----------------------------------------------------------------------===//
      16             : 
      17             : #include "llvm/Analysis/CallPrinter.h"
      18             : #include "llvm/Analysis/CallGraph.h"
      19             : #include "llvm/Analysis/DOTGraphTraitsPass.h"
      20             : 
      21             : using namespace llvm;
      22             : 
      23             : namespace llvm {
      24             : 
      25             : template <> struct DOTGraphTraits<CallGraph *> : public DefaultDOTGraphTraits {
      26           0 :   DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
      27             : 
      28           0 :   static std::string getGraphName(CallGraph *Graph) { return "Call graph"; }
      29             : 
      30           0 :   std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
      31           0 :     if (Function *Func = Node->getFunction())
      32           0 :       return Func->getName();
      33             : 
      34           0 :     return "external node";
      35             :   }
      36             : };
      37             : 
      38             : struct AnalysisCallGraphWrapperPassTraits {
      39             :   static CallGraph *getGraph(CallGraphWrapperPass *P) {
      40           0 :     return &P->getCallGraph();
      41             :   }
      42             : };
      43             : 
      44             : } // end llvm namespace
      45             : 
      46             : namespace {
      47             : 
      48           0 : struct CallGraphViewer
      49             :     : public DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
      50             :                                         AnalysisCallGraphWrapperPassTraits> {
      51             :   static char ID;
      52             : 
      53           0 :   CallGraphViewer()
      54             :       : DOTGraphTraitsModuleViewer<CallGraphWrapperPass, true, CallGraph *,
      55             :                                    AnalysisCallGraphWrapperPassTraits>(
      56           0 :             "callgraph", ID) {
      57           0 :     initializeCallGraphViewerPass(*PassRegistry::getPassRegistry());
      58           0 :   }
      59             : };
      60             : 
      61           0 : struct CallGraphDOTPrinter : public DOTGraphTraitsModulePrinter<
      62             :                               CallGraphWrapperPass, true, CallGraph *,
      63             :                               AnalysisCallGraphWrapperPassTraits> {
      64             :   static char ID;
      65             : 
      66           0 :   CallGraphDOTPrinter()
      67             :       : DOTGraphTraitsModulePrinter<CallGraphWrapperPass, true, CallGraph *,
      68             :                                     AnalysisCallGraphWrapperPassTraits>(
      69           0 :             "callgraph", ID) {
      70           0 :     initializeCallGraphDOTPrinterPass(*PassRegistry::getPassRegistry());
      71           0 :   }
      72             : };
      73             : 
      74             : } // end anonymous namespace
      75             : 
      76             : char CallGraphViewer::ID = 0;
      77       45790 : INITIALIZE_PASS(CallGraphViewer, "view-callgraph", "View call graph", false,
      78             :                 false)
      79             : 
      80             : char CallGraphDOTPrinter::ID = 0;
      81       45790 : INITIALIZE_PASS(CallGraphDOTPrinter, "dot-callgraph",
      82             :                 "Print call graph to 'dot' file", false, false)
      83             : 
      84             : // Create methods available outside of this file, to use them
      85             : // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
      86             : // the link time optimization.
      87             : 
      88           0 : ModulePass *llvm::createCallGraphViewerPass() { return new CallGraphViewer(); }
      89             : 
      90           0 : ModulePass *llvm::createCallGraphDOTPrinterPass() {
      91           0 :   return new CallGraphDOTPrinter();
      92             : }

Generated by: LCOV version 1.13