@@ -185,28 +185,7 @@ bool Verify(const DominatorTreeBaseByGraphTraits<GraphTraits<N>> &DT);
185
185
// / This class is a generic template over graph nodes. It is instantiated for
186
186
// / various graphs in the LLVM IR or in the code generator.
187
187
template <class NodeT > class DominatorTreeBase {
188
- bool dominatedBySlowTreeWalk (const DomTreeNodeBase<NodeT> *A,
189
- const DomTreeNodeBase<NodeT> *B) const {
190
- assert (A != B);
191
- assert (isReachableFromEntry (B));
192
- assert (isReachableFromEntry (A));
193
-
194
- const DomTreeNodeBase<NodeT> *IDom;
195
- while ((IDom = B->getIDom ()) != nullptr && IDom != A && IDom != B)
196
- B = IDom; // Walk up the tree
197
- return IDom != nullptr ;
198
- }
199
-
200
- // / \brief Wipe this tree's state without releasing any resources.
201
- // /
202
- // / This is essentially a post-move helper only. It leaves the object in an
203
- // / assignable and destroyable state, but otherwise invalid.
204
- void wipe () {
205
- DomTreeNodes.clear ();
206
- RootNode = nullptr ;
207
- }
208
-
209
- protected:
188
+ protected:
210
189
std::vector<NodeT *> Roots;
211
190
bool IsPostDominators;
212
191
@@ -218,73 +197,10 @@ template <class NodeT> class DominatorTreeBase {
218
197
mutable bool DFSInfoValid = false ;
219
198
mutable unsigned int SlowQueries = 0 ;
220
199
221
- void reset () {
222
- DomTreeNodes.clear ();
223
- this ->Roots .clear ();
224
- RootNode = nullptr ;
225
- DFSInfoValid = false ;
226
- SlowQueries = 0 ;
227
- }
228
-
229
- // NewBB is split and now it has one successor. Update dominator tree to
230
- // reflect this change.
231
- template <class N >
232
- void Split (typename GraphTraits<N>::NodeRef NewBB) {
233
- using GraphT = GraphTraits<N>;
234
- using NodeRef = typename GraphT::NodeRef;
235
- assert (std::distance (GraphT::child_begin (NewBB),
236
- GraphT::child_end (NewBB)) == 1 &&
237
- " NewBB should have a single successor!" );
238
- NodeRef NewBBSucc = *GraphT::child_begin (NewBB);
239
-
240
- std::vector<NodeRef> PredBlocks;
241
- for (const auto &Pred : children<Inverse<N>>(NewBB))
242
- PredBlocks.push_back (Pred);
243
-
244
- assert (!PredBlocks.empty () && " No predblocks?" );
245
-
246
- bool NewBBDominatesNewBBSucc = true ;
247
- for (const auto &Pred : children<Inverse<N>>(NewBBSucc)) {
248
- if (Pred != NewBB && !dominates (NewBBSucc, Pred) &&
249
- isReachableFromEntry (Pred)) {
250
- NewBBDominatesNewBBSucc = false ;
251
- break ;
252
- }
253
- }
254
-
255
- // Find NewBB's immediate dominator and create new dominator tree node for
256
- // NewBB.
257
- NodeT *NewBBIDom = nullptr ;
258
- unsigned i = 0 ;
259
- for (i = 0 ; i < PredBlocks.size (); ++i)
260
- if (isReachableFromEntry (PredBlocks[i])) {
261
- NewBBIDom = PredBlocks[i];
262
- break ;
263
- }
264
-
265
- // It's possible that none of the predecessors of NewBB are reachable;
266
- // in that case, NewBB itself is unreachable, so nothing needs to be
267
- // changed.
268
- if (!NewBBIDom)
269
- return ;
270
-
271
- for (i = i + 1 ; i < PredBlocks.size (); ++i) {
272
- if (isReachableFromEntry (PredBlocks[i]))
273
- NewBBIDom = findNearestCommonDominator (NewBBIDom, PredBlocks[i]);
274
- }
275
-
276
- // Create the new dominator tree node... and set the idom of NewBB.
277
- DomTreeNodeBase<NodeT> *NewBBNode = addNewBlock (NewBB, NewBBIDom);
278
-
279
- // If NewBB strictly dominates other blocks, then it is now the immediate
280
- // dominator of NewBBSucc. Update the dominator tree as appropriate.
281
- if (NewBBDominatesNewBBSucc) {
282
- DomTreeNodeBase<NodeT> *NewBBSuccNode = getNode (NewBBSucc);
283
- changeImmediateDominator (NewBBSuccNode, NewBBNode);
284
- }
285
- }
200
+ friend struct DomTreeBuilder ::SemiNCAInfo<NodeT>;
201
+ using SNCAInfoTy = DomTreeBuilder::SemiNCAInfo<NodeT>;
286
202
287
- public:
203
+ public:
288
204
explicit DominatorTreeBase (bool isPostDom) : IsPostDominators(isPostDom) {}
289
205
290
206
DominatorTreeBase (DominatorTreeBase &&Arg)
@@ -633,16 +549,6 @@ template <class NodeT> class DominatorTreeBase {
633
549
if (getRootNode ()) PrintDomTree<NodeT>(getRootNode (), O, 1 );
634
550
}
635
551
636
- protected:
637
- friend struct DomTreeBuilder ::SemiNCAInfo<NodeT>;
638
- using SNCAInfoTy = DomTreeBuilder::SemiNCAInfo<NodeT>;
639
-
640
- template <class FuncT , class NodeTy >
641
- friend void Calculate (DominatorTreeBaseByGraphTraits<GraphTraits<NodeTy>> &DT,
642
- FuncT &F);
643
-
644
- void addRoot (NodeT *BB) { this ->Roots .push_back (BB); }
645
-
646
552
public:
647
553
// / updateDFSNumbers - Assign In and Out numbers to the nodes while walking
648
554
// / dominator tree in dfs order.
@@ -721,6 +627,96 @@ template <class NodeT> class DominatorTreeBase {
721
627
? DomTreeBuilder::Verify<Inverse<NodeT *>>(*this )
722
628
: DomTreeBuilder::Verify<NodeT *>(*this );
723
629
}
630
+
631
+ protected:
632
+ void addRoot (NodeT *BB) { this ->Roots .push_back (BB); }
633
+
634
+ void reset () {
635
+ DomTreeNodes.clear ();
636
+ this ->Roots .clear ();
637
+ RootNode = nullptr ;
638
+ DFSInfoValid = false ;
639
+ SlowQueries = 0 ;
640
+ }
641
+
642
+ // NewBB is split and now it has one successor. Update dominator tree to
643
+ // reflect this change.
644
+ template <class N >
645
+ void Split (typename GraphTraits<N>::NodeRef NewBB) {
646
+ using GraphT = GraphTraits<N>;
647
+ using NodeRef = typename GraphT::NodeRef;
648
+ assert (std::distance (GraphT::child_begin (NewBB),
649
+ GraphT::child_end (NewBB)) == 1 &&
650
+ " NewBB should have a single successor!" );
651
+ NodeRef NewBBSucc = *GraphT::child_begin (NewBB);
652
+
653
+ std::vector<NodeRef> PredBlocks;
654
+ for (const auto &Pred : children<Inverse<N>>(NewBB))
655
+ PredBlocks.push_back (Pred);
656
+
657
+ assert (!PredBlocks.empty () && " No predblocks?" );
658
+
659
+ bool NewBBDominatesNewBBSucc = true ;
660
+ for (const auto &Pred : children<Inverse<N>>(NewBBSucc)) {
661
+ if (Pred != NewBB && !dominates (NewBBSucc, Pred) &&
662
+ isReachableFromEntry (Pred)) {
663
+ NewBBDominatesNewBBSucc = false ;
664
+ break ;
665
+ }
666
+ }
667
+
668
+ // Find NewBB's immediate dominator and create new dominator tree node for
669
+ // NewBB.
670
+ NodeT *NewBBIDom = nullptr ;
671
+ unsigned i = 0 ;
672
+ for (i = 0 ; i < PredBlocks.size (); ++i)
673
+ if (isReachableFromEntry (PredBlocks[i])) {
674
+ NewBBIDom = PredBlocks[i];
675
+ break ;
676
+ }
677
+
678
+ // It's possible that none of the predecessors of NewBB are reachable;
679
+ // in that case, NewBB itself is unreachable, so nothing needs to be
680
+ // changed.
681
+ if (!NewBBIDom) return ;
682
+
683
+ for (i = i + 1 ; i < PredBlocks.size (); ++i) {
684
+ if (isReachableFromEntry (PredBlocks[i]))
685
+ NewBBIDom = findNearestCommonDominator (NewBBIDom, PredBlocks[i]);
686
+ }
687
+
688
+ // Create the new dominator tree node... and set the idom of NewBB.
689
+ DomTreeNodeBase<NodeT> *NewBBNode = addNewBlock (NewBB, NewBBIDom);
690
+
691
+ // If NewBB strictly dominates other blocks, then it is now the immediate
692
+ // dominator of NewBBSucc. Update the dominator tree as appropriate.
693
+ if (NewBBDominatesNewBBSucc) {
694
+ DomTreeNodeBase<NodeT> *NewBBSuccNode = getNode (NewBBSucc);
695
+ changeImmediateDominator (NewBBSuccNode, NewBBNode);
696
+ }
697
+ }
698
+
699
+ private:
700
+ bool dominatedBySlowTreeWalk (const DomTreeNodeBase<NodeT> *A,
701
+ const DomTreeNodeBase<NodeT> *B) const {
702
+ assert (A != B);
703
+ assert (isReachableFromEntry (B));
704
+ assert (isReachableFromEntry (A));
705
+
706
+ const DomTreeNodeBase<NodeT> *IDom;
707
+ while ((IDom = B->getIDom ()) != nullptr && IDom != A && IDom != B)
708
+ B = IDom; // Walk up the tree
709
+ return IDom != nullptr ;
710
+ }
711
+
712
+ // / \brief Wipe this tree's state without releasing any resources.
713
+ // /
714
+ // / This is essentially a post-move helper only. It leaves the object in an
715
+ // / assignable and destroyable state, but otherwise invalid.
716
+ void wipe () {
717
+ DomTreeNodes.clear ();
718
+ RootNode = nullptr ;
719
+ }
724
720
};
725
721
726
722
// These two functions are declared out of line as a workaround for building
0 commit comments