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