xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/SIRegisterInfo.td (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1//===-- SIRegisterInfo.td - SI Register defs ---------------*- tablegen -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10//  Subregister declarations
11//===----------------------------------------------------------------------===//
12
13class Indexes<int N> {
14  list<int> all = [0,   1,  2,  3,  4,  5,  6 , 7,
15                   8,   9, 10, 11, 12, 13, 14, 15,
16                   16, 17, 18, 19, 20, 21, 22, 23,
17                   24, 25, 26, 27, 28, 29, 30, 31];
18
19  // Returns list of indexes [0..N)
20  list<int> slice = !filter(i, all, !lt(i, N));
21}
22
23let Namespace = "AMDGPU" in {
24
25def lo16 : SubRegIndex<16, 0>;
26def hi16 : SubRegIndex<16, 16>;
27
28foreach Index = 0...31 in {
29  def sub#Index : SubRegIndex<32, !shl(Index, 5)>;
30}
31
32foreach Index = 1...31 in {
33  def sub#Index#_lo16 : ComposedSubRegIndex<!cast<SubRegIndex>(sub#Index), lo16>;
34  def sub#Index#_hi16 : ComposedSubRegIndex<!cast<SubRegIndex>(sub#Index), hi16>;
35}
36
37foreach Size = {2...6,8,16} in {
38  foreach Index = Indexes<!sub(33, Size)>.slice in {
39    def !interleave(!foreach(cur, Indexes<Size>.slice, "sub"#!add(cur, Index)),
40                    "_") :
41      SubRegIndex<!mul(Size, 32), !shl(Index, 5)> {
42      let CoveringSubRegIndices =
43        !foreach(cur, Indexes<Size>.slice,
44                 !cast<SubRegIndex>(sub#!add(cur, Index)));
45    }
46  }
47}
48
49}
50
51//===----------------------------------------------------------------------===//
52//  Helpers
53//===----------------------------------------------------------------------===//
54
55class getSubRegs<int size> {
56  list<SubRegIndex> ret2 = [sub0, sub1];
57  list<SubRegIndex> ret3 = [sub0, sub1, sub2];
58  list<SubRegIndex> ret4 = [sub0, sub1, sub2, sub3];
59  list<SubRegIndex> ret5 = [sub0, sub1, sub2, sub3, sub4];
60  list<SubRegIndex> ret6 = [sub0, sub1, sub2, sub3, sub4, sub5];
61  list<SubRegIndex> ret7 = [sub0, sub1, sub2, sub3, sub4, sub5, sub6];
62  list<SubRegIndex> ret8 = [sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7];
63  list<SubRegIndex> ret16 = [sub0, sub1, sub2, sub3,
64                             sub4, sub5, sub6, sub7,
65                             sub8, sub9, sub10, sub11,
66                             sub12, sub13, sub14, sub15];
67  list<SubRegIndex> ret32 = [sub0, sub1, sub2, sub3,
68                             sub4, sub5, sub6, sub7,
69                             sub8, sub9, sub10, sub11,
70                             sub12, sub13, sub14, sub15,
71                             sub16, sub17, sub18, sub19,
72                             sub20, sub21, sub22, sub23,
73                             sub24, sub25, sub26, sub27,
74                             sub28, sub29, sub30, sub31];
75
76  list<SubRegIndex> ret = !if(!eq(size, 2), ret2,
77                              !if(!eq(size, 3), ret3,
78                                  !if(!eq(size, 4), ret4,
79                                      !if(!eq(size, 5), ret5,
80                                          !if(!eq(size, 6), ret6,
81                                              !if(!eq(size, 7), ret7,
82                                                  !if(!eq(size, 8), ret8,
83                                                      !if(!eq(size, 16), ret16,
84                                                          ret32))))))));
85}
86
87// Generates list of sequential register tuple names.
88// E.g. RegSeq<3,2,2,"s">.ret -> [ "s[0:1]", "s[2:3]" ]
89class RegSeqNames<int last_reg, int stride, int size, string prefix,
90                  int start = 0> {
91  int next = !add(start, stride);
92  int end_reg = !add(start, size, -1);
93  list<string> ret =
94    !if(!le(end_reg, last_reg),
95        !listconcat([prefix # "[" # start # ":" # end_reg # "]"],
96                    RegSeqNames<last_reg, stride, size, prefix, next>.ret),
97                    []);
98}
99
100// Generates list of dags for register tupless.
101class RegSeqDags<RegisterClass RC, int last_reg, int stride, int size,
102                int start = 0> {
103  dag trunc_rc = (trunc RC,
104                  !if(!and(!eq(stride, 1), !eq(start, 0)),
105                      !sub(!add(last_reg, 2), size),
106                      !add(last_reg, 1)));
107  list<dag> ret =
108    !if(!lt(start, size),
109        !listconcat([(add (decimate (shl trunc_rc, start), stride))],
110                    RegSeqDags<RC, last_reg, stride, size, !add(start, 1)>.ret),
111        []);
112}
113
114class SIRegisterTuples<list<SubRegIndex> Indices, RegisterClass RC,
115                       int last_reg, int stride, int size, string prefix> :
116  RegisterTuples<Indices,
117                 RegSeqDags<RC, last_reg, stride, size>.ret,
118                 RegSeqNames<last_reg, stride, size, prefix>.ret>;
119
120//===----------------------------------------------------------------------===//
121//  Declarations that describe the SI registers
122//===----------------------------------------------------------------------===//
123class SIReg <string n, bits<16> regIdx = 0> :
124  Register<n> {
125  let Namespace = "AMDGPU";
126  let HWEncoding = regIdx;
127}
128
129// For register classes that use TSFlags.
130class SIRegisterClass <string n, list<ValueType> rTypes, int Align, dag rList>
131  : RegisterClass <n, rTypes, Align, rList> {
132  // For vector register classes.
133  field bit HasVGPR = 0;
134  field bit HasAGPR = 0;
135
136  // These need to be kept in sync with the enum SIRCFlags.
137  let TSFlags{0} = HasVGPR;
138  let TSFlags{1} = HasAGPR;
139}
140
141multiclass SIRegLoHi16 <string n, bits<16> regIdx, bit ArtificialHigh = 1,
142                        bit HWEncodingHigh = 0> {
143  // There is no special encoding for 16 bit subregs, these are not real
144  // registers but rather operands for instructions preserving other 16 bits
145  // of the result or reading just 16 bits of a 32 bit VGPR.
146  // It is encoded as a corresponding 32 bit register.
147  // Non-VGPR register classes use it as we need to have matching subregisters
148  // to move instructions and data between ALUs.
149  def _LO16 : SIReg<n#".l", regIdx> {
150    let HWEncoding{8} = HWEncodingHigh;
151  }
152  def _HI16 : SIReg<!if(ArtificialHigh, "", n#".h"), regIdx> {
153    let isArtificial = ArtificialHigh;
154    let HWEncoding{8} = HWEncodingHigh;
155  }
156  def "" : RegisterWithSubRegs<n, [!cast<Register>(NAME#"_LO16"),
157                                   !cast<Register>(NAME#"_HI16")]> {
158    let Namespace = "AMDGPU";
159    let SubRegIndices = [lo16, hi16];
160    let CoveredBySubRegs = !not(ArtificialHigh);
161    let HWEncoding = regIdx;
162    let HWEncoding{8} = HWEncodingHigh;
163  }
164}
165
166// Special Registers
167defm VCC_LO : SIRegLoHi16<"vcc_lo", 106>;
168defm VCC_HI : SIRegLoHi16<"vcc_hi", 107>;
169
170// Pseudo-registers: Used as placeholders during isel and immediately
171// replaced, never seeing the verifier.
172def PRIVATE_RSRC_REG : SIReg<"private_rsrc", 0>;
173def FP_REG : SIReg<"fp", 0>;
174def SP_REG : SIReg<"sp", 0>;
175
176// Pseudo-register to represent the program-counter DWARF register.
177def PC_REG : SIReg<"pc", 0>, DwarfRegNum<[16, 16]> {
178  // There is no physical register corresponding to a "program counter", but
179  // we need to encode the concept in debug information in order to represent
180  // things like the return value in unwind information.
181  let isArtificial = 1;
182}
183
184// VCC for 64-bit instructions
185def VCC : RegisterWithSubRegs<"vcc", [VCC_LO, VCC_HI]> {
186  let Namespace = "AMDGPU";
187  let SubRegIndices = [sub0, sub1];
188  let HWEncoding = 106;
189}
190
191defm EXEC_LO : SIRegLoHi16<"exec_lo", 126>, DwarfRegNum<[1, 1]>;
192defm EXEC_HI : SIRegLoHi16<"exec_hi", 127>;
193
194def EXEC : RegisterWithSubRegs<"exec", [EXEC_LO, EXEC_HI]>, DwarfRegNum<[17, 1]> {
195  let Namespace = "AMDGPU";
196  let SubRegIndices = [sub0, sub1];
197  let HWEncoding = 126;
198}
199
200// 32-bit real registers, for MC only.
201// May be used with both 32-bit and 64-bit operands.
202defm SRC_VCCZ : SIRegLoHi16<"src_vccz", 251>;
203defm SRC_EXECZ : SIRegLoHi16<"src_execz", 252>;
204defm SRC_SCC : SIRegLoHi16<"src_scc", 253>;
205
206// 1-bit pseudo register, for codegen only.
207// Should never be emitted.
208def SCC : SIReg<"scc">;
209
210defm M0 : SIRegLoHi16 <"m0", 124>;
211defm SGPR_NULL : SIRegLoHi16 <"null", 125>;
212
213defm SRC_SHARED_BASE : SIRegLoHi16<"src_shared_base", 235>;
214defm SRC_SHARED_LIMIT : SIRegLoHi16<"src_shared_limit", 236>;
215defm SRC_PRIVATE_BASE : SIRegLoHi16<"src_private_base", 237>;
216defm SRC_PRIVATE_LIMIT : SIRegLoHi16<"src_private_limit", 238>;
217defm SRC_POPS_EXITING_WAVE_ID : SIRegLoHi16<"src_pops_exiting_wave_id", 239>;
218
219// Not addressable
220def MODE : SIReg <"mode", 0>;
221
222def LDS_DIRECT : SIReg <"src_lds_direct", 254> {
223  // There is no physical register corresponding to this. This is an
224  // encoding value in a source field, which will ultimately trigger a
225  // read from m0.
226  let isArtificial = 1;
227}
228
229defm XNACK_MASK_LO : SIRegLoHi16<"xnack_mask_lo", 104>;
230defm XNACK_MASK_HI : SIRegLoHi16<"xnack_mask_hi", 105>;
231
232def XNACK_MASK :
233    RegisterWithSubRegs<"xnack_mask", [XNACK_MASK_LO, XNACK_MASK_HI]> {
234  let Namespace = "AMDGPU";
235  let SubRegIndices = [sub0, sub1];
236  let HWEncoding = 104;
237}
238
239// Trap handler registers
240defm TBA_LO : SIRegLoHi16<"tba_lo", 108>;
241defm TBA_HI : SIRegLoHi16<"tba_hi", 109>;
242
243def TBA : RegisterWithSubRegs<"tba", [TBA_LO, TBA_HI]> {
244  let Namespace = "AMDGPU";
245  let SubRegIndices = [sub0, sub1];
246  let HWEncoding = 108;
247}
248
249defm TMA_LO : SIRegLoHi16<"tma_lo", 110>;
250defm TMA_HI : SIRegLoHi16<"tma_hi", 111>;
251
252def TMA : RegisterWithSubRegs<"tma", [TMA_LO, TMA_HI]> {
253  let Namespace = "AMDGPU";
254  let SubRegIndices = [sub0, sub1];
255  let HWEncoding = 110;
256}
257
258foreach Index = 0...15 in {
259  defm TTMP#Index#_vi       : SIRegLoHi16<"ttmp"#Index, !add(112, Index)>;
260  defm TTMP#Index#_gfx9plus : SIRegLoHi16<"ttmp"#Index, !add(108, Index)>;
261  defm TTMP#Index           : SIRegLoHi16<"ttmp"#Index, 0>;
262}
263
264multiclass FLAT_SCR_LOHI_m <string n, bits<16> ci_e, bits<16> vi_e> {
265  defm _ci : SIRegLoHi16<n, ci_e>;
266  defm _vi : SIRegLoHi16<n, vi_e>;
267  defm "" : SIRegLoHi16<n, 0>;
268}
269
270class FlatReg <Register lo, Register hi, bits<16> encoding> :
271    RegisterWithSubRegs<"flat_scratch", [lo, hi]> {
272  let Namespace = "AMDGPU";
273  let SubRegIndices = [sub0, sub1];
274  let HWEncoding = encoding;
275}
276
277defm FLAT_SCR_LO : FLAT_SCR_LOHI_m<"flat_scratch_lo", 104, 102>; // Offset in units of 256-bytes.
278defm FLAT_SCR_HI : FLAT_SCR_LOHI_m<"flat_scratch_hi", 105, 103>; // Size is the per-thread scratch size, in bytes.
279
280def FLAT_SCR_ci : FlatReg<FLAT_SCR_LO_ci, FLAT_SCR_HI_ci, 104>;
281def FLAT_SCR_vi : FlatReg<FLAT_SCR_LO_vi, FLAT_SCR_HI_vi, 102>;
282def FLAT_SCR : FlatReg<FLAT_SCR_LO, FLAT_SCR_HI, 0>;
283
284// SGPR registers
285foreach Index = 0...105 in {
286  defm SGPR#Index :
287     SIRegLoHi16 <"s"#Index, Index>,
288     DwarfRegNum<[!if(!le(Index, 63), !add(Index, 32), !add(Index, 1024)),
289                  !if(!le(Index, 63), !add(Index, 32), !add(Index, 1024))]>;
290}
291
292// VGPR registers
293foreach Index = 0...255 in {
294  defm VGPR#Index :
295    SIRegLoHi16 <"v"#Index, Index, 0, 1>,
296    DwarfRegNum<[!add(Index, 2560), !add(Index, 1536)]>;
297}
298
299// AccVGPR registers
300foreach Index = 0...255 in {
301  defm AGPR#Index :
302      SIRegLoHi16 <"a"#Index, Index, 1, 1>,
303      DwarfRegNum<[!add(Index, 3072), !add(Index, 2048)]>;
304}
305
306//===----------------------------------------------------------------------===//
307//  Groupings using register classes and tuples
308//===----------------------------------------------------------------------===//
309
310def SCC_CLASS : RegisterClass<"AMDGPU", [i1], 1, (add SCC)> {
311  let CopyCost = -1;
312  let isAllocatable = 0;
313}
314
315def M0_CLASS : RegisterClass<"AMDGPU", [i32], 32, (add M0)> {
316  let CopyCost = 1;
317  let isAllocatable = 0;
318}
319
320def M0_CLASS_LO16 : RegisterClass<"AMDGPU", [i16, f16], 16, (add M0_LO16)> {
321  let CopyCost = 1;
322  let Size = 16;
323  let isAllocatable = 0;
324}
325
326// TODO: Do we need to set DwarfRegAlias on register tuples?
327
328def SGPR_LO16 : RegisterClass<"AMDGPU", [i16, f16], 16,
329                              (add (sequence "SGPR%u_LO16", 0, 105))> {
330  let AllocationPriority = 9;
331  let Size = 16;
332  let GeneratePressureSet = 0;
333}
334
335def SGPR_HI16 : RegisterClass<"AMDGPU", [i16, f16], 16,
336                              (add (sequence "SGPR%u_HI16", 0, 105))> {
337  let isAllocatable = 0;
338  let Size = 16;
339  let GeneratePressureSet = 0;
340}
341
342// SGPR 32-bit registers
343def SGPR_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
344                            (add (sequence "SGPR%u", 0, 105))> {
345  // Give all SGPR classes higher priority than VGPR classes, because
346  // we want to spill SGPRs to VGPRs.
347  let AllocationPriority = 9;
348  let GeneratePressureSet = 0;
349}
350
351// SGPR 64-bit registers
352def SGPR_64Regs : SIRegisterTuples<getSubRegs<2>.ret, SGPR_32, 105, 2, 2, "s">;
353
354// SGPR 96-bit registers. No operations use these, but for symmetry with 96-bit VGPRs.
355def SGPR_96Regs : SIRegisterTuples<getSubRegs<3>.ret, SGPR_32, 105, 3, 3, "s">;
356
357// SGPR 128-bit registers
358def SGPR_128Regs : SIRegisterTuples<getSubRegs<4>.ret, SGPR_32, 105, 4, 4, "s">;
359
360// SGPR 160-bit registers. No operations use these, but for symmetry with 160-bit VGPRs.
361def SGPR_160Regs : SIRegisterTuples<getSubRegs<5>.ret, SGPR_32, 105, 4, 5, "s">;
362
363// SGPR 192-bit registers. No operations use these, but for symmetry with 192-bit VGPRs.
364def SGPR_192Regs : SIRegisterTuples<getSubRegs<6>.ret, SGPR_32, 105, 4, 6, "s">;
365
366// SGPR 224-bit registers. No operations use these, but for symmetry with 224-bit VGPRs.
367def SGPR_224Regs : SIRegisterTuples<getSubRegs<7>.ret, SGPR_32, 105, 4, 7, "s">;
368
369// SGPR 256-bit registers
370def SGPR_256Regs : SIRegisterTuples<getSubRegs<8>.ret, SGPR_32, 105, 4, 8, "s">;
371
372// SGPR 512-bit registers
373def SGPR_512Regs : SIRegisterTuples<getSubRegs<16>.ret, SGPR_32, 105, 4, 16, "s">;
374
375// SGPR 1024-bit registers
376def SGPR_1024Regs : SIRegisterTuples<getSubRegs<32>.ret, SGPR_32, 105, 4, 32, "s">;
377
378// Trap handler TMP 32-bit registers
379def TTMP_32 : RegisterClass<"AMDGPU", [i32, f32, v2i16, v2f16], 32,
380                            (add (sequence "TTMP%u", 0, 15))> {
381  let isAllocatable = 0;
382}
383
384// Trap handler TMP 16-bit registers
385def TTMP_LO16 : RegisterClass<"AMDGPU", [i16, f16], 16,
386                              (add (sequence "TTMP%u_LO16", 0, 15))> {
387  let Size = 16;
388  let isAllocatable = 0;
389}
390
391// Trap handler TMP 64-bit registers
392def TTMP_64Regs : SIRegisterTuples<getSubRegs<2>.ret, TTMP_32, 15, 2, 2, "ttmp">;
393
394// Trap handler TMP 96-bit registers
395def TTMP_96Regs : SIRegisterTuples<getSubRegs<3>.ret, TTMP_32, 15, 3, 3, "ttmp">;
396
397// Trap handler TMP 128-bit registers
398def TTMP_128Regs : SIRegisterTuples<getSubRegs<4>.ret, TTMP_32, 15, 4, 4, "ttmp">;
399
400// Trap handler TMP 160-bit registers
401def TTMP_160Regs : SIRegisterTuples<getSubRegs<5>.ret, TTMP_32, 15, 4, 5, "ttmp">;
402
403// Trap handler TMP 192-bit registers
404def TTMP_192Regs : SIRegisterTuples<getSubRegs<6>.ret, TTMP_32, 15, 4, 6, "ttmp">;
405
406// Trap handler TMP 224-bit registers
407def TTMP_224Regs : SIRegisterTuples<getSubRegs<7>.ret, TTMP_32, 15, 4, 7, "ttmp">;
408
409// Trap handler TMP 256-bit registers
410def TTMP_256Regs : SIRegisterTuples<getSubRegs<8>.ret, TTMP_32, 15, 4, 8, "ttmp">;
411
412// Trap handler TMP 512-bit registers
413def TTMP_512Regs : SIRegisterTuples<getSubRegs<16>.ret, TTMP_32, 15, 4, 16, "ttmp">;
414
415class TmpRegTuplesBase<int index, int size,
416                       list<Register> subRegs,
417                       list<SubRegIndex> indices = getSubRegs<size>.ret,
418                       int index1 = !add(index, size, -1),
419                       string name = "ttmp["#index#":"#index1#"]"> :
420  RegisterWithSubRegs<name, subRegs> {
421  let HWEncoding = subRegs[0].HWEncoding;
422  let SubRegIndices = indices;
423}
424
425class TmpRegTuples<string tgt,
426                   int size,
427                   int index0,
428                   int index1 = !add(index0, 1),
429                   int index2 = !add(index0, !if(!eq(size, 2), 1, 2)),
430                   int index3 = !add(index0, !if(!eq(size, 2), 1, 3)),
431                   int index4 = !add(index0, !if(!eq(size, 8), 4, 1)),
432                   int index5 = !add(index0, !if(!eq(size, 8), 5, 1)),
433                   int index6 = !add(index0, !if(!eq(size, 8), 6, 1)),
434                   int index7 = !add(index0, !if(!eq(size, 8), 7, 1)),
435                   Register r0 = !cast<Register>("TTMP"#index0#tgt),
436                   Register r1 = !cast<Register>("TTMP"#index1#tgt),
437                   Register r2 = !cast<Register>("TTMP"#index2#tgt),
438                   Register r3 = !cast<Register>("TTMP"#index3#tgt),
439                   Register r4 = !cast<Register>("TTMP"#index4#tgt),
440                   Register r5 = !cast<Register>("TTMP"#index5#tgt),
441                   Register r6 = !cast<Register>("TTMP"#index6#tgt),
442                   Register r7 = !cast<Register>("TTMP"#index7#tgt)> :
443  TmpRegTuplesBase<index0, size,
444                   !if(!eq(size, 2), [r0, r1],
445                       !if(!eq(size, 4), [r0, r1, r2, r3],
446                                         [r0, r1, r2, r3, r4, r5, r6, r7])),
447                   getSubRegs<size>.ret>;
448
449foreach Index = {0, 2, 4, 6, 8, 10, 12, 14} in {
450  def TTMP#Index#_TTMP#!add(Index,1)#_vi       : TmpRegTuples<"_vi",   2, Index>;
451  def TTMP#Index#_TTMP#!add(Index,1)#_gfx9plus : TmpRegTuples<"_gfx9plus", 2, Index>;
452}
453
454foreach Index = {0, 4, 8, 12} in {
455  def TTMP#Index#_TTMP#!add(Index,1)#
456                 _TTMP#!add(Index,2)#
457                 _TTMP#!add(Index,3)#_vi : TmpRegTuples<"_vi",   4, Index>;
458  def TTMP#Index#_TTMP#!add(Index,1)#
459                 _TTMP#!add(Index,2)#
460                 _TTMP#!add(Index,3)#_gfx9plus : TmpRegTuples<"_gfx9plus", 4, Index>;
461}
462
463foreach Index = {0, 4, 8} in {
464  def TTMP#Index#_TTMP#!add(Index,1)#
465                 _TTMP#!add(Index,2)#
466                 _TTMP#!add(Index,3)#
467                 _TTMP#!add(Index,4)#
468                 _TTMP#!add(Index,5)#
469                 _TTMP#!add(Index,6)#
470                 _TTMP#!add(Index,7)#_vi : TmpRegTuples<"_vi",   8, Index>;
471  def TTMP#Index#_TTMP#!add(Index,1)#
472                 _TTMP#!add(Index,2)#
473                 _TTMP#!add(Index,3)#
474                 _TTMP#!add(Index,4)#
475                 _TTMP#!add(Index,5)#
476                 _TTMP#!add(Index,6)#
477                 _TTMP#!add(Index,7)#_gfx9plus : TmpRegTuples<"_gfx9plus", 8, Index>;
478}
479
480def TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15_vi :
481  TmpRegTuplesBase<0, 16,
482                   [TTMP0_vi, TTMP1_vi, TTMP2_vi, TTMP3_vi,
483                    TTMP4_vi, TTMP5_vi, TTMP6_vi, TTMP7_vi,
484                    TTMP8_vi, TTMP9_vi, TTMP10_vi, TTMP11_vi,
485                    TTMP12_vi, TTMP13_vi, TTMP14_vi, TTMP15_vi]>;
486
487def TTMP0_TTMP1_TTMP2_TTMP3_TTMP4_TTMP5_TTMP6_TTMP7_TTMP8_TTMP9_TTMP10_TTMP11_TTMP12_TTMP13_TTMP14_TTMP15_gfx9plus :
488  TmpRegTuplesBase<0, 16,
489                   [TTMP0_gfx9plus, TTMP1_gfx9plus, TTMP2_gfx9plus, TTMP3_gfx9plus,
490                    TTMP4_gfx9plus, TTMP5_gfx9plus, TTMP6_gfx9plus, TTMP7_gfx9plus,
491                    TTMP8_gfx9plus, TTMP9_gfx9plus, TTMP10_gfx9plus, TTMP11_gfx9plus,
492                    TTMP12_gfx9plus, TTMP13_gfx9plus, TTMP14_gfx9plus, TTMP15_gfx9plus]>;
493
494class RegisterTypes<list<ValueType> reg_types> {
495  list<ValueType> types = reg_types;
496}
497
498def Reg16Types : RegisterTypes<[i16, f16]>;
499def Reg32Types : RegisterTypes<[i32, f32, v2i16, v2f16, p2, p3, p5, p6]>;
500
501let HasVGPR = 1 in {
502def VGPR_LO16 : SIRegisterClass<"AMDGPU", Reg16Types.types, 16,
503                              (add (sequence "VGPR%u_LO16", 0, 255))> {
504  let AllocationPriority = 1;
505  let Size = 16;
506  let GeneratePressureSet = 0;
507}
508
509def VGPR_HI16 : SIRegisterClass<"AMDGPU", Reg16Types.types, 16,
510                              (add (sequence "VGPR%u_HI16", 0, 255))> {
511  let AllocationPriority = 1;
512  let Size = 16;
513  let GeneratePressureSet = 0;
514}
515
516// VGPR 32-bit registers
517// i16/f16 only on VI+
518def VGPR_32 : SIRegisterClass<"AMDGPU", !listconcat(Reg32Types.types, Reg16Types.types), 32,
519                            (add (sequence "VGPR%u", 0, 255))> {
520  let AllocationPriority = 1;
521  let Size = 32;
522  let Weight = 1;
523}
524} // End HasVGPR = 1
525
526// VGPR 64-bit registers
527def VGPR_64 : SIRegisterTuples<getSubRegs<2>.ret, VGPR_32, 255, 1, 2, "v">;
528
529// VGPR 96-bit registers
530def VGPR_96 : SIRegisterTuples<getSubRegs<3>.ret, VGPR_32, 255, 1, 3, "v">;
531
532// VGPR 128-bit registers
533def VGPR_128 : SIRegisterTuples<getSubRegs<4>.ret, VGPR_32, 255, 1, 4, "v">;
534
535// VGPR 160-bit registers
536def VGPR_160 : SIRegisterTuples<getSubRegs<5>.ret, VGPR_32, 255, 1, 5, "v">;
537
538// VGPR 192-bit registers
539def VGPR_192 : SIRegisterTuples<getSubRegs<6>.ret, VGPR_32, 255, 1, 6, "v">;
540
541// VGPR 224-bit registers
542def VGPR_224 : SIRegisterTuples<getSubRegs<7>.ret, VGPR_32, 255, 1, 7, "v">;
543
544// VGPR 256-bit registers
545def VGPR_256 : SIRegisterTuples<getSubRegs<8>.ret, VGPR_32, 255, 1, 8, "v">;
546
547// VGPR 512-bit registers
548def VGPR_512 : SIRegisterTuples<getSubRegs<16>.ret, VGPR_32, 255, 1, 16, "v">;
549
550// VGPR 1024-bit registers
551def VGPR_1024 : SIRegisterTuples<getSubRegs<32>.ret, VGPR_32, 255, 1, 32, "v">;
552
553let HasAGPR = 1 in {
554def AGPR_LO16 : SIRegisterClass<"AMDGPU", Reg16Types.types, 16,
555                              (add (sequence "AGPR%u_LO16", 0, 255))> {
556  let isAllocatable = 0;
557  let Size = 16;
558  let GeneratePressureSet = 0;
559}
560
561// AccVGPR 32-bit registers
562def AGPR_32 : SIRegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
563                            (add (sequence "AGPR%u", 0, 255))> {
564  let AllocationPriority = 1;
565  let Size = 32;
566  let Weight = 1;
567}
568} // End HasAGPR = 1
569
570// AGPR 64-bit registers
571def AGPR_64 : SIRegisterTuples<getSubRegs<2>.ret, AGPR_32, 255, 1, 2, "a">;
572
573// AGPR 96-bit registers
574def AGPR_96 : SIRegisterTuples<getSubRegs<3>.ret, AGPR_32, 255, 1, 3, "a">;
575
576// AGPR 128-bit registers
577def AGPR_128 : SIRegisterTuples<getSubRegs<4>.ret, AGPR_32, 255, 1, 4, "a">;
578
579// AGPR 160-bit registers
580def AGPR_160 : SIRegisterTuples<getSubRegs<5>.ret, AGPR_32, 255, 1, 5, "a">;
581
582// AGPR 192-bit registers
583def AGPR_192 : SIRegisterTuples<getSubRegs<6>.ret, AGPR_32, 255, 1, 6, "a">;
584
585// AGPR 224-bit registers
586def AGPR_224 : SIRegisterTuples<getSubRegs<7>.ret, AGPR_32, 255, 1, 7, "a">;
587
588// AGPR 256-bit registers
589def AGPR_256 : SIRegisterTuples<getSubRegs<8>.ret, AGPR_32, 255, 1, 8, "a">;
590
591// AGPR 512-bit registers
592def AGPR_512 : SIRegisterTuples<getSubRegs<16>.ret, AGPR_32, 255, 1, 16, "a">;
593
594// AGPR 1024-bit registers
595def AGPR_1024 : SIRegisterTuples<getSubRegs<32>.ret, AGPR_32, 255, 1, 32, "a">;
596
597//===----------------------------------------------------------------------===//
598//  Register classes used as source and destination
599//===----------------------------------------------------------------------===//
600
601def Pseudo_SReg_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
602  (add FP_REG, SP_REG)> {
603  let isAllocatable = 0;
604  let CopyCost = -1;
605}
606
607def Pseudo_SReg_128 : RegisterClass<"AMDGPU", [v4i32, v2i64, v2f64], 32,
608  (add PRIVATE_RSRC_REG)> {
609  let isAllocatable = 0;
610  let CopyCost = -1;
611}
612
613def LDS_DIRECT_CLASS : RegisterClass<"AMDGPU", [i32], 32,
614  (add LDS_DIRECT)> {
615  let isAllocatable = 0;
616  let CopyCost = -1;
617}
618
619let GeneratePressureSet = 0 in {
620// Subset of SReg_32 without M0 for SMRD instructions and alike.
621// See comments in SIInstructions.td for more info.
622def SReg_32_XM0_XEXEC : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16, i1], 32,
623  (add SGPR_32, VCC_LO, VCC_HI, FLAT_SCR_LO, FLAT_SCR_HI, XNACK_MASK_LO, XNACK_MASK_HI,
624   SGPR_NULL, TTMP_32, TMA_LO, TMA_HI, TBA_LO, TBA_HI, SRC_SHARED_BASE, SRC_SHARED_LIMIT,
625   SRC_PRIVATE_BASE, SRC_PRIVATE_LIMIT, SRC_POPS_EXITING_WAVE_ID,
626   SRC_VCCZ, SRC_EXECZ, SRC_SCC)> {
627  let AllocationPriority = 10;
628}
629
630def SReg_LO16_XM0_XEXEC : RegisterClass<"AMDGPU", [i16, f16], 16,
631  (add SGPR_LO16, VCC_LO_LO16, VCC_HI_LO16, FLAT_SCR_LO_LO16, FLAT_SCR_HI_LO16,
632   XNACK_MASK_LO_LO16, XNACK_MASK_HI_LO16, SGPR_NULL_LO16, TTMP_LO16, TMA_LO_LO16,
633   TMA_HI_LO16, TBA_LO_LO16, TBA_HI_LO16, SRC_SHARED_BASE_LO16,
634   SRC_SHARED_LIMIT_LO16, SRC_PRIVATE_BASE_LO16, SRC_PRIVATE_LIMIT_LO16,
635   SRC_POPS_EXITING_WAVE_ID_LO16, SRC_VCCZ_LO16, SRC_EXECZ_LO16, SRC_SCC_LO16)> {
636  let Size = 16;
637  let AllocationPriority = 10;
638}
639
640def SReg_32_XEXEC_HI : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16, i1], 32,
641  (add SReg_32_XM0_XEXEC, EXEC_LO, M0_CLASS)> {
642  let AllocationPriority = 10;
643}
644
645def SReg_LO16_XEXEC_HI : RegisterClass<"AMDGPU", [i16, f16], 16,
646  (add SReg_LO16_XM0_XEXEC, EXEC_LO_LO16, M0_CLASS_LO16)> {
647  let Size = 16;
648  let AllocationPriority = 10;
649}
650
651def SReg_32_XM0 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16, i1], 32,
652  (add SReg_32_XM0_XEXEC, EXEC_LO, EXEC_HI)> {
653  let AllocationPriority = 10;
654}
655
656def SReg_LO16_XM0 : RegisterClass<"AMDGPU", [i16, f16], 16,
657  (add SReg_LO16_XM0_XEXEC, EXEC_LO_LO16, EXEC_HI_LO16)> {
658  let Size = 16;
659  let AllocationPriority = 10;
660}
661
662def SReg_LO16 : RegisterClass<"AMDGPU", [i16, f16], 16,
663  (add SGPR_LO16, SReg_LO16_XM0, M0_CLASS_LO16, EXEC_LO_LO16, EXEC_HI_LO16, SReg_LO16_XEXEC_HI)> {
664  let Size = 16;
665  let AllocationPriority = 10;
666}
667} // End GeneratePressureSet = 0
668
669// Register class for all scalar registers (SGPRs + Special Registers)
670def SReg_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16, i1], 32,
671  (add SReg_32_XM0, M0_CLASS, EXEC_LO, EXEC_HI, SReg_32_XEXEC_HI)> {
672  let AllocationPriority = 10;
673}
674
675let GeneratePressureSet = 0 in {
676def SRegOrLds_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
677  (add SReg_32, LDS_DIRECT_CLASS)> {
678  let isAllocatable = 0;
679}
680
681def SGPR_64 : RegisterClass<"AMDGPU", [v2i32, i64, v2f32, f64, v4i16, v4f16], 32,
682                            (add SGPR_64Regs)> {
683  let CopyCost = 1;
684  let AllocationPriority = 11;
685}
686
687// CCR (call clobbered registers) SGPR 64-bit registers
688def CCR_SGPR_64 : RegisterClass<"AMDGPU", SGPR_64.RegTypes, 32,
689                                (add (trunc SGPR_64, 16))> {
690  let CopyCost = SGPR_64.CopyCost;
691  let AllocationPriority = SGPR_64.AllocationPriority;
692}
693
694// Call clobbered 64-bit SGPRs for AMDGPU_Gfx CC
695def Gfx_CCR_SGPR_64 : RegisterClass<"AMDGPU", SGPR_64.RegTypes, 32,
696                                (add (trunc (shl SGPR_64, 15), 1), // s[30:31]
697                                     (trunc (shl SGPR_64, 18), 14))> { // s[36:37]-s[s62:63]
698  let CopyCost = SGPR_64.CopyCost;
699  let AllocationPriority = SGPR_64.AllocationPriority;
700}
701
702def TTMP_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64, v4i16, v4f16], 32,
703                            (add TTMP_64Regs)> {
704  let isAllocatable = 0;
705}
706
707def SReg_64_XEXEC : RegisterClass<"AMDGPU", [v2i32, i64, v2f32, f64, i1, v4i16, v4f16], 32,
708  (add SGPR_64, VCC, FLAT_SCR, XNACK_MASK, TTMP_64, TBA, TMA)> {
709  let CopyCost = 1;
710  let AllocationPriority = 13;
711}
712
713def SReg_64 : RegisterClass<"AMDGPU", [v2i32, i64, v2f32, f64, i1, v4i16, v4f16], 32,
714  (add SReg_64_XEXEC, EXEC)> {
715  let CopyCost = 1;
716  let AllocationPriority = 13;
717}
718
719def SReg_1_XEXEC : RegisterClass<"AMDGPU", [i1], 32,
720  (add SReg_64_XEXEC, SReg_32_XM0_XEXEC)> {
721  let CopyCost = 1;
722  let isAllocatable = 0;
723}
724
725def SReg_1 : RegisterClass<"AMDGPU", [i1], 32,
726  (add SReg_1_XEXEC, EXEC, EXEC_LO)> {
727  let CopyCost = 1;
728  let isAllocatable = 0;
729}
730
731multiclass SRegClass<int numRegs, int priority,
732                     list<ValueType> regTypes,
733                     SIRegisterTuples regList,
734                     SIRegisterTuples ttmpList = regList,
735                     int copyCost = !sra(!add(numRegs, 1), 1)> {
736  defvar hasTTMP = !ne(regList, ttmpList);
737  defvar suffix = !cast<string>(!mul(numRegs, 32));
738  defvar sgprName = !strconcat("SGPR_", suffix);
739  defvar ttmpName = !strconcat("TTMP_", suffix);
740
741  let AllocationPriority = priority, CopyCost = copyCost in {
742    def "" # sgprName : RegisterClass<"AMDGPU", regTypes, 32, (add regList)> {
743    }
744
745    if hasTTMP then {
746      def "" # ttmpName : RegisterClass<"AMDGPU", regTypes, 32, (add ttmpList)> {
747        let isAllocatable = 0;
748      }
749    }
750
751    def SReg_ # suffix :
752      RegisterClass<"AMDGPU", regTypes, 32,
753                    !con(!dag(add, [!cast<RegisterClass>(sgprName)], ["sgpr"]),
754                    !if(hasTTMP,
755                        !dag(add, [!cast<RegisterClass>(ttmpName)], ["ttmp"]),
756                        (add)))> {
757      let isAllocatable = 0;
758    }
759  }
760}
761
762defm "" : SRegClass<3, 14, [v3i32, v3f32], SGPR_96Regs, TTMP_96Regs>;
763defm "" : SRegClass<4, 15, [v4i32, v4f32, v2i64], SGPR_128Regs, TTMP_128Regs>;
764defm "" : SRegClass<5, 16, [v5i32, v5f32], SGPR_160Regs, TTMP_160Regs>;
765defm "" : SRegClass<6, 17, [v6i32, v6f32, v3i64, v3f64], SGPR_192Regs, TTMP_192Regs>;
766defm "" : SRegClass<7, 18, [v7i32, v7f32], SGPR_224Regs, TTMP_224Regs>;
767defm "" : SRegClass<8, 19, [v8i32, v8f32, v4i64, v4f64], SGPR_256Regs, TTMP_256Regs>;
768defm "" : SRegClass<16, 20, [v16i32, v16f32, v8i64, v8f64], SGPR_512Regs, TTMP_512Regs>;
769defm "" : SRegClass<32, 21, [v32i32, v32f32, v16i64, v16f64], SGPR_1024Regs>;
770
771def VRegOrLds_32 : SIRegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
772                                 (add VGPR_32, LDS_DIRECT_CLASS)> {
773  let isAllocatable = 0;
774  let HasVGPR = 1;
775}
776
777// Register class for all vector registers (VGPRs + Interpolation Registers)
778class VRegClassBase<int numRegs, list<ValueType> regTypes, dag regList> :
779    SIRegisterClass<"AMDGPU", regTypes, 32, regList> {
780  let Size = !mul(numRegs, 32);
781
782  // Requires n v_mov_b32 to copy
783  let CopyCost = numRegs;
784  let AllocationPriority = numRegs;
785  let Weight = numRegs;
786}
787
788// Define a register tuple class, along with one requiring an even
789// aligned base register.
790multiclass VRegClass<int numRegs, list<ValueType> regTypes, dag regList> {
791  let HasVGPR = 1 in {
792    // Define the regular class.
793    def "" : VRegClassBase<numRegs, regTypes, regList>;
794
795    // Define 2-aligned variant
796    def _Align2 : VRegClassBase<numRegs, regTypes, (decimate regList, 2)>;
797  }
798}
799
800defm VReg_64 : VRegClass<2, [i64, f64, v2i32, v2f32, v4f16, v4i16, p0, p1, p4],
801                                (add VGPR_64)>;
802defm VReg_96 : VRegClass<3, [v3i32, v3f32], (add VGPR_96)>;
803defm VReg_128 : VRegClass<4, [v4i32, v4f32, v2i64, v2f64], (add VGPR_128)>;
804defm VReg_160 : VRegClass<5, [v5i32, v5f32], (add VGPR_160)>;
805
806defm VReg_192 : VRegClass<6, [v6i32, v6f32, v3i64, v3f64], (add VGPR_192)>;
807defm VReg_224 : VRegClass<7, [v7i32, v7f32], (add VGPR_224)>;
808defm VReg_256 : VRegClass<8, [v8i32, v8f32, v4i64, v4f64], (add VGPR_256)>;
809defm VReg_512 : VRegClass<16, [v16i32, v16f32, v8i64, v8f64], (add VGPR_512)>;
810defm VReg_1024 : VRegClass<32, [v32i32, v32f32, v16i64, v16f64], (add VGPR_1024)>;
811
812multiclass ARegClass<int numRegs, list<ValueType> regTypes, dag regList> {
813  let CopyCost = !add(numRegs, numRegs, 1), HasAGPR = 1 in {
814    // Define the regular class.
815    def "" : VRegClassBase<numRegs, regTypes, regList>;
816
817    // Define 2-aligned variant
818    def _Align2 : VRegClassBase<numRegs, regTypes, (decimate regList, 2)>;
819  }
820}
821
822defm AReg_64 : ARegClass<2, [i64, f64, v2i32, v2f32, v4f16, v4i16],
823                        (add AGPR_64)>;
824defm AReg_96 : ARegClass<3, [v3i32, v3f32], (add AGPR_96)>;
825defm AReg_128 : ARegClass<4, [v4i32, v4f32, v2i64, v2f64], (add AGPR_128)>;
826defm AReg_160 : ARegClass<5, [v5i32, v5f32], (add AGPR_160)>;
827defm AReg_192 : ARegClass<6, [v6i32, v6f32, v3i64, v3f64], (add AGPR_192)>;
828defm AReg_224 : ARegClass<7, [v7i32, v7f32], (add AGPR_224)>;
829defm AReg_256 : ARegClass<8, [v8i32, v8f32, v4i64, v4f64], (add AGPR_256)>;
830defm AReg_512 : ARegClass<16, [v16i32, v16f32, v8i64, v8f64], (add AGPR_512)>;
831defm AReg_1024 : ARegClass<32, [v32i32, v32f32, v16i64, v16f64], (add AGPR_1024)>;
832
833} // End GeneratePressureSet = 0
834
835// This is not a real register. This is just to have a register to add
836// to VReg_1 that does not alias any real register that would
837// introduce inferred register classes.
838def ARTIFICIAL_VGPR : SIReg <"invalid vgpr", 0> {
839  let isArtificial = 1;
840}
841
842let GeneratePressureSet = 0 in {
843// FIXME: Should specify an empty set for this. No register should
844// ever be allocated using VReg_1. This is a hack for SelectionDAG
845// that should always be lowered by SILowerI1Copies. TableGen crashes
846// on an empty register set, but also sorts register classes based on
847// the number of registerss in them. Add only one register so this is
848// sorted to the end and not preferred over VGPR_32.
849def VReg_1 : SIRegisterClass<"AMDGPU", [i1], 32, (add ARTIFICIAL_VGPR)> {
850  let Size = 1;
851  let HasVGPR = 1;
852}
853
854def VS_32 : SIRegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
855                          (add VGPR_32, SReg_32, LDS_DIRECT_CLASS)> {
856  let isAllocatable = 0;
857  let HasVGPR = 1;
858}
859
860def VS_64 : SIRegisterClass<"AMDGPU", [i64, f64, v2f32], 32, (add VReg_64, SReg_64)> {
861  let isAllocatable = 0;
862  let HasVGPR = 1;
863}
864
865def AV_32 : SIRegisterClass<"AMDGPU", VGPR_32.RegTypes, 32,
866                          (add AGPR_32, VGPR_32)> {
867  let isAllocatable = 0;
868  let HasVGPR = 1;
869  let HasAGPR = 1;
870}
871
872def AV_64 : SIRegisterClass<"AMDGPU", VReg_64.RegTypes, 32,
873                          (add AReg_64, VReg_64)> {
874  let isAllocatable = 0;
875  let HasVGPR = 1;
876  let HasAGPR = 1;
877}
878} // End GeneratePressureSet = 0
879
880let HasVGPR = 1, HasAGPR = 1 in {
881def AV_96 : SIRegisterClass<"AMDGPU", VReg_96.RegTypes, 32,
882                          (add AReg_96, VReg_96)> {
883  let isAllocatable = 0;
884}
885
886def AV_128 : SIRegisterClass<"AMDGPU", VReg_128.RegTypes, 32,
887                          (add AReg_128, VReg_128)> {
888  let isAllocatable = 0;
889}
890
891def AV_160 : SIRegisterClass<"AMDGPU", VReg_160.RegTypes, 32,
892                          (add AReg_160, VReg_160)> {
893  let isAllocatable = 0;
894}
895} // End HasVGPR = 1, HasAGPR = 1
896
897//===----------------------------------------------------------------------===//
898//  Register operands
899//===----------------------------------------------------------------------===//
900
901class RegImmMatcher<string name> : AsmOperandClass {
902  let Name = name;
903  let RenderMethod = "addRegOrImmOperands";
904}
905
906multiclass SIRegOperand32 <string rc, string MatchName, string opType,
907                           string rc_suffix = "_32"> {
908  let OperandNamespace = "AMDGPU" in {
909    def _b16 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
910      let OperandType = opType#"_INT16";
911      let ParserMatchClass = RegImmMatcher<MatchName#"B16">;
912      let DecoderMethod = "decodeOperand_VSrc16";
913    }
914
915    def _f16 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
916      let OperandType = opType#"_FP16";
917      let ParserMatchClass = RegImmMatcher<MatchName#"F16">;
918      let DecoderMethod = "decodeOperand_" # rc # "_16";
919    }
920
921    def _b32 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
922      let OperandType = opType#"_INT32";
923      let ParserMatchClass = RegImmMatcher<MatchName#"B32">;
924      let DecoderMethod = "decodeOperand_" # rc # rc_suffix;
925    }
926
927    def _f32 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
928      let OperandType = opType#"_FP32";
929      let ParserMatchClass = RegImmMatcher<MatchName#"F32">;
930      let DecoderMethod = "decodeOperand_" # rc # rc_suffix;
931    }
932
933    def _v2b16 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
934      let OperandType = opType#"_V2INT16";
935      let ParserMatchClass = RegImmMatcher<MatchName#"V2B16">;
936      let DecoderMethod = "decodeOperand_VSrcV216";
937    }
938
939    def _v2f16 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
940      let OperandType = opType#"_V2FP16";
941      let ParserMatchClass = RegImmMatcher<MatchName#"V2F16">;
942      let DecoderMethod = "decodeOperand_VSrcV216";
943    }
944  }
945}
946
947multiclass SIRegOperand64 <string rc, string MatchName, string opType,
948                           string rc_suffix = "_64", bit Vectors = 1> {
949  let OperandNamespace = "AMDGPU" in {
950    def _b64 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
951      let OperandType = opType#"_INT64";
952      let ParserMatchClass = RegImmMatcher<MatchName#"B64">;
953    }
954
955    def _f64 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
956      let OperandType = opType#"_FP64";
957      let ParserMatchClass = RegImmMatcher<MatchName#"F64">;
958    }
959
960    if Vectors then
961    def _v2f32 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
962      let OperandType = opType#"_V2FP32";
963      let ParserMatchClass = RegImmMatcher<MatchName#"V2FP32">;
964      let DecoderMethod = "decodeOperand_VSrcV232";
965    }
966    if Vectors then
967    def _v2b32 : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
968      let OperandType = opType#"_V2INT32";
969      let ParserMatchClass = RegImmMatcher<MatchName#"V2INT32">;
970      let DecoderMethod = "decodeOperand_VSrcV232";
971    }
972  }
973}
974
975multiclass SIRegOperand <string rc, string MatchName, string opType> :
976  SIRegOperand32<rc, MatchName, opType>,
977  SIRegOperand64<rc, MatchName, opType>;
978
979// FIXME: 64-bit sources can sometimes use 32-bit constants.
980multiclass RegImmOperand <string rc, string MatchName>
981  : SIRegOperand<rc, MatchName, "OPERAND_REG_IMM">;
982
983multiclass RegInlineOperand <string rc, string MatchName>
984  : SIRegOperand<rc, MatchName, "OPERAND_REG_INLINE_C">;
985
986multiclass RegInlineOperand32 <string rc, string MatchName,
987                               string rc_suffix = "_32">
988  : SIRegOperand32<rc, MatchName, "OPERAND_REG_INLINE_C", rc_suffix>;
989
990multiclass RegInlineOperand64 <string rc, string MatchName,
991                               string rc_suffix = "_64">
992  : SIRegOperand64<rc, MatchName, "OPERAND_REG_INLINE_C", rc_suffix>;
993
994multiclass RegInlineOperandAC <string rc, string MatchName,
995                               string rc_suffix = "_32">
996  : SIRegOperand32<rc, MatchName, "OPERAND_REG_INLINE_AC", rc_suffix>;
997
998multiclass RegInlineOperandAC64 <string rc, string MatchName,
999                                 string rc_suffix = "_64">
1000  : SIRegOperand64<rc, MatchName, "OPERAND_REG_INLINE_AC", rc_suffix, 0>;
1001
1002//===----------------------------------------------------------------------===//
1003//  SSrc_* Operands with an SGPR or a 32-bit immediate
1004//===----------------------------------------------------------------------===//
1005
1006defm SSrc : RegImmOperand<"SReg", "SSrc">;
1007
1008def SSrcOrLds_b32 : RegisterOperand<SRegOrLds_32> {
1009  let OperandNamespace = "AMDGPU";
1010  let OperandType = "OPERAND_REG_IMM_INT32";
1011  let ParserMatchClass = RegImmMatcher<"SSrcOrLdsB32">;
1012}
1013
1014//===----------------------------------------------------------------------===//
1015//  SCSrc_* Operands with an SGPR or a inline constant
1016//===----------------------------------------------------------------------===//
1017
1018defm SCSrc : RegInlineOperand<"SReg", "SCSrc"> ;
1019
1020//===----------------------------------------------------------------------===//
1021//  VSrc_* Operands with an SGPR, VGPR or a 32-bit immediate
1022//===----------------------------------------------------------------------===//
1023
1024defm VSrc : RegImmOperand<"VS", "VSrc">;
1025
1026def VSrc_128 : RegisterOperand<VReg_128> {
1027  let DecoderMethod = "DecodeVS_128RegisterClass";
1028}
1029
1030//===----------------------------------------------------------------------===//
1031//  VSrc_*_Deferred Operands with an SGPR, VGPR or a 32-bit immediate for use
1032//  with FMAMK/FMAAK
1033//===----------------------------------------------------------------------===//
1034
1035multiclass SIRegOperand32_Deferred <string rc, string MatchName, string opType,
1036                           string rc_suffix = "_32"> {
1037  let OperandNamespace = "AMDGPU" in {
1038    def _f16_Deferred : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
1039      let OperandType = opType#"_FP16_DEFERRED";
1040      let ParserMatchClass = RegImmMatcher<MatchName#"F16">;
1041      let DecoderMethod = "decodeOperand_" # rc # "_16_Deferred";
1042    }
1043
1044    def _f32_Deferred : RegisterOperand<!cast<RegisterClass>(rc#rc_suffix)> {
1045      let OperandType = opType#"_FP32_DEFERRED";
1046      let ParserMatchClass = RegImmMatcher<MatchName#"F32">;
1047      let DecoderMethod = "decodeOperand_" # rc # "_32_Deferred";
1048    }
1049  }
1050}
1051
1052defm VSrc : SIRegOperand32_Deferred<"VS", "VSrc", "OPERAND_REG_IMM">;
1053
1054//===----------------------------------------------------------------------===//
1055//  VRegSrc_* Operands with a VGPR
1056//===----------------------------------------------------------------------===//
1057
1058// This is for operands with the enum(9), VSrc encoding restriction,
1059// but only allows VGPRs.
1060def VRegSrc_32 : RegisterOperand<VGPR_32> {
1061  //let ParserMatchClass = RegImmMatcher<"VRegSrc32">;
1062  let DecoderMethod = "DecodeVS_32RegisterClass";
1063}
1064
1065//===----------------------------------------------------------------------===//
1066//  ASrc_* Operands with an AccVGPR
1067//===----------------------------------------------------------------------===//
1068
1069def ARegSrc_32 : RegisterOperand<AGPR_32> {
1070  let DecoderMethod = "DecodeAGPR_32RegisterClass";
1071  let EncoderMethod = "getAVOperandEncoding";
1072}
1073
1074//===----------------------------------------------------------------------===//
1075//  VCSrc_* Operands with an SGPR, VGPR or an inline constant
1076//===----------------------------------------------------------------------===//
1077
1078defm VCSrc : RegInlineOperand<"VS", "VCSrc">;
1079
1080//===----------------------------------------------------------------------===//
1081//  VISrc_* Operands with a VGPR or an inline constant
1082//===----------------------------------------------------------------------===//
1083
1084defm VISrc : RegInlineOperand32<"VGPR", "VISrc">;
1085let DecoderMethod = "decodeOperand_VReg_64" in
1086defm VISrc_64   : RegInlineOperand64<"VReg", "VISrc_64",   "_64">;
1087defm VISrc_128  : RegInlineOperandAC<"VReg", "VISrc_128",  "_128">;
1088let DecoderMethod = "decodeOperand_VReg_256" in
1089defm VISrc_256  : RegInlineOperand64<"VReg", "VISrc_256",  "_256">;
1090defm VISrc_512  : RegInlineOperandAC<"VReg", "VISrc_512",  "_512">;
1091defm VISrc_1024 : RegInlineOperandAC<"VReg", "VISrc_1024", "_1024">;
1092
1093//===----------------------------------------------------------------------===//
1094//  AVSrc_* Operands with an AGPR or VGPR
1095//===----------------------------------------------------------------------===//
1096
1097def AVSrc_32 : RegisterOperand<AV_32> {
1098  let DecoderMethod = "DecodeAV_32RegisterClass";
1099  let EncoderMethod = "getAVOperandEncoding";
1100}
1101
1102def AVSrc_64 : RegisterOperand<AV_64> {
1103  let DecoderMethod = "DecodeAV_64RegisterClass";
1104  let EncoderMethod = "getAVOperandEncoding";
1105}
1106
1107def AVLdSt_32 : RegisterOperand<AV_32> {
1108  let DecoderMethod = "DecodeAVLdSt_32RegisterClass";
1109  let EncoderMethod = "getAVOperandEncoding";
1110}
1111
1112def AVLdSt_64 : RegisterOperand<AV_64> {
1113  let DecoderMethod = "DecodeAVLdSt_64RegisterClass";
1114  let EncoderMethod = "getAVOperandEncoding";
1115}
1116
1117def AVLdSt_96 : RegisterOperand<AV_96> {
1118  let DecoderMethod = "DecodeAVLdSt_96RegisterClass";
1119  let EncoderMethod = "getAVOperandEncoding";
1120}
1121
1122def AVLdSt_128 : RegisterOperand<AV_128> {
1123  let DecoderMethod = "DecodeAVLdSt_128RegisterClass";
1124  let EncoderMethod = "getAVOperandEncoding";
1125}
1126
1127def AVLdSt_160 : RegisterOperand<AV_160> {
1128  let DecoderMethod = "DecodeAVLdSt_160RegisterClass";
1129  let EncoderMethod = "getAVOperandEncoding";
1130}
1131
1132//===----------------------------------------------------------------------===//
1133//  ACSrc_* Operands with an AGPR or an inline constant
1134//===----------------------------------------------------------------------===//
1135
1136defm AISrc      : RegInlineOperandAC<"AGPR", "AISrc">;
1137defm AISrc_128  : RegInlineOperandAC<"AReg", "AISrc_128",  "_128">;
1138defm AISrc_512  : RegInlineOperandAC<"AReg", "AISrc_512",  "_512">;
1139defm AISrc_1024 : RegInlineOperandAC<"AReg", "AISrc_1024", "_1024">;
1140
1141let DecoderMethod = "decodeOperand_AReg_64" in
1142defm AISrc_64   : RegInlineOperandAC64<"AReg", "AISrc_64",   "_64">;
1143let DecoderMethod = "decodeOperand_AReg_256" in
1144defm AISrc_256  : RegInlineOperandAC64<"AReg", "AISrc_256",  "_256">;
1145