xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Target/ARM/ARMRegisterInfo.td (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg//===-- ARMRegisterInfo.td - ARM Register defs -------------*- tablegen -*-===//
27330f729Sjoerg//
37330f729Sjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg// See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg//
77330f729Sjoerg//===----------------------------------------------------------------------===//
87330f729Sjoerg
97330f729Sjoerginclude "ARMSystemRegister.td"
107330f729Sjoerg
117330f729Sjoerg//===----------------------------------------------------------------------===//
127330f729Sjoerg//  Declarations that describe the ARM register file
137330f729Sjoerg//===----------------------------------------------------------------------===//
147330f729Sjoerg
157330f729Sjoerg// Registers are identified with 4-bit ID numbers.
167330f729Sjoergclass ARMReg<bits<16> Enc, string n, list<Register> subregs = [],
177330f729Sjoerg             list<string> altNames = []> : Register<n, altNames> {
187330f729Sjoerg  let HWEncoding = Enc;
197330f729Sjoerg  let Namespace = "ARM";
207330f729Sjoerg  let SubRegs = subregs;
217330f729Sjoerg  // All bits of ARM registers with sub-registers are covered by sub-registers.
227330f729Sjoerg  let CoveredBySubRegs = 1;
237330f729Sjoerg}
247330f729Sjoerg
257330f729Sjoergclass ARMFReg<bits<16> Enc, string n> : Register<n> {
267330f729Sjoerg  let HWEncoding = Enc;
277330f729Sjoerg  let Namespace = "ARM";
287330f729Sjoerg}
297330f729Sjoerg
307330f729Sjoerglet Namespace = "ARM",
317330f729Sjoerg    FallbackRegAltNameIndex = NoRegAltName in {
327330f729Sjoerg  def RegNamesRaw : RegAltNameIndex;
337330f729Sjoerg}
347330f729Sjoerg
357330f729Sjoerg// Subregister indices.
367330f729Sjoerglet Namespace = "ARM" in {
377330f729Sjoergdef qqsub_0 : SubRegIndex<256>;
387330f729Sjoergdef qqsub_1 : SubRegIndex<256, 256>;
397330f729Sjoerg
407330f729Sjoerg// Note: Code depends on these having consecutive numbers.
417330f729Sjoergdef qsub_0 : SubRegIndex<128>;
427330f729Sjoergdef qsub_1 : SubRegIndex<128, 128>;
437330f729Sjoergdef qsub_2 : ComposedSubRegIndex<qqsub_1, qsub_0>;
447330f729Sjoergdef qsub_3 : ComposedSubRegIndex<qqsub_1, qsub_1>;
457330f729Sjoerg
467330f729Sjoergdef dsub_0 : SubRegIndex<64>;
477330f729Sjoergdef dsub_1 : SubRegIndex<64, 64>;
487330f729Sjoergdef dsub_2 : ComposedSubRegIndex<qsub_1, dsub_0>;
497330f729Sjoergdef dsub_3 : ComposedSubRegIndex<qsub_1, dsub_1>;
507330f729Sjoergdef dsub_4 : ComposedSubRegIndex<qsub_2, dsub_0>;
517330f729Sjoergdef dsub_5 : ComposedSubRegIndex<qsub_2, dsub_1>;
527330f729Sjoergdef dsub_6 : ComposedSubRegIndex<qsub_3, dsub_0>;
537330f729Sjoergdef dsub_7 : ComposedSubRegIndex<qsub_3, dsub_1>;
547330f729Sjoerg
557330f729Sjoergdef ssub_0  : SubRegIndex<32>;
567330f729Sjoergdef ssub_1  : SubRegIndex<32, 32>;
577330f729Sjoergdef ssub_2  : ComposedSubRegIndex<dsub_1, ssub_0>;
587330f729Sjoergdef ssub_3  : ComposedSubRegIndex<dsub_1, ssub_1>;
597330f729Sjoergdef ssub_4  : ComposedSubRegIndex<dsub_2, ssub_0>;
607330f729Sjoergdef ssub_5  : ComposedSubRegIndex<dsub_2, ssub_1>;
617330f729Sjoergdef ssub_6  : ComposedSubRegIndex<dsub_3, ssub_0>;
627330f729Sjoergdef ssub_7  : ComposedSubRegIndex<dsub_3, ssub_1>;
637330f729Sjoergdef ssub_8  : ComposedSubRegIndex<dsub_4, ssub_0>;
647330f729Sjoergdef ssub_9  : ComposedSubRegIndex<dsub_4, ssub_1>;
657330f729Sjoergdef ssub_10 : ComposedSubRegIndex<dsub_5, ssub_0>;
667330f729Sjoergdef ssub_11 : ComposedSubRegIndex<dsub_5, ssub_1>;
677330f729Sjoergdef ssub_12 : ComposedSubRegIndex<dsub_6, ssub_0>;
687330f729Sjoergdef ssub_13 : ComposedSubRegIndex<dsub_6, ssub_1>;
697330f729Sjoerg
707330f729Sjoergdef gsub_0 : SubRegIndex<32>;
717330f729Sjoergdef gsub_1 : SubRegIndex<32, 32>;
727330f729Sjoerg// Let TableGen synthesize the remaining 12 ssub_* indices.
737330f729Sjoerg// We don't need to name them.
747330f729Sjoerg}
757330f729Sjoerg
767330f729Sjoerg// Integer registers
777330f729Sjoergdef R0  : ARMReg< 0, "r0">,  DwarfRegNum<[0]>;
787330f729Sjoergdef R1  : ARMReg< 1, "r1">,  DwarfRegNum<[1]>;
797330f729Sjoergdef R2  : ARMReg< 2, "r2">,  DwarfRegNum<[2]>;
807330f729Sjoergdef R3  : ARMReg< 3, "r3">,  DwarfRegNum<[3]>;
817330f729Sjoergdef R4  : ARMReg< 4, "r4">,  DwarfRegNum<[4]>;
827330f729Sjoergdef R5  : ARMReg< 5, "r5">,  DwarfRegNum<[5]>;
837330f729Sjoergdef R6  : ARMReg< 6, "r6">,  DwarfRegNum<[6]>;
847330f729Sjoergdef R7  : ARMReg< 7, "r7">,  DwarfRegNum<[7]>;
857330f729Sjoerg// These require 32-bit instructions.
86*82d56013Sjoerglet CostPerUse = [1] in {
877330f729Sjoergdef R8  : ARMReg< 8, "r8">,  DwarfRegNum<[8]>;
887330f729Sjoergdef R9  : ARMReg< 9, "r9">,  DwarfRegNum<[9]>;
897330f729Sjoergdef R10 : ARMReg<10, "r10">, DwarfRegNum<[10]>;
907330f729Sjoergdef R11 : ARMReg<11, "r11">, DwarfRegNum<[11]>;
917330f729Sjoergdef R12 : ARMReg<12, "r12">, DwarfRegNum<[12]>;
927330f729Sjoerglet RegAltNameIndices = [RegNamesRaw] in {
937330f729Sjoergdef SP  : ARMReg<13, "sp", [], ["r13"]>,  DwarfRegNum<[13]>;
947330f729Sjoergdef LR  : ARMReg<14, "lr", [], ["r14"]>,  DwarfRegNum<[14]>;
957330f729Sjoergdef PC  : ARMReg<15, "pc", [], ["r15"]>,  DwarfRegNum<[15]>;
967330f729Sjoerg}
977330f729Sjoerg}
987330f729Sjoerg
997330f729Sjoerg// Float registers
1007330f729Sjoergdef S0  : ARMFReg< 0, "s0">;  def S1  : ARMFReg< 1, "s1">;
1017330f729Sjoergdef S2  : ARMFReg< 2, "s2">;  def S3  : ARMFReg< 3, "s3">;
1027330f729Sjoergdef S4  : ARMFReg< 4, "s4">;  def S5  : ARMFReg< 5, "s5">;
1037330f729Sjoergdef S6  : ARMFReg< 6, "s6">;  def S7  : ARMFReg< 7, "s7">;
1047330f729Sjoergdef S8  : ARMFReg< 8, "s8">;  def S9  : ARMFReg< 9, "s9">;
1057330f729Sjoergdef S10 : ARMFReg<10, "s10">; def S11 : ARMFReg<11, "s11">;
1067330f729Sjoergdef S12 : ARMFReg<12, "s12">; def S13 : ARMFReg<13, "s13">;
1077330f729Sjoergdef S14 : ARMFReg<14, "s14">; def S15 : ARMFReg<15, "s15">;
1087330f729Sjoergdef S16 : ARMFReg<16, "s16">; def S17 : ARMFReg<17, "s17">;
1097330f729Sjoergdef S18 : ARMFReg<18, "s18">; def S19 : ARMFReg<19, "s19">;
1107330f729Sjoergdef S20 : ARMFReg<20, "s20">; def S21 : ARMFReg<21, "s21">;
1117330f729Sjoergdef S22 : ARMFReg<22, "s22">; def S23 : ARMFReg<23, "s23">;
1127330f729Sjoergdef S24 : ARMFReg<24, "s24">; def S25 : ARMFReg<25, "s25">;
1137330f729Sjoergdef S26 : ARMFReg<26, "s26">; def S27 : ARMFReg<27, "s27">;
1147330f729Sjoergdef S28 : ARMFReg<28, "s28">; def S29 : ARMFReg<29, "s29">;
1157330f729Sjoergdef S30 : ARMFReg<30, "s30">; def S31 : ARMFReg<31, "s31">;
1167330f729Sjoerg
1177330f729Sjoerg// Aliases of the F* registers used to hold 64-bit fp values (doubles)
1187330f729Sjoerglet SubRegIndices = [ssub_0, ssub_1] in {
1197330f729Sjoergdef D0  : ARMReg< 0,  "d0", [S0,   S1]>, DwarfRegNum<[256]>;
1207330f729Sjoergdef D1  : ARMReg< 1,  "d1", [S2,   S3]>, DwarfRegNum<[257]>;
1217330f729Sjoergdef D2  : ARMReg< 2,  "d2", [S4,   S5]>, DwarfRegNum<[258]>;
1227330f729Sjoergdef D3  : ARMReg< 3,  "d3", [S6,   S7]>, DwarfRegNum<[259]>;
1237330f729Sjoergdef D4  : ARMReg< 4,  "d4", [S8,   S9]>, DwarfRegNum<[260]>;
1247330f729Sjoergdef D5  : ARMReg< 5,  "d5", [S10, S11]>, DwarfRegNum<[261]>;
1257330f729Sjoergdef D6  : ARMReg< 6,  "d6", [S12, S13]>, DwarfRegNum<[262]>;
1267330f729Sjoergdef D7  : ARMReg< 7,  "d7", [S14, S15]>, DwarfRegNum<[263]>;
1277330f729Sjoergdef D8  : ARMReg< 8,  "d8", [S16, S17]>, DwarfRegNum<[264]>;
1287330f729Sjoergdef D9  : ARMReg< 9,  "d9", [S18, S19]>, DwarfRegNum<[265]>;
1297330f729Sjoergdef D10 : ARMReg<10, "d10", [S20, S21]>, DwarfRegNum<[266]>;
1307330f729Sjoergdef D11 : ARMReg<11, "d11", [S22, S23]>, DwarfRegNum<[267]>;
1317330f729Sjoergdef D12 : ARMReg<12, "d12", [S24, S25]>, DwarfRegNum<[268]>;
1327330f729Sjoergdef D13 : ARMReg<13, "d13", [S26, S27]>, DwarfRegNum<[269]>;
1337330f729Sjoergdef D14 : ARMReg<14, "d14", [S28, S29]>, DwarfRegNum<[270]>;
1347330f729Sjoergdef D15 : ARMReg<15, "d15", [S30, S31]>, DwarfRegNum<[271]>;
1357330f729Sjoerg}
1367330f729Sjoerg
1377330f729Sjoerg// VFP3 defines 16 additional double registers
1387330f729Sjoergdef D16 : ARMFReg<16, "d16">, DwarfRegNum<[272]>;
1397330f729Sjoergdef D17 : ARMFReg<17, "d17">, DwarfRegNum<[273]>;
1407330f729Sjoergdef D18 : ARMFReg<18, "d18">, DwarfRegNum<[274]>;
1417330f729Sjoergdef D19 : ARMFReg<19, "d19">, DwarfRegNum<[275]>;
1427330f729Sjoergdef D20 : ARMFReg<20, "d20">, DwarfRegNum<[276]>;
1437330f729Sjoergdef D21 : ARMFReg<21, "d21">, DwarfRegNum<[277]>;
1447330f729Sjoergdef D22 : ARMFReg<22, "d22">, DwarfRegNum<[278]>;
1457330f729Sjoergdef D23 : ARMFReg<23, "d23">, DwarfRegNum<[279]>;
1467330f729Sjoergdef D24 : ARMFReg<24, "d24">, DwarfRegNum<[280]>;
1477330f729Sjoergdef D25 : ARMFReg<25, "d25">, DwarfRegNum<[281]>;
1487330f729Sjoergdef D26 : ARMFReg<26, "d26">, DwarfRegNum<[282]>;
1497330f729Sjoergdef D27 : ARMFReg<27, "d27">, DwarfRegNum<[283]>;
1507330f729Sjoergdef D28 : ARMFReg<28, "d28">, DwarfRegNum<[284]>;
1517330f729Sjoergdef D29 : ARMFReg<29, "d29">, DwarfRegNum<[285]>;
1527330f729Sjoergdef D30 : ARMFReg<30, "d30">, DwarfRegNum<[286]>;
1537330f729Sjoergdef D31 : ARMFReg<31, "d31">, DwarfRegNum<[287]>;
1547330f729Sjoerg
1557330f729Sjoerg// Advanced SIMD (NEON) defines 16 quad-word aliases
1567330f729Sjoerglet SubRegIndices = [dsub_0, dsub_1] in {
1577330f729Sjoergdef Q0  : ARMReg< 0,  "q0", [D0,   D1]>;
1587330f729Sjoergdef Q1  : ARMReg< 1,  "q1", [D2,   D3]>;
1597330f729Sjoergdef Q2  : ARMReg< 2,  "q2", [D4,   D5]>;
1607330f729Sjoergdef Q3  : ARMReg< 3,  "q3", [D6,   D7]>;
1617330f729Sjoergdef Q4  : ARMReg< 4,  "q4", [D8,   D9]>;
1627330f729Sjoergdef Q5  : ARMReg< 5,  "q5", [D10, D11]>;
1637330f729Sjoergdef Q6  : ARMReg< 6,  "q6", [D12, D13]>;
1647330f729Sjoergdef Q7  : ARMReg< 7,  "q7", [D14, D15]>;
1657330f729Sjoerg}
1667330f729Sjoerglet SubRegIndices = [dsub_0, dsub_1] in {
1677330f729Sjoergdef Q8  : ARMReg< 8,  "q8", [D16, D17]>;
1687330f729Sjoergdef Q9  : ARMReg< 9,  "q9", [D18, D19]>;
1697330f729Sjoergdef Q10 : ARMReg<10, "q10", [D20, D21]>;
1707330f729Sjoergdef Q11 : ARMReg<11, "q11", [D22, D23]>;
1717330f729Sjoergdef Q12 : ARMReg<12, "q12", [D24, D25]>;
1727330f729Sjoergdef Q13 : ARMReg<13, "q13", [D26, D27]>;
1737330f729Sjoergdef Q14 : ARMReg<14, "q14", [D28, D29]>;
1747330f729Sjoergdef Q15 : ARMReg<15, "q15", [D30, D31]>;
1757330f729Sjoerg}
1767330f729Sjoerg
1777330f729Sjoerg// Current Program Status Register.
1787330f729Sjoerg// We model fpscr with two registers: FPSCR models the control bits and will be
1797330f729Sjoerg// reserved. FPSCR_NZCV models the flag bits and will be unreserved. APSR_NZCV
1807330f729Sjoerg// models the APSR when it's accessed by some special instructions. In such cases
1817330f729Sjoerg// it has the same encoding as PC.
1827330f729Sjoergdef CPSR       : ARMReg<0,  "cpsr">;
1837330f729Sjoergdef APSR       : ARMReg<15, "apsr">;
1847330f729Sjoergdef APSR_NZCV  : ARMReg<15, "apsr_nzcv">;
1857330f729Sjoergdef SPSR       : ARMReg<2,  "spsr">;
1867330f729Sjoergdef FPSCR      : ARMReg<3,  "fpscr">;
1877330f729Sjoergdef FPSCR_NZCV : ARMReg<3,  "fpscr_nzcv"> {
1887330f729Sjoerg  let Aliases = [FPSCR];
1897330f729Sjoerg}
1907330f729Sjoergdef ITSTATE    : ARMReg<4, "itstate">;
1917330f729Sjoerg
1927330f729Sjoerg// Special Registers - only available in privileged mode.
1937330f729Sjoergdef FPSID   : ARMReg<0,  "fpsid">;
1947330f729Sjoergdef MVFR2   : ARMReg<5,  "mvfr2">;
1957330f729Sjoergdef MVFR1   : ARMReg<6,  "mvfr1">;
1967330f729Sjoergdef MVFR0   : ARMReg<7,  "mvfr0">;
1977330f729Sjoergdef FPEXC   : ARMReg<8,  "fpexc">;
1987330f729Sjoergdef FPINST  : ARMReg<9,  "fpinst">;
1997330f729Sjoergdef FPINST2 : ARMReg<10, "fpinst2">;
2007330f729Sjoerg// These encodings aren't actual instruction encodings, their encoding depends
2017330f729Sjoerg// on the instruction they are used in and for VPR 32 was chosen such that it
2027330f729Sjoerg// always comes last in spr_reglist_with_vpr.
2037330f729Sjoergdef VPR     : ARMReg<32, "vpr">;
2047330f729Sjoergdef FPSCR_NZCVQC
2057330f729Sjoerg            : ARMReg<2, "fpscr_nzcvqc">;
2067330f729Sjoergdef P0      : ARMReg<13, "p0">;
2077330f729Sjoergdef FPCXTNS : ARMReg<14, "fpcxtns">;
2087330f729Sjoergdef FPCXTS  : ARMReg<15, "fpcxts">;
2097330f729Sjoerg
2107330f729Sjoergdef ZR  : ARMReg<15, "zr">,  DwarfRegNum<[15]>;
2117330f729Sjoerg
2127330f729Sjoerg// Register classes.
2137330f729Sjoerg//
2147330f729Sjoerg// pc  == Program Counter
2157330f729Sjoerg// lr  == Link Register
2167330f729Sjoerg// sp  == Stack Pointer
2177330f729Sjoerg// r12 == ip (scratch)
2187330f729Sjoerg// r7  == Frame Pointer (thumb-style backtraces)
2197330f729Sjoerg// r9  == May be reserved as Thread Register
2207330f729Sjoerg// r11 == Frame Pointer (arm-style backtraces)
2217330f729Sjoerg// r10 == Stack Limit
2227330f729Sjoerg//
2237330f729Sjoergdef GPR : RegisterClass<"ARM", [i32], 32, (add (sequence "R%u", 0, 12),
2247330f729Sjoerg                                               SP, LR, PC)> {
2257330f729Sjoerg  // Allocate LR as the first CSR since it is always saved anyway.
2267330f729Sjoerg  // For Thumb1 mode, we don't want to allocate hi regs at all, as we don't
2277330f729Sjoerg  // know how to spill them. If we make our prologue/epilogue code smarter at
2287330f729Sjoerg  // some point, we can go back to using the above allocation orders for the
2297330f729Sjoerg  // Thumb1 instructions that know how to use hi regs.
2307330f729Sjoerg  let AltOrders = [(add LR, GPR), (trunc GPR, 8),
2317330f729Sjoerg                   (add (trunc GPR, 8), R12, LR, (shl GPR, 8))];
2327330f729Sjoerg  let AltOrderSelect = [{
2337330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().getGPRAllocationOrder(MF);
2347330f729Sjoerg  }];
2357330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r15]";
2367330f729Sjoerg}
2377330f729Sjoerg
238*82d56013Sjoerg// Register set that excludes registers that are reserved for procedure calls.
239*82d56013Sjoerg// This is used for pseudo-instructions that are actually implemented using a
240*82d56013Sjoerg// procedure call.
241*82d56013Sjoergdef GPRnoip : RegisterClass<"ARM", [i32], 32, (sub GPR, R12, LR)> {
242*82d56013Sjoerg  // Allocate LR as the first CSR since it is always saved anyway.
243*82d56013Sjoerg  // For Thumb1 mode, we don't want to allocate hi regs at all, as we don't
244*82d56013Sjoerg  // know how to spill them. If we make our prologue/epilogue code smarter at
245*82d56013Sjoerg  // some point, we can go back to using the above allocation orders for the
246*82d56013Sjoerg  // Thumb1 instructions that know how to use hi regs.
247*82d56013Sjoerg  let AltOrders = [(add GPRnoip, GPRnoip), (trunc GPRnoip, 8),
248*82d56013Sjoerg                   (add (trunc GPRnoip, 8), (shl GPRnoip, 8))];
249*82d56013Sjoerg  let AltOrderSelect = [{
250*82d56013Sjoerg      return MF.getSubtarget<ARMSubtarget>().getGPRAllocationOrder(MF);
251*82d56013Sjoerg  }];
252*82d56013Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r14]";
253*82d56013Sjoerg}
254*82d56013Sjoerg
2557330f729Sjoerg// GPRs without the PC.  Some ARM instructions do not allow the PC in
2567330f729Sjoerg// certain operand slots, particularly as the destination.  Primarily
2577330f729Sjoerg// useful for disassembly.
2587330f729Sjoergdef GPRnopc : RegisterClass<"ARM", [i32], 32, (sub GPR, PC)> {
2597330f729Sjoerg  let AltOrders = [(add LR, GPRnopc), (trunc GPRnopc, 8),
2607330f729Sjoerg                   (add (trunc GPRnopc, 8), R12, LR, (shl GPRnopc, 8))];
2617330f729Sjoerg  let AltOrderSelect = [{
2627330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().getGPRAllocationOrder(MF);
2637330f729Sjoerg  }];
2647330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r14]";
2657330f729Sjoerg}
2667330f729Sjoerg
2677330f729Sjoerg// GPRs without the PC but with APSR. Some instructions allow accessing the
2687330f729Sjoerg// APSR, while actually encoding PC in the register field. This is useful
2697330f729Sjoerg// for assembly and disassembly only.
2707330f729Sjoergdef GPRwithAPSR : RegisterClass<"ARM", [i32], 32, (add (sub GPR, PC), APSR_NZCV)> {
2717330f729Sjoerg  let AltOrders = [(add LR, GPRnopc), (trunc GPRnopc, 8)];
2727330f729Sjoerg  let AltOrderSelect = [{
2737330f729Sjoerg      return 1 + MF.getSubtarget<ARMSubtarget>().isThumb1Only();
2747330f729Sjoerg  }];
2757330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r14] or apsr_nzcv";
2767330f729Sjoerg}
2777330f729Sjoerg
2787330f729Sjoerg// GPRs without the PC and SP registers but with APSR. Used by CLRM instruction.
2797330f729Sjoergdef GPRwithAPSRnosp : RegisterClass<"ARM", [i32], 32, (add (sequence "R%u", 0, 12), LR, APSR)> {
2807330f729Sjoerg  let isAllocatable = 0;
2817330f729Sjoerg}
2827330f729Sjoerg
2837330f729Sjoergdef GPRwithZR : RegisterClass<"ARM", [i32], 32, (add (sub GPR, PC), ZR)> {
2847330f729Sjoerg  let AltOrders = [(add LR, GPRwithZR), (trunc GPRwithZR, 8)];
2857330f729Sjoerg  let AltOrderSelect = [{
2867330f729Sjoerg      return 1 + MF.getSubtarget<ARMSubtarget>().isThumb1Only();
2877330f729Sjoerg  }];
2887330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r14] or zr";
2897330f729Sjoerg}
2907330f729Sjoerg
2917330f729Sjoergdef GPRwithZRnosp : RegisterClass<"ARM", [i32], 32, (sub GPRwithZR, SP)> {
2927330f729Sjoerg  let AltOrders = [(add LR, GPRwithZRnosp), (trunc GPRwithZRnosp, 8)];
2937330f729Sjoerg  let AltOrderSelect = [{
2947330f729Sjoerg      return 1 + MF.getSubtarget<ARMSubtarget>().isThumb1Only();
2957330f729Sjoerg  }];
2967330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r12] or r14 or zr";
2977330f729Sjoerg}
2987330f729Sjoerg
2997330f729Sjoerg// GPRsp - Only the SP is legal. Used by Thumb1 instructions that want the
3007330f729Sjoerg// implied SP argument list.
3017330f729Sjoerg// FIXME: It would be better to not use this at all and refactor the
3027330f729Sjoerg// instructions to not have SP an an explicit argument. That makes
3037330f729Sjoerg// frame index resolution a bit trickier, though.
3047330f729Sjoergdef GPRsp : RegisterClass<"ARM", [i32], 32, (add SP)> {
3057330f729Sjoerg  let DiagnosticString = "operand must be a register sp";
3067330f729Sjoerg}
3077330f729Sjoerg
3087330f729Sjoerg// GPRlr - Only LR is legal. Used by ARMv8.1-M Low Overhead Loop instructions
3097330f729Sjoerg// where LR is the only legal loop counter register.
3107330f729Sjoergdef GPRlr : RegisterClass<"ARM", [i32], 32, (add LR)>;
3117330f729Sjoerg
3127330f729Sjoerg// restricted GPR register class. Many Thumb2 instructions allow the full
3137330f729Sjoerg// register range for operands, but have undefined behaviours when PC
3147330f729Sjoerg// or SP (R13 or R15) are used. The ARM ISA refers to these operands
3157330f729Sjoerg// via the BadReg() pseudo-code description.
3167330f729Sjoergdef rGPR : RegisterClass<"ARM", [i32], 32, (sub GPR, SP, PC)> {
3177330f729Sjoerg  let AltOrders = [(add LR, rGPR), (trunc rGPR, 8),
3187330f729Sjoerg                   (add (trunc rGPR, 8), R12, LR, (shl rGPR, 8))];
3197330f729Sjoerg  let AltOrderSelect = [{
3207330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().getGPRAllocationOrder(MF);
3217330f729Sjoerg  }];
3227330f729Sjoerg  let DiagnosticType = "rGPR";
3237330f729Sjoerg}
3247330f729Sjoerg
325*82d56013Sjoerg// GPRs without the PC and SP but with APSR_NZCV.Some instructions allow
326*82d56013Sjoerg// accessing the APSR_NZCV, while actually encoding PC in the register field.
327*82d56013Sjoerg// This is useful for assembly and disassembly only.
328*82d56013Sjoerg// Currently used by the CDE extension.
329*82d56013Sjoergdef GPRwithAPSR_NZCVnosp
330*82d56013Sjoerg  : RegisterClass<"ARM", [i32], 32, (add (sequence "R%u", 0, 12), LR, APSR_NZCV)> {
331*82d56013Sjoerg  let isAllocatable = 0;
332*82d56013Sjoerg  let DiagnosticString =
333*82d56013Sjoerg    "operand must be a register in the range [r0, r12], r14 or apsr_nzcv";
334*82d56013Sjoerg}
335*82d56013Sjoerg
3367330f729Sjoerg// Thumb registers are R0-R7 normally. Some instructions can still use
3377330f729Sjoerg// the general GPR register class above (MOV, e.g.)
3387330f729Sjoergdef tGPR : RegisterClass<"ARM", [i32], 32, (trunc GPR, 8)> {
3397330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r0, r7]";
3407330f729Sjoerg}
3417330f729Sjoerg
3427330f729Sjoerg// Thumb registers R0-R7 and the PC. Some instructions like TBB or THH allow
3437330f729Sjoerg// the PC to be used as a destination operand as well.
3447330f729Sjoergdef tGPRwithpc : RegisterClass<"ARM", [i32], 32, (add tGPR, PC)>;
3457330f729Sjoerg
3467330f729Sjoerg// The high registers in thumb mode, R8-R15.
3477330f729Sjoergdef hGPR : RegisterClass<"ARM", [i32], 32, (sub GPR, tGPR)> {
3487330f729Sjoerg  let DiagnosticString = "operand must be a register in range [r8, r15]";
3497330f729Sjoerg}
3507330f729Sjoerg
3517330f729Sjoerg// For tail calls, we can't use callee-saved registers, as they are restored
3527330f729Sjoerg// to the saved value before the tail call, which would clobber a call address.
3537330f729Sjoerg// Note, getMinimalPhysRegClass(R0) returns tGPR because of the names of
3547330f729Sjoerg// this class and the preceding one(!)  This is what we want.
3557330f729Sjoergdef tcGPR : RegisterClass<"ARM", [i32], 32, (add R0, R1, R2, R3, R12)> {
3567330f729Sjoerg  let AltOrders = [(and tcGPR, tGPR)];
3577330f729Sjoerg  let AltOrderSelect = [{
3587330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().isThumb1Only();
3597330f729Sjoerg  }];
3607330f729Sjoerg}
3617330f729Sjoerg
3627330f729Sjoergdef tGPROdd : RegisterClass<"ARM", [i32], 32, (add R1, R3, R5, R7, R9, R11)> {
3637330f729Sjoerg  let AltOrders = [(and tGPROdd, tGPR)];
3647330f729Sjoerg  let AltOrderSelect = [{
3657330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().isThumb1Only();
3667330f729Sjoerg  }];
3677330f729Sjoerg  let DiagnosticString =
3687330f729Sjoerg    "operand must be an odd-numbered register in range [r1,r11]";
3697330f729Sjoerg}
3707330f729Sjoerg
3717330f729Sjoergdef tGPREven : RegisterClass<"ARM", [i32], 32, (add R0, R2, R4, R6, R8, R10, R12, LR)> {
3727330f729Sjoerg  let AltOrders = [(and tGPREven, tGPR)];
3737330f729Sjoerg  let AltOrderSelect = [{
3747330f729Sjoerg      return MF.getSubtarget<ARMSubtarget>().isThumb1Only();
3757330f729Sjoerg  }];
3767330f729Sjoerg  let DiagnosticString = "operand must be an even-numbered register";
3777330f729Sjoerg}
3787330f729Sjoerg
3797330f729Sjoerg// Condition code registers.
3807330f729Sjoergdef CCR : RegisterClass<"ARM", [i32], 32, (add CPSR)> {
3817330f729Sjoerg  let CopyCost = -1;  // Don't allow copying of status registers.
3827330f729Sjoerg  let isAllocatable = 0;
3837330f729Sjoerg}
3847330f729Sjoerg
3857330f729Sjoerg// MVE Condition code register.
3867330f729Sjoergdef VCCR : RegisterClass<"ARM", [i32, v16i1, v8i1, v4i1], 32, (add VPR)> {
3877330f729Sjoerg//  let CopyCost = -1;  // Don't allow copying of status registers.
3887330f729Sjoerg}
3897330f729Sjoerg
3907330f729Sjoerg// FPSCR, when the flags at the top of it are used as the input or
3917330f729Sjoerg// output to an instruction such as MVE VADC.
3927330f729Sjoergdef cl_FPSCR_NZCV : RegisterClass<"ARM", [i32], 32, (add FPSCR_NZCV)>;
3937330f729Sjoerg
3947330f729Sjoerg// Scalar single precision floating point register class..
3957330f729Sjoerg// FIXME: Allocation order changed to s0, s2, ... or s0, s4, ... as a quick hack
3967330f729Sjoerg// to avoid partial-write dependencies on D or Q (depending on platform)
3977330f729Sjoerg// registers (S registers are renamed as portions of D/Q registers).
3987330f729Sjoergdef SPR : RegisterClass<"ARM", [f32], 32, (sequence "S%u", 0, 31)> {
3997330f729Sjoerg  let AltOrders = [(add (decimate SPR, 2), SPR),
4007330f729Sjoerg                   (add (decimate SPR, 4),
4017330f729Sjoerg                        (decimate SPR, 2),
4027330f729Sjoerg                        (decimate (rotl SPR, 1), 4),
4037330f729Sjoerg                        (decimate (rotl SPR, 1), 2))];
4047330f729Sjoerg  let AltOrderSelect = [{
4057330f729Sjoerg    return 1 + MF.getSubtarget<ARMSubtarget>().useStride4VFPs();
4067330f729Sjoerg  }];
4077330f729Sjoerg  let DiagnosticString = "operand must be a register in range [s0, s31]";
4087330f729Sjoerg}
4097330f729Sjoerg
410*82d56013Sjoergdef HPR : RegisterClass<"ARM", [f16, bf16], 32, (sequence "S%u", 0, 31)> {
4117330f729Sjoerg  let AltOrders = [(add (decimate HPR, 2), SPR),
4127330f729Sjoerg                   (add (decimate HPR, 4),
4137330f729Sjoerg                        (decimate HPR, 2),
4147330f729Sjoerg                        (decimate (rotl HPR, 1), 4),
4157330f729Sjoerg                        (decimate (rotl HPR, 1), 2))];
4167330f729Sjoerg  let AltOrderSelect = [{
4177330f729Sjoerg    return 1 + MF.getSubtarget<ARMSubtarget>().useStride4VFPs();
4187330f729Sjoerg  }];
4197330f729Sjoerg  let DiagnosticString = "operand must be a register in range [s0, s31]";
4207330f729Sjoerg}
4217330f729Sjoerg
4227330f729Sjoerg// Subset of SPR which can be used as a source of NEON scalars for 16-bit
4237330f729Sjoerg// operations
4247330f729Sjoergdef SPR_8 : RegisterClass<"ARM", [f32], 32, (sequence "S%u", 0, 15)> {
4257330f729Sjoerg  let DiagnosticString = "operand must be a register in range [s0, s15]";
4267330f729Sjoerg}
4277330f729Sjoerg
4287330f729Sjoerg// Scalar double precision floating point / generic 64-bit vector register
4297330f729Sjoerg// class.
4307330f729Sjoerg// ARM requires only word alignment for double. It's more performant if it
4317330f729Sjoerg// is double-word alignment though.
432*82d56013Sjoergdef DPR : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32, v4f16, v4bf16], 64,
4337330f729Sjoerg                        (sequence "D%u", 0, 31)> {
4347330f729Sjoerg  // Allocate non-VFP2 registers D16-D31 first, and prefer even registers on
4357330f729Sjoerg  // Darwin platforms.
4367330f729Sjoerg  let AltOrders = [(rotl DPR, 16),
4377330f729Sjoerg                   (add (decimate (rotl DPR, 16), 2), (rotl DPR, 16))];
4387330f729Sjoerg  let AltOrderSelect = [{
4397330f729Sjoerg    return 1 + MF.getSubtarget<ARMSubtarget>().useStride4VFPs();
4407330f729Sjoerg  }];
4417330f729Sjoerg  let DiagnosticType = "DPR";
4427330f729Sjoerg}
4437330f729Sjoerg
4447330f729Sjoerg// Scalar single and double precision floating point and VPR register class,
4457330f729Sjoerg// this is only used for parsing, don't use it anywhere else as the size and
4467330f729Sjoerg// types don't match!
4477330f729Sjoergdef FPWithVPR : RegisterClass<"ARM", [f32], 32, (add SPR, DPR, VPR)> {
4487330f729Sjoerg    let isAllocatable = 0;
4497330f729Sjoerg}
4507330f729Sjoerg
4517330f729Sjoerg// Subset of DPR that are accessible with VFP2 (and so that also have
4527330f729Sjoerg// 32-bit SPR subregs).
453*82d56013Sjoergdef DPR_VFP2 : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32, v4f16, v4bf16], 64,
4547330f729Sjoerg                             (trunc DPR, 16)> {
4557330f729Sjoerg  let DiagnosticString = "operand must be a register in range [d0, d15]";
4567330f729Sjoerg}
4577330f729Sjoerg
4587330f729Sjoerg// Subset of DPR which can be used as a source of NEON scalars for 16-bit
4597330f729Sjoerg// operations
460*82d56013Sjoergdef DPR_8 : RegisterClass<"ARM", [f64, v8i8, v4i16, v2i32, v1i64, v2f32, v4f16, v4bf16], 64,
4617330f729Sjoerg                          (trunc DPR, 8)> {
4627330f729Sjoerg  let DiagnosticString = "operand must be a register in range [d0, d7]";
4637330f729Sjoerg}
4647330f729Sjoerg
4657330f729Sjoerg// Generic 128-bit vector register class.
466*82d56013Sjoergdef QPR : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64, v8f16, v8bf16], 128,
4677330f729Sjoerg                        (sequence "Q%u", 0, 15)> {
4687330f729Sjoerg  // Allocate non-VFP2 aliases Q8-Q15 first.
4697330f729Sjoerg  let AltOrders = [(rotl QPR, 8), (trunc QPR, 8)];
4707330f729Sjoerg  let AltOrderSelect = [{
4717330f729Sjoerg    return 1 + MF.getSubtarget<ARMSubtarget>().hasMVEIntegerOps();
4727330f729Sjoerg  }];
4737330f729Sjoerg  let DiagnosticString = "operand must be a register in range [q0, q15]";
4747330f729Sjoerg}
4757330f729Sjoerg
4767330f729Sjoerg// Subset of QPR that have 32-bit SPR subregs.
4777330f729Sjoergdef QPR_VFP2 : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
4787330f729Sjoerg                             128, (trunc QPR, 8)> {
4797330f729Sjoerg  let DiagnosticString = "operand must be a register in range [q0, q7]";
4807330f729Sjoerg}
4817330f729Sjoerg
4827330f729Sjoerg// Subset of QPR that have DPR_8 and SPR_8 subregs.
4837330f729Sjoergdef QPR_8 : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
4847330f729Sjoerg                           128, (trunc QPR, 4)> {
4857330f729Sjoerg  let DiagnosticString = "operand must be a register in range [q0, q3]";
4867330f729Sjoerg}
4877330f729Sjoerg
4887330f729Sjoerg// MVE 128-bit vector register class. This class is only really needed for
4897330f729Sjoerg// parsing assembly, since we still have to truncate the register set in the QPR
4907330f729Sjoerg// class anyway.
4917330f729Sjoergdef MQPR : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64, v8f16],
4927330f729Sjoerg                         128, (trunc QPR, 8)>;
4937330f729Sjoerg
4947330f729Sjoerg// Pseudo-registers representing odd-even pairs of D registers. The even-odd
4957330f729Sjoerg// pairs are already represented by the Q registers.
4967330f729Sjoerg// These are needed by NEON instructions requiring two consecutive D registers.
4977330f729Sjoerg// There is no D31_D0 register as that is always an UNPREDICTABLE encoding.
4987330f729Sjoergdef TuplesOE2D : RegisterTuples<[dsub_0, dsub_1],
4997330f729Sjoerg                                [(decimate (shl DPR, 1), 2),
5007330f729Sjoerg                                 (decimate (shl DPR, 2), 2)]>;
5017330f729Sjoerg
5027330f729Sjoerg// Register class representing a pair of consecutive D registers.
5037330f729Sjoerg// Use the Q registers for the even-odd pairs.
5047330f729Sjoergdef DPair : RegisterClass<"ARM", [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64],
5057330f729Sjoerg                          128, (interleave QPR, TuplesOE2D)> {
5067330f729Sjoerg  // Allocate starting at non-VFP2 registers D16-D31 first.
5077330f729Sjoerg  // Prefer even-odd pairs as they are easier to copy.
5087330f729Sjoerg  let AltOrders = [(add (rotl QPR, 8),  (rotl DPair, 16)),
5097330f729Sjoerg                   (add (trunc QPR, 8), (trunc DPair, 16))];
5107330f729Sjoerg  let AltOrderSelect = [{
5117330f729Sjoerg    return 1 + MF.getSubtarget<ARMSubtarget>().hasMVEIntegerOps();
5127330f729Sjoerg  }];
5137330f729Sjoerg}
5147330f729Sjoerg
5157330f729Sjoerg// Pseudo-registers representing even-odd pairs of GPRs from R1 to R13/SP.
5167330f729Sjoerg// These are needed by instructions (e.g. ldrexd/strexd) requiring even-odd GPRs.
5177330f729Sjoergdef Tuples2Rnosp : RegisterTuples<[gsub_0, gsub_1],
5187330f729Sjoerg                                  [(add R0, R2, R4, R6, R8, R10),
5197330f729Sjoerg                                   (add R1, R3, R5, R7, R9, R11)]>;
5207330f729Sjoerg
5217330f729Sjoergdef Tuples2Rsp   : RegisterTuples<[gsub_0, gsub_1],
5227330f729Sjoerg                                  [(add R12), (add SP)]>;
5237330f729Sjoerg
5247330f729Sjoerg// Register class representing a pair of even-odd GPRs.
5257330f729Sjoergdef GPRPair : RegisterClass<"ARM", [untyped], 64, (add Tuples2Rnosp, Tuples2Rsp)> {
5267330f729Sjoerg  let Size = 64; // 2 x 32 bits, we have no predefined type of that size.
5277330f729Sjoerg}
5287330f729Sjoerg
5297330f729Sjoerg// Register class representing a pair of even-odd GPRs, except (R12, SP).
5307330f729Sjoergdef GPRPairnosp : RegisterClass<"ARM", [untyped], 64, (add Tuples2Rnosp)> {
5317330f729Sjoerg  let Size = 64; // 2 x 32 bits, we have no predefined type of that size.
5327330f729Sjoerg}
5337330f729Sjoerg
5347330f729Sjoerg// Pseudo-registers representing 3 consecutive D registers.
5357330f729Sjoergdef Tuples3D : RegisterTuples<[dsub_0, dsub_1, dsub_2],
5367330f729Sjoerg                              [(shl DPR, 0),
5377330f729Sjoerg                               (shl DPR, 1),
5387330f729Sjoerg                               (shl DPR, 2)]>;
5397330f729Sjoerg
5407330f729Sjoerg// 3 consecutive D registers.
5417330f729Sjoergdef DTriple : RegisterClass<"ARM", [untyped], 64, (add Tuples3D)> {
5427330f729Sjoerg  let Size = 192; // 3 x 64 bits, we have no predefined type of that size.
5437330f729Sjoerg}
5447330f729Sjoerg
5457330f729Sjoerg// Pseudo 256-bit registers to represent pairs of Q registers. These should
5467330f729Sjoerg// never be present in the emitted code.
5477330f729Sjoerg// These are used for NEON load / store instructions, e.g., vld4, vst3.
5487330f729Sjoergdef Tuples2Q : RegisterTuples<[qsub_0, qsub_1], [(shl QPR, 0), (shl QPR, 1)]>;
5497330f729Sjoerg
5507330f729Sjoerg// Pseudo 256-bit vector register class to model pairs of Q registers
5517330f729Sjoerg// (4 consecutive D registers).
5527330f729Sjoergdef QQPR : RegisterClass<"ARM", [v4i64], 256, (add Tuples2Q)> {
5537330f729Sjoerg  // Allocate non-VFP2 aliases first.
5547330f729Sjoerg  let AltOrders = [(rotl QQPR, 8)];
5557330f729Sjoerg  let AltOrderSelect = [{ return 1; }];
5567330f729Sjoerg}
5577330f729Sjoerg
5587330f729Sjoerg// Tuples of 4 D regs that isn't also a pair of Q regs.
5597330f729Sjoergdef TuplesOE4D : RegisterTuples<[dsub_0, dsub_1, dsub_2, dsub_3],
5607330f729Sjoerg                                [(decimate (shl DPR, 1), 2),
5617330f729Sjoerg                                 (decimate (shl DPR, 2), 2),
5627330f729Sjoerg                                 (decimate (shl DPR, 3), 2),
5637330f729Sjoerg                                 (decimate (shl DPR, 4), 2)]>;
5647330f729Sjoerg
5657330f729Sjoerg// 4 consecutive D registers.
5667330f729Sjoergdef DQuad : RegisterClass<"ARM", [v4i64], 256,
5677330f729Sjoerg                          (interleave Tuples2Q, TuplesOE4D)>;
5687330f729Sjoerg
5697330f729Sjoerg// Pseudo 512-bit registers to represent four consecutive Q registers.
5707330f729Sjoergdef Tuples2QQ : RegisterTuples<[qqsub_0, qqsub_1],
5717330f729Sjoerg                               [(shl QQPR, 0), (shl QQPR, 2)]>;
5727330f729Sjoerg
5737330f729Sjoerg// Pseudo 512-bit vector register class to model 4 consecutive Q registers
5747330f729Sjoerg// (8 consecutive D registers).
5757330f729Sjoergdef QQQQPR : RegisterClass<"ARM", [v8i64], 256, (add Tuples2QQ)> {
5767330f729Sjoerg  // Allocate non-VFP2 aliases first.
5777330f729Sjoerg  let AltOrders = [(rotl QQQQPR, 8)];
5787330f729Sjoerg  let AltOrderSelect = [{ return 1; }];
5797330f729Sjoerg}
5807330f729Sjoerg
5817330f729Sjoerg
5827330f729Sjoerg// Pseudo-registers representing 2-spaced consecutive D registers.
5837330f729Sjoergdef Tuples2DSpc : RegisterTuples<[dsub_0, dsub_2],
5847330f729Sjoerg                                 [(shl DPR, 0),
5857330f729Sjoerg                                  (shl DPR, 2)]>;
5867330f729Sjoerg
5877330f729Sjoerg// Spaced pairs of D registers.
5887330f729Sjoergdef DPairSpc : RegisterClass<"ARM", [v2i64], 64, (add Tuples2DSpc)>;
5897330f729Sjoerg
5907330f729Sjoergdef Tuples3DSpc : RegisterTuples<[dsub_0, dsub_2, dsub_4],
5917330f729Sjoerg                                 [(shl DPR, 0),
5927330f729Sjoerg                                  (shl DPR, 2),
5937330f729Sjoerg                                  (shl DPR, 4)]>;
5947330f729Sjoerg
5957330f729Sjoerg// Spaced triples of D registers.
5967330f729Sjoergdef DTripleSpc : RegisterClass<"ARM", [untyped], 64, (add Tuples3DSpc)> {
5977330f729Sjoerg  let Size = 192; // 3 x 64 bits, we have no predefined type of that size.
5987330f729Sjoerg}
5997330f729Sjoerg
6007330f729Sjoergdef Tuples4DSpc : RegisterTuples<[dsub_0, dsub_2, dsub_4, dsub_6],
6017330f729Sjoerg                                 [(shl DPR, 0),
6027330f729Sjoerg                                  (shl DPR, 2),
6037330f729Sjoerg                                  (shl DPR, 4),
6047330f729Sjoerg                                  (shl DPR, 6)]>;
6057330f729Sjoerg
6067330f729Sjoerg// Spaced quads of D registers.
6077330f729Sjoergdef DQuadSpc : RegisterClass<"ARM", [v4i64], 64, (add Tuples3DSpc)>;
608*82d56013Sjoerg
609*82d56013Sjoerg// FP context payload
610*82d56013Sjoergdef FPCXTRegs : RegisterClass<"ARM", [i32], 32, (add FPCXTNS)>;
611