Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/MachineRegionInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- lib/Codegen/MachineRegionInfo.cpp ----------------------------------===//
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
#include "llvm/CodeGen/MachineRegionInfo.h"
10
#include "llvm/ADT/Statistic.h"
11
#include "llvm/Analysis/RegionInfoImpl.h"
12
#include "llvm/CodeGen/MachinePostDominators.h"
13
#include "llvm/Config/llvm-config.h"
14
#include "llvm/Pass.h"
15
#include "llvm/Support/Compiler.h"
16
#include "llvm/Support/Debug.h"
17
18
#define DEBUG_TYPE "machine-region-info"
19
20
using namespace llvm;
21
22
STATISTIC(numMachineRegions,       "The # of machine regions");
23
STATISTIC(numMachineSimpleRegions, "The # of simple machine regions");
24
25
namespace llvm {
26
27
template class RegionBase<RegionTraits<MachineFunction>>;
28
template class RegionNodeBase<RegionTraits<MachineFunction>>;
29
template class RegionInfoBase<RegionTraits<MachineFunction>>;
30
31
} // end namespace llvm
32
33
//===----------------------------------------------------------------------===//
34
// MachineRegion implementation
35
36
MachineRegion::MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit,
37
                             MachineRegionInfo* RI,
38
                             MachineDominatorTree *DT, MachineRegion *Parent) :
39
0
  RegionBase<RegionTraits<MachineFunction>>(Entry, Exit, RI, DT, Parent) {}
40
41
0
MachineRegion::~MachineRegion() = default;
42
43
//===----------------------------------------------------------------------===//
44
// MachineRegionInfo implementation
45
46
0
MachineRegionInfo::MachineRegionInfo() = default;
47
48
0
MachineRegionInfo::~MachineRegionInfo() = default;
49
50
0
void MachineRegionInfo::updateStatistics(MachineRegion *R) {
51
0
  ++numMachineRegions;
52
0
53
0
  // TODO: Slow. Should only be enabled if -stats is used.
54
0
  if (R->isSimple())
55
0
    ++numMachineSimpleRegions;
56
0
}
57
58
void MachineRegionInfo::recalculate(MachineFunction &F,
59
                                    MachineDominatorTree *DT_,
60
                                    MachinePostDominatorTree *PDT_,
61
0
                                    MachineDominanceFrontier *DF_) {
62
0
  DT = DT_;
63
0
  PDT = PDT_;
64
0
  DF = DF_;
65
0
66
0
  MachineBasicBlock *Entry = GraphTraits<MachineFunction*>::getEntryNode(&F);
67
0
68
0
  TopLevelRegion = new MachineRegion(Entry, nullptr, this, DT, nullptr);
69
0
  updateStatistics(TopLevelRegion);
70
0
  calculate(F);
71
0
}
72
73
//===----------------------------------------------------------------------===//
74
// MachineRegionInfoPass implementation
75
//
76
77
0
MachineRegionInfoPass::MachineRegionInfoPass() : MachineFunctionPass(ID) {
78
0
  initializeMachineRegionInfoPassPass(*PassRegistry::getPassRegistry());
79
0
}
80
81
0
MachineRegionInfoPass::~MachineRegionInfoPass() = default;
82
83
0
bool MachineRegionInfoPass::runOnMachineFunction(MachineFunction &F) {
84
0
  releaseMemory();
85
0
86
0
  auto DT = &getAnalysis<MachineDominatorTree>();
87
0
  auto PDT = &getAnalysis<MachinePostDominatorTree>();
88
0
  auto DF = &getAnalysis<MachineDominanceFrontier>();
89
0
90
0
  RI.recalculate(F, DT, PDT, DF);
91
0
92
0
  LLVM_DEBUG(RI.dump());
93
0
94
0
  return false;
95
0
}
96
97
0
void MachineRegionInfoPass::releaseMemory() {
98
0
  RI.releaseMemory();
99
0
}
100
101
0
void MachineRegionInfoPass::verifyAnalysis() const {
102
0
  // Only do verification when user wants to, otherwise this expensive check
103
0
  // will be invoked by PMDataManager::verifyPreservedAnalysis when
104
0
  // a regionpass (marked PreservedAll) finish.
105
0
  if (MachineRegionInfo::VerifyRegionInfo)
106
0
    RI.verifyAnalysis();
107
0
}
108
109
0
void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
110
0
  AU.setPreservesAll();
111
0
  AU.addRequired<MachineDominatorTree>();
112
0
  AU.addRequired<MachinePostDominatorTree>();
113
0
  AU.addRequired<MachineDominanceFrontier>();
114
0
  MachineFunctionPass::getAnalysisUsage(AU);
115
0
}
116
117
0
void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
118
0
  RI.print(OS);
119
0
}
120
121
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
122
LLVM_DUMP_METHOD void MachineRegionInfoPass::dump() const {
123
  RI.dump();
124
}
125
#endif
126
127
char MachineRegionInfoPass::ID = 0;
128
char &MachineRegionInfoPassID = MachineRegionInfoPass::ID;
129
130
42.3k
INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE,
131
42.3k
                      "Detect single entry single exit regions", true, true)
132
42.3k
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
133
42.3k
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
134
42.3k
INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier)
135
42.3k
INITIALIZE_PASS_END(MachineRegionInfoPass, DEBUG_TYPE,
136
                    "Detect single entry single exit regions", true, true)
137
138
// Create methods available outside of this file, to use them
139
// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
140
// the link time optimization.
141
142
namespace llvm {
143
144
0
FunctionPass *createMachineRegionInfoPass() {
145
0
  return new MachineRegionInfoPass();
146
0
}
147
148
} // end namespace llvm