LLVM 24.0.0git
VE.h
Go to the documentation of this file.
1//===-- VE.h - Top-level interface for VE representation --------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the entry points for global functions defined in the LLVM
10// VE back-end.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_VE_VE_H
15#define LLVM_LIB_TARGET_VE_VE_H
16
21#include "llvm/IR/Analysis.h"
22#include "llvm/IR/PassManager.h"
26
27namespace llvm {
28class AsmPrinter;
29class FunctionPass;
30class MCInst;
31class MachineInstr;
32class PassRegistry;
33class VETargetMachine;
34
39
41
42class VELVLGenPass : public RequiredPassInfoMixin<VELVLGenPass> {
43public:
46};
47
51
53 AsmPrinter &AP);
54} // namespace llvm
55
56namespace llvm {
57// Enums corresponding to VE condition codes, both icc's and fcc's. These
58// values must be kept in sync with the ones in the .td file.
59namespace VECC {
61 // Integer comparison
62 CC_IG = 0, // Greater
63 CC_IL = 1, // Less
64 CC_INE = 2, // Not Equal
65 CC_IEQ = 3, // Equal
66 CC_IGE = 4, // Greater or Equal
67 CC_ILE = 5, // Less or Equal
68
69 // Floating point comparison
70 CC_AF = 0 + 6, // Never
71 CC_G = 1 + 6, // Greater
72 CC_L = 2 + 6, // Less
73 CC_NE = 3 + 6, // Not Equal
74 CC_EQ = 4 + 6, // Equal
75 CC_GE = 5 + 6, // Greater or Equal
76 CC_LE = 6 + 6, // Less or Equal
77 CC_NUM = 7 + 6, // Number
78 CC_NAN = 8 + 6, // NaN
79 CC_GNAN = 9 + 6, // Greater or NaN
80 CC_LNAN = 10 + 6, // Less or NaN
81 CC_NENAN = 11 + 6, // Not Equal or NaN
82 CC_EQNAN = 12 + 6, // Equal or NaN
83 CC_GENAN = 13 + 6, // Greater or Equal or NaN
84 CC_LENAN = 14 + 6, // Less or Equal or NaN
85 CC_AT = 15 + 6, // Always
87};
88}
89// Enums corresponding to VE Rounding Mode. These values must be kept in
90// sync with the ones in the .td file.
91namespace VERD {
93 RD_NONE = 0, // According to PSW
94 RD_RZ = 8, // Round toward Zero
95 RD_RP = 9, // Round toward Plus infinity
96 RD_RM = 10, // Round toward Minus infinity
97 RD_RN = 11, // Round to Nearest (ties to Even)
98 RD_RA = 12, // Round to Nearest (ties to Away)
100};
101}
102
103inline static const char *VECondCodeToString(VECC::CondCode CC) {
104 switch (CC) {
105 case VECC::CC_IG: return "gt";
106 case VECC::CC_IL: return "lt";
107 case VECC::CC_INE: return "ne";
108 case VECC::CC_IEQ: return "eq";
109 case VECC::CC_IGE: return "ge";
110 case VECC::CC_ILE: return "le";
111 case VECC::CC_AF: return "af";
112 case VECC::CC_G: return "gt";
113 case VECC::CC_L: return "lt";
114 case VECC::CC_NE: return "ne";
115 case VECC::CC_EQ: return "eq";
116 case VECC::CC_GE: return "ge";
117 case VECC::CC_LE: return "le";
118 case VECC::CC_NUM: return "num";
119 case VECC::CC_NAN: return "nan";
120 case VECC::CC_GNAN: return "gtnan";
121 case VECC::CC_LNAN: return "ltnan";
122 case VECC::CC_NENAN: return "nenan";
123 case VECC::CC_EQNAN: return "eqnan";
124 case VECC::CC_GENAN: return "genan";
125 case VECC::CC_LENAN: return "lenan";
126 case VECC::CC_AT: return "at";
127 default:
128 llvm_unreachable("Invalid cond code");
129 }
130}
131
134 .Case("gt", VECC::CC_IG)
135 .Case("lt", VECC::CC_IL)
136 .Case("ne", VECC::CC_INE)
137 .Case("eq", VECC::CC_IEQ)
138 .Case("ge", VECC::CC_IGE)
139 .Case("le", VECC::CC_ILE)
140 .Case("af", VECC::CC_AF)
141 .Case("at", VECC::CC_AT)
142 .Case("", VECC::CC_AT)
144}
145
148 .Case("gt", VECC::CC_G)
149 .Case("lt", VECC::CC_L)
150 .Case("ne", VECC::CC_NE)
151 .Case("eq", VECC::CC_EQ)
152 .Case("ge", VECC::CC_GE)
153 .Case("le", VECC::CC_LE)
154 .Case("num", VECC::CC_NUM)
155 .Case("nan", VECC::CC_NAN)
156 .Case("gtnan", VECC::CC_GNAN)
157 .Case("ltnan", VECC::CC_LNAN)
158 .Case("nenan", VECC::CC_NENAN)
159 .Case("eqnan", VECC::CC_EQNAN)
160 .Case("genan", VECC::CC_GENAN)
161 .Case("lenan", VECC::CC_LENAN)
162 .Case("af", VECC::CC_AF)
163 .Case("at", VECC::CC_AT)
164 .Case("", VECC::CC_AT)
166}
167
168inline static bool isIntVECondCode(VECC::CondCode CC) {
169 return CC < VECC::CC_AF;
170}
171
172inline static unsigned VECondCodeToVal(VECC::CondCode CC) {
173 switch (CC) {
174 case VECC::CC_IG:
175 return 1;
176 case VECC::CC_IL:
177 return 2;
178 case VECC::CC_INE:
179 return 3;
180 case VECC::CC_IEQ:
181 return 4;
182 case VECC::CC_IGE:
183 return 5;
184 case VECC::CC_ILE:
185 return 6;
186 case VECC::CC_AF:
187 return 0;
188 case VECC::CC_G:
189 return 1;
190 case VECC::CC_L:
191 return 2;
192 case VECC::CC_NE:
193 return 3;
194 case VECC::CC_EQ:
195 return 4;
196 case VECC::CC_GE:
197 return 5;
198 case VECC::CC_LE:
199 return 6;
200 case VECC::CC_NUM:
201 return 7;
202 case VECC::CC_NAN:
203 return 8;
204 case VECC::CC_GNAN:
205 return 9;
206 case VECC::CC_LNAN:
207 return 10;
208 case VECC::CC_NENAN:
209 return 11;
210 case VECC::CC_EQNAN:
211 return 12;
212 case VECC::CC_GENAN:
213 return 13;
214 case VECC::CC_LENAN:
215 return 14;
216 case VECC::CC_AT:
217 return 15;
218 default:
219 llvm_unreachable("Invalid cond code");
220 }
221}
222
223inline static VECC::CondCode VEValToCondCode(unsigned Val, bool IsInteger) {
224 if (IsInteger) {
225 switch (Val) {
226 case 0:
227 return VECC::CC_AF;
228 case 1:
229 return VECC::CC_IG;
230 case 2:
231 return VECC::CC_IL;
232 case 3:
233 return VECC::CC_INE;
234 case 4:
235 return VECC::CC_IEQ;
236 case 5:
237 return VECC::CC_IGE;
238 case 6:
239 return VECC::CC_ILE;
240 case 15:
241 return VECC::CC_AT;
242 }
243 } else {
244 switch (Val) {
245 case 0:
246 return VECC::CC_AF;
247 case 1:
248 return VECC::CC_G;
249 case 2:
250 return VECC::CC_L;
251 case 3:
252 return VECC::CC_NE;
253 case 4:
254 return VECC::CC_EQ;
255 case 5:
256 return VECC::CC_GE;
257 case 6:
258 return VECC::CC_LE;
259 case 7:
260 return VECC::CC_NUM;
261 case 8:
262 return VECC::CC_NAN;
263 case 9:
264 return VECC::CC_GNAN;
265 case 10:
266 return VECC::CC_LNAN;
267 case 11:
268 return VECC::CC_NENAN;
269 case 12:
270 return VECC::CC_EQNAN;
271 case 13:
272 return VECC::CC_GENAN;
273 case 14:
274 return VECC::CC_LENAN;
275 case 15:
276 return VECC::CC_AT;
277 }
278 }
279 llvm_unreachable("Invalid cond code");
280}
281
282inline static const char *VERDToString(VERD::RoundingMode R) {
283 switch (R) {
284 case VERD::RD_NONE:
285 return "";
286 case VERD::RD_RZ:
287 return ".rz";
288 case VERD::RD_RP:
289 return ".rp";
290 case VERD::RD_RM:
291 return ".rm";
292 case VERD::RD_RN:
293 return ".rn";
294 case VERD::RD_RA:
295 return ".ra";
296 default:
297 llvm_unreachable("Invalid branch predicate");
298 }
299}
300
303 .Case("", VERD::RD_NONE)
304 .Case(".rz", VERD::RD_RZ)
305 .Case(".rp", VERD::RD_RP)
306 .Case(".rm", VERD::RD_RM)
307 .Case(".rn", VERD::RD_RN)
308 .Case(".ra", VERD::RD_RA)
310}
311
312inline static unsigned VERDToVal(VERD::RoundingMode R) {
313 switch (R) {
314 case VERD::RD_NONE:
315 case VERD::RD_RZ:
316 case VERD::RD_RP:
317 case VERD::RD_RM:
318 case VERD::RD_RN:
319 case VERD::RD_RA:
320 return static_cast<unsigned>(R);
321 default:
322 break;
323 }
324 llvm_unreachable("Invalid branch predicates");
325}
326
327inline static VERD::RoundingMode VEValToRD(unsigned Val) {
328 switch (Val) {
329 case static_cast<unsigned>(VERD::RD_NONE):
330 return VERD::RD_NONE;
331 case static_cast<unsigned>(VERD::RD_RZ):
332 return VERD::RD_RZ;
333 case static_cast<unsigned>(VERD::RD_RP):
334 return VERD::RD_RP;
335 case static_cast<unsigned>(VERD::RD_RM):
336 return VERD::RD_RM;
337 case static_cast<unsigned>(VERD::RD_RN):
338 return VERD::RD_RN;
339 case static_cast<unsigned>(VERD::RD_RA):
340 return VERD::RD_RA;
341 default:
342 break;
343 }
344 llvm_unreachable("Invalid branch predicates");
345}
346
347// MImm - Special immediate value of sequential bit stream of 0 or 1.
348// See VEInstrInfo.td for details.
349inline static bool isMImmVal(uint64_t Val) {
350 if (Val == 0) {
351 // (0)1 is 0
352 return true;
353 }
354 if (isMask_64(Val)) {
355 // (m)0 patterns
356 return true;
357 }
358 // (m)1 patterns
359 return (Val & (UINT64_C(1) << 63)) && isShiftedMask_64(Val);
360}
361
362inline static bool isMImm32Val(uint32_t Val) {
363 if (Val == 0) {
364 // (0)1 is 0
365 return true;
366 }
367 if (isMask_32(Val)) {
368 // (m)0 patterns
369 return true;
370 }
371 // (m)1 patterns
372 return (Val & (UINT32_C(1) << 31)) && isShiftedMask_32(Val);
373}
374
375/// val2MImm - Convert an integer immediate value to target MImm immediate.
376inline static uint64_t val2MImm(uint64_t Val) {
377 if (Val == 0)
378 return 0; // (0)1
379 if (Val & (UINT64_C(1) << 63))
380 return llvm::countl_one(Val); // (m)1
381 return llvm::countl_zero(Val) | 0x40; // (m)0
382}
383
384/// mimm2Val - Convert a target MImm immediate to an integer immediate value.
385inline static uint64_t mimm2Val(uint64_t Val) {
386 if (Val == 0)
387 return 0; // (0)1
388 if ((Val & 0x40) == 0)
389 return (uint64_t)((INT64_C(1) << 63) >> (Val & 0x3f)); // (m)1
390 return ((uint64_t)INT64_C(-1) >> (Val & 0x3f)); // (m)0
391}
392
393inline unsigned M0(unsigned Val) { return Val + 64; }
394inline unsigned M1(unsigned Val) { return Val; }
395
396static const unsigned StandardVectorWidth = 256;
397static const unsigned PackedVectorWidth = 512;
398
399} // namespace llvm
400#endif
uint64_t uint64_t
IRTranslator LLVM IR MI
This header defines various interfaces for pass management in LLVM.
RISCVCC::CondCode CC
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Representation of each machine instruction.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
SelectionDAGISelPass(std::unique_ptr< SelectionDAGISel > Selector)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
VEDAGToDAGISelPass(VETargetMachine &TM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition LVLGen.cpp:147
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CondCode
Definition VE.h:60
@ CC_GENAN
Definition VE.h:83
@ CC_EQNAN
Definition VE.h:82
@ CC_G
Definition VE.h:71
@ CC_NENAN
Definition VE.h:81
@ CC_LE
Definition VE.h:76
@ CC_LENAN
Definition VE.h:84
@ CC_ILE
Definition VE.h:67
@ CC_NUM
Definition VE.h:77
@ CC_EQ
Definition VE.h:74
@ CC_GNAN
Definition VE.h:79
@ CC_IG
Definition VE.h:62
@ CC_INE
Definition VE.h:64
@ CC_AF
Definition VE.h:70
@ CC_L
Definition VE.h:72
@ CC_GE
Definition VE.h:75
@ CC_NE
Definition VE.h:73
@ CC_LNAN
Definition VE.h:80
@ CC_IEQ
Definition VE.h:65
@ UNKNOWN
Definition VE.h:86
@ CC_AT
Definition VE.h:85
@ CC_NAN
Definition VE.h:78
@ CC_IGE
Definition VE.h:66
@ CC_IL
Definition VE.h:63
RoundingMode
Definition VE.h:92
@ UNKNOWN
Definition VE.h:99
@ RD_RP
Definition VE.h:95
@ RD_NONE
Definition VE.h:93
@ RD_RN
Definition VE.h:97
@ RD_RZ
Definition VE.h:94
@ RD_RM
Definition VE.h:96
@ RD_RA
Definition VE.h:98
This is an optimization pass for GlobalISel generic memory operations.
static bool isIntVECondCode(VECC::CondCode CC)
Definition VE.h:168
void initializeVEDAGToDAGISelLegacyPass(PassRegistry &)
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition MathExtras.h:256
void LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
constexpr bool isShiftedMask_32(uint32_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (32 bit ver...
Definition MathExtras.h:268
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
Definition MathExtras.h:274
unsigned M1(unsigned Val)
Definition VE.h:394
static const unsigned StandardVectorWidth
Definition VE.h:396
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
Definition bit.h:263
static VECC::CondCode VEValToCondCode(unsigned Val, bool IsInteger)
Definition VE.h:223
static const unsigned PackedVectorWidth
Definition VE.h:397
static VECC::CondCode stringToVEFCondCode(StringRef S)
Definition VE.h:146
static const char * VECondCodeToString(VECC::CondCode CC)
Definition VE.h:103
static unsigned VECondCodeToVal(VECC::CondCode CC)
Definition VE.h:172
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition MathExtras.h:262
static uint64_t val2MImm(uint64_t Val)
val2MImm - Convert an integer immediate value to target MImm immediate.
Definition VE.h:376
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
Definition bit.h:302
static unsigned VERDToVal(VERD::RoundingMode R)
Definition VE.h:312
static uint64_t mimm2Val(uint64_t Val)
mimm2Val - Convert a target MImm immediate to an integer immediate value.
Definition VE.h:385
FunctionPass * createVELVLGenLegacyPass()
Definition LVLGen.cpp:40
unsigned M0(unsigned Val)
Definition VE.h:393
static VERD::RoundingMode VEValToRD(unsigned Val)
Definition VE.h:327
void initializeVEAsmPrinterPass(PassRegistry &)
static bool isMImmVal(uint64_t Val)
Definition VE.h:349
static const char * VERDToString(VERD::RoundingMode R)
Definition VE.h:282
static VERD::RoundingMode stringToVERD(StringRef S)
Definition VE.h:301
static bool isMImm32Val(uint32_t Val)
Definition VE.h:362
static VECC::CondCode stringToVEICondCode(StringRef S)
Definition VE.h:132
FunctionPass * createVEDAGToDAGISelLegacyPass(VETargetMachine &TM)
createVEISelDag - This pass converts a legalized DAG into a VE-specific DAG, ready for instruction sc...
A CRTP mix-in for passes that should not be skipped.