1 //===-- SISchedule.td - SI Scheduling definitons -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // MachineModel definitions for Southern Islands (SI)
11 //===----------------------------------------------------------------------===//
13 def : PredicateProlog<[{
14 const SIInstrInfo *TII =
15 static_cast<const SIInstrInfo*>(SchedModel->getInstrInfo());
19 def WriteBranch : SchedWrite;
20 def WriteExport : SchedWrite;
21 def WriteLDS : SchedWrite;
22 def WriteSALU : SchedWrite;
23 def WriteSMEM : SchedWrite;
24 def WriteVMEM : SchedWrite;
25 def WriteBarrier : SchedWrite;
27 def MIVGPRRead : SchedRead;
28 def MIMFMARead : SchedRead;
30 // Vector ALU instructions
31 def Write32Bit : SchedWrite;
32 def WriteQuarterRate32 : SchedWrite;
33 def WriteFullOrQuarterRate32 : SchedWrite;
35 def WriteFloatFMA : SchedWrite;
37 // Slow quarter rate f64 instruction.
38 def WriteDouble : SchedWrite;
40 // half rate f64 instruction (same as v_add_f64)
41 def WriteDoubleAdd : SchedWrite;
43 // Conversion to or from f64 instruction
44 def WriteDoubleCvt : SchedWrite;
46 // Half rate 64-bit instructions.
47 def Write64Bit : SchedWrite;
49 // mAI multipass instructions.
50 def Write2PassMAI : SchedWrite;
51 def Write8PassMAI : SchedWrite;
52 def Write16PassMAI : SchedWrite;
54 // FIXME: Should there be a class for instructions which are VALU
55 // instructions and have VALU rates, but write to the SALU (i.e. VOPC
58 class SISchedMachineModel : SchedMachineModel {
59 let CompleteModel = 0;
60 // MicroOpBufferSize = 1 means that instructions will always be added
61 // the ready queue when they become available. This exposes them
62 // to the register pressure analysis.
63 let MicroOpBufferSize = 1;
65 let PostRAScheduler = 1;
67 // FIXME:Approximate 2 * branch cost. Try to hack around bad
68 // early-ifcvt heuristics. These need improvement to avoid the OOE
70 int MispredictPenalty = 20;
73 def SIFullSpeedModel : SISchedMachineModel;
74 def SIQuarterSpeedModel : SISchedMachineModel;
75 def GFX10SpeedModel : SISchedMachineModel;
77 // XXX: Are the resource counts correct?
78 def HWBranch : ProcResource<1> {
81 def HWExport : ProcResource<1> {
82 let BufferSize = 7; // Taken from S_WAITCNT
84 def HWLGKM : ProcResource<1> {
85 let BufferSize = 31; // Taken from S_WAITCNT
87 def HWSALU : ProcResource<1> {
90 def HWVMEM : ProcResource<1> {
91 let BufferSize = 15; // Taken from S_WAITCNT
93 def HWVALU : ProcResource<1> {
96 def HWRC : ProcResource<1> { // Register destination cache
100 class HWWriteRes<SchedWrite write, list<ProcResourceKind> resources,
101 int latency> : WriteRes<write, resources> {
102 let Latency = latency;
105 class HWVALUWriteRes<SchedWrite write, int latency> :
106 HWWriteRes<write, [HWVALU], latency>;
108 def PredMIReadVGPR : SchedPredicate<[{TII->hasVGPRUses(*MI)}]>;
110 def MIReadVGPR : SchedReadVariant<[
111 SchedVar<PredMIReadVGPR, [MIVGPRRead]>,
112 SchedVar<NoSchedPred, [ReadDefault]>]>;
114 // The latency numbers are taken from AMD Accelerated Parallel Processing
115 // guide. They may not be accurate.
117 // The latency values are 1 / (operations / cycle) / 4.
118 multiclass SICommonWriteRes {
120 def : HWWriteRes<WriteBranch, [HWBranch], 8>;
121 def : HWWriteRes<WriteExport, [HWExport], 4>;
122 def : HWWriteRes<WriteLDS, [HWLGKM], 5>; // Can be between 2 and 64
123 def : HWWriteRes<WriteSALU, [HWSALU], 1>;
124 def : HWWriteRes<WriteSMEM, [HWLGKM], 5>;
125 def : HWWriteRes<WriteVMEM, [HWVMEM], 80>;
126 def : HWWriteRes<WriteBarrier, [HWBranch], 500>; // XXX: Guessed ???
128 def : HWVALUWriteRes<Write32Bit, 1>;
129 def : HWVALUWriteRes<Write64Bit, 2>;
130 def : HWVALUWriteRes<WriteQuarterRate32, 4>;
131 def : HWVALUWriteRes<Write2PassMAI, 2>;
132 def : HWVALUWriteRes<Write8PassMAI, 8>;
133 def : HWVALUWriteRes<Write16PassMAI, 16>;
135 def : ReadAdvance<MIVGPRRead, -2>;
136 def : InstRW<[Write64Bit, MIReadVGPR], (instregex "^V_ACCVGPR_WRITE_B32$")>;
138 // Technicaly mfma reads can be from 0 to 4 cycles but that does not make
139 // sense to model because its register setup is huge. In particular if we
140 // properly model read advanice as -2 for a vgpr read it will result in a
141 // bad scheduling of acc writes before that mfma. To avoid it we would
142 // need to consume 2 or 4 more vgprs to be initialized before the acc
143 // write sequence. Just assume worst case here.
144 def : ReadAdvance<MIMFMARead, -4>;
146 def : InstRW<[Write2PassMAI, MIMFMARead], (instregex "^V_MFMA_..._4X4X")>;
147 def : InstRW<[Write8PassMAI, MIMFMARead], (instregex "^V_MFMA_..._16X16X")>;
148 def : InstRW<[Write16PassMAI, MIMFMARead], (instregex "^V_MFMA_..._32X32X")>;
151 def PredIsVGPR32Copy : SchedPredicate<[{TII->isVGPRCopy(*MI) && TII->getOpSize(*MI, 0) <= 32}]>;
152 def PredIsVGPR64Copy : SchedPredicate<[{TII->isVGPRCopy(*MI) && TII->getOpSize(*MI, 0) > 32}]>;
153 def WriteCopy : SchedWriteVariant<[
154 SchedVar<PredIsVGPR32Copy, [Write32Bit]>,
155 SchedVar<PredIsVGPR64Copy, [Write64Bit]>,
156 SchedVar<NoSchedPred, [WriteSALU]>]>;
158 let SchedModel = SIFullSpeedModel in {
160 defm : SICommonWriteRes;
162 def : HWVALUWriteRes<WriteFloatFMA, 1>;
163 def : HWVALUWriteRes<WriteDouble, 4>;
164 def : HWVALUWriteRes<WriteDoubleAdd, 2>;
165 def : HWVALUWriteRes<WriteDoubleCvt, 4>;
167 def : InstRW<[WriteCopy], (instrs COPY)>;
169 } // End SchedModel = SIFullSpeedModel
171 let SchedModel = SIQuarterSpeedModel in {
173 defm : SICommonWriteRes;
175 def : HWVALUWriteRes<WriteFloatFMA, 16>;
176 def : HWVALUWriteRes<WriteDouble, 16>;
177 def : HWVALUWriteRes<WriteDoubleAdd, 8>;
178 def : HWVALUWriteRes<WriteDoubleCvt, 4>;
180 def : InstRW<[WriteCopy], (instrs COPY)>;
182 } // End SchedModel = SIQuarterSpeedModel
184 let SchedModel = GFX10SpeedModel in {
186 // The latency values are 1 / (operations / cycle).
187 // Add 1 stall cycle for VGPR read.
188 def : HWWriteRes<Write32Bit, [HWVALU, HWRC], 5>;
189 def : HWWriteRes<Write64Bit, [HWVALU, HWRC], 9>;
190 def : HWWriteRes<WriteQuarterRate32, [HWVALU, HWRC], 17>;
191 def : HWWriteRes<WriteFloatFMA, [HWVALU, HWRC], 5>;
192 def : HWWriteRes<WriteDouble, [HWVALU, HWRC], 17>;
193 def : HWWriteRes<WriteDoubleAdd, [HWVALU, HWRC], 17>;
194 def : HWWriteRes<WriteDoubleCvt, [HWVALU, HWRC], 17>;
196 def : HWWriteRes<WriteBranch, [HWBranch], 32>;
197 def : HWWriteRes<WriteExport, [HWExport, HWRC], 16>;
198 def : HWWriteRes<WriteLDS, [HWLGKM, HWRC], 20>;
199 def : HWWriteRes<WriteSALU, [HWSALU, HWRC], 5>;
200 def : HWWriteRes<WriteSMEM, [HWLGKM, HWRC], 20>;
201 def : HWWriteRes<WriteVMEM, [HWVMEM, HWRC], 320>;
202 def : HWWriteRes<WriteBarrier, [HWBranch], 2000>;
204 def : InstRW<[WriteCopy], (instrs COPY)>;
206 } // End SchedModel = GFX10SpeedModel