@@ -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,39 @@ 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
662+ // Begin processor itinerary table
674663 OS << " \n " ;
675- OS << " static const llvm::InstrItinerary " ;
664+ OS << " static constexpr llvm::InstrItinerary " << ItinsDef->getName ()
665+ << " [] = {\n " ;
676666
677- // Begin processor itinerary table
678- OS << ItinsDef-> getName () << " [] = { \n " ;
667+ ArrayRef<CodeGenSchedClass> ItinSchedClasses =
668+ SchedModels. schedClasses (). take_front (ItinList. size ()) ;
679669
680670 // 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-
671+ for (const auto &[Idx, Intinerary, SchedClass] :
672+ enumerate(ItinList, ItinSchedClasses)) {
684673 // Emit Itinerary in the form of
685- // { firstStage, lastStage, firstCycle, lastCycle } // index
674+ // { NumMicroOps, FirstStage, LastStage, FirstOperandCycle,
675+ // LastOperandCycle } // index class name
686676 OS << " { " << Intinerary.NumMicroOps << " , " << Intinerary.FirstStage
687677 << " , " << Intinerary.LastStage << " , " << Intinerary.FirstOperandCycle
688- << " , " << Intinerary.LastOperandCycle << " }"
689- << " , // " << J << " " << SchedModels. getSchedClass (J) .Name << " \n " ;
678+ << " , " << Intinerary.LastOperandCycle << " }" << " , // " << Idx << " "
679+ << SchedClass .Name << " \n " ;
690680 }
691681 // End processor itinerary table
692682 OS << " { 0, uint16_t(~0U), uint16_t(~0U), uint16_t(~0U), uint16_t(~0U) }"
@@ -1438,18 +1428,16 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables,
14381428 OS << " }; // " << Target << " ReadAdvanceTable\n " ;
14391429
14401430 // 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 ())
1431+ for (const auto &[Idx, Proc] : enumerate(SchedModels.procModels ())) {
1432+ if (!Proc.hasInstrSchedModel ())
14451433 continue ;
14461434
14471435 std::vector<MCSchedClassDesc> &SCTab =
1448- SchedTables.ProcSchedClasses [1 + (PI - SchedModels. procModelBegin ()) ];
1436+ SchedTables.ProcSchedClasses [1 + Idx ];
14491437
14501438 OS << " \n // {Name, NumMicroOps, BeginGroup, EndGroup, RetireOOO,"
14511439 << " WriteProcResIdx,#, WriteLatencyIdx,#, ReadAdvanceIdx,#}\n " ;
1452- OS << " static const llvm::MCSchedClassDesc " << PI-> ModelName
1440+ OS << " static const llvm::MCSchedClassDesc " << Proc. ModelName
14531441 << " SchedClasses[] = {\n " ;
14541442
14551443 // The first class is always invalid. We no way to distinguish it except by
@@ -1476,7 +1464,7 @@ void SubtargetEmitter::emitSchedClassTables(SchedClassTables &SchedTables,
14761464 << format (" %2d" , MCDesc.ReadAdvanceIdx ) << " , "
14771465 << MCDesc.NumReadAdvanceEntries << " }, // #" << SCIdx << ' \n ' ;
14781466 }
1479- OS << " }; // " << PI-> ModelName << " SchedClasses\n " ;
1467+ OS << " }; // " << Proc. ModelName << " SchedClasses\n " ;
14801468 }
14811469}
14821470
@@ -1524,14 +1512,10 @@ void SubtargetEmitter::emitProcessorModels(raw_ostream &OS) {
15241512
15251513 OS << " " << PM.Index << " , // Processor ID\n " ;
15261514 if (PM.hasInstrSchedModel ())
1527- OS << " " << PM.ModelName << " ProcResources"
1528- << " ,\n "
1529- << " " << PM.ModelName << " SchedClasses"
1530- << " ,\n "
1515+ OS << " " << PM.ModelName << " ProcResources" << " ,\n "
1516+ << " " << PM.ModelName << " SchedClasses" << " ,\n "
15311517 << " " << PM.ProcResourceDefs .size () + 1 << " ,\n "
1532- << " "
1533- << (SchedModels.schedClassEnd () - SchedModels.schedClassBegin ())
1534- << " ,\n " ;
1518+ << " " << SchedModels.schedClasses ().size () << " ,\n " ;
15351519 else
15361520 OS << " nullptr, nullptr, 0, 0,"
15371521 << " // No instruction-level machine model.\n " ;
@@ -1743,7 +1727,7 @@ void SubtargetEmitter::emitSchedModelHelpersImpl(
17431727 ? " if (CPUID == "
17441728 : " if (SchedModel->getProcessorID() == " );
17451729 OS << PI << " ) " ;
1746- OS << " { // " << ( SchedModels.procModelBegin () + PI)-> ModelName << ' \n ' ;
1730+ OS << " { // " << SchedModels.procModels ()[PI]. ModelName << ' \n ' ;
17471731 }
17481732
17491733 // Now emit transitions associated with processor PI.
0 commit comments