Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 1 | //===- 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 Biagio | 30c1ba4 | 2018-03-13 15:22:13 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCSubtargetInfo.h" |
Duncan P. N. Exon Smith | f787ed0 | 2015-07-10 22:17:49 +0000 | [diff] [blame] | 16 | #include <type_traits> |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | static_assert(std::is_pod<MCSchedModel>::value, |
| 21 | "We shouldn't have a static constructor here"); |
| 22 | const 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 Biagio | 823e5f9 | 2018-04-03 13:52:26 +0000 | [diff] [blame^] | 35 | nullptr, |
Duncan P. N. Exon Smith | f862f87 | 2015-07-10 22:13:43 +0000 | [diff] [blame] | 36 | nullptr}; |
Andrea Di Biagio | 30c1ba4 | 2018-03-13 15:22:13 +0000 | [diff] [blame] | 37 | |
| 38 | int 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 Biagio | 7faea7c | 2018-03-13 16:28:55 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | Optional<double> |
| 56 | MCSchedModel::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 | } |