[llvm] [Support][NFC] Simplify DomTreeNodeBase::addChild (PR #101056)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 11:32:18 PDT 2024
https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/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.
This was added in a72d6ef891707173b when introducing unique_ptr, previosuly this was a source code size optimization.
---
Context: this will simplify replacing DomTreeNodes with a different data structure, see [this RFC](https://discourse.llvm.org/t/rfc-add-auxiliary-field-for-per-pass-custom-data-to-basicblock/80229).
>From 95575db25216a88ae6bd7ce1c5c563e28ee854f8 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Mon, 29 Jul 2024 09:14:39 +0000
Subject: [PATCH] [Support][NFC] Simplify DomTreeNodeBase::addChild
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.
This was added in a72d6ef891707173b when introducing unique_ptr,
previosuly this was a source code size optimization.
---
llvm/include/llvm/Support/GenericDomTree.h | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h
index a8e178d6461e0..5bf4a34eb9770 100644
--- a/llvm/include/llvm/Support/GenericDomTree.h
+++ b/llvm/include/llvm/Support/GenericDomTree.h
@@ -90,11 +90,7 @@ template <class NodeT> class DomTreeNodeBase {
DomTreeNodeBase *getIDom() const { return IDom; }
unsigned getLevel() const { return Level; }
- std::unique_ptr<DomTreeNodeBase> addChild(
- std::unique_ptr<DomTreeNodeBase> C) {
- Children.push_back(C.get());
- return C;
- }
+ void addChild(DomTreeNodeBase *C) { Children.push_back(C); }
bool isLeaf() const { return Children.empty(); }
size_t getNumChildren() const { return Children.size(); }
@@ -655,8 +651,8 @@ class DominatorTreeBase {
} else {
assert(Roots.size() == 1);
NodeT *OldRoot = Roots.front();
- auto &OldNode = DomTreeNodes[OldRoot];
- OldNode = NewNode->addChild(std::move(DomTreeNodes[OldRoot]));
+ DomTreeNodeBase<NodeT> *OldNode = getNode(OldRoot);
+ NewNode->addChild(OldNode);
OldNode->IDom = NewNode;
OldNode->UpdateLevel();
Roots[0] = BB;
@@ -831,9 +827,10 @@ class DominatorTreeBase {
void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
DomTreeNodeBase<NodeT> *createChild(NodeT *BB, DomTreeNodeBase<NodeT> *IDom) {
- return (DomTreeNodes[BB] = IDom->addChild(
- std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDom)))
- .get();
+ auto Node = std::make_unique<DomTreeNodeBase<NodeT>>(BB, IDom);
+ auto *NodePtr = (DomTreeNodes[BB] = std::move(Node)).get();
+ IDom->addChild(NodePtr);
+ return NodePtr;
}
DomTreeNodeBase<NodeT> *createNode(NodeT *BB) {
More information about the llvm-commits
mailing list