@@ -44,11 +44,37 @@ extern template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTree
44
44
using MachineDomTree = DomTreeBase<MachineBasicBlock>;
45
45
using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
46
46
47
+ namespace DomTreeBuilder {
48
+ using MBBDomTree = MachineDomTree;
49
+ using MBBUpdates = ArrayRef<llvm::cfg::Update<MachineBasicBlock *>>;
50
+ using MBBDomTreeGraphDiff = GraphDiff<MachineBasicBlock *, false >;
51
+
52
+ extern template void Calculate<MBBDomTree>(MBBDomTree &DT);
53
+ extern template void CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT,
54
+ MBBUpdates U);
55
+
56
+ extern template void InsertEdge<MBBDomTree>(MBBDomTree &DT,
57
+ MachineBasicBlock *From,
58
+ MachineBasicBlock *To);
59
+
60
+ extern template void DeleteEdge<MBBDomTree>(MBBDomTree &DT,
61
+ MachineBasicBlock *From,
62
+ MachineBasicBlock *To);
63
+
64
+ extern template void ApplyUpdates<MBBDomTree>(MBBDomTree &DT,
65
+ MBBDomTreeGraphDiff &,
66
+ MBBDomTreeGraphDiff *);
67
+
68
+ extern template bool Verify<MBBDomTree>(const MBBDomTree &DT,
69
+ MBBDomTree::VerificationLevel VL);
70
+ } // namespace DomTreeBuilder
71
+
47
72
// ===-------------------------------------
48
73
// / DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
49
74
// / compute a normal dominator tree.
50
75
// /
51
- class MachineDominatorTree : public MachineFunctionPass {
76
+ class MachineDominatorTree : public MachineDomTree {
77
+ friend class MachineDominatorTreeWrapperPass ;
52
78
// / Helper structure used to hold all the basic blocks
53
79
// / involved in the split of a critical edge.
54
80
struct CriticalEdge {
@@ -70,70 +96,61 @@ class MachineDominatorTree : public MachineFunctionPass {
70
96
// / such as BB == elt.NewBB.
71
97
mutable SmallSet<MachineBasicBlock *, 32 > NewBBs;
72
98
73
- // / The DominatorTreeBase that is used to compute a normal dominator tree.
74
- std::unique_ptr<MachineDomTree> DT;
75
-
76
99
// / Apply all the recorded critical edges to the DT.
77
100
// / This updates the underlying DT information in a way that uses
78
101
// / the fast query path of DT as much as possible.
102
+ // / FIXME: This method should not be a const member!
79
103
// /
80
104
// / \post CriticalEdgesToSplit.empty().
81
105
void applySplitCriticalEdges () const ;
82
106
83
107
public:
84
- static char ID; // Pass ID, replacement for typeid
108
+ using Base = MachineDomTree;
85
109
86
- MachineDominatorTree ();
87
- explicit MachineDominatorTree (MachineFunction &MF) : MachineFunctionPass(ID) {
88
- calculate (MF);
89
- }
110
+ MachineDominatorTree () = default ;
111
+ explicit MachineDominatorTree (MachineFunction &MF) { calculate (MF); }
90
112
91
113
MachineDomTree &getBase () {
92
- if (!DT)
93
- DT.reset (new MachineDomTree ());
94
114
applySplitCriticalEdges ();
95
- return *DT ;
115
+ return *this ;
96
116
}
97
117
98
- void getAnalysisUsage (AnalysisUsage &AU) const override ;
99
-
100
118
MachineBasicBlock *getRoot () const {
101
119
applySplitCriticalEdges ();
102
- return DT-> getRoot ();
120
+ return Base:: getRoot ();
103
121
}
104
122
105
123
MachineDomTreeNode *getRootNode () const {
106
124
applySplitCriticalEdges ();
107
- return DT-> getRootNode ();
125
+ return const_cast <MachineDomTreeNode *>( Base:: getRootNode () );
108
126
}
109
127
110
- bool runOnMachineFunction (MachineFunction &F) override ;
111
-
112
128
void calculate (MachineFunction &F);
113
129
114
130
bool dominates (const MachineDomTreeNode *A,
115
131
const MachineDomTreeNode *B) const {
116
132
applySplitCriticalEdges ();
117
- return DT-> dominates (A, B);
133
+ return Base:: dominates (A, B);
118
134
}
119
135
120
136
void getDescendants (MachineBasicBlock *A,
121
137
SmallVectorImpl<MachineBasicBlock *> &Result) {
122
138
applySplitCriticalEdges ();
123
- DT-> getDescendants (A, Result);
139
+ Base:: getDescendants (A, Result);
124
140
}
125
141
126
142
bool dominates (const MachineBasicBlock *A, const MachineBasicBlock *B) const {
127
143
applySplitCriticalEdges ();
128
- return DT-> dominates (A, B);
144
+ return Base:: dominates (A, B);
129
145
}
130
146
131
147
// dominates - Return true if A dominates B. This performs the
132
148
// special checks necessary if A and B are in the same basic block.
133
149
bool dominates (const MachineInstr *A, const MachineInstr *B) const {
134
150
applySplitCriticalEdges ();
135
151
const MachineBasicBlock *BBA = A->getParent (), *BBB = B->getParent ();
136
- if (BBA != BBB) return DT->dominates (BBA, BBB);
152
+ if (BBA != BBB)
153
+ return Base::dominates (BBA, BBB);
137
154
138
155
// Loop through the basic block until we find A or B.
139
156
MachineBasicBlock::const_iterator I = BBA->begin ();
@@ -146,34 +163,34 @@ class MachineDominatorTree : public MachineFunctionPass {
146
163
bool properlyDominates (const MachineDomTreeNode *A,
147
164
const MachineDomTreeNode *B) const {
148
165
applySplitCriticalEdges ();
149
- return DT-> properlyDominates (A, B);
166
+ return Base:: properlyDominates (A, B);
150
167
}
151
168
152
169
bool properlyDominates (const MachineBasicBlock *A,
153
170
const MachineBasicBlock *B) const {
154
171
applySplitCriticalEdges ();
155
- return DT-> properlyDominates (A, B);
172
+ return Base:: properlyDominates (A, B);
156
173
}
157
174
158
175
// / findNearestCommonDominator - Find nearest common dominator basic block
159
176
// / for basic block A and B. If there is no such block then return NULL.
160
177
MachineBasicBlock *findNearestCommonDominator (MachineBasicBlock *A,
161
178
MachineBasicBlock *B) {
162
179
applySplitCriticalEdges ();
163
- return DT-> findNearestCommonDominator (A, B);
180
+ return Base:: findNearestCommonDominator (A, B);
164
181
}
165
182
166
183
MachineDomTreeNode *operator [](MachineBasicBlock *BB) const {
167
184
applySplitCriticalEdges ();
168
- return DT-> getNode (BB);
185
+ return Base:: getNode (BB);
169
186
}
170
187
171
188
// / getNode - return the (Post)DominatorTree node for the specified basic
172
189
// / block. This is the same as using operator[] on this class.
173
190
// /
174
191
MachineDomTreeNode *getNode (MachineBasicBlock *BB) const {
175
192
applySplitCriticalEdges ();
176
- return DT-> getNode (BB);
193
+ return Base:: getNode (BB);
177
194
}
178
195
179
196
// / addNewBlock - Add a new node to the dominator tree information. This
@@ -182,7 +199,7 @@ class MachineDominatorTree : public MachineFunctionPass {
182
199
MachineDomTreeNode *addNewBlock (MachineBasicBlock *BB,
183
200
MachineBasicBlock *DomBB) {
184
201
applySplitCriticalEdges ();
185
- return DT-> addNewBlock (BB, DomBB);
202
+ return Base:: addNewBlock (BB, DomBB);
186
203
}
187
204
188
205
// / changeImmediateDominator - This method is used to update the dominator
@@ -191,43 +208,37 @@ class MachineDominatorTree : public MachineFunctionPass {
191
208
void changeImmediateDominator (MachineBasicBlock *N,
192
209
MachineBasicBlock *NewIDom) {
193
210
applySplitCriticalEdges ();
194
- DT-> changeImmediateDominator (N, NewIDom);
211
+ Base:: changeImmediateDominator (N, NewIDom);
195
212
}
196
213
197
214
void changeImmediateDominator (MachineDomTreeNode *N,
198
215
MachineDomTreeNode *NewIDom) {
199
216
applySplitCriticalEdges ();
200
- DT-> changeImmediateDominator (N, NewIDom);
217
+ Base:: changeImmediateDominator (N, NewIDom);
201
218
}
202
219
203
220
// / eraseNode - Removes a node from the dominator tree. Block must not
204
221
// / dominate any other blocks. Removes node from its immediate dominator's
205
222
// / children list. Deletes dominator node associated with basic block BB.
206
223
void eraseNode (MachineBasicBlock *BB) {
207
224
applySplitCriticalEdges ();
208
- DT-> eraseNode (BB);
225
+ Base:: eraseNode (BB);
209
226
}
210
227
211
228
// / splitBlock - BB is split and now it has one successor. Update dominator
212
229
// / tree to reflect this change.
213
230
void splitBlock (MachineBasicBlock* NewBB) {
214
231
applySplitCriticalEdges ();
215
- DT-> splitBlock (NewBB);
232
+ Base:: splitBlock (NewBB);
216
233
}
217
234
218
235
// / isReachableFromEntry - Return true if A is dominated by the entry
219
236
// / block of the function containing it.
220
237
bool isReachableFromEntry (const MachineBasicBlock *A) {
221
238
applySplitCriticalEdges ();
222
- return DT-> isReachableFromEntry (A);
239
+ return Base:: isReachableFromEntry (A);
223
240
}
224
241
225
- void releaseMemory () override ;
226
-
227
- void verifyAnalysis () const override ;
228
-
229
- void print (raw_ostream &OS, const Module*) const override ;
230
-
231
242
// / Record that the critical edge (FromBB, ToBB) has been
232
243
// / split with NewBB.
233
244
// / This is best to use this method instead of directly update the
@@ -251,6 +262,32 @@ class MachineDominatorTree : public MachineFunctionPass {
251
262
}
252
263
};
253
264
265
+ // / \brief Analysis pass which computes a \c MachineDominatorTree.
266
+ class MachineDominatorTreeWrapperPass : public MachineFunctionPass {
267
+ MachineDominatorTree DT;
268
+
269
+ public:
270
+ static char ID;
271
+
272
+ MachineDominatorTreeWrapperPass ();
273
+
274
+ MachineDominatorTree &getDomTree () { return DT; }
275
+ const MachineDominatorTree &getDomTree () const { return DT; }
276
+
277
+ bool runOnMachineFunction (MachineFunction &MF) override ;
278
+
279
+ void verifyAnalysis () const override ;
280
+
281
+ void getAnalysisUsage (AnalysisUsage &AU) const override {
282
+ AU.setPreservesAll ();
283
+ MachineFunctionPass::getAnalysisUsage (AU);
284
+ }
285
+
286
+ void releaseMemory () override ;
287
+
288
+ void print (raw_ostream &OS, const Module *M = nullptr ) const override ;
289
+ };
290
+
254
291
// ===-------------------------------------
255
292
// / DominatorTree GraphTraits specialization so the DominatorTree can be
256
293
// / iterable by generic graph iterators.
0 commit comments