Skip to content

Commit 72c57ec

Browse files
committed
[Dominators][CodeGen] Clean up MachineDominators
Summary: This is a cleanup patch for MachineDominatorTree. It would be an NFC, except for replacing custom DomTree verification with the generic one. Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao Reviewed By: arsenm Subscribers: wdng, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67976 llvm-svn: 373101
1 parent 1a55431 commit 72c57ec

File tree

2 files changed

+32
-47
lines changed

2 files changed

+32
-47
lines changed

llvm/include/llvm/CodeGen/MachineDominators.h

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
4444
/// compute a normal dominator tree.
4545
///
4646
class MachineDominatorTree : public MachineFunctionPass {
47+
using DomTreeT = DomTreeBase<MachineBasicBlock>;
48+
4749
/// Helper structure used to hold all the basic blocks
4850
/// involved in the split of a critical edge.
4951
struct CriticalEdge {
@@ -65,8 +67,8 @@ class MachineDominatorTree : public MachineFunctionPass {
6567
/// such as BB == elt.NewBB.
6668
mutable SmallSet<MachineBasicBlock *, 32> NewBBs;
6769

68-
/// The DominatorTreeBase that is used to compute a normal dominator tree
69-
std::unique_ptr<DomTreeBase<MachineBasicBlock>> DT;
70+
/// The DominatorTreeBase that is used to compute a normal dominator tree.
71+
std::unique_ptr<DomTreeT> DT;
7072

7173
/// Apply all the recorded critical edges to the DT.
7274
/// This updates the underlying DT information in a way that uses
@@ -80,8 +82,8 @@ class MachineDominatorTree : public MachineFunctionPass {
8082

8183
MachineDominatorTree();
8284

83-
DomTreeBase<MachineBasicBlock> &getBase() {
84-
if (!DT) DT.reset(new DomTreeBase<MachineBasicBlock>());
85+
DomTreeT &getBase() {
86+
if (!DT) DT.reset(new DomTreeT());
8587
applySplitCriticalEdges();
8688
return *DT;
8789
}
@@ -92,31 +94,30 @@ class MachineDominatorTree : public MachineFunctionPass {
9294
/// multiple blocks if we are computing post dominators. For forward
9395
/// dominators, this will always be a single block (the entry node).
9496
///
95-
inline const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
97+
const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
9698
applySplitCriticalEdges();
9799
return DT->getRoots();
98100
}
99101

100-
inline MachineBasicBlock *getRoot() const {
102+
MachineBasicBlock *getRoot() const {
101103
applySplitCriticalEdges();
102104
return DT->getRoot();
103105
}
104106

105-
inline MachineDomTreeNode *getRootNode() const {
107+
MachineDomTreeNode *getRootNode() const {
106108
applySplitCriticalEdges();
107109
return DT->getRootNode();
108110
}
109111

110112
bool runOnMachineFunction(MachineFunction &F) override;
111113

112-
inline bool dominates(const MachineDomTreeNode* A,
113-
const MachineDomTreeNode* B) const {
114+
bool dominates(const MachineDomTreeNode *A,
115+
const MachineDomTreeNode *B) const {
114116
applySplitCriticalEdges();
115117
return DT->dominates(A, B);
116118
}
117119

118-
inline bool dominates(const MachineBasicBlock* A,
119-
const MachineBasicBlock* B) const {
120+
bool dominates(const MachineBasicBlock *A, const MachineBasicBlock *B) const {
120121
applySplitCriticalEdges();
121122
return DT->dominates(A, B);
122123
}
@@ -133,83 +134,77 @@ class MachineDominatorTree : public MachineFunctionPass {
133134
for (; &*I != A && &*I != B; ++I)
134135
/*empty*/ ;
135136

136-
//if(!DT.IsPostDominators) {
137-
// A dominates B if it is found first in the basic block.
138-
return &*I == A;
139-
//} else {
140-
// // A post-dominates B if B is found first in the basic block.
141-
// return &*I == B;
142-
//}
137+
return &*I == A;
143138
}
144139

145-
inline bool properlyDominates(const MachineDomTreeNode* A,
146-
const MachineDomTreeNode* B) const {
140+
bool properlyDominates(const MachineDomTreeNode *A,
141+
const MachineDomTreeNode *B) const {
147142
applySplitCriticalEdges();
148143
return DT->properlyDominates(A, B);
149144
}
150145

151-
inline bool properlyDominates(const MachineBasicBlock* A,
152-
const MachineBasicBlock* B) const {
146+
bool properlyDominates(const MachineBasicBlock *A,
147+
const MachineBasicBlock *B) const {
153148
applySplitCriticalEdges();
154149
return DT->properlyDominates(A, B);
155150
}
156151

157152
/// findNearestCommonDominator - Find nearest common dominator basic block
158153
/// for basic block A and B. If there is no such block then return NULL.
159-
inline MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
160-
MachineBasicBlock *B) {
154+
MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A,
155+
MachineBasicBlock *B) {
161156
applySplitCriticalEdges();
162157
return DT->findNearestCommonDominator(A, B);
163158
}
164159

165-
inline MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
160+
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
166161
applySplitCriticalEdges();
167162
return DT->getNode(BB);
168163
}
169164

170165
/// getNode - return the (Post)DominatorTree node for the specified basic
171166
/// block. This is the same as using operator[] on this class.
172167
///
173-
inline MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
168+
MachineDomTreeNode *getNode(MachineBasicBlock *BB) const {
174169
applySplitCriticalEdges();
175170
return DT->getNode(BB);
176171
}
177172

178173
/// addNewBlock - Add a new node to the dominator tree information. This
179174
/// creates a new node as a child of DomBB dominator node,linking it into
180175
/// the children list of the immediate dominator.
181-
inline MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB,
182-
MachineBasicBlock *DomBB) {
176+
MachineDomTreeNode *addNewBlock(MachineBasicBlock *BB,
177+
MachineBasicBlock *DomBB) {
183178
applySplitCriticalEdges();
184179
return DT->addNewBlock(BB, DomBB);
185180
}
186181

187182
/// changeImmediateDominator - This method is used to update the dominator
188183
/// tree information when a node's immediate dominator changes.
189184
///
190-
inline void changeImmediateDominator(MachineBasicBlock *N,
191-
MachineBasicBlock* NewIDom) {
185+
void changeImmediateDominator(MachineBasicBlock *N,
186+
MachineBasicBlock *NewIDom) {
192187
applySplitCriticalEdges();
193188
DT->changeImmediateDominator(N, NewIDom);
194189
}
195190

196-
inline void changeImmediateDominator(MachineDomTreeNode *N,
197-
MachineDomTreeNode* NewIDom) {
191+
void changeImmediateDominator(MachineDomTreeNode *N,
192+
MachineDomTreeNode *NewIDom) {
198193
applySplitCriticalEdges();
199194
DT->changeImmediateDominator(N, NewIDom);
200195
}
201196

202197
/// eraseNode - Removes a node from the dominator tree. Block must not
203198
/// dominate any other blocks. Removes node from its immediate dominator's
204199
/// children list. Deletes dominator node associated with basic block BB.
205-
inline void eraseNode(MachineBasicBlock *BB) {
200+
void eraseNode(MachineBasicBlock *BB) {
206201
applySplitCriticalEdges();
207202
DT->eraseNode(BB);
208203
}
209204

210205
/// splitBlock - BB is split and now it has one successor. Update dominator
211206
/// tree to reflect this change.
212-
inline void splitBlock(MachineBasicBlock* NewBB) {
207+
void splitBlock(MachineBasicBlock* NewBB) {
213208
applySplitCriticalEdges();
214209
DT->splitBlock(NewBB);
215210
}

llvm/lib/CodeGen/MachineDominators.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,11 @@ void MachineDominatorTree::releaseMemory() {
6464
}
6565

6666
void MachineDominatorTree::verifyAnalysis() const {
67-
if (DT && VerifyMachineDomInfo) {
68-
MachineFunction &F = *getRoot()->getParent();
69-
70-
DomTreeBase<MachineBasicBlock> OtherDT;
71-
OtherDT.recalculate(F);
72-
if (getRootNode()->getBlock() != OtherDT.getRootNode()->getBlock() ||
73-
DT->compare(OtherDT)) {
74-
errs() << "MachineDominatorTree for function " << F.getName()
75-
<< " is not up to date!\nComputed:\n";
76-
DT->print(errs());
77-
errs() << "\nActual:\n";
78-
OtherDT.print(errs());
67+
if (DT && VerifyMachineDomInfo)
68+
if (!DT->verify(DomTreeT::VerificationLevel::Basic)) {
69+
errs() << "MachineDominatorTree verification failed\n";
7970
abort();
8071
}
81-
}
8272
}
8373

8474
void MachineDominatorTree::print(raw_ostream &OS, const Module*) const {

0 commit comments

Comments
 (0)