1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
| //===-- RISCVBaseInfo.h - Top level definitions for RISCV MC ----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains small standalone enum definitions for the RISCV target
// useful for the compiler back-end and the MC libraries.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H
#include "MCTargetDesc/RISCVMCTargetDesc.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/SubtargetFeature.h"
namespace llvm {
// RISCVII - This namespace holds all of the target specific flags that
// instruction info tracks. All definitions must match RISCVInstrFormats.td.
namespace RISCVII {
enum {
InstFormatPseudo = 0,
InstFormatR = 1,
InstFormatR4 = 2,
InstFormatI = 3,
InstFormatS = 4,
InstFormatB = 5,
InstFormatU = 6,
InstFormatJ = 7,
InstFormatCR = 8,
InstFormatCI = 9,
InstFormatCSS = 10,
InstFormatCIW = 11,
InstFormatCL = 12,
InstFormatCS = 13,
InstFormatCA = 14,
InstFormatCB = 15,
InstFormatCJ = 16,
InstFormatOther = 17,
InstFormatMask = 31
};
enum {
MO_None,
MO_CALL,
MO_PLT,
MO_LO,
MO_HI,
MO_PCREL_LO,
MO_PCREL_HI,
MO_GOT_HI,
MO_TPREL_LO,
MO_TPREL_HI,
MO_TPREL_ADD,
MO_TLS_GOT_HI,
MO_TLS_GD_HI,
};
} // namespace RISCVII
namespace RISCVOp {
enum OperandType : unsigned {
OPERAND_FIRST_RISCV_IMM = MCOI::OPERAND_FIRST_TARGET,
OPERAND_UIMM4 = OPERAND_FIRST_RISCV_IMM,
OPERAND_UIMM5,
OPERAND_UIMM12,
OPERAND_SIMM12,
OPERAND_SIMM13_LSB0,
OPERAND_UIMM20,
OPERAND_SIMM21_LSB0,
OPERAND_UIMMLOG2XLEN,
OPERAND_LAST_RISCV_IMM = OPERAND_UIMMLOG2XLEN
};
} // namespace RISCVOp
// Describes the predecessor/successor bits used in the FENCE instruction.
namespace RISCVFenceField {
enum FenceField {
I = 8,
O = 4,
R = 2,
W = 1
};
}
// Describes the supported floating point rounding mode encodings.
namespace RISCVFPRndMode {
enum RoundingMode {
RNE = 0,
RTZ = 1,
RDN = 2,
RUP = 3,
RMM = 4,
DYN = 7,
Invalid
};
inline static StringRef roundingModeToString(RoundingMode RndMode) {
switch (RndMode) {
default:
llvm_unreachable("Unknown floating point rounding mode");
case RISCVFPRndMode::RNE:
return "rne";
case RISCVFPRndMode::RTZ:
return "rtz";
case RISCVFPRndMode::RDN:
return "rdn";
case RISCVFPRndMode::RUP:
return "rup";
case RISCVFPRndMode::RMM:
return "rmm";
case RISCVFPRndMode::DYN:
return "dyn";
}
}
inline static RoundingMode stringToRoundingMode(StringRef Str) {
return StringSwitch<RoundingMode>(Str)
.Case("rne", RISCVFPRndMode::RNE)
.Case("rtz", RISCVFPRndMode::RTZ)
.Case("rdn", RISCVFPRndMode::RDN)
.Case("rup", RISCVFPRndMode::RUP)
.Case("rmm", RISCVFPRndMode::RMM)
.Case("dyn", RISCVFPRndMode::DYN)
.Default(RISCVFPRndMode::Invalid);
}
inline static bool isValidRoundingMode(unsigned Mode) {
switch (Mode) {
default:
return false;
case RISCVFPRndMode::RNE:
case RISCVFPRndMode::RTZ:
case RISCVFPRndMode::RDN:
case RISCVFPRndMode::RUP:
case RISCVFPRndMode::RMM:
case RISCVFPRndMode::DYN:
return true;
}
}
} // namespace RISCVFPRndMode
namespace RISCVSysReg {
struct SysReg {
const char *Name;
unsigned Encoding;
// FIXME: add these additional fields when needed.
// Privilege Access: Read, Write, Read-Only.
// unsigned ReadWrite;
// Privilege Mode: User, System or Machine.
// unsigned Mode;
// Check field name.
// unsigned Extra;
// Register number without the privilege bits.
// unsigned Number;
FeatureBitset FeaturesRequired;
bool isRV32Only;
bool haveRequiredFeatures(FeatureBitset ActiveFeatures) const {
// Not in 32-bit mode.
if (isRV32Only && ActiveFeatures[RISCV::Feature64Bit])
return false;
// No required feature associated with the system register.
if (FeaturesRequired.none())
return true;
return (FeaturesRequired & ActiveFeatures) == FeaturesRequired;
}
};
#define GET_SysRegsList_DECL
#include "RISCVGenSystemOperands.inc"
} // end namespace RISCVSysReg
namespace RISCVABI {
enum ABI {
ABI_ILP32,
ABI_ILP32F,
ABI_ILP32D,
ABI_ILP32E,
ABI_LP64,
ABI_LP64F,
ABI_LP64D,
ABI_Unknown
};
// Returns the target ABI, or else a StringError if the requested ABIName is
// not supported for the given TT and FeatureBits combination.
ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits,
StringRef ABIName);
} // namespace RISCVABI
namespace RISCVFeatures {
// Validates if the given combination of features are valid for the target
// triple. Exits with report_fatal_error if not.
void validate(const Triple &TT, const FeatureBitset &FeatureBits);
} // namespace RISCVFeatures
} // namespace llvm
#endif
|