17a7e6055SDimitry Andric //===- llvm/Target/TargetSchedule.cpp - Sched Machine Model ---------------===//
23861d79fSDimitry Andric //
33861d79fSDimitry Andric //                     The LLVM Compiler Infrastructure
43861d79fSDimitry Andric //
53861d79fSDimitry Andric // This file is distributed under the University of Illinois Open Source
63861d79fSDimitry Andric // License. See LICENSE.TXT for details.
73861d79fSDimitry Andric //
83861d79fSDimitry Andric //===----------------------------------------------------------------------===//
93861d79fSDimitry Andric //
103861d79fSDimitry Andric // This file implements a wrapper around MCSchedModel that allows the interface
113861d79fSDimitry Andric // to benefit from information currently only available in TargetInstrInfo.
123861d79fSDimitry Andric //
133861d79fSDimitry Andric //===----------------------------------------------------------------------===//
143861d79fSDimitry Andric 
15db17bf38SDimitry Andric #include "llvm/CodeGen/TargetSchedule.h"
167a7e6055SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
177a7e6055SDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
187a7e6055SDimitry Andric #include "llvm/CodeGen/MachineOperand.h"
192cab237bSDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
202cab237bSDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
212cab237bSDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
227a7e6055SDimitry Andric #include "llvm/MC/MCInstrDesc.h"
237a7e6055SDimitry Andric #include "llvm/MC/MCInstrItineraries.h"
247a7e6055SDimitry Andric #include "llvm/MC/MCSchedule.h"
25139f7f9bSDimitry Andric #include "llvm/Support/CommandLine.h"
267a7e6055SDimitry Andric #include "llvm/Support/ErrorHandling.h"
27139f7f9bSDimitry Andric #include "llvm/Support/raw_ostream.h"
287a7e6055SDimitry Andric #include <algorithm>
297a7e6055SDimitry Andric #include <cassert>
307a7e6055SDimitry Andric #include <cstdint>
313861d79fSDimitry Andric 
323861d79fSDimitry Andric using namespace llvm;
333861d79fSDimitry Andric 
343861d79fSDimitry Andric static cl::opt<bool> EnableSchedModel("schedmodel", cl::Hidden, cl::init(true),
353861d79fSDimitry Andric   cl::desc("Use TargetSchedModel for latency lookup"));
363861d79fSDimitry Andric 
373861d79fSDimitry Andric static cl::opt<bool> EnableSchedItins("scheditins", cl::Hidden, cl::init(true),
383861d79fSDimitry Andric   cl::desc("Use InstrItineraryData for latency lookup"));
393861d79fSDimitry Andric 
hasInstrSchedModel() const403861d79fSDimitry Andric bool TargetSchedModel::hasInstrSchedModel() const {
413861d79fSDimitry Andric   return EnableSchedModel && SchedModel.hasInstrSchedModel();
423861d79fSDimitry Andric }
433861d79fSDimitry Andric 
hasInstrItineraries() const443861d79fSDimitry Andric bool TargetSchedModel::hasInstrItineraries() const {
453861d79fSDimitry Andric   return EnableSchedItins && !InstrItins.isEmpty();
463861d79fSDimitry Andric }
473861d79fSDimitry Andric 
gcd(unsigned Dividend,unsigned Divisor)483861d79fSDimitry Andric static unsigned gcd(unsigned Dividend, unsigned Divisor) {
493861d79fSDimitry Andric   // Dividend and Divisor will be naturally swapped as needed.
503861d79fSDimitry Andric   while (Divisor) {
513861d79fSDimitry Andric     unsigned Rem = Dividend % Divisor;
523861d79fSDimitry Andric     Dividend = Divisor;
533861d79fSDimitry Andric     Divisor = Rem;
543861d79fSDimitry Andric   };
553861d79fSDimitry Andric   return Dividend;
563861d79fSDimitry Andric }
577a7e6055SDimitry Andric 
lcm(unsigned A,unsigned B)583861d79fSDimitry Andric static unsigned lcm(unsigned A, unsigned B) {
593861d79fSDimitry Andric   unsigned LCM = (uint64_t(A) * B) / gcd(A, B);
603861d79fSDimitry Andric   assert((LCM >= A && LCM >= B) && "LCM overflow");
613861d79fSDimitry Andric   return LCM;
623861d79fSDimitry Andric }
633861d79fSDimitry Andric 
init(const TargetSubtargetInfo * TSInfo)64*4ba319b5SDimitry Andric void TargetSchedModel::init(const TargetSubtargetInfo *TSInfo) {
65*4ba319b5SDimitry Andric   STI = TSInfo;
66*4ba319b5SDimitry Andric   SchedModel = TSInfo->getSchedModel();
67*4ba319b5SDimitry Andric   TII = TSInfo->getInstrInfo();
683861d79fSDimitry Andric   STI->initInstrItins(InstrItins);
693861d79fSDimitry Andric 
703861d79fSDimitry Andric   unsigned NumRes = SchedModel.getNumProcResourceKinds();
713861d79fSDimitry Andric   ResourceFactors.resize(NumRes);
723861d79fSDimitry Andric   ResourceLCM = SchedModel.IssueWidth;
733861d79fSDimitry Andric   for (unsigned Idx = 0; Idx < NumRes; ++Idx) {
743861d79fSDimitry Andric     unsigned NumUnits = SchedModel.getProcResource(Idx)->NumUnits;
753861d79fSDimitry Andric     if (NumUnits > 0)
763861d79fSDimitry Andric       ResourceLCM = lcm(ResourceLCM, NumUnits);
773861d79fSDimitry Andric   }
783861d79fSDimitry Andric   MicroOpFactor = ResourceLCM / SchedModel.IssueWidth;
793861d79fSDimitry Andric   for (unsigned Idx = 0; Idx < NumRes; ++Idx) {
803861d79fSDimitry Andric     unsigned NumUnits = SchedModel.getProcResource(Idx)->NumUnits;
813861d79fSDimitry Andric     ResourceFactors[Idx] = NumUnits ? (ResourceLCM / NumUnits) : 0;
823861d79fSDimitry Andric   }
833861d79fSDimitry Andric }
843861d79fSDimitry Andric 
857a7e6055SDimitry Andric /// Returns true only if instruction is specified as single issue.
mustBeginGroup(const MachineInstr * MI,const MCSchedClassDesc * SC) const867a7e6055SDimitry Andric bool TargetSchedModel::mustBeginGroup(const MachineInstr *MI,
877a7e6055SDimitry Andric                                      const MCSchedClassDesc *SC) const {
887a7e6055SDimitry Andric   if (hasInstrSchedModel()) {
897a7e6055SDimitry Andric     if (!SC)
907a7e6055SDimitry Andric       SC = resolveSchedClass(MI);
917a7e6055SDimitry Andric     if (SC->isValid())
927a7e6055SDimitry Andric       return SC->BeginGroup;
937a7e6055SDimitry Andric   }
947a7e6055SDimitry Andric   return false;
957a7e6055SDimitry Andric }
967a7e6055SDimitry Andric 
mustEndGroup(const MachineInstr * MI,const MCSchedClassDesc * SC) const977a7e6055SDimitry Andric bool TargetSchedModel::mustEndGroup(const MachineInstr *MI,
987a7e6055SDimitry Andric                                      const MCSchedClassDesc *SC) const {
997a7e6055SDimitry Andric   if (hasInstrSchedModel()) {
1007a7e6055SDimitry Andric     if (!SC)
1017a7e6055SDimitry Andric       SC = resolveSchedClass(MI);
1027a7e6055SDimitry Andric     if (SC->isValid())
1037a7e6055SDimitry Andric       return SC->EndGroup;
1047a7e6055SDimitry Andric   }
1057a7e6055SDimitry Andric   return false;
1067a7e6055SDimitry Andric }
1077a7e6055SDimitry Andric 
getNumMicroOps(const MachineInstr * MI,const MCSchedClassDesc * SC) const1083861d79fSDimitry Andric unsigned TargetSchedModel::getNumMicroOps(const MachineInstr *MI,
1093861d79fSDimitry Andric                                           const MCSchedClassDesc *SC) const {
1103861d79fSDimitry Andric   if (hasInstrItineraries()) {
1113861d79fSDimitry Andric     int UOps = InstrItins.getNumMicroOps(MI->getDesc().getSchedClass());
1123ca95b02SDimitry Andric     return (UOps >= 0) ? UOps : TII->getNumMicroOps(&InstrItins, *MI);
1133861d79fSDimitry Andric   }
1143861d79fSDimitry Andric   if (hasInstrSchedModel()) {
1153861d79fSDimitry Andric     if (!SC)
1163861d79fSDimitry Andric       SC = resolveSchedClass(MI);
1173861d79fSDimitry Andric     if (SC->isValid())
1183861d79fSDimitry Andric       return SC->NumMicroOps;
1193861d79fSDimitry Andric   }
1203861d79fSDimitry Andric   return MI->isTransient() ? 0 : 1;
1213861d79fSDimitry Andric }
1223861d79fSDimitry Andric 
1233861d79fSDimitry Andric // The machine model may explicitly specify an invalid latency, which
1243861d79fSDimitry Andric // effectively means infinite latency. Since users of the TargetSchedule API
1253861d79fSDimitry Andric // don't know how to handle this, we convert it to a very large latency that is
1263861d79fSDimitry Andric // easy to distinguish when debugging the DAG but won't induce overflow.
capLatency(int Cycles)127f785676fSDimitry Andric static unsigned capLatency(int Cycles) {
1283861d79fSDimitry Andric   return Cycles >= 0 ? Cycles : 1000;
1293861d79fSDimitry Andric }
1303861d79fSDimitry Andric 
1313861d79fSDimitry Andric /// Return the MCSchedClassDesc for this instruction. Some SchedClasses require
1323861d79fSDimitry Andric /// evaluation of predicates that depend on instruction operands or flags.
1333861d79fSDimitry Andric const MCSchedClassDesc *TargetSchedModel::
resolveSchedClass(const MachineInstr * MI) const1343861d79fSDimitry Andric resolveSchedClass(const MachineInstr *MI) const {
1353861d79fSDimitry Andric   // Get the definition's scheduling class descriptor from this machine model.
1363861d79fSDimitry Andric   unsigned SchedClass = MI->getDesc().getSchedClass();
1373861d79fSDimitry Andric   const MCSchedClassDesc *SCDesc = SchedModel.getSchedClassDesc(SchedClass);
138284c1978SDimitry Andric   if (!SCDesc->isValid())
139284c1978SDimitry Andric     return SCDesc;
1403861d79fSDimitry Andric 
1413861d79fSDimitry Andric #ifndef NDEBUG
1423861d79fSDimitry Andric   unsigned NIter = 0;
1433861d79fSDimitry Andric #endif
1443861d79fSDimitry Andric   while (SCDesc->isVariant()) {
1453861d79fSDimitry Andric     assert(++NIter < 6 && "Variants are nested deeper than the magic number");
1463861d79fSDimitry Andric 
1473861d79fSDimitry Andric     SchedClass = STI->resolveSchedClass(SchedClass, MI, this);
1483861d79fSDimitry Andric     SCDesc = SchedModel.getSchedClassDesc(SchedClass);
1493861d79fSDimitry Andric   }
1503861d79fSDimitry Andric   return SCDesc;
1513861d79fSDimitry Andric }
1523861d79fSDimitry Andric 
1533861d79fSDimitry Andric /// Find the def index of this operand. This index maps to the machine model and
1543861d79fSDimitry Andric /// is independent of use operands. Def operands may be reordered with uses or
1553861d79fSDimitry Andric /// merged with uses without affecting the def index (e.g. before/after
1563861d79fSDimitry Andric /// regalloc). However, an instruction's def operands must never be reordered
1573861d79fSDimitry Andric /// with respect to each other.
findDefIdx(const MachineInstr * MI,unsigned DefOperIdx)1583861d79fSDimitry Andric static unsigned findDefIdx(const MachineInstr *MI, unsigned DefOperIdx) {
1593861d79fSDimitry Andric   unsigned DefIdx = 0;
1603861d79fSDimitry Andric   for (unsigned i = 0; i != DefOperIdx; ++i) {
1613861d79fSDimitry Andric     const MachineOperand &MO = MI->getOperand(i);
1623861d79fSDimitry Andric     if (MO.isReg() && MO.isDef())
1633861d79fSDimitry Andric       ++DefIdx;
1643861d79fSDimitry Andric   }
1653861d79fSDimitry Andric   return DefIdx;
1663861d79fSDimitry Andric }
1673861d79fSDimitry Andric 
1683861d79fSDimitry Andric /// Find the use index of this operand. This is independent of the instruction's
1693861d79fSDimitry Andric /// def operands.
1703861d79fSDimitry Andric ///
1713861d79fSDimitry Andric /// Note that uses are not determined by the operand's isUse property, which
1723861d79fSDimitry Andric /// is simply the inverse of isDef. Here we consider any readsReg operand to be
1733861d79fSDimitry Andric /// a "use". The machine model allows an operand to be both a Def and Use.
findUseIdx(const MachineInstr * MI,unsigned UseOperIdx)1743861d79fSDimitry Andric static unsigned findUseIdx(const MachineInstr *MI, unsigned UseOperIdx) {
1753861d79fSDimitry Andric   unsigned UseIdx = 0;
1763861d79fSDimitry Andric   for (unsigned i = 0; i != UseOperIdx; ++i) {
1773861d79fSDimitry Andric     const MachineOperand &MO = MI->getOperand(i);
178d88c1a5aSDimitry Andric     if (MO.isReg() && MO.readsReg() && !MO.isDef())
1793861d79fSDimitry Andric       ++UseIdx;
1803861d79fSDimitry Andric   }
1813861d79fSDimitry Andric   return UseIdx;
1823861d79fSDimitry Andric }
1833861d79fSDimitry Andric 
1843861d79fSDimitry Andric // Top-level API for clients that know the operand indices.
computeOperandLatency(const MachineInstr * DefMI,unsigned DefOperIdx,const MachineInstr * UseMI,unsigned UseOperIdx) const1853861d79fSDimitry Andric unsigned TargetSchedModel::computeOperandLatency(
1863861d79fSDimitry Andric   const MachineInstr *DefMI, unsigned DefOperIdx,
187f785676fSDimitry Andric   const MachineInstr *UseMI, unsigned UseOperIdx) const {
1883861d79fSDimitry Andric 
189f785676fSDimitry Andric   if (!hasInstrSchedModel() && !hasInstrItineraries())
1903ca95b02SDimitry Andric     return TII->defaultDefLatency(SchedModel, *DefMI);
1913861d79fSDimitry Andric 
1923861d79fSDimitry Andric   if (hasInstrItineraries()) {
1933861d79fSDimitry Andric     int OperLatency = 0;
1943861d79fSDimitry Andric     if (UseMI) {
1953ca95b02SDimitry Andric       OperLatency = TII->getOperandLatency(&InstrItins, *DefMI, DefOperIdx,
1963ca95b02SDimitry Andric                                            *UseMI, UseOperIdx);
1973861d79fSDimitry Andric     }
1983861d79fSDimitry Andric     else {
1993861d79fSDimitry Andric       unsigned DefClass = DefMI->getDesc().getSchedClass();
2003861d79fSDimitry Andric       OperLatency = InstrItins.getOperandCycle(DefClass, DefOperIdx);
2013861d79fSDimitry Andric     }
2023861d79fSDimitry Andric     if (OperLatency >= 0)
2033861d79fSDimitry Andric       return OperLatency;
2043861d79fSDimitry Andric 
2053861d79fSDimitry Andric     // No operand latency was found.
2063ca95b02SDimitry Andric     unsigned InstrLatency = TII->getInstrLatency(&InstrItins, *DefMI);
2073861d79fSDimitry Andric 
2083861d79fSDimitry Andric     // Expected latency is the max of the stage latency and itinerary props.
2093861d79fSDimitry Andric     // Rather than directly querying InstrItins stage latency, we call a TII
2103861d79fSDimitry Andric     // hook to allow subtargets to specialize latency. This hook is only
2113861d79fSDimitry Andric     // applicable to the InstrItins model. InstrSchedModel should model all
2123861d79fSDimitry Andric     // special cases without TII hooks.
2133ca95b02SDimitry Andric     InstrLatency =
2143ca95b02SDimitry Andric         std::max(InstrLatency, TII->defaultDefLatency(SchedModel, *DefMI));
2153861d79fSDimitry Andric     return InstrLatency;
2163861d79fSDimitry Andric   }
217f785676fSDimitry Andric   // hasInstrSchedModel()
2183861d79fSDimitry Andric   const MCSchedClassDesc *SCDesc = resolveSchedClass(DefMI);
2193861d79fSDimitry Andric   unsigned DefIdx = findDefIdx(DefMI, DefOperIdx);
2203861d79fSDimitry Andric   if (DefIdx < SCDesc->NumWriteLatencyEntries) {
2213861d79fSDimitry Andric     // Lookup the definition's write latency in SubtargetInfo.
2223861d79fSDimitry Andric     const MCWriteLatencyEntry *WLEntry =
2233861d79fSDimitry Andric       STI->getWriteLatencyEntry(SCDesc, DefIdx);
2243861d79fSDimitry Andric     unsigned WriteID = WLEntry->WriteResourceID;
225f785676fSDimitry Andric     unsigned Latency = capLatency(WLEntry->Cycles);
2263861d79fSDimitry Andric     if (!UseMI)
2273861d79fSDimitry Andric       return Latency;
2283861d79fSDimitry Andric 
2293861d79fSDimitry Andric     // Lookup the use's latency adjustment in SubtargetInfo.
2303861d79fSDimitry Andric     const MCSchedClassDesc *UseDesc = resolveSchedClass(UseMI);
2313861d79fSDimitry Andric     if (UseDesc->NumReadAdvanceEntries == 0)
2323861d79fSDimitry Andric       return Latency;
2333861d79fSDimitry Andric     unsigned UseIdx = findUseIdx(UseMI, UseOperIdx);
234f785676fSDimitry Andric     int Advance = STI->getReadAdvanceCycles(UseDesc, UseIdx, WriteID);
235f785676fSDimitry Andric     if (Advance > 0 && (unsigned)Advance > Latency) // unsigned wrap
236f785676fSDimitry Andric       return 0;
237f785676fSDimitry Andric     return Latency - Advance;
2383861d79fSDimitry Andric   }
2393861d79fSDimitry Andric   // If DefIdx does not exist in the model (e.g. implicit defs), then return
2403861d79fSDimitry Andric   // unit latency (defaultDefLatency may be too conservative).
2413861d79fSDimitry Andric #ifndef NDEBUG
2423861d79fSDimitry Andric   if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit()
243f785676fSDimitry Andric       && !DefMI->getDesc().OpInfo[DefOperIdx].isOptionalDef()
244f785676fSDimitry Andric       && SchedModel.isComplete()) {
2457d523365SDimitry Andric     errs() << "DefIdx " << DefIdx << " exceeds machine model writes for "
2464d0b32cdSDimitry Andric            << *DefMI << " (Try with MCSchedModel.CompleteModel set to false)";
2477d523365SDimitry Andric     llvm_unreachable("incomplete machine model");
2483861d79fSDimitry Andric   }
2493861d79fSDimitry Andric #endif
250139f7f9bSDimitry Andric   // FIXME: Automatically giving all implicit defs defaultDefLatency is
251139f7f9bSDimitry Andric   // undesirable. We should only do it for defs that are known to the MC
252139f7f9bSDimitry Andric   // desc like flags. Truly implicit defs should get 1 cycle latency.
2533ca95b02SDimitry Andric   return DefMI->isTransient() ? 0 : TII->defaultDefLatency(SchedModel, *DefMI);
25439d628a0SDimitry Andric }
25539d628a0SDimitry Andric 
256ff0cc061SDimitry Andric unsigned
computeInstrLatency(const MCSchedClassDesc & SCDesc) const257ff0cc061SDimitry Andric TargetSchedModel::computeInstrLatency(const MCSchedClassDesc &SCDesc) const {
258*4ba319b5SDimitry Andric   return capLatency(MCSchedModel::computeInstrLatency(*STI, SCDesc));
25939d628a0SDimitry Andric }
26039d628a0SDimitry Andric 
computeInstrLatency(unsigned Opcode) const261ff0cc061SDimitry Andric unsigned TargetSchedModel::computeInstrLatency(unsigned Opcode) const {
262ff0cc061SDimitry Andric   assert(hasInstrSchedModel() && "Only call this function with a SchedModel");
263ff0cc061SDimitry Andric   unsigned SCIdx = TII->get(Opcode).getSchedClass();
264*4ba319b5SDimitry Andric   return capLatency(SchedModel.computeInstrLatency(*STI, SCIdx));
2657a7e6055SDimitry Andric }
266*4ba319b5SDimitry Andric 
computeInstrLatency(const MCInst & Inst) const267*4ba319b5SDimitry Andric unsigned TargetSchedModel::computeInstrLatency(const MCInst &Inst) const {
268*4ba319b5SDimitry Andric   if (hasInstrSchedModel())
269*4ba319b5SDimitry Andric     return capLatency(SchedModel.computeInstrLatency(*STI, *TII, Inst));
270*4ba319b5SDimitry Andric   return computeInstrLatency(Inst.getOpcode());
2713861d79fSDimitry Andric }
2723861d79fSDimitry Andric 
273f785676fSDimitry Andric unsigned
computeInstrLatency(const MachineInstr * MI,bool UseDefaultDefLatency) const274f785676fSDimitry Andric TargetSchedModel::computeInstrLatency(const MachineInstr *MI,
275f785676fSDimitry Andric                                       bool UseDefaultDefLatency) const {
2763861d79fSDimitry Andric   // For the itinerary model, fall back to the old subtarget hook.
2773861d79fSDimitry Andric   // Allow subtargets to compute Bundle latencies outside the machine model.
278f785676fSDimitry Andric   if (hasInstrItineraries() || MI->isBundle() ||
279f785676fSDimitry Andric       (!hasInstrSchedModel() && !UseDefaultDefLatency))
2803ca95b02SDimitry Andric     return TII->getInstrLatency(&InstrItins, *MI);
2813861d79fSDimitry Andric 
2823861d79fSDimitry Andric   if (hasInstrSchedModel()) {
2833861d79fSDimitry Andric     const MCSchedClassDesc *SCDesc = resolveSchedClass(MI);
284ff0cc061SDimitry Andric     if (SCDesc->isValid())
285ff0cc061SDimitry Andric       return computeInstrLatency(*SCDesc);
2863861d79fSDimitry Andric   }
2873ca95b02SDimitry Andric   return TII->defaultDefLatency(SchedModel, *MI);
2883861d79fSDimitry Andric }
2893861d79fSDimitry Andric 
2903861d79fSDimitry Andric unsigned TargetSchedModel::
computeOutputLatency(const MachineInstr * DefMI,unsigned DefOperIdx,const MachineInstr * DepMI) const2913861d79fSDimitry Andric computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
2923861d79fSDimitry Andric                      const MachineInstr *DepMI) const {
2933ca95b02SDimitry Andric   if (!SchedModel.isOutOfOrder())
2943861d79fSDimitry Andric     return 1;
2953861d79fSDimitry Andric 
2963ca95b02SDimitry Andric   // Out-of-order processor can dispatch WAW dependencies in the same cycle.
2973861d79fSDimitry Andric 
2983861d79fSDimitry Andric   // Treat predication as a data dependency for out-of-order cpus. In-order
2993861d79fSDimitry Andric   // cpus do not need to treat predicated writes specially.
3003861d79fSDimitry Andric   //
3013861d79fSDimitry Andric   // TODO: The following hack exists because predication passes do not
3023861d79fSDimitry Andric   // correctly append imp-use operands, and readsReg() strangely returns false
3033861d79fSDimitry Andric   // for predicated defs.
3043861d79fSDimitry Andric   unsigned Reg = DefMI->getOperand(DefOperIdx).getReg();
3052cab237bSDimitry Andric   const MachineFunction &MF = *DefMI->getMF();
30639d628a0SDimitry Andric   const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
3073ca95b02SDimitry Andric   if (!DepMI->readsRegister(Reg, TRI) && TII->isPredicated(*DepMI))
3083861d79fSDimitry Andric     return computeInstrLatency(DefMI);
3093861d79fSDimitry Andric 
3103861d79fSDimitry Andric   // If we have a per operand scheduling model, check if this def is writing
3113861d79fSDimitry Andric   // an unbuffered resource. If so, it treated like an in-order cpu.
3123861d79fSDimitry Andric   if (hasInstrSchedModel()) {
3133861d79fSDimitry Andric     const MCSchedClassDesc *SCDesc = resolveSchedClass(DefMI);
3143861d79fSDimitry Andric     if (SCDesc->isValid()) {
3153861d79fSDimitry Andric       for (const MCWriteProcResEntry *PRI = STI->getWriteProcResBegin(SCDesc),
3163861d79fSDimitry Andric              *PRE = STI->getWriteProcResEnd(SCDesc); PRI != PRE; ++PRI) {
317f785676fSDimitry Andric         if (!SchedModel.getProcResource(PRI->ProcResourceIdx)->BufferSize)
3183861d79fSDimitry Andric           return 1;
3193861d79fSDimitry Andric       }
3203861d79fSDimitry Andric     }
3213861d79fSDimitry Andric   }
3223861d79fSDimitry Andric   return 0;
3233861d79fSDimitry Andric }
3247a7e6055SDimitry Andric 
325*4ba319b5SDimitry Andric double
computeReciprocalThroughput(const MachineInstr * MI) const326*4ba319b5SDimitry Andric TargetSchedModel::computeReciprocalThroughput(const MachineInstr *MI) const {
327*4ba319b5SDimitry Andric   if (hasInstrItineraries()) {
328*4ba319b5SDimitry Andric     unsigned SchedClass = MI->getDesc().getSchedClass();
329*4ba319b5SDimitry Andric     return MCSchedModel::getReciprocalThroughput(SchedClass,
330*4ba319b5SDimitry Andric                                                  *getInstrItineraries());
3317a7e6055SDimitry Andric   }
3327a7e6055SDimitry Andric 
3337a7e6055SDimitry Andric   if (hasInstrSchedModel())
334*4ba319b5SDimitry Andric     return MCSchedModel::getReciprocalThroughput(*STI, *resolveSchedClass(MI));
335*4ba319b5SDimitry Andric 
336*4ba319b5SDimitry Andric   return 0.0;
3377a7e6055SDimitry Andric }
3387a7e6055SDimitry Andric 
339*4ba319b5SDimitry Andric double
computeReciprocalThroughput(unsigned Opcode) const340*4ba319b5SDimitry Andric TargetSchedModel::computeReciprocalThroughput(unsigned Opcode) const {
3417a7e6055SDimitry Andric   unsigned SchedClass = TII->get(Opcode).getSchedClass();
3427a7e6055SDimitry Andric   if (hasInstrItineraries())
343*4ba319b5SDimitry Andric     return MCSchedModel::getReciprocalThroughput(SchedClass,
344*4ba319b5SDimitry Andric                                                  *getInstrItineraries());
3457a7e6055SDimitry Andric   if (hasInstrSchedModel()) {
346*4ba319b5SDimitry Andric     const MCSchedClassDesc &SCDesc = *SchedModel.getSchedClassDesc(SchedClass);
347*4ba319b5SDimitry Andric     if (SCDesc.isValid() && !SCDesc.isVariant())
348*4ba319b5SDimitry Andric       return MCSchedModel::getReciprocalThroughput(*STI, SCDesc);
3497a7e6055SDimitry Andric   }
350*4ba319b5SDimitry Andric 
351*4ba319b5SDimitry Andric   return 0.0;
3527a7e6055SDimitry Andric }
353*4ba319b5SDimitry Andric 
354*4ba319b5SDimitry Andric double
computeReciprocalThroughput(const MCInst & MI) const355*4ba319b5SDimitry Andric TargetSchedModel::computeReciprocalThroughput(const MCInst &MI) const {
356*4ba319b5SDimitry Andric   if (hasInstrSchedModel())
357*4ba319b5SDimitry Andric     return SchedModel.getReciprocalThroughput(*STI, *TII, MI);
358*4ba319b5SDimitry Andric   return computeReciprocalThroughput(MI.getOpcode());
359*4ba319b5SDimitry Andric }
360*4ba319b5SDimitry Andric 
361