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 44e8d8bef9SDimitry Andricdef FeatureExtZfh 45e8d8bef9SDimitry Andric : SubtargetFeature<"experimental-zfh", "HasStdExtZfh", "true", 46e8d8bef9SDimitry Andric "'Zfh' (Half-Precision Floating-Point)", 47e8d8bef9SDimitry Andric [FeatureStdExtF]>; 48e8d8bef9SDimitry Andricdef HasStdExtZfh : Predicate<"Subtarget->hasStdExtZfh()">, 49e8d8bef9SDimitry Andric AssemblerPredicate<(all_of FeatureExtZfh), 50e8d8bef9SDimitry Andric "'Zfh' (Half-Precision Floating-Point)">; 51e8d8bef9SDimitry Andric 520b57cec5SDimitry Andricdef FeatureStdExtC 530b57cec5SDimitry Andric : SubtargetFeature<"c", "HasStdExtC", "true", 540b57cec5SDimitry Andric "'C' (Compressed Instructions)">; 550b57cec5SDimitry Andricdef HasStdExtC : Predicate<"Subtarget->hasStdExtC()">, 565ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtC), 57480093f4SDimitry Andric "'C' (Compressed Instructions)">; 580b57cec5SDimitry Andric 59e8d8bef9SDimitry Andricdef FeatureExtZba 60e8d8bef9SDimitry Andric : SubtargetFeature<"experimental-zba", "HasStdExtZba", "true", 61e8d8bef9SDimitry Andric "'Zba' (Address calculation 'B' Instructions)">; 62e8d8bef9SDimitry Andricdef HasStdExtZba : Predicate<"Subtarget->hasStdExtZba()">, 63e8d8bef9SDimitry Andric AssemblerPredicate<(all_of FeatureExtZba), 64e8d8bef9SDimitry Andric "'Zba' (Address calculation 'B' Instructions)">; 65e8d8bef9SDimitry Andricdef NotHasStdExtZba : Predicate<"!Subtarget->hasStdExtZba()">; 66e8d8bef9SDimitry Andric 675ffd83dbSDimitry Andricdef FeatureExtZbb 685ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbb", "HasStdExtZbb", "true", 695ffd83dbSDimitry Andric "'Zbb' (Base 'B' Instructions)">; 705ffd83dbSDimitry Andricdef HasStdExtZbb : Predicate<"Subtarget->hasStdExtZbb()">, 715ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbb), 725ffd83dbSDimitry Andric "'Zbb' (Base 'B' Instructions)">; 735ffd83dbSDimitry Andric 745ffd83dbSDimitry Andricdef FeatureExtZbc 755ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbc", "HasStdExtZbc", "true", 765ffd83dbSDimitry Andric "'Zbc' (Carry-Less 'B' Instructions)">; 775ffd83dbSDimitry Andricdef HasStdExtZbc : Predicate<"Subtarget->hasStdExtZbc()">, 785ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbc), 795ffd83dbSDimitry Andric "'Zbc' (Carry-Less 'B' Instructions)">; 805ffd83dbSDimitry Andric 815ffd83dbSDimitry Andricdef FeatureExtZbe 825ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbe", "HasStdExtZbe", "true", 835ffd83dbSDimitry Andric "'Zbe' (Extract-Deposit 'B' Instructions)">; 845ffd83dbSDimitry Andricdef HasStdExtZbe : Predicate<"Subtarget->hasStdExtZbe()">, 855ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbe), 865ffd83dbSDimitry Andric "'Zbe' (Extract-Deposit 'B' Instructions)">; 875ffd83dbSDimitry Andric 885ffd83dbSDimitry Andricdef FeatureExtZbf 895ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbf", "HasStdExtZbf", "true", 905ffd83dbSDimitry Andric "'Zbf' (Bit-Field 'B' Instructions)">; 915ffd83dbSDimitry Andricdef HasStdExtZbf : Predicate<"Subtarget->hasStdExtZbf()">, 925ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbf), 935ffd83dbSDimitry Andric "'Zbf' (Bit-Field 'B' Instructions)">; 945ffd83dbSDimitry Andric 955ffd83dbSDimitry Andricdef FeatureExtZbm 965ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbm", "HasStdExtZbm", "true", 975ffd83dbSDimitry Andric "'Zbm' (Matrix 'B' Instructions)">; 985ffd83dbSDimitry Andricdef HasStdExtZbm : Predicate<"Subtarget->hasStdExtZbm()">, 995ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbm), 1005ffd83dbSDimitry Andric "'Zbm' (Matrix 'B' Instructions)">; 1015ffd83dbSDimitry Andric 1025ffd83dbSDimitry Andricdef FeatureExtZbp 1035ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbp", "HasStdExtZbp", "true", 1045ffd83dbSDimitry Andric "'Zbp' (Permutation 'B' Instructions)">; 1055ffd83dbSDimitry Andricdef HasStdExtZbp : Predicate<"Subtarget->hasStdExtZbp()">, 1065ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbp), 1075ffd83dbSDimitry Andric "'Zbp' (Permutation 'B' Instructions)">; 1085ffd83dbSDimitry Andric 1095ffd83dbSDimitry Andricdef FeatureExtZbr 1105ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbr", "HasStdExtZbr", "true", 1115ffd83dbSDimitry Andric "'Zbr' (Polynomial Reduction 'B' Instructions)">; 1125ffd83dbSDimitry Andricdef HasStdExtZbr : Predicate<"Subtarget->hasStdExtZbr()">, 1135ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbr), 1145ffd83dbSDimitry Andric "'Zbr' (Polynomial Reduction 'B' Instructions)">; 1155ffd83dbSDimitry Andric 1165ffd83dbSDimitry Andricdef FeatureExtZbs 1175ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbs", "HasStdExtZbs", "true", 1185ffd83dbSDimitry Andric "'Zbs' (Single-Bit 'B' Instructions)">; 1195ffd83dbSDimitry Andricdef HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">, 1205ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbs), 1215ffd83dbSDimitry Andric "'Zbs' (Single-Bit 'B' Instructions)">; 1225ffd83dbSDimitry Andric 1235ffd83dbSDimitry Andricdef FeatureExtZbt 1245ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbt", "HasStdExtZbt", "true", 1255ffd83dbSDimitry Andric "'Zbt' (Ternary 'B' Instructions)">; 1265ffd83dbSDimitry Andricdef HasStdExtZbt : Predicate<"Subtarget->hasStdExtZbt()">, 1275ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbt), 1285ffd83dbSDimitry Andric "'Zbt' (Ternary 'B' Instructions)">; 1295ffd83dbSDimitry Andric 1305ffd83dbSDimitry Andric// Some instructions belong to both the basic and the permutation 1315ffd83dbSDimitry Andric// subextensions. They should be enabled if either has been specified. 1325ffd83dbSDimitry Andricdef HasStdExtZbbOrZbp 1335ffd83dbSDimitry Andric : Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp()">, 134e8d8bef9SDimitry Andric AssemblerPredicate<(any_of FeatureExtZbb, FeatureExtZbp), 135e8d8bef9SDimitry Andric "'Zbb' (Base 'B' Instructions) or " 136e8d8bef9SDimitry Andric "'Zbp' (Permutation 'B' Instructions)">; 1375ffd83dbSDimitry Andric 1385ffd83dbSDimitry Andricdef FeatureExtZbproposedc 1395ffd83dbSDimitry Andric : SubtargetFeature<"experimental-zbproposedc", "HasStdExtZbproposedc", "true", 1405ffd83dbSDimitry Andric "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 1415ffd83dbSDimitry Andricdef HasStdExtZbproposedc : Predicate<"Subtarget->hasStdExtZbproposedc()">, 1425ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureExtZbproposedc), 1435ffd83dbSDimitry Andric "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 1445ffd83dbSDimitry Andric 1455ffd83dbSDimitry Andricdef FeatureStdExtB 1465ffd83dbSDimitry Andric : SubtargetFeature<"experimental-b", "HasStdExtB", "true", 1475ffd83dbSDimitry Andric "'B' (Bit Manipulation Instructions)", 148e8d8bef9SDimitry Andric [FeatureExtZba, 149e8d8bef9SDimitry Andric FeatureExtZbb, 1505ffd83dbSDimitry Andric FeatureExtZbc, 1515ffd83dbSDimitry Andric FeatureExtZbe, 1525ffd83dbSDimitry Andric FeatureExtZbf, 1535ffd83dbSDimitry Andric FeatureExtZbm, 1545ffd83dbSDimitry Andric FeatureExtZbp, 1555ffd83dbSDimitry Andric FeatureExtZbr, 1565ffd83dbSDimitry Andric FeatureExtZbs, 1575ffd83dbSDimitry Andric FeatureExtZbt]>; 1585ffd83dbSDimitry Andricdef HasStdExtB : Predicate<"Subtarget->hasStdExtB()">, 1595ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtB), 1605ffd83dbSDimitry Andric "'B' (Bit Manipulation Instructions)">; 1615ffd83dbSDimitry Andric 1625ffd83dbSDimitry Andricdef FeatureNoRVCHints 1635ffd83dbSDimitry Andric : SubtargetFeature<"no-rvc-hints", "EnableRVCHintInstrs", "false", 1645ffd83dbSDimitry Andric "Disable RVC Hint Instructions.">; 1658bcb0991SDimitry Andricdef HasRVCHints : Predicate<"Subtarget->enableRVCHintInstrs()">, 1665ffd83dbSDimitry Andric AssemblerPredicate<(all_of(not FeatureNoRVCHints)), 167480093f4SDimitry Andric "RVC Hint Instructions">; 1680b57cec5SDimitry Andric 1695ffd83dbSDimitry Andricdef FeatureStdExtV 1705ffd83dbSDimitry Andric : SubtargetFeature<"experimental-v", "HasStdExtV", "true", 171e8d8bef9SDimitry Andric "'V' (Vector Instructions)">; 1725ffd83dbSDimitry Andricdef HasStdExtV : Predicate<"Subtarget->hasStdExtV()">, 1735ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureStdExtV), 1745ffd83dbSDimitry Andric "'V' (Vector Instructions)">; 1755ffd83dbSDimitry Andric 176e8d8bef9SDimitry Andricdef FeatureStdExtZvlsseg 177e8d8bef9SDimitry Andric : SubtargetFeature<"experimental-zvlsseg", "HasStdExtZvlsseg", "true", 178e8d8bef9SDimitry Andric "'Zvlsseg' (Vector segment load/store instructions)", 179e8d8bef9SDimitry Andric [FeatureStdExtV]>; 180e8d8bef9SDimitry Andricdef HasStdExtZvlsseg : Predicate<"Subtarget->hasStdExtZvlsseg()">, 181e8d8bef9SDimitry Andric AssemblerPredicate<(all_of FeatureStdExtZvlsseg), 182e8d8bef9SDimitry Andric "'Zvlsseg' (Vector segment load/store instructions)">; 183*fe6060f1SDimitry Andric 184e8d8bef9SDimitry Andricdef FeatureExtZvamo 185e8d8bef9SDimitry Andric : SubtargetFeature<"experimental-zvamo", "HasStdExtZvamo", "true", 186e8d8bef9SDimitry Andric "'Zvamo' (Vector AMO Operations)", 187e8d8bef9SDimitry Andric [FeatureStdExtV]>; 188e8d8bef9SDimitry Andricdef HasStdExtZvamo : Predicate<"Subtarget->hasStdExtZvamo()">, 189e8d8bef9SDimitry Andric AssemblerPredicate<(all_of FeatureExtZvamo), 190e8d8bef9SDimitry Andric "'Zvamo' (Vector AMO Operations)">; 191e8d8bef9SDimitry Andric 1920b57cec5SDimitry Andricdef Feature64Bit 1930b57cec5SDimitry Andric : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">; 1940b57cec5SDimitry Andricdef IsRV64 : Predicate<"Subtarget->is64Bit()">, 1955ffd83dbSDimitry Andric AssemblerPredicate<(all_of Feature64Bit), 196480093f4SDimitry Andric "RV64I Base Instruction Set">; 1970b57cec5SDimitry Andricdef IsRV32 : Predicate<"!Subtarget->is64Bit()">, 1985ffd83dbSDimitry Andric AssemblerPredicate<(all_of (not Feature64Bit)), 199480093f4SDimitry Andric "RV32I Base Instruction Set">; 2000b57cec5SDimitry Andric 201e8d8bef9SDimitry Andricdefvar RV32 = DefaultMode; 2020b57cec5SDimitry Andricdef RV64 : HwMode<"+64bit">; 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andricdef FeatureRV32E 2050b57cec5SDimitry Andric : SubtargetFeature<"e", "IsRV32E", "true", 2060b57cec5SDimitry Andric "Implements RV32E (provides 16 rather than 32 GPRs)">; 2070b57cec5SDimitry Andricdef IsRV32E : Predicate<"Subtarget->isRV32E()">, 2085ffd83dbSDimitry Andric AssemblerPredicate<(all_of FeatureRV32E)>; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andricdef FeatureRelax 2110b57cec5SDimitry Andric : SubtargetFeature<"relax", "EnableLinkerRelax", "true", 2120b57cec5SDimitry Andric "Enable Linker relaxation.">; 2130b57cec5SDimitry Andric 214480093f4SDimitry Andricforeach i = {1-31} in 215480093f4SDimitry Andric def FeatureReserveX#i : 216480093f4SDimitry Andric SubtargetFeature<"reserve-x"#i, "UserReservedRegister[RISCV::X"#i#"]", 217480093f4SDimitry Andric "true", "Reserve X"#i>; 218480093f4SDimitry Andric 2195ffd83dbSDimitry Andricdef FeatureSaveRestore : SubtargetFeature<"save-restore", "EnableSaveRestore", 2205ffd83dbSDimitry Andric "true", "Enable save/restore.">; 2215ffd83dbSDimitry Andric 2220b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2230b57cec5SDimitry Andric// Named operands for CSR instructions. 2240b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andricinclude "RISCVSystemOperands.td" 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2290b57cec5SDimitry Andric// Registers, calling conventions, instruction descriptions. 2300b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2310b57cec5SDimitry Andric 23213138422SDimitry Andricinclude "RISCVSchedule.td" 2330b57cec5SDimitry Andricinclude "RISCVRegisterInfo.td" 2340b57cec5SDimitry Andricinclude "RISCVCallingConv.td" 2350b57cec5SDimitry Andricinclude "RISCVInstrInfo.td" 2368bcb0991SDimitry Andricinclude "RISCVRegisterBanks.td" 237e8d8bef9SDimitry Andricinclude "RISCVSchedRocket.td" 238e8d8bef9SDimitry Andricinclude "RISCVSchedSiFive7.td" 2390b57cec5SDimitry Andric 2400b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2410b57cec5SDimitry Andric// RISC-V processors supported. 2420b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2430b57cec5SDimitry Andric 2445ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv32", NoSchedModel, []>; 2455ffd83dbSDimitry Andricdef : ProcessorModel<"generic-rv64", NoSchedModel, [Feature64Bit]>; 2460b57cec5SDimitry Andric 247e8d8bef9SDimitry Andricdef : ProcessorModel<"rocket-rv32", RocketModel, []>; 248e8d8bef9SDimitry Andricdef : ProcessorModel<"rocket-rv64", RocketModel, [Feature64Bit]>; 24913138422SDimitry Andric 250e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-7-rv32", SiFive7Model, []>; 251e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-7-rv64", SiFive7Model, [Feature64Bit]>; 25213138422SDimitry Andric 253e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-e31", RocketModel, [FeatureStdExtM, 254590d96feSDimitry Andric FeatureStdExtA, 255590d96feSDimitry Andric FeatureStdExtC]>; 256590d96feSDimitry Andric 257e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-u54", RocketModel, [Feature64Bit, 258e8d8bef9SDimitry Andric FeatureStdExtM, 259e8d8bef9SDimitry Andric FeatureStdExtA, 260e8d8bef9SDimitry Andric FeatureStdExtF, 261e8d8bef9SDimitry Andric FeatureStdExtD, 262e8d8bef9SDimitry Andric FeatureStdExtC]>; 263e8d8bef9SDimitry Andric 264e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-e76", SiFive7Model, [FeatureStdExtM, 265e8d8bef9SDimitry Andric FeatureStdExtA, 266e8d8bef9SDimitry Andric FeatureStdExtF, 267e8d8bef9SDimitry Andric FeatureStdExtC]>; 268e8d8bef9SDimitry Andric 269e8d8bef9SDimitry Andricdef : ProcessorModel<"sifive-u74", SiFive7Model, [Feature64Bit, 270590d96feSDimitry Andric FeatureStdExtM, 271590d96feSDimitry Andric FeatureStdExtA, 272590d96feSDimitry Andric FeatureStdExtF, 273590d96feSDimitry Andric FeatureStdExtD, 274590d96feSDimitry Andric FeatureStdExtC]>; 27513138422SDimitry Andric 2760b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2770b57cec5SDimitry Andric// Define the RISC-V target. 2780b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 2790b57cec5SDimitry Andric 2800b57cec5SDimitry Andricdef RISCVInstrInfo : InstrInfo { 2810b57cec5SDimitry Andric let guessInstructionProperties = 0; 2820b57cec5SDimitry Andric} 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andricdef RISCVAsmParser : AsmParser { 2850b57cec5SDimitry Andric let ShouldEmitMatchRegisterAltName = 1; 2860b57cec5SDimitry Andric let AllowDuplicateRegisterNames = 1; 2870b57cec5SDimitry Andric} 2880b57cec5SDimitry Andric 2890b57cec5SDimitry Andricdef RISCVAsmWriter : AsmWriter { 2900b57cec5SDimitry Andric int PassSubtarget = 1; 2910b57cec5SDimitry Andric} 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andricdef RISCV : Target { 2940b57cec5SDimitry Andric let InstructionSet = RISCVInstrInfo; 2950b57cec5SDimitry Andric let AssemblyParsers = [RISCVAsmParser]; 2960b57cec5SDimitry Andric let AssemblyWriters = [RISCVAsmWriter]; 2970b57cec5SDimitry Andric let AllowRegisterRenaming = 1; 2980b57cec5SDimitry Andric} 299