Skip to content

Commit c4bbce7

Browse files
committedJun 29, 2017
[Dominators] Rearrange access specifiers in DominatorTreeBase
Summary: This patch makes DominatorTreeBase more readable by putting most important members on top of the class. Before, the class looked like that: private -> protected (including data members) -> public -> protected. The patch changes it to: protected (data members only) -> public -> protected -> public. Reviewers: dberlin, sanjoy, chandlerc Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34527 llvm-svn: 306714
1 parent 35fca34 commit c4bbce7

File tree

1 file changed

+94
-98
lines changed

1 file changed

+94
-98
lines changed
 

‎llvm/include/llvm/Support/GenericDomTree.h

+94-98
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,7 @@ bool Verify(const DominatorTreeBaseByGraphTraits<GraphTraits<N>> &DT);
185185
/// This class is a generic template over graph nodes. It is instantiated for
186186
/// various graphs in the LLVM IR or in the code generator.
187187
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:
210189
std::vector<NodeT *> Roots;
211190
bool IsPostDominators;
212191

@@ -218,73 +197,10 @@ template <class NodeT> class DominatorTreeBase {
218197
mutable bool DFSInfoValid = false;
219198
mutable unsigned int SlowQueries = 0;
220199

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>;
286202

287-
public:
203+
public:
288204
explicit DominatorTreeBase(bool isPostDom) : IsPostDominators(isPostDom) {}
289205

290206
DominatorTreeBase(DominatorTreeBase &&Arg)
@@ -633,16 +549,6 @@ template <class NodeT> class DominatorTreeBase {
633549
if (getRootNode()) PrintDomTree<NodeT>(getRootNode(), O, 1);
634550
}
635551

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-
646552
public:
647553
/// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
648554
/// dominator tree in dfs order.
@@ -721,6 +627,96 @@ template <class NodeT> class DominatorTreeBase {
721627
? DomTreeBuilder::Verify<Inverse<NodeT *>>(*this)
722628
: DomTreeBuilder::Verify<NodeT *>(*this);
723629
}
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+
}
724720
};
725721

726722
// These two functions are declared out of line as a workaround for building

0 commit comments

Comments
 (0)
Please sign in to comment.