1 //===-- RISCVBaseInfo.h - Top level definitions for RISCV MC ----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains small standalone enum definitions for the RISCV target
10 // useful for the compiler back-end and the MC libraries.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
14 #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
16 #include "MCTargetDesc/RISCVMCTargetDesc.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/MC/MCInstrDesc.h"
20 #include "llvm/MC/SubtargetFeature.h"
24 // RISCVII - This namespace holds all of the target specific flags that
25 // instruction info tracks. All definitions must match RISCVInstrFormats.td.
65 } // namespace RISCVII
68 enum OperandType
: unsigned {
69 OPERAND_FIRST_RISCV_IMM
= MCOI::OPERAND_FIRST_TARGET
,
70 OPERAND_UIMM4
= OPERAND_FIRST_RISCV_IMM
,
78 OPERAND_LAST_RISCV_IMM
= OPERAND_UIMMLOG2XLEN
80 } // namespace RISCVOp
82 // Describes the predecessor/successor bits used in the FENCE instruction.
83 namespace RISCVFenceField
{
92 // Describes the supported floating point rounding mode encodings.
93 namespace RISCVFPRndMode
{
104 inline static StringRef
roundingModeToString(RoundingMode RndMode
) {
107 llvm_unreachable("Unknown floating point rounding mode");
108 case RISCVFPRndMode::RNE
:
110 case RISCVFPRndMode::RTZ
:
112 case RISCVFPRndMode::RDN
:
114 case RISCVFPRndMode::RUP
:
116 case RISCVFPRndMode::RMM
:
118 case RISCVFPRndMode::DYN
:
123 inline static RoundingMode
stringToRoundingMode(StringRef Str
) {
124 return StringSwitch
<RoundingMode
>(Str
)
125 .Case("rne", RISCVFPRndMode::RNE
)
126 .Case("rtz", RISCVFPRndMode::RTZ
)
127 .Case("rdn", RISCVFPRndMode::RDN
)
128 .Case("rup", RISCVFPRndMode::RUP
)
129 .Case("rmm", RISCVFPRndMode::RMM
)
130 .Case("dyn", RISCVFPRndMode::DYN
)
131 .Default(RISCVFPRndMode::Invalid
);
134 inline static bool isValidRoundingMode(unsigned Mode
) {
138 case RISCVFPRndMode::RNE
:
139 case RISCVFPRndMode::RTZ
:
140 case RISCVFPRndMode::RDN
:
141 case RISCVFPRndMode::RUP
:
142 case RISCVFPRndMode::RMM
:
143 case RISCVFPRndMode::DYN
:
147 } // namespace RISCVFPRndMode
149 namespace RISCVSysReg
{
153 // FIXME: add these additional fields when needed.
154 // Privilege Access: Read, Write, Read-Only.
155 // unsigned ReadWrite;
156 // Privilege Mode: User, System or Machine.
160 // Register number without the privilege bits.
162 FeatureBitset FeaturesRequired
;
165 bool haveRequiredFeatures(FeatureBitset ActiveFeatures
) const {
166 // Not in 32-bit mode.
167 if (isRV32Only
&& ActiveFeatures
[RISCV::Feature64Bit
])
169 // No required feature associated with the system register.
170 if (FeaturesRequired
.none())
172 return (FeaturesRequired
& ActiveFeatures
) == FeaturesRequired
;
176 #define GET_SysRegsList_DECL
177 #include "RISCVGenSystemOperands.inc"
178 } // end namespace RISCVSysReg
193 // Returns the target ABI, or else a StringError if the requested ABIName is
194 // not supported for the given TT and FeatureBits combination.
195 ABI
computeTargetABI(const Triple
&TT
, FeatureBitset FeatureBits
,
198 } // namespace RISCVABI
200 namespace RISCVFeatures
{
202 // Validates if the given combination of features are valid for the target
203 // triple. Exits with report_fatal_error if not.
204 void validate(const Triple
&TT
, const FeatureBitset
&FeatureBits
);
206 } // namespace RISCVFeatures