@@ -378,8 +378,12 @@ struct MCSchedModel {
378
378
379
379
template <typename MCSubtargetInfo, typename MCInstrInfo,
380
380
typename InstrItineraryData, typename MCInstOrMachineInstr>
381
- int computeInstrLatency (const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
382
- const MCInstOrMachineInstr &Inst) const ;
381
+ int computeInstrLatency (
382
+ const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
383
+ const MCInstOrMachineInstr &Inst,
384
+ llvm::function_ref<const MCSchedClassDesc *(const MCSchedClassDesc *)>
385
+ ResolveVariantSchedClass =
386
+ [](const MCSchedClassDesc *SCDesc) { return SCDesc; }) const ;
383
387
384
388
// Returns the reciprocal throughput information from a MCSchedClassDesc.
385
389
static double
@@ -408,9 +412,11 @@ struct MCSchedModel {
408
412
// the MC layer depend on CodeGen.
409
413
template <typename MCSubtargetInfo, typename MCInstrInfo,
410
414
typename InstrItineraryData, typename MCInstOrMachineInstr>
411
- int MCSchedModel::computeInstrLatency (const MCSubtargetInfo &STI,
412
- const MCInstrInfo &MCII,
413
- const MCInstOrMachineInstr &Inst) const {
415
+ int MCSchedModel::computeInstrLatency (
416
+ const MCSubtargetInfo &STI, const MCInstrInfo &MCII,
417
+ const MCInstOrMachineInstr &Inst,
418
+ llvm::function_ref<const MCSchedClassDesc *(const MCSchedClassDesc *)>
419
+ ResolveVariantSchedClass) const {
414
420
static const int NoInformationAvailable = -1 ;
415
421
// Check if we have a scheduling model for instructions.
416
422
if (!hasInstrSchedModel ()) {
@@ -440,25 +446,12 @@ int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
440
446
441
447
unsigned SchedClass = MCII.get (Inst.getOpcode ()).getSchedClass ();
442
448
const MCSchedClassDesc *SCDesc = getSchedClassDesc (SchedClass);
443
- if (!SCDesc->isValid ())
444
- return 0 ;
445
-
446
- if constexpr (std::is_same_v<MCInstOrMachineInstr, MCInst>) {
447
- unsigned CPUID = getProcessorID ();
448
- while (SCDesc->isVariant ()) {
449
- SchedClass =
450
- STI.resolveVariantSchedClass (SchedClass, &Inst, &MCII, CPUID);
451
- SCDesc = getSchedClassDesc (SchedClass);
452
- }
453
-
454
- if (SchedClass)
455
- return MCSchedModel::computeInstrLatency (STI, *SCDesc);
449
+ SCDesc = ResolveVariantSchedClass (SCDesc);
456
450
457
- llvm_unreachable (" unsupported variant scheduling class" );
458
- } else if (SchedClass)
459
- return MCSchedModel::computeInstrLatency (STI, SchedClass);
451
+ if (!SCDesc || !SCDesc->isValid ())
452
+ return NoInformationAvailable;
460
453
461
- return NoInformationAvailable ;
454
+ return MCSchedModel::computeInstrLatency (STI, *SCDesc) ;
462
455
}
463
456
464
457
} // namespace llvm
0 commit comments