From d1fefa3d7cfebb468a2280b73895cd1e2ad70e82 Mon Sep 17 00:00:00 2001 From: "Andrew V. Tischenko" Date: Wed, 26 Jul 2017 18:55:14 +0000 Subject: This patch returns proper value to indicate the case when instruction throughput can't be calculated. Differential revision https://reviews.llvm.org/D35831 llvm-svn: 309156 --- llvm/lib/CodeGen/TargetSchedule.cpp | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/TargetSchedule.cpp b/llvm/lib/CodeGen/TargetSchedule.cpp index 9210ea8a83f..e1f7edc627b 100644 --- a/llvm/lib/CodeGen/TargetSchedule.cpp +++ b/llvm/lib/CodeGen/TargetSchedule.cpp @@ -339,42 +339,46 @@ computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx, static Optional getRThroughputFromItineraries(unsigned schedClass, const InstrItineraryData *IID){ - double Unknown = std::numeric_limits::infinity(); - double Throughput = Unknown; + Optional Throughput; for (const InstrStage *IS = IID->beginStage(schedClass), *E = IID->endStage(schedClass); IS != E; ++IS) { - unsigned Cycles = IS->getCycles(); - if (!Cycles) - continue; - Throughput = - std::min(Throughput, countPopulation(IS->getUnits()) * 1.0 / Cycles); + if (IS->getCycles()) { + double Temp = countPopulation(IS->getUnits()) * 1.0 / IS->getCycles(); + Throughput = Throughput.hasValue() + ? std::min(Throughput.getValue(), Temp) + : Temp; + } } - // We need reciprocal throughput that's why we return such value. - return 1 / Throughput; + if (Throughput.hasValue()) + // We need reciprocal throughput that's why we return such value. + return 1 / Throughput.getValue(); + return Throughput; } static Optional getRThroughputFromInstrSchedModel(const MCSchedClassDesc *SCDesc, const TargetSubtargetInfo *STI, const MCSchedModel &SchedModel) { - double Unknown = std::numeric_limits::infinity(); - double Throughput = Unknown; + Optional Throughput; for (const MCWriteProcResEntry *WPR = STI->getWriteProcResBegin(SCDesc), *WEnd = STI->getWriteProcResEnd(SCDesc); WPR != WEnd; ++WPR) { - unsigned Cycles = WPR->Cycles; - if (!Cycles) - return Optional(); - - unsigned NumUnits = - SchedModel.getProcResource(WPR->ProcResourceIdx)->NumUnits; - Throughput = std::min(Throughput, NumUnits * 1.0 / Cycles); + if (WPR->Cycles) { + unsigned NumUnits = + SchedModel.getProcResource(WPR->ProcResourceIdx)->NumUnits; + double Temp = NumUnits * 1.0 / WPR->Cycles; + Throughput = Throughput.hasValue() + ? std::min(Throughput.getValue(), Temp) + : Temp; + } } - // We need reciprocal throughput that's why we return such value. - return 1 / Throughput; + if (Throughput.hasValue()) + // We need reciprocal throughput that's why we return such value. + return 1 / Throughput.getValue(); + return Throughput; } Optional -- cgit v1.2.3