[llvm] r328142 - [TableGen] Hoist the code for copying InstRWs from an old scheduling class to a new one out of the loop that assigns instructions to the new class. NFCI

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 21 12:52:13 PDT 2018


Author: ctopper
Date: Wed Mar 21 12:52:13 2018
New Revision: 328142

URL: http://llvm.org/viewvc/llvm-project?rev=328142&view=rev
Log:
[TableGen] Hoist the code for copying InstRWs from an old scheduling class to a new one out of the loop that assigns instructions to the new class. NFCI

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.

Modified:
    llvm/trunk/utils/TableGen/CodeGenSchedule.cpp

Modified: llvm/trunk/utils/TableGen/CodeGenSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenSchedule.cpp?rev=328142&r1=328141&r2=328142&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenSchedule.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenSchedule.cpp Wed Mar 21 12:52:13 2018
@@ -800,25 +800,25 @@ void CodeGenSchedModels::createInstRWCla
     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);
   }
 }




More information about the llvm-commits mailing list