[TableGen] Avoid a couple vector copies in ExpandHwModeBasedTypes.
authorCraig Topper <craig.topper@sifive.com>
Sat, 30 Jan 2021 20:19:14 +0000 (12:19 -0800)
committerCraig Topper <craig.topper@sifive.com>
Sat, 30 Jan 2021 21:16:39 +0000 (13:16 -0800)
Use vector::swap instead of copying to a local vector and clearing
the original. We can just swap into the just created local vector
instead which will move the pointers and not the data.

Use std::move in another place to avoid a copy.

llvm/utils/TableGen/CodeGenDAGPatterns.cpp

index 1ca4a68..d4409db 100644 (file)
@@ -4282,8 +4282,8 @@ static void collectModes(std::set<unsigned> &Modes, const TreePatternNode *N) {
 void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
   const CodeGenHwModes &CGH = getTargetInfo().getHwModes();
   std::map<unsigned,std::vector<Predicate>> ModeChecks;
-  std::vector<PatternToMatch> Copy = PatternsToMatch;
-  PatternsToMatch.clear();
+  std::vector<PatternToMatch> Copy;
+  PatternsToMatch.swap(Copy);
 
   auto AppendPattern = [this, &ModeChecks](PatternToMatch &P, unsigned Mode) {
     TreePatternNodePtr NewSrc = P.SrcPattern->clone();
@@ -4295,8 +4295,9 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
     std::vector<Predicate> Preds = P.Predicates;
     const std::vector<Predicate> &MC = ModeChecks[Mode];
     llvm::append_range(Preds, MC);
-    PatternsToMatch.emplace_back(P.getSrcRecord(), Preds, std::move(NewSrc),
-                                 std::move(NewDst), P.getDstRegs(),
+    PatternsToMatch.emplace_back(P.getSrcRecord(), std::move(Preds),
+                                 std::move(NewSrc), std::move(NewDst),
+                                 P.getDstRegs(),
                                  P.getAddedComplexity(), Record::getNewUID(),
                                  Mode);
   };