xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYRegisterInfo.td (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1e8d8bef9SDimitry Andric//===-- CSKYRegisterInfo.td - CSKY Register defs -----------*- tablegen -*-===//
2e8d8bef9SDimitry Andric//
3e8d8bef9SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric//
7e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric
9e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
10e8d8bef9SDimitry Andric//  Declarations that describe the CSKY registers.
11e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
12e8d8bef9SDimitry Andric
13e8d8bef9SDimitry Andriclet Namespace = "CSKY" in {
14e8d8bef9SDimitry Andric  class CSKYReg<bits<6> Enc, string n, list<string> alt = []> : Register<n> {
15e8d8bef9SDimitry Andric    let HWEncoding{5 - 0} = Enc;
16e8d8bef9SDimitry Andric    let AltNames = alt;
17e8d8bef9SDimitry Andric  }
18e8d8bef9SDimitry Andric
19e8d8bef9SDimitry Andric  class CSKYFReg32<bits<5> Enc, string n, list<string> alt = []> : Register<n> {
20e8d8bef9SDimitry Andric    let HWEncoding{4 - 0} = Enc;
21e8d8bef9SDimitry Andric    let AltNames = alt;
22e8d8bef9SDimitry Andric  }
23e8d8bef9SDimitry Andric
24e8d8bef9SDimitry Andric  // Because CSKYFReg64 register have AsmName and AltNames that alias with their
25e8d8bef9SDimitry Andric  // 32-bit sub-register, CSKYAsmParser will need to coerce a register number
26e8d8bef9SDimitry Andric  // from a CSKYFReg32 to the equivalent CSKYFReg64 when appropriate.
27e8d8bef9SDimitry Andric  def sub32_0 : SubRegIndex<32, 0>;
28e8d8bef9SDimitry Andric  def sub32_32 : SubRegIndex<32, 32>;
29e8d8bef9SDimitry Andric  def sub64_0 : SubRegIndex<64, 0>;
30e8d8bef9SDimitry Andric  def sub64_64 : SubRegIndex<64,64>;
31e8d8bef9SDimitry Andric
32e8d8bef9SDimitry Andric  class CSKYFReg64<CSKYFReg32 subreg> : Register<""> {
33e8d8bef9SDimitry Andric    let HWEncoding{4 - 0} = subreg.HWEncoding{4 - 0};
34e8d8bef9SDimitry Andric    let SubRegs = [subreg];
35e8d8bef9SDimitry Andric    let SubRegIndices = [sub32_0];
36e8d8bef9SDimitry Andric    let AsmName = subreg.AsmName;
37e8d8bef9SDimitry Andric    let AltNames = subreg.AltNames;
38e8d8bef9SDimitry Andric  }
39e8d8bef9SDimitry Andric
40e8d8bef9SDimitry Andric  class CSKYFReg128<CSKYFReg64 subreg> : Register<""> {
41e8d8bef9SDimitry Andric    let HWEncoding{4 - 0} = subreg.HWEncoding{4 - 0};
42e8d8bef9SDimitry Andric    let SubRegs = [subreg];
43e8d8bef9SDimitry Andric    let SubRegIndices = [sub64_0];
44e8d8bef9SDimitry Andric    let AsmName = subreg.AsmName;
45e8d8bef9SDimitry Andric    let AltNames = subreg.AltNames;
46e8d8bef9SDimitry Andric  }
47e8d8bef9SDimitry Andric
48e8d8bef9SDimitry Andric  def ABIRegAltName : RegAltNameIndex;
49e8d8bef9SDimitry Andric} // Namespace = "CSKY"
50e8d8bef9SDimitry Andric
51e8d8bef9SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
52e8d8bef9SDimitry Andric  def R0 : CSKYReg<0, "r0", ["a0"]>, DwarfRegNum<[0]>;
53e8d8bef9SDimitry Andric  def R1 : CSKYReg<1, "r1", ["a1"]>, DwarfRegNum<[1]>;
54e8d8bef9SDimitry Andric  def R2 : CSKYReg<2, "r2", ["a2"]>, DwarfRegNum<[2]>;
55e8d8bef9SDimitry Andric  def R3 : CSKYReg<3, "r3", ["a3"]>, DwarfRegNum<[3]>;
56e8d8bef9SDimitry Andric  def R4 : CSKYReg<4, "r4", ["l0"]>, DwarfRegNum<[4]>;
57e8d8bef9SDimitry Andric  def R5 : CSKYReg<5, "r5", ["l1"]>, DwarfRegNum<[5]>;
58e8d8bef9SDimitry Andric  def R6 : CSKYReg<6, "r6", ["l2"]>, DwarfRegNum<[6]>;
59e8d8bef9SDimitry Andric  def R7 : CSKYReg<7, "r7", ["l3"]>, DwarfRegNum<[7]>;
60e8d8bef9SDimitry Andric  def R8 : CSKYReg<8, "r8", ["l4"]>, DwarfRegNum<[8]>;
61e8d8bef9SDimitry Andric  def R9 : CSKYReg<9, "r9", ["l5"]>, DwarfRegNum<[9]>;
62e8d8bef9SDimitry Andric  def R10 : CSKYReg<10, "r10", ["l6"]>, DwarfRegNum<[10]>;
63e8d8bef9SDimitry Andric  def R11 : CSKYReg<11, "r11", ["l7"]>, DwarfRegNum<[11]>;
64e8d8bef9SDimitry Andric  def R12 : CSKYReg<12, "r12", ["t0"]>, DwarfRegNum<[12]>;
65e8d8bef9SDimitry Andric  def R13 : CSKYReg<13, "r13", ["t1"]>, DwarfRegNum<[13]>;
66e8d8bef9SDimitry Andric  def R14 : CSKYReg<14, "r14", ["sp"]>, DwarfRegNum<[14]>;
67e8d8bef9SDimitry Andric  def R15 : CSKYReg<15, "r15", ["lr"]>, DwarfRegNum<[15]>;
68e8d8bef9SDimitry Andric  def R16 : CSKYReg<16, "r16", ["l8"]>, DwarfRegNum<[16]>;
69e8d8bef9SDimitry Andric  def R17 : CSKYReg<17, "r17", ["l9"]>, DwarfRegNum<[17]>;
70e8d8bef9SDimitry Andric  def R18 : CSKYReg<18, "r18", ["t2"]>, DwarfRegNum<[18]>;
71e8d8bef9SDimitry Andric  def R19 : CSKYReg<19, "r19", ["t3"]>, DwarfRegNum<[19]>;
72e8d8bef9SDimitry Andric  def R20 : CSKYReg<20, "r20", ["t4"]>, DwarfRegNum<[20]>;
73e8d8bef9SDimitry Andric  def R21 : CSKYReg<21, "r21", ["t5"]>, DwarfRegNum<[21]>;
74e8d8bef9SDimitry Andric  def R22 : CSKYReg<22, "r22", ["t6"]>, DwarfRegNum<[22]>;
75e8d8bef9SDimitry Andric  def R23 : CSKYReg<23, "r23", ["t7"]>, DwarfRegNum<[23]>;
76e8d8bef9SDimitry Andric  def R24 : CSKYReg<24, "r24", ["t8"]>, DwarfRegNum<[24]>;
77e8d8bef9SDimitry Andric  def R25 : CSKYReg<25, "r25", ["t9"]>, DwarfRegNum<[25]>;
78e8d8bef9SDimitry Andric  def R26 : CSKYReg<26, "r26", ["r26"]>, DwarfRegNum<[26]>;
79e8d8bef9SDimitry Andric  def R27 : CSKYReg<27, "r27", ["r27"]>, DwarfRegNum<[27]>;
80e8d8bef9SDimitry Andric  def R28 : CSKYReg<28, "r28", ["rgb"]>, DwarfRegNum<[28]>;
81e8d8bef9SDimitry Andric  def R29 : CSKYReg<29, "r29", ["rtb"]>, DwarfRegNum<[29]>;
82e8d8bef9SDimitry Andric  def R30 : CSKYReg<30, "r30", ["svbr"]>, DwarfRegNum<[30]>;
83e8d8bef9SDimitry Andric  def R31 : CSKYReg<31, "r31", ["tls"]>, DwarfRegNum<[31]>;
84*81ad6265SDimitry Andric
85*81ad6265SDimitry Andric  // Faked for GPRTuple
86*81ad6265SDimitry Andric  def R32 : CSKYReg<32, "r32", ["r32"]>, DwarfRegNum<[32]>;
87*81ad6265SDimitry Andric
88*81ad6265SDimitry Andric  def C : CSKYReg<33, "cr0", ["psr"]>;
89e8d8bef9SDimitry Andric
90e8d8bef9SDimitry Andric}
91e8d8bef9SDimitry Andric
92e8d8bef9SDimitry Andricdef GPRTuple : RegisterTuples<
93e8d8bef9SDimitry Andric          [sub32_0, sub32_32],
94*81ad6265SDimitry Andric          [(add (sequence "R%u", 0, 31)), (add (sequence "R%u", 1, 32))],
95e8d8bef9SDimitry Andric          [ "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
96e8d8bef9SDimitry Andric            "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
97e8d8bef9SDimitry Andric            "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
98*81ad6265SDimitry Andric            "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
99e8d8bef9SDimitry Andric          ]>;
100e8d8bef9SDimitry Andric
101e8d8bef9SDimitry Andric// Floating point registers
102e8d8bef9SDimitry Andriclet RegAltNameIndices = [ABIRegAltName] in {
103e8d8bef9SDimitry Andric  def F0_32 : CSKYFReg32<0, "fr0", ["vr0"]>, DwarfRegNum<[32]>;
104e8d8bef9SDimitry Andric  def F1_32 : CSKYFReg32<1, "fr1", ["vr1"]>, DwarfRegNum<[33]>;
105e8d8bef9SDimitry Andric  def F2_32 : CSKYFReg32<2, "fr2", ["vr2"]>, DwarfRegNum<[34]>;
106e8d8bef9SDimitry Andric  def F3_32 : CSKYFReg32<3, "fr3", ["vr3"]>, DwarfRegNum<[35]>;
107e8d8bef9SDimitry Andric  def F4_32 : CSKYFReg32<4, "fr4", ["vr4"]>, DwarfRegNum<[36]>;
108e8d8bef9SDimitry Andric  def F5_32 : CSKYFReg32<5, "fr5", ["vr5"]>, DwarfRegNum<[37]>;
109e8d8bef9SDimitry Andric  def F6_32 : CSKYFReg32<6, "fr6", ["vr6"]>, DwarfRegNum<[38]>;
110e8d8bef9SDimitry Andric  def F7_32 : CSKYFReg32<7, "fr7", ["vr7"]>, DwarfRegNum<[39]>;
111e8d8bef9SDimitry Andric  def F8_32 : CSKYFReg32<8, "fr8", ["vr8"]>, DwarfRegNum<[40]>;
112e8d8bef9SDimitry Andric  def F9_32 : CSKYFReg32<9, "fr9", ["vr9"]>, DwarfRegNum<[41]>;
113e8d8bef9SDimitry Andric  def F10_32 : CSKYFReg32<10, "fr10", ["vr10"]>, DwarfRegNum<[42]>;
114e8d8bef9SDimitry Andric  def F11_32 : CSKYFReg32<11, "fr11", ["vr11"]>, DwarfRegNum<[43]>;
115e8d8bef9SDimitry Andric  def F12_32 : CSKYFReg32<12, "fr12", ["vr12"]>, DwarfRegNum<[44]>;
116e8d8bef9SDimitry Andric  def F13_32 : CSKYFReg32<13, "fr13", ["vr13"]>, DwarfRegNum<[45]>;
117e8d8bef9SDimitry Andric  def F14_32 : CSKYFReg32<14, "fr14", ["vr14"]>, DwarfRegNum<[46]>;
118e8d8bef9SDimitry Andric  def F15_32 : CSKYFReg32<15, "fr15", ["vr15"]>, DwarfRegNum<[47]>;
119e8d8bef9SDimitry Andric  def F16_32 : CSKYFReg32<16, "fr16", ["vr16"]>, DwarfRegNum<[48]>;
120e8d8bef9SDimitry Andric  def F17_32 : CSKYFReg32<17, "fr17", ["vr17"]>, DwarfRegNum<[49]>;
121e8d8bef9SDimitry Andric  def F18_32 : CSKYFReg32<18, "fr18", ["vr18"]>, DwarfRegNum<[50]>;
122e8d8bef9SDimitry Andric  def F19_32 : CSKYFReg32<19, "fr19", ["vr19"]>, DwarfRegNum<[51]>;
123e8d8bef9SDimitry Andric  def F20_32 : CSKYFReg32<20, "fr20", ["vr20"]>, DwarfRegNum<[52]>;
124e8d8bef9SDimitry Andric  def F21_32 : CSKYFReg32<21, "fr21", ["vr21"]>, DwarfRegNum<[53]>;
125e8d8bef9SDimitry Andric  def F22_32 : CSKYFReg32<22, "fr22", ["vr22"]>, DwarfRegNum<[54]>;
126e8d8bef9SDimitry Andric  def F23_32 : CSKYFReg32<23, "fr23", ["vr23"]>, DwarfRegNum<[55]>;
127e8d8bef9SDimitry Andric  def F24_32 : CSKYFReg32<24, "fr24", ["vr24"]>, DwarfRegNum<[56]>;
128e8d8bef9SDimitry Andric  def F25_32 : CSKYFReg32<25, "fr25", ["vr25"]>, DwarfRegNum<[57]>;
129e8d8bef9SDimitry Andric  def F26_32 : CSKYFReg32<26, "fr26", ["vr26"]>, DwarfRegNum<[58]>;
130e8d8bef9SDimitry Andric  def F27_32 : CSKYFReg32<27, "fr27", ["vr27"]>, DwarfRegNum<[59]>;
131e8d8bef9SDimitry Andric  def F28_32 : CSKYFReg32<28, "fr28", ["vr28"]>, DwarfRegNum<[60]>;
132e8d8bef9SDimitry Andric  def F29_32 : CSKYFReg32<29, "fr29", ["vr29"]>, DwarfRegNum<[61]>;
133e8d8bef9SDimitry Andric  def F30_32 : CSKYFReg32<30, "fr30", ["vr30"]>, DwarfRegNum<[62]>;
134e8d8bef9SDimitry Andric  def F31_32 : CSKYFReg32<31, "fr31", ["vr31"]>, DwarfRegNum<[63]>;
135e8d8bef9SDimitry Andric
136e8d8bef9SDimitry Andric  foreach Index = 0 - 31 in {
137e8d8bef9SDimitry Andric    def F#Index#_64 : CSKYFReg64<!cast<CSKYFReg32>("F"#Index#"_32")>,
138e8d8bef9SDimitry Andric                      DwarfRegNum<[!add(Index, 32)]>;
139e8d8bef9SDimitry Andric
140e8d8bef9SDimitry Andric    def F#Index#_128 : CSKYFReg128<!cast<CSKYFReg64>("F"#Index#"_64")>,
141e8d8bef9SDimitry Andric                       DwarfRegNum<[!add(Index, 32)]>;
142e8d8bef9SDimitry Andric  }
143e8d8bef9SDimitry Andric}
144e8d8bef9SDimitry Andric
145e8d8bef9SDimitry Andric
146e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
147e8d8bef9SDimitry Andric// Declarations that describe the CSKY register class.
148e8d8bef9SDimitry Andric//===----------------------------------------------------------------------===//
149e8d8bef9SDimitry Andric
150e8d8bef9SDimitry Andric// The order of registers represents the preferred allocation sequence.
151e8d8bef9SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials.
152e8d8bef9SDimitry Andricdef GPR : RegisterClass<"CSKY", [i32], 32,
153e8d8bef9SDimitry Andric                        (add (sequence "R%u", 0, 3), (sequence "R%u", 12, 13),
154e8d8bef9SDimitry Andric                             (sequence "R%u", 18, 25), R15, (sequence "R%u", 4, 11),
155e8d8bef9SDimitry Andric                             (sequence "R%u", 16, 17), (sequence "R%u", 26, 27), R28,
156e8d8bef9SDimitry Andric                             (sequence "R%u", 29, 30), R14, R31)> {
157e8d8bef9SDimitry Andric  let Size = 32;
158e8d8bef9SDimitry Andric}
159e8d8bef9SDimitry Andric
160349cc55cSDimitry Andric// Register class for R0 - R15.
161349cc55cSDimitry Andric// Some 16-bit integer instructions can only access R0 - R15.
162349cc55cSDimitry Andricdef sGPR : RegisterClass<"CSKY", [i32], 32,
163349cc55cSDimitry Andric                        (add (sequence "R%u", 0, 3), (sequence "R%u", 12, 13), R15,
164349cc55cSDimitry Andric                        (sequence "R%u", 4, 11), R14)> {
165349cc55cSDimitry Andric  let Size = 32;
166349cc55cSDimitry Andric}
167349cc55cSDimitry Andric
168349cc55cSDimitry Andric// Register class for R0 - R7.
169349cc55cSDimitry Andric// Some 16-bit integer instructions can only access R0 - R7.
170349cc55cSDimitry Andricdef mGPR : RegisterClass<"CSKY", [i32], 32,
171349cc55cSDimitry Andric                        (add (sequence "R%u", 0, 7))> {
172349cc55cSDimitry Andric  let Size = 32;
173349cc55cSDimitry Andric}
174349cc55cSDimitry Andric
1750eae32dcSDimitry Andric// Register class for SP only.
1760eae32dcSDimitry Andricdef GPRSP : RegisterClass<"CSKY", [i32], 32, (add R14)> {
1770eae32dcSDimitry Andric  let Size = 32;
1780eae32dcSDimitry Andric}
1790eae32dcSDimitry Andric
180e8d8bef9SDimitry Andricdef GPRPair : RegisterClass<"CSKY", [untyped], 32, (add GPRTuple)> {
181e8d8bef9SDimitry Andric  let Size = 64;
182e8d8bef9SDimitry Andric}
183e8d8bef9SDimitry Andric
184e8d8bef9SDimitry Andricdef CARRY : RegisterClass<"CSKY", [i32], 32, (add C)> {
185e8d8bef9SDimitry Andric  let Size = 32;
186e8d8bef9SDimitry Andric  let CopyCost = -1;
187e8d8bef9SDimitry Andric}
188e8d8bef9SDimitry Andric
189e8d8bef9SDimitry Andric// The order of registers represents the preferred allocation sequence.
190e8d8bef9SDimitry Andric// Registers are listed in the order caller-save, callee-save, specials.
191e8d8bef9SDimitry Andricdef FPR32 : RegisterClass<"CSKY", [f32], 32,
192e8d8bef9SDimitry Andric                         (add (sequence "F%u_32", 0, 31))>;
193e8d8bef9SDimitry Andricdef sFPR32 : RegisterClass<"CSKY", [f32], 32,
194e8d8bef9SDimitry Andric                         (add (sequence "F%u_32", 0, 15))>;
195e8d8bef9SDimitry Andric
196*81ad6265SDimitry Andricdef FPR64 : RegisterClass<"CSKY", [f64], 32,
197e8d8bef9SDimitry Andric                         (add (sequence "F%u_64", 0, 31))>;
198*81ad6265SDimitry Andricdef sFPR64 : RegisterClass<"CSKY", [f64], 32,
199e8d8bef9SDimitry Andric                         (add (sequence "F%u_64", 0, 15))>;
200e8d8bef9SDimitry Andric
20104eeddc0SDimitry Andricdef sFPR64_V : RegisterClass<"CSKY", [v2f32], 32, (add sFPR64)>;
20204eeddc0SDimitry Andric
203e8d8bef9SDimitry Andricdef FPR128 : RegisterClass<"CSKY",
204e8d8bef9SDimitry Andric             [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64, v8f16], 128,
205e8d8bef9SDimitry Andric             (add (sequence "F%u_128", 0, 31))>;
206e8d8bef9SDimitry Andricdef sFPR128 : RegisterClass<"CSKY",
207e8d8bef9SDimitry Andric              [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64, v8f16], 128,
208e8d8bef9SDimitry Andric              (add (sequence "F%u_128", 0, 15))>;
209