LCOV - code coverage report
Current view: top level - lib/CodeGen - EdgeBundles.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 45 62.2 %
Date: 2017-09-14 15:23:50 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-------- EdgeBundles.cpp - Bundles of CFG edges ----------------------===//
       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 provides the implementation of the EdgeBundles analysis.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/CodeGen/EdgeBundles.h"
      15             : #include "llvm/CodeGen/MachineBasicBlock.h"
      16             : #include "llvm/CodeGen/MachineFunction.h"
      17             : #include "llvm/CodeGen/Passes.h"
      18             : #include "llvm/Support/CommandLine.h"
      19             : #include "llvm/Support/GraphWriter.h"
      20             : #include "llvm/Support/raw_ostream.h"
      21             : 
      22             : using namespace llvm;
      23             : 
      24             : static cl::opt<bool>
      25       72306 : ViewEdgeBundles("view-edge-bundles", cl::Hidden,
      26      144612 :                 cl::desc("Pop up a window to show edge bundle graphs"));
      27             : 
      28             : char EdgeBundles::ID = 0;
      29             : 
      30      181937 : INITIALIZE_PASS(EdgeBundles, "edge-bundles", "Bundle Machine CFG Edges",
      31             :                 /* cfg = */true, /* analysis = */ true)
      32             : 
      33             : char &llvm::EdgeBundlesID = EdgeBundles::ID;
      34             : 
      35       22033 : void EdgeBundles::getAnalysisUsage(AnalysisUsage &AU) const {
      36       22033 :   AU.setPreservesAll();
      37       22033 :   MachineFunctionPass::getAnalysisUsage(AU);
      38       22033 : }
      39             : 
      40      205246 : bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) {
      41      205246 :   MF = &mf;
      42      410492 :   EC.clear();
      43      410492 :   EC.grow(2 * MF->getNumBlockIDs());
      44             : 
      45     1097411 :   for (const auto &MBB : *MF) {
      46      481673 :     unsigned OutE = 2 * MBB.getNumber() + 1;
      47             :     // Join the outgoing bundle with the ingoing bundles of all successors.
      48      481673 :     for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
      49     1345148 :            SE = MBB.succ_end(); SI != SE; ++SI)
      50      381802 :       EC.join(OutE, 2 * (*SI)->getNumber());
      51             :   }
      52      205246 :   EC.compress();
      53      205246 :   if (ViewEdgeBundles)
      54           0 :     view();
      55             : 
      56             :   // Compute the reverse mapping.
      57      205246 :   Blocks.clear();
      58      410492 :   Blocks.resize(getNumBundles());
      59             : 
      60      892173 :   for (unsigned i = 0, e = MF->getNumBlockIDs(); i != e; ++i) {
      61      963362 :     unsigned b0 = getBundle(i, false);
      62      963362 :     unsigned b1 = getBundle(i, true);
      63      963362 :     Blocks[b0].push_back(i);
      64      481681 :     if (b1 != b0)
      65      892542 :       Blocks[b1].push_back(i);
      66             :   }
      67             : 
      68      205246 :   return false;
      69             : }
      70             : 
      71             : /// Specialize WriteGraph, the standard implementation won't work.
      72             : namespace llvm {
      73             : 
      74             : template<>
      75           0 : raw_ostream &WriteGraph<>(raw_ostream &O, const EdgeBundles &G,
      76             :                           bool ShortNames,
      77             :                           const Twine &Title) {
      78           0 :   const MachineFunction *MF = G.getMachineFunction();
      79             : 
      80           0 :   O << "digraph {\n";
      81           0 :   for (const auto &MBB : *MF) {
      82           0 :     unsigned BB = MBB.getNumber();
      83           0 :     O << "\t\"BB#" << BB << "\" [ shape=box ]\n"
      84           0 :       << '\t' << G.getBundle(BB, false) << " -> \"BB#" << BB << "\"\n"
      85           0 :       << "\t\"BB#" << BB << "\" -> " << G.getBundle(BB, true) << '\n';
      86           0 :     for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
      87           0 :            SE = MBB.succ_end(); SI != SE; ++SI)
      88           0 :       O << "\t\"BB#" << BB << "\" -> \"BB#" << (*SI)->getNumber()
      89           0 :         << "\" [ color=lightgray ]\n";
      90             :   }
      91           0 :   O << "}\n";
      92           0 :   return O;
      93             : }
      94             : 
      95             : } // end namespace llvm
      96             : 
      97             : /// view - Visualize the annotated bipartite CFG with Graphviz.
      98           0 : void EdgeBundles::view() const {
      99           0 :   ViewGraph(*this, "EdgeBundles");
     100      216918 : }

Generated by: LCOV version 1.13