Skip to content

Commit cae80a8

Browse files
arichardsonjrtc27
andcommitted
[RISC-V][MC] Add a RegisterClass definition for Y extension (CHERI)
This is the first commit in a series of changes to add initial MC-layer support for the upcoming Y extension for CHERI. Specification: https://riscv.github.io/riscv-cheri/ Co-authored-by: Jessica Clarke <[email protected]>
1 parent 6ca835b commit cae80a8

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ class RISCVReg128<RISCVReg64 subreg>
5252
let SubRegIndices = [sub_64];
5353
}
5454

55+
// A subreg index for the address part of capability registers (this is just the
56+
// default XLEN-wide X<N> register).
57+
def sub_cap_addr : SubRegIndex<32> {
58+
let SubRegRanges =
59+
SubRegRangeByHwMode<[RV32, RV64], [SubRegRange<32>, SubRegRange<64>]>;
60+
}
61+
class RISCVCapReg<RISCVRegWithSubRegs subreg, string n, list<string> alt = []>
62+
: RISCVRegWithSubRegs<subreg.HWEncoding{4 -0}, n, [subreg], alt> {
63+
let SubRegIndices = [sub_cap_addr];
64+
}
65+
5566
let FallbackRegAltNameIndex = NoRegAltName in
5667
def ABIRegAltName : RegAltNameIndex;
5768

@@ -211,6 +222,46 @@ let RegAltNameIndices = [ABIRegAltName] in {
211222
def X31 : RISCVRegWithSubRegs<31,"x31", [X31_W], ["t6"]>, DwarfRegNum<[31]>;
212223
}
213224
}
225+
// CHERI capability registers (Y extension)
226+
let SubRegIndices = [sub_cap_addr] in {
227+
let isConstant = true in def X0_Y : RISCVCapReg<X0, "x0", ["zero", "null"]>,
228+
DwarfRegAlias<X0>;
229+
let CostPerUse = [0, 1] in {
230+
def X1_Y : RISCVCapReg<X1, "x1", ["ra"]>, DwarfRegAlias<X1>;
231+
def X2_Y : RISCVCapReg<X2, "x2", ["sp"]>, DwarfRegAlias<X2>;
232+
def X3_Y : RISCVCapReg<X3, "x3", ["gp"]>, DwarfRegAlias<X3>;
233+
def X4_Y : RISCVCapReg<X4, "x4", ["tp"]>, DwarfRegAlias<X4>;
234+
def X5_Y : RISCVCapReg<X5, "x5", ["t0"]>, DwarfRegAlias<X5>;
235+
def X6_Y : RISCVCapReg<X6, "x6", ["t1"]>, DwarfRegAlias<X6>;
236+
def X7_Y : RISCVCapReg<X7, "x7", ["t2"]>, DwarfRegAlias<X7>;
237+
}
238+
def X8_Y : RISCVCapReg<X8, "x8", ["s0", "fp"]>, DwarfRegAlias<X8>;
239+
def X9_Y : RISCVCapReg<X9, "x9", ["s1"]>, DwarfRegAlias<X9>;
240+
def X10_Y : RISCVCapReg<X10, "x10", ["a0"]>, DwarfRegAlias<X0>;
241+
def X11_Y : RISCVCapReg<X11, "x11", ["a1"]>, DwarfRegAlias<X1>;
242+
def X12_Y : RISCVCapReg<X12, "x12", ["a2"]>, DwarfRegAlias<X2>;
243+
def X13_Y : RISCVCapReg<X13, "x13", ["a3"]>, DwarfRegAlias<X3>;
244+
def X14_Y : RISCVCapReg<X14, "x14", ["a4"]>, DwarfRegAlias<X4>;
245+
def X15_Y : RISCVCapReg<X15, "x15", ["a5"]>, DwarfRegAlias<X5>;
246+
let CostPerUse = [0, 1] in {
247+
def X16_Y : RISCVCapReg<X16, "x16", ["a6"]>, DwarfRegAlias<X16>;
248+
def X17_Y : RISCVCapReg<X17, "x17", ["a7"]>, DwarfRegAlias<X17>;
249+
def X18_Y : RISCVCapReg<X18, "x18", ["s2"]>, DwarfRegAlias<X18>;
250+
def X19_Y : RISCVCapReg<X19, "x19", ["s3"]>, DwarfRegAlias<X19>;
251+
def X20_Y : RISCVCapReg<X20, "x20", ["s4"]>, DwarfRegAlias<X20>;
252+
def X21_Y : RISCVCapReg<X21, "x21", ["s5"]>, DwarfRegAlias<X21>;
253+
def X22_Y : RISCVCapReg<X22, "x22", ["s6"]>, DwarfRegAlias<X22>;
254+
def X23_Y : RISCVCapReg<X23, "x23", ["s7"]>, DwarfRegAlias<X23>;
255+
def X24_Y : RISCVCapReg<X24, "x24", ["s8"]>, DwarfRegAlias<X24>;
256+
def X25_Y : RISCVCapReg<X25, "x25", ["s9"]>, DwarfRegAlias<X25>;
257+
def X26_Y : RISCVCapReg<X26, "x26", ["s10"]>, DwarfRegAlias<X26>;
258+
def X27_Y : RISCVCapReg<X27, "x27", ["s11"]>, DwarfRegAlias<X27>;
259+
def X28_Y : RISCVCapReg<X28, "x28", ["t3"]>, DwarfRegAlias<X28>;
260+
def X29_Y : RISCVCapReg<X29, "x29", ["t4"]>, DwarfRegAlias<X29>;
261+
def X30_Y : RISCVCapReg<X30, "x30", ["t5"]>, DwarfRegAlias<X30>;
262+
def X31_Y : RISCVCapReg<X31, "x31", ["t6"]>, DwarfRegAlias<X31>;
263+
}
264+
}
214265
}
215266

216267
def XLenVT : ValueTypeByHwMode<[RV32, RV64],
@@ -225,6 +276,9 @@ def XLenPairFVT : ValueTypeByHwMode<[RV32],
225276
def XLenRI : RegInfoByHwMode<
226277
[RV32, RV64],
227278
[RegInfo<32,32,32>, RegInfo<64,64,64>]>;
279+
def YLenVT : ValueTypeByHwMode<[RV32, RV64], [c64, c128]>;
280+
def YLenRI : RegInfoByHwMode<[RV32, RV64], [RegInfo<64, 64, 64>,
281+
RegInfo<128, 128, 128>]>;
228282

229283
class RISCVRegisterClass<list<ValueType> regTypes, int align, dag regList>
230284
: RegisterClass<"RISCV", regTypes, align, regList> {
@@ -251,6 +305,14 @@ def GPR : GPRRegisterClass<(add (sequence "X%u", 10, 17),
251305
(sequence "X%u", 18, 27),
252306
(sequence "X%u", 0, 4))>;
253307

308+
def YGPR
309+
: RegisterClass<"RISCV", [YLenVT], 64,
310+
(add (sequence "X%u_Y", 10, 17), (sequence "X%u_Y", 5, 7),
311+
(sequence "X%u_Y", 28, 31), (sequence "X%u_Y", 8, 9),
312+
(sequence "X%u_Y", 18, 27), (sequence "X%u_Y", 0, 4))> {
313+
let RegInfos = YLenRI;
314+
}
315+
254316
def GPRX0 : GPRRegisterClass<(add X0)>;
255317

256318
def GPRX1 : GPRRegisterClass<(add X1)> {

0 commit comments

Comments
 (0)