xref: /src/contrib/llvm-project/llvm/lib/CodeGen/TargetSchedule.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
171d5a254SDimitry Andric //===- llvm/Target/TargetSchedule.cpp - Sched Machine Model ---------------===//
2522600a2SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6522600a2SDimitry Andric //
7522600a2SDimitry Andric //===----------------------------------------------------------------------===//
8522600a2SDimitry Andric //
9522600a2SDimitry Andric // This file implements a wrapper around MCSchedModel that allows the interface
10522600a2SDimitry Andric // to benefit from information currently only available in TargetInstrInfo.
11522600a2SDimitry Andric //
12522600a2SDimitry Andric //===----------------------------------------------------------------------===//
13522600a2SDimitry Andric 
147ab83427SDimitry Andric #include "llvm/CodeGen/TargetSchedule.h"
1571d5a254SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
1671d5a254SDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
1771d5a254SDimitry Andric #include "llvm/CodeGen/MachineOperand.h"
18044eb2f6SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
19044eb2f6SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
2071d5a254SDimitry Andric #include "llvm/MC/MCInstrDesc.h"
2171d5a254SDimitry Andric #include "llvm/MC/MCInstrItineraries.h"
2271d5a254SDimitry Andric #include "llvm/MC/MCSchedule.h"
234a16efa3SDimitry Andric #include "llvm/Support/CommandLine.h"
2471d5a254SDimitry Andric #include "llvm/Support/ErrorHandling.h"
254a16efa3SDimitry Andric #include "llvm/Support/raw_ostream.h"
2671d5a254SDimitry Andric #include <algorithm>
2771d5a254SDimitry Andric #include <cassert>
2871d5a254SDimitry Andric #include <cstdint>
29e3b55780SDimitry Andric #include <numeric>
30522600a2SDimitry Andric 
31522600a2SDimitry Andric using namespace llvm;
32522600a2SDimitry Andric 
33522600a2SDimitry Andric static cl::opt<bool> EnableSchedModel("schedmodel", cl::Hidden, cl::init(true),
34522600a2SDimitry Andric   cl::desc("Use TargetSchedModel for latency lookup"));
35522600a2SDimitry Andric 
36522600a2SDimitry Andric static cl::opt<bool> EnableSchedItins("scheditins", cl::Hidden, cl::init(true),
37522600a2SDimitry Andric   cl::desc("Use InstrItineraryData for latency lookup"));
38522600a2SDimitry Andric 
39b1c73532SDimitry Andric static cl::opt<bool> ForceEnableIntervals(
40b1c73532SDimitry Andric     "sched-model-force-enable-intervals", cl::Hidden, cl::init(false),
41b1c73532SDimitry Andric     cl::desc("Force the use of resource intervals in the schedule model"));
42b1c73532SDimitry Andric 
hasInstrSchedModel() const43522600a2SDimitry Andric bool TargetSchedModel::hasInstrSchedModel() const {
44522600a2SDimitry Andric   return EnableSchedModel && SchedModel.hasInstrSchedModel();
45522600a2SDimitry Andric }
46522600a2SDimitry Andric 
hasInstrItineraries() const47522600a2SDimitry Andric bool TargetSchedModel::hasInstrItineraries() const {
48522600a2SDimitry Andric   return EnableSchedItins && !InstrItins.isEmpty();
49522600a2SDimitry Andric }
50522600a2SDimitry Andric 
init(const TargetSubtargetInfo * TSInfo)51eb11fae6SDimitry Andric void TargetSchedModel::init(const TargetSubtargetInfo *TSInfo) {
52eb11fae6SDimitry Andric   STI = TSInfo;
53eb11fae6SDimitry Andric   SchedModel = TSInfo->getSchedModel();
54eb11fae6SDimitry Andric   TII = TSInfo->getInstrInfo();
55522600a2SDimitry Andric   STI->initInstrItins(InstrItins);
56522600a2SDimitry Andric 
57522600a2SDimitry Andric   unsigned NumRes = SchedModel.getNumProcResourceKinds();
58522600a2SDimitry Andric   ResourceFactors.resize(NumRes);
59522600a2SDimitry Andric   ResourceLCM = SchedModel.IssueWidth;
60522600a2SDimitry Andric   for (unsigned Idx = 0; Idx < NumRes; ++Idx) {
61522600a2SDimitry Andric     unsigned NumUnits = SchedModel.getProcResource(Idx)->NumUnits;
62522600a2SDimitry Andric     if (NumUnits > 0)
63e3b55780SDimitry Andric       ResourceLCM = std::lcm(ResourceLCM, NumUnits);
64522600a2SDimitry Andric   }
65522600a2SDimitry Andric   MicroOpFactor = ResourceLCM / SchedModel.IssueWidth;
66522600a2SDimitry Andric   for (unsigned Idx = 0; Idx < NumRes; ++Idx) {
67522600a2SDimitry Andric     unsigned NumUnits = SchedModel.getProcResource(Idx)->NumUnits;
68522600a2SDimitry Andric     ResourceFactors[Idx] = NumUnits ? (ResourceLCM / NumUnits) : 0;
69522600a2SDimitry Andric   }
70522600a2SDimitry Andric }
71522600a2SDimitry Andric 
7271d5a254SDimitry Andric /// Returns true only if instruction is specified as single issue.
mustBeginGroup(const MachineInstr * MI,const MCSchedClassDesc * SC) const7371d5a254SDimitry Andric bool TargetSchedModel::mustBeginGroup(const MachineInstr *MI,
7471d5a254SDimitry Andric                                      const MCSchedClassDesc *SC) const {
7571d5a254SDimitry Andric   if (hasInstrSchedModel()) {
7671d5a254SDimitry Andric     if (!SC)
7771d5a254SDimitry Andric       SC = resolveSchedClass(MI);
7871d5a254SDimitry Andric     if (SC->isValid())
7971d5a254SDimitry Andric       return SC->BeginGroup;
8071d5a254SDimitry Andric   }
8171d5a254SDimitry Andric   return false;
8271d5a254SDimitry Andric }
8371d5a254SDimitry Andric 
mustEndGroup(const MachineInstr * MI,const MCSchedClassDesc * SC) const8471d5a254SDimitry Andric bool TargetSchedModel::mustEndGroup(const MachineInstr *MI,
8571d5a254SDimitry Andric                                      const MCSchedClassDesc *SC) const {
8671d5a254SDimitry Andric   if (hasInstrSchedModel()) {
8771d5a254SDimitry Andric     if (!SC)
8871d5a254SDimitry Andric       SC = resolveSchedClass(MI);
8971d5a254SDimitry Andric     if (SC->isValid())
9071d5a254SDimitry Andric       return SC->EndGroup;
9171d5a254SDimitry Andric   }
9271d5a254SDimitry Andric   return false;
9371d5a254SDimitry Andric }
9471d5a254SDimitry Andric 
getNumMicroOps(const MachineInstr * MI,const MCSchedClassDesc * SC) const95522600a2SDimitry Andric unsigned TargetSchedModel::getNumMicroOps(const MachineInstr *MI,
96522600a2SDimitry Andric                                           const MCSchedClassDesc *SC) const {
97522600a2SDimitry Andric   if (hasInstrItineraries()) {
98522600a2SDimitry Andric     int UOps = InstrItins.getNumMicroOps(MI->getDesc().getSchedClass());
9901095a5dSDimitry Andric     return (UOps >= 0) ? UOps : TII->getNumMicroOps(&InstrItins, *MI);
100522600a2SDimitry Andric   }
101522600a2SDimitry Andric   if (hasInstrSchedModel()) {
102522600a2SDimitry Andric     if (!SC)
103522600a2SDimitry Andric       SC = resolveSchedClass(MI);
104522600a2SDimitry Andric     if (SC->isValid())
105522600a2SDimitry Andric       return SC->NumMicroOps;
106522600a2SDimitry Andric   }
107522600a2SDimitry Andric   return MI->isTransient() ? 0 : 1;
108522600a2SDimitry Andric }
109522600a2SDimitry Andric 
110522600a2SDimitry Andric // The machine model may explicitly specify an invalid latency, which
111522600a2SDimitry Andric // effectively means infinite latency. Since users of the TargetSchedule API
112522600a2SDimitry Andric // don't know how to handle this, we convert it to a very large latency that is
113522600a2SDimitry Andric // easy to distinguish when debugging the DAG but won't induce overflow.
capLatency(int Cycles)114f8af5cf6SDimitry Andric static unsigned capLatency(int Cycles) {
115522600a2SDimitry Andric   return Cycles >= 0 ? Cycles : 1000;
116522600a2SDimitry Andric }
117522600a2SDimitry Andric 
118522600a2SDimitry Andric /// Return the MCSchedClassDesc for this instruction. Some SchedClasses require
119522600a2SDimitry Andric /// evaluation of predicates that depend on instruction operands or flags.
120522600a2SDimitry Andric const MCSchedClassDesc *TargetSchedModel::
resolveSchedClass(const MachineInstr * MI) const121522600a2SDimitry Andric resolveSchedClass(const MachineInstr *MI) const {
122522600a2SDimitry Andric   // Get the definition's scheduling class descriptor from this machine model.
123522600a2SDimitry Andric   unsigned SchedClass = MI->getDesc().getSchedClass();
124522600a2SDimitry Andric   const MCSchedClassDesc *SCDesc = SchedModel.getSchedClassDesc(SchedClass);
12559d6cff9SDimitry Andric   if (!SCDesc->isValid())
12659d6cff9SDimitry Andric     return SCDesc;
127522600a2SDimitry Andric 
128522600a2SDimitry Andric #ifndef NDEBUG
129522600a2SDimitry Andric   unsigned NIter = 0;
130522600a2SDimitry Andric #endif
131522600a2SDimitry Andric   while (SCDesc->isVariant()) {
132522600a2SDimitry Andric     assert(++NIter < 6 && "Variants are nested deeper than the magic number");
133522600a2SDimitry Andric 
134522600a2SDimitry Andric     SchedClass = STI->resolveSchedClass(SchedClass, MI, this);
135522600a2SDimitry Andric     SCDesc = SchedModel.getSchedClassDesc(SchedClass);
136522600a2SDimitry Andric   }
137522600a2SDimitry Andric   return SCDesc;
138522600a2SDimitry Andric }
139522600a2SDimitry Andric 
140522600a2SDimitry Andric /// Find the def index of this operand. This index maps to the machine model and
141522600a2SDimitry Andric /// is independent of use operands. Def operands may be reordered with uses or
142522600a2SDimitry Andric /// merged with uses without affecting the def index (e.g. before/after
143522600a2SDimitry Andric /// regalloc). However, an instruction's def operands must never be reordered
144522600a2SDimitry Andric /// with respect to each other.
findDefIdx(const MachineInstr * MI,unsigned DefOperIdx)145522600a2SDimitry Andric static unsigned findDefIdx(const MachineInstr *MI, unsigned DefOperIdx) {
146522600a2SDimitry Andric   unsigned DefIdx = 0;
147522600a2SDimitry Andric   for (unsigned i = 0; i != DefOperIdx; ++i) {
148522600a2SDimitry Andric     const MachineOperand &MO = MI->getOperand(i);
149522600a2SDimitry Andric     if (MO.isReg() && MO.isDef())
150522600a2SDimitry Andric       ++DefIdx;
151522600a2SDimitry Andric   }
152522600a2SDimitry Andric   return DefIdx;
153522600a2SDimitry Andric }
154522600a2SDimitry Andric 
155522600a2SDimitry Andric /// Find the use index of this operand. This is independent of the instruction's
156522600a2SDimitry Andric /// def operands.
157522600a2SDimitry Andric ///
158522600a2SDimitry Andric /// Note that uses are not determined by the operand's isUse property, which
159522600a2SDimitry Andric /// is simply the inverse of isDef. Here we consider any readsReg operand to be
160522600a2SDimitry Andric /// a "use". The machine model allows an operand to be both a Def and Use.
findUseIdx(const MachineInstr * MI,unsigned UseOperIdx)161522600a2SDimitry Andric static unsigned findUseIdx(const MachineInstr *MI, unsigned UseOperIdx) {
162522600a2SDimitry Andric   unsigned UseIdx = 0;
163522600a2SDimitry Andric   for (unsigned i = 0; i != UseOperIdx; ++i) {
164522600a2SDimitry Andric     const MachineOperand &MO = MI->getOperand(i);
165b915e9e0SDimitry Andric     if (MO.isReg() && MO.readsReg() && !MO.isDef())
166522600a2SDimitry Andric       ++UseIdx;
167522600a2SDimitry Andric   }
168522600a2SDimitry Andric   return UseIdx;
169522600a2SDimitry Andric }
170522600a2SDimitry Andric 
171b1c73532SDimitry Andric // Top-level API for clients that know the operand indices. This doesn't need to
172b1c73532SDimitry Andric // return std::optional<unsigned>, as it always returns a valid latency.
computeOperandLatency(const MachineInstr * DefMI,unsigned DefOperIdx,const MachineInstr * UseMI,unsigned UseOperIdx) const173522600a2SDimitry Andric unsigned TargetSchedModel::computeOperandLatency(
174522600a2SDimitry Andric   const MachineInstr *DefMI, unsigned DefOperIdx,
175f8af5cf6SDimitry Andric   const MachineInstr *UseMI, unsigned UseOperIdx) const {
176522600a2SDimitry Andric 
177b1c73532SDimitry Andric   const unsigned InstrLatency = computeInstrLatency(DefMI);
178b1c73532SDimitry Andric   const unsigned DefaultDefLatency = TII->defaultDefLatency(SchedModel, *DefMI);
179b1c73532SDimitry Andric 
180f8af5cf6SDimitry Andric   if (!hasInstrSchedModel() && !hasInstrItineraries())
181b1c73532SDimitry Andric     return DefaultDefLatency;
182522600a2SDimitry Andric 
183522600a2SDimitry Andric   if (hasInstrItineraries()) {
184b1c73532SDimitry Andric     std::optional<unsigned> OperLatency;
185522600a2SDimitry Andric     if (UseMI) {
18601095a5dSDimitry Andric       OperLatency = TII->getOperandLatency(&InstrItins, *DefMI, DefOperIdx,
18701095a5dSDimitry Andric                                            *UseMI, UseOperIdx);
188522600a2SDimitry Andric     }
189522600a2SDimitry Andric     else {
190522600a2SDimitry Andric       unsigned DefClass = DefMI->getDesc().getSchedClass();
191522600a2SDimitry Andric       OperLatency = InstrItins.getOperandCycle(DefClass, DefOperIdx);
192522600a2SDimitry Andric     }
193522600a2SDimitry Andric 
194b1c73532SDimitry Andric     // Expected latency is the max of InstrLatency and DefaultDefLatency, if we
195b1c73532SDimitry Andric     // didn't find an operand latency.
196b1c73532SDimitry Andric     return OperLatency ? *OperLatency
197b1c73532SDimitry Andric                        : std::max(InstrLatency, DefaultDefLatency);
198522600a2SDimitry Andric   }
199b1c73532SDimitry Andric 
200f8af5cf6SDimitry Andric   // hasInstrSchedModel()
201522600a2SDimitry Andric   const MCSchedClassDesc *SCDesc = resolveSchedClass(DefMI);
202522600a2SDimitry Andric   unsigned DefIdx = findDefIdx(DefMI, DefOperIdx);
203522600a2SDimitry Andric   if (DefIdx < SCDesc->NumWriteLatencyEntries) {
204522600a2SDimitry Andric     // Lookup the definition's write latency in SubtargetInfo.
205522600a2SDimitry Andric     const MCWriteLatencyEntry *WLEntry =
206522600a2SDimitry Andric       STI->getWriteLatencyEntry(SCDesc, DefIdx);
207522600a2SDimitry Andric     unsigned WriteID = WLEntry->WriteResourceID;
208f8af5cf6SDimitry Andric     unsigned Latency = capLatency(WLEntry->Cycles);
209522600a2SDimitry Andric     if (!UseMI)
210522600a2SDimitry Andric       return Latency;
211522600a2SDimitry Andric 
212522600a2SDimitry Andric     // Lookup the use's latency adjustment in SubtargetInfo.
213522600a2SDimitry Andric     const MCSchedClassDesc *UseDesc = resolveSchedClass(UseMI);
214522600a2SDimitry Andric     if (UseDesc->NumReadAdvanceEntries == 0)
215522600a2SDimitry Andric       return Latency;
216522600a2SDimitry Andric     unsigned UseIdx = findUseIdx(UseMI, UseOperIdx);
217f8af5cf6SDimitry Andric     int Advance = STI->getReadAdvanceCycles(UseDesc, UseIdx, WriteID);
218f8af5cf6SDimitry Andric     if (Advance > 0 && (unsigned)Advance > Latency) // unsigned wrap
219f8af5cf6SDimitry Andric       return 0;
220f8af5cf6SDimitry Andric     return Latency - Advance;
221522600a2SDimitry Andric   }
222522600a2SDimitry Andric   // If DefIdx does not exist in the model (e.g. implicit defs), then return
223522600a2SDimitry Andric   // unit latency (defaultDefLatency may be too conservative).
224522600a2SDimitry Andric #ifndef NDEBUG
225e3b55780SDimitry Andric   if (SCDesc->isValid() && !DefMI->getOperand(DefOperIdx).isImplicit() &&
226e3b55780SDimitry Andric       !DefMI->getDesc().operands()[DefOperIdx].isOptionalDef() &&
227e3b55780SDimitry Andric       SchedModel.isComplete()) {
228dd58ef01SDimitry Andric     errs() << "DefIdx " << DefIdx << " exceeds machine model writes for "
2298a6c1c25SDimitry Andric            << *DefMI << " (Try with MCSchedModel.CompleteModel set to false)";
230dd58ef01SDimitry Andric     llvm_unreachable("incomplete machine model");
231522600a2SDimitry Andric   }
232522600a2SDimitry Andric #endif
2334a16efa3SDimitry Andric   // FIXME: Automatically giving all implicit defs defaultDefLatency is
2344a16efa3SDimitry Andric   // undesirable. We should only do it for defs that are known to the MC
2354a16efa3SDimitry Andric   // desc like flags. Truly implicit defs should get 1 cycle latency.
236b1c73532SDimitry Andric   return DefMI->isTransient() ? 0 : DefaultDefLatency;
23767c32a98SDimitry Andric }
23867c32a98SDimitry Andric 
2395a5ac124SDimitry Andric unsigned
computeInstrLatency(const MCSchedClassDesc & SCDesc) const2405a5ac124SDimitry Andric TargetSchedModel::computeInstrLatency(const MCSchedClassDesc &SCDesc) const {
241eb11fae6SDimitry Andric   return capLatency(MCSchedModel::computeInstrLatency(*STI, SCDesc));
24267c32a98SDimitry Andric }
24367c32a98SDimitry Andric 
computeInstrLatency(unsigned Opcode) const2445a5ac124SDimitry Andric unsigned TargetSchedModel::computeInstrLatency(unsigned Opcode) const {
2455a5ac124SDimitry Andric   assert(hasInstrSchedModel() && "Only call this function with a SchedModel");
2465a5ac124SDimitry Andric   unsigned SCIdx = TII->get(Opcode).getSchedClass();
247eb11fae6SDimitry Andric   return capLatency(SchedModel.computeInstrLatency(*STI, SCIdx));
24871d5a254SDimitry Andric }
249eb11fae6SDimitry Andric 
computeInstrLatency(const MCInst & Inst) const250eb11fae6SDimitry Andric unsigned TargetSchedModel::computeInstrLatency(const MCInst &Inst) const {
251eb11fae6SDimitry Andric   if (hasInstrSchedModel())
252eb11fae6SDimitry Andric     return capLatency(SchedModel.computeInstrLatency(*STI, *TII, Inst));
253eb11fae6SDimitry Andric   return computeInstrLatency(Inst.getOpcode());
254522600a2SDimitry Andric }
255522600a2SDimitry Andric 
256f8af5cf6SDimitry Andric unsigned
computeInstrLatency(const MachineInstr * MI,bool UseDefaultDefLatency) const257f8af5cf6SDimitry Andric TargetSchedModel::computeInstrLatency(const MachineInstr *MI,
258f8af5cf6SDimitry Andric                                       bool UseDefaultDefLatency) const {
259522600a2SDimitry Andric   // For the itinerary model, fall back to the old subtarget hook.
260522600a2SDimitry Andric   // Allow subtargets to compute Bundle latencies outside the machine model.
261f8af5cf6SDimitry Andric   if (hasInstrItineraries() || MI->isBundle() ||
262f8af5cf6SDimitry Andric       (!hasInstrSchedModel() && !UseDefaultDefLatency))
26301095a5dSDimitry Andric     return TII->getInstrLatency(&InstrItins, *MI);
264522600a2SDimitry Andric 
265522600a2SDimitry Andric   if (hasInstrSchedModel()) {
266522600a2SDimitry Andric     const MCSchedClassDesc *SCDesc = resolveSchedClass(MI);
2675a5ac124SDimitry Andric     if (SCDesc->isValid())
2685a5ac124SDimitry Andric       return computeInstrLatency(*SCDesc);
269522600a2SDimitry Andric   }
27001095a5dSDimitry Andric   return TII->defaultDefLatency(SchedModel, *MI);
271522600a2SDimitry Andric }
272522600a2SDimitry Andric 
273522600a2SDimitry Andric unsigned TargetSchedModel::
computeOutputLatency(const MachineInstr * DefMI,unsigned DefOperIdx,const MachineInstr * DepMI) const274522600a2SDimitry Andric computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
275522600a2SDimitry Andric                      const MachineInstr *DepMI) const {
27601095a5dSDimitry Andric   if (!SchedModel.isOutOfOrder())
277522600a2SDimitry Andric     return 1;
278522600a2SDimitry Andric 
27901095a5dSDimitry Andric   // Out-of-order processor can dispatch WAW dependencies in the same cycle.
280522600a2SDimitry Andric 
281522600a2SDimitry Andric   // Treat predication as a data dependency for out-of-order cpus. In-order
282522600a2SDimitry Andric   // cpus do not need to treat predicated writes specially.
283522600a2SDimitry Andric   //
284522600a2SDimitry Andric   // TODO: The following hack exists because predication passes do not
285522600a2SDimitry Andric   // correctly append imp-use operands, and readsReg() strangely returns false
286522600a2SDimitry Andric   // for predicated defs.
2871d5ae102SDimitry Andric   Register Reg = DefMI->getOperand(DefOperIdx).getReg();
288044eb2f6SDimitry Andric   const MachineFunction &MF = *DefMI->getMF();
28967c32a98SDimitry Andric   const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
29001095a5dSDimitry Andric   if (!DepMI->readsRegister(Reg, TRI) && TII->isPredicated(*DepMI))
291522600a2SDimitry Andric     return computeInstrLatency(DefMI);
292522600a2SDimitry Andric 
293522600a2SDimitry Andric   // If we have a per operand scheduling model, check if this def is writing
294522600a2SDimitry Andric   // an unbuffered resource. If so, it treated like an in-order cpu.
295522600a2SDimitry Andric   if (hasInstrSchedModel()) {
296522600a2SDimitry Andric     const MCSchedClassDesc *SCDesc = resolveSchedClass(DefMI);
297522600a2SDimitry Andric     if (SCDesc->isValid()) {
298522600a2SDimitry Andric       for (const MCWriteProcResEntry *PRI = STI->getWriteProcResBegin(SCDesc),
299522600a2SDimitry Andric              *PRE = STI->getWriteProcResEnd(SCDesc); PRI != PRE; ++PRI) {
300f8af5cf6SDimitry Andric         if (!SchedModel.getProcResource(PRI->ProcResourceIdx)->BufferSize)
301522600a2SDimitry Andric           return 1;
302522600a2SDimitry Andric       }
303522600a2SDimitry Andric     }
304522600a2SDimitry Andric   }
305522600a2SDimitry Andric   return 0;
306522600a2SDimitry Andric }
30771d5a254SDimitry Andric 
308eb11fae6SDimitry Andric double
computeReciprocalThroughput(const MachineInstr * MI) const309eb11fae6SDimitry Andric TargetSchedModel::computeReciprocalThroughput(const MachineInstr *MI) const {
310eb11fae6SDimitry Andric   if (hasInstrItineraries()) {
311eb11fae6SDimitry Andric     unsigned SchedClass = MI->getDesc().getSchedClass();
312eb11fae6SDimitry Andric     return MCSchedModel::getReciprocalThroughput(SchedClass,
313eb11fae6SDimitry Andric                                                  *getInstrItineraries());
31471d5a254SDimitry Andric   }
31571d5a254SDimitry Andric 
31671d5a254SDimitry Andric   if (hasInstrSchedModel())
317eb11fae6SDimitry Andric     return MCSchedModel::getReciprocalThroughput(*STI, *resolveSchedClass(MI));
318eb11fae6SDimitry Andric 
319eb11fae6SDimitry Andric   return 0.0;
32071d5a254SDimitry Andric }
32171d5a254SDimitry Andric 
322eb11fae6SDimitry Andric double
computeReciprocalThroughput(unsigned Opcode) const323eb11fae6SDimitry Andric TargetSchedModel::computeReciprocalThroughput(unsigned Opcode) const {
32471d5a254SDimitry Andric   unsigned SchedClass = TII->get(Opcode).getSchedClass();
32571d5a254SDimitry Andric   if (hasInstrItineraries())
326eb11fae6SDimitry Andric     return MCSchedModel::getReciprocalThroughput(SchedClass,
327eb11fae6SDimitry Andric                                                  *getInstrItineraries());
32871d5a254SDimitry Andric   if (hasInstrSchedModel()) {
329eb11fae6SDimitry Andric     const MCSchedClassDesc &SCDesc = *SchedModel.getSchedClassDesc(SchedClass);
330eb11fae6SDimitry Andric     if (SCDesc.isValid() && !SCDesc.isVariant())
331eb11fae6SDimitry Andric       return MCSchedModel::getReciprocalThroughput(*STI, SCDesc);
33271d5a254SDimitry Andric   }
333eb11fae6SDimitry Andric 
334eb11fae6SDimitry Andric   return 0.0;
33571d5a254SDimitry Andric }
336eb11fae6SDimitry Andric 
337eb11fae6SDimitry Andric double
computeReciprocalThroughput(const MCInst & MI) const338eb11fae6SDimitry Andric TargetSchedModel::computeReciprocalThroughput(const MCInst &MI) const {
339eb11fae6SDimitry Andric   if (hasInstrSchedModel())
340eb11fae6SDimitry Andric     return SchedModel.getReciprocalThroughput(*STI, *TII, MI);
341eb11fae6SDimitry Andric   return computeReciprocalThroughput(MI.getOpcode());
342eb11fae6SDimitry Andric }
343eb11fae6SDimitry Andric 
enableIntervals() const344b1c73532SDimitry Andric bool TargetSchedModel::enableIntervals() const {
345b1c73532SDimitry Andric   if (ForceEnableIntervals)
346b1c73532SDimitry Andric     return true;
347b1c73532SDimitry Andric 
348b1c73532SDimitry Andric   return SchedModel.EnableIntervals;
349b1c73532SDimitry Andric }
350