blob: b71b530f0910e5ea448948d2d53e444c51c0e995 [file] [log] [blame]
Duncan P. N. Exon Smithf862f872015-07-10 22:13:43 +00001//===- MCSchedule.cpp - Scheduling ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the default scheduling model.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/MC/MCSchedule.h"
Andrea Di Biagio30c1ba42018-03-13 15:22:13 +000015#include "llvm/MC/MCSubtargetInfo.h"
Duncan P. N. Exon Smithf787ed02015-07-10 22:17:49 +000016#include <type_traits>
Duncan P. N. Exon Smithf862f872015-07-10 22:13:43 +000017
18using namespace llvm;
19
20static_assert(std::is_pod<MCSchedModel>::value,
21 "We shouldn't have a static constructor here");
22const MCSchedModel MCSchedModel::Default = {DefaultIssueWidth,
23 DefaultMicroOpBufferSize,
24 DefaultLoopMicroOpBufferSize,
25 DefaultLoadLatency,
26 DefaultHighLatency,
27 DefaultMispredictPenalty,
28 false,
29 true,
30 0,
31 nullptr,
32 nullptr,
33 0,
34 0,
Andrea Di Biagio823e5f92018-04-03 13:52:26 +000035 nullptr,
Duncan P. N. Exon Smithf862f872015-07-10 22:13:43 +000036 nullptr};
Andrea Di Biagio30c1ba42018-03-13 15:22:13 +000037
38int MCSchedModel::computeInstrLatency(const MCSubtargetInfo &STI,
39 const MCSchedClassDesc &SCDesc) {
40 int Latency = 0;
41 for (unsigned DefIdx = 0, DefEnd = SCDesc.NumWriteLatencyEntries;
42 DefIdx != DefEnd; ++DefIdx) {
43 // Lookup the definition's write latency in SubtargetInfo.
44 const MCWriteLatencyEntry *WLEntry =
45 STI.getWriteLatencyEntry(&SCDesc, DefIdx);
46 // Early exit if we found an invalid latency.
47 if (WLEntry->Cycles < 0)
48 return WLEntry->Cycles;
49 Latency = std::max(Latency, static_cast<int>(WLEntry->Cycles));
50 }
51 return Latency;
52}
Andrea Di Biagio7faea7c2018-03-13 16:28:55 +000053
54
55Optional<double>
56MCSchedModel::getReciprocalThroughput(const MCSubtargetInfo &STI,
57 const MCSchedClassDesc &SCDesc) {
58 Optional<double> Throughput;
59 const MCSchedModel &SchedModel = STI.getSchedModel();
60
61 for (const MCWriteProcResEntry *WPR = STI.getWriteProcResBegin(&SCDesc),
62 *WEnd = STI.getWriteProcResEnd(&SCDesc);
63 WPR != WEnd; ++WPR) {
64 if (WPR->Cycles) {
65 unsigned NumUnits =
66 SchedModel.getProcResource(WPR->ProcResourceIdx)->NumUnits;
67 double Temp = NumUnits * 1.0 / WPR->Cycles;
68 Throughput =
69 Throughput.hasValue() ? std::min(Throughput.getValue(), Temp) : Temp;
70 }
71 }
72
73 if (Throughput.hasValue())
74 return 1 / Throughput.getValue();
75 return Throughput;
76}