2015-07-11 06:13:43 +08:00
|
|
|
//===- MCSchedule.cpp - Scheduling ------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the default scheduling model.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCSchedule.h"
|
2018-05-31 21:30:42 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2018-04-16 01:32:17 +08:00
|
|
|
#include "llvm/MC/MCInstrDesc.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2018-03-13 23:22:13 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2015-07-11 06:17:49 +08:00
|
|
|
#include <type_traits>
|
2015-07-11 06:13:43 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
static_assert(std::is_pod<MCSchedModel>::value,
|
|
|
|
"We shouldn't have a static constructor here");
|
|
|
|
const MCSchedModel MCSchedModel::Default = {DefaultIssueWidth,
|
|
|
|
DefaultMicroOpBufferSize,
|
|
|
|
DefaultLoopMicroOpBufferSize,
|
|
|
|
DefaultLoadLatency,
|
|
|
|
DefaultHighLatency,
|
|
|
|
DefaultMispredictPenalty,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
0,
|
2018-04-03 21:52:26 +08:00
|
|
|
nullptr,
|
2015-07-11 06:13:43 +08:00
|
|
|
nullptr};
|
2018-03-13 23:22:13 +08:00
|
|
|
|
|
|
|
int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
|
|
|
|
const MCSchedClassDesc &SCDesc) {
|
|
|
|
int Latency = 0;
|
|
|
|
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);
|
|
|
|
// Early exit if we found an invalid latency.
|
|
|
|
if (WLEntry->Cycles < 0)
|
|
|
|
return WLEntry->Cycles;
|
|
|
|
Latency = std::max(Latency, static_cast<int>(WLEntry->Cycles));
|
|
|
|
}
|
|
|
|
return Latency;
|
|
|
|
}
|
2018-03-14 00:28:55 +08:00
|
|
|
|
2018-04-16 01:32:17 +08:00
|
|
|
int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
|
|
|
|
unsigned SchedClass) const {
|
|
|
|
const MCSchedClassDesc &SCDesc = *getSchedClassDesc(SchedClass);
|
|
|
|
if (!SCDesc.isValid())
|
|
|
|
return 0;
|
|
|
|
if (!SCDesc.isVariant())
|
|
|
|
return MCSchedModel::computeInstrLatency(STI, SCDesc);
|
|
|
|
|
|
|
|
llvm_unreachable("unsupported variant scheduling class");
|
|
|
|
}
|
2018-03-14 00:28:55 +08:00
|
|
|
|
2018-05-31 21:30:42 +08:00
|
|
|
int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
|
|
|
|
const MCInstrInfo &MCII,
|
|
|
|
const MCInst &Inst) const {
|
|
|
|
unsigned SchedClass = MCII.get(Inst.getOpcode()).getSchedClass();
|
|
|
|
const MCSchedClassDesc *SCDesc = getSchedClassDesc(SchedClass);
|
|
|
|
if (!SCDesc->isValid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned CPUID = getProcessorID();
|
|
|
|
while (SCDesc->isVariant()) {
|
|
|
|
SchedClass = STI.resolveVariantSchedClass(SchedClass, &Inst, CPUID);
|
|
|
|
SCDesc = getSchedClassDesc(SchedClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SchedClass)
|
|
|
|
return MCSchedModel::computeInstrLatency(STI, *SCDesc);
|
|
|
|
|
|
|
|
llvm_unreachable("unsupported variant scheduling class");
|
|
|
|
}
|
|
|
|
|
2018-06-06 07:34:45 +08:00
|
|
|
double
|
2018-03-14 00:28:55 +08:00
|
|
|
MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI,
|
|
|
|
const MCSchedClassDesc &SCDesc) {
|
|
|
|
Optional<double> Throughput;
|
2018-04-16 01:32:17 +08:00
|
|
|
const MCSchedModel &SM = STI.getSchedModel();
|
|
|
|
const MCWriteProcResEntry *I = STI.getWriteProcResBegin(&SCDesc);
|
|
|
|
const MCWriteProcResEntry *E = STI.getWriteProcResEnd(&SCDesc);
|
|
|
|
for (; I != E; ++I) {
|
|
|
|
if (!I->Cycles)
|
|
|
|
continue;
|
|
|
|
unsigned NumUnits = SM.getProcResource(I->ProcResourceIdx)->NumUnits;
|
|
|
|
double Temp = NumUnits * 1.0 / I->Cycles;
|
|
|
|
Throughput = Throughput ? std::min(Throughput.getValue(), Temp) : Temp;
|
2018-03-14 00:28:55 +08:00
|
|
|
}
|
2018-06-06 07:34:45 +08:00
|
|
|
if (Throughput.hasValue())
|
|
|
|
return 1.0 / Throughput.getValue();
|
|
|
|
|
|
|
|
// If no throughput value was calculated, assume that we can execute at the
|
|
|
|
// maximum issue width scaled by number of micro-ops for the schedule class.
|
|
|
|
return ((double)SCDesc.NumMicroOps) / SM.IssueWidth;
|
2018-04-16 01:32:17 +08:00
|
|
|
}
|
2018-03-14 00:28:55 +08:00
|
|
|
|
2018-06-06 07:34:45 +08:00
|
|
|
double
|
2018-05-31 21:30:42 +08:00
|
|
|
MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI,
|
|
|
|
const MCInstrInfo &MCII,
|
|
|
|
const MCInst &Inst) const {
|
|
|
|
unsigned SchedClass = MCII.get(Inst.getOpcode()).getSchedClass();
|
|
|
|
const MCSchedClassDesc *SCDesc = getSchedClassDesc(SchedClass);
|
2018-06-06 07:34:45 +08:00
|
|
|
|
|
|
|
// If there's no valid class, assume that the instruction executes/completes
|
|
|
|
// at the maximum issue width.
|
2018-05-31 21:30:42 +08:00
|
|
|
if (!SCDesc->isValid())
|
2018-06-06 07:34:45 +08:00
|
|
|
return 1.0 / IssueWidth;
|
2018-05-31 21:30:42 +08:00
|
|
|
|
|
|
|
unsigned CPUID = getProcessorID();
|
|
|
|
while (SCDesc->isVariant()) {
|
|
|
|
SchedClass = STI.resolveVariantSchedClass(SchedClass, &Inst, CPUID);
|
|
|
|
SCDesc = getSchedClassDesc(SchedClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SchedClass)
|
|
|
|
return MCSchedModel::getReciprocalThroughput(STI, *SCDesc);
|
|
|
|
|
|
|
|
llvm_unreachable("unsupported variant scheduling class");
|
|
|
|
}
|
|
|
|
|
2018-06-06 07:34:45 +08:00
|
|
|
double
|
2018-04-16 01:32:17 +08:00
|
|
|
MCSchedModel::getReciprocalThroughput(unsigned SchedClass,
|
|
|
|
const InstrItineraryData &IID) {
|
|
|
|
Optional<double> Throughput;
|
|
|
|
const InstrStage *I = IID.beginStage(SchedClass);
|
|
|
|
const InstrStage *E = IID.endStage(SchedClass);
|
|
|
|
for (; I != E; ++I) {
|
|
|
|
if (!I->getCycles())
|
|
|
|
continue;
|
|
|
|
double Temp = countPopulation(I->getUnits()) * 1.0 / I->getCycles();
|
|
|
|
Throughput = Throughput ? std::min(Throughput.getValue(), Temp) : Temp;
|
|
|
|
}
|
2018-06-06 07:34:45 +08:00
|
|
|
if (Throughput.hasValue())
|
|
|
|
return 1.0 / Throughput.getValue();
|
|
|
|
|
|
|
|
// If there are no execution resources specified for this class, then assume
|
|
|
|
// that it can execute at the maximum default issue width.
|
|
|
|
return 1.0 / DefaultIssueWidth;
|
2018-03-14 00:28:55 +08:00
|
|
|
}
|