@@ -106,7 +106,7 @@ class SubtargetEmitter {
106106 void emitStageAndOperandCycleData (
107107 raw_ostream &OS, std::vector<std::vector<InstrItinerary>> &ProcItinLists);
108108 void emitItineraries (raw_ostream &OS,
109- std::vector <std::vector<InstrItinerary>> & ProcItinLists);
109+ ArrayRef <std::vector<InstrItinerary>> ProcItinLists);
110110 unsigned emitRegisterFileTables (const CodeGenProcModel &ProcModel,
111111 raw_ostream &OS);
112112 void emitLoadStoreQueueInfo (const CodeGenProcModel &ProcModel,
@@ -477,7 +477,6 @@ void SubtargetEmitter::emitStageAndOperandCycleData(
477477
478478 // Emit functional units for all the itineraries.
479479 for (const CodeGenProcModel &ProcModel : SchedModels.procModels ()) {
480-
481480 if (!ItinsDefSet.insert (ProcModel.ItinsDef ).second )
482481 continue ;
483482
@@ -489,25 +488,23 @@ void SubtargetEmitter::emitStageAndOperandCycleData(
489488 OS << " \n // Functional units for \" " << Name << " \"\n "
490489 << " namespace " << Name << " FU {\n " ;
491490
492- for (unsigned J = 0 , FUN = FUs. size (); J < FUN; ++J )
493- OS << " const InstrStage::FuncUnits " << FUs[J] ->getName ()
494- << " = 1ULL << " << J << " ;\n " ;
491+ for (const auto &[Idx, FU] : enumerate(FUs) )
492+ OS << " const InstrStage::FuncUnits " << FU ->getName () << " = 1ULL << "
493+ << Idx << " ;\n " ;
495494
496495 OS << " } // end namespace " << Name << " FU\n " ;
497496
498497 ConstRecVec BPs = ProcModel.ItinsDef ->getValueAsListOfDefs (" BP" );
499- if (! BPs.empty ()) {
500- OS << " \n // Pipeline forwarding paths for itineraries \" " << Name
501- << " \"\n "
502- << " namespace " << Name << " Bypass {\n " ;
498+ if (BPs.empty ())
499+ continue ;
500+ OS << " \n // Pipeline forwarding paths for itineraries \" " << Name << " \"\n "
501+ << " namespace " << Name << " Bypass {\n " ;
503502
504- OS << " const unsigned NoBypass = 0;\n " ;
505- for (unsigned J = 0 , BPN = BPs.size (); J < BPN; ++J)
506- OS << " const unsigned " << BPs[J]->getName () << " = 1 << " << J
507- << " ;\n " ;
503+ OS << " const unsigned NoBypass = 0;\n " ;
504+ for (const auto &[Idx, BP] : enumerate(BPs))
505+ OS << " const unsigned " << BP->getName () << " = 1 << " << Idx << " ;\n " ;
508506
509- OS << " } // end namespace " << Name << " Bypass\n " ;
510- }
507+ OS << " } // end namespace " << Name << " Bypass\n " ;
511508 }
512509
513510 // Begin stages table
@@ -647,46 +644,36 @@ void SubtargetEmitter::emitStageAndOperandCycleData(
647644// CodeGenSchedClass::Index.
648645//
649646void SubtargetEmitter::emitItineraries (
650- raw_ostream &OS, std::vector <std::vector<InstrItinerary>> & ProcItinLists) {
647+ raw_ostream &OS, ArrayRef <std::vector<InstrItinerary>> ProcItinLists) {
651648 // Multiple processor models may share an itinerary record. Emit it once.
652649 SmallPtrSet<const Record *, 8 > ItinsDefSet;
653650
654- // For each processor's machine model
655- std::vector<std::vector<InstrItinerary>>::iterator ProcItinListsIter =
656- ProcItinLists.begin ();
657- for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin (),
658- PE = SchedModels.procModelEnd ();
659- PI != PE; ++PI, ++ProcItinListsIter) {
660-
661- const Record *ItinsDef = PI->ItinsDef ;
651+ for (const auto &[Proc, ItinList] :
652+ zip_equal (SchedModels.procModels (), ProcItinLists)) {
653+ const Record *ItinsDef = Proc.ItinsDef ;
662654 if (!ItinsDefSet.insert (ItinsDef).second )
663655 continue ;
664656
665- // Get the itinerary list for the processor.
666- assert (ProcItinListsIter != ProcItinLists.end () && " bad iterator" );
667- std::vector<InstrItinerary> &ItinList = *ProcItinListsIter;
668-
669657 // Empty itineraries aren't referenced anywhere in the tablegen output
670658 // so don't emit them.
671659 if (ItinList.empty ())
672660 continue ;
673661
674- OS << " \n " ;
675- OS << " static const llvm::InstrItinerary " ;
676-
677662 // Begin processor itinerary table
678- OS << ItinsDef->getName () << " [] = {\n " ;
663+ OS << " \n " ;
664+ OS << " static constexpr llvm::InstrItinerary " << ItinsDef->getName ()
665+ << " [] = {\n " ;
679666
680667 // For each itinerary class in CodeGenSchedClass::Index order.
681- for (unsigned J = 0 , M = ItinList.size (); J < M; ++J) {
682- InstrItinerary &Intinerary = ItinList[J];
683-
668+ for (const auto &[Idx, Intinerary, SchedClass] :
669+ enumerate(ItinList, SchedModels.schedClasses ())) {
684670 // Emit Itinerary in the form of
685- // { firstStage, lastStage, firstCycle, lastCycle } // index
671+ // { NumMicroOps, FirstStage, LastStage, FirstOperandCycle,
672+ // LastOperandCycle } // index class name
686673 OS << " { " << Intinerary.NumMicroOps << " , " << Intinerary.FirstStage
687674 << " , " << Intinerary.LastStage << " , " << Intinerary.FirstOperandCycle
688- << " , " << Intinerary.LastOperandCycle << " }"
689- << " , // " << J << " " << SchedModels. getSchedClass (J) .Name << " \n " ;
675+ << " , " << Intinerary.LastOperandCycle << " }" << " , // " << Idx << " "
676+ << SchedClass .Name << " \n " ;
690677 }
691678 // End processor itinerary table
692679 OS << " { 0, uint16_t(~0U), uint16_t(~0U), uint16_t(~0U), uint16_t(~0U) }"
@@ -1438,18 +1425,16 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables,
14381425 OS << " }; // " << Target << " ReadAdvanceTable\n " ;
14391426
14401427 // Emit a SchedClass table for each processor.
1441- for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin (),
1442- PE = SchedModels.procModelEnd ();
1443- PI != PE; ++PI) {
1444- if (!PI->hasInstrSchedModel ())
1428+ for (const auto &[Idx, Proc] : enumerate(SchedModels.procModels ())) {
1429+ if (!Proc.hasInstrSchedModel ())
14451430 continue ;
14461431
14471432 std::vector<MCSchedClassDesc> &SCTab =
1448- SchedTables.ProcSchedClasses [1 + (PI - SchedModels. procModelBegin ()) ];
1433+ SchedTables.ProcSchedClasses [1 + Idx ];
14491434
14501435 OS << " \n // {Name, NumMicroOps, BeginGroup, EndGroup, RetireOOO,"
14511436 << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n " ;
1452- OS << " static const llvm::MCSchedClassDesc " << PI-> ModelName
1437+ OS << " static const llvm::MCSchedClassDesc " << Proc. ModelName
14531438 << " SchedClasses[] = {\n " ;
14541439
14551440 // The first class is always invalid. We no way to distinguish it except by
@@ -1476,7 +1461,7 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables,
14761461 << format (" %2d" , MCDesc.ReadAdvanceIdx ) << " , "
14771462 << MCDesc.NumReadAdvanceEntries << " }, // #" << SCIdx << ' \n ' ;
14781463 }
1479- OS << " }; // " << PI-> ModelName << " SchedClasses\n " ;
1464+ OS << " }; // " << Proc. ModelName << " SchedClasses\n " ;
14801465 }
14811466}
14821467
@@ -1524,14 +1509,10 @@ void SubtargetEmitter::emitProcessorModels(raw_ostream &OS) {
15241509
15251510 OS << " " << PM.Index << " , // Processor ID\n " ;
15261511 if (PM.hasInstrSchedModel ())
1527- OS << " " << PM.ModelName << " ProcResources"
1528- << " ,\n "
1529- << " " << PM.ModelName << " SchedClasses"
1530- << " ,\n "
1512+ OS << " " << PM.ModelName << " ProcResources" << " ,\n "
1513+ << " " << PM.ModelName << " SchedClasses" << " ,\n "
15311514 << " " << PM.ProcResourceDefs .size () + 1 << " ,\n "
1532- << " "
1533- << (SchedModels.schedClassEnd () - SchedModels.schedClassBegin ())
1534- << " ,\n " ;
1515+ << " " << SchedModels.schedClasses ().size () << " ,\n " ;
15351516 else
15361517 OS << " nullptr, nullptr, 0, 0,"
15371518 << " // No instruction-level machine model.\n " ;
@@ -1743,7 +1724,7 @@ void SubtargetEmitter::emitSchedModelHelpersImpl(
17431724 ? " if (CPUID == "
17441725 : " if (SchedModel->getProcessorID() == " );
17451726 OS << PI << " ) " ;
1746- OS << " { // " << ( SchedModels.procModelBegin () + PI)-> ModelName << ' \n ' ;
1727+ OS << " { // " << SchedModels.procModels ()[PI]. ModelName << ' \n ' ;
17471728 }
17481729
17491730 // Now emit transitions associated with processor PI.
0 commit comments