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, |
| 51 | MO_LO, |
| 52 | MO_HI, |
| 53 | MO_PCREL_HI, |
| 54 | }; |
| 55 | } // namespace RISCVII |
| 56 | |
| 57 | // Describes the predecessor/successor bits used in the FENCE instruction. |
| 58 | namespace RISCVFenceField { |
| 59 | enum FenceField { |
| 60 | I = 8, |
| 61 | O = 4, |
| 62 | R = 2, |
| 63 | W = 1 |
| 64 | }; |
| 65 | } |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 66 | |
| 67 | // Describes the supported floating point rounding mode encodings. |
| 68 | namespace RISCVFPRndMode { |
| 69 | enum RoundingMode { |
| 70 | RNE = 0, |
| 71 | RTZ = 1, |
| 72 | RDN = 2, |
| 73 | RUP = 3, |
| 74 | RMM = 4, |
| 75 | DYN = 7, |
| 76 | Invalid |
| 77 | }; |
| 78 | |
| 79 | inline static StringRef roundingModeToString(RoundingMode RndMode) { |
| 80 | switch (RndMode) { |
| 81 | default: |
| 82 | llvm_unreachable("Unknown floating point rounding mode"); |
| 83 | case RISCVFPRndMode::RNE: |
| 84 | return "rne"; |
| 85 | case RISCVFPRndMode::RTZ: |
| 86 | return "rtz"; |
| 87 | case RISCVFPRndMode::RDN: |
| 88 | return "rdn"; |
| 89 | case RISCVFPRndMode::RUP: |
| 90 | return "rup"; |
| 91 | case RISCVFPRndMode::RMM: |
| 92 | return "rmm"; |
| 93 | case RISCVFPRndMode::DYN: |
| 94 | return "dyn"; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | inline static RoundingMode stringToRoundingMode(StringRef Str) { |
| 99 | return StringSwitch<RoundingMode>(Str) |
| 100 | .Case("rne", RISCVFPRndMode::RNE) |
| 101 | .Case("rtz", RISCVFPRndMode::RTZ) |
| 102 | .Case("rdn", RISCVFPRndMode::RDN) |
| 103 | .Case("rup", RISCVFPRndMode::RUP) |
| 104 | .Case("rmm", RISCVFPRndMode::RMM) |
| 105 | .Case("dyn", RISCVFPRndMode::DYN) |
| 106 | .Default(RISCVFPRndMode::Invalid); |
| 107 | } |
Ana Pazos | b2ed11a | 2018-09-07 18:43:43 +0000 | [diff] [blame] | 108 | |
| 109 | inline static bool isValidRoundingMode(unsigned Mode) { |
| 110 | switch (Mode) { |
| 111 | default: |
| 112 | return false; |
| 113 | case RISCVFPRndMode::RNE: |
| 114 | case RISCVFPRndMode::RTZ: |
| 115 | case RISCVFPRndMode::RDN: |
| 116 | case RISCVFPRndMode::RUP: |
| 117 | case RISCVFPRndMode::RMM: |
| 118 | case RISCVFPRndMode::DYN: |
| 119 | return true; |
| 120 | } |
| 121 | } |
Alex Bradbury | 0d6cf90 | 2017-12-07 10:26:05 +0000 | [diff] [blame] | 122 | } // namespace RISCVFPRndMode |
Ana Pazos | 9d6c553 | 2018-10-04 21:50:54 +0000 | [diff] [blame] | 123 | |
| 124 | namespace RISCVSysReg { |
| 125 | struct SysReg { |
| 126 | const char *Name; |
| 127 | unsigned Encoding; |
| 128 | // FIXME: add these additional fields when needed. |
| 129 | // Privilege Access: Read, Write, Read-Only. |
| 130 | // unsigned ReadWrite; |
| 131 | // Privilege Mode: User, System or Machine. |
| 132 | // unsigned Mode; |
| 133 | // Check field name. |
| 134 | // unsigned Extra; |
| 135 | // Register number without the privilege bits. |
| 136 | // unsigned Number; |
| 137 | FeatureBitset FeaturesRequired; |
| 138 | bool isRV32Only; |
| 139 | |
| 140 | bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const { |
| 141 | // Not in 32-bit mode. |
| 142 | if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit]) |
| 143 | return false; |
| 144 | // No required feature associated with the system register. |
| 145 | if (FeaturesRequired.none()) |
| 146 | return true; |
| 147 | return (FeaturesRequired & ActiveFeatures) == FeaturesRequired; |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | #define GET_SysRegsList_DECL |
| 152 | #include "RISCVGenSystemOperands.inc" |
| 153 | } // end namespace RISCVSysReg |
| 154 | |
Alex Bradbury | 6758ecb | 2017-09-17 14:27:35 +0000 | [diff] [blame] | 155 | } // namespace llvm |
| 156 | |
| 157 | #endif |