Skip to content

Commit fe6782d

Browse files
committed
[TargetInstrInfo] Add target hook for InstrSchedModel latency. [NFCI]
Allows targets to dynamically set latency values in the DAG builder. This is useful in multi-pass schedulers like in the AMDGUP backend where we may want to schedule a region multiple times with a different machine model or tweaked latencies for a specific instruction type.
1 parent 98542a3 commit fe6782d

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,13 +1802,18 @@ class TargetInstrInfo : public MCInstrInfo {
18021802
const MachineInstr &DefMI, unsigned DefIdx,
18031803
const MachineInstr &UseMI, unsigned UseIdx) const;
18041804

1805-
/// Compute the instruction latency of a given instruction.
1806-
/// If the instruction has higher cost when predicated, it's returned via
1807-
/// PredCost.
1805+
/// Compute the instruction latency of a given instruction using the itinerary
1806+
/// model. If the instruction has higher cost when predicated, it's returned
1807+
/// via PredCost.
18081808
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData,
18091809
const MachineInstr &MI,
18101810
unsigned *PredCost = nullptr) const;
18111811

1812+
/// Compute the instruction latency using the InstrSchedModel or the default
1813+
/// def latency when no model is available.
1814+
virtual unsigned getInstrLatency(const TargetSchedModel &TargetSchedModel,
1815+
const MachineInstr &MI) const;
1816+
18121817
virtual unsigned getPredicationCost(const MachineInstr &MI) const;
18131818

18141819
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData,

llvm/include/llvm/CodeGen/TargetSchedule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class TargetSchedModel {
4343
// Resource units per cycle. Latency normalization factor.
4444
unsigned ResourceLCM = 0;
4545

46-
unsigned computeInstrLatency(const MCSchedClassDesc &SCDesc) const;
47-
4846
public:
4947
TargetSchedModel() : SchedModel(MCSchedModel::Default) {}
5048

@@ -189,6 +187,7 @@ class TargetSchedModel {
189187
bool UseDefaultDefLatency = true) const;
190188
unsigned computeInstrLatency(const MCInst &Inst) const;
191189
unsigned computeInstrLatency(unsigned Opcode) const;
190+
unsigned computeInstrLatency(const MCSchedClassDesc &SCDesc) const;
192191

193192

194193
/// Output dependency latency of a pair of defs of the same register.

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,18 @@ unsigned TargetInstrInfo::getInstrLatency(const InstrItineraryData *ItinData,
15141514
return ItinData->getStageLatency(MI.getDesc().getSchedClass());
15151515
}
15161516

1517+
unsigned
1518+
TargetInstrInfo::getInstrLatency(const TargetSchedModel &TargetSchedModel,
1519+
const MachineInstr &MI) const {
1520+
if (TargetSchedModel.hasInstrSchedModel()) {
1521+
const MCSchedClassDesc *SCDesc = TargetSchedModel.resolveSchedClass(&MI);
1522+
if (SCDesc->isValid())
1523+
return TargetSchedModel.computeInstrLatency(*SCDesc);
1524+
}
1525+
1526+
return defaultDefLatency(*TargetSchedModel.getMCSchedModel(), MI);
1527+
}
1528+
15171529
bool TargetInstrInfo::hasLowDefLatency(const TargetSchedModel &SchedModel,
15181530
const MachineInstr &DefMI,
15191531
unsigned DefIdx) const {

llvm/lib/CodeGen/TargetSchedule.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,9 @@ TargetSchedModel::computeInstrLatency(const MachineInstr *MI,
261261
(!hasInstrSchedModel() && !UseDefaultDefLatency))
262262
return TII->getInstrLatency(&InstrItins, *MI);
263263

264-
if (hasInstrSchedModel()) {
265-
const MCSchedClassDesc *SCDesc = resolveSchedClass(MI);
266-
if (SCDesc->isValid())
267-
return computeInstrLatency(*SCDesc);
268-
}
269-
return TII->defaultDefLatency(SchedModel, *MI);
264+
// This is used by targets that define an InstrSchedModel or want to use the
265+
// default def latency.
266+
return TII->getInstrLatency(*this, *MI);
270267
}
271268

272269
unsigned TargetSchedModel::

0 commit comments

Comments
 (0)