[llvm] f0c3dfd - [TableGen] Avoid extra IntrusiveRefCntPtr when calling SimplifyTree. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 16 19:09:41 PDT 2023


Author: Craig Topper
Date: 2023-04-16T18:57:27-07:00
New Revision: f0c3dfdbf1e3921638fa3dda4944fd84e9bb7e45

URL: https://github.com/llvm/llvm-project/commit/f0c3dfdbf1e3921638fa3dda4944fd84e9bb7e45
DIFF: https://github.com/llvm/llvm-project/commit/f0c3dfdbf1e3921638fa3dda4944fd84e9bb7e45.diff

LOG: [TableGen] Avoid extra IntrusiveRefCntPtr when calling SimplifyTree. NFC

Add a helper to get modifiable access to the IntrusiveRefCntPtr
stored in the Children array. This avoids copying and overwriting the child.

Added: 
    

Modified: 
    llvm/utils/TableGen/CodeGenDAGPatterns.cpp
    llvm/utils/TableGen/CodeGenDAGPatterns.h

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 93e9ea1221752..d8ec427b2f353 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -3058,11 +3058,9 @@ static bool SimplifyTree(TreePatternNodePtr &N) {
 
   // Walk all children.
   bool MadeChange = false;
-  for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
-    TreePatternNodePtr Child = N->getChildShared(i);
-    MadeChange |= SimplifyTree(Child);
-    N->setChild(i, std::move(Child));
-  }
+  for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
+    MadeChange |= SimplifyTree(N->getChildSharedPtr(i));
+
   return MadeChange;
 }
 

diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h
index e04a0873521c7..0dd99a4a51faa 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h
@@ -727,6 +727,9 @@ class TreePatternNode : public RefCountedBase<TreePatternNode> {
   const TreePatternNodePtr &getChildShared(unsigned N) const {
     return Children[N];
   }
+  TreePatternNodePtr &getChildSharedPtr(unsigned N) {
+    return Children[N];
+  }
   void setChild(unsigned i, TreePatternNodePtr N) { Children[i] = N; }
 
   /// hasChild - Return true if N is any of our children.


        


More information about the llvm-commits mailing list