[llvm] r222948 - Make RecordKeeper::addClass/addDef take unique_ptrs instead of creating one internally.

Craig Topper craig.topper at gmail.com
Fri Nov 28 21:52:51 PST 2014


Author: ctopper
Date: Fri Nov 28 23:52:51 2014
New Revision: 222948

URL: http://llvm.org/viewvc/llvm-project?rev=222948&view=rev
Log:
Make RecordKeeper::addClass/addDef take unique_ptrs instead of creating one internally.

Modified:
    llvm/trunk/include/llvm/TableGen/Record.h
    llvm/trunk/lib/TableGen/TGParser.cpp

Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=222948&r1=222947&r2=222948&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Fri Nov 28 23:52:51 2014
@@ -1688,15 +1688,13 @@ public:
     auto I = Defs.find(Name);
     return I == Defs.end() ? nullptr : I->second.get();
   }
-  void addClass(Record *_R) {
-    std::unique_ptr<Record> R(_R);
+  void addClass(std::unique_ptr<Record> R) {
     bool Ins = Classes.insert(std::make_pair(R->getName(),
                                              std::move(R))).second;
     (void)Ins;
     assert(Ins && "Class already exists");
   }
-  void addDef(Record *_R) {
-    std::unique_ptr<Record> R(_R);
+  void addDef(std::unique_ptr<Record> R) {
     bool Ins = Defs.insert(std::make_pair(R->getName(),
                                           std::move(R))).second;
     (void)Ins;

Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=222948&r1=222947&r2=222948&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Fri Nov 28 23:52:51 2014
@@ -371,7 +371,7 @@ bool TGParser::ProcessForeachDefs(Record
   }
 
   Record *IterRecSave = IterRec.get(); // Keep a copy before release.
-  Records.addDef(IterRec.release());
+  Records.addDef(std::move(IterRec));
   IterRecSave->resolveReferences();
   return false;
 }
@@ -1252,7 +1252,7 @@ Init *TGParser::ParseSimpleValue(Record
 
     if (!CurMultiClass) {
       NewRec->resolveReferences();
-      Records.addDef(NewRecOwner.release());
+      Records.addDef(std::move(NewRecOwner));
     } else {
       // This needs to get resolved once the multiclass template arguments are
       // known before any use.
@@ -2044,7 +2044,7 @@ bool TGParser::ParseDef(MultiClass *CurM
     if (Records.getDef(CurRec->getNameInitAsString()))
       return Error(DefLoc, "def '" + CurRec->getNameInitAsString()+
                    "' already defined");
-    Records.addDef(CurRecOwner.release());
+    Records.addDef(std::move(CurRecOwner));
 
     if (ParseObjectBody(CurRec))
       return true;
@@ -2169,8 +2169,10 @@ bool TGParser::ParseClass() {
                       + "' already defined");
   } else {
     // If this is the first reference to this class, create and add it.
-    CurRec = new Record(Lex.getCurStrVal(), Lex.getLoc(), Records);
-    Records.addClass(CurRec);
+    auto NewRec = make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(),
+                                      Records);
+    CurRec = NewRec.get();
+    Records.addClass(std::move(NewRec));
   }
   Lex.Lex(); // eat the name.
 
@@ -2442,7 +2444,7 @@ InstantiateMulticlassDef(MultiClass &MC,
     }
 
     Record *CurRecSave = CurRec.get(); // Keep a copy before we release.
-    Records.addDef(CurRec.release());
+    Records.addDef(std::move(CurRec));
     return CurRecSave;
   }
 





More information about the llvm-commits mailing list