1 //===-- SISchedule.td - SI Scheduling definitions -------------------------===//
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 // Normal 16 or 32 bit VALU instructions
31 def Write32Bit : SchedWrite;
32 // Conversion to or from F32 (but not converting F64 to or from F32)
33 def WriteFloatCvt : SchedWrite;
34 // F16 or F32 transcendental instructions (these are quarter rate)
35 def WriteTrans32 : SchedWrite;
36 // Other quarter rate VALU instructions
37 def WriteQuarterRate32 : SchedWrite;
39 def WriteFloatFMA : SchedWrite;
41 // Slow quarter rate f64 instruction.
42 def WriteDouble : SchedWrite;
44 // half rate f64 instruction (same as v_add_f64)
45 def WriteDoubleAdd : SchedWrite;
47 // Conversion to or from f64 instruction
48 def WriteDoubleCvt : SchedWrite;
50 // F64 "transcendental" (actually only reciprocal and/or square root)
52 def WriteTrans64 : SchedWrite;
54 // Half rate 64-bit instructions.
55 def Write64Bit : SchedWrite;
57 // Integer multiplications.
58 def WriteIntMul : SchedWrite;
60 // mAI multipass instructions.
61 def Write2PassMAI : SchedWrite;
62 def Write8PassMAI : SchedWrite;
63 def Write16PassMAI : SchedWrite;
64 def Write4PassDGEMM : SchedWrite;
65 def Write8PassDGEMM : SchedWrite;
67 // FIXME: Should there be a class for instructions which are VALU
68 // instructions and have VALU rates, but write to the SALU (i.e. VOPC
71 class SISchedMachineModel : SchedMachineModel {
72 let CompleteModel = 1;
73 // MicroOpBufferSize = 1 means that instructions will always be added
74 // the ready queue when they become available. This exposes them
75 // to the register pressure analysis.
76 let MicroOpBufferSize = 1;
78 let PostRAScheduler = 1;
80 // FIXME:Approximate 2 * branch cost. Try to hack around bad
81 // early-ifcvt heuristics. These need improvement to avoid the OOE
83 int MispredictPenalty = 20;
86 def SIFullSpeedModel : SISchedMachineModel;
87 def SIQuarterSpeedModel : SISchedMachineModel;
88 def SIDPFullSpeedModel : SISchedMachineModel;
89 def GFX10SpeedModel : SISchedMachineModel;
91 // XXX: Are the resource counts correct?
92 def HWBranch : ProcResource<1> {
95 def HWExport : ProcResource<1> {
96 let BufferSize = 7; // Taken from S_WAITCNT
98 def HWLGKM : ProcResource<1> {
99 let BufferSize = 31; // Taken from S_WAITCNT
101 def HWSALU : ProcResource<1> {
104 def HWVMEM : ProcResource<1> {
105 let BufferSize = 15; // Taken from S_WAITCNT
107 def HWVALU : ProcResource<1> {
110 def HWTransVALU : ProcResource<1> { // Transcendental VALU
113 def HWRC : ProcResource<1> { // Register destination cache
116 def HWXDL : ProcResource<1> { // MFMA CU
120 class HWWriteRes<SchedWrite write, list<ProcResourceKind> resources,
121 int latency> : WriteRes<write, resources> {
122 let Latency = latency;
125 class HWVALUWriteRes<SchedWrite write, int latency> :
126 HWWriteRes<write, [HWVALU], latency>;
128 def PredMIReadVGPR : SchedPredicate<[{TII->hasVGPRUses(*MI)}]>;
130 def MIReadVGPR : SchedReadVariant<[
131 SchedVar<PredMIReadVGPR, [MIVGPRRead]>,
132 SchedVar<NoSchedPred, [ReadDefault]>]>;
134 // The latency numbers are taken from AMD Accelerated Parallel Processing
135 // guide. They may not be accurate.
137 // The latency values are 1 / (operations / cycle) / 4.
138 multiclass SICommonWriteRes {
140 def : HWWriteRes<WriteBranch, [HWBranch], 8>;
141 def : HWWriteRes<WriteExport, [HWExport], 4>;
142 def : HWWriteRes<WriteLDS, [HWLGKM], 5>; // Can be between 2 and 64
143 def : HWWriteRes<WriteSALU, [HWSALU], 1>;
144 def : HWWriteRes<WriteSMEM, [HWLGKM], 5>;
145 def : HWWriteRes<WriteVMEM, [HWVMEM], 80>;
146 def : HWWriteRes<WriteBarrier, [HWBranch], 500>; // XXX: Guessed ???
148 def : HWVALUWriteRes<Write32Bit, 1>;
149 def : HWVALUWriteRes<WriteFloatCvt, 4>;
150 def : HWVALUWriteRes<WriteTrans32, 4>;
151 def : HWVALUWriteRes<WriteQuarterRate32, 4>;
153 def : HWVALUWriteRes<Write4PassDGEMM, 4>;
154 def : HWVALUWriteRes<Write8PassDGEMM, 16>;
156 let ResourceCycles = [2] in
157 def : HWWriteRes<Write2PassMAI, [HWXDL], 2>;
158 let ResourceCycles = [8] in
159 def : HWWriteRes<Write8PassMAI, [HWXDL], 8>;
160 let ResourceCycles = [16] in
161 def : HWWriteRes<Write16PassMAI, [HWXDL], 16>;
163 def : ReadAdvance<MIVGPRRead, -2>;
165 // Technically mfma reads can be from 0 to 4 cycles but that does not make
166 // sense to model because its register setup is huge. In particular if we
167 // properly model read advance as -2 for a vgpr read it will result in a
168 // bad scheduling of acc writes before that mfma. To avoid it we would
169 // need to consume 2 or 4 more vgprs to be initialized before the acc
170 // write sequence. Just assume worst case here.
171 def : ReadAdvance<MIMFMARead, -4>;
174 def PredIsVGPR32Copy : SchedPredicate<[{TII->isVGPRCopy(*MI) && TII->getOpSize(*MI, 0) <= 32}]>;
175 def PredIsVGPR64Copy : SchedPredicate<[{TII->isVGPRCopy(*MI) && TII->getOpSize(*MI, 0) > 32}]>;
176 def WriteCopy : SchedWriteVariant<[
177 SchedVar<PredIsVGPR32Copy, [Write32Bit]>,
178 SchedVar<PredIsVGPR64Copy, [Write64Bit]>,
179 SchedVar<NoSchedPred, [WriteSALU]>]>;
181 let SchedModel = SIFullSpeedModel in {
183 defm : SICommonWriteRes;
185 def : HWVALUWriteRes<Write64Bit, 2>;
186 def : HWVALUWriteRes<WriteIntMul, 4>;
187 def : HWVALUWriteRes<WriteFloatFMA, 1>;
188 def : HWVALUWriteRes<WriteDouble, 4>;
189 def : HWVALUWriteRes<WriteDoubleAdd, 2>;
190 def : HWVALUWriteRes<WriteDoubleCvt, 4>;
191 def : HWVALUWriteRes<WriteTrans64, 4>;
193 def : InstRW<[WriteCopy], (instrs COPY)>;
195 } // End SchedModel = SIFullSpeedModel
197 let SchedModel = SIQuarterSpeedModel in {
199 defm : SICommonWriteRes;
201 def : HWVALUWriteRes<Write64Bit, 2>;
202 def : HWVALUWriteRes<WriteIntMul, 4>;
203 def : HWVALUWriteRes<WriteFloatFMA, 16>;
204 def : HWVALUWriteRes<WriteDouble, 16>;
205 def : HWVALUWriteRes<WriteDoubleAdd, 8>;
206 def : HWVALUWriteRes<WriteDoubleCvt, 4>;
207 def : HWVALUWriteRes<WriteTrans64, 16>;
209 def : InstRW<[WriteCopy], (instrs COPY)>;
210 def : InstRW<[Write64Bit, MIReadVGPR], (instregex "^V_ACCVGPR_WRITE_B32_e64$")>;
211 def : InstRW<[Write2PassMAI, MIMFMARead], (instregex "^V_MFMA_..._4X4X")>;
212 def : InstRW<[Write8PassMAI, MIMFMARead], (instregex "^V_MFMA_..._16X16X")>;
213 def : InstRW<[Write16PassMAI, MIMFMARead], (instregex "^V_MFMA_..._32X32X")>;
215 } // End SchedModel = SIQuarterSpeedModel
217 let SchedModel = SIDPFullSpeedModel in {
219 defm : SICommonWriteRes;
221 def : HWVALUWriteRes<WriteFloatFMA, 1>;
222 def : HWVALUWriteRes<WriteDouble, 1>;
223 def : HWVALUWriteRes<WriteDoubleAdd, 1>;
224 def : HWVALUWriteRes<WriteDoubleCvt, 1>;
225 def : HWVALUWriteRes<WriteTrans64, 4>;
226 def : HWVALUWriteRes<WriteIntMul, 1>;
227 def : HWVALUWriteRes<Write64Bit, 1>;
229 def : InstRW<[WriteCopy], (instrs COPY)>;
230 def : InstRW<[Write64Bit], (instregex "^V_ACCVGPR_WRITE_B32_e64$")>;
231 def : InstRW<[Write2PassMAI, MIMFMARead], (instregex "^V_MFMA_.32_4X4X")>;
232 def : InstRW<[Write8PassMAI, MIMFMARead], (instregex "^V_MFMA_.32_16X16X")>;
233 def : InstRW<[Write16PassMAI, MIMFMARead], (instregex "^V_MFMA_.32_32X32X")>;
234 def : InstRW<[Write4PassDGEMM, MIMFMARead], (instregex "^V_MFMA_.64_4X4X")>;
235 def : InstRW<[Write8PassDGEMM, MIMFMARead], (instregex "^V_MFMA_.64_16X16X")>;
237 } // End SchedModel = SIDPFullSpeedModel
239 let SchedModel = GFX10SpeedModel in {
241 // The latency values are 1 / (operations / cycle).
242 // Add 1 stall cycle for VGPR read.
243 def : HWWriteRes<Write32Bit, [HWVALU, HWRC], 5>;
244 def : HWWriteRes<WriteFloatCvt, [HWVALU, HWRC], 5>;
245 def : HWWriteRes<Write64Bit, [HWVALU, HWRC], 6>;
246 def : HWWriteRes<WriteTrans32, [HWTransVALU, HWRC], 10>;
247 def : HWWriteRes<WriteQuarterRate32, [HWVALU, HWRC], 8>;
248 def : HWWriteRes<WriteFloatFMA, [HWVALU, HWRC], 5>;
249 def : HWWriteRes<WriteDouble, [HWVALU, HWRC], 22>;
250 def : HWWriteRes<WriteDoubleAdd, [HWVALU, HWRC], 22>;
251 def : HWWriteRes<WriteDoubleCvt, [HWVALU, HWRC], 22>;
252 def : HWWriteRes<WriteIntMul, [HWVALU, HWRC], 8>;
253 def : HWWriteRes<WriteTrans64, [HWVALU, HWTransVALU, HWRC], 24>;
255 def : HWWriteRes<WriteBranch, [HWBranch], 32>;
256 def : HWWriteRes<WriteExport, [HWExport, HWRC], 16>;
257 def : HWWriteRes<WriteLDS, [HWLGKM, HWRC], 20>;
258 def : HWWriteRes<WriteSALU, [HWSALU, HWRC], 2>;
259 def : HWWriteRes<WriteSMEM, [HWLGKM, HWRC], 20>;
260 def : HWWriteRes<WriteVMEM, [HWVMEM, HWRC], 320>;
261 def : HWWriteRes<WriteBarrier, [HWBranch], 2000>;
263 def : InstRW<[WriteCopy], (instrs COPY)>;
265 } // End SchedModel = GFX10SpeedModel