Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineRegionInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/MachineRegionInfo.h -------------------------*- C++ -*-===//
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
#ifndef LLVM_CODEGEN_MACHINEREGIONINFO_H
10
#define LLVM_CODEGEN_MACHINEREGIONINFO_H
11
12
#include "llvm/ADT/DepthFirstIterator.h"
13
#include "llvm/Analysis/RegionInfo.h"
14
#include "llvm/Analysis/RegionIterator.h"
15
#include "llvm/CodeGen/MachineBasicBlock.h"
16
#include "llvm/CodeGen/MachineDominanceFrontier.h"
17
#include "llvm/CodeGen/MachineDominators.h"
18
#include "llvm/CodeGen/MachineFunction.h"
19
#include "llvm/CodeGen/MachineFunctionPass.h"
20
#include "llvm/CodeGen/MachineLoopInfo.h"
21
#include <cassert>
22
23
namespace llvm {
24
25
struct MachinePostDominatorTree;
26
class MachineRegion;
27
class MachineRegionNode;
28
class MachineRegionInfo;
29
30
template <> struct RegionTraits<MachineFunction> {
31
  using FuncT = MachineFunction;
32
  using BlockT = MachineBasicBlock;
33
  using RegionT = MachineRegion;
34
  using RegionNodeT = MachineRegionNode;
35
  using RegionInfoT = MachineRegionInfo;
36
  using DomTreeT = MachineDominatorTree;
37
  using DomTreeNodeT = MachineDomTreeNode;
38
  using PostDomTreeT = MachinePostDominatorTree;
39
  using DomFrontierT = MachineDominanceFrontier;
40
  using InstT = MachineInstr;
41
  using LoopT = MachineLoop;
42
  using LoopInfoT = MachineLoopInfo;
43
44
0
  static unsigned getNumSuccessors(MachineBasicBlock *BB) {
45
0
    return BB->succ_size();
46
0
  }
47
};
48
49
class MachineRegionNode : public RegionNodeBase<RegionTraits<MachineFunction>> {
50
public:
51
  inline MachineRegionNode(MachineRegion *Parent, MachineBasicBlock *Entry,
52
                           bool isSubRegion = false)
53
      : RegionNodeBase<RegionTraits<MachineFunction>>(Parent, Entry,
54
0
                                                      isSubRegion) {}
55
56
0
  bool operator==(const MachineRegion &RN) const {
57
0
    return this == reinterpret_cast<const MachineRegionNode *>(&RN);
58
0
  }
59
};
60
61
class MachineRegion : public RegionBase<RegionTraits<MachineFunction>> {
62
public:
63
  MachineRegion(MachineBasicBlock *Entry, MachineBasicBlock *Exit,
64
                MachineRegionInfo *RI, MachineDominatorTree *DT,
65
                MachineRegion *Parent = nullptr);
66
  ~MachineRegion();
67
68
0
  bool operator==(const MachineRegionNode &RN) const {
69
0
    return &RN == reinterpret_cast<const MachineRegionNode *>(this);
70
0
  }
71
};
72
73
class MachineRegionInfo : public RegionInfoBase<RegionTraits<MachineFunction>> {
74
public:
75
  explicit MachineRegionInfo();
76
  ~MachineRegionInfo() override;
77
78
  // updateStatistics - Update statistic about created regions.
79
  void updateStatistics(MachineRegion *R) final;
80
81
  void recalculate(MachineFunction &F, MachineDominatorTree *DT,
82
                   MachinePostDominatorTree *PDT, MachineDominanceFrontier *DF);
83
};
84
85
class MachineRegionInfoPass : public MachineFunctionPass {
86
  MachineRegionInfo RI;
87
88
public:
89
  static char ID;
90
91
  explicit MachineRegionInfoPass();
92
  ~MachineRegionInfoPass() override;
93
94
0
  MachineRegionInfo &getRegionInfo() { return RI; }
95
96
0
  const MachineRegionInfo &getRegionInfo() const { return RI; }
97
98
  /// @name MachineFunctionPass interface
99
  //@{
100
  bool runOnMachineFunction(MachineFunction &F) override;
101
  void releaseMemory() override;
102
  void verifyAnalysis() const override;
103
  void getAnalysisUsage(AnalysisUsage &AU) const override;
104
  void print(raw_ostream &OS, const Module *) const override;
105
  void dump() const;
106
  //@}
107
};
108
109
template <>
110
template <>
111
inline MachineBasicBlock *
112
RegionNodeBase<RegionTraits<MachineFunction>>::getNodeAs<MachineBasicBlock>()
113
0
    const {
114
0
  assert(!isSubRegion() && "This is not a MachineBasicBlock RegionNode!");
115
0
  return getEntry();
116
0
}
117
118
template <>
119
template <>
120
inline MachineRegion *
121
RegionNodeBase<RegionTraits<MachineFunction>>::getNodeAs<MachineRegion>()
122
0
    const {
123
0
  assert(isSubRegion() && "This is not a subregion RegionNode!");
124
0
  auto Unconst =
125
0
      const_cast<RegionNodeBase<RegionTraits<MachineFunction>> *>(this);
126
0
  return reinterpret_cast<MachineRegion *>(Unconst);
127
0
}
128
129
RegionNodeGraphTraits(MachineRegionNode, MachineBasicBlock, MachineRegion);
130
RegionNodeGraphTraits(const MachineRegionNode, MachineBasicBlock,
131
                      MachineRegion);
132
133
RegionGraphTraits(MachineRegion, MachineRegionNode);
134
RegionGraphTraits(const MachineRegion, const MachineRegionNode);
135
136
template <>
137
struct GraphTraits<MachineRegionInfo *>
138
    : public GraphTraits<FlatIt<MachineRegionNode *>> {
139
  using nodes_iterator = df_iterator<NodeRef, df_iterator_default_set<NodeRef>,
140
                                     false, GraphTraits<FlatIt<NodeRef>>>;
141
142
0
  static NodeRef getEntryNode(MachineRegionInfo *RI) {
143
0
    return GraphTraits<FlatIt<MachineRegion *>>::getEntryNode(
144
0
        RI->getTopLevelRegion());
145
0
  }
146
147
0
  static nodes_iterator nodes_begin(MachineRegionInfo *RI) {
148
0
    return nodes_iterator::begin(getEntryNode(RI));
149
0
  }
150
151
0
  static nodes_iterator nodes_end(MachineRegionInfo *RI) {
152
0
    return nodes_iterator::end(getEntryNode(RI));
153
0
  }
154
};
155
156
template <>
157
struct GraphTraits<MachineRegionInfoPass *>
158
    : public GraphTraits<MachineRegionInfo *> {
159
  using nodes_iterator = df_iterator<NodeRef, df_iterator_default_set<NodeRef>,
160
                                     false, GraphTraits<FlatIt<NodeRef>>>;
161
162
0
  static NodeRef getEntryNode(MachineRegionInfoPass *RI) {
163
0
    return GraphTraits<MachineRegionInfo *>::getEntryNode(&RI->getRegionInfo());
164
0
  }
165
166
0
  static nodes_iterator nodes_begin(MachineRegionInfoPass *RI) {
167
0
    return GraphTraits<MachineRegionInfo *>::nodes_begin(&RI->getRegionInfo());
168
0
  }
169
170
0
  static nodes_iterator nodes_end(MachineRegionInfoPass *RI) {
171
0
    return GraphTraits<MachineRegionInfo *>::nodes_end(&RI->getRegionInfo());
172
0
  }
173
};
174
175
extern template class RegionBase<RegionTraits<MachineFunction>>;
176
extern template class RegionNodeBase<RegionTraits<MachineFunction>>;
177
extern template class RegionInfoBase<RegionTraits<MachineFunction>>;
178
179
} // end namespace llvm
180
181
#endif // LLVM_CODEGEN_MACHINEREGIONINFO_H