LLVM 20.0.0git
|
Provide an instruction scheduling machine model to CodeGen passes. More...
#include "llvm/CodeGen/TargetSchedule.h"
Public Types | |
using | ProcResIter = const MCWriteProcResEntry * |
Public Member Functions | |
TargetSchedModel () | |
void | init (const TargetSubtargetInfo *TSInfo) |
Initialize the machine model for instruction scheduling. | |
const MCSchedClassDesc * | resolveSchedClass (const MachineInstr *MI) const |
Return the MCSchedClassDesc for this instruction. | |
const TargetSubtargetInfo * | getSubtargetInfo () const |
TargetSubtargetInfo getter. | |
const TargetInstrInfo * | getInstrInfo () const |
TargetInstrInfo getter. | |
bool | hasInstrSchedModel () const |
Return true if this machine model includes an instruction-level scheduling model. | |
const MCSchedModel * | getMCSchedModel () const |
bool | hasInstrItineraries () const |
Return true if this machine model includes cycle-to-cycle itinerary data. | |
const InstrItineraryData * | getInstrItineraries () const |
bool | hasInstrSchedModelOrItineraries () const |
Return true if this machine model includes an instruction-level scheduling model or cycle-to-cycle itinerary data. | |
bool | enableIntervals () const |
unsigned | getProcessorID () const |
Identify the processor corresponding to the current subtarget. | |
unsigned | getIssueWidth () const |
Maximum number of micro-ops that may be scheduled per cycle. | |
bool | mustBeginGroup (const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const |
Return true if new group must begin. | |
bool | mustEndGroup (const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const |
Return true if current group must end. | |
unsigned | getNumMicroOps (const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const |
Return the number of issue slots required for this MI. | |
unsigned | getNumProcResourceKinds () const |
Get the number of kinds of resources for this target. | |
const MCProcResourceDesc * | getProcResource (unsigned PIdx) const |
Get a processor resource by ID for convenience. | |
const char * | getResourceName (unsigned PIdx) const |
ProcResIter | getWriteProcResBegin (const MCSchedClassDesc *SC) const |
ProcResIter | getWriteProcResEnd (const MCSchedClassDesc *SC) const |
unsigned | getResourceFactor (unsigned ResIdx) const |
Multiply the number of units consumed for a resource by this factor to normalize it relative to other resources. | |
unsigned | getMicroOpFactor () const |
Multiply number of micro-ops by this factor to normalize it relative to other resources. | |
unsigned | getLatencyFactor () const |
Multiply cycle count by this factor to normalize it relative to other resources. | |
unsigned | getMicroOpBufferSize () const |
Number of micro-ops that may be buffered for OOO execution. | |
int | getResourceBufferSize (unsigned PIdx) const |
Number of resource units that may be buffered for OOO execution. | |
unsigned | computeOperandLatency (const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const |
Compute operand latency based on the available machine model. | |
unsigned | computeInstrLatency (const MachineInstr *MI, bool UseDefaultDefLatency=true) const |
Compute the instruction latency based on the available machine model. | |
unsigned | computeInstrLatency (const MCInst &Inst) const |
unsigned | computeInstrLatency (unsigned Opcode) const |
unsigned | computeOutputLatency (const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *DepMI) const |
Output dependency latency of a pair of defs of the same register. | |
double | computeReciprocalThroughput (const MachineInstr *MI) const |
Compute the reciprocal throughput of the given instruction. | |
double | computeReciprocalThroughput (const MCInst &MI) const |
double | computeReciprocalThroughput (unsigned Opcode) const |
Provide an instruction scheduling machine model to CodeGen passes.
Definition at line 30 of file TargetSchedule.h.
Definition at line 129 of file TargetSchedule.h.
|
inline |
Definition at line 49 of file TargetSchedule.h.
unsigned TargetSchedModel::computeInstrLatency | ( | const MachineInstr * | MI, |
bool | UseDefaultDefLatency = true |
||
) | const |
Compute the instruction latency based on the available machine model.
Compute and return the expected latency of this instruction independent of a particular use. computeOperandLatency is the preferred API, but this is occasionally useful to help estimate instruction cost.
If UseDefaultDefLatency is false and no new machine sched model is present this method falls back to TII->getInstrLatency with an empty instruction itinerary (this is so we preserve the previous behavior of the if converter after moving it to TargetSchedModel).
Definition at line 257 of file TargetSchedule.cpp.
References llvm::TargetInstrInfo::defaultDefLatency(), llvm::TargetInstrInfo::getInstrLatency(), hasInstrItineraries(), hasInstrSchedModel(), llvm::MCSchedClassDesc::isValid(), MI, and resolveSchedClass().
Definition at line 250 of file TargetSchedule.cpp.
References capLatency(), llvm::MCSchedModel::computeInstrLatency(), llvm::MCInst::getOpcode(), and hasInstrSchedModel().
Definition at line 244 of file TargetSchedule.cpp.
References assert(), capLatency(), llvm::MCSchedModel::computeInstrLatency(), llvm::MCInstrInfo::get(), llvm::MCInstrDesc::getSchedClass(), and hasInstrSchedModel().
unsigned TargetSchedModel::computeOperandLatency | ( | const MachineInstr * | DefMI, |
unsigned | DefOperIdx, | ||
const MachineInstr * | UseMI, | ||
unsigned | UseOperIdx | ||
) | const |
Compute operand latency based on the available machine model.
Compute and return the latency of the given data dependent def and use when the operand indices are already known. UseMI may be NULL for an unknown user.
Definition at line 173 of file TargetSchedule.cpp.
References capLatency(), llvm::MCWriteLatencyEntry::Cycles, llvm::TargetInstrInfo::defaultDefLatency(), DefMI, llvm::errs(), findDefIdx(), findUseIdx(), llvm::MachineInstr::getDesc(), llvm::MachineInstr::getOperand(), llvm::InstrItineraryData::getOperandCycle(), llvm::TargetInstrInfo::getOperandLatency(), llvm::MCSubtargetInfo::getReadAdvanceCycles(), llvm::MCInstrDesc::getSchedClass(), llvm::MCSubtargetInfo::getWriteLatencyEntry(), hasInstrItineraries(), hasInstrSchedModel(), llvm::MCSchedModel::isComplete(), llvm::MachineOperand::isImplicit(), llvm::MachineInstr::isTransient(), llvm::MCSchedClassDesc::isValid(), llvm::Latency, llvm_unreachable, llvm::MCSchedClassDesc::NumReadAdvanceEntries, llvm::MCInstrDesc::operands(), resolveSchedClass(), UseMI, and llvm::MCWriteLatencyEntry::WriteResourceID.
Referenced by llvm::ScheduleDAGInstrs::addPhysRegDataDeps(), llvm::ScheduleDAGInstrs::addVRegDefDeps(), llvm::AArch64Subtarget::adjustSchedDependency(), llvm::GCNSubtarget::adjustSchedDependency(), pushDepHeight(), and updatePhysDepsUpwards().
unsigned TargetSchedModel::computeOutputLatency | ( | const MachineInstr * | DefMI, |
unsigned | DefOperIdx, | ||
const MachineInstr * | DepMI | ||
) | const |
Output dependency latency of a pair of defs of the same register.
This is typically one cycle.
Definition at line 273 of file TargetSchedule.cpp.
References llvm::MCProcResourceDesc::BufferSize, DefMI, llvm::MachineInstr::getMF(), llvm::MachineInstr::getOperand(), llvm::MCSchedModel::getProcResource(), llvm::MachineOperand::getReg(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), llvm::MCSubtargetInfo::getWriteProcResBegin(), llvm::MCSubtargetInfo::getWriteProcResEnd(), hasInstrSchedModel(), llvm::MCSchedModel::isOutOfOrder(), llvm::TargetInstrInfo::isPredicated(), llvm::MCSchedClassDesc::isValid(), llvm::MachineInstr::readsRegister(), resolveSchedClass(), and TRI.
Referenced by llvm::ScheduleDAGInstrs::addPhysRegDeps(), and llvm::ScheduleDAGInstrs::addVRegDefDeps().
double TargetSchedModel::computeReciprocalThroughput | ( | const MachineInstr * | MI | ) | const |
Compute the reciprocal throughput of the given instruction.
Definition at line 309 of file TargetSchedule.cpp.
References getInstrItineraries(), llvm::MCSchedModel::getReciprocalThroughput(), hasInstrItineraries(), hasInstrSchedModel(), MI, and resolveSchedClass().
Referenced by computeReciprocalThroughput().
Definition at line 338 of file TargetSchedule.cpp.
References computeReciprocalThroughput(), llvm::MCSchedModel::getReciprocalThroughput(), hasInstrSchedModel(), and MI.
double TargetSchedModel::computeReciprocalThroughput | ( | unsigned | Opcode | ) | const |
Definition at line 323 of file TargetSchedule.cpp.
References llvm::MCInstrInfo::get(), getInstrItineraries(), llvm::MCSchedModel::getReciprocalThroughput(), llvm::MCInstrDesc::getSchedClass(), llvm::MCSchedModel::getSchedClassDesc(), hasInstrItineraries(), hasInstrSchedModel(), llvm::MCSchedClassDesc::isValid(), and llvm::MCSchedClassDesc::isVariant().
bool TargetSchedModel::enableIntervals | ( | ) | const |
Definition at line 344 of file TargetSchedule.cpp.
References llvm::MCSchedModel::EnableIntervals, and ForceEnableIntervals.
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::dumpReservedCycles(), and llvm::SchedBoundary::getNextResourceCycleByInstance().
|
inline |
|
inline |
Definition at line 82 of file TargetSchedule.h.
References hasInstrItineraries().
Referenced by computeReciprocalThroughput(), llvm::TargetInstrInfo::hasLowDefLatency(), llvm::GenericScheduler::initialize(), llvm::PostGenericScheduler::initialize(), and llvm::ConvergingVLIWScheduler::initialize().
|
inline |
Maximum number of micro-ops that may be scheduled per cycle.
Definition at line 98 of file TargetSchedule.h.
References llvm::MCSchedModel::IssueWidth.
Referenced by llvm::ConvergingVLIWScheduler::VLIWSchedBoundary::bumpCycle(), llvm::SchedBoundary::bumpCycle(), llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), llvm::ConvergingVLIWScheduler::VLIWSchedBoundary::checkHazard(), llvm::ConvergingVLIWScheduler::VLIWSchedBoundary::init(), llvm::PPCTTIImpl::isHardwareLoopProfitable(), llvm::VLIWResourceModel::reserveResources(), and llvm::VLIWResourceModel::VLIWResourceModel().
|
inline |
Multiply cycle count by this factor to normalize it relative to other resources.
This is the number of resource units per cycle.
Definition at line 155 of file TargetSchedule.h.
Referenced by llvm::SchedBoundary::bumpCycle(), llvm::SchedBoundary::bumpNode(), llvm::GenericScheduler::checkAcyclicLatency(), llvm::SchedBoundary::countResource(), llvm::SchedBoundary::dumpScheduledState(), llvm::SchedBoundary::getExecutedCount(), and llvm::GenericSchedulerBase::setPolicy().
|
inline |
Definition at line 74 of file TargetSchedule.h.
|
inline |
Number of micro-ops that may be buffered for OOO execution.
Definition at line 160 of file TargetSchedule.h.
References llvm::MCSchedModel::MicroOpBufferSize.
Referenced by llvm::SchedBoundary::bumpCycle(), llvm::SchedBoundary::bumpNode(), llvm::GenericScheduler::checkAcyclicLatency(), llvm::GenericScheduler::registerRoots(), and llvm::SchedBoundary::releaseNode().
|
inline |
Multiply number of micro-ops by this factor to normalize it relative to other resources.
Definition at line 149 of file TargetSchedule.h.
Referenced by llvm::SchedBoundary::bumpNode(), llvm::GenericScheduler::checkAcyclicLatency(), llvm::SchedBoundary::dumpScheduledState(), llvm::SchedBoundary::getCriticalCount(), llvm::SchedBoundary::getOtherResourceCount(), and llvm::SchedRemainder::init().
unsigned TargetSchedModel::getNumMicroOps | ( | const MachineInstr * | MI, |
const MCSchedClassDesc * | SC = nullptr |
||
) | const |
Return the number of issue slots required for this MI.
Definition at line 95 of file TargetSchedule.cpp.
References llvm::TargetInstrInfo::getNumMicroOps(), llvm::InstrItineraryData::getNumMicroOps(), hasInstrItineraries(), hasInstrSchedModel(), MI, and resolveSchedClass().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::ConvergingVLIWScheduler::VLIWSchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), llvm::ConvergingVLIWScheduler::VLIWSchedBoundary::checkHazard(), and llvm::SchedRemainder::init().
|
inline |
Get the number of kinds of resources for this target.
Definition at line 112 of file TargetSchedule.h.
References llvm::MCSchedModel::getNumProcResourceKinds().
Referenced by llvm::SystemZHazardRecognizer::dumpProcResourceCounters(), llvm::SchedBoundary::dumpReservedCycles(), llvm::MachineTraceMetrics::Ensemble::Ensemble(), llvm::SchedBoundary::getOtherResourceCount(), llvm::MachineTraceMetrics::getProcReleaseAtCycles(), llvm::MachineTraceMetrics::getResources(), llvm::SchedRemainder::init(), llvm::SchedBoundary::init(), and llvm::MachineTraceMetrics::runOnMachineFunction().
|
inline |
Identify the processor corresponding to the current subtarget.
Definition at line 95 of file TargetSchedule.h.
References llvm::MCSchedModel::getProcessorID().
|
inline |
Get a processor resource by ID for convenience.
Definition at line 117 of file TargetSchedule.h.
References llvm::MCSchedModel::getProcResource().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SystemZHazardRecognizer::dumpProcResourceCounters(), llvm::SchedBoundary::dumpReservedCycles(), llvm::SystemZHazardRecognizer::dumpSU(), llvm::SystemZHazardRecognizer::emitInstruction(), llvm::SystemZHazardRecognizer::EmitInstruction(), llvm::SchedBoundary::getNextResourceCycle(), llvm::SchedBoundary::init(), llvm::ScheduleDAGInstrs::initSUnits(), llvm::SchedBoundary::isUnbufferedGroup(), and llvm::GenericSchedulerBase::traceCandidate().
|
inline |
Number of resource units that may be buffered for OOO execution.
Definition at line 164 of file TargetSchedule.h.
References llvm::MCProcResourceDesc::BufferSize, and llvm::MCSchedModel::getProcResource().
Multiply the number of units consumed for a resource by this factor to normalize it relative to other resources.
Definition at line 143 of file TargetSchedule.h.
Referenced by llvm::SchedBoundary::countResource(), llvm::SchedBoundary::dumpScheduledState(), llvm::SchedBoundary::getOtherResourceCount(), llvm::MachineTraceMetrics::getResources(), and llvm::SchedRemainder::init().
Definition at line 122 of file TargetSchedule.h.
References llvm::MCSchedModel::getProcResource(), and llvm::MCProcResourceDesc::Name.
Referenced by llvm::SchedBoundary::checkHazard(), llvm::SchedBoundary::countResource(), llvm::SchedBoundary::dumpReservedCycles(), llvm::SchedBoundary::dumpScheduledState(), llvm::ScheduleDAGMI::dumpScheduleTraceBottomUp(), llvm::ScheduleDAGMI::dumpScheduleTraceTopDown(), llvm::SchedBoundary::getNextResourceCycle(), llvm::SchedBoundary::getOtherResourceCount(), and llvm::GenericSchedulerBase::setPolicy().
|
inline |
TargetSubtargetInfo getter.
Definition at line 62 of file TargetSchedule.h.
|
inline |
Definition at line 133 of file TargetSchedule.h.
References llvm::MCSubtargetInfo::getWriteProcResBegin().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), llvm::ScheduleDAGMI::dumpScheduleTraceBottomUp(), llvm::ScheduleDAGMI::dumpScheduleTraceTopDown(), llvm::SystemZHazardRecognizer::dumpSU(), llvm::SystemZHazardRecognizer::emitInstruction(), llvm::SystemZHazardRecognizer::EmitInstruction(), llvm::SchedBoundary::getNextResourceCycle(), llvm::MachineTraceMetrics::getResources(), llvm::SchedRemainder::init(), llvm::GenericSchedulerBase::SchedCandidate::initResourceDelta(), llvm::ScheduleDAGInstrs::initSUnits(), and llvm::SystemZHazardRecognizer::resourcesCost().
|
inline |
Definition at line 137 of file TargetSchedule.h.
References llvm::MCSubtargetInfo::getWriteProcResEnd().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), llvm::ScheduleDAGMI::dumpScheduleTraceBottomUp(), llvm::ScheduleDAGMI::dumpScheduleTraceTopDown(), llvm::SystemZHazardRecognizer::dumpSU(), llvm::SystemZHazardRecognizer::emitInstruction(), llvm::SystemZHazardRecognizer::EmitInstruction(), llvm::SchedBoundary::getNextResourceCycle(), llvm::MachineTraceMetrics::getResources(), llvm::SchedRemainder::init(), llvm::GenericSchedulerBase::SchedCandidate::initResourceDelta(), llvm::ScheduleDAGInstrs::initSUnits(), and llvm::SystemZHazardRecognizer::resourcesCost().
bool TargetSchedModel::hasInstrItineraries | ( | ) | const |
Return true if this machine model includes cycle-to-cycle itinerary data.
This models scheduling at each stage in the processor pipeline.
Definition at line 47 of file TargetSchedule.cpp.
References EnableSchedItins, and llvm::InstrItineraryData::isEmpty().
Referenced by computeInstrLatency(), computeOperandLatency(), computeReciprocalThroughput(), getInstrItineraries(), getNumMicroOps(), and hasInstrSchedModelOrItineraries().
bool TargetSchedModel::hasInstrSchedModel | ( | ) | const |
Return true if this machine model includes an instruction-level scheduling model.
This is more detailed than the course grain IssueWidth and default latency properties, but separate from the per-cycle itinerary data.
Definition at line 43 of file TargetSchedule.cpp.
References EnableSchedModel, and llvm::MCSchedModel::hasInstrSchedModel().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), computeInstrLatency(), computeOperandLatency(), computeOutputLatency(), computeReciprocalThroughput(), llvm::SchedBoundary::dumpReservedCycles(), llvm::ScheduleDAGMI::dumpScheduleTraceBottomUp(), llvm::ScheduleDAGMI::dumpScheduleTraceTopDown(), getNumMicroOps(), llvm::SchedBoundary::getOtherResourceCount(), llvm::MachineTraceMetrics::getResources(), llvm::ScheduleDAGInstrs::getSchedClass(), llvm::SystemZHazardRecognizer::getSchedClass(), hasInstrSchedModelOrItineraries(), llvm::SchedRemainder::init(), llvm::SchedBoundary::init(), llvm::ScheduleDAGInstrs::initSUnits(), mustBeginGroup(), mustEndGroup(), and llvm::GenericSchedulerBase::setPolicy().
|
inline |
Return true if this machine model includes an instruction-level scheduling model or cycle-to-cycle itinerary data.
Definition at line 90 of file TargetSchedule.h.
References hasInstrItineraries(), and hasInstrSchedModel().
void TargetSchedModel::init | ( | const TargetSubtargetInfo * | TSInfo | ) |
Initialize the machine model for instruction scheduling.
The machine model API keeps a copy of the top-level MCSchedModel table indices and may query TargetSubtargetInfo and TargetInstrInfo to resolve dynamic properties.
Definition at line 51 of file TargetSchedule.cpp.
References llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MCSchedModel::getNumProcResourceKinds(), llvm::MCSchedModel::getProcResource(), llvm::MCSubtargetInfo::getSchedModel(), Idx, llvm::MCSubtargetInfo::initInstrItins(), llvm::MCSchedModel::IssueWidth, llvm::MCProcResourceDesc::NumUnits, and llvm::SmallVectorImpl< T >::resize().
Referenced by llvm::GCNHazardRecognizer::GCNHazardRecognizer(), llvm::PPCTTIImpl::isHardwareLoopProfitable(), llvm::MachineTraceMetrics::runOnMachineFunction(), llvm::ScheduleDAGInstrs::ScheduleDAGInstrs(), llvm::SIInstrInfo::SIInstrInfo(), and llvm::SystemZPostRASchedStrategy::SystemZPostRASchedStrategy().
bool TargetSchedModel::mustBeginGroup | ( | const MachineInstr * | MI, |
const MCSchedClassDesc * | SC = nullptr |
||
) | const |
Return true if new group must begin.
Returns true only if instruction is specified as single issue.
Definition at line 73 of file TargetSchedule.cpp.
References hasInstrSchedModel(), MI, and resolveSchedClass().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), and llvm::ScheduleDAGMILive::dump().
bool TargetSchedModel::mustEndGroup | ( | const MachineInstr * | MI, |
const MCSchedClassDesc * | SC = nullptr |
||
) | const |
Return true if current group must end.
Definition at line 84 of file TargetSchedule.cpp.
References hasInstrSchedModel(), MI, and resolveSchedClass().
Referenced by llvm::SchedBoundary::bumpNode(), llvm::SchedBoundary::checkHazard(), and llvm::ScheduleDAGMILive::dump().
const MCSchedClassDesc * TargetSchedModel::resolveSchedClass | ( | const MachineInstr * | MI | ) | const |
Return the MCSchedClassDesc for this instruction.
Some SchedClasses require evaluation of predicates that depend on instruction operands or flags.
Definition at line 120 of file TargetSchedule.cpp.
References assert(), llvm::MCSchedModel::getSchedClassDesc(), llvm::MCSchedClassDesc::isValid(), llvm::MCSchedClassDesc::isVariant(), MI, and llvm::TargetSubtargetInfo::resolveSchedClass().
Referenced by computeInstrLatency(), computeOperandLatency(), computeOutputLatency(), computeReciprocalThroughput(), llvm::SystemZHazardRecognizer::emitInstruction(), getNumMicroOps(), llvm::MachineTraceMetrics::getResources(), llvm::ScheduleDAGInstrs::getSchedClass(), llvm::SystemZHazardRecognizer::getSchedClass(), mustBeginGroup(), and mustEndGroup().