LLVM 22.0.0git
SPIRVLegalizerInfo.cpp
Go to the documentation of this file.
1//===- SPIRVLegalizerInfo.cpp --- SPIR-V Legalization Rules ------*- 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 implements the targeting of the Machinelegalizer class for SPIR-V.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVLegalizerInfo.h"
14#include "SPIRV.h"
15#include "SPIRVGlobalRegistry.h"
16#include "SPIRVSubtarget.h"
23#include "llvm/IR/IntrinsicsSPIRV.h"
24#include "llvm/Support/Debug.h"
26
27using namespace llvm;
28using namespace llvm::LegalizeActions;
29using namespace llvm::LegalityPredicates;
30
31#define DEBUG_TYPE "spirv-legalizer"
32
33LegalityPredicate typeOfExtendedScalars(unsigned TypeIdx, bool IsExtendedInts) {
34 return [IsExtendedInts, TypeIdx](const LegalityQuery &Query) {
35 const LLT Ty = Query.Types[TypeIdx];
36 return IsExtendedInts && Ty.isValid() && Ty.isScalar();
37 };
38}
39
41 using namespace TargetOpcode;
42
43 this->ST = &ST;
44 GR = ST.getSPIRVGlobalRegistry();
45
46 const LLT s1 = LLT::scalar(1);
47 const LLT s8 = LLT::scalar(8);
48 const LLT s16 = LLT::scalar(16);
49 const LLT s32 = LLT::scalar(32);
50 const LLT s64 = LLT::scalar(64);
51
52 const LLT v16s64 = LLT::fixed_vector(16, 64);
53 const LLT v16s32 = LLT::fixed_vector(16, 32);
54 const LLT v16s16 = LLT::fixed_vector(16, 16);
55 const LLT v16s8 = LLT::fixed_vector(16, 8);
56 const LLT v16s1 = LLT::fixed_vector(16, 1);
57
58 const LLT v8s64 = LLT::fixed_vector(8, 64);
59 const LLT v8s32 = LLT::fixed_vector(8, 32);
60 const LLT v8s16 = LLT::fixed_vector(8, 16);
61 const LLT v8s8 = LLT::fixed_vector(8, 8);
62 const LLT v8s1 = LLT::fixed_vector(8, 1);
63
64 const LLT v4s64 = LLT::fixed_vector(4, 64);
65 const LLT v4s32 = LLT::fixed_vector(4, 32);
66 const LLT v4s16 = LLT::fixed_vector(4, 16);
67 const LLT v4s8 = LLT::fixed_vector(4, 8);
68 const LLT v4s1 = LLT::fixed_vector(4, 1);
69
70 const LLT v3s64 = LLT::fixed_vector(3, 64);
71 const LLT v3s32 = LLT::fixed_vector(3, 32);
72 const LLT v3s16 = LLT::fixed_vector(3, 16);
73 const LLT v3s8 = LLT::fixed_vector(3, 8);
74 const LLT v3s1 = LLT::fixed_vector(3, 1);
75
76 const LLT v2s64 = LLT::fixed_vector(2, 64);
77 const LLT v2s32 = LLT::fixed_vector(2, 32);
78 const LLT v2s16 = LLT::fixed_vector(2, 16);
79 const LLT v2s8 = LLT::fixed_vector(2, 8);
80 const LLT v2s1 = LLT::fixed_vector(2, 1);
81
82 const unsigned PSize = ST.getPointerSize();
83 const LLT p0 = LLT::pointer(0, PSize); // Function
84 const LLT p1 = LLT::pointer(1, PSize); // CrossWorkgroup
85 const LLT p2 = LLT::pointer(2, PSize); // UniformConstant
86 const LLT p3 = LLT::pointer(3, PSize); // Workgroup
87 const LLT p4 = LLT::pointer(4, PSize); // Generic
88 const LLT p5 =
89 LLT::pointer(5, PSize); // Input, SPV_INTEL_usm_storage_classes (Device)
90 const LLT p6 = LLT::pointer(6, PSize); // SPV_INTEL_usm_storage_classes (Host)
91 const LLT p7 = LLT::pointer(7, PSize); // Input
92 const LLT p8 = LLT::pointer(8, PSize); // Output
93 const LLT p9 =
94 LLT::pointer(9, PSize); // CodeSectionINTEL, SPV_INTEL_function_pointers
95 const LLT p10 = LLT::pointer(10, PSize); // Private
96 const LLT p11 = LLT::pointer(11, PSize); // StorageBuffer
97 const LLT p12 = LLT::pointer(12, PSize); // Uniform
98
99 // TODO: remove copy-pasting here by using concatenation in some way.
100 auto allPtrsScalarsAndVectors = {
101 p0, p1, p2, p3, p4, p5, p6, p7, p8,
102 p9, p10, p11, p12, s1, s8, s16, s32, s64,
103 v2s1, v2s8, v2s16, v2s32, v2s64, v3s1, v3s8, v3s16, v3s32,
104 v3s64, v4s1, v4s8, v4s16, v4s32, v4s64, v8s1, v8s8, v8s16,
105 v8s32, v8s64, v16s1, v16s8, v16s16, v16s32, v16s64};
106
107 auto allVectors = {v2s1, v2s8, v2s16, v2s32, v2s64, v3s1, v3s8,
108 v3s16, v3s32, v3s64, v4s1, v4s8, v4s16, v4s32,
109 v4s64, v8s1, v8s8, v8s16, v8s32, v8s64, v16s1,
110 v16s8, v16s16, v16s32, v16s64};
111
112 auto allShaderVectors = {v2s1, v2s8, v2s16, v2s32, v2s64,
113 v3s1, v3s8, v3s16, v3s32, v3s64,
114 v4s1, v4s8, v4s16, v4s32, v4s64};
115
116 auto allScalarsAndVectors = {
117 s1, s8, s16, s32, s64, v2s1, v2s8, v2s16, v2s32, v2s64,
118 v3s1, v3s8, v3s16, v3s32, v3s64, v4s1, v4s8, v4s16, v4s32, v4s64,
119 v8s1, v8s8, v8s16, v8s32, v8s64, v16s1, v16s8, v16s16, v16s32, v16s64};
120
121 auto allIntScalarsAndVectors = {s8, s16, s32, s64, v2s8, v2s16,
122 v2s32, v2s64, v3s8, v3s16, v3s32, v3s64,
123 v4s8, v4s16, v4s32, v4s64, v8s8, v8s16,
124 v8s32, v8s64, v16s8, v16s16, v16s32, v16s64};
125
126 auto allBoolScalarsAndVectors = {s1, v2s1, v3s1, v4s1, v8s1, v16s1};
127
128 auto allIntScalars = {s8, s16, s32, s64};
129
130 auto allFloatScalars = {s16, s32, s64};
131
132 auto allFloatScalarsAndVectors = {
133 s16, s32, s64, v2s16, v2s32, v2s64, v3s16, v3s32, v3s64,
134 v4s16, v4s32, v4s64, v8s16, v8s32, v8s64, v16s16, v16s32, v16s64};
135
136 auto allFloatAndIntScalarsAndPtrs = {s8, s16, s32, s64, p0, p1, p2, p3, p4,
137 p5, p6, p7, p8, p9, p10, p11, p12};
138
139 auto allPtrs = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12};
140
141 auto &allowedVectorTypes = ST.isShader() ? allShaderVectors : allVectors;
142
143 bool IsExtendedInts =
144 ST.canUseExtension(
145 SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers) ||
146 ST.canUseExtension(SPIRV::Extension::SPV_KHR_bit_instructions) ||
147 ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4);
148 auto extendedScalarsAndVectors =
149 [IsExtendedInts](const LegalityQuery &Query) {
150 const LLT Ty = Query.Types[0];
151 return IsExtendedInts && Ty.isValid() && !Ty.isPointerOrPointerVector();
152 };
153 auto extendedScalarsAndVectorsProduct = [IsExtendedInts](
154 const LegalityQuery &Query) {
155 const LLT Ty1 = Query.Types[0], Ty2 = Query.Types[1];
156 return IsExtendedInts && Ty1.isValid() && Ty2.isValid() &&
157 !Ty1.isPointerOrPointerVector() && !Ty2.isPointerOrPointerVector();
158 };
159 auto extendedPtrsScalarsAndVectors =
160 [IsExtendedInts](const LegalityQuery &Query) {
161 const LLT Ty = Query.Types[0];
162 return IsExtendedInts && Ty.isValid();
163 };
164
165 // The universal validation rules in the SPIR-V specification state that
166 // vector sizes are typically limited to 2, 3, or 4. However, larger vector
167 // sizes (8 and 16) are enabled when the Kernel capability is present. For
168 // shader execution models, vector sizes are strictly limited to 4. In
169 // non-shader contexts, vector sizes of 8 and 16 are also permitted, but
170 // arbitrary sizes (e.g., 6 or 11) are not.
171 uint32_t MaxVectorSize = ST.isShader() ? 4 : 16;
172
173 for (auto Opc : getTypeFoldingSupportedOpcodes()) {
174 if (Opc != G_EXTRACT_VECTOR_ELT)
176 }
177
178 getActionDefinitionsBuilder(G_INTRINSIC_W_SIDE_EFFECTS).custom();
179
180 getActionDefinitionsBuilder(G_SHUFFLE_VECTOR)
181 .legalForCartesianProduct(allowedVectorTypes, allowedVectorTypes)
183 .lowerIf(vectorElementCountIsGreaterThan(0, MaxVectorSize))
185 .lowerIf(vectorElementCountIsGreaterThan(1, MaxVectorSize))
186 .alwaysLegal();
187
188 getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT)
192 1, ElementCount::getFixed(MaxVectorSize)))
193 .custom();
194
195 // Illegal G_UNMERGE_VALUES instructions should be handled
196 // during the combine phase.
197 getActionDefinitionsBuilder(G_BUILD_VECTOR)
201 0, ElementCount::getFixed(MaxVectorSize)));
202
203 // When entering the legalizer, there should be no G_BITCAST instructions.
204 // They should all be calls to the `spv_bitcast` intrinsic. The call to
205 // the intrinsic will be converted to a G_BITCAST during legalization if
206 // the vectors are not legal. After using the rules to legalize a G_BITCAST,
207 // we turn it back into a call to the intrinsic with a custom rule to avoid
208 // potential machine verifier failures.
214 0, ElementCount::getFixed(MaxVectorSize)))
215 .lowerIf(vectorElementCountIsGreaterThan(1, MaxVectorSize))
216 .custom();
217
218 getActionDefinitionsBuilder(G_CONCAT_VECTORS)
221 .lowerIf(vectorElementCountIsGreaterThan(0, MaxVectorSize))
222 .alwaysLegal();
223
224 getActionDefinitionsBuilder(G_SPLAT_VECTOR)
229 .alwaysLegal();
230
231 // Vector Reduction Operations
233 {G_VECREDUCE_SMIN, G_VECREDUCE_SMAX, G_VECREDUCE_UMIN, G_VECREDUCE_UMAX,
234 G_VECREDUCE_ADD, G_VECREDUCE_MUL, G_VECREDUCE_FMUL, G_VECREDUCE_FMIN,
235 G_VECREDUCE_FMAX, G_VECREDUCE_FMINIMUM, G_VECREDUCE_FMAXIMUM,
236 G_VECREDUCE_OR, G_VECREDUCE_AND, G_VECREDUCE_XOR})
237 .legalFor(allowedVectorTypes)
238 .scalarize(1)
239 .lower();
240
241 getActionDefinitionsBuilder({G_VECREDUCE_SEQ_FADD, G_VECREDUCE_SEQ_FMUL})
242 .scalarize(2)
243 .lower();
244
245 // Illegal G_UNMERGE_VALUES instructions should be handled
246 // during the combine phase.
247 getActionDefinitionsBuilder(G_UNMERGE_VALUES)
249
250 getActionDefinitionsBuilder({G_MEMCPY, G_MEMMOVE})
251 .unsupportedIf(LegalityPredicates::any(typeIs(0, p9), typeIs(1, p9)))
252 .legalIf(all(typeInSet(0, allPtrs), typeInSet(1, allPtrs)));
253
255 .unsupportedIf(typeIs(0, p9))
256 .legalIf(all(typeInSet(0, allPtrs), typeInSet(1, allIntScalars)));
257
258 getActionDefinitionsBuilder(G_ADDRSPACE_CAST)
261 all(typeIsNot(0, p9), typeIs(1, p9))))
262 .legalForCartesianProduct(allPtrs, allPtrs);
263
264 getActionDefinitionsBuilder({G_LOAD, G_STORE})
265 .unsupportedIf(typeIs(1, p9))
266 .legalIf(typeInSet(1, allPtrs));
267
268 getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX, G_ABS,
269 G_BITREVERSE, G_SADDSAT, G_UADDSAT, G_SSUBSAT,
270 G_USUBSAT, G_SCMP, G_UCMP})
271 .legalFor(allIntScalarsAndVectors)
272 .legalIf(extendedScalarsAndVectors);
273
274 getActionDefinitionsBuilder({G_FMA, G_STRICT_FMA})
275 .legalFor(allFloatScalarsAndVectors);
276
277 getActionDefinitionsBuilder(G_STRICT_FLDEXP)
278 .legalForCartesianProduct(allFloatScalarsAndVectors, allIntScalars);
279
280 getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
281 .legalForCartesianProduct(allIntScalarsAndVectors,
282 allFloatScalarsAndVectors);
283
284 getActionDefinitionsBuilder({G_FPTOSI_SAT, G_FPTOUI_SAT})
285 .legalForCartesianProduct(allIntScalarsAndVectors,
286 allFloatScalarsAndVectors);
287
288 getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
289 .legalForCartesianProduct(allFloatScalarsAndVectors,
290 allScalarsAndVectors);
291
293 .legalForCartesianProduct(allIntScalarsAndVectors)
294 .legalIf(extendedScalarsAndVectorsProduct);
295
296 // Extensions.
297 getActionDefinitionsBuilder({G_TRUNC, G_ZEXT, G_SEXT, G_ANYEXT})
298 .legalForCartesianProduct(allScalarsAndVectors)
299 .legalIf(extendedScalarsAndVectorsProduct);
300
302 .legalFor(allPtrsScalarsAndVectors)
303 .legalIf(extendedPtrsScalarsAndVectors);
304
306 all(typeInSet(0, allPtrsScalarsAndVectors),
307 typeInSet(1, allPtrsScalarsAndVectors)));
308
309 getActionDefinitionsBuilder({G_IMPLICIT_DEF, G_FREEZE})
310 .legalFor({s1})
311 .legalFor(allFloatAndIntScalarsAndPtrs)
312 .legalFor(allowedVectorTypes)
316 0, ElementCount::getFixed(MaxVectorSize)));
317
318 getActionDefinitionsBuilder({G_STACKSAVE, G_STACKRESTORE}).alwaysLegal();
319
321 .legalForCartesianProduct(allPtrs, allIntScalars)
322 .legalIf(
323 all(typeInSet(0, allPtrs), typeOfExtendedScalars(1, IsExtendedInts)));
325 .legalForCartesianProduct(allIntScalars, allPtrs)
326 .legalIf(
327 all(typeOfExtendedScalars(0, IsExtendedInts), typeInSet(1, allPtrs)));
329 .legalForCartesianProduct(allPtrs, allIntScalars)
330 .legalIf(
331 all(typeInSet(0, allPtrs), typeOfExtendedScalars(1, IsExtendedInts)));
332
333 // ST.canDirectlyComparePointers() for pointer args is supported in
334 // legalizeCustom().
337 all(typeIs(0, p9), typeInSet(1, allPtrs), typeIsNot(1, p9)),
338 all(typeInSet(0, allPtrs), typeIsNot(0, p9), typeIs(1, p9))))
339 .customIf(all(typeInSet(0, allBoolScalarsAndVectors),
340 typeInSet(1, allPtrsScalarsAndVectors)));
341
343 all(typeInSet(0, allBoolScalarsAndVectors),
344 typeInSet(1, allFloatScalarsAndVectors)));
345
346 getActionDefinitionsBuilder({G_ATOMICRMW_OR, G_ATOMICRMW_ADD, G_ATOMICRMW_AND,
347 G_ATOMICRMW_MAX, G_ATOMICRMW_MIN,
348 G_ATOMICRMW_SUB, G_ATOMICRMW_XOR,
349 G_ATOMICRMW_UMAX, G_ATOMICRMW_UMIN})
350 .legalForCartesianProduct(allIntScalars, allPtrs);
351
353 {G_ATOMICRMW_FADD, G_ATOMICRMW_FSUB, G_ATOMICRMW_FMIN, G_ATOMICRMW_FMAX})
354 .legalForCartesianProduct(allFloatScalars, allPtrs);
355
356 getActionDefinitionsBuilder(G_ATOMICRMW_XCHG)
357 .legalForCartesianProduct(allFloatAndIntScalarsAndPtrs, allPtrs);
358
359 getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG_WITH_SUCCESS).lower();
360 // TODO: add proper legalization rules.
361 getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG).alwaysLegal();
362
364 {G_UADDO, G_SADDO, G_USUBO, G_SSUBO, G_UMULO, G_SMULO})
365 .alwaysLegal();
366
367 getActionDefinitionsBuilder({G_LROUND, G_LLROUND})
368 .legalForCartesianProduct(allFloatScalarsAndVectors,
369 allIntScalarsAndVectors);
370
371 // FP conversions.
372 getActionDefinitionsBuilder({G_FPTRUNC, G_FPEXT})
373 .legalForCartesianProduct(allFloatScalarsAndVectors);
374
375 // Pointer-handling.
376 getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0});
377
378 getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor(allPtrs);
379
380 // Control-flow. In some cases (e.g. constants) s1 may be promoted to s32.
381 getActionDefinitionsBuilder(G_BRCOND).legalFor({s1, s32});
382
384 allFloatScalarsAndVectors, {s32, v2s32, v3s32, v4s32, v8s32, v16s32});
385
386 // TODO: Review the target OpenCL and GLSL Extended Instruction Set specs to
387 // tighten these requirements. Many of these math functions are only legal on
388 // specific bitwidths, so they are not selectable for
389 // allFloatScalarsAndVectors.
390 getActionDefinitionsBuilder({G_STRICT_FSQRT,
391 G_FPOW,
392 G_FEXP,
393 G_FMODF,
394 G_FEXP2,
395 G_FLOG,
396 G_FLOG2,
397 G_FLOG10,
398 G_FABS,
399 G_FMINNUM,
400 G_FMAXNUM,
401 G_FCEIL,
402 G_FCOS,
403 G_FSIN,
404 G_FTAN,
405 G_FACOS,
406 G_FASIN,
407 G_FATAN,
408 G_FATAN2,
409 G_FCOSH,
410 G_FSINH,
411 G_FTANH,
412 G_FSQRT,
413 G_FFLOOR,
414 G_FRINT,
415 G_FNEARBYINT,
416 G_INTRINSIC_ROUND,
417 G_INTRINSIC_TRUNC,
418 G_FMINIMUM,
419 G_FMAXIMUM,
420 G_INTRINSIC_ROUNDEVEN})
421 .legalFor(allFloatScalarsAndVectors);
422
423 getActionDefinitionsBuilder(G_FCOPYSIGN)
424 .legalForCartesianProduct(allFloatScalarsAndVectors,
425 allFloatScalarsAndVectors);
426
428 allFloatScalarsAndVectors, allIntScalarsAndVectors);
429
430 if (ST.canUseExtInstSet(SPIRV::InstructionSet::OpenCL_std)) {
432 {G_CTTZ, G_CTTZ_ZERO_UNDEF, G_CTLZ, G_CTLZ_ZERO_UNDEF})
433 .legalForCartesianProduct(allIntScalarsAndVectors,
434 allIntScalarsAndVectors);
435
436 // Struct return types become a single scalar, so cannot easily legalize.
437 getActionDefinitionsBuilder({G_SMULH, G_UMULH}).alwaysLegal();
438 }
439
440 getActionDefinitionsBuilder(G_IS_FPCLASS).custom();
441
443 verify(*ST.getInstrInfo());
444}
445
448 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
449 Register DstReg = MI.getOperand(0).getReg();
450 Register SrcReg = MI.getOperand(1).getReg();
451 Register IdxReg = MI.getOperand(2).getReg();
452
453 MIRBuilder
454 .buildIntrinsic(Intrinsic::spv_extractelt, ArrayRef<Register>{DstReg})
455 .addUse(SrcReg)
456 .addUse(IdxReg);
457 MI.eraseFromParent();
458 return true;
459}
460
462 LegalizerHelper &Helper,
465 Register ConvReg = MRI.createGenericVirtualRegister(ConvTy);
466 MRI.setRegClass(ConvReg, GR->getRegClass(SpvType));
467 GR->assignSPIRVTypeToVReg(SpvType, ConvReg, Helper.MIRBuilder.getMF());
468 Helper.MIRBuilder.buildInstr(TargetOpcode::G_PTRTOINT)
469 .addDef(ConvReg)
470 .addUse(Reg);
471 return ConvReg;
472}
473
476 LostDebugLocObserver &LocObserver) const {
477 MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
478 switch (MI.getOpcode()) {
479 default:
480 // TODO: implement legalization for other opcodes.
481 return true;
482 case TargetOpcode::G_BITCAST:
483 return legalizeBitcast(Helper, MI);
484 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
485 return legalizeExtractVectorElt(Helper, MI, GR);
486 case TargetOpcode::G_INTRINSIC:
487 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
488 return legalizeIntrinsic(Helper, MI);
489 case TargetOpcode::G_IS_FPCLASS:
490 return legalizeIsFPClass(Helper, MI, LocObserver);
491 case TargetOpcode::G_ICMP: {
492 assert(GR->getSPIRVTypeForVReg(MI.getOperand(0).getReg()));
493 auto &Op0 = MI.getOperand(2);
494 auto &Op1 = MI.getOperand(3);
495 Register Reg0 = Op0.getReg();
496 Register Reg1 = Op1.getReg();
498 static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
499 if ((!ST->canDirectlyComparePointers() ||
501 MRI.getType(Reg0).isPointer() && MRI.getType(Reg1).isPointer()) {
502 LLT ConvT = LLT::scalar(ST->getPointerSize());
503 Type *LLVMTy = IntegerType::get(MI.getMF()->getFunction().getContext(),
504 ST->getPointerSize());
505 SPIRVType *SpirvTy = GR->getOrCreateSPIRVType(
506 LLVMTy, Helper.MIRBuilder, SPIRV::AccessQualifier::ReadWrite, true);
507 Op0.setReg(convertPtrToInt(Reg0, ConvT, SpirvTy, Helper, MRI, GR));
508 Op1.setReg(convertPtrToInt(Reg1, ConvT, SpirvTy, Helper, MRI, GR));
509 }
510 return true;
511 }
512 }
513}
514
516 MachineInstr &MI) const {
517 LLVM_DEBUG(dbgs() << "legalizeIntrinsic: " << MI);
518
519 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
520 MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
521 const SPIRVSubtarget &ST = MI.getMF()->getSubtarget<SPIRVSubtarget>();
522
523 auto IntrinsicID = cast<GIntrinsic>(MI).getIntrinsicID();
524 if (IntrinsicID == Intrinsic::spv_bitcast) {
525 LLVM_DEBUG(dbgs() << "Found a bitcast instruction\n");
526 Register DstReg = MI.getOperand(0).getReg();
527 Register SrcReg = MI.getOperand(2).getReg();
528 LLT DstTy = MRI.getType(DstReg);
529 LLT SrcTy = MRI.getType(SrcReg);
530
531 int32_t MaxVectorSize = ST.isShader() ? 4 : 16;
532
533 bool DstNeedsLegalization = false;
534 bool SrcNeedsLegalization = false;
535
536 if (DstTy.isVector()) {
537 if (DstTy.getNumElements() > 4 &&
538 !isPowerOf2_32(DstTy.getNumElements())) {
539 DstNeedsLegalization = true;
540 }
541
542 if (DstTy.getNumElements() > MaxVectorSize) {
543 DstNeedsLegalization = true;
544 }
545 }
546
547 if (SrcTy.isVector()) {
548 if (SrcTy.getNumElements() > 4 &&
549 !isPowerOf2_32(SrcTy.getNumElements())) {
550 SrcNeedsLegalization = true;
551 }
552
553 if (SrcTy.getNumElements() > MaxVectorSize) {
554 SrcNeedsLegalization = true;
555 }
556 }
557
558 // If an spv_bitcast needs to be legalized, we convert it to G_BITCAST to
559 // allow using the generic legalization rules.
560 if (DstNeedsLegalization || SrcNeedsLegalization) {
561 LLVM_DEBUG(dbgs() << "Replacing with a G_BITCAST\n");
562 MIRBuilder.buildBitcast(DstReg, SrcReg);
563 MI.eraseFromParent();
564 }
565 return true;
566 }
567 return true;
568}
569
570bool SPIRVLegalizerInfo::legalizeBitcast(LegalizerHelper &Helper,
571 MachineInstr &MI) const {
572 // Once the G_BITCAST is using vectors that are allowed, we turn it back into
573 // an spv_bitcast to avoid verifier problems when the register types are the
574 // same for the source and the result. Note that the SPIR-V types associated
575 // with the bitcast can be different even if the register types are the same.
576 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
577 Register DstReg = MI.getOperand(0).getReg();
578 Register SrcReg = MI.getOperand(1).getReg();
579 SmallVector<Register, 1> DstRegs = {DstReg};
580 MIRBuilder.buildIntrinsic(Intrinsic::spv_bitcast, DstRegs).addUse(SrcReg);
581 MI.eraseFromParent();
582 return true;
583}
584
585// Note this code was copied from LegalizerHelper::lowerISFPCLASS and adjusted
586// to ensure that all instructions created during the lowering have SPIR-V types
587// assigned to them.
588bool SPIRVLegalizerInfo::legalizeIsFPClass(
590 LostDebugLocObserver &LocObserver) const {
591 auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
592 FPClassTest Mask = static_cast<FPClassTest>(MI.getOperand(2).getImm());
593
594 auto &MIRBuilder = Helper.MIRBuilder;
595 auto &MF = MIRBuilder.getMF();
596 MachineRegisterInfo &MRI = MF.getRegInfo();
597
598 Type *LLVMDstTy =
599 IntegerType::get(MIRBuilder.getContext(), DstTy.getScalarSizeInBits());
600 if (DstTy.isVector())
601 LLVMDstTy = VectorType::get(LLVMDstTy, DstTy.getElementCount());
602 SPIRVType *SPIRVDstTy = GR->getOrCreateSPIRVType(
603 LLVMDstTy, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
604 /*EmitIR*/ true);
605
606 unsigned BitSize = SrcTy.getScalarSizeInBits();
607 const fltSemantics &Semantics = getFltSemanticForLLT(SrcTy.getScalarType());
608
609 LLT IntTy = LLT::scalar(BitSize);
610 Type *LLVMIntTy = IntegerType::get(MIRBuilder.getContext(), BitSize);
611 if (SrcTy.isVector()) {
612 IntTy = LLT::vector(SrcTy.getElementCount(), IntTy);
613 LLVMIntTy = VectorType::get(LLVMIntTy, SrcTy.getElementCount());
614 }
615 SPIRVType *SPIRVIntTy = GR->getOrCreateSPIRVType(
616 LLVMIntTy, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
617 /*EmitIR*/ true);
618
619 // Clang doesn't support capture of structured bindings:
620 LLT DstTyCopy = DstTy;
621 const auto assignSPIRVTy = [&](MachineInstrBuilder &&MI) {
622 // Assign this MI's (assumed only) destination to one of the two types we
623 // expect: either the G_IS_FPCLASS's destination type, or the integer type
624 // bitcast from the source type.
625 LLT MITy = MRI.getType(MI.getReg(0));
626 assert((MITy == IntTy || MITy == DstTyCopy) &&
627 "Unexpected LLT type while lowering G_IS_FPCLASS");
628 auto *SPVTy = MITy == IntTy ? SPIRVIntTy : SPIRVDstTy;
629 GR->assignSPIRVTypeToVReg(SPVTy, MI.getReg(0), MF);
630 return MI;
631 };
632
633 // Helper to build and assign a constant in one go
634 const auto buildSPIRVConstant = [&](LLT Ty, auto &&C) -> MachineInstrBuilder {
635 if (!Ty.isFixedVector())
636 return assignSPIRVTy(MIRBuilder.buildConstant(Ty, C));
637 auto ScalarC = MIRBuilder.buildConstant(Ty.getScalarType(), C);
638 assert((Ty == IntTy || Ty == DstTyCopy) &&
639 "Unexpected LLT type while lowering constant for G_IS_FPCLASS");
640 SPIRVType *VecEltTy = GR->getOrCreateSPIRVType(
641 (Ty == IntTy ? LLVMIntTy : LLVMDstTy)->getScalarType(), MIRBuilder,
642 SPIRV::AccessQualifier::ReadWrite,
643 /*EmitIR*/ true);
644 GR->assignSPIRVTypeToVReg(VecEltTy, ScalarC.getReg(0), MF);
645 return assignSPIRVTy(MIRBuilder.buildSplatBuildVector(Ty, ScalarC));
646 };
647
648 if (Mask == fcNone) {
649 MIRBuilder.buildCopy(DstReg, buildSPIRVConstant(DstTy, 0));
650 MI.eraseFromParent();
651 return true;
652 }
653 if (Mask == fcAllFlags) {
654 MIRBuilder.buildCopy(DstReg, buildSPIRVConstant(DstTy, 1));
655 MI.eraseFromParent();
656 return true;
657 }
658
659 // Note that rather than creating a COPY here (between a floating-point and
660 // integer type of the same size) we create a SPIR-V bitcast immediately. We
661 // can't create a G_BITCAST because the LLTs are the same, and we can't seem
662 // to correctly lower COPYs to SPIR-V bitcasts at this moment.
663 Register ResVReg = MRI.createGenericVirtualRegister(IntTy);
664 MRI.setRegClass(ResVReg, GR->getRegClass(SPIRVIntTy));
665 GR->assignSPIRVTypeToVReg(SPIRVIntTy, ResVReg, Helper.MIRBuilder.getMF());
666 auto AsInt = MIRBuilder.buildInstr(SPIRV::OpBitcast)
667 .addDef(ResVReg)
668 .addUse(GR->getSPIRVTypeID(SPIRVIntTy))
669 .addUse(SrcReg);
670 AsInt = assignSPIRVTy(std::move(AsInt));
671
672 // Various masks.
673 APInt SignBit = APInt::getSignMask(BitSize);
674 APInt ValueMask = APInt::getSignedMaxValue(BitSize); // All bits but sign.
675 APInt Inf = APFloat::getInf(Semantics).bitcastToAPInt(); // Exp and int bit.
676 APInt ExpMask = Inf;
677 APInt AllOneMantissa = APFloat::getLargest(Semantics).bitcastToAPInt() & ~Inf;
678 APInt QNaNBitMask =
679 APInt::getOneBitSet(BitSize, AllOneMantissa.getActiveBits() - 1);
680 APInt InversionMask = APInt::getAllOnes(DstTy.getScalarSizeInBits());
681
682 auto SignBitC = buildSPIRVConstant(IntTy, SignBit);
683 auto ValueMaskC = buildSPIRVConstant(IntTy, ValueMask);
684 auto InfC = buildSPIRVConstant(IntTy, Inf);
685 auto ExpMaskC = buildSPIRVConstant(IntTy, ExpMask);
686 auto ZeroC = buildSPIRVConstant(IntTy, 0);
687
688 auto Abs = assignSPIRVTy(MIRBuilder.buildAnd(IntTy, AsInt, ValueMaskC));
689 auto Sign = assignSPIRVTy(
690 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_NE, DstTy, AsInt, Abs));
691
692 auto Res = buildSPIRVConstant(DstTy, 0);
693
694 const auto appendToRes = [&](MachineInstrBuilder &&ToAppend) {
695 Res = assignSPIRVTy(
696 MIRBuilder.buildOr(DstTyCopy, Res, assignSPIRVTy(std::move(ToAppend))));
697 };
698
699 // Tests that involve more than one class should be processed first.
700 if ((Mask & fcFinite) == fcFinite) {
701 // finite(V) ==> abs(V) u< exp_mask
702 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, Abs,
703 ExpMaskC));
704 Mask &= ~fcFinite;
705 } else if ((Mask & fcFinite) == fcPosFinite) {
706 // finite(V) && V > 0 ==> V u< exp_mask
707 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, AsInt,
708 ExpMaskC));
709 Mask &= ~fcPosFinite;
710 } else if ((Mask & fcFinite) == fcNegFinite) {
711 // finite(V) && V < 0 ==> abs(V) u< exp_mask && signbit == 1
712 auto Cmp = assignSPIRVTy(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT,
713 DstTy, Abs, ExpMaskC));
714 appendToRes(MIRBuilder.buildAnd(DstTy, Cmp, Sign));
715 Mask &= ~fcNegFinite;
716 }
717
718 if (FPClassTest PartialCheck = Mask & (fcZero | fcSubnormal)) {
719 // fcZero | fcSubnormal => test all exponent bits are 0
720 // TODO: Handle sign bit specific cases
721 // TODO: Handle inverted case
722 if (PartialCheck == (fcZero | fcSubnormal)) {
723 auto ExpBits = assignSPIRVTy(MIRBuilder.buildAnd(IntTy, AsInt, ExpMaskC));
724 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
725 ExpBits, ZeroC));
726 Mask &= ~PartialCheck;
727 }
728 }
729
730 // Check for individual classes.
731 if (FPClassTest PartialCheck = Mask & fcZero) {
732 if (PartialCheck == fcPosZero)
733 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
734 AsInt, ZeroC));
735 else if (PartialCheck == fcZero)
736 appendToRes(
737 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy, Abs, ZeroC));
738 else // fcNegZero
739 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
740 AsInt, SignBitC));
741 }
742
743 if (FPClassTest PartialCheck = Mask & fcSubnormal) {
744 // issubnormal(V) ==> unsigned(abs(V) - 1) u< (all mantissa bits set)
745 // issubnormal(V) && V>0 ==> unsigned(V - 1) u< (all mantissa bits set)
746 auto V = (PartialCheck == fcPosSubnormal) ? AsInt : Abs;
747 auto OneC = buildSPIRVConstant(IntTy, 1);
748 auto VMinusOne = MIRBuilder.buildSub(IntTy, V, OneC);
749 auto SubnormalRes = assignSPIRVTy(
750 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, VMinusOne,
751 buildSPIRVConstant(IntTy, AllOneMantissa)));
752 if (PartialCheck == fcNegSubnormal)
753 SubnormalRes = MIRBuilder.buildAnd(DstTy, SubnormalRes, Sign);
754 appendToRes(std::move(SubnormalRes));
755 }
756
757 if (FPClassTest PartialCheck = Mask & fcInf) {
758 if (PartialCheck == fcPosInf)
759 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
760 AsInt, InfC));
761 else if (PartialCheck == fcInf)
762 appendToRes(
763 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy, Abs, InfC));
764 else { // fcNegInf
765 APInt NegInf = APFloat::getInf(Semantics, true).bitcastToAPInt();
766 auto NegInfC = buildSPIRVConstant(IntTy, NegInf);
767 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
768 AsInt, NegInfC));
769 }
770 }
771
772 if (FPClassTest PartialCheck = Mask & fcNan) {
773 auto InfWithQnanBitC =
774 buildSPIRVConstant(IntTy, std::move(Inf) | QNaNBitMask);
775 if (PartialCheck == fcNan) {
776 // isnan(V) ==> abs(V) u> int(inf)
777 appendToRes(
778 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGT, DstTy, Abs, InfC));
779 } else if (PartialCheck == fcQNan) {
780 // isquiet(V) ==> abs(V) u>= (unsigned(Inf) | quiet_bit)
781 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGE, DstTy, Abs,
782 InfWithQnanBitC));
783 } else { // fcSNan
784 // issignaling(V) ==> abs(V) u> unsigned(Inf) &&
785 // abs(V) u< (unsigned(Inf) | quiet_bit)
786 auto IsNan = assignSPIRVTy(
787 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGT, DstTy, Abs, InfC));
788 auto IsNotQnan = assignSPIRVTy(MIRBuilder.buildICmp(
789 CmpInst::Predicate::ICMP_ULT, DstTy, Abs, InfWithQnanBitC));
790 appendToRes(MIRBuilder.buildAnd(DstTy, IsNan, IsNotQnan));
791 }
792 }
793
794 if (FPClassTest PartialCheck = Mask & fcNormal) {
795 // isnormal(V) ==> (0 u< exp u< max_exp) ==> (unsigned(exp-1) u<
796 // (max_exp-1))
797 APInt ExpLSB = ExpMask & ~(ExpMask.shl(1));
798 auto ExpMinusOne = assignSPIRVTy(
799 MIRBuilder.buildSub(IntTy, Abs, buildSPIRVConstant(IntTy, ExpLSB)));
800 APInt MaxExpMinusOne = std::move(ExpMask) - ExpLSB;
801 auto NormalRes = assignSPIRVTy(
802 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, ExpMinusOne,
803 buildSPIRVConstant(IntTy, MaxExpMinusOne)));
804 if (PartialCheck == fcNegNormal)
805 NormalRes = MIRBuilder.buildAnd(DstTy, NormalRes, Sign);
806 else if (PartialCheck == fcPosNormal) {
807 auto PosSign = assignSPIRVTy(MIRBuilder.buildXor(
808 DstTy, Sign, buildSPIRVConstant(DstTy, InversionMask)));
809 NormalRes = MIRBuilder.buildAnd(DstTy, NormalRes, PosSign);
810 }
811 appendToRes(std::move(NormalRes));
812 }
813
814 MIRBuilder.buildCopy(DstReg, Res);
815 MI.eraseFromParent();
816 return true;
817}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void scalarize(Instruction *I, SmallVectorImpl< Instruction * > &Worklist)
Definition ExpandFp.cpp:921
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
IRTranslator LLVM IR MI
This file declares the MachineIRBuilder class.
Register Reg
Promote Memory to Register
Definition Mem2Reg.cpp:110
ppc ctr loops verify
const SmallVectorImpl< MachineOperand > & Cond
static Register convertPtrToInt(Register Reg, LLT ConvTy, SPIRVType *SpvType, LegalizerHelper &Helper, MachineRegisterInfo &MRI, SPIRVGlobalRegistry *GR)
LegalityPredicate typeOfExtendedScalars(unsigned TypeIdx, bool IsExtendedInts)
static bool legalizeExtractVectorElt(LegalizerHelper &Helper, MachineInstr &MI, SPIRVGlobalRegistry *GR)
#define LLVM_DEBUG(...)
Definition Debug.h:114
APInt bitcastToAPInt() const
Definition APFloat.h:1335
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
Definition APFloat.h:1120
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Definition APFloat.h:1080
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:235
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
Definition APInt.h:230
unsigned getActiveBits() const
Compute the number of active bits in the value.
Definition APInt.h:1513
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
Definition APInt.h:210
APInt shl(unsigned shiftAmt) const
Left-shift function.
Definition APInt.h:874
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Definition APInt.h:240
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:676
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:700
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:699
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:701
@ ICMP_NE
not equal
Definition InstrTypes.h:698
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:318
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
constexpr uint16_t getNumElements() const
Returns the number of elements in a vector LLT.
constexpr bool isVector() const
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
constexpr bool isPointerOrPointerVector() const
constexpr bool isFixedVector() const
Returns true if the LLT is a fixed vector.
constexpr LLT getScalarType() const
LLVM_ABI void computeTables()
Compute any ancillary tables needed to quickly decide how an operation should be handled.
LegalizeRuleSet & legalFor(std::initializer_list< LLT > Types)
The instruction is legal when type index 0 is any type in the given list.
LegalizeRuleSet & fewerElementsIf(LegalityPredicate Predicate, LegalizeMutation Mutation)
Remove elements to reach the type selected by the mutation if the predicate is true.
LegalizeRuleSet & moreElementsToNextPow2(unsigned TypeIdx)
Add more elements to the vector to reach the next power of two.
LegalizeRuleSet & lower()
The instruction is lowered.
LegalizeRuleSet & lowerIf(LegalityPredicate Predicate)
The instruction is lowered if predicate is true.
LegalizeRuleSet & custom()
Unconditionally custom lower.
LegalizeRuleSet & unsupportedIf(LegalityPredicate Predicate)
LegalizeRuleSet & alwaysLegal()
LegalizeRuleSet & customIf(LegalityPredicate Predicate)
LegalizeRuleSet & scalarize(unsigned TypeIdx)
LegalizeRuleSet & legalForCartesianProduct(std::initializer_list< LLT > Types)
The instruction is legal when type indexes 0 and 1 are both in the given list.
LegalizeRuleSet & legalIf(LegalityPredicate Predicate)
The instruction is legal if predicate is true.
MachineIRBuilder & MIRBuilder
Expose MIRBuilder so clients can set their own RecordInsertInstruction functions.
LegalizeRuleSet & getActionDefinitionsBuilder(unsigned Opcode)
Get the action definition builder for the given opcode.
const LegacyLegalizerInfo & getLegacyLegalizerInfo() const
Helper class to build MachineInstr.
LLVMContext & getContext() const
MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_AND Op0, Op1.
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_SUB Op0, Op1.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef< Register > Res, bool HasSideEffects, bool isConvergent)
Build and insert a G_INTRINSIC instruction.
MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src)
Build and insert Dst = G_BITCAST Src.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_OR Op0, Op1.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1)
Build and insert Res = G_XOR Op0, Op1.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, const MachineFunction &MF)
const TargetRegisterClass * getRegClass(SPIRVType *SpvType) const
SPIRVLegalizerInfo(const SPIRVSubtarget &ST)
bool legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, LostDebugLocObserver &LocObserver) const override
Called for instructions with the Custom LegalizationAction.
bool legalizeIntrinsic(LegalizerHelper &Helper, MachineInstr &MI) const override
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI LegalityPredicate vectorElementCountIsLessThanOrEqualTo(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a vector with a number of elements that's less than or equal to ...
LLVM_ABI LegalityPredicate typeInSet(unsigned TypeIdx, std::initializer_list< LLT > TypesInit)
True iff the given type index is one of the specified types.
LLVM_ABI LegalityPredicate vectorElementCountIsGreaterThan(unsigned TypeIdx, unsigned Size)
True iff the specified type index is a vector with a number of elements that's greater than the given...
Predicate any(Predicate P0, Predicate P1)
True iff P0 or P1 are true.
LegalityPredicate typeIsNot(unsigned TypeIdx, LLT Type)
True iff the given type index is not the specified type.
Predicate all(Predicate P0, Predicate P1)
True iff P0 and P1 are true.
LLVM_ABI LegalityPredicate typeIs(unsigned TypeIdx, LLT TypesInit)
True iff the given type index is the specified type.
LLVM_ABI LegalizeMutation changeElementCountTo(unsigned TypeIdx, unsigned FromTypeIdx)
Keep the same scalar or element type as TypeIdx, but take the number of elements from FromTypeIdx.
LLVM_ABI LegalizeMutation changeElementSizeTo(unsigned TypeIdx, unsigned FromTypeIdx)
Change the scalar size or element size to have the same scalar size as type index FromIndex.
Invariant opcodes: All instruction sets have these as their low opcodes.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI const llvm::fltSemantics & getFltSemanticForLLT(LLT Ty)
Get the appropriate floating point arithmetic semantic based on the bit size of the given scalar LLT.
std::function< bool(const LegalityQuery &)> LegalityPredicate
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
const MachineInstr SPIRVType
const std::set< unsigned > & getTypeFoldingSupportedOpcodes()
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
The LegalityQuery object bundles together all the information that's needed to decide whether a given...