1 //==- SystemZRegisterInfo.td - SystemZ register definitions -*- tablegen -*-==//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 class SystemZReg<string n> : Register<n> {
14 let Namespace = "SystemZ";
17 class SystemZRegWithSubregs<string n, list<Register> subregs>
18 : RegisterWithSubRegs<n, subregs> {
19 let Namespace = "SystemZ";
22 let Namespace = "SystemZ" in {
23 def subreg_l32 : SubRegIndex<32, 0>; // Also acts as subreg_ll32.
24 def subreg_h32 : SubRegIndex<32, 32>; // Also acts as subreg_lh32.
25 def subreg_l64 : SubRegIndex<64, 0>;
26 def subreg_h64 : SubRegIndex<64, 64>;
27 def subreg_hh32 : ComposedSubRegIndex<subreg_h64, subreg_h32>;
28 def subreg_hl32 : ComposedSubRegIndex<subreg_h64, subreg_l32>;
31 // Define a register class that contains values of types TYPES and an
32 // associated operand called NAME. SIZE is the size and alignment
33 // of the registers and REGLIST is the list of individual registers.
34 multiclass SystemZRegClass<string name, list<ValueType> types, int size,
35 dag regList, bit allocatable = 1> {
36 def AsmOperand : AsmOperandClass {
38 let ParserMethod = "parse"##name;
39 let RenderMethod = "addRegOperands";
41 let isAllocatable = allocatable in
42 def Bit : RegisterClass<"SystemZ", types, size, regList> {
45 def "" : RegisterOperand<!cast<RegisterClass>(name##"Bit")> {
46 let ParserMatchClass = !cast<AsmOperandClass>(name##"AsmOperand");
50 //===----------------------------------------------------------------------===//
51 // General-purpose registers
52 //===----------------------------------------------------------------------===//
54 // Lower 32 bits of one of the 16 64-bit general-purpose registers
55 class GPR32<bits<16> num, string n> : SystemZReg<n> {
59 // One of the 16 64-bit general-purpose registers.
60 class GPR64<bits<16> num, string n, GPR32 low, GPR32 high>
61 : SystemZRegWithSubregs<n, [low, high]> {
63 let SubRegIndices = [subreg_l32, subreg_h32];
64 let CoveredBySubRegs = 1;
67 // 8 even-odd pairs of GPR64s.
68 class GPR128<bits<16> num, string n, GPR64 low, GPR64 high>
69 : SystemZRegWithSubregs<n, [low, high]> {
71 let SubRegIndices = [subreg_l64, subreg_h64];
72 let CoveredBySubRegs = 1;
75 // General-purpose registers
77 def R#I#L : GPR32<I, "r"#I>;
78 def R#I#H : GPR32<I, "r"#I>;
79 def R#I#D : GPR64<I, "r"#I, !cast<GPR32>("R"#I#"L"), !cast<GPR32>("R"#I#"H")>,
83 foreach I = [0, 2, 4, 6, 8, 10, 12, 14] in {
84 def R#I#Q : GPR128<I, "r"#I, !cast<GPR64>("R"#!add(I, 1)#"D"),
85 !cast<GPR64>("R"#I#"D")>;
88 /// Allocate the callee-saved R6-R13 backwards. That way they can be saved
89 /// together with R14 and R15 in one prolog instruction.
90 defm GR32 : SystemZRegClass<"GR32", [i32], 32,
91 (add (sequence "R%uL", 0, 5),
92 (sequence "R%uL", 15, 6))>;
93 defm GRH32 : SystemZRegClass<"GRH32", [i32], 32,
94 (add (sequence "R%uH", 0, 5),
95 (sequence "R%uH", 15, 6))>;
96 defm GR64 : SystemZRegClass<"GR64", [i64], 64,
97 (add (sequence "R%uD", 0, 5),
98 (sequence "R%uD", 15, 6))>;
100 // Combine the low and high GR32s into a single class. This can only be
101 // used for virtual registers if the high-word facility is available.
102 defm GRX32 : SystemZRegClass<"GRX32", [i32], 32,
103 (add (sequence "R%uL", 0, 5),
104 (sequence "R%uH", 0, 5),
105 R15L, R15H, R14L, R14H, R13L, R13H,
106 R12L, R12H, R11L, R11H, R10L, R10H,
107 R9L, R9H, R8L, R8H, R7L, R7H, R6L, R6H)>;
109 // The architecture doesn't really have any i128 support, so model the
110 // register pairs as untyped instead.
111 defm GR128 : SystemZRegClass<"GR128", [untyped], 128,
112 (add R0Q, R2Q, R4Q, R12Q, R10Q, R8Q, R6Q, R14Q)>;
114 // Base and index registers. Everything except R0, which in an address
115 // context evaluates as 0.
116 defm ADDR32 : SystemZRegClass<"ADDR32", [i32], 32, (sub GR32Bit, R0L)>;
117 defm ADDR64 : SystemZRegClass<"ADDR64", [i64], 64, (sub GR64Bit, R0D)>;
119 // Not used directly, but needs to exist for ADDR32 and ADDR64 subregs
121 defm ADDR128 : SystemZRegClass<"ADDR128", [untyped], 128, (sub GR128Bit, R0Q)>;
123 // Any type register. Used for .insn directives when we don't know what the
124 // register types could be.
125 defm AnyReg : SystemZRegClass<"AnyReg",
126 [i64, f64, v8i8, v4i16, v2i32, v2f32], 64,
127 (add (sequence "R%uD", 0, 15),
128 (sequence "F%uD", 0, 15),
129 (sequence "V%u", 0, 15)), 0/*allocatable*/>;
131 //===----------------------------------------------------------------------===//
132 // Floating-point registers
133 //===----------------------------------------------------------------------===//
135 // Maps FPR register numbers to their DWARF encoding.
136 class DwarfMapping<int id> { int Id = id; }
138 def F0Dwarf : DwarfMapping<16>;
139 def F2Dwarf : DwarfMapping<17>;
140 def F4Dwarf : DwarfMapping<18>;
141 def F6Dwarf : DwarfMapping<19>;
143 def F1Dwarf : DwarfMapping<20>;
144 def F3Dwarf : DwarfMapping<21>;
145 def F5Dwarf : DwarfMapping<22>;
146 def F7Dwarf : DwarfMapping<23>;
148 def F8Dwarf : DwarfMapping<24>;
149 def F10Dwarf : DwarfMapping<25>;
150 def F12Dwarf : DwarfMapping<26>;
151 def F14Dwarf : DwarfMapping<27>;
153 def F9Dwarf : DwarfMapping<28>;
154 def F11Dwarf : DwarfMapping<29>;
155 def F13Dwarf : DwarfMapping<30>;
156 def F15Dwarf : DwarfMapping<31>;
158 def F16Dwarf : DwarfMapping<68>;
159 def F18Dwarf : DwarfMapping<69>;
160 def F20Dwarf : DwarfMapping<70>;
161 def F22Dwarf : DwarfMapping<71>;
163 def F17Dwarf : DwarfMapping<72>;
164 def F19Dwarf : DwarfMapping<73>;
165 def F21Dwarf : DwarfMapping<74>;
166 def F23Dwarf : DwarfMapping<75>;
168 def F24Dwarf : DwarfMapping<76>;
169 def F26Dwarf : DwarfMapping<77>;
170 def F28Dwarf : DwarfMapping<78>;
171 def F30Dwarf : DwarfMapping<79>;
173 def F25Dwarf : DwarfMapping<80>;
174 def F27Dwarf : DwarfMapping<81>;
175 def F29Dwarf : DwarfMapping<82>;
176 def F31Dwarf : DwarfMapping<83>;
178 // Upper 32 bits of one of the floating-point registers
179 class FPR32<bits<16> num, string n> : SystemZReg<n> {
180 let HWEncoding = num;
183 // One of the floating-point registers.
184 class FPR64<bits<16> num, string n, FPR32 high>
185 : SystemZRegWithSubregs<n, [high]> {
186 let HWEncoding = num;
187 let SubRegIndices = [subreg_h32];
190 // 8 pairs of FPR64s, with a one-register gap inbetween.
191 class FPR128<bits<16> num, string n, FPR64 low, FPR64 high>
192 : SystemZRegWithSubregs<n, [low, high]> {
193 let HWEncoding = num;
194 let SubRegIndices = [subreg_l64, subreg_h64];
195 let CoveredBySubRegs = 1;
198 // Floating-point registers. Registers 16-31 require the vector facility.
199 foreach I = 0-15 in {
200 def F#I#S : FPR32<I, "f"#I>;
201 def F#I#D : FPR64<I, "f"#I, !cast<FPR32>("F"#I#"S")>,
202 DwarfRegNum<[!cast<DwarfMapping>("F"#I#"Dwarf").Id]>;
204 foreach I = 16-31 in {
205 def F#I#S : FPR32<I, "v"#I>;
206 def F#I#D : FPR64<I, "v"#I, !cast<FPR32>("F"#I#"S")>,
207 DwarfRegNum<[!cast<DwarfMapping>("F"#I#"Dwarf").Id]>;
210 foreach I = [0, 1, 4, 5, 8, 9, 12, 13] in {
211 def F#I#Q : FPR128<I, "f"#I, !cast<FPR64>("F"#!add(I, 2)#"D"),
212 !cast<FPR64>("F"#I#"D")>;
215 // There's no store-multiple instruction for FPRs, so we're not fussy
216 // about the order in which call-saved registers are allocated.
217 defm FP32 : SystemZRegClass<"FP32", [f32], 32, (sequence "F%uS", 0, 15)>;
218 defm FP64 : SystemZRegClass<"FP64", [f64], 64, (sequence "F%uD", 0, 15)>;
219 defm FP128 : SystemZRegClass<"FP128", [f128], 128,
220 (add F0Q, F1Q, F4Q, F5Q, F8Q, F9Q, F12Q, F13Q)>;
222 //===----------------------------------------------------------------------===//
224 //===----------------------------------------------------------------------===//
226 // A full 128-bit vector register, with an FPR64 as its high part.
227 class VR128<bits<16> num, string n, FPR64 high>
228 : SystemZRegWithSubregs<n, [high]> {
229 let HWEncoding = num;
230 let SubRegIndices = [subreg_h64];
233 // Full vector registers.
234 foreach I = 0-31 in {
235 def V#I : VR128<I, "v"#I, !cast<FPR64>("F"#I#"D")>,
236 DwarfRegNum<[!cast<DwarfMapping>("F"#I#"Dwarf").Id]>;
239 // Class used to store 32-bit values in the first element of a vector
240 // register. f32 scalars are used for the WLEDB and WLDEB instructions.
241 defm VR32 : SystemZRegClass<"VR32", [f32, v4i8, v2i16], 32,
242 (add (sequence "F%uS", 0, 7),
243 (sequence "F%uS", 16, 31),
244 (sequence "F%uS", 8, 15))>;
246 // Class used to store 64-bit values in the upper half of a vector register.
247 // The vector facility also includes scalar f64 instructions that operate
248 // on the full vector register set.
249 defm VR64 : SystemZRegClass<"VR64", [f64, v8i8, v4i16, v2i32, v2f32], 64,
250 (add (sequence "F%uD", 0, 7),
251 (sequence "F%uD", 16, 31),
252 (sequence "F%uD", 8, 15))>;
254 // The subset of vector registers that can be used for floating-point
256 defm VF128 : SystemZRegClass<"VF128",
257 [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64], 128,
258 (sequence "V%u", 0, 15)>;
260 // All vector registers.
261 defm VR128 : SystemZRegClass<"VR128",
262 [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64, f128],
263 128, (add (sequence "V%u", 0, 7),
264 (sequence "V%u", 16, 31),
265 (sequence "V%u", 8, 15))>;
267 // Attaches a ValueType to a register operand, to make the instruction
268 // definitions easier.
269 class TypedReg<ValueType vtin, RegisterOperand opin> {
271 RegisterOperand op = opin;
274 def v32f : TypedReg<i32, VR32>;
275 def v32sb : TypedReg<f32, VR32>;
276 def v64g : TypedReg<i64, VR64>;
277 def v64db : TypedReg<f64, VR64>;
278 def v128b : TypedReg<v16i8, VR128>;
279 def v128h : TypedReg<v8i16, VR128>;
280 def v128f : TypedReg<v4i32, VR128>;
281 def v128g : TypedReg<v2i64, VR128>;
282 def v128q : TypedReg<v16i8, VR128>;
283 def v128sb : TypedReg<v4f32, VR128>;
284 def v128db : TypedReg<v2f64, VR128>;
285 def v128xb : TypedReg<f128, VR128>;
286 def v128any : TypedReg<untyped, VR128>;
288 //===----------------------------------------------------------------------===//
290 //===----------------------------------------------------------------------===//
292 // The 2-bit condition code field of the PSW. Every register named in an
293 // inline asm needs a class associated with it.
294 def CC : SystemZReg<"cc">;
295 let isAllocatable = 0, CopyCost = -1 in
296 def CCR : RegisterClass<"SystemZ", [i32], 32, (add CC)>;
298 // The floating-point control register.
299 // Note: We only model the current rounding modes and the IEEE masks.
300 // IEEE flags and DXC are not modeled here.
301 def FPC : SystemZReg<"fpc">;
302 let isAllocatable = 0 in
303 def FPCRegs : RegisterClass<"SystemZ", [i32], 32, (add FPC)>;
306 class ACR32<bits<16> num, string n> : SystemZReg<n> {
307 let HWEncoding = num;
309 foreach I = 0-15 in {
310 def A#I : ACR32<I, "a"#I>, DwarfRegNum<[!add(I, 48)]>;
312 defm AR32 : SystemZRegClass<"AR32", [i32], 32,
313 (add (sequence "A%u", 0, 15)), 0>;
315 // Control registers.
316 class CREG64<bits<16> num, string n> : SystemZReg<n> {
317 let HWEncoding = num;
319 foreach I = 0-15 in {
320 def C#I : CREG64<I, "c"#I>, DwarfRegNum<[!add(I, 32)]>;
322 defm CR64 : SystemZRegClass<"CR64", [i64], 64,
323 (add (sequence "C%u", 0, 15)), 0>;