From c0dfffa448ad7ab647779bc3e7f2aee5c76cb31b Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Tue, 9 Oct 2012 23:44:32 +0000 Subject: misched: Add computeInstrLatency to TargetSchedModel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165566 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetSchedule.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/CodeGen/TargetSchedule.cpp') diff --git a/lib/CodeGen/TargetSchedule.cpp b/lib/CodeGen/TargetSchedule.cpp index 6e7cccce42..cf9d059492 100644 --- a/lib/CodeGen/TargetSchedule.cpp +++ b/lib/CodeGen/TargetSchedule.cpp @@ -146,6 +146,10 @@ unsigned TargetSchedModel::computeOperandLatency( unsigned InstrLatency = TII->getInstrLatency(&InstrItins, DefMI); // Expected latency is the max of the stage latency and itinerary props. + // Rather than directly querying InstrItins stage latency, we call a TII + // hook to allow subtargets to specialize latency. This hook is only + // applicable to the InstrItins model. InstrSchedModel should model all + // special cases without TII hooks. if (!FindMin) InstrLatency = std::max(InstrLatency, TII->defaultDefLatency(&SchedModel, DefMI)); @@ -185,3 +189,23 @@ unsigned TargetSchedModel::computeOperandLatency( #endif return 1; } + +unsigned TargetSchedModel::computeInstrLatency(const MachineInstr *MI) const { + if (hasInstrItineraries()) { + // For the itinerary model, fall back to the old subtarget hook. + return TII->getInstrLatency(&InstrItins, MI); + } + if (hasInstrSchedModel()) { + unsigned Latency = 0; + const MCSchedClassDesc *SCDesc = resolveSchedClass(MI); + for (unsigned DefIdx = 0, DefEnd = SCDesc->NumWriteLatencyEntries; + DefIdx != DefEnd; ++DefIdx) { + // Lookup the definition's write latency in SubtargetInfo. + const MCWriteLatencyEntry *WLEntry = + STI->getWriteLatencyEntry(SCDesc, DefIdx); + Latency = std::max(Latency, WLEntry->Cycles); + } + return Latency; + } + return TII->defaultDefLatency(&SchedModel, MI); +} -- cgit v1.2.3-70-g09d2