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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 12:07:06 PDT 2024


================
@@ -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;
----------------
nikic wrote:

Can we do something like this?
```suggestion
    auto *NodePtr = Node.get();
    DomTreeNodes[BB] = std::move(Node);
    return NodePtr;
```
Really not a fan of this "using return value of move assignment operator" pattern...

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


More information about the llvm-commits mailing list