Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/EdgeBundles.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-------- EdgeBundles.cpp - Bundles of CFG edges ----------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file provides the implementation of the EdgeBundles analysis.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/CodeGen/EdgeBundles.h"
14
#include "llvm/CodeGen/MachineBasicBlock.h"
15
#include "llvm/CodeGen/MachineFunction.h"
16
#include "llvm/CodeGen/Passes.h"
17
#include "llvm/Support/CommandLine.h"
18
#include "llvm/Support/GraphWriter.h"
19
#include "llvm/Support/raw_ostream.h"
20
21
using namespace llvm;
22
23
static cl::opt<bool>
24
ViewEdgeBundles("view-edge-bundles", cl::Hidden,
25
                cl::desc("Pop up a window to show edge bundle graphs"));
26
27
char EdgeBundles::ID = 0;
28
29
INITIALIZE_PASS(EdgeBundles, "edge-bundles", "Bundle Machine CFG Edges",
30
                /* cfg = */true, /* is_analysis = */ true)
31
32
char &llvm::EdgeBundlesID = EdgeBundles::ID;
33
34
45.7k
void EdgeBundles::getAnalysisUsage(AnalysisUsage &AU) const {
35
45.7k
  AU.setPreservesAll();
36
45.7k
  MachineFunctionPass::getAnalysisUsage(AU);
37
45.7k
}
38
39
622k
bool EdgeBundles::runOnMachineFunction(MachineFunction &mf) {
40
622k
  MF = &mf;
41
622k
  EC.clear();
42
622k
  EC.grow(2 * MF->getNumBlockIDs());
43
622k
44
3.24M
  for (const auto &MBB : *MF) {
45
3.24M
    unsigned OutE = 2 * MBB.getNumber() + 1;
46
3.24M
    // Join the outgoing bundle with the ingoing bundles of all successors.
47
3.24M
    for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
48
7.11M
           SE = MBB.succ_end(); SI != SE; 
++SI3.87M
)
49
3.87M
      EC.join(OutE, 2 * (*SI)->getNumber());
50
3.24M
  }
51
622k
  EC.compress();
52
622k
  if (ViewEdgeBundles)
53
0
    view();
54
622k
55
622k
  // Compute the reverse mapping.
56
622k
  Blocks.clear();
57
622k
  Blocks.resize(getNumBundles());
58
622k
59
3.86M
  for (unsigned i = 0, e = MF->getNumBlockIDs(); i != e; 
++i3.24M
) {
60
3.24M
    unsigned b0 = getBundle(i, false);
61
3.24M
    unsigned b1 = getBundle(i, true);
62
3.24M
    Blocks[b0].push_back(i);
63
3.24M
    if (b1 != b0)
64
2.65M
      Blocks[b1].push_back(i);
65
3.24M
  }
66
622k
67
622k
  return false;
68
622k
}
69
70
/// Specialize WriteGraph, the standard implementation won't work.
71
namespace llvm {
72
73
template<>
74
raw_ostream &WriteGraph<>(raw_ostream &O, const EdgeBundles &G,
75
                          bool ShortNames,
76
0
                          const Twine &Title) {
77
0
  const MachineFunction *MF = G.getMachineFunction();
78
0
79
0
  O << "digraph {\n";
80
0
  for (const auto &MBB : *MF) {
81
0
    unsigned BB = MBB.getNumber();
82
0
    O << "\t\"" << printMBBReference(MBB) << "\" [ shape=box ]\n"
83
0
      << '\t' << G.getBundle(BB, false) << " -> \"" << printMBBReference(MBB)
84
0
      << "\"\n"
85
0
      << "\t\"" << printMBBReference(MBB) << "\" -> " << G.getBundle(BB, true)
86
0
      << '\n';
87
0
    for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
88
0
           SE = MBB.succ_end(); SI != SE; ++SI)
89
0
      O << "\t\"" << printMBBReference(MBB) << "\" -> \""
90
0
        << printMBBReference(**SI) << "\" [ color=lightgray ]\n";
91
0
  }
92
0
  O << "}\n";
93
0
  return O;
94
0
}
95
96
} // end namespace llvm
97
98
/// view - Visualize the annotated bipartite CFG with Graphviz.
99
0
void EdgeBundles::view() const {
100
0
  ViewGraph(*this, "EdgeBundles");
101
0
}