LLVM  10.0.0
RISCVBaseInfo.h
Go to the documentation of this file.
1 //===-- RISCVBaseInfo.h - Top level definitions for RISCV 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 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 
16 #include "RISCVRegisterInfo.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/MC/MCInstrDesc.h"
22 
23 namespace llvm {
24 
25 // RISCVII - This namespace holds all of the target specific flags that
26 // instruction info tracks. All definitions must match RISCVInstrFormats.td.
27 namespace RISCVII {
28 enum {
47 
49 };
50 
51 // RISC-V Specific Machine Operand Flags
52 enum {
53  MO_None = 0,
54  MO_CALL = 1,
55  MO_PLT = 2,
56  MO_LO = 3,
57  MO_HI = 4,
60  MO_GOT_HI = 7,
66 
67  // Used to differentiate between target-specific "direct" flags and "bitmask"
68  // flags. A machine operand can only have one "direct" flag, but can have
69  // multiple "bitmask" flags.
71 };
72 } // namespace RISCVII
73 
74 namespace RISCVOp {
75 enum OperandType : unsigned {
86 };
87 } // namespace RISCVOp
88 
89 // Describes the predecessor/successor bits used in the FENCE instruction.
90 namespace RISCVFenceField {
91 enum FenceField {
92  I = 8,
93  O = 4,
94  R = 2,
95  W = 1
96 };
97 }
98 
99 // Describes the supported floating point rounding mode encodings.
100 namespace RISCVFPRndMode {
102  RNE = 0,
103  RTZ = 1,
104  RDN = 2,
105  RUP = 3,
106  RMM = 4,
107  DYN = 7,
108  Invalid
109 };
110 
112  switch (RndMode) {
113  default:
114  llvm_unreachable("Unknown floating point rounding mode");
115  case RISCVFPRndMode::RNE:
116  return "rne";
117  case RISCVFPRndMode::RTZ:
118  return "rtz";
119  case RISCVFPRndMode::RDN:
120  return "rdn";
121  case RISCVFPRndMode::RUP:
122  return "rup";
123  case RISCVFPRndMode::RMM:
124  return "rmm";
125  case RISCVFPRndMode::DYN:
126  return "dyn";
127  }
128 }
129 
131  return StringSwitch<RoundingMode>(Str)
132  .Case("rne", RISCVFPRndMode::RNE)
133  .Case("rtz", RISCVFPRndMode::RTZ)
134  .Case("rdn", RISCVFPRndMode::RDN)
135  .Case("rup", RISCVFPRndMode::RUP)
136  .Case("rmm", RISCVFPRndMode::RMM)
137  .Case("dyn", RISCVFPRndMode::DYN)
139 }
140 
141 inline static bool isValidRoundingMode(unsigned Mode) {
142  switch (Mode) {
143  default:
144  return false;
145  case RISCVFPRndMode::RNE:
146  case RISCVFPRndMode::RTZ:
147  case RISCVFPRndMode::RDN:
148  case RISCVFPRndMode::RUP:
149  case RISCVFPRndMode::RMM:
150  case RISCVFPRndMode::DYN:
151  return true;
152  }
153 }
154 } // namespace RISCVFPRndMode
155 
156 namespace RISCVSysReg {
157 struct SysReg {
158  const char *Name;
159  unsigned Encoding;
160  // FIXME: add these additional fields when needed.
161  // Privilege Access: Read, Write, Read-Only.
162  // unsigned ReadWrite;
163  // Privilege Mode: User, System or Machine.
164  // unsigned Mode;
165  // Check field name.
166  // unsigned Extra;
167  // Register number without the privilege bits.
168  // unsigned Number;
171 
172  bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const {
173  // Not in 32-bit mode.
174  if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit])
175  return false;
176  // No required feature associated with the system register.
177  if (FeaturesRequired.none())
178  return true;
179  return (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
180  }
181 };
182 
183 #define GET_SysRegsList_DECL
184 #include "RISCVGenSystemOperands.inc"
185 } // end namespace RISCVSysReg
186 
187 namespace RISCVABI {
188 
189 enum ABI {
198 };
199 
200 // Returns the target ABI, or else a StringError if the requested ABIName is
201 // not supported for the given TT and FeatureBits combination.
202 ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits,
203  StringRef ABIName);
204 
205 ABI getTargetABI(StringRef ABIName);
206 
207 // Returns the register used to hold the stack pointer after realignment.
209 
210 } // namespace RISCVABI
211 
212 namespace RISCVFeatures {
213 
214 // Validates if the given combination of features are valid for the target
215 // triple. Exits with report_fatal_error if not.
216 void validate(const Triple &TT, const FeatureBitset &FeatureBits);
217 
218 } // namespace RISCVFeatures
219 
220 } // namespace llvm
221 
222 #endif
static bool isValidRoundingMode(unsigned Mode)
static ARMBaseTargetMachine::ARMABI computeTargetABI(const Triple &TT, StringRef CPU, const TargetOptions &Options)
SI Whole Quad Mode
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static RoundingMode stringToRoundingMode(StringRef Str)
bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
FeatureBitset FeaturesRequired
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
Container class for subtarget features.
ABI getTargetABI(StringRef ABIName)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
Register getBPReg()
#define I(x, y, z)
Definition: MD5.cpp:58
static StringRef roundingModeToString(RoundingMode RndMode)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Wrapper class representing virtual and physical registers.
Definition: Register.h:19