1 //===-- RISCVBaseInfo.h - Top level definitions for RISC-V MC ---*- C++ -*-===// 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 // 9 // This file contains small standalone enum definitions for the RISC-V target 10 // useful for the compiler back-end and the MC libraries. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H 14 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H 15 16 #include "MCTargetDesc/RISCVMCTargetDesc.h" 17 #include "llvm/ADT/APFloat.h" 18 #include "llvm/ADT/APInt.h" 19 #include "llvm/ADT/StringRef.h" 20 #include "llvm/ADT/StringSwitch.h" 21 #include "llvm/MC/MCInstrDesc.h" 22 #include "llvm/Support/RISCVISAInfo.h" 23 #include "llvm/TargetParser/SubtargetFeature.h" 24 25 namespace llvm { 26 27 // RISCVII - This namespace holds all of the target specific flags that 28 // instruction info tracks. All definitions must match RISCVInstrFormats.td. 29 namespace RISCVII { 30 enum { 31 InstFormatPseudo = 0, 32 InstFormatR = 1, 33 InstFormatR4 = 2, 34 InstFormatI = 3, 35 InstFormatS = 4, 36 InstFormatB = 5, 37 InstFormatU = 6, 38 InstFormatJ = 7, 39 InstFormatCR = 8, 40 InstFormatCI = 9, 41 InstFormatCSS = 10, 42 InstFormatCIW = 11, 43 InstFormatCL = 12, 44 InstFormatCS = 13, 45 InstFormatCA = 14, 46 InstFormatCB = 15, 47 InstFormatCJ = 16, 48 InstFormatCU = 17, 49 InstFormatCLB = 18, 50 InstFormatCLH = 19, 51 InstFormatCSB = 20, 52 InstFormatCSH = 21, 53 InstFormatOther = 22, 54 55 InstFormatMask = 31, 56 InstFormatShift = 0, 57 58 ConstraintShift = InstFormatShift + 5, 59 VS2Constraint = 0b001 << ConstraintShift, 60 VS1Constraint = 0b010 << ConstraintShift, 61 VMConstraint = 0b100 << ConstraintShift, 62 ConstraintMask = 0b111 << ConstraintShift, 63 64 VLMulShift = ConstraintShift + 3, 65 VLMulMask = 0b111 << VLMulShift, 66 67 // Force a tail agnostic policy even this instruction has a tied destination. 68 ForceTailAgnosticShift = VLMulShift + 3, 69 ForceTailAgnosticMask = 1 << ForceTailAgnosticShift, 70 71 // Is this a _TIED vector pseudo instruction. For these instructions we 72 // shouldn't skip the tied operand when converting to MC instructions. 73 IsTiedPseudoShift = ForceTailAgnosticShift + 1, 74 IsTiedPseudoMask = 1 << IsTiedPseudoShift, 75 76 // Does this instruction have a SEW operand. It will be the last explicit 77 // operand unless there is a vector policy operand. Used by RVV Pseudos. 78 HasSEWOpShift = IsTiedPseudoShift + 1, 79 HasSEWOpMask = 1 << HasSEWOpShift, 80 81 // Does this instruction have a VL operand. It will be the second to last 82 // explicit operand unless there is a vector policy operand. Used by RVV 83 // Pseudos. 84 HasVLOpShift = HasSEWOpShift + 1, 85 HasVLOpMask = 1 << HasVLOpShift, 86 87 // Does this instruction have a vector policy operand. It will be the last 88 // explicit operand. Used by RVV Pseudos. 89 HasVecPolicyOpShift = HasVLOpShift + 1, 90 HasVecPolicyOpMask = 1 << HasVecPolicyOpShift, 91 92 // Is this instruction a vector widening reduction instruction. Used by RVV 93 // Pseudos. 94 IsRVVWideningReductionShift = HasVecPolicyOpShift + 1, 95 IsRVVWideningReductionMask = 1 << IsRVVWideningReductionShift, 96 97 // Does this instruction care about mask policy. If it is not, the mask policy 98 // could be either agnostic or undisturbed. For example, unmasked, store, and 99 // reduction operations result would not be affected by mask policy, so 100 // compiler has free to select either one. 101 UsesMaskPolicyShift = IsRVVWideningReductionShift + 1, 102 UsesMaskPolicyMask = 1 << UsesMaskPolicyShift, 103 104 // Indicates that the result can be considered sign extended from bit 31. Some 105 // instructions with this flag aren't W instructions, but are either sign 106 // extended from a smaller size, always outputs a small integer, or put zeros 107 // in bits 63:31. Used by the SExtWRemoval pass. 108 IsSignExtendingOpWShift = UsesMaskPolicyShift + 1, 109 IsSignExtendingOpWMask = 1ULL << IsSignExtendingOpWShift, 110 111 HasRoundModeOpShift = IsSignExtendingOpWShift + 1, 112 HasRoundModeOpMask = 1 << HasRoundModeOpShift, 113 114 UsesVXRMShift = HasRoundModeOpShift + 1, 115 UsesVXRMMask = 1 << UsesVXRMShift, 116 117 // Indicates whether these instructions can partially overlap between source 118 // registers and destination registers according to the vector spec. 119 // 0 -> not a vector pseudo 120 // 1 -> default value for vector pseudos. not widening or narrowing. 121 // 2 -> narrowing case 122 // 3 -> widening case 123 TargetOverlapConstraintTypeShift = UsesVXRMShift + 1, 124 TargetOverlapConstraintTypeMask = 3ULL << TargetOverlapConstraintTypeShift, 125 }; 126 127 enum VLMUL : uint8_t { 128 LMUL_1 = 0, 129 LMUL_2, 130 LMUL_4, 131 LMUL_8, 132 LMUL_RESERVED, 133 LMUL_F8, 134 LMUL_F4, 135 LMUL_F2 136 }; 137 138 enum { 139 TAIL_UNDISTURBED_MASK_UNDISTURBED = 0, 140 TAIL_AGNOSTIC = 1, 141 MASK_AGNOSTIC = 2, 142 }; 143 144 // Helper functions to read TSFlags. 145 /// \returns the format of the instruction. 146 static inline unsigned getFormat(uint64_t TSFlags) { 147 return (TSFlags & InstFormatMask) >> InstFormatShift; 148 } 149 /// \returns the LMUL for the instruction. 150 static inline VLMUL getLMul(uint64_t TSFlags) { 151 return static_cast<VLMUL>((TSFlags & VLMulMask) >> VLMulShift); 152 } 153 /// \returns true if tail agnostic is enforced for the instruction. 154 static inline bool doesForceTailAgnostic(uint64_t TSFlags) { 155 return TSFlags & ForceTailAgnosticMask; 156 } 157 /// \returns true if this a _TIED pseudo. 158 static inline bool isTiedPseudo(uint64_t TSFlags) { 159 return TSFlags & IsTiedPseudoMask; 160 } 161 /// \returns true if there is a SEW operand for the instruction. 162 static inline bool hasSEWOp(uint64_t TSFlags) { 163 return TSFlags & HasSEWOpMask; 164 } 165 /// \returns true if there is a VL operand for the instruction. 166 static inline bool hasVLOp(uint64_t TSFlags) { 167 return TSFlags & HasVLOpMask; 168 } 169 /// \returns true if there is a vector policy operand for this instruction. 170 static inline bool hasVecPolicyOp(uint64_t TSFlags) { 171 return TSFlags & HasVecPolicyOpMask; 172 } 173 /// \returns true if it is a vector widening reduction instruction. 174 static inline bool isRVVWideningReduction(uint64_t TSFlags) { 175 return TSFlags & IsRVVWideningReductionMask; 176 } 177 /// \returns true if mask policy is valid for the instruction. 178 static inline bool usesMaskPolicy(uint64_t TSFlags) { 179 return TSFlags & UsesMaskPolicyMask; 180 } 181 182 /// \returns true if there is a rounding mode operand for this instruction 183 static inline bool hasRoundModeOp(uint64_t TSFlags) { 184 return TSFlags & HasRoundModeOpMask; 185 } 186 187 /// \returns true if this instruction uses vxrm 188 static inline bool usesVXRM(uint64_t TSFlags) { return TSFlags & UsesVXRMMask; } 189 190 static inline unsigned getVLOpNum(const MCInstrDesc &Desc) { 191 const uint64_t TSFlags = Desc.TSFlags; 192 // This method is only called if we expect to have a VL operand, and all 193 // instructions with VL also have SEW. 194 assert(hasSEWOp(TSFlags) && hasVLOp(TSFlags)); 195 unsigned Offset = 2; 196 if (hasVecPolicyOp(TSFlags)) 197 Offset = 3; 198 return Desc.getNumOperands() - Offset; 199 } 200 201 static inline unsigned getSEWOpNum(const MCInstrDesc &Desc) { 202 const uint64_t TSFlags = Desc.TSFlags; 203 assert(hasSEWOp(TSFlags)); 204 unsigned Offset = 1; 205 if (hasVecPolicyOp(TSFlags)) 206 Offset = 2; 207 return Desc.getNumOperands() - Offset; 208 } 209 210 static inline unsigned getVecPolicyOpNum(const MCInstrDesc &Desc) { 211 assert(hasVecPolicyOp(Desc.TSFlags)); 212 return Desc.getNumOperands() - 1; 213 } 214 215 /// \returns the index to the rounding mode immediate value if any, otherwise 216 /// returns -1. 217 static inline int getFRMOpNum(const MCInstrDesc &Desc) { 218 const uint64_t TSFlags = Desc.TSFlags; 219 if (!hasRoundModeOp(TSFlags) || usesVXRM(TSFlags)) 220 return -1; 221 222 // The operand order 223 // -------------------------------------- 224 // | n-1 (if any) | n-2 | n-3 | n-4 | 225 // | policy | sew | vl | frm | 226 // -------------------------------------- 227 return getVLOpNum(Desc) - 1; 228 } 229 230 /// \returns the index to the rounding mode immediate value if any, otherwise 231 /// returns -1. 232 static inline int getVXRMOpNum(const MCInstrDesc &Desc) { 233 const uint64_t TSFlags = Desc.TSFlags; 234 if (!hasRoundModeOp(TSFlags) || !usesVXRM(TSFlags)) 235 return -1; 236 // The operand order 237 // -------------------------------------- 238 // | n-1 (if any) | n-2 | n-3 | n-4 | 239 // | policy | sew | vl | vxrm | 240 // -------------------------------------- 241 return getVLOpNum(Desc) - 1; 242 } 243 244 // Is the first def operand tied to the first use operand. This is true for 245 // vector pseudo instructions that have a merge operand for tail/mask 246 // undisturbed. It's also true for vector FMA instructions where one of the 247 // operands is also the destination register. 248 static inline bool isFirstDefTiedToFirstUse(const MCInstrDesc &Desc) { 249 return Desc.getNumDefs() < Desc.getNumOperands() && 250 Desc.getOperandConstraint(Desc.getNumDefs(), MCOI::TIED_TO) == 0; 251 } 252 253 // RISC-V Specific Machine Operand Flags 254 enum { 255 MO_None = 0, 256 MO_CALL = 1, 257 MO_LO = 3, 258 MO_HI = 4, 259 MO_PCREL_LO = 5, 260 MO_PCREL_HI = 6, 261 MO_GOT_HI = 7, 262 MO_TPREL_LO = 8, 263 MO_TPREL_HI = 9, 264 MO_TPREL_ADD = 10, 265 MO_TLS_GOT_HI = 11, 266 MO_TLS_GD_HI = 12, 267 268 // Used to differentiate between target-specific "direct" flags and "bitmask" 269 // flags. A machine operand can only have one "direct" flag, but can have 270 // multiple "bitmask" flags. 271 MO_DIRECT_FLAG_MASK = 15 272 }; 273 } // namespace RISCVII 274 275 namespace RISCVOp { 276 enum OperandType : unsigned { 277 OPERAND_FIRST_RISCV_IMM = MCOI::OPERAND_FIRST_TARGET, 278 OPERAND_UIMM1 = OPERAND_FIRST_RISCV_IMM, 279 OPERAND_UIMM2, 280 OPERAND_UIMM2_LSB0, 281 OPERAND_UIMM3, 282 OPERAND_UIMM4, 283 OPERAND_UIMM5, 284 OPERAND_UIMM6, 285 OPERAND_UIMM7, 286 OPERAND_UIMM7_LSB00, 287 OPERAND_UIMM8_LSB00, 288 OPERAND_UIMM8, 289 OPERAND_UIMM8_LSB000, 290 OPERAND_UIMM8_GE32, 291 OPERAND_UIMM9_LSB000, 292 OPERAND_UIMM10_LSB00_NONZERO, 293 OPERAND_UIMM12, 294 OPERAND_ZERO, 295 OPERAND_SIMM5, 296 OPERAND_SIMM5_PLUS1, 297 OPERAND_SIMM6, 298 OPERAND_SIMM6_NONZERO, 299 OPERAND_SIMM10_LSB0000_NONZERO, 300 OPERAND_SIMM12, 301 OPERAND_SIMM12_LSB00000, 302 OPERAND_UIMM20, 303 OPERAND_UIMMLOG2XLEN, 304 OPERAND_UIMMLOG2XLEN_NONZERO, 305 OPERAND_CLUI_IMM, 306 OPERAND_VTYPEI10, 307 OPERAND_VTYPEI11, 308 OPERAND_RVKRNUM, 309 OPERAND_RVKRNUM_0_7, 310 OPERAND_RVKRNUM_1_10, 311 OPERAND_RVKRNUM_2_14, 312 OPERAND_LAST_RISCV_IMM = OPERAND_RVKRNUM_2_14, 313 // Operand is either a register or uimm5, this is used by V extension pseudo 314 // instructions to represent a value that be passed as AVL to either vsetvli 315 // or vsetivli. 316 OPERAND_AVL, 317 }; 318 } // namespace RISCVOp 319 320 // Describes the predecessor/successor bits used in the FENCE instruction. 321 namespace RISCVFenceField { 322 enum FenceField { 323 I = 8, 324 O = 4, 325 R = 2, 326 W = 1 327 }; 328 } 329 330 // Describes the supported floating point rounding mode encodings. 331 namespace RISCVFPRndMode { 332 enum RoundingMode { 333 RNE = 0, 334 RTZ = 1, 335 RDN = 2, 336 RUP = 3, 337 RMM = 4, 338 DYN = 7, 339 Invalid 340 }; 341 342 inline static StringRef roundingModeToString(RoundingMode RndMode) { 343 switch (RndMode) { 344 default: 345 llvm_unreachable("Unknown floating point rounding mode"); 346 case RISCVFPRndMode::RNE: 347 return "rne"; 348 case RISCVFPRndMode::RTZ: 349 return "rtz"; 350 case RISCVFPRndMode::RDN: 351 return "rdn"; 352 case RISCVFPRndMode::RUP: 353 return "rup"; 354 case RISCVFPRndMode::RMM: 355 return "rmm"; 356 case RISCVFPRndMode::DYN: 357 return "dyn"; 358 } 359 } 360 361 inline static RoundingMode stringToRoundingMode(StringRef Str) { 362 return StringSwitch<RoundingMode>(Str) 363 .Case("rne", RISCVFPRndMode::RNE) 364 .Case("rtz", RISCVFPRndMode::RTZ) 365 .Case("rdn", RISCVFPRndMode::RDN) 366 .Case("rup", RISCVFPRndMode::RUP) 367 .Case("rmm", RISCVFPRndMode::RMM) 368 .Case("dyn", RISCVFPRndMode::DYN) 369 .Default(RISCVFPRndMode::Invalid); 370 } 371 372 inline static bool isValidRoundingMode(unsigned Mode) { 373 switch (Mode) { 374 default: 375 return false; 376 case RISCVFPRndMode::RNE: 377 case RISCVFPRndMode::RTZ: 378 case RISCVFPRndMode::RDN: 379 case RISCVFPRndMode::RUP: 380 case RISCVFPRndMode::RMM: 381 case RISCVFPRndMode::DYN: 382 return true; 383 } 384 } 385 } // namespace RISCVFPRndMode 386 387 //===----------------------------------------------------------------------===// 388 // Floating-point Immediates 389 // 390 391 namespace RISCVLoadFPImm { 392 float getFPImm(unsigned Imm); 393 394 /// getLoadFPImm - Return a 5-bit binary encoding of the floating-point 395 /// immediate value. If the value cannot be represented as a 5-bit binary 396 /// encoding, then return -1. 397 int getLoadFPImm(APFloat FPImm); 398 } // namespace RISCVLoadFPImm 399 400 namespace RISCVSysReg { 401 struct SysReg { 402 const char *Name; 403 const char *AltName; 404 const char *DeprecatedName; 405 unsigned Encoding; 406 // FIXME: add these additional fields when needed. 407 // Privilege Access: Read, Write, Read-Only. 408 // unsigned ReadWrite; 409 // Privilege Mode: User, System or Machine. 410 // unsigned Mode; 411 // Check field name. 412 // unsigned Extra; 413 // Register number without the privilege bits. 414 // unsigned Number; 415 FeatureBitset FeaturesRequired; 416 bool isRV32Only; 417 418 bool haveRequiredFeatures(const FeatureBitset &ActiveFeatures) const { 419 // Not in 32-bit mode. 420 if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit]) 421 return false; 422 // No required feature associated with the system register. 423 if (FeaturesRequired.none()) 424 return true; 425 return (FeaturesRequired & ActiveFeatures) == FeaturesRequired; 426 } 427 }; 428 429 #define GET_SysRegsList_DECL 430 #include "RISCVGenSearchableTables.inc" 431 } // end namespace RISCVSysReg 432 433 namespace RISCVInsnOpcode { 434 struct RISCVOpcode { 435 const char *Name; 436 unsigned Value; 437 }; 438 439 #define GET_RISCVOpcodesList_DECL 440 #include "RISCVGenSearchableTables.inc" 441 } // end namespace RISCVInsnOpcode 442 443 namespace RISCVABI { 444 445 enum ABI { 446 ABI_ILP32, 447 ABI_ILP32F, 448 ABI_ILP32D, 449 ABI_ILP32E, 450 ABI_LP64, 451 ABI_LP64F, 452 ABI_LP64D, 453 ABI_LP64E, 454 ABI_Unknown 455 }; 456 457 // Returns the target ABI, or else a StringError if the requested ABIName is 458 // not supported for the given TT and FeatureBits combination. 459 ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, 460 StringRef ABIName); 461 462 ABI getTargetABI(StringRef ABIName); 463 464 // Returns the register used to hold the stack pointer after realignment. 465 MCRegister getBPReg(); 466 467 // Returns the register holding shadow call stack pointer. 468 MCRegister getSCSPReg(); 469 470 } // namespace RISCVABI 471 472 namespace RISCVFeatures { 473 474 // Validates if the given combination of features are valid for the target 475 // triple. Exits with report_fatal_error if not. 476 void validate(const Triple &TT, const FeatureBitset &FeatureBits); 477 478 llvm::Expected<std::unique_ptr<RISCVISAInfo>> 479 parseFeatureBits(bool IsRV64, const FeatureBitset &FeatureBits); 480 481 } // namespace RISCVFeatures 482 483 namespace RISCVVType { 484 // Is this a SEW value that can be encoded into the VTYPE format. 485 inline static bool isValidSEW(unsigned SEW) { 486 return isPowerOf2_32(SEW) && SEW >= 8 && SEW <= 1024; 487 } 488 489 // Is this a LMUL value that can be encoded into the VTYPE format. 490 inline static bool isValidLMUL(unsigned LMUL, bool Fractional) { 491 return isPowerOf2_32(LMUL) && LMUL <= 8 && (!Fractional || LMUL != 1); 492 } 493 494 unsigned encodeVTYPE(RISCVII::VLMUL VLMUL, unsigned SEW, bool TailAgnostic, 495 bool MaskAgnostic); 496 497 inline static RISCVII::VLMUL getVLMUL(unsigned VType) { 498 unsigned VLMUL = VType & 0x7; 499 return static_cast<RISCVII::VLMUL>(VLMUL); 500 } 501 502 // Decode VLMUL into 1,2,4,8 and fractional indicator. 503 std::pair<unsigned, bool> decodeVLMUL(RISCVII::VLMUL VLMUL); 504 505 inline static RISCVII::VLMUL encodeLMUL(unsigned LMUL, bool Fractional) { 506 assert(isValidLMUL(LMUL, Fractional) && "Unsupported LMUL"); 507 unsigned LmulLog2 = Log2_32(LMUL); 508 return static_cast<RISCVII::VLMUL>(Fractional ? 8 - LmulLog2 : LmulLog2); 509 } 510 511 inline static unsigned decodeVSEW(unsigned VSEW) { 512 assert(VSEW < 8 && "Unexpected VSEW value"); 513 return 1 << (VSEW + 3); 514 } 515 516 inline static unsigned encodeSEW(unsigned SEW) { 517 assert(isValidSEW(SEW) && "Unexpected SEW value"); 518 return Log2_32(SEW) - 3; 519 } 520 521 inline static unsigned getSEW(unsigned VType) { 522 unsigned VSEW = (VType >> 3) & 0x7; 523 return decodeVSEW(VSEW); 524 } 525 526 inline static bool isTailAgnostic(unsigned VType) { return VType & 0x40; } 527 528 inline static bool isMaskAgnostic(unsigned VType) { return VType & 0x80; } 529 530 void printVType(unsigned VType, raw_ostream &OS); 531 532 unsigned getSEWLMULRatio(unsigned SEW, RISCVII::VLMUL VLMul); 533 534 std::optional<RISCVII::VLMUL> 535 getSameRatioLMUL(unsigned SEW, RISCVII::VLMUL VLMUL, unsigned EEW); 536 } // namespace RISCVVType 537 538 namespace RISCVRVC { 539 bool compress(MCInst &OutInst, const MCInst &MI, const MCSubtargetInfo &STI); 540 bool uncompress(MCInst &OutInst, const MCInst &MI, const MCSubtargetInfo &STI); 541 } // namespace RISCVRVC 542 543 namespace RISCVZC { 544 enum RLISTENCODE { 545 RA = 4, 546 RA_S0, 547 RA_S0_S1, 548 RA_S0_S2, 549 RA_S0_S3, 550 RA_S0_S4, 551 RA_S0_S5, 552 RA_S0_S6, 553 RA_S0_S7, 554 RA_S0_S8, 555 RA_S0_S9, 556 // note - to include s10, s11 must also be included 557 RA_S0_S11, 558 INVALID_RLIST, 559 }; 560 561 inline unsigned encodeRlist(MCRegister EndReg, bool IsRV32E = false) { 562 assert((!IsRV32E || EndReg <= RISCV::X9) && "Invalid Rlist for RV32E"); 563 switch (EndReg) { 564 case RISCV::X1: 565 return RLISTENCODE::RA; 566 case RISCV::X8: 567 return RLISTENCODE::RA_S0; 568 case RISCV::X9: 569 return RLISTENCODE::RA_S0_S1; 570 case RISCV::X18: 571 return RLISTENCODE::RA_S0_S2; 572 case RISCV::X19: 573 return RLISTENCODE::RA_S0_S3; 574 case RISCV::X20: 575 return RLISTENCODE::RA_S0_S4; 576 case RISCV::X21: 577 return RLISTENCODE::RA_S0_S5; 578 case RISCV::X22: 579 return RLISTENCODE::RA_S0_S6; 580 case RISCV::X23: 581 return RLISTENCODE::RA_S0_S7; 582 case RISCV::X24: 583 return RLISTENCODE::RA_S0_S8; 584 case RISCV::X25: 585 return RLISTENCODE::RA_S0_S9; 586 case RISCV::X26: 587 return RLISTENCODE::INVALID_RLIST; 588 case RISCV::X27: 589 return RLISTENCODE::RA_S0_S11; 590 default: 591 llvm_unreachable("Undefined input."); 592 } 593 } 594 595 inline static unsigned getStackAdjBase(unsigned RlistVal, bool IsRV64, 596 bool IsEABI) { 597 assert(RlistVal != RLISTENCODE::INVALID_RLIST && 598 "{ra, s0-s10} is not supported, s11 must be included."); 599 if (IsEABI) 600 return 16; 601 if (!IsRV64) { 602 switch (RlistVal) { 603 case RLISTENCODE::RA: 604 case RLISTENCODE::RA_S0: 605 case RLISTENCODE::RA_S0_S1: 606 case RLISTENCODE::RA_S0_S2: 607 return 16; 608 case RLISTENCODE::RA_S0_S3: 609 case RLISTENCODE::RA_S0_S4: 610 case RLISTENCODE::RA_S0_S5: 611 case RLISTENCODE::RA_S0_S6: 612 return 32; 613 case RLISTENCODE::RA_S0_S7: 614 case RLISTENCODE::RA_S0_S8: 615 case RLISTENCODE::RA_S0_S9: 616 return 48; 617 case RLISTENCODE::RA_S0_S11: 618 return 64; 619 } 620 } else { 621 switch (RlistVal) { 622 case RLISTENCODE::RA: 623 case RLISTENCODE::RA_S0: 624 return 16; 625 case RLISTENCODE::RA_S0_S1: 626 case RLISTENCODE::RA_S0_S2: 627 return 32; 628 case RLISTENCODE::RA_S0_S3: 629 case RLISTENCODE::RA_S0_S4: 630 return 48; 631 case RLISTENCODE::RA_S0_S5: 632 case RLISTENCODE::RA_S0_S6: 633 return 64; 634 case RLISTENCODE::RA_S0_S7: 635 case RLISTENCODE::RA_S0_S8: 636 return 80; 637 case RLISTENCODE::RA_S0_S9: 638 return 96; 639 case RLISTENCODE::RA_S0_S11: 640 return 112; 641 } 642 } 643 llvm_unreachable("Unexpected RlistVal"); 644 } 645 646 inline static bool getSpimm(unsigned RlistVal, unsigned &SpimmVal, 647 int64_t StackAdjustment, bool IsRV64, bool IsEABI) { 648 if (RlistVal == RLISTENCODE::INVALID_RLIST) 649 return false; 650 unsigned stackAdj = getStackAdjBase(RlistVal, IsRV64, IsEABI); 651 SpimmVal = (StackAdjustment - stackAdj) / 16; 652 if (SpimmVal > 3) 653 return false; 654 return true; 655 } 656 657 void printRlist(unsigned SlistEncode, raw_ostream &OS); 658 void printSpimm(int64_t Spimm, raw_ostream &OS); 659 } // namespace RISCVZC 660 661 } // namespace llvm 662 663 #endif 664