diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h index 407a06043cbaf5..10e591a69d369b 100644 --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/include/llvm/Support/GenericDomTree.h @@ -590,8 +590,7 @@ class DominatorTreeBase { DomTreeNodeBase *IDomNode = getNode(DomBB); assert(IDomNode && "Not immediate dominator specified for block!"); DFSInfoValid = false; - return (DomTreeNodes[BB] = IDomNode->addChild( - std::make_unique>(BB, IDomNode))).get(); + return createChild(BB, IDomNode); } /// Add a new node to the forward dominator tree and make it a new root. @@ -604,8 +603,7 @@ class DominatorTreeBase { assert(!this->isPostDominator() && "Cannot change root of post-dominator tree"); DFSInfoValid = false; - DomTreeNodeBase *NewNode = (DomTreeNodes[BB] = - std::make_unique>(BB, nullptr)).get(); + DomTreeNodeBase *NewNode = createNode(BB); if (Roots.empty()) { addRoot(BB); } else { @@ -786,6 +784,18 @@ class DominatorTreeBase { protected: void addRoot(NodeT *BB) { this->Roots.push_back(BB); } + DomTreeNodeBase *createChild(NodeT *BB, DomTreeNodeBase *IDom) { + return (DomTreeNodes[BB] = IDom->addChild( + std::make_unique>(BB, IDom))) + .get(); + } + + DomTreeNodeBase *createNode(NodeT *BB) { + return (DomTreeNodes[BB] = + std::make_unique>(BB, nullptr)) + .get(); + } + // NewBB is split and now it has one successor. Update dominator tree to // reflect this change. template diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h index bde59ff8c276fa..464de4e2b3ba1b 100644 --- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h +++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h @@ -187,9 +187,7 @@ struct SemiNCAInfo { // Add a new tree node for this NodeT, and link it as a child of // IDomNode - return (DT.DomTreeNodes[BB] = IDomNode->addChild( - std::make_unique>(BB, IDomNode))) - .get(); + return DT.createChild(BB, IDomNode); } static bool AlwaysDescend(NodePtr, NodePtr) { return true; } @@ -587,9 +585,7 @@ struct SemiNCAInfo { // all real exits (including multiple exit blocks, infinite loops). NodePtr Root = IsPostDom ? nullptr : DT.Roots[0]; - DT.RootNode = (DT.DomTreeNodes[Root] = - std::make_unique>(Root, nullptr)) - .get(); + DT.RootNode = DT.createNode(Root); SNCA.attachNewSubtree(DT, DT.RootNode); } @@ -610,8 +606,7 @@ struct SemiNCAInfo { // Add a new tree node for this BasicBlock, and link it as a child of // IDomNode. - DT.DomTreeNodes[W] = IDomNode->addChild( - std::make_unique>(W, IDomNode)); + DT.createChild(W, IDomNode); } } @@ -661,10 +656,7 @@ struct SemiNCAInfo { // The unreachable node becomes a new root -- a tree node for it. TreeNodePtr VirtualRoot = DT.getNode(nullptr); - FromTN = - (DT.DomTreeNodes[From] = VirtualRoot->addChild( - std::make_unique>(From, VirtualRoot))) - .get(); + FromTN = DT.createChild(From, VirtualRoot); DT.Roots.push_back(From); }