Skip to content

Commit f6a928a

Browse files
authored
[Support][NFC] Simplify DomTreeNodeBase::addChild (llvm#101056)
Previously, the method would take the unique_ptr, store the pointer in its Children vector, and then return the unique_ptr. Pass the raw pointer as parameter instead. Also merge createChild and createNode to avoid code duplication. This was added in a72d6ef when introducing unique_ptr, previously this was a source code size optimization.
1 parent 933b800 commit f6a928a

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ template <class NodeT> class DomTreeNodeBase {
9090
DomTreeNodeBase *getIDom() const { return IDom; }
9191
unsigned getLevel() const { return Level; }
9292

93-
std::unique_ptr<DomTreeNodeBase> addChild(
94-
std::unique_ptr<DomTreeNodeBase> C) {
95-
Children.push_back(C.get());
96-
return C;
97-
}
93+
void addChild(DomTreeNodeBase *C) { Children.push_back(C); }
9894

9995
bool isLeaf() const { return Children.empty(); }
10096
size_t getNumChildren() const { return Children.size(); }
@@ -636,7 +632,7 @@ class DominatorTreeBase {
636632
DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB);
637633
assert(IDomNode && "Not immediate dominator specified for block!");
638634
DFSInfoValid = false;
639-
return createChild(BB, IDomNode);
635+
return createNode(BB, IDomNode);
640636
}
641637

642638
/// Add a new node to the forward dominator tree and make it a new root.
@@ -655,8 +651,8 @@ class DominatorTreeBase {
655651
} else {
656652
assert(Roots.size() == 1);
657653
NodeT *OldRoot = Roots.front();
658-
auto &OldNode = DomTreeNodes[OldRoot];
659-
OldNode = NewNode->addChild(std::move(DomTreeNodes[OldRoot]));
654+
DomTreeNodeBase<NodeT> *OldNode = getNode(OldRoot);
655+
NewNode->addChild(OldNode);
660656
OldNode->IDom = NewNode;
661657
OldNode->UpdateLevel();
662658
Roots[0] = BB;
@@ -831,16 +827,14 @@ class DominatorTreeBase {
831827
protected:
832828
void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
833829

834-
DomTreeNodeBase<NodeT> *createChild(NodeT *BB, DomTreeNodeBase<NodeT> *IDom) {
835-
return (DomTreeNodes[BB] = IDom->addChild(
836-
std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDom)))
837-
.get();
838-
}
839-
840-
DomTreeNodeBase<NodeT> *createNode(NodeT *BB) {
841-
return (DomTreeNodes[BB] =
842-
std::make_unique<DomTreeNodeBase<NodeT>>(BB, nullptr))
843-
.get();
830+
DomTreeNodeBase<NodeT> *createNode(NodeT *BB,
831+
DomTreeNodeBase<NodeT> *IDom = nullptr) {
832+
auto Node = std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDom);
833+
auto *NodePtr = Node.get();
834+
DomTreeNodes[BB] = std::move(Node);
835+
if (IDom)
836+
IDom->addChild(NodePtr);
837+
return NodePtr;
844838
}
845839

846840
// NewBB is split and now it has one successor. Update dominator tree to

llvm/include/llvm/Support/GenericDomTreeConstruction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct SemiNCAInfo {
142142

143143
// Add a new tree node for this NodeT, and link it as a child of
144144
// IDomNode
145-
return DT.createChild(BB, IDomNode);
145+
return DT.createNode(BB, IDomNode);
146146
}
147147

148148
static bool AlwaysDescend(NodePtr, NodePtr) { return true; }
@@ -595,7 +595,7 @@ struct SemiNCAInfo {
595595

596596
// Add a new tree node for this BasicBlock, and link it as a child of
597597
// IDomNode.
598-
DT.createChild(W, IDomNode);
598+
DT.createNode(W, IDomNode);
599599
}
600600
}
601601

@@ -644,7 +644,7 @@ struct SemiNCAInfo {
644644

645645
// The unreachable node becomes a new root -- a tree node for it.
646646
TreeNodePtr VirtualRoot = DT.getNode(nullptr);
647-
FromTN = DT.createChild(From, VirtualRoot);
647+
FromTN = DT.createNode(From, VirtualRoot);
648648
DT.Roots.push_back(From);
649649
}
650650

0 commit comments

Comments
 (0)