1//===-- RISCV.td - Describe the RISCV Target Machine -------*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9include "llvm/Target/Target.td" 10 11//===----------------------------------------------------------------------===// 12// RISC-V subtarget features and instruction predicates. 13//===----------------------------------------------------------------------===// 14 15def FeatureStdExtM 16 : SubtargetFeature<"m", "HasStdExtM", "true", 17 "'M' (Integer Multiplication and Division)">; 18def HasStdExtM : Predicate<"Subtarget->hasStdExtM()">, 19 AssemblerPredicate<(all_of FeatureStdExtM), 20 "'M' (Integer Multiplication and Division)">; 21 22def FeatureStdExtA 23 : SubtargetFeature<"a", "HasStdExtA", "true", 24 "'A' (Atomic Instructions)">; 25def HasStdExtA : Predicate<"Subtarget->hasStdExtA()">, 26 AssemblerPredicate<(all_of FeatureStdExtA), 27 "'A' (Atomic Instructions)">; 28 29def FeatureStdExtF 30 : SubtargetFeature<"f", "HasStdExtF", "true", 31 "'F' (Single-Precision Floating-Point)">; 32def HasStdExtF : Predicate<"Subtarget->hasStdExtF()">, 33 AssemblerPredicate<(all_of FeatureStdExtF), 34 "'F' (Single-Precision Floating-Point)">; 35 36def FeatureStdExtD 37 : SubtargetFeature<"d", "HasStdExtD", "true", 38 "'D' (Double-Precision Floating-Point)", 39 [FeatureStdExtF]>; 40def HasStdExtD : Predicate<"Subtarget->hasStdExtD()">, 41 AssemblerPredicate<(all_of FeatureStdExtD), 42 "'D' (Double-Precision Floating-Point)">; 43 44def FeatureStdExtC 45 : SubtargetFeature<"c", "HasStdExtC", "true", 46 "'C' (Compressed Instructions)">; 47def HasStdExtC : Predicate<"Subtarget->hasStdExtC()">, 48 AssemblerPredicate<(all_of FeatureStdExtC), 49 "'C' (Compressed Instructions)">; 50 51def FeatureExtZbb 52 : SubtargetFeature<"experimental-zbb", "HasStdExtZbb", "true", 53 "'Zbb' (Base 'B' Instructions)">; 54def HasStdExtZbb : Predicate<"Subtarget->hasStdExtZbb()">, 55 AssemblerPredicate<(all_of FeatureExtZbb), 56 "'Zbb' (Base 'B' Instructions)">; 57 58def FeatureExtZbc 59 : SubtargetFeature<"experimental-zbc", "HasStdExtZbc", "true", 60 "'Zbc' (Carry-Less 'B' Instructions)">; 61def HasStdExtZbc : Predicate<"Subtarget->hasStdExtZbc()">, 62 AssemblerPredicate<(all_of FeatureExtZbc), 63 "'Zbc' (Carry-Less 'B' Instructions)">; 64 65def FeatureExtZbe 66 : SubtargetFeature<"experimental-zbe", "HasStdExtZbe", "true", 67 "'Zbe' (Extract-Deposit 'B' Instructions)">; 68def HasStdExtZbe : Predicate<"Subtarget->hasStdExtZbe()">, 69 AssemblerPredicate<(all_of FeatureExtZbe), 70 "'Zbe' (Extract-Deposit 'B' Instructions)">; 71 72def FeatureExtZbf 73 : SubtargetFeature<"experimental-zbf", "HasStdExtZbf", "true", 74 "'Zbf' (Bit-Field 'B' Instructions)">; 75def HasStdExtZbf : Predicate<"Subtarget->hasStdExtZbf()">, 76 AssemblerPredicate<(all_of FeatureExtZbf), 77 "'Zbf' (Bit-Field 'B' Instructions)">; 78 79def FeatureExtZbm 80 : SubtargetFeature<"experimental-zbm", "HasStdExtZbm", "true", 81 "'Zbm' (Matrix 'B' Instructions)">; 82def HasStdExtZbm : Predicate<"Subtarget->hasStdExtZbm()">, 83 AssemblerPredicate<(all_of FeatureExtZbm), 84 "'Zbm' (Matrix 'B' Instructions)">; 85 86def FeatureExtZbp 87 : SubtargetFeature<"experimental-zbp", "HasStdExtZbp", "true", 88 "'Zbp' (Permutation 'B' Instructions)">; 89def HasStdExtZbp : Predicate<"Subtarget->hasStdExtZbp()">, 90 AssemblerPredicate<(all_of FeatureExtZbp), 91 "'Zbp' (Permutation 'B' Instructions)">; 92 93def FeatureExtZbr 94 : SubtargetFeature<"experimental-zbr", "HasStdExtZbr", "true", 95 "'Zbr' (Polynomial Reduction 'B' Instructions)">; 96def HasStdExtZbr : Predicate<"Subtarget->hasStdExtZbr()">, 97 AssemblerPredicate<(all_of FeatureExtZbr), 98 "'Zbr' (Polynomial Reduction 'B' Instructions)">; 99 100def FeatureExtZbs 101 : SubtargetFeature<"experimental-zbs", "HasStdExtZbs", "true", 102 "'Zbs' (Single-Bit 'B' Instructions)">; 103def HasStdExtZbs : Predicate<"Subtarget->hasStdExtZbs()">, 104 AssemblerPredicate<(all_of FeatureExtZbs), 105 "'Zbs' (Single-Bit 'B' Instructions)">; 106 107def FeatureExtZbt 108 : SubtargetFeature<"experimental-zbt", "HasStdExtZbt", "true", 109 "'Zbt' (Ternary 'B' Instructions)">; 110def HasStdExtZbt : Predicate<"Subtarget->hasStdExtZbt()">, 111 AssemblerPredicate<(all_of FeatureExtZbt), 112 "'Zbt' (Ternary 'B' Instructions)">; 113 114// Some instructions belong to both the basic and the permutation 115// subextensions. They should be enabled if either has been specified. 116def HasStdExtZbbOrZbp 117 : Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp()">, 118 AssemblerPredicate<(any_of FeatureExtZbb, FeatureExtZbp)>; 119 120def FeatureExtZbproposedc 121 : SubtargetFeature<"experimental-zbproposedc", "HasStdExtZbproposedc", "true", 122 "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 123def HasStdExtZbproposedc : Predicate<"Subtarget->hasStdExtZbproposedc()">, 124 AssemblerPredicate<(all_of FeatureExtZbproposedc), 125 "'Zbproposedc' (Proposed Compressed 'B' Instructions)">; 126 127def FeatureStdExtB 128 : SubtargetFeature<"experimental-b", "HasStdExtB", "true", 129 "'B' (Bit Manipulation Instructions)", 130 [FeatureExtZbb, 131 FeatureExtZbc, 132 FeatureExtZbe, 133 FeatureExtZbf, 134 FeatureExtZbm, 135 FeatureExtZbp, 136 FeatureExtZbr, 137 FeatureExtZbs, 138 FeatureExtZbt]>; 139def HasStdExtB : Predicate<"Subtarget->hasStdExtB()">, 140 AssemblerPredicate<(all_of FeatureStdExtB), 141 "'B' (Bit Manipulation Instructions)">; 142 143def FeatureRVCHints 144 : SubtargetFeature<"rvc-hints", "EnableRVCHintInstrs", "true", 145 "Enable RVC Hint Instructions.">; 146def HasRVCHints : Predicate<"Subtarget->enableRVCHintInstrs()">, 147 AssemblerPredicate<(all_of FeatureRVCHints), 148 "RVC Hint Instructions">; 149 150def Feature64Bit 151 : SubtargetFeature<"64bit", "HasRV64", "true", "Implements RV64">; 152def IsRV64 : Predicate<"Subtarget->is64Bit()">, 153 AssemblerPredicate<(all_of Feature64Bit), 154 "RV64I Base Instruction Set">; 155def IsRV32 : Predicate<"!Subtarget->is64Bit()">, 156 AssemblerPredicate<(all_of (not Feature64Bit)), 157 "RV32I Base Instruction Set">; 158 159def RV64 : HwMode<"+64bit">; 160def RV32 : HwMode<"-64bit">; 161 162def FeatureRV32E 163 : SubtargetFeature<"e", "IsRV32E", "true", 164 "Implements RV32E (provides 16 rather than 32 GPRs)">; 165def IsRV32E : Predicate<"Subtarget->isRV32E()">, 166 AssemblerPredicate<(all_of FeatureRV32E)>; 167 168def FeatureRelax 169 : SubtargetFeature<"relax", "EnableLinkerRelax", "true", 170 "Enable Linker relaxation.">; 171 172foreach i = {1-31} in 173 def FeatureReserveX#i : 174 SubtargetFeature<"reserve-x"#i, "UserReservedRegister[RISCV::X"#i#"]", 175 "true", "Reserve X"#i>; 176 177def FeatureSaveRestore : SubtargetFeature<"save-restore", "EnableSaveRestore", 178 "true", "Enable save/restore.">; 179 180//===----------------------------------------------------------------------===// 181// Named operands for CSR instructions. 182//===----------------------------------------------------------------------===// 183 184include "RISCVSystemOperands.td" 185 186//===----------------------------------------------------------------------===// 187// Registers, calling conventions, instruction descriptions. 188//===----------------------------------------------------------------------===// 189 190include "RISCVSchedule.td" 191include "RISCVRegisterInfo.td" 192include "RISCVCallingConv.td" 193include "RISCVInstrInfo.td" 194include "RISCVRegisterBanks.td" 195include "RISCVSchedRocket32.td" 196include "RISCVSchedRocket64.td" 197 198//===----------------------------------------------------------------------===// 199// RISC-V processors supported. 200//===----------------------------------------------------------------------===// 201 202def : ProcessorModel<"generic-rv32", NoSchedModel, [FeatureRVCHints]>; 203 204def : ProcessorModel<"generic-rv64", NoSchedModel, [Feature64Bit, 205 FeatureRVCHints]>; 206 207def : ProcessorModel<"rocket-rv32", Rocket32Model, [FeatureRVCHints]>; 208 209def : ProcessorModel<"rocket-rv64", Rocket64Model, [Feature64Bit, 210 FeatureRVCHints]>; 211 212 213//===----------------------------------------------------------------------===// 214// Define the RISC-V target. 215//===----------------------------------------------------------------------===// 216 217def RISCVInstrInfo : InstrInfo { 218 let guessInstructionProperties = 0; 219} 220 221def RISCVAsmParser : AsmParser { 222 let ShouldEmitMatchRegisterAltName = 1; 223 let AllowDuplicateRegisterNames = 1; 224} 225 226def RISCVAsmWriter : AsmWriter { 227 int PassSubtarget = 1; 228} 229 230def RISCV : Target { 231 let InstructionSet = RISCVInstrInfo; 232 let AssemblyParsers = [RISCVAsmParser]; 233 let AssemblyWriters = [RISCVAsmWriter]; 234 let AllowRegisterRenaming = 1; 235} 236