@@ -256,16 +256,6 @@ void DFAPacketizerEmitter::emitForItineraries(
256
256
}
257
257
OS << " \n };\n\n " ;
258
258
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
-
269
259
// And the mapping from Itinerary index into the previous table.
270
260
OS << " constexpr unsigned " << TargetName << DFAName
271
261
<< " ProcResourceIndexStart[] = {\n " ;
@@ -276,6 +266,38 @@ void DFAPacketizerEmitter::emitForItineraries(
276
266
}
277
267
OS << " " << ScheduleClasses.size () << " \n };\n\n " ;
278
268
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
+
279
301
// The type of a state in the nondeterministic automaton we're defining.
280
302
using NfaStateTy = uint64_t ;
281
303
@@ -355,7 +377,7 @@ void DFAPacketizerEmitter::emitForItineraries(
355
377
<< " Transition>(" << TargetAndDFAName << " Transitions), "
356
378
<< TargetAndDFAName << " TransitionInfo);\n "
357
379
<< " unsigned Index = " << TargetName << DFAName
358
- << " ProcIdToResourceIndexStartMapping[ IID->SchedModel.ProcID] ;\n "
380
+ << " GetResourceIndex( IID->SchedModel.ProcID) ;\n "
359
381
<< " unsigned ProcResIdxStart = " << TargetAndDFAName
360
382
<< " ProcResourceIndexStart[Index];\n "
361
383
<< " unsigned ProcResIdxNum = " << TargetAndDFAName
0 commit comments