26 cl::desc(
"Use TargetSchedModel for latency lookup"));
29 cl::desc(
"Use InstrItineraryData for latency lookup"));
39 static unsigned gcd(
unsigned Dividend,
unsigned Divisor) {
42 unsigned Rem = Dividend % Divisor;
48 static unsigned lcm(
unsigned A,
unsigned B) {
49 unsigned LCM = (uint64_t(A) * B) /
gcd(A, B);
50 assert((LCM >= A && LCM >= B) &&
"LCM overflow");
63 ResourceFactors.
resize(NumRes);
65 for (
unsigned Idx = 0; Idx < NumRes; ++Idx) {
68 ResourceLCM =
lcm(ResourceLCM, NumUnits);
70 MicroOpFactor = ResourceLCM / SchedModel.
IssueWidth;
71 for (
unsigned Idx = 0; Idx < NumRes; ++Idx) {
73 ResourceFactors[Idx] = NumUnits ? (ResourceLCM / NumUnits) : 0;
97 return Cycles >= 0 ? Cycles : 1000;
115 assert(++NIter < 6 &&
"Variants are nested deeper than the magic number");
130 for (
unsigned i = 0; i != DefOperIdx; ++i) {
146 for (
unsigned i = 0; i != UseOperIdx; ++i) {
172 if (OperLatency >= 0)
183 InstrLatency = std::max(InstrLatency,
189 unsigned DefIdx =
findDefIdx(DefMI, DefOperIdx);
190 if (DefIdx < SCDesc->NumWriteLatencyEntries) {
203 unsigned UseIdx =
findUseIdx(UseMI, UseOperIdx);
205 if (Advance > 0 && (
unsigned)Advance > Latency)
207 return Latency - Advance;
217 ss <<
"DefIdx " << DefIdx <<
" exceeds machine model writes for "
230 bool UseDefaultDefLatency)
const {
240 unsigned Latency = 0;
242 DefIdx != DefEnd; ++DefIdx) {
const MachineFunction * getParent() const
const MCSchedClassDesc * resolveSchedClass(const MachineInstr *MI) const
Return the MCSchedClassDesc for this instruction.
bool hasInstrItineraries() const
Return true if this machine model includes cycle-to-cycle itinerary data.
static unsigned lcm(unsigned A, unsigned B)
int getNumMicroOps(unsigned ItinClassIndx) const
const MCWriteProcResEntry * getWriteProcResBegin(const MCSchedClassDesc *SC) const
unsigned computeOutputLatency(const MachineInstr *DefMI, unsigned DefIdx, const MachineInstr *DepMI) const
Output dependency latency of a pair of defs of the same register.
unsigned getNumMicroOps(const MachineInstr *MI, const MCSchedClassDesc *SC=0) const
Return the number of issue slots required for this MI.
unsigned short NumMicroOps
void init(const MCSchedModel &sm, const TargetSubtargetInfo *sti, const TargetInstrInfo *tii)
Initialize the machine model for instruction scheduling.
const MCInstrDesc & getDesc() const
static unsigned gcd(unsigned Dividend, unsigned Divisor)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
int getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const
void initInstrItins(InstrItineraryData &InstrItins) const
Initialize an InstrItineraryData instance.
const MCWriteProcResEntry * getWriteProcResEnd(const MCSchedClassDesc *SC) const
static cl::opt< bool > EnableSchedItins("scheditins", cl::Hidden, cl::init(true), cl::desc("Use InstrItineraryData for latency lookup"))
bool isReg() const
isReg - Tests if this is a MO_Register operand.
int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx, unsigned WriteResID) const
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI=NULL) const
unsigned NumReadAdvanceEntries
const MachineBasicBlock * getParent() const
initializer< Ty > init(const Ty &Val)
unsigned NumWriteLatencyEntries
bool isOptionalDef() const
const MachineOperand & getOperand(unsigned i) const
const MCWriteLatencyEntry * getWriteLatencyEntry(const MCSchedClassDesc *SC, unsigned DefIdx) const
const MCProcResourceDesc * getProcResource(unsigned ProcResourceIdx) const
unsigned getNumProcResourceKinds() const
bool hasInstrSchedModel() const
Return true if this machine model includes an instruction-level scheduling model. ...
virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, const MachineInstr *MI) const
virtual unsigned resolveSchedClass(unsigned SchedClass, const MachineInstr *MI, const TargetSchedModel *SchedModel) const
unsigned MicroOpBufferSize
bool hasInstrSchedModel() const
Does this machine model include instruction-level scheduling.
unsigned defaultDefLatency(const MCSchedModel *SchedModel, const MachineInstr *DefMI) const
Return the default expected latency for a def based on it's opcode.
const MCSchedClassDesc * getSchedClassDesc(unsigned SchedClassIdx) const
static unsigned findUseIdx(const MachineInstr *MI, unsigned UseOperIdx)
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr *MI, unsigned *PredCost=0) const
unsigned getSchedClass() const
Return the scheduling class for this instruction. The scheduling class is an index into the InstrItin...
static cl::opt< bool > EnableSchedModel("schedmodel", cl::Hidden, cl::init(true), cl::desc("Use TargetSchedModel for latency lookup"))
const TargetMachine & getTarget() const
virtual int getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const
virtual const TargetRegisterInfo * getRegisterInfo() const
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 getReg() const
getReg - Returns the register number.
const MCOperandInfo * OpInfo
virtual bool isPredicated(const MachineInstr *MI) const
static unsigned findDefIdx(const MachineInstr *MI, unsigned DefOperIdx)
static unsigned capLatency(int Cycles)