@@ -378,8 +378,12 @@ struct MCSchedModel {
378378
379379 template <typename MCSubtargetInfo, typename MCInstrInfo,
380380 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 ;
383387
384388 // Returns the reciprocal throughput information from a MCSchedClassDesc.
385389 static double
@@ -408,9 +412,11 @@ struct MCSchedModel {
408412// the MC layer depend on CodeGen.
409413template <typename MCSubtargetInfo, typename MCInstrInfo,
410414 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 {
414420 static const int NoInformationAvailable = -1 ;
415421 // Check if we have a scheduling model for instructions.
416422 if (!hasInstrSchedModel ()) {
@@ -440,25 +446,12 @@ int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
440446
441447 unsigned SchedClass = MCII.get (Inst.getOpcode ()).getSchedClass ();
442448 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);
456450
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;
460453
461- return NoInformationAvailable ;
454+ return MCSchedModel::computeInstrLatency (STI, *SCDesc) ;
462455}
463456
464457} // namespace llvm
0 commit comments