[llvm] r253834 - Further simplify from r253832 with some unique_ptr and coalescing conditions

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 22 12:11:21 PST 2015


Author: dblaikie
Date: Sun Nov 22 14:11:21 2015
New Revision: 253834

URL: http://llvm.org/viewvc/llvm-project?rev=253834&view=rev
Log:
Further simplify from r253832 with some unique_ptr and coalescing conditions

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

Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=253834&r1=253833&r2=253834&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Sun Nov 22 14:11:21 2015
@@ -3523,8 +3523,8 @@ static void CombineChildVariants(TreePat
     std::vector<TreePatternNode*> NewChildren;
     for (unsigned i = 0, e = ChildVariants.size(); i != e; ++i)
       NewChildren.push_back(ChildVariants[i][Idxs[i]]);
-    TreePatternNode *R = new TreePatternNode(Orig->getOperator(), NewChildren,
-                                             Orig->getNumTypes());
+    auto R = llvm::make_unique<TreePatternNode>(
+        Orig->getOperator(), NewChildren, Orig->getNumTypes());
 
     // Copy over properties.
     R->setName(Orig->getName());
@@ -3535,21 +3535,16 @@ static void CombineChildVariants(TreePat
 
     // If this pattern cannot match, do not include it as a variant.
     std::string ErrString;
-    if (!R->canPatternMatch(ErrString, CDP)) {
-      delete R;
-    } else {
-      // Scan to see if this pattern has already been emitted.  We can get
-      // duplication due to things like commuting:
-      //   (and GPRC:$a, GPRC:$b) -> (and GPRC:$b, GPRC:$a)
-      // which are the same pattern.  Ignore the dups.
-      if (std::any_of(OutVariants.begin(), OutVariants.end(),
-                      [=](TreePatternNode *Variant) {
-                        return R->isIsomorphicTo(Variant, DepVars);
-                      }))
-        delete R;
-      else
-        OutVariants.push_back(R);
-    }
+    // Scan to see if this pattern has already been emitted.  We can get
+    // duplication due to things like commuting:
+    //   (and GPRC:$a, GPRC:$b) -> (and GPRC:$b, GPRC:$a)
+    // which are the same pattern.  Ignore the dups.
+    if (R->canPatternMatch(ErrString, CDP) &&
+        std::none_of(OutVariants.begin(), OutVariants.end(),
+                     [&](TreePatternNode *Variant) {
+                       return R->isIsomorphicTo(Variant, DepVars);
+                     }))
+      OutVariants.push_back(R.release());
 
     // Increment indices to the next permutation by incrementing the
     // indices from last index backward, e.g., generate the sequence




More information about the llvm-commits mailing list