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