35 cl::desc(
"Use TargetSchedModel for latency lookup"));
38 cl::desc(
"Use InstrItineraryData for latency lookup"));
48 static unsigned gcd(
unsigned Dividend,
unsigned Divisor) {
51 unsigned Rem = Dividend % Divisor;
58 static unsigned lcm(
unsigned A,
unsigned B) {
59 unsigned LCM = (uint64_t(A) *
B) /
gcd(A, B);
60 assert((LCM >= A && LCM >= B) &&
"LCM overflow");
71 ResourceFactors.
resize(NumRes);
73 for (
unsigned Idx = 0; Idx < NumRes; ++Idx) {
76 ResourceLCM =
lcm(ResourceLCM, NumUnits);
78 MicroOpFactor = ResourceLCM / SchedModel.
IssueWidth;
79 for (
unsigned Idx = 0; Idx < NumRes; ++Idx) {
81 ResourceFactors[Idx] = NumUnits ? (ResourceLCM / NumUnits) : 0;
112 return (UOps >= 0) ? UOps : TII->
getNumMicroOps(&InstrItins, *MI);
128 return Cycles >= 0 ? Cycles : 1000;
145 assert(++NIter < 6 &&
"Variants are nested deeper than the magic number");
160 for (
unsigned i = 0; i != DefOperIdx; ++i) {
176 for (
unsigned i = 0; i != UseOperIdx; ++i) {
202 if (OperLatency >= 0)
219 unsigned DefIdx =
findDefIdx(DefMI, DefOperIdx);
220 if (DefIdx < SCDesc->NumWriteLatencyEntries) {
233 unsigned UseIdx =
findUseIdx(UseMI, UseOperIdx);
235 if (Advance > 0 && (
unsigned)Advance > Latency)
237 return Latency - Advance;
245 errs() <<
"DefIdx " << DefIdx <<
" exceeds machine model writes for " 246 << *DefMI <<
" (Try with MCSchedModel.CompleteModel set to false)";
257 TargetSchedModel::computeInstrLatency(
const MCSchedClassDesc &SCDesc)
const {
261 unsigned TargetSchedModel::computeInstrLatency(
unsigned Opcode)
const {
267 unsigned TargetSchedModel::computeInstrLatency(
const MCInst &Inst)
const {
270 return computeInstrLatency(Inst.
getOpcode());
275 bool UseDefaultDefLatency)
const {
285 return computeInstrLatency(*SCDesc);
308 return computeInstrLatency(DefMI);
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
double computeReciprocalThroughput(const MachineInstr *MI) const
Compute the reciprocal throughput of the given instruction.
static unsigned lcm(unsigned A, unsigned B)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned getReg() const
getReg - Returns the register number.
uint16_t NumReadAdvanceEntries
const MCProcResourceDesc * getProcResource(unsigned ProcResourceIdx) const
unsigned computeOperandLatency(const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *UseMI, unsigned UseOperIdx) const
Compute operand latency based on the available machine model.
bool isTransient() const
Return true if this is a transient instruction that is either very likely to be eliminated during reg...
unsigned const TargetRegisterInfo * TRI
static unsigned gcd(unsigned Dividend, unsigned Divisor)
const MCSchedClassDesc * getSchedClassDesc(unsigned SchedClassIdx) const
unsigned defaultDefLatency(const MCSchedModel &SchedModel, const MachineInstr &DefMI) const
Return the default expected latency for a def based on its opcode.
virtual unsigned resolveSchedClass(unsigned SchedClass, const MachineInstr *MI, const TargetSchedModel *SchedModel) const
Resolve a SchedClass at runtime, where SchedClass identifies an MCSchedClassDesc with the isVariant p...
bool isComplete() const
Return true if this machine model data for all instructions with a scheduling class (itinerary class ...
static cl::opt< bool > EnableSchedItins("scheditins", cl::Hidden, cl::init(true), cl::desc("Use InstrItineraryData for latency lookup"))
const InstrItineraryData * getInstrItineraries() const
bool hasInstrSchedModel() const
Return true if this machine model includes an instruction-level scheduling model. ...
unsigned getNumMicroOps(const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const
Return the number of issue slots required for this MI.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...
const MCWriteLatencyEntry * getWriteLatencyEntry(const MCSchedClassDesc *SC, unsigned DefIdx) const
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const MCWriteProcResEntry * getWriteProcResEnd(const MCSchedClassDesc *SC) const
virtual unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const
Compute the instruction latency of a given instruction.
int getNumMicroOps(unsigned ItinClassIndx) const
Return the number of micro-ops that the given class decodes to.
virtual const TargetInstrInfo * getInstrInfo() const
Instances of this class represent a single low-level machine instruction.
void initInstrItins(InstrItineraryData &InstrItins) const
Initialize an InstrItineraryData instance.
unsigned getSchedClass() const
Return the scheduling class for this instruction.
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isOptionalDef() const
Set if this operand is a optional def.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Identify one of the processor resource kinds consumed by a particular scheduling class for the specif...
MachineInstrBuilder & UseMI
virtual unsigned getNumMicroOps(const InstrItineraryData *ItinData, const MachineInstr &MI) const
Return the number of u-operations the given machine instruction will be decoded to on the target cpu...
Summarize the scheduling resources required for an instruction of a particular scheduling class...
void init(const TargetSubtargetInfo *TSInfo)
Initialize the machine model for instruction scheduling.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool mustEndGroup(const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const
Return true if current group must end.
virtual bool isPredicated(const MachineInstr &MI) const
Returns true if the instruction is already predicated.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool hasInstrSchedModel() const
Does this machine model include instruction-level scheduling.
Specify the latency in cpu cycles for a particular scheduling class and def index.
MachineOperand class - Representation of each machine instruction operand.
bool mustBeginGroup(const MachineInstr *MI, const MCSchedClassDesc *SC=nullptr) const
Return true if new group must begin.
MachineInstrBuilder MachineInstrBuilder & DefMI
CHAIN = SC CHAIN, Imm128 - System call.
bool isOutOfOrder() const
Return true if machine supports out of order execution.
bool readsRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr reads the specified register.
bool hasInstrItineraries() const
Return true if this machine model includes cycle-to-cycle itinerary data.
static unsigned findUseIdx(const MachineInstr *MI, unsigned UseOperIdx)
Find the use index of this operand.
unsigned computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx, const MachineInstr *DepMI) const
Output dependency latency of a pair of defs of the same register.
const MCSchedClassDesc * resolveSchedClass(const MachineInstr *MI) const
Return the MCSchedClassDesc for this instruction.
bool isEmpty() const
Returns true if there are no itineraries.
TargetSubtargetInfo - Generic base class for all target subtargets.
static double getReciprocalThroughput(const MCSubtargetInfo &STI, const MCSchedClassDesc &SCDesc)
Representation of each machine instruction.
static int computeInstrLatency(const MCSubtargetInfo &STI, const MCSchedClassDesc &SCDesc)
Returns the latency value for the scheduling class.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
static cl::opt< bool > EnableSchedModel("schedmodel", cl::Hidden, cl::init(true), cl::desc("Use TargetSchedModel for latency lookup"))
const MCWriteProcResEntry * getWriteProcResBegin(const MCSchedClassDesc *SC) const
Return an iterator at the first process resource consumed by the given scheduling class...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
int getReadAdvanceCycles(const MCSchedClassDesc *SC, unsigned UseIdx, unsigned WriteResID) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCOperandInfo * OpInfo
int getOperandCycle(unsigned ItinClassIndx, unsigned OperandIdx) const
Return the cycle for the given class and operand.
unsigned getOpcode() const
const MachineOperand & getOperand(unsigned i) const
static unsigned findDefIdx(const MachineInstr *MI, unsigned DefOperIdx)
Find the def index of this operand.
virtual int getOperandLatency(const InstrItineraryData *ItinData, SDNode *DefNode, unsigned DefIdx, SDNode *UseNode, unsigned UseIdx) const
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
static unsigned capLatency(int Cycles)
unsigned getNumProcResourceKinds() const