Skip to content

Commit f987ba3

Browse files
committed
DomTree: add private create{Child,Node} helpers
Summary: Aside from unifying the code a bit, this change smooths the transition to use of future "opaque generic block references" in the type-erased dominator tree base class. Change-Id: If924b092cc8561c4b6a7450fe79bc96df0e12472 Reviewers: arsenm, RKSimon, mehdi_amini, courbet Subscribers: wdng, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83086
1 parent dfcc68c commit f987ba3

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,7 @@ class DominatorTreeBase {
590590
DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB);
591591
assert(IDomNode && "Not immediate dominator specified for block!");
592592
DFSInfoValid = false;
593-
return (DomTreeNodes[BB] = IDomNode->addChild(
594-
std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
593+
return createChild(BB, IDomNode);
595594
}
596595

597596
/// Add a new node to the forward dominator tree and make it a new root.
@@ -604,8 +603,7 @@ class DominatorTreeBase {
604603
assert(!this->isPostDominator() &&
605604
"Cannot change root of post-dominator tree");
606605
DFSInfoValid = false;
607-
DomTreeNodeBase<NodeT> *NewNode = (DomTreeNodes[BB] =
608-
std::make_unique<DomTreeNodeBase<NodeT>>(BB, nullptr)).get();
606+
DomTreeNodeBase<NodeT> *NewNode = createNode(BB);
609607
if (Roots.empty()) {
610608
addRoot(BB);
611609
} else {
@@ -786,6 +784,18 @@ class DominatorTreeBase {
786784
protected:
787785
void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
788786

787+
DomTreeNodeBase<NodeT> *createChild(NodeT *BB, DomTreeNodeBase<NodeT> *IDom) {
788+
return (DomTreeNodes[BB] = IDom->addChild(
789+
std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDom)))
790+
.get();
791+
}
792+
793+
DomTreeNodeBase<NodeT> *createNode(NodeT *BB) {
794+
return (DomTreeNodes[BB] =
795+
std::make_unique<DomTreeNodeBase<NodeT>>(BB, nullptr))
796+
.get();
797+
}
798+
789799
// NewBB is split and now it has one successor. Update dominator tree to
790800
// reflect this change.
791801
template <class N>

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ struct SemiNCAInfo {
187187

188188
// Add a new tree node for this NodeT, and link it as a child of
189189
// IDomNode
190-
return (DT.DomTreeNodes[BB] = IDomNode->addChild(
191-
std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode)))
192-
.get();
190+
return DT.createChild(BB, IDomNode);
193191
}
194192

195193
static bool AlwaysDescend(NodePtr, NodePtr) { return true; }
@@ -587,9 +585,7 @@ struct SemiNCAInfo {
587585
// all real exits (including multiple exit blocks, infinite loops).
588586
NodePtr Root = IsPostDom ? nullptr : DT.Roots[0];
589587

590-
DT.RootNode = (DT.DomTreeNodes[Root] =
591-
std::make_unique<DomTreeNodeBase<NodeT>>(Root, nullptr))
592-
.get();
588+
DT.RootNode = DT.createNode(Root);
593589
SNCA.attachNewSubtree(DT, DT.RootNode);
594590
}
595591

@@ -610,8 +606,7 @@ struct SemiNCAInfo {
610606

611607
// Add a new tree node for this BasicBlock, and link it as a child of
612608
// IDomNode.
613-
DT.DomTreeNodes[W] = IDomNode->addChild(
614-
std::make_unique<DomTreeNodeBase<NodeT>>(W, IDomNode));
609+
DT.createChild(W, IDomNode);
615610
}
616611
}
617612

@@ -661,10 +656,7 @@ struct SemiNCAInfo {
661656

662657
// The unreachable node becomes a new root -- a tree node for it.
663658
TreeNodePtr VirtualRoot = DT.getNode(nullptr);
664-
FromTN =
665-
(DT.DomTreeNodes[From] = VirtualRoot->addChild(
666-
std::make_unique<DomTreeNodeBase<NodeT>>(From, VirtualRoot)))
667-
.get();
659+
FromTN = DT.createChild(From, VirtualRoot);
668660
DT.Roots.push_back(From);
669661
}
670662

0 commit comments

Comments
 (0)