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/SubtargetFeature.h"
23 // RISCVII - This namespace holds all of the target specific flags that
24 // instruction info tracks. All definitions must match RISCVInstrFormats.td.
64 } // namespace RISCVII
66 // Describes the predecessor/successor bits used in the FENCE instruction.
67 namespace RISCVFenceField
{
76 // Describes the supported floating point rounding mode encodings.
77 namespace RISCVFPRndMode
{
88 inline static StringRef
roundingModeToString(RoundingMode RndMode
) {
91 llvm_unreachable("Unknown floating point rounding mode");
92 case RISCVFPRndMode::RNE
:
94 case RISCVFPRndMode::RTZ
:
96 case RISCVFPRndMode::RDN
:
98 case RISCVFPRndMode::RUP
:
100 case RISCVFPRndMode::RMM
:
102 case RISCVFPRndMode::DYN
:
107 inline static RoundingMode
stringToRoundingMode(StringRef Str
) {
108 return StringSwitch
<RoundingMode
>(Str
)
109 .Case("rne", RISCVFPRndMode::RNE
)
110 .Case("rtz", RISCVFPRndMode::RTZ
)
111 .Case("rdn", RISCVFPRndMode::RDN
)
112 .Case("rup", RISCVFPRndMode::RUP
)
113 .Case("rmm", RISCVFPRndMode::RMM
)
114 .Case("dyn", RISCVFPRndMode::DYN
)
115 .Default(RISCVFPRndMode::Invalid
);
118 inline static bool isValidRoundingMode(unsigned Mode
) {
122 case RISCVFPRndMode::RNE
:
123 case RISCVFPRndMode::RTZ
:
124 case RISCVFPRndMode::RDN
:
125 case RISCVFPRndMode::RUP
:
126 case RISCVFPRndMode::RMM
:
127 case RISCVFPRndMode::DYN
:
131 } // namespace RISCVFPRndMode
133 namespace RISCVSysReg
{
137 // FIXME: add these additional fields when needed.
138 // Privilege Access: Read, Write, Read-Only.
139 // unsigned ReadWrite;
140 // Privilege Mode: User, System or Machine.
144 // Register number without the privilege bits.
146 FeatureBitset FeaturesRequired
;
149 bool haveRequiredFeatures(FeatureBitset ActiveFeatures
) const {
150 // Not in 32-bit mode.
151 if (isRV32Only
&& ActiveFeatures
[RISCV::Feature64Bit
])
153 // No required feature associated with the system register.
154 if (FeaturesRequired
.none())
156 return (FeaturesRequired
& ActiveFeatures
) == FeaturesRequired
;
160 #define GET_SysRegsList_DECL
161 #include "RISCVGenSystemOperands.inc"
162 } // end namespace RISCVSysReg
177 // Returns the target ABI, or else a StringError if the requested ABIName is
178 // not supported for the given TT and FeatureBits combination.
179 ABI
computeTargetABI(const Triple
&TT
, FeatureBitset FeatureBits
,
182 } // namespace RISCVABI
184 namespace RISCVFeatures
{
186 // Validates if the given combination of features are valid for the target
187 // triple. Exits with report_fatal_error if not.
188 void validate(const Triple
&TT
, const FeatureBitset
&FeatureBits
);
190 } // namespace RISCVFeatures