summaryrefslogtreecommitdiff
path: root/lib/CodeGen/TargetSchedule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/TargetSchedule.cpp')
-rw-r--r--lib/CodeGen/TargetSchedule.cpp52
1 files changed, 28 insertions, 24 deletions
diff --git a/lib/CodeGen/TargetSchedule.cpp b/lib/CodeGen/TargetSchedule.cpp
index 9210ea8a83f6..86dbf1b2aeab 100644
--- a/lib/CodeGen/TargetSchedule.cpp
+++ b/lib/CodeGen/TargetSchedule.cpp
@@ -16,15 +16,15 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCInstrItineraries.h"
#include "llvm/MC/MCSchedule.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetInstrInfo.h"
-#include "llvm/Target/TargetRegisterInfo.h"
-#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
@@ -316,7 +316,7 @@ computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
// correctly append imp-use operands, and readsReg() strangely returns false
// for predicated defs.
unsigned Reg = DefMI->getOperand(DefOperIdx).getReg();
- const MachineFunction &MF = *DefMI->getParent()->getParent();
+ const MachineFunction &MF = *DefMI->getMF();
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!DepMI->readsRegister(Reg, TRI) && TII->isPredicated(*DepMI))
return computeInstrLatency(DefMI);
@@ -339,42 +339,46 @@ computeOutputLatency(const MachineInstr *DefMI, unsigned DefOperIdx,
static Optional<double>
getRThroughputFromItineraries(unsigned schedClass,
const InstrItineraryData *IID){
- double Unknown = std::numeric_limits<double>::infinity();
- double Throughput = Unknown;
+ Optional<double> 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<double>
getRThroughputFromInstrSchedModel(const MCSchedClassDesc *SCDesc,
const TargetSubtargetInfo *STI,
const MCSchedModel &SchedModel) {
- double Unknown = std::numeric_limits<double>::infinity();
- double Throughput = Unknown;
+ Optional<double> Throughput;
for (const MCWriteProcResEntry *WPR = STI->getWriteProcResBegin(SCDesc),
*WEnd = STI->getWriteProcResEnd(SCDesc);
WPR != WEnd; ++WPR) {
- unsigned Cycles = WPR->Cycles;
- if (!Cycles)
- return Optional<double>();
-
- 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<double>