blob: 449cb9281ce8a9dd01f621e6b261e630ab1a463d (
plain)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef RCC_TABLEGEN_RECORD_H
#define RCC_TABLEGEN_RECORD_H
#include "rcc/Support/TextDiagnostic.h"
#include <cstdint>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
namespace rcc::targetgen {
struct SourceTarget final {
std::string Namespace;
std::string Name;
std::string Triple;
std::string CPU;
std::string ABI;
std::string DataLayout;
std::vector<std::string> Features;
TextRange Range;
};
struct SourceRegisterUnit final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
TextRange Range;
};
struct SourceRegisterUnitLane final {
std::string UnitSymbol;
std::uint64_t Lanes = 0;
TextRange Range;
};
struct SourceRegister final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::uint32_t Encoding = 0;
std::uint32_t DwarfRegister = 0;
std::vector<SourceRegisterUnitLane> Units;
bool IsConstant = false;
bool IsArtificial = false;
bool IsReserved = false;
std::vector<std::string> AlternativeNames;
TextRange Range;
};
struct SourceRegisterBank final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::uint32_t MaximumSizeInBits = 0;
TextRange Range;
};
struct SourceRegisterClass final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::string BankSymbol;
std::uint32_t SizeInBits = 0;
std::uint32_t SpillSizeInBits = 0;
std::uint32_t SpillAlignmentInBits = 0;
std::uint64_t Lanes = 0;
std::vector<std::string> RegisterSymbols;
std::vector<std::string> AllocationOrderSymbols;
std::vector<std::string> SuperClassSymbols;
bool Allocatable = true;
std::uint32_t CopyCost = 1;
TextRange Range;
};
struct SourceRegisterMask final {
std::string Name;
std::vector<std::string> PreservedRegisterSymbols;
TextRange Range;
};
struct SourceMIROperandFlag final {
std::string Name;
std::uint32_t Value = 0;
TextRange Range;
};
struct SourceMIROperandFlags final {
std::uint32_t DirectMask = 0;
std::vector<SourceMIROperandFlag> Direct;
std::vector<SourceMIROperandFlag> Bitmask;
TextRange Range;
};
struct SourceCallingConvention final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::string IntegerRegisterClassSymbol;
std::string FloatingRegisterClassSymbol;
std::vector<std::string> IntegerArgumentRegisterSymbols;
std::vector<std::string> FloatingArgumentRegisterSymbols;
std::vector<std::string> IntegerReturnRegisterSymbols;
std::vector<std::string> FloatingReturnRegisterSymbols;
std::string PreservedMaskName;
std::uint32_t StackAlignmentBytes = 0;
std::uint32_t StackArgumentAlignmentBytes = 0;
std::uint32_t ShadowSpaceBytes = 0;
bool SupportsVarArgs = false;
bool SupportsTailCalls = false;
TextRange Range;
};
struct SourceNamedOperand final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
TextRange Range;
};
struct SourceImmediatePredicate final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::string Kind;
std::uint32_t Bits = 0;
std::uint64_t Alignment = 1;
bool NonZero = false;
std::vector<std::int64_t> AllowedValues;
TextRange Range;
};
struct SourceSchedulingClass final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::uint32_t MicroOps = 0;
std::uint32_t Latency = 0;
TextRange Range;
};
struct SourceEncodingCategory final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::uint32_t SizeInBytes = 0;
TextRange Range;
};
struct SourceAssemblyFormat final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
TextRange Range;
};
struct SourceOperand final {
std::vector<std::string> Kinds;
std::string RegisterRole = "none";
std::optional<std::string> RegisterClassSymbol;
std::optional<std::string> RegisterBankSymbol;
std::optional<std::string> ImmediatePredicateSymbol;
std::string MemoryRole = "none";
std::optional<std::uint32_t> DefaultTiedOperand;
bool EarlyClobber = false;
bool Optional = false;
bool VariadicGroup = false;
bool AllowSubReg = false;
std::optional<std::string> NameSymbol;
std::optional<std::uint16_t> TypeIndex;
std::uint32_t AllowedTargetFlags = 0;
TextRange Range;
};
struct SourceImplicitRegister final {
std::string RegisterSymbol;
bool EarlyClobber = false;
bool Renamable = false;
TextRange Range;
};
struct SourceInstruction final {
std::uint32_t ID = 0;
std::string Symbol;
std::string Name;
std::string AssemblyMnemonic;
std::optional<std::uint32_t> BinaryEncoding;
std::vector<SourceOperand> Operands;
std::uint32_t NumExplicitDefs = 0;
bool Variadic = false;
std::vector<SourceImplicitRegister> ImplicitDefs;
std::vector<SourceImplicitRegister> ImplicitUses;
bool AllowExtraImplicitOperands = false;
std::vector<std::string> Flags;
std::string SchedulingClassSymbol;
std::string EncodingCategorySymbol;
std::uint32_t SizeInBytes = 0;
std::string AssemblyFormatSymbol;
bool RequiresMemoryOperands = false;
std::string Owner = "none";
std::string Deadline = "emission";
TextRange Range;
};
struct SourceSelectionTypePredicate final {
std::string Kind;
std::uint32_t Bits = 0;
TextRange Range;
};
struct SourceSelectionOperandTypePredicate final {
std::uint32_t OperandIndex = 0;
SourceSelectionTypePredicate Type;
TextRange Range;
};
struct SourceSelectionOperandBankPredicate final {
std::uint32_t OperandIndex = 0;
std::string BankSymbol;
TextRange Range;
};
struct SourceSelectionOperandClassPredicate final {
std::uint32_t OperandIndex = 0;
std::string ClassSymbol;
TextRange Range;
};
struct SourceSelectionIntegerPredicate final {
std::uint32_t OperandIndex = 0;
std::string Predicate;
TextRange Range;
};
struct SourceSelectionTargetPredicate final {
std::string Symbol;
TextRange Range;
};
struct SourceSelectionConstantRange final {
std::int64_t Minimum = 0;
std::int64_t Maximum = 0;
TextRange SourceRange;
};
struct SourceSelectionOperandImmediatePredicate final {
std::uint32_t OperandIndex = 0;
std::vector<SourceSelectionConstantRange> Ranges;
TextRange Range;
};
struct SourceSelectionOperandDefConstantPredicate final {
std::uint32_t OperandIndex = 0;
std::vector<SourceSelectionConstantRange> Ranges;
TextRange Range;
};
struct SourceSelectionDefUseCapture final {
std::string Symbol;
std::uint32_t OperandIndex = 0;
TextRange Range;
};
struct SourceSelectionDefUsePredicate final {
std::uint32_t RootOperandIndex = 0;
std::string OpcodeSymbol;
std::optional<SourceSelectionIntegerPredicate> IntegerPredicate;
std::vector<SourceSelectionDefUseCapture> Captures;
std::vector<SourceSelectionOperandDefConstantPredicate> OperandDefConstants;
TextRange Range;
};
struct SourceSelectionTemporary final {
std::string Symbol;
std::uint32_t TypeFromOperand = 0;
TextRange Range;
};
struct SourceSelectionOperandRenderer final {
std::optional<std::uint32_t> OperandIndex;
std::optional<std::uint32_t> ComplexOperandIndex;
std::string PhysicalRegisterSymbol;
std::string ComplexRendererSymbol;
std::string TemporarySymbol;
std::string CapturedOperandSymbol;
std::optional<std::uint32_t> CapturedImmediateOperand;
std::optional<std::int64_t> Immediate;
std::string ImmediateTransform;
std::vector<std::string> Flags;
TextRange Range;
};
struct SourceSelectionAction final {
std::string ResultOpcodeSymbol;
bool ReplacesRoot = false;
std::vector<SourceSelectionOperandRenderer> OperandRenderers;
TextRange Range;
};
struct SourceSelectionRule final {
std::string Symbol;
std::uint32_t Priority = 0;
std::string MatchOpcodeSymbol;
std::optional<SourceSelectionTypePredicate> ResultType;
std::optional<SourceSelectionIntegerPredicate> IntegerPredicate;
std::vector<SourceSelectionTargetPredicate> TargetPredicates;
std::vector<SourceSelectionOperandTypePredicate> OperandTypes;
std::vector<SourceSelectionOperandBankPredicate> OperandBanks;
std::vector<SourceSelectionOperandClassPredicate> OperandClasses;
std::vector<SourceSelectionOperandImmediatePredicate> OperandImmediates;
std::vector<SourceSelectionOperandDefConstantPredicate> OperandDefConstants;
std::vector<SourceSelectionDefUsePredicate> DefUsePredicates;
std::vector<SourceSelectionTemporary> Temporaries;
std::vector<SourceSelectionAction> Actions;
std::vector<std::uint32_t> EraseOperandDefinitions;
TextRange Range;
};
struct DescriptionAST final {
SourceTarget Target;
std::vector<SourceRegisterUnit> RegisterUnits;
std::vector<SourceRegister> Registers;
std::vector<SourceRegisterBank> RegisterBanks;
std::vector<SourceRegisterClass> RegisterClasses;
std::vector<SourceRegisterMask> RegisterMasks;
SourceMIROperandFlags MIROperandFlags;
std::vector<SourceCallingConvention> CallingConventions;
std::vector<SourceNamedOperand> NamedOperands;
std::vector<SourceImmediatePredicate> ImmediatePredicates;
std::vector<SourceSchedulingClass> SchedulingClasses;
std::vector<SourceEncodingCategory> EncodingCategories;
std::vector<SourceAssemblyFormat> AssemblyFormats;
std::vector<SourceInstruction> Instructions;
std::vector<SourceSelectionRule> SelectionRules;
};
[[nodiscard]] std::string lowerASCII(std::string_view Value);
[[nodiscard]] bool isIdentifier(std::string_view Value) noexcept;
[[nodiscard]] bool isAssemblyMnemonic(std::string_view Value) noexcept;
[[nodiscard]] std::string upperIdentifier(std::string_view Value);
void appendQuoted(std::ostream &Output, std::string_view Value);
} // namespace rcc::targetgen
#endif // RCC_TABLEGEN_RECORD_H
|