@@ -39,16 +39,40 @@ inline void DominatorTreeBase<MachineBasicBlock, false>::addRoot(
3939
4040extern template class DomTreeNodeBase <MachineBasicBlock>;
4141extern template class DominatorTreeBase <MachineBasicBlock, false >; // DomTree
42- extern template class DominatorTreeBase <MachineBasicBlock, true >; // PostDomTree
4342
44- using MachineDomTree = DomTreeBase<MachineBasicBlock>;
4543using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
4644
45+ namespace DomTreeBuilder {
46+ using MBBDomTree = DomTreeBase<MachineBasicBlock>;
47+ using MBBUpdates = ArrayRef<llvm::cfg::Update<MachineBasicBlock *>>;
48+ using MBBDomTreeGraphDiff = GraphDiff<MachineBasicBlock *, false >;
49+
50+ extern template void Calculate<MBBDomTree>(MBBDomTree &DT);
51+ extern template void CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT,
52+ MBBUpdates U);
53+
54+ extern template void InsertEdge<MBBDomTree>(MBBDomTree &DT,
55+ MachineBasicBlock *From,
56+ MachineBasicBlock *To);
57+
58+ extern template void DeleteEdge<MBBDomTree>(MBBDomTree &DT,
59+ MachineBasicBlock *From,
60+ MachineBasicBlock *To);
61+
62+ extern template void ApplyUpdates<MBBDomTree>(MBBDomTree &DT,
63+ MBBDomTreeGraphDiff &,
64+ MBBDomTreeGraphDiff *);
65+
66+ extern template bool Verify<MBBDomTree>(const MBBDomTree &DT,
67+ MBBDomTree::VerificationLevel VL);
68+ } // namespace DomTreeBuilder
69+
4770// ===-------------------------------------
4871// / DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
4972// / compute a normal dominator tree.
5073// /
51- class MachineDominatorTree : public MachineFunctionPass {
74+ class MachineDominatorTree : public DomTreeBase <MachineBasicBlock> {
75+ friend class MachineDominatorTreeWrapperPass ;
5276 // / Helper structure used to hold all the basic blocks
5377 // / involved in the split of a critical edge.
5478 struct CriticalEdge {
@@ -70,70 +94,64 @@ class MachineDominatorTree : public MachineFunctionPass {
7094 // / such as BB == elt.NewBB.
7195 mutable SmallSet<MachineBasicBlock *, 32 > NewBBs;
7296
73- // / The DominatorTreeBase that is used to compute a normal dominator tree.
74- std::unique_ptr<MachineDomTree> DT;
75-
7697 // / Apply all the recorded critical edges to the DT.
7798 // / This updates the underlying DT information in a way that uses
7899 // / the fast query path of DT as much as possible.
100+ // / FIXME: This method should not be a const member!
79101 // /
80102 // / \post CriticalEdgesToSplit.empty().
81103 void applySplitCriticalEdges () const ;
82104
83105public:
84- static char ID; // Pass ID, replacement for typeid
106+ using Base = DomTreeBase<MachineBasicBlock>;
85107
86- MachineDominatorTree ();
87- explicit MachineDominatorTree (MachineFunction &MF) : MachineFunctionPass(ID) {
88- calculate (MF);
89- }
108+ MachineDominatorTree () = default ;
109+ explicit MachineDominatorTree (MachineFunction &MF) { calculate (MF); }
90110
91- MachineDomTree &getBase () {
92- if (!DT)
93- DT.reset (new MachineDomTree ());
111+ // FIXME: If there is an updater for MachineDominatorTree,
112+ // migrate to this updater and remove these wrappers.
113+
114+ MachineDominatorTree &getBase () {
94115 applySplitCriticalEdges ();
95- return *DT ;
116+ return *this ;
96117 }
97118
98- void getAnalysisUsage (AnalysisUsage &AU) const override ;
99-
100119 MachineBasicBlock *getRoot () const {
101120 applySplitCriticalEdges ();
102- return DT-> getRoot ();
121+ return Base:: getRoot ();
103122 }
104123
105124 MachineDomTreeNode *getRootNode () const {
106125 applySplitCriticalEdges ();
107- return DT-> getRootNode ();
126+ return const_cast <MachineDomTreeNode *>( Base:: getRootNode () );
108127 }
109128
110- bool runOnMachineFunction (MachineFunction &F) override ;
111-
112129 void calculate (MachineFunction &F);
113130
114131 bool dominates (const MachineDomTreeNode *A,
115132 const MachineDomTreeNode *B) const {
116133 applySplitCriticalEdges ();
117- return DT-> dominates (A, B);
134+ return Base:: dominates (A, B);
118135 }
119136
120137 void getDescendants (MachineBasicBlock *A,
121138 SmallVectorImpl<MachineBasicBlock *> &Result) {
122139 applySplitCriticalEdges ();
123- DT-> getDescendants (A, Result);
140+ Base:: getDescendants (A, Result);
124141 }
125142
126143 bool dominates (const MachineBasicBlock *A, const MachineBasicBlock *B) const {
127144 applySplitCriticalEdges ();
128- return DT-> dominates (A, B);
145+ return Base:: dominates (A, B);
129146 }
130147
131148 // dominates - Return true if A dominates B. This performs the
132149 // special checks necessary if A and B are in the same basic block.
133150 bool dominates (const MachineInstr *A, const MachineInstr *B) const {
134151 applySplitCriticalEdges ();
135152 const MachineBasicBlock *BBA = A->getParent (), *BBB = B->getParent ();
136- if (BBA != BBB) return DT->dominates (BBA, BBB);
153+ if (BBA != BBB)
154+ return Base::dominates (BBA, BBB);
137155
138156 // Loop through the basic block until we find A or B.
139157 MachineBasicBlock::const_iterator I = BBA->begin ();
@@ -146,34 +164,34 @@ class MachineDominatorTree : public MachineFunctionPass {
146164 bool properlyDominates (const MachineDomTreeNode *A,
147165 const MachineDomTreeNode *B) const {
148166 applySplitCriticalEdges ();
149- return DT-> properlyDominates (A, B);
167+ return Base:: properlyDominates (A, B);
150168 }
151169
152170 bool properlyDominates (const MachineBasicBlock *A,
153171 const MachineBasicBlock *B) const {
154172 applySplitCriticalEdges ();
155- return DT-> properlyDominates (A, B);
173+ return Base:: properlyDominates (A, B);
156174 }
157175
158176 // / findNearestCommonDominator - Find nearest common dominator basic block
159177 // / for basic block A and B. If there is no such block then return NULL.
160178 MachineBasicBlock *findNearestCommonDominator (MachineBasicBlock *A,
161179 MachineBasicBlock *B) {
162180 applySplitCriticalEdges ();
163- return DT-> findNearestCommonDominator (A, B);
181+ return Base:: findNearestCommonDominator (A, B);
164182 }
165183
166184 MachineDomTreeNode *operator [](MachineBasicBlock *BB) const {
167185 applySplitCriticalEdges ();
168- return DT-> getNode (BB);
186+ return Base:: getNode (BB);
169187 }
170188
171189 // / getNode - return the (Post)DominatorTree node for the specified basic
172190 // / block. This is the same as using operator[] on this class.
173191 // /
174192 MachineDomTreeNode *getNode (MachineBasicBlock *BB) const {
175193 applySplitCriticalEdges ();
176- return DT-> getNode (BB);
194+ return Base:: getNode (BB);
177195 }
178196
179197 // / addNewBlock - Add a new node to the dominator tree information. This
@@ -182,7 +200,7 @@ class MachineDominatorTree : public MachineFunctionPass {
182200 MachineDomTreeNode *addNewBlock (MachineBasicBlock *BB,
183201 MachineBasicBlock *DomBB) {
184202 applySplitCriticalEdges ();
185- return DT-> addNewBlock (BB, DomBB);
203+ return Base:: addNewBlock (BB, DomBB);
186204 }
187205
188206 // / changeImmediateDominator - This method is used to update the dominator
@@ -191,43 +209,37 @@ class MachineDominatorTree : public MachineFunctionPass {
191209 void changeImmediateDominator (MachineBasicBlock *N,
192210 MachineBasicBlock *NewIDom) {
193211 applySplitCriticalEdges ();
194- DT-> changeImmediateDominator (N, NewIDom);
212+ Base:: changeImmediateDominator (N, NewIDom);
195213 }
196214
197215 void changeImmediateDominator (MachineDomTreeNode *N,
198216 MachineDomTreeNode *NewIDom) {
199217 applySplitCriticalEdges ();
200- DT-> changeImmediateDominator (N, NewIDom);
218+ Base:: changeImmediateDominator (N, NewIDom);
201219 }
202220
203221 // / eraseNode - Removes a node from the dominator tree. Block must not
204222 // / dominate any other blocks. Removes node from its immediate dominator's
205223 // / children list. Deletes dominator node associated with basic block BB.
206224 void eraseNode (MachineBasicBlock *BB) {
207225 applySplitCriticalEdges ();
208- DT-> eraseNode (BB);
226+ Base:: eraseNode (BB);
209227 }
210228
211229 // / splitBlock - BB is split and now it has one successor. Update dominator
212230 // / tree to reflect this change.
213231 void splitBlock (MachineBasicBlock* NewBB) {
214232 applySplitCriticalEdges ();
215- DT-> splitBlock (NewBB);
233+ Base:: splitBlock (NewBB);
216234 }
217235
218236 // / isReachableFromEntry - Return true if A is dominated by the entry
219237 // / block of the function containing it.
220238 bool isReachableFromEntry (const MachineBasicBlock *A) {
221239 applySplitCriticalEdges ();
222- return DT-> isReachableFromEntry (A);
240+ return Base:: isReachableFromEntry (A);
223241 }
224242
225- void releaseMemory () override ;
226-
227- void verifyAnalysis () const override ;
228-
229- void print (raw_ostream &OS, const Module*) const override ;
230-
231243 // / Record that the critical edge (FromBB, ToBB) has been
232244 // / split with NewBB.
233245 // / This is best to use this method instead of directly update the
@@ -251,6 +263,32 @@ class MachineDominatorTree : public MachineFunctionPass {
251263 }
252264};
253265
266+ // / \brief Analysis pass which computes a \c MachineDominatorTree.
267+ class MachineDominatorTreeWrapperPass : public MachineFunctionPass {
268+ MachineDominatorTree DT;
269+
270+ public:
271+ static char ID;
272+
273+ MachineDominatorTreeWrapperPass ();
274+
275+ MachineDominatorTree &getDomTree () { return DT; }
276+ const MachineDominatorTree &getDomTree () const { return DT; }
277+
278+ bool runOnMachineFunction (MachineFunction &MF) override ;
279+
280+ void verifyAnalysis () const override ;
281+
282+ void getAnalysisUsage (AnalysisUsage &AU) const override {
283+ AU.setPreservesAll ();
284+ MachineFunctionPass::getAnalysisUsage (AU);
285+ }
286+
287+ void releaseMemory () override ;
288+
289+ void print (raw_ostream &OS, const Module *M = nullptr ) const override ;
290+ };
291+
254292// ===-------------------------------------
255293// / DominatorTree GraphTraits specialization so the DominatorTree can be
256294// / iterable by generic graph iterators.
0 commit comments