]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/SIRegisterInfo.td
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r308421, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / 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 // Pseudo-registers: Used as placeholders during isel and immediately
27 // replaced, never seeing the verifier.
28 def PRIVATE_RSRC_REG : SIReg<"", 0>;
29 def FP_REG : SIReg<"", 0>;
30 def SP_REG : SIReg<"", 0>;
31 def SCRATCH_WAVE_OFFSET_REG : SIReg<"", 0>;
32
33 // VCC for 64-bit instructions
34 def VCC : RegisterWithSubRegs<"vcc", [VCC_LO, VCC_HI]>,
35           DwarfRegAlias<VCC_LO> {
36   let Namespace = "AMDGPU";
37   let SubRegIndices = [sub0, sub1];
38   let HWEncoding = 106;
39 }
40
41 def EXEC_LO : SIReg<"exec_lo", 126>;
42 def EXEC_HI : SIReg<"exec_hi", 127>;
43
44 def EXEC : RegisterWithSubRegs<"EXEC", [EXEC_LO, EXEC_HI]>,
45            DwarfRegAlias<EXEC_LO> {
46   let Namespace = "AMDGPU";
47   let SubRegIndices = [sub0, sub1];
48   let HWEncoding = 126;
49 }
50
51 def SCC : SIReg<"scc", 253>;
52 def M0 : SIReg <"m0", 124>;
53
54 def SRC_SHARED_BASE : SIReg<"src_shared_base", 235>;
55 def SRC_SHARED_LIMIT : SIReg<"src_shared_limit", 236>;
56 def SRC_PRIVATE_BASE : SIReg<"src_private_base", 237>;
57 def SRC_PRIVATE_LIMIT : SIReg<"src_private_limit", 238>;
58
59 // Trap handler registers
60 def TBA_LO : SIReg<"tba_lo", 108>;
61 def TBA_HI : SIReg<"tba_hi", 109>;
62
63 def TBA : RegisterWithSubRegs<"tba", [TBA_LO, TBA_HI]>,
64           DwarfRegAlias<TBA_LO> {
65   let Namespace = "AMDGPU";
66   let SubRegIndices = [sub0, sub1];
67   let HWEncoding = 108;
68 }
69
70 def TMA_LO : SIReg<"tma_lo", 110>;
71 def TMA_HI : SIReg<"tma_hi", 111>;
72
73 def TMA : RegisterWithSubRegs<"tma", [TMA_LO, TMA_HI]>,
74           DwarfRegAlias<TMA_LO> {
75   let Namespace = "AMDGPU";
76   let SubRegIndices = [sub0, sub1];
77   let HWEncoding = 110;
78 }
79
80 def TTMP0 : SIReg <"ttmp0", 112>;
81 def TTMP1 : SIReg <"ttmp1", 113>;
82 def TTMP2 : SIReg <"ttmp2", 114>;
83 def TTMP3 : SIReg <"ttmp3", 115>;
84 def TTMP4 : SIReg <"ttmp4", 116>;
85 def TTMP5 : SIReg <"ttmp5", 117>;
86 def TTMP6 : SIReg <"ttmp6", 118>;
87 def TTMP7 : SIReg <"ttmp7", 119>;
88 def TTMP8 : SIReg <"ttmp8", 120>;
89 def TTMP9 : SIReg <"ttmp9", 121>;
90 def TTMP10 : SIReg <"ttmp10", 122>;
91 def TTMP11 : SIReg <"ttmp11", 123>;
92
93 multiclass FLAT_SCR_LOHI_m <string n, bits<16> ci_e, bits<16> vi_e> {
94   def _ci : SIReg<n, ci_e>;
95   def _vi : SIReg<n, vi_e>;
96   def "" : SIReg<"", 0>;
97 }
98
99 class FlatReg <Register lo, Register hi, bits<16> encoding> :
100     RegisterWithSubRegs<"flat_scratch", [lo, hi]>,
101     DwarfRegAlias<lo> {
102   let Namespace = "AMDGPU";
103   let SubRegIndices = [sub0, sub1];
104   let HWEncoding = encoding;
105 }
106
107 defm FLAT_SCR_LO : FLAT_SCR_LOHI_m<"flat_scratch_lo", 104, 102>; // Offset in units of 256-bytes.
108 defm FLAT_SCR_HI : FLAT_SCR_LOHI_m<"flat_scratch_hi", 105, 103>; // Size is the per-thread scratch size, in bytes.
109
110 def FLAT_SCR_ci : FlatReg<FLAT_SCR_LO_ci, FLAT_SCR_HI_ci, 104>;
111 def FLAT_SCR_vi : FlatReg<FLAT_SCR_LO_vi, FLAT_SCR_HI_vi, 102>;
112 def FLAT_SCR : FlatReg<FLAT_SCR_LO, FLAT_SCR_HI, 0>;
113
114 // SGPR registers
115 foreach Index = 0-103 in {
116   def SGPR#Index : SIReg <"SGPR"#Index, Index>;
117 }
118
119 // VGPR registers
120 foreach Index = 0-255 in {
121   def VGPR#Index : SIReg <"VGPR"#Index, Index> {
122     let HWEncoding{8} = 1;
123   }
124 }
125
126 //===----------------------------------------------------------------------===//
127 //  Groupings using register classes and tuples
128 //===----------------------------------------------------------------------===//
129
130 def SCC_CLASS : RegisterClass<"AMDGPU", [i1], 1, (add SCC)> {
131   let CopyCost = -1;
132   let isAllocatable = 0;
133 }
134
135 def M0_CLASS : RegisterClass<"AMDGPU", [i32], 32, (add M0)> {
136   let CopyCost = 1;
137   let isAllocatable = 0;
138 }
139
140 // TODO: Do we need to set DwarfRegAlias on register tuples?
141
142 // SGPR 32-bit registers
143 def SGPR_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
144                             (add (sequence "SGPR%u", 0, 103))> {
145   // Give all SGPR classes higher priority than VGPR classes, because
146   // we want to spill SGPRs to VGPRs.
147   let AllocationPriority = 7;
148 }
149
150 // SGPR 64-bit registers
151 def SGPR_64Regs : RegisterTuples<[sub0, sub1],
152                              [(add (decimate SGPR_32, 2)),
153                               (add (decimate (shl SGPR_32, 1), 2))]>;
154
155 // SGPR 128-bit registers
156 def SGPR_128Regs : RegisterTuples<[sub0, sub1, sub2, sub3],
157                               [(add (decimate SGPR_32, 4)),
158                                (add (decimate (shl SGPR_32, 1), 4)),
159                                (add (decimate (shl SGPR_32, 2), 4)),
160                                (add (decimate (shl SGPR_32, 3), 4))]>;
161
162 // SGPR 256-bit registers
163 def SGPR_256 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7],
164                               [(add (decimate SGPR_32, 4)),
165                                (add (decimate (shl SGPR_32, 1), 4)),
166                                (add (decimate (shl SGPR_32, 2), 4)),
167                                (add (decimate (shl SGPR_32, 3), 4)),
168                                (add (decimate (shl SGPR_32, 4), 4)),
169                                (add (decimate (shl SGPR_32, 5), 4)),
170                                (add (decimate (shl SGPR_32, 6), 4)),
171                                (add (decimate (shl SGPR_32, 7), 4))]>;
172
173 // SGPR 512-bit registers
174 def SGPR_512 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7,
175                                sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15],
176                               [(add (decimate SGPR_32, 4)),
177                                (add (decimate (shl SGPR_32, 1), 4)),
178                                (add (decimate (shl SGPR_32, 2), 4)),
179                                (add (decimate (shl SGPR_32, 3), 4)),
180                                (add (decimate (shl SGPR_32, 4), 4)),
181                                (add (decimate (shl SGPR_32, 5), 4)),
182                                (add (decimate (shl SGPR_32, 6), 4)),
183                                (add (decimate (shl SGPR_32, 7), 4)),
184                                (add (decimate (shl SGPR_32, 8), 4)),
185                                (add (decimate (shl SGPR_32, 9), 4)),
186                                (add (decimate (shl SGPR_32, 10), 4)),
187                                (add (decimate (shl SGPR_32, 11), 4)),
188                                (add (decimate (shl SGPR_32, 12), 4)),
189                                (add (decimate (shl SGPR_32, 13), 4)),
190                                (add (decimate (shl SGPR_32, 14), 4)),
191                                (add (decimate (shl SGPR_32, 15), 4))]>;
192
193 // Trap handler TMP 32-bit registers
194 def TTMP_32 : RegisterClass<"AMDGPU", [i32, f32, v2i16, v2f16], 32,
195                             (add (sequence "TTMP%u", 0, 11))> {
196   let isAllocatable = 0;
197 }
198
199 // Trap handler TMP 64-bit registers
200 def TTMP_64Regs : RegisterTuples<[sub0, sub1],
201                              [(add (decimate TTMP_32, 2)),
202                               (add (decimate (shl TTMP_32, 1), 2))]>;
203
204 // Trap handler TMP 128-bit registers
205 def TTMP_128Regs : RegisterTuples<[sub0, sub1, sub2, sub3],
206                               [(add (decimate TTMP_32, 4)),
207                                (add (decimate (shl TTMP_32, 1), 4)),
208                                (add (decimate (shl TTMP_32, 2), 4)),
209                                (add (decimate (shl TTMP_32, 3), 4))]>;
210
211 // VGPR 32-bit registers
212 // i16/f16 only on VI+
213 def VGPR_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
214                             (add (sequence "VGPR%u", 0, 255))> {
215   let AllocationPriority = 1;
216   let Size = 32;
217 }
218
219 // VGPR 64-bit registers
220 def VGPR_64 : RegisterTuples<[sub0, sub1],
221                              [(add (trunc VGPR_32, 255)),
222                               (add (shl VGPR_32, 1))]>;
223
224 // VGPR 96-bit registers
225 def VGPR_96 : RegisterTuples<[sub0, sub1, sub2],
226                              [(add (trunc VGPR_32, 254)),
227                               (add (shl VGPR_32, 1)),
228                               (add (shl VGPR_32, 2))]>;
229
230 // VGPR 128-bit registers
231 def VGPR_128 : RegisterTuples<[sub0, sub1, sub2, sub3],
232                               [(add (trunc VGPR_32, 253)),
233                                (add (shl VGPR_32, 1)),
234                                (add (shl VGPR_32, 2)),
235                                (add (shl VGPR_32, 3))]>;
236
237 // VGPR 256-bit registers
238 def VGPR_256 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7],
239                               [(add (trunc VGPR_32, 249)),
240                                (add (shl VGPR_32, 1)),
241                                (add (shl VGPR_32, 2)),
242                                (add (shl VGPR_32, 3)),
243                                (add (shl VGPR_32, 4)),
244                                (add (shl VGPR_32, 5)),
245                                (add (shl VGPR_32, 6)),
246                                (add (shl VGPR_32, 7))]>;
247
248 // VGPR 512-bit registers
249 def VGPR_512 : RegisterTuples<[sub0, sub1, sub2, sub3, sub4, sub5, sub6, sub7,
250                                sub8, sub9, sub10, sub11, sub12, sub13, sub14, sub15],
251                               [(add (trunc VGPR_32, 241)),
252                                (add (shl VGPR_32, 1)),
253                                (add (shl VGPR_32, 2)),
254                                (add (shl VGPR_32, 3)),
255                                (add (shl VGPR_32, 4)),
256                                (add (shl VGPR_32, 5)),
257                                (add (shl VGPR_32, 6)),
258                                (add (shl VGPR_32, 7)),
259                                (add (shl VGPR_32, 8)),
260                                (add (shl VGPR_32, 9)),
261                                (add (shl VGPR_32, 10)),
262                                (add (shl VGPR_32, 11)),
263                                (add (shl VGPR_32, 12)),
264                                (add (shl VGPR_32, 13)),
265                                (add (shl VGPR_32, 14)),
266                                (add (shl VGPR_32, 15))]>;
267
268 //===----------------------------------------------------------------------===//
269 //  Register classes used as source and destination
270 //===----------------------------------------------------------------------===//
271
272 // Subset of SReg_32 without M0 for SMRD instructions and alike.
273 // See comments in SIInstructions.td for more info.
274 def SReg_32_XM0_XEXEC : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
275   (add SGPR_32, VCC_LO, VCC_HI, FLAT_SCR_LO, FLAT_SCR_HI,
276    TTMP_32, TMA_LO, TMA_HI, TBA_LO, TBA_HI, SRC_SHARED_BASE, SRC_SHARED_LIMIT,
277    SRC_PRIVATE_BASE, SRC_PRIVATE_LIMIT,
278    FP_REG, SP_REG, SCRATCH_WAVE_OFFSET_REG)> {
279   let AllocationPriority = 7;
280 }
281
282 def SReg_32_XM0 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
283   (add SReg_32_XM0_XEXEC, EXEC_LO, EXEC_HI)> {
284   let AllocationPriority = 7;
285 }
286
287 // Register class for all scalar registers (SGPRs + Special Registers)
288 def SReg_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
289   (add SReg_32_XM0, M0_CLASS, EXEC_LO, EXEC_HI)> {
290   let AllocationPriority = 7;
291 }
292
293 def SGPR_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64], 32, (add SGPR_64Regs)> {
294   let CopyCost = 1;
295   let AllocationPriority = 8;
296 }
297
298 def TTMP_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64], 32, (add TTMP_64Regs)> {
299   let isAllocatable = 0;
300 }
301
302 def SReg_64_XEXEC : RegisterClass<"AMDGPU", [v2i32, i64, f64, i1], 32,
303   (add SGPR_64, VCC, FLAT_SCR, TTMP_64, TBA, TMA)> {
304   let CopyCost = 1;
305   let AllocationPriority = 8;
306 }
307
308 def SReg_64 : RegisterClass<"AMDGPU", [v2i32, i64, f64, i1], 32,
309   (add SReg_64_XEXEC, EXEC)> {
310   let CopyCost = 1;
311   let AllocationPriority = 8;
312 }
313
314 // Requires 2 s_mov_b64 to copy
315 let CopyCost = 2 in {
316
317 def SGPR_128 : RegisterClass<"AMDGPU", [v4i32, v16i8, v2i64], 32, (add SGPR_128Regs)> {
318   let AllocationPriority = 10;
319 }
320
321 def TTMP_128 : RegisterClass<"AMDGPU", [v4i32, v16i8, v2i64], 32, (add TTMP_128Regs)> {
322   let isAllocatable = 0;
323 }
324
325 def SReg_128 : RegisterClass<"AMDGPU", [v4i32, v16i8, v2i64], 32,
326   (add SGPR_128, TTMP_128)> {
327   let AllocationPriority = 10;
328 }
329
330 } // End CopyCost = 2
331
332 def SReg_256 : RegisterClass<"AMDGPU", [v8i32, v8f32], 32, (add SGPR_256)> {
333   // Requires 4 s_mov_b64 to copy
334   let CopyCost = 4;
335   let AllocationPriority = 11;
336 }
337
338 def SReg_512 : RegisterClass<"AMDGPU", [v16i32, v16f32], 32, (add SGPR_512)> {
339   // Requires 8 s_mov_b64 to copy
340   let CopyCost = 8;
341   let AllocationPriority = 12;
342 }
343
344 // Register class for all vector registers (VGPRs + Interploation Registers)
345 def VReg_64 : RegisterClass<"AMDGPU", [i64, f64, v2i32, v2f32], 32, (add VGPR_64)> {
346   let Size = 64;
347
348   // Requires 2 v_mov_b32 to copy
349   let CopyCost = 2;
350   let AllocationPriority = 2;
351 }
352
353 def VReg_96 : RegisterClass<"AMDGPU", [untyped], 32, (add VGPR_96)> {
354   let Size = 96;
355
356   // Requires 3 v_mov_b32 to copy
357   let CopyCost = 3;
358   let AllocationPriority = 3;
359 }
360
361 def VReg_128 : RegisterClass<"AMDGPU", [v4i32, v4f32, v2i64, v2f64], 32, (add VGPR_128)> {
362   let Size = 128;
363
364   // Requires 4 v_mov_b32 to copy
365   let CopyCost = 4;
366   let AllocationPriority = 4;
367 }
368
369 def VReg_256 : RegisterClass<"AMDGPU", [v8i32, v8f32], 32, (add VGPR_256)> {
370   let Size = 256;
371   let CopyCost = 8;
372   let AllocationPriority = 5;
373 }
374
375 def VReg_512 : RegisterClass<"AMDGPU", [v16i32, v16f32], 32, (add VGPR_512)> {
376   let Size = 512;
377   let CopyCost = 16;
378   let AllocationPriority = 6;
379 }
380
381 def VReg_1 : RegisterClass<"AMDGPU", [i1], 32, (add VGPR_32)> {
382   let Size = 32;
383 }
384
385 def VS_32 : RegisterClass<"AMDGPU", [i32, f32, i16, f16, v2i16, v2f16], 32,
386                           (add VGPR_32, SReg_32)> {
387   let isAllocatable = 0;
388 }
389
390 def VS_64 : RegisterClass<"AMDGPU", [i64, f64], 32, (add VReg_64, SReg_64)> {
391   let isAllocatable = 0;
392 }
393
394 //===----------------------------------------------------------------------===//
395 //  Register operands
396 //===----------------------------------------------------------------------===//
397
398 class RegImmMatcher<string name> : AsmOperandClass {
399   let Name = name;
400   let RenderMethod = "addRegOrImmOperands";
401 }
402
403 multiclass SIRegOperand <string rc, string MatchName, string opType> {
404   let OperandNamespace = "AMDGPU" in {
405     def _b16 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
406       let OperandType = opType#"_INT16";
407       let ParserMatchClass = RegImmMatcher<MatchName#"B16">;
408       let DecoderMethod = "decodeOperand_VSrc16";
409     }
410
411     def _f16 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
412       let OperandType = opType#"_FP16";
413       let ParserMatchClass = RegImmMatcher<MatchName#"F16">;
414       let DecoderMethod = "decodeOperand_VSrc16";
415     }
416
417     def _b32 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
418       let OperandType = opType#"_INT32";
419       let ParserMatchClass = RegImmMatcher<MatchName#"B32">;
420     }
421
422     def _f32 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
423       let OperandType = opType#"_FP32";
424       let ParserMatchClass = RegImmMatcher<MatchName#"F32">;
425     }
426
427     def _b64 : RegisterOperand<!cast<RegisterClass>(rc#"_64")> {
428       let OperandType = opType#"_INT64";
429       let ParserMatchClass = RegImmMatcher<MatchName#"B64">;
430     }
431
432     def _f64 : RegisterOperand<!cast<RegisterClass>(rc#"_64")> {
433       let OperandType = opType#"_FP64";
434       let ParserMatchClass = RegImmMatcher<MatchName#"F64">;
435     }
436
437     def _v2b16 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
438       let OperandType = opType#"_V2INT16";
439       let ParserMatchClass = RegImmMatcher<MatchName#"V2B16">;
440       let DecoderMethod = "decodeOperand_VSrcV216";
441     }
442
443     def _v2f16 : RegisterOperand<!cast<RegisterClass>(rc#"_32")> {
444       let OperandType = opType#"_V2FP16";
445       let ParserMatchClass = RegImmMatcher<MatchName#"V2F16">;
446       let DecoderMethod = "decodeOperand_VSrcV216";
447     }
448   }
449 }
450
451 // FIXME: 64-bit sources can sometimes use 32-bit constants.
452 multiclass RegImmOperand <string rc, string MatchName>
453   : SIRegOperand<rc, MatchName, "OPERAND_REG_IMM">;
454
455 multiclass RegInlineOperand <string rc, string MatchName>
456   : SIRegOperand<rc, MatchName, "OPERAND_REG_INLINE_C">;
457
458 //===----------------------------------------------------------------------===//
459 //  SSrc_* Operands with an SGPR or a 32-bit immediate
460 //===----------------------------------------------------------------------===//
461
462 defm SSrc : RegImmOperand<"SReg", "SSrc">;
463
464 //===----------------------------------------------------------------------===//
465 //  SCSrc_* Operands with an SGPR or a inline constant
466 //===----------------------------------------------------------------------===//
467
468 defm SCSrc : RegInlineOperand<"SReg", "SCSrc"> ;
469
470 //===----------------------------------------------------------------------===//
471 //  VSrc_* Operands with an SGPR, VGPR or a 32-bit immediate
472 //===----------------------------------------------------------------------===//
473
474 defm VSrc : RegImmOperand<"VS", "VSrc">;
475
476 def VSrc_128 : RegisterOperand<VReg_128> {
477   let DecoderMethod = "DecodeVS_128RegisterClass";
478 }
479
480 //===----------------------------------------------------------------------===//
481 //  VSrc_* Operands with an VGPR
482 //===----------------------------------------------------------------------===//
483
484 // This is for operands with the enum(9), VSrc encoding restriction,
485 // but only allows VGPRs.
486 def VRegSrc_32 : RegisterOperand<VGPR_32> {
487   //let ParserMatchClass = RegImmMatcher<"VRegSrc32">;
488   let DecoderMethod = "DecodeVS_32RegisterClass";
489 }
490
491 //===----------------------------------------------------------------------===//
492 //  VCSrc_* Operands with an SGPR, VGPR or an inline constant
493 //===----------------------------------------------------------------------===//
494
495 defm VCSrc : RegInlineOperand<"VS", "VCSrc">;