Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 1 | //===-- RISCVBaseInfo.h - Top level definitions for RISCV MC ----*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains small standalone enum definitions for the RISCV 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 | |
Ana Pazos | 9d6c553 | 2018-10-04 21:50:54 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/RISCVMCTargetDesc.h" |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include "llvm/ADT/StringSwitch.h" |
Ana Pazos | 9d6c553 | 2018-10-04 21:50:54 +0000 | [diff] [blame] | 19 | #include "llvm/MC/SubtargetFeature.h" |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | // RISCVII - This namespace holds all of the target specific flags that |
| 24 | // instruction info tracks. All definitions must match RISCVInstrFormats.td. |
| 25 | namespace RISCVII { |
| 26 | enum { |
| 27 | InstFormatPseudo = 0, |
| 28 | InstFormatR = 1, |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 29 | InstFormatR4 = 2, |
| 30 | InstFormatI = 3, |
| 31 | InstFormatS = 4, |
| 32 | InstFormatB = 5, |
| 33 | InstFormatU = 6, |
| 34 | InstFormatJ = 7, |
Alex Bradbury | 9f6aec4 | 2017-12-07 12:50:32 +0000 | [diff] [blame] | 35 | InstFormatCR = 8, |
| 36 | InstFormatCI = 9, |
| 37 | InstFormatCSS = 10, |
| 38 | InstFormatCIW = 11, |
| 39 | InstFormatCL = 12, |
| 40 | InstFormatCS = 13, |
Alex Bradbury | b4a64ce | 2018-11-16 10:33:23 +0000 | [diff] [blame] | 41 | InstFormatCA = 14, |
| 42 | InstFormatCB = 15, |
| 43 | InstFormatCJ = 16, |
| 44 | InstFormatOther = 17, |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 45 | |
Alex Bradbury | 9f6aec4 | 2017-12-07 12:50:32 +0000 | [diff] [blame] | 46 | InstFormatMask = 31 |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 47 | }; |
Alex Bradbury | 9d3f125 | 2017-09-28 08:26:24 +0000 | [diff] [blame] | 48 | |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 49 | enum { |
| 50 | MO_None, |
Alex Bradbury | 44668ae | 2019-04-01 14:53:17 +0000 | [diff] [blame] | 51 | MO_CALL, |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 52 | MO_LO, |
| 53 | MO_HI, |
Alex Bradbury | da20f5c | 2019-04-01 14:42:56 +0000 | [diff] [blame] | 54 | MO_PCREL_LO, |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 55 | MO_PCREL_HI, |
Lewis Revill | a524036 | 2019-06-11 12:57:47 +0000 | [diff] [blame^] | 56 | MO_GOT_HI, |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 57 | }; |
| 58 | } // namespace RISCVII |
| 59 | |
| 60 | // Describes the predecessor/successor bits used in the FENCE instruction. |
| 61 | namespace RISCVFenceField { |
| 62 | enum FenceField { |
| 63 | I = 8, |
| 64 | O = 4, |
| 65 | R = 2, |
| 66 | W = 1 |
| 67 | }; |
| 68 | } |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 69 | |
| 70 | // Describes the supported floating point rounding mode encodings. |
| 71 | namespace RISCVFPRndMode { |
| 72 | enum RoundingMode { |
| 73 | RNE = 0, |
| 74 | RTZ = 1, |
| 75 | RDN = 2, |
| 76 | RUP = 3, |
| 77 | RMM = 4, |
| 78 | DYN = 7, |
| 79 | Invalid |
| 80 | }; |
| 81 | |
| 82 | inline static StringRef roundingModeToString(RoundingMode RndMode) { |
| 83 | switch (RndMode) { |
| 84 | default: |
| 85 | llvm_unreachable("Unknown floating point rounding mode"); |
| 86 | case RISCVFPRndMode::RNE: |
| 87 | return "rne"; |
| 88 | case RISCVFPRndMode::RTZ: |
| 89 | return "rtz"; |
| 90 | case RISCVFPRndMode::RDN: |
| 91 | return "rdn"; |
| 92 | case RISCVFPRndMode::RUP: |
| 93 | return "rup"; |
| 94 | case RISCVFPRndMode::RMM: |
| 95 | return "rmm"; |
| 96 | case RISCVFPRndMode::DYN: |
| 97 | return "dyn"; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | inline static RoundingMode stringToRoundingMode(StringRef Str) { |
| 102 | return StringSwitch<RoundingMode>(Str) |
| 103 | .Case("rne", RISCVFPRndMode::RNE) |
| 104 | .Case("rtz", RISCVFPRndMode::RTZ) |
| 105 | .Case("rdn", RISCVFPRndMode::RDN) |
| 106 | .Case("rup", RISCVFPRndMode::RUP) |
| 107 | .Case("rmm", RISCVFPRndMode::RMM) |
| 108 | .Case("dyn", RISCVFPRndMode::DYN) |
| 109 | .Default(RISCVFPRndMode::Invalid); |
| 110 | } |
Ana Pazos | b2ed11a | 2018-09-07 18:43:43 +0000 | [diff] [blame] | 111 | |
| 112 | inline static bool isValidRoundingMode(unsigned Mode) { |
| 113 | switch (Mode) { |
| 114 | default: |
| 115 | return false; |
| 116 | case RISCVFPRndMode::RNE: |
| 117 | case RISCVFPRndMode::RTZ: |
| 118 | case RISCVFPRndMode::RDN: |
| 119 | case RISCVFPRndMode::RUP: |
| 120 | case RISCVFPRndMode::RMM: |
| 121 | case RISCVFPRndMode::DYN: |
| 122 | return true; |
| 123 | } |
| 124 | } |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 125 | } // namespace RISCVFPRndMode |
Ana Pazos | 9d6c553 | 2018-10-04 21:50:54 +0000 | [diff] [blame] | 126 | |
| 127 | namespace RISCVSysReg { |
| 128 | struct SysReg { |
| 129 | const char *Name; |
| 130 | unsigned Encoding; |
| 131 | // FIXME: add these additional fields when needed. |
| 132 | // Privilege Access: Read, Write, Read-Only. |
| 133 | // unsigned ReadWrite; |
| 134 | // Privilege Mode: User, System or Machine. |
| 135 | // unsigned Mode; |
| 136 | // Check field name. |
| 137 | // unsigned Extra; |
| 138 | // Register number without the privilege bits. |
| 139 | // unsigned Number; |
| 140 | FeatureBitset FeaturesRequired; |
| 141 | bool isRV32Only; |
| 142 | |
| 143 | bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const { |
| 144 | // Not in 32-bit mode. |
| 145 | if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit]) |
| 146 | return false; |
| 147 | // No required feature associated with the system register. |
| 148 | if (FeaturesRequired.none()) |
| 149 | return true; |
| 150 | return (FeaturesRequired & ActiveFeatures) == FeaturesRequired; |
| 151 | } |
| 152 | }; |
| 153 | |
| 154 | #define GET_SysRegsList_DECL |
| 155 | #include "RISCVGenSystemOperands.inc" |
| 156 | } // end namespace RISCVSysReg |
| 157 | |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 158 | namespace RISCVABI { |
| 159 | |
| 160 | enum ABI { |
| 161 | ABI_ILP32, |
| 162 | ABI_ILP32F, |
| 163 | ABI_ILP32D, |
| 164 | ABI_ILP32E, |
| 165 | ABI_LP64, |
| 166 | ABI_LP64F, |
| 167 | ABI_LP64D, |
| 168 | ABI_Unknown |
| 169 | }; |
| 170 | |
| 171 | // Returns the target ABI, or else a StringError if the requested ABIName is |
| 172 | // not supported for the given TT and FeatureBits combination. |
| 173 | ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, |
| 174 | StringRef ABIName); |
| 175 | |
| 176 | } // namespace RISCVABI |
| 177 | |
Alex Bradbury | dab1f6f | 2019-03-22 11:21:40 +0000 | [diff] [blame] | 178 | namespace RISCVFeatures { |
| 179 | |
| 180 | // Validates if the given combination of features are valid for the target |
| 181 | // triple. Exits with report_fatal_error if not. |
| 182 | void validate(const Triple &TT, const FeatureBitset &FeatureBits); |
| 183 | |
| 184 | } // namespace RISCVFeatures |
| 185 | |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 186 | } // namespace llvm |
| 187 | |
| 188 | #endif |