[llvm] r334706 - [TableGen] Move some shared_ptrs to avoid unnecessary copies (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 14 04:56:19 PDT 2018


Author: fhahn
Date: Thu Jun 14 04:56:19 2018
New Revision: 334706

URL: http://llvm.org/viewvc/llvm-project?rev=334706&view=rev
Log:
[TableGen] Move some shared_ptrs to avoid unnecessary copies (NFC).

Those changes were suggested post-commit for D47463.

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=334706&r1=334705&r2=334706&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Thu Jun 14 04:56:19 2018
@@ -1825,7 +1825,7 @@ void TreePatternNode::SubstituteFormalAr
         assert((Child->getPredicateFns().empty() ||
                 NewChild->getPredicateFns() == Child->getPredicateFns()) &&
                "Non-empty child predicate clobbered!");
-        setChild(i, NewChild);
+        setChild(i, std::move(NewChild));
       }
     } else {
       getChild(i)->SubstituteFormalArguments(ArgMap);
@@ -1856,7 +1856,7 @@ TreePatternNodePtr TreePatternNode::Inli
               NewChild->getPredicateFns() == Child->getPredicateFns()) &&
              "Non-empty child predicate clobbered!");
 
-      setChild(i, NewChild);
+      setChild(i, std::move(NewChild));
     }
     return T;
   }
@@ -1883,7 +1883,7 @@ TreePatternNodePtr TreePatternNode::Inli
     // Compute the map of formal to actual arguments.
     std::map<std::string, TreePatternNodePtr> ArgMap;
     for (unsigned i = 0, e = Frag->getNumArgs(); i != e; ++i) {
-      TreePatternNodePtr Child = getChildShared(i);
+      const TreePatternNodePtr &Child = getChildShared(i);
       ArgMap[Frag->getArgName(i)] = Child->InlinePatternFragments(Child, TP);
     }
 
@@ -2673,9 +2673,8 @@ TreePatternNodePtr TreePattern::ParseTre
     else // Otherwise, no chain.
       Operator = getDAGPatterns().get_intrinsic_wo_chain_sdnode();
 
-    TreePatternNodePtr IIDNode =
-        std::make_shared<TreePatternNode>(IntInit::get(IID), 1);
-    Children.insert(Children.begin(), IIDNode);
+    Children.insert(Children.begin(),
+                    std::make_shared<TreePatternNode>(IntInit::get(IID), 1));
   }
 
   if (Operator->isSubClassOf("ComplexPattern")) {
@@ -2736,7 +2735,7 @@ static bool SimplifyTree(TreePatternNode
   for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
     TreePatternNodePtr Child = N->getChildShared(i);
     MadeChange |= SimplifyTree(Child);
-    N->setChild(i, Child);
+    N->setChild(i, std::move(Child));
   }
   return MadeChange;
 }
@@ -3057,7 +3056,7 @@ void CodeGenDAGPatterns::ParseDefaultOpe
                         DefaultOps[i]->getName() +
                         "' doesn't have a concrete type!");
       }
-      DefaultOpInfo.DefaultOps.push_back(TPN);
+      DefaultOpInfo.DefaultOps.push_back(std::move(TPN));
     }
 
     // Insert it into the DefaultOperands map so we can find it later.
@@ -3488,9 +3487,9 @@ const DAGInstruction &CodeGenDAGPatterns
     if (!RNode)
       I->error("Operand $" + OpName + " does not exist in operand list!");
 
-    ResNodes.push_back(RNode);
 
     Record *R = cast<DefInit>(RNode->getLeafValue())->getDef();
+    ResNodes.push_back(std::move(RNode));
     if (!R)
       I->error("Operand $" + OpName + " should be a set destination: all "
                "outputs must occur before inputs in operand list!");
@@ -3555,7 +3554,7 @@ const DAGInstruction &CodeGenDAGPatterns
                                                  OpNode->getNumTypes());
     }
 
-    ResultNodeOperands.push_back(OpNode);
+    ResultNodeOperands.push_back(std::move(OpNode));
   }
 
   if (!InstInputsCheck.empty())
@@ -3744,7 +3743,7 @@ void CodeGenDAGPatterns::AddPatternToMat
         SrcNames[Entry.first].second == 1)
       Pattern->error("Pattern has dead named input: $" + Entry.first);
 
-  PatternsToMatch.push_back(std::move(PTM));
+  PatternsToMatch.push_back(PTM);
 }
 
 void CodeGenDAGPatterns::InferInstructionFlags() {
@@ -4084,9 +4083,10 @@ void CodeGenDAGPatterns::ExpandHwModeBas
     std::vector<Predicate> Preds = P.Predicates;
     const std::vector<Predicate> &MC = ModeChecks[Mode];
     Preds.insert(Preds.end(), MC.begin(), MC.end());
-    PatternsToMatch.emplace_back(P.getSrcRecord(), Preds, NewSrc, NewDst,
-                                 P.getDstRegs(), P.getAddedComplexity(),
-                                 Record::getNewUID(), Mode);
+    PatternsToMatch.emplace_back(P.getSrcRecord(), Preds, std::move(NewSrc),
+                                 std::move(NewDst), P.getDstRegs(),
+                                 P.getAddedComplexity(), Record::getNewUID(),
+                                 Mode);
   };
 
   for (PatternToMatch &P : Copy) {
@@ -4390,18 +4390,18 @@ static void GenerateVariantsOf(TreePatte
       assert(NC >= 3 &&
              "Commutative intrinsic should have at least 3 children!");
       std::vector<std::vector<TreePatternNodePtr>> Variants;
-      Variants.push_back(ChildVariants[0]); // Intrinsic id.
-      Variants.push_back(ChildVariants[2]);
-      Variants.push_back(ChildVariants[1]);
+      Variants.push_back(std::move(ChildVariants[0])); // Intrinsic id.
+      Variants.push_back(std::move(ChildVariants[2]));
+      Variants.push_back(std::move(ChildVariants[1]));
       for (unsigned i = 3; i != NC; ++i)
-        Variants.push_back(ChildVariants[i]);
+        Variants.push_back(std::move(ChildVariants[i]));
       CombineChildVariants(N, Variants, OutVariants, CDP, DepVars);
     } else if (NC == N->getNumChildren()) {
       std::vector<std::vector<TreePatternNodePtr>> Variants;
-      Variants.push_back(ChildVariants[1]);
-      Variants.push_back(ChildVariants[0]);
+      Variants.push_back(std::move(ChildVariants[1]));
+      Variants.push_back(std::move(ChildVariants[0]));
       for (unsigned i = 2; i != NC; ++i)
-        Variants.push_back(ChildVariants[i]);
+        Variants.push_back(std::move(ChildVariants[i]));
       CombineChildVariants(N, Variants, OutVariants, CDP, DepVars);
     }
   }




More information about the llvm-commits mailing list