xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCV.td (revision 590d96feea75246dee213cb528930df8f6234b87)
10b57cec5SDimitry Andric//===-- RISCV.td - Describe the RISCV Target Machine -------*- tablegen -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andricinclude "llvm/Target/Target.td"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric// RISC-V subtarget features and instruction predicates.
130b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric
150b57cec5SDimitry Andricdef FeatureStdExtM
160b57cec5SDimitry Andric    : SubtargetFeature<"m", "HasStdExtM", "true",
170b57cec5SDimitry Andric                       "'M' (Integer Multiplication and Division)">;
180b57cec5SDimitry Andricdef HasStdExtM : Predicate<"Subtarget->hasStdExtM()">,
195ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtM),
20480093f4SDimitry Andric                           "'M' (Integer Multiplication and Division)">;
210b57cec5SDimitry Andric
220b57cec5SDimitry Andricdef FeatureStdExtA
230b57cec5SDimitry Andric    : SubtargetFeature<"a", "HasStdExtA", "true",
240b57cec5SDimitry Andric                       "'A' (Atomic Instructions)">;
250b57cec5SDimitry Andricdef HasStdExtA : Predicate<"Subtarget->hasStdExtA()">,
265ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtA),
27480093f4SDimitry Andric                           "'A' (Atomic Instructions)">;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andricdef FeatureStdExtF
300b57cec5SDimitry Andric    : SubtargetFeature<"f", "HasStdExtF", "true",
310b57cec5SDimitry Andric                       "'F' (Single-Precision Floating-Point)">;
320b57cec5SDimitry Andricdef HasStdExtF : Predicate<"Subtarget->hasStdExtF()">,
335ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtF),
34480093f4SDimitry Andric                           "'F' (Single-Precision Floating-Point)">;
350b57cec5SDimitry Andric
360b57cec5SDimitry Andricdef FeatureStdExtD
370b57cec5SDimitry Andric    : SubtargetFeature<"d", "HasStdExtD", "true",
380b57cec5SDimitry Andric                       "'D' (Double-Precision Floating-Point)",
390b57cec5SDimitry Andric                       [FeatureStdExtF]>;
400b57cec5SDimitry Andricdef HasStdExtD : Predicate<"Subtarget->hasStdExtD()">,
415ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtD),
42480093f4SDimitry Andric                           "'D' (Double-Precision Floating-Point)">;
430b57cec5SDimitry Andric
440b57cec5SDimitry Andricdef FeatureStdExtC
450b57cec5SDimitry Andric    : SubtargetFeature<"c", "HasStdExtC", "true",
460b57cec5SDimitry Andric                       "'C' (Compressed Instructions)">;
470b57cec5SDimitry Andricdef HasStdExtC : Predicate<"Subtarget->hasStdExtC()">,
485ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtC),
49480093f4SDimitry Andric                           "'C' (Compressed Instructions)">;
500b57cec5SDimitry Andric
515ffd83dbSDimitry Andricdef FeatureExtZbb
525ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbb", "HasStdExtZbb", "true",
535ffd83dbSDimitry Andric                       "'Zbb' (Base 'B' Instructions)">;
545ffd83dbSDimitry Andricdef HasStdExtZbb : Predicate<"Subtarget->hasStdExtZbb()">,
555ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbb),
565ffd83dbSDimitry Andric                             "'Zbb' (Base 'B' Instructions)">;
575ffd83dbSDimitry Andric
585ffd83dbSDimitry Andricdef FeatureExtZbc
595ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbc", "HasStdExtZbc", "true",
605ffd83dbSDimitry Andric                       "'Zbc' (Carry-Less 'B' Instructions)">;
615ffd83dbSDimitry Andricdef HasStdExtZbc : Predicate<"Subtarget->hasStdExtZbc()">,
625ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbc),
635ffd83dbSDimitry Andric                             "'Zbc' (Carry-Less 'B' Instructions)">;
645ffd83dbSDimitry Andric
655ffd83dbSDimitry Andricdef FeatureExtZbe
665ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbe", "HasStdExtZbe", "true",
675ffd83dbSDimitry Andric                       "'Zbe' (Extract-Deposit 'B' Instructions)">;
685ffd83dbSDimitry Andricdef HasStdExtZbe : Predicate<"Subtarget->hasStdExtZbe()">,
695ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbe),
705ffd83dbSDimitry Andric                             "'Zbe' (Extract-Deposit 'B' Instructions)">;
715ffd83dbSDimitry Andric
725ffd83dbSDimitry Andricdef FeatureExtZbf
735ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbf", "HasStdExtZbf", "true",
745ffd83dbSDimitry Andric                       "'Zbf' (Bit-Field 'B' Instructions)">;
755ffd83dbSDimitry Andricdef HasStdExtZbf : Predicate<"Subtarget->hasStdExtZbf()">,
765ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbf),
775ffd83dbSDimitry Andric                             "'Zbf' (Bit-Field 'B' Instructions)">;
785ffd83dbSDimitry Andric
795ffd83dbSDimitry Andricdef FeatureExtZbm
805ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbm", "HasStdExtZbm", "true",
815ffd83dbSDimitry Andric                       "'Zbm' (Matrix 'B' Instructions)">;
825ffd83dbSDimitry Andricdef HasStdExtZbm : Predicate<"Subtarget->hasStdExtZbm()">,
835ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbm),
845ffd83dbSDimitry Andric                             "'Zbm' (Matrix 'B' Instructions)">;
855ffd83dbSDimitry Andric
865ffd83dbSDimitry Andricdef FeatureExtZbp
875ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbp", "HasStdExtZbp", "true",
885ffd83dbSDimitry Andric                       "'Zbp' (Permutation 'B' Instructions)">;
895ffd83dbSDimitry Andricdef HasStdExtZbp : Predicate<"Subtarget->hasStdExtZbp()">,
905ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbp),
915ffd83dbSDimitry Andric                             "'Zbp' (Permutation 'B' Instructions)">;
925ffd83dbSDimitry Andric
935ffd83dbSDimitry Andricdef FeatureExtZbr
945ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbr", "HasStdExtZbr", "true",
955ffd83dbSDimitry Andric                       "'Zbr' (Polynomial Reduction 'B' Instructions)">;
965ffd83dbSDimitry Andricdef HasStdExtZbr : Predicate<"Subtarget->hasStdExtZbr()">,
975ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbr),
985ffd83dbSDimitry Andric                             "'Zbr' (Polynomial Reduction 'B' Instructions)">;
995ffd83dbSDimitry Andric
1005ffd83dbSDimitry Andricdef FeatureExtZbs
1015ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbs", "HasStdExtZbs", "true",
1025ffd83dbSDimitry Andric                       "'Zbs' (Single-Bit 'B' Instructions)">;
1035ffd83dbSDimitry Andricdef HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">,
1045ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbs),
1055ffd83dbSDimitry Andric                             "'Zbs' (Single-Bit 'B' Instructions)">;
1065ffd83dbSDimitry Andric
1075ffd83dbSDimitry Andricdef FeatureExtZbt
1085ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbt", "HasStdExtZbt", "true",
1095ffd83dbSDimitry Andric                       "'Zbt' (Ternary 'B' Instructions)">;
1105ffd83dbSDimitry Andricdef HasStdExtZbt : Predicate<"Subtarget->hasStdExtZbt()">,
1115ffd83dbSDimitry Andric                             AssemblerPredicate<(all_of FeatureExtZbt),
1125ffd83dbSDimitry Andric                             "'Zbt' (Ternary 'B' Instructions)">;
1135ffd83dbSDimitry Andric
1145ffd83dbSDimitry Andric// Some instructions belong to both the basic and the permutation
1155ffd83dbSDimitry Andric// subextensions. They should be enabled if either has been specified.
1165ffd83dbSDimitry Andricdef HasStdExtZbbOrZbp
1175ffd83dbSDimitry Andric    : Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp()">,
1185ffd83dbSDimitry Andric                AssemblerPredicate<(any_of FeatureExtZbb, FeatureExtZbp)>;
1195ffd83dbSDimitry Andric
1205ffd83dbSDimitry Andricdef FeatureExtZbproposedc
1215ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-zbproposedc", "HasStdExtZbproposedc", "true",
1225ffd83dbSDimitry Andric                       "'Zbproposedc' (Proposed Compressed 'B' Instructions)">;
1235ffd83dbSDimitry Andricdef HasStdExtZbproposedc : Predicate<"Subtarget->hasStdExtZbproposedc()">,
1245ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureExtZbproposedc),
1255ffd83dbSDimitry Andric                           "'Zbproposedc' (Proposed Compressed 'B' Instructions)">;
1265ffd83dbSDimitry Andric
1275ffd83dbSDimitry Andricdef FeatureStdExtB
1285ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-b", "HasStdExtB", "true",
1295ffd83dbSDimitry Andric                       "'B' (Bit Manipulation Instructions)",
1305ffd83dbSDimitry Andric                       [FeatureExtZbb,
1315ffd83dbSDimitry Andric                        FeatureExtZbc,
1325ffd83dbSDimitry Andric                        FeatureExtZbe,
1335ffd83dbSDimitry Andric                        FeatureExtZbf,
1345ffd83dbSDimitry Andric                        FeatureExtZbm,
1355ffd83dbSDimitry Andric                        FeatureExtZbp,
1365ffd83dbSDimitry Andric                        FeatureExtZbr,
1375ffd83dbSDimitry Andric                        FeatureExtZbs,
1385ffd83dbSDimitry Andric                        FeatureExtZbt]>;
1395ffd83dbSDimitry Andricdef HasStdExtB : Predicate<"Subtarget->hasStdExtB()">,
1405ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtB),
1415ffd83dbSDimitry Andric                           "'B' (Bit Manipulation Instructions)">;
1425ffd83dbSDimitry Andric
1435ffd83dbSDimitry Andricdef FeatureNoRVCHints
1445ffd83dbSDimitry Andric    : SubtargetFeature<"no-rvc-hints", "EnableRVCHintInstrs", "false",
1455ffd83dbSDimitry Andric                       "Disable RVC Hint Instructions.">;
1468bcb0991SDimitry Andricdef HasRVCHints : Predicate<"Subtarget->enableRVCHintInstrs()">,
1475ffd83dbSDimitry Andric                  AssemblerPredicate<(all_of(not FeatureNoRVCHints)),
148480093f4SDimitry Andric                                     "RVC Hint Instructions">;
1490b57cec5SDimitry Andric
1505ffd83dbSDimitry Andricdef FeatureStdExtV
1515ffd83dbSDimitry Andric    : SubtargetFeature<"experimental-v", "HasStdExtV", "true",
1525ffd83dbSDimitry Andric                       "'V' (Vector Instructions)",
1535ffd83dbSDimitry Andric                       [FeatureStdExtF]>;
1545ffd83dbSDimitry Andricdef HasStdExtV : Predicate<"Subtarget->hasStdExtV()">,
1555ffd83dbSDimitry Andric                           AssemblerPredicate<(all_of FeatureStdExtV),
1565ffd83dbSDimitry Andric                           "'V' (Vector Instructions)">;
1575ffd83dbSDimitry Andric
1580b57cec5SDimitry Andricdef Feature64Bit
1590b57cec5SDimitry Andric    : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">;
1600b57cec5SDimitry Andricdef IsRV64 : Predicate<"Subtarget->is64Bit()">,
1615ffd83dbSDimitry Andric                       AssemblerPredicate<(all_of Feature64Bit),
162480093f4SDimitry Andric                       "RV64I Base Instruction Set">;
1630b57cec5SDimitry Andricdef IsRV32 : Predicate<"!Subtarget->is64Bit()">,
1645ffd83dbSDimitry Andric                       AssemblerPredicate<(all_of (not Feature64Bit)),
165480093f4SDimitry Andric                       "RV32I Base Instruction Set">;
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andricdef RV64           : HwMode<"+64bit">;
1680b57cec5SDimitry Andricdef RV32           : HwMode<"-64bit">;
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andricdef FeatureRV32E
1710b57cec5SDimitry Andric    : SubtargetFeature<"e", "IsRV32E", "true",
1720b57cec5SDimitry Andric                       "Implements RV32E (provides 16 rather than 32 GPRs)">;
1730b57cec5SDimitry Andricdef IsRV32E : Predicate<"Subtarget->isRV32E()">,
1745ffd83dbSDimitry Andric                        AssemblerPredicate<(all_of FeatureRV32E)>;
1750b57cec5SDimitry Andric
1760b57cec5SDimitry Andricdef FeatureRelax
1770b57cec5SDimitry Andric    : SubtargetFeature<"relax", "EnableLinkerRelax", "true",
1780b57cec5SDimitry Andric                       "Enable Linker relaxation.">;
1790b57cec5SDimitry Andric
180480093f4SDimitry Andricforeach i = {1-31} in
181480093f4SDimitry Andric    def FeatureReserveX#i :
182480093f4SDimitry Andric        SubtargetFeature<"reserve-x"#i, "UserReservedRegister[RISCV::X"#i#"]",
183480093f4SDimitry Andric                         "true", "Reserve X"#i>;
184480093f4SDimitry Andric
1855ffd83dbSDimitry Andricdef FeatureSaveRestore : SubtargetFeature<"save-restore", "EnableSaveRestore",
1865ffd83dbSDimitry Andric                                          "true", "Enable save/restore.">;
1875ffd83dbSDimitry Andric
1880b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1890b57cec5SDimitry Andric// Named operands for CSR instructions.
1900b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andricinclude "RISCVSystemOperands.td"
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1950b57cec5SDimitry Andric// Registers, calling conventions, instruction descriptions.
1960b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1970b57cec5SDimitry Andric
19813138422SDimitry Andricinclude "RISCVSchedule.td"
1990b57cec5SDimitry Andricinclude "RISCVRegisterInfo.td"
2000b57cec5SDimitry Andricinclude "RISCVCallingConv.td"
2010b57cec5SDimitry Andricinclude "RISCVInstrInfo.td"
2028bcb0991SDimitry Andricinclude "RISCVRegisterBanks.td"
20313138422SDimitry Andricinclude "RISCVSchedRocket32.td"
20413138422SDimitry Andricinclude "RISCVSchedRocket64.td"
2050b57cec5SDimitry Andric
2060b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2070b57cec5SDimitry Andric// RISC-V processors supported.
2080b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2090b57cec5SDimitry Andric
2105ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv32", NoSchedModel, []>;
2110b57cec5SDimitry Andric
2125ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv64", NoSchedModel, [Feature64Bit]>;
2130b57cec5SDimitry Andric
2145ffd83dbSDimitry Andricdef : ProcessorModel<"rocket-rv32", Rocket32Model, []>;
21513138422SDimitry Andric
2165ffd83dbSDimitry Andricdef : ProcessorModel<"rocket-rv64", Rocket64Model, [Feature64Bit]>;
21713138422SDimitry Andric
218*590d96feSDimitry Andricdef : ProcessorModel<"sifive-e31", Rocket32Model, [FeatureStdExtM,
219*590d96feSDimitry Andric                                                   FeatureStdExtA,
220*590d96feSDimitry Andric                                                   FeatureStdExtC]>;
221*590d96feSDimitry Andric
222*590d96feSDimitry Andricdef : ProcessorModel<"sifive-u54", Rocket64Model, [Feature64Bit,
223*590d96feSDimitry Andric                                                   FeatureStdExtM,
224*590d96feSDimitry Andric                                                   FeatureStdExtA,
225*590d96feSDimitry Andric                                                   FeatureStdExtF,
226*590d96feSDimitry Andric                                                   FeatureStdExtD,
227*590d96feSDimitry Andric                                                   FeatureStdExtC]>;
22813138422SDimitry Andric
2290b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2300b57cec5SDimitry Andric// Define the RISC-V target.
2310b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andricdef RISCVInstrInfo : InstrInfo {
2340b57cec5SDimitry Andric  let guessInstructionProperties = 0;
2350b57cec5SDimitry Andric}
2360b57cec5SDimitry Andric
2370b57cec5SDimitry Andricdef RISCVAsmParser : AsmParser {
2380b57cec5SDimitry Andric  let ShouldEmitMatchRegisterAltName = 1;
2390b57cec5SDimitry Andric  let AllowDuplicateRegisterNames = 1;
2400b57cec5SDimitry Andric}
2410b57cec5SDimitry Andric
2420b57cec5SDimitry Andricdef RISCVAsmWriter : AsmWriter {
2430b57cec5SDimitry Andric  int PassSubtarget = 1;
2440b57cec5SDimitry Andric}
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andricdef RISCV : Target {
2470b57cec5SDimitry Andric  let InstructionSet = RISCVInstrInfo;
2480b57cec5SDimitry Andric  let AssemblyParsers = [RISCVAsmParser];
2490b57cec5SDimitry Andric  let AssemblyWriters = [RISCVAsmWriter];
2500b57cec5SDimitry Andric  let AllowRegisterRenaming = 1;
2510b57cec5SDimitry Andric}
252