[llvm] r216350 - TableGen: unique_ptr-ify RecordKeeper

Dylan Noblesmith nobled at dreamwidth.org
Sun Aug 24 12:10:58 PDT 2014


Author: nobled
Date: Sun Aug 24 14:10:57 2014
New Revision: 216350

URL: http://llvm.org/viewvc/llvm-project?rev=216350&view=rev
Log:
TableGen: unique_ptr-ify RecordKeeper

Modified:
    llvm/trunk/include/llvm/TableGen/Record.h
    llvm/trunk/lib/TableGen/Record.cpp
    llvm/trunk/utils/TableGen/CTagsEmitter.cpp
    llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp

Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=216350&r1=216349&r2=216350&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Sun Aug 24 14:10:57 2014
@@ -1650,36 +1650,32 @@ struct MultiClass {
 };
 
 class RecordKeeper {
-  std::map<std::string, Record*> Classes, Defs;
+  typedef std::map<std::string, std::unique_ptr<Record>> RecordMap;
+  RecordMap Classes, Defs;
 
 public:
-  ~RecordKeeper() {
-    for (std::map<std::string, Record*>::iterator I = Classes.begin(),
-           E = Classes.end(); I != E; ++I)
-      delete I->second;
-    for (std::map<std::string, Record*>::iterator I = Defs.begin(),
-           E = Defs.end(); I != E; ++I)
-      delete I->second;
-  }
-
-  const std::map<std::string, Record*> &getClasses() const { return Classes; }
-  const std::map<std::string, Record*> &getDefs() const { return Defs; }
+  const RecordMap &getClasses() const { return Classes; }
+  const RecordMap &getDefs() const { return Defs; }
 
   Record *getClass(const std::string &Name) const {
-    std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
-    return I == Classes.end() ? nullptr : I->second;
+    auto I = Classes.find(Name);
+    return I == Classes.end() ? nullptr : I->second.get();
   }
   Record *getDef(const std::string &Name) const {
-    std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
-    return I == Defs.end() ? nullptr : I->second;
+    auto I = Defs.find(Name);
+    return I == Defs.end() ? nullptr : I->second.get();
   }
-  void addClass(Record *R) {
-    bool Ins = Classes.insert(std::make_pair(R->getName(), R)).second;
+  void addClass(Record *_R) {
+    std::unique_ptr<Record> R(_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) {
-    bool Ins = Defs.insert(std::make_pair(R->getName(), R)).second;
+  void addDef(Record *_R) {
+    std::unique_ptr<Record> R(_R);
+    bool Ins = Defs.insert(std::make_pair(R->getName(),
+                                          std::move(R))).second;
     (void)Ins;
     assert(Ins && "Record already exists");
   }

Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=216350&r1=216349&r2=216350&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Sun Aug 24 14:10:57 2014
@@ -2031,7 +2031,7 @@ RecordKeeper::getAllDerivedDefinitions(c
   std::vector<Record*> Defs;
   for (const auto &D : getDefs())
     if (D.second->isSubClassOf(Class))
-      Defs.push_back(D.second);
+      Defs.push_back(D.second.get());
 
   return Defs;
 }

Modified: llvm/trunk/utils/TableGen/CTagsEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CTagsEmitter.cpp?rev=216350&r1=216349&r2=216350&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CTagsEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/CTagsEmitter.cpp Sun Aug 24 14:10:57 2014
@@ -75,9 +75,9 @@ void CTagsEmitter::run(raw_ostream &OS)
   // Collect tags.
   Tags.reserve(Classes.size() + Defs.size());
   for (const auto &C : Classes)
-    Tags.push_back(Tag(C.first, locate(C.second)));
+    Tags.push_back(Tag(C.first, locate(C.second.get())));
   for (const auto &D : Defs)
-    Tags.push_back(Tag(D.first, locate(D.second)));
+    Tags.push_back(Tag(D.first, locate(D.second.get())));
   // Emit tags.
   std::sort(Tags.begin(), Tags.end());
   OS << "!_TAG_FILE_FORMAT\t1\t/original ctags format/\n";

Modified: llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp?rev=216350&r1=216349&r2=216350&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/PseudoLoweringEmitter.cpp Sun Aug 24 14:10:57 2014
@@ -280,7 +280,7 @@ void PseudoLoweringEmitter::run(raw_ostr
   for (const auto &D : Records.getDefs()) {
     if (D.second->isSubClassOf(ExpansionClass) &&
         D.second->isSubClassOf(InstructionClass))
-      Insts.push_back(D.second);
+      Insts.push_back(D.second.get());
   }
 
   // Process the pseudo expansion definitions, validating them as we do so.





More information about the llvm-commits mailing list