OSDN Git Service

[TableGen] Hoist the code for copying InstRWs from an old scheduling class to a new...
authorCraig Topper <craig.topper@intel.com>
Wed, 21 Mar 2018 19:52:13 +0000 (19:52 +0000)
committerCraig Topper <craig.topper@intel.com>
Wed, 21 Mar 2018 19:52:13 +0000 (19:52 +0000)
We already know all the of instructions we're processing in the instruction loop belong to no class or all to the same class. So we only have to worry about remapping one class. So hoist it all out and remove the SmallPtrSet that tracked which class we'd already remapped.

I had to introduce new instruction loop inside this code to print an error message, but that only occurs on the error path.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328142 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CodeGenSchedule.cpp

index 446a641..a21e44b 100644 (file)
@@ -800,25 +800,25 @@ void CodeGenSchedModels::createInstRWClass(Record *InstRWDef) {
     SC.Writes = SchedClasses[OldSCIdx].Writes;
     SC.Reads = SchedClasses[OldSCIdx].Reads;
     SC.ProcIndices.push_back(0);
-    // Map each Instr to this new class.
-    // Note that InstDefs may be a smaller list than InstRWDef's "Instrs".
-    Record *RWModelDef = InstRWDef->getValueAsDef("SchedModel");
-    SmallSet<unsigned, 4> RemappedClassIDs;
-    for (Record *InstDef : InstDefs) {
-      if (OldSCIdx && RemappedClassIDs.insert(OldSCIdx).second) {
-        for (Record *OldRWDef : SchedClasses[OldSCIdx].InstRWs) {
-          if (OldRWDef->getValueAsDef("SchedModel") == RWModelDef) {
+    // If we had an old class, copy it's InstRWs to this new class.
+    if (OldSCIdx) {
+      Record *RWModelDef = InstRWDef->getValueAsDef("SchedModel");
+      for (Record *OldRWDef : SchedClasses[OldSCIdx].InstRWs) {
+        if (OldRWDef->getValueAsDef("SchedModel") == RWModelDef) {
+          for (Record *InstDef : InstDefs) {
             PrintFatalError(OldRWDef->getLoc(), "Overlapping InstRW def " +
                        InstDef->getName() + " also matches " +
                        OldRWDef->getValue("Instrs")->getValue()->getAsString());
           }
-          assert(OldRWDef != InstRWDef &&
-                 "SchedClass has duplicate InstRW def");
-          SC.InstRWs.push_back(OldRWDef);
         }
+        assert(OldRWDef != InstRWDef &&
+               "SchedClass has duplicate InstRW def");
+        SC.InstRWs.push_back(OldRWDef);
       }
-      InstrClassMap[InstDef] = SCIdx;
     }
+    // Map each Instr to this new class.
+    for (Record *InstDef : InstDefs)
+      InstrClassMap[InstDef] = SCIdx;
     SC.InstRWs.push_back(InstRWDef);
   }
 }