[llvm] [Support][NFC] Simplify DomTreeNodeBase::addChild (PR #101056)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 11:32:50 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Alexis Engelke (aengelke)

<details>
<summary>Changes</summary>

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).

---
Full diff: https://github.com/llvm/llvm-project/pull/101056.diff


1 Files Affected:

- (modified) llvm/include/llvm/Support/GenericDomTree.h (+7-10) 


``````````diff
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) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/101056


More information about the llvm-commits mailing list