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()">, 19*5ffd83dbSDimitry 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()">, 26*5ffd83dbSDimitry 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()">, 33*5ffd83dbSDimitry 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()">, 41*5ffd83dbSDimitry 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()">, 48*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtC), 49480093f4SDimitry Andric "'C' (Compressed Instructions)">; 500b57cec5SDimitry Andric 51*5ffd83dbSDimitry Andricdef FeatureExtZbb 52*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbb", "HasStdExtZbb", "true", 53*5ffd83dbSDimitry Andric "'Zbb' (Base 'B' Instructions)">; 54*5ffd83dbSDimitry Andricdef HasStdExtZbb : Predicate<"Subtarget->hasStdExtZbb()">, 55*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbb), 56*5ffd83dbSDimitry Andric "'Zbb' (Base 'B' Instructions)">; 57*5ffd83dbSDimitry Andric 58*5ffd83dbSDimitry Andricdef FeatureExtZbc 59*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbc", "HasStdExtZbc", "true", 60*5ffd83dbSDimitry Andric "'Zbc' (Carry-Less 'B' Instructions)">; 61*5ffd83dbSDimitry Andricdef HasStdExtZbc : Predicate<"Subtarget->hasStdExtZbc()">, 62*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbc), 63*5ffd83dbSDimitry Andric "'Zbc' (Carry-Less 'B' Instructions)">; 64*5ffd83dbSDimitry Andric 65*5ffd83dbSDimitry Andricdef FeatureExtZbe 66*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbe", "HasStdExtZbe", "true", 67*5ffd83dbSDimitry Andric "'Zbe' (Extract-Deposit 'B' Instructions)">; 68*5ffd83dbSDimitry Andricdef HasStdExtZbe : Predicate<"Subtarget->hasStdExtZbe()">, 69*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbe), 70*5ffd83dbSDimitry Andric "'Zbe' (Extract-Deposit 'B' Instructions)">; 71*5ffd83dbSDimitry Andric 72*5ffd83dbSDimitry Andricdef FeatureExtZbf 73*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbf", "HasStdExtZbf", "true", 74*5ffd83dbSDimitry Andric "'Zbf' (Bit-Field 'B' Instructions)">; 75*5ffd83dbSDimitry Andricdef HasStdExtZbf : Predicate<"Subtarget->hasStdExtZbf()">, 76*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbf), 77*5ffd83dbSDimitry Andric "'Zbf' (Bit-Field 'B' Instructions)">; 78*5ffd83dbSDimitry Andric 79*5ffd83dbSDimitry Andricdef FeatureExtZbm 80*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbm", "HasStdExtZbm", "true", 81*5ffd83dbSDimitry Andric "'Zbm' (Matrix 'B' Instructions)">; 82*5ffd83dbSDimitry Andricdef HasStdExtZbm : Predicate<"Subtarget->hasStdExtZbm()">, 83*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbm), 84*5ffd83dbSDimitry Andric "'Zbm' (Matrix 'B' Instructions)">; 85*5ffd83dbSDimitry Andric 86*5ffd83dbSDimitry Andricdef FeatureExtZbp 87*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbp", "HasStdExtZbp", "true", 88*5ffd83dbSDimitry Andric "'Zbp' (Permutation 'B' Instructions)">; 89*5ffd83dbSDimitry Andricdef HasStdExtZbp : Predicate<"Subtarget->hasStdExtZbp()">, 90*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbp), 91*5ffd83dbSDimitry Andric "'Zbp' (Permutation 'B' Instructions)">; 92*5ffd83dbSDimitry Andric 93*5ffd83dbSDimitry Andricdef FeatureExtZbr 94*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbr", "HasStdExtZbr", "true", 95*5ffd83dbSDimitry Andric "'Zbr' (Polynomial Reduction 'B' Instructions)">; 96*5ffd83dbSDimitry Andricdef HasStdExtZbr : Predicate<"Subtarget->hasStdExtZbr()">, 97*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbr), 98*5ffd83dbSDimitry Andric "'Zbr' (Polynomial Reduction 'B' Instructions)">; 99*5ffd83dbSDimitry Andric 100*5ffd83dbSDimitry Andricdef FeatureExtZbs 101*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbs", "HasStdExtZbs", "true", 102*5ffd83dbSDimitry Andric "'Zbs' (Single-Bit 'B' Instructions)">; 103*5ffd83dbSDimitry Andricdef HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">, 104*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbs), 105*5ffd83dbSDimitry Andric "'Zbs' (Single-Bit 'B' Instructions)">; 106*5ffd83dbSDimitry Andric 107*5ffd83dbSDimitry Andricdef FeatureExtZbt 108*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbt", "HasStdExtZbt", "true", 109*5ffd83dbSDimitry Andric "'Zbt' (Ternary 'B' Instructions)">; 110*5ffd83dbSDimitry Andricdef HasStdExtZbt : Predicate<"Subtarget->hasStdExtZbt()">, 111*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbt), 112*5ffd83dbSDimitry Andric "'Zbt' (Ternary 'B' Instructions)">; 113*5ffd83dbSDimitry Andric 114*5ffd83dbSDimitry Andric// Some instructions belong to both the basic and the permutation 115*5ffd83dbSDimitry Andric// subextensions. They should be enabled if either has been specified. 116*5ffd83dbSDimitry Andricdef HasStdExtZbbOrZbp 117*5ffd83dbSDimitry Andric : Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp()">, 118*5ffd83dbSDimitry Andric AssemblerPredicate<(any_of FeatureExtZbb, FeatureExtZbp)>; 119*5ffd83dbSDimitry Andric 120*5ffd83dbSDimitry Andricdef FeatureExtZbproposedc 121*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbproposedc", "HasStdExtZbproposedc", "true", 122*5ffd83dbSDimitry Andric "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 123*5ffd83dbSDimitry Andricdef HasStdExtZbproposedc : Predicate<"Subtarget->hasStdExtZbproposedc()">, 124*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbproposedc), 125*5ffd83dbSDimitry Andric "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 126*5ffd83dbSDimitry Andric 127*5ffd83dbSDimitry Andricdef FeatureStdExtB 128*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-b", "HasStdExtB", "true", 129*5ffd83dbSDimitry Andric "'B' (Bit Manipulation Instructions)", 130*5ffd83dbSDimitry Andric [FeatureExtZbb, 131*5ffd83dbSDimitry Andric FeatureExtZbc, 132*5ffd83dbSDimitry Andric FeatureExtZbe, 133*5ffd83dbSDimitry Andric FeatureExtZbf, 134*5ffd83dbSDimitry Andric FeatureExtZbm, 135*5ffd83dbSDimitry Andric FeatureExtZbp, 136*5ffd83dbSDimitry Andric FeatureExtZbr, 137*5ffd83dbSDimitry Andric FeatureExtZbs, 138*5ffd83dbSDimitry Andric FeatureExtZbt]>; 139*5ffd83dbSDimitry Andricdef HasStdExtB : Predicate<"Subtarget->hasStdExtB()">, 140*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtB), 141*5ffd83dbSDimitry Andric "'B' (Bit Manipulation Instructions)">; 142*5ffd83dbSDimitry Andric 143*5ffd83dbSDimitry Andricdef FeatureNoRVCHints 144*5ffd83dbSDimitry Andric : SubtargetFeature<"no-rvc-hints", "EnableRVCHintInstrs", "false", 145*5ffd83dbSDimitry Andric "Disable RVC Hint Instructions.">; 1468bcb0991SDimitry Andricdef HasRVCHints : Predicate<"Subtarget->enableRVCHintInstrs()">, 147*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of(not FeatureNoRVCHints)), 148480093f4SDimitry Andric "RVC Hint Instructions">; 1490b57cec5SDimitry Andric 150*5ffd83dbSDimitry Andricdef FeatureStdExtV 151*5ffd83dbSDimitry Andric : SubtargetFeature<"experimental-v", "HasStdExtV", "true", 152*5ffd83dbSDimitry Andric "'V' (Vector Instructions)", 153*5ffd83dbSDimitry Andric [FeatureStdExtF]>; 154*5ffd83dbSDimitry Andricdef HasStdExtV : Predicate<"Subtarget->hasStdExtV()">, 155*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtV), 156*5ffd83dbSDimitry Andric "'V' (Vector Instructions)">; 157*5ffd83dbSDimitry Andric 1580b57cec5SDimitry Andricdef Feature64Bit 1590b57cec5SDimitry Andric : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">; 1600b57cec5SDimitry Andricdef IsRV64 : Predicate<"Subtarget->is64Bit()">, 161*5ffd83dbSDimitry Andric AssemblerPredicate<(all_of Feature64Bit), 162480093f4SDimitry Andric "RV64I Base Instruction Set">; 1630b57cec5SDimitry Andricdef IsRV32 : Predicate<"!Subtarget->is64Bit()">, 164*5ffd83dbSDimitry 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()">, 174*5ffd83dbSDimitry 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 185*5ffd83dbSDimitry Andricdef FeatureSaveRestore : SubtargetFeature<"save-restore", "EnableSaveRestore", 186*5ffd83dbSDimitry Andric "true", "Enable save/restore.">; 187*5ffd83dbSDimitry 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 210*5ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv32", NoSchedModel, []>; 2110b57cec5SDimitry Andric 212*5ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv64", NoSchedModel, [Feature64Bit]>; 2130b57cec5SDimitry Andric 214*5ffd83dbSDimitry Andricdef : ProcessorModel<"rocket-rv32", Rocket32Model, []>; 21513138422SDimitry Andric 216*5ffd83dbSDimitry Andricdef : ProcessorModel<"rocket-rv64", Rocket64Model, [Feature64Bit]>; 21713138422SDimitry Andric 21813138422SDimitry Andric 2190b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2200b57cec5SDimitry Andric// Define the RISC-V target. 2210b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andricdef RISCVInstrInfo : InstrInfo { 2240b57cec5SDimitry Andric let guessInstructionProperties = 0; 2250b57cec5SDimitry Andric} 2260b57cec5SDimitry Andric 2270b57cec5SDimitry Andricdef RISCVAsmParser : AsmParser { 2280b57cec5SDimitry Andric let ShouldEmitMatchRegisterAltName = 1; 2290b57cec5SDimitry Andric let AllowDuplicateRegisterNames = 1; 2300b57cec5SDimitry Andric} 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andricdef RISCVAsmWriter : AsmWriter { 2330b57cec5SDimitry Andric int PassSubtarget = 1; 2340b57cec5SDimitry Andric} 2350b57cec5SDimitry Andric 2360b57cec5SDimitry Andricdef RISCV : Target { 2370b57cec5SDimitry Andric let InstructionSet = RISCVInstrInfo; 2380b57cec5SDimitry Andric let AssemblyParsers = [RISCVAsmParser]; 2390b57cec5SDimitry Andric let AssemblyWriters = [RISCVAsmWriter]; 2400b57cec5SDimitry Andric let AllowRegisterRenaming = 1; 2410b57cec5SDimitry Andric} 242