@@ -256,16 +256,6 @@ void DFAPacketizerEmitter::emitForItineraries(
256256 }
257257 OS << " \n };\n\n " ;
258258
259- // Output the mapping from proc ID to ResourceIndexStart
260- Idx = 1 ;
261- OS << " std::map<unsigned, unsigned> " << TargetName << DFAName
262- << " ProcIdToResourceIndexStartMapping = {\n " ;
263- for (const CodeGenProcModel *Model : ProcModels) {
264- OS << " { " << Model->Index << " , " << Idx++ << " }, // "
265- << Model->ModelName << " \n " ;
266- }
267- OS << " };\n\n " ;
268-
269259 // And the mapping from Itinerary index into the previous table.
270260 OS << " constexpr unsigned " << TargetName << DFAName
271261 << " ProcResourceIndexStart[] = {\n " ;
@@ -276,6 +266,38 @@ void DFAPacketizerEmitter::emitForItineraries(
276266 }
277267 OS << " " << ScheduleClasses.size () << " \n };\n\n " ;
278268
269+ // Output the mapping from proc ID to ResourceIndexStart
270+ Idx = 1 ;
271+ OS << " int " << TargetName << DFAName
272+ << " GetResourceIndex(unsigned ProcID) { \n "
273+ << " static const unsigned " << TargetName << DFAName
274+ << " ProcIdToProcResourceIdxTable[][2] = {\n " ;
275+ for (const CodeGenProcModel *Model : ProcModels) {
276+ OS << " { " << Model->Index << " , " << Idx++ << " }, // "
277+ << Model->ModelName << " \n " ;
278+ }
279+ OS << " };\n "
280+ << " unsigned Mid;\n "
281+ << " unsigned Start = 0;\n "
282+ << " unsigned End = " << ProcModels.size () << " ;\n "
283+ << " while (Start < End) {\n "
284+ << " Mid = Start + (End - Start) / 2;\n "
285+ << " if (ProcID == " << TargetName << DFAName
286+ << " ProcIdToProcResourceIdxTable[Mid][0]) {\n "
287+ << " break;\n "
288+ << " }\n "
289+ << " if (ProcID < " << TargetName << DFAName
290+ << " ProcIdToProcResourceIdxTable[Mid][0])\n "
291+ << " End = Mid;\n "
292+ << " else\n "
293+ << " Start = Mid + 1;\n "
294+ << " }\n "
295+ << " if (Start == End)\n "
296+ << " return -1; // Didn't find\n "
297+ << " return " << TargetName << DFAName
298+ << " ProcIdToProcResourceIdxTable[Mid][1];\n "
299+ << " }\n\n " ;
300+
279301 // The type of a state in the nondeterministic automaton we're defining.
280302 using NfaStateTy = uint64_t ;
281303
@@ -355,7 +377,7 @@ void DFAPacketizerEmitter::emitForItineraries(
355377 << " Transition>(" << TargetAndDFAName << " Transitions), "
356378 << TargetAndDFAName << " TransitionInfo);\n "
357379 << " unsigned Index = " << TargetName << DFAName
358- << " ProcIdToResourceIndexStartMapping[ IID->SchedModel.ProcID] ;\n "
380+ << " GetResourceIndex( IID->SchedModel.ProcID) ;\n "
359381 << " unsigned ProcResIdxStart = " << TargetAndDFAName
360382 << " ProcResourceIndexStart[Index];\n "
361383 << " unsigned ProcResIdxNum = " << TargetAndDFAName
0 commit comments