1//===-- SIRegisterInfo.td - SI Register defs ---------------*- tablegen -*-===//
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//===----------------------------------------------------------------------===//
11//  Declarations that describe the SI registers
12//===----------------------------------------------------------------------===//
13
14class SIReg <string n, bits<16> encoding = 0> : Register<n> {
15  let Namespace = "AMDGPU";
16  let HWEncoding = encoding;
17}
18
19// Special Registers
20def VCC_LO : SIReg<"vcc_lo", 106>;
21def VCC_HI : SIReg<"vcc_hi", 107>;
22
23// VCC for 64-bit instructions
24def VCC : RegisterWithSubRegs<"vcc", [VCC_LO, VCC_HI]> {
25  let Namespace = "AMDGPU";
26  let SubRegIndices = [sub0, sub1];
27  let HWEncoding = 106;
28}
29
30def EXEC_LO : SIReg<"exec_lo", 126>;
31def EXEC_HI : SIReg<"exec_hi", 127>;
32
33def EXEC : RegisterWithSubRegs<"EXEC", [EXEC_LO, EXEC_HI]> {
34  let Namespace = "AMDGPU";
35  let SubRegIndices = [sub0, sub1];
36  let HWEncoding = 126;
37}
38
39def SCC : SIReg<"scc", 253>;
40def M0 : SIReg <"m0", 124>;
41
42def FLAT_SCR_LO : SIReg<"flat_scr_lo", 104>; // Offset in units of 256-bytes.
43def FLAT_SCR_HI : SIReg<"flat_scr_hi", 105>; // Size is the per-thread scratch size, in bytes.
44
45// Pair to indicate location of scratch space for flat accesses.
46def FLAT_SCR : RegisterWithSubRegs <"flat_scr", [FLAT_SCR_LO, FLAT_SCR_HI]> {
47  let Namespace = "AMDGPU";
48  let SubRegIndices = [sub0, sub1];
49  let HWEncoding = 104;
50}
51
52// SGPR registers
53foreach Index = 0-101 in {
54  def SGPR#Index : SIReg <"SGPR"#Index, Index>;
55}
56
57// VGPR registers
58foreach Index = 0-255 in {
59  def VGPR#Index : SIReg <"VGPR"#Index, Index> {
60    let HWEncoding{8} = 1;
61  }
62}
63
64//===----------------------------------------------------------------------===//
65//  Groupings using register classes and tuples
66//===----------------------------------------------------------------------===//
67
68// SGPR 32-bit registers
69def SGPR_32 : RegisterClass<"AMDGPU", [i32, f32], 32,
70                            (add (sequence "SGPR%u", 0, 101))>;
71
72// SGPR 64-bit registers
73def SGPR_64Regs : RegisterTuples<[sub0, sub1],
74                             [(add (decimate (trunc SGPR_32, 101), 2)),
75                              (add (decimate (shl SGPR_32, 1), 2))]>;
76
77// SGPR 128-bit registers
78def SGPR_128 : RegisterTuples<[sub0, sub1, sub2, sub3],
79                              [(add (decimate (trunc SGPR_32, 99), 4)),
80                               (add (decimate (shl SGPR_32, 1), 4)),
81                               (add (decimate (shl SGPR_32, 2), 4)),
82                               (add (decimate (shl SGPR_32, 3), 4))]>;
83
84// SGPR 256-bit registers
85def SGPR_256 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7],
86                              [(add (decimate (trunc SGPR_32, 95), 4)),
87                               (add (decimate (shl SGPR_32, 1), 4)),
88                               (add (decimate (shl SGPR_32, 2), 4)),
89                               (add (decimate (shl SGPR_32, 3), 4)),
90                               (add (decimate (shl SGPR_32, 4), 4)),
91                               (add (decimate (shl SGPR_32, 5), 4)),
92                               (add (decimate (shl SGPR_32, 6), 4)),
93                               (add (decimate (shl SGPR_32, 7), 4))]>;
94
95// SGPR 512-bit registers
96def SGPR_512 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7,
97                               sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15],
98                              [(add (decimate (trunc SGPR_32, 87), 4)),
99                               (add (decimate (shl SGPR_32, 1), 4)),
100                               (add (decimate (shl SGPR_32, 2), 4)),
101                               (add (decimate (shl SGPR_32, 3), 4)),
102                               (add (decimate (shl SGPR_32, 4), 4)),
103                               (add (decimate (shl SGPR_32, 5), 4)),
104                               (add (decimate (shl SGPR_32, 6), 4)),
105                               (add (decimate (shl SGPR_32, 7), 4)),
106                               (add (decimate (shl SGPR_32, 8), 4)),
107                               (add (decimate (shl SGPR_32, 9), 4)),
108                               (add (decimate (shl SGPR_32, 10), 4)),
109                               (add (decimate (shl SGPR_32, 11), 4)),
110                               (add (decimate (shl SGPR_32, 12), 4)),
111                               (add (decimate (shl SGPR_32, 13), 4)),
112                               (add (decimate (shl SGPR_32, 14), 4)),
113                               (add (decimate (shl SGPR_32, 15), 4))]>;
114
115// VGPR 32-bit registers
116def VGPR_32 : RegisterClass<"AMDGPU", [i32, f32], 32,
117                            (add (sequence "VGPR%u", 0, 255))>;
118
119// VGPR 64-bit registers
120def VGPR_64 : RegisterTuples<[sub0, sub1],
121                             [(add (trunc VGPR_32, 255)),
122                              (add (shl VGPR_32, 1))]>;
123
124// VGPR 96-bit registers
125def VGPR_96 : RegisterTuples<[sub0, sub1, sub2],
126                             [(add (trunc VGPR_32, 254)),
127                              (add (shl VGPR_32, 1)),
128                              (add (shl VGPR_32, 2))]>;
129
130// VGPR 128-bit registers
131def VGPR_128 : RegisterTuples<[sub0, sub1, sub2, sub3],
132                              [(add (trunc VGPR_32, 253)),
133                               (add (shl VGPR_32, 1)),
134                               (add (shl VGPR_32, 2)),
135                               (add (shl VGPR_32, 3))]>;
136
137// VGPR 256-bit registers
138def VGPR_256 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7],
139                              [(add (trunc VGPR_32, 249)),
140                               (add (shl VGPR_32, 1)),
141                               (add (shl VGPR_32, 2)),
142                               (add (shl VGPR_32, 3)),
143                               (add (shl VGPR_32, 4)),
144                               (add (shl VGPR_32, 5)),
145                               (add (shl VGPR_32, 6)),
146                               (add (shl VGPR_32, 7))]>;
147
148// VGPR 512-bit registers
149def VGPR_512 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7,
150                               sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15],
151                              [(add (trunc VGPR_32, 241)),
152                               (add (shl VGPR_32, 1)),
153                               (add (shl VGPR_32, 2)),
154                               (add (shl VGPR_32, 3)),
155                               (add (shl VGPR_32, 4)),
156                               (add (shl VGPR_32, 5)),
157                               (add (shl VGPR_32, 6)),
158                               (add (shl VGPR_32, 7)),
159                               (add (shl VGPR_32, 8)),
160                               (add (shl VGPR_32, 9)),
161                               (add (shl VGPR_32, 10)),
162                               (add (shl VGPR_32, 11)),
163                               (add (shl VGPR_32, 12)),
164                               (add (shl VGPR_32, 13)),
165                               (add (shl VGPR_32, 14)),
166                               (add (shl VGPR_32, 15))]>;
167
168//===----------------------------------------------------------------------===//
169//  Register classes used as source and destination
170//===----------------------------------------------------------------------===//
171
172class RegImmMatcher<string name> : AsmOperandClass {
173  let Name = name;
174  let RenderMethod = "addRegOrImmOperands";
175}
176
177// Special register classes for predicates and the M0 register
178def SCCReg : RegisterClass<"AMDGPU", [i32, i1], 32, (add SCC)> {
179  let CopyCost = -1; // Theoretically it is possible to read from SCC,
180                     // but it should never be necessary.
181}
182
183def VCCReg : RegisterClass<"AMDGPU", [i64, i1], 64, (add VCC)>;
184def EXECReg : RegisterClass<"AMDGPU", [i64, i1], 64, (add EXEC)>;
185def M0Reg : RegisterClass<"AMDGPU", [i32], 32, (add M0)>;
186
187// Register class for all scalar registers (SGPRs + Special Registers)
188def SReg_32 : RegisterClass<"AMDGPU", [i32, f32], 32,
189  (add SGPR_32, M0Reg, VCC_LO, VCC_HI, EXEC_LO, EXEC_HI, FLAT_SCR_LO, FLAT_SCR_HI)
190>;
191
192def SGPR_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64], 64, (add SGPR_64Regs)>;
193
194def SReg_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64, i1], 64,
195  (add SGPR_64, VCCReg, EXECReg, FLAT_SCR)
196>;
197
198def SReg_128 : RegisterClass<"AMDGPU", [v4i32, v16i8], 128, (add SGPR_128)>;
199
200def SReg_256 : RegisterClass<"AMDGPU", [v32i8, v8i32, v8f32], 256, (add SGPR_256)>;
201
202def SReg_512 : RegisterClass<"AMDGPU", [v64i8, v16i32], 512, (add SGPR_512)>;
203
204// Register class for all vector registers (VGPRs + Interploation Registers)
205def VReg_64 : RegisterClass<"AMDGPU", [i64, f64, v2i32, v2f32], 64, (add VGPR_64)>;
206
207def VReg_96 : RegisterClass<"AMDGPU", [untyped], 96, (add VGPR_96)> {
208  let Size = 96;
209}
210
211def VReg_128 : RegisterClass<"AMDGPU", [v4i32, v4f32], 128, (add VGPR_128)>;
212
213def VReg_256 : RegisterClass<"AMDGPU", [v32i8, v8i32, v8f32], 256, (add VGPR_256)>;
214
215def VReg_512 : RegisterClass<"AMDGPU", [v16i32, v16f32], 512, (add VGPR_512)>;
216
217def VReg_1 : RegisterClass<"AMDGPU", [i1], 32, (add VGPR_32)> {
218  let Size = 32;
219}
220
221class RegImmOperand <RegisterClass rc> : RegisterOperand<rc> {
222  let OperandNamespace = "AMDGPU";
223  let OperandType = "OPERAND_REG_IMM32";
224}
225
226class RegInlineOperand <RegisterClass rc> : RegisterOperand<rc> {
227  let OperandNamespace = "AMDGPU";
228  let OperandType = "OPERAND_REG_INLINE_C";
229}
230
231//===----------------------------------------------------------------------===//
232//  SSrc_* Operands with an SGPR or a 32-bit immediate
233//===----------------------------------------------------------------------===//
234
235def SSrc_32 : RegImmOperand<SReg_32> {
236  let ParserMatchClass = RegImmMatcher<"SSrc32">;
237}
238
239def SSrc_64 : RegImmOperand<SReg_64> {
240  let ParserMatchClass = RegImmMatcher<"SSrc64">;
241}
242
243//===----------------------------------------------------------------------===//
244//  SCSrc_* Operands with an SGPR or a inline constant
245//===----------------------------------------------------------------------===//
246
247def SCSrc_32 : RegInlineOperand<SReg_32> {
248  let ParserMatchClass = RegImmMatcher<"SCSrc32">;
249}
250
251//===----------------------------------------------------------------------===//
252//  VSrc_* Operands with an SGPR, VGPR or a 32-bit immediate
253//===----------------------------------------------------------------------===//
254
255def VS_32 : RegisterClass<"AMDGPU", [i32, f32], 32, (add VGPR_32, SReg_32)>;
256
257def VS_64 : RegisterClass<"AMDGPU", [i64, f64], 64, (add VReg_64, SReg_64)>;
258
259def VSrc_32 : RegisterOperand<VS_32> {
260  let OperandNamespace = "AMDGPU";
261  let OperandType = "OPERAND_REG_IMM32";
262  let ParserMatchClass = RegImmMatcher<"VSrc32">;
263}
264
265def VSrc_64 : RegisterOperand<VS_64> {
266  let OperandNamespace = "AMDGPU";
267  let OperandType = "OPERAND_REG_IMM32";
268  let ParserMatchClass = RegImmMatcher<"VSrc64">;
269}
270
271//===----------------------------------------------------------------------===//
272//  VCSrc_* Operands with an SGPR, VGPR or an inline constant
273//===----------------------------------------------------------------------===//
274
275def VCSrc_32 : RegisterOperand<VS_32> {
276  let OperandNamespace = "AMDGPU";
277  let OperandType = "OPERAND_REG_INLINE_C";
278  let ParserMatchClass = RegImmMatcher<"VCSrc32">;
279}
280
281def VCSrc_64 : RegisterOperand<VS_64> {
282  let OperandNamespace = "AMDGPU";
283  let OperandType = "OPERAND_REG_INLINE_C";
284  let ParserMatchClass = RegImmMatcher<"VCSrc64">;
285}
286