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 allFloatScalarsAndF16Vector2AndVector4s = {s16, s32, s64, v2s16, v4s16};
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(allFloatScalarsAndF16Vector2AndVector4s,
355 allPtrs);
356
357 getActionDefinitionsBuilder(G_ATOMICRMW_XCHG)
358 .legalForCartesianProduct(allFloatAndIntScalarsAndPtrs, allPtrs);
359
360 getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG_WITH_SUCCESS).lower();
361 // TODO: add proper legalization rules.
362 getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG).alwaysLegal();
363
365 {G_UADDO, G_SADDO, G_USUBO, G_SSUBO, G_UMULO, G_SMULO})
366 .alwaysLegal();
367
368 getActionDefinitionsBuilder({G_LROUND, G_LLROUND})
369 .legalForCartesianProduct(allFloatScalarsAndVectors,
370 allIntScalarsAndVectors);
371
372 // FP conversions.
373 getActionDefinitionsBuilder({G_FPTRUNC, G_FPEXT})
374 .legalForCartesianProduct(allFloatScalarsAndVectors);
375
376 // Pointer-handling.
377 getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0});
378
379 getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor(allPtrs);
380
381 // Control-flow. In some cases (e.g. constants) s1 may be promoted to s32.
382 getActionDefinitionsBuilder(G_BRCOND).legalFor({s1, s32});
383
385 allFloatScalarsAndVectors, {s32, v2s32, v3s32, v4s32, v8s32, v16s32});
386
387 // TODO: Review the target OpenCL and GLSL Extended Instruction Set specs to
388 // tighten these requirements. Many of these math functions are only legal on
389 // specific bitwidths, so they are not selectable for
390 // allFloatScalarsAndVectors.
391 getActionDefinitionsBuilder({G_STRICT_FSQRT,
392 G_FPOW,
393 G_FEXP,
394 G_FMODF,
395 G_FEXP2,
396 G_FLOG,
397 G_FLOG2,
398 G_FLOG10,
399 G_FABS,
400 G_FMINNUM,
401 G_FMAXNUM,
402 G_FCEIL,
403 G_FCOS,
404 G_FSIN,
405 G_FTAN,
406 G_FACOS,
407 G_FASIN,
408 G_FATAN,
409 G_FATAN2,
410 G_FCOSH,
411 G_FSINH,
412 G_FTANH,
413 G_FSQRT,
414 G_FFLOOR,
415 G_FRINT,
416 G_FNEARBYINT,
417 G_INTRINSIC_ROUND,
418 G_INTRINSIC_TRUNC,
419 G_FMINIMUM,
420 G_FMAXIMUM,
421 G_INTRINSIC_ROUNDEVEN})
422 .legalFor(allFloatScalarsAndVectors);
423
424 getActionDefinitionsBuilder(G_FCOPYSIGN)
425 .legalForCartesianProduct(allFloatScalarsAndVectors,
426 allFloatScalarsAndVectors);
427
429 allFloatScalarsAndVectors, allIntScalarsAndVectors);
430
431 if (ST.canUseExtInstSet(SPIRV::InstructionSet::OpenCL_std)) {
433 {G_CTTZ, G_CTTZ_ZERO_UNDEF, G_CTLZ, G_CTLZ_ZERO_UNDEF})
434 .legalForCartesianProduct(allIntScalarsAndVectors,
435 allIntScalarsAndVectors);
436
437 // Struct return types become a single scalar, so cannot easily legalize.
438 getActionDefinitionsBuilder({G_SMULH, G_UMULH}).alwaysLegal();
439 }
440
441 getActionDefinitionsBuilder(G_IS_FPCLASS).custom();
442
444 verify(*ST.getInstrInfo());
445}
446
449 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
450 Register DstReg = MI.getOperand(0).getReg();
451 Register SrcReg = MI.getOperand(1).getReg();
452 Register IdxReg = MI.getOperand(2).getReg();
453
454 MIRBuilder
455 .buildIntrinsic(Intrinsic::spv_extractelt, ArrayRef<Register>{DstReg})
456 .addUse(SrcReg)
457 .addUse(IdxReg);
458 MI.eraseFromParent();
459 return true;
460}
461
463 LegalizerHelper &Helper,
466 Register ConvReg = MRI.createGenericVirtualRegister(ConvTy);
467 MRI.setRegClass(ConvReg, GR->getRegClass(SpvType));
468 GR->assignSPIRVTypeToVReg(SpvType, ConvReg, Helper.MIRBuilder.getMF());
469 Helper.MIRBuilder.buildInstr(TargetOpcode::G_PTRTOINT)
470 .addDef(ConvReg)
471 .addUse(Reg);
472 return ConvReg;
473}
474
477 LostDebugLocObserver &LocObserver) const {
478 MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
479 switch (MI.getOpcode()) {
480 default:
481 // TODO: implement legalization for other opcodes.
482 return true;
483 case TargetOpcode::G_BITCAST:
484 return legalizeBitcast(Helper, MI);
485 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
486 return legalizeExtractVectorElt(Helper, MI, GR);
487 case TargetOpcode::G_INTRINSIC:
488 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
489 return legalizeIntrinsic(Helper, MI);
490 case TargetOpcode::G_IS_FPCLASS:
491 return legalizeIsFPClass(Helper, MI, LocObserver);
492 case TargetOpcode::G_ICMP: {
493 assert(GR->getSPIRVTypeForVReg(MI.getOperand(0).getReg()));
494 auto &Op0 = MI.getOperand(2);
495 auto &Op1 = MI.getOperand(3);
496 Register Reg0 = Op0.getReg();
497 Register Reg1 = Op1.getReg();
499 static_cast<CmpInst::Predicate>(MI.getOperand(1).getPredicate());
500 if ((!ST->canDirectlyComparePointers() ||
502 MRI.getType(Reg0).isPointer() && MRI.getType(Reg1).isPointer()) {
503 LLT ConvT = LLT::scalar(ST->getPointerSize());
504 Type *LLVMTy = IntegerType::get(MI.getMF()->getFunction().getContext(),
505 ST->getPointerSize());
506 SPIRVType *SpirvTy = GR->getOrCreateSPIRVType(
507 LLVMTy, Helper.MIRBuilder, SPIRV::AccessQualifier::ReadWrite, true);
508 Op0.setReg(convertPtrToInt(Reg0, ConvT, SpirvTy, Helper, MRI, GR));
509 Op1.setReg(convertPtrToInt(Reg1, ConvT, SpirvTy, Helper, MRI, GR));
510 }
511 return true;
512 }
513 }
514}
515
517 MachineInstr &MI) const {
518 LLVM_DEBUG(dbgs() << "legalizeIntrinsic: " << MI);
519
520 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
521 MachineRegisterInfo &MRI = *MIRBuilder.getMRI();
522 const SPIRVSubtarget &ST = MI.getMF()->getSubtarget<SPIRVSubtarget>();
523
524 auto IntrinsicID = cast<GIntrinsic>(MI).getIntrinsicID();
525 if (IntrinsicID == Intrinsic::spv_bitcast) {
526 LLVM_DEBUG(dbgs() << "Found a bitcast instruction\n");
527 Register DstReg = MI.getOperand(0).getReg();
528 Register SrcReg = MI.getOperand(2).getReg();
529 LLT DstTy = MRI.getType(DstReg);
530 LLT SrcTy = MRI.getType(SrcReg);
531
532 int32_t MaxVectorSize = ST.isShader() ? 4 : 16;
533
534 bool DstNeedsLegalization = false;
535 bool SrcNeedsLegalization = false;
536
537 if (DstTy.isVector()) {
538 if (DstTy.getNumElements() > 4 &&
539 !isPowerOf2_32(DstTy.getNumElements())) {
540 DstNeedsLegalization = true;
541 }
542
543 if (DstTy.getNumElements() > MaxVectorSize) {
544 DstNeedsLegalization = true;
545 }
546 }
547
548 if (SrcTy.isVector()) {
549 if (SrcTy.getNumElements() > 4 &&
550 !isPowerOf2_32(SrcTy.getNumElements())) {
551 SrcNeedsLegalization = true;
552 }
553
554 if (SrcTy.getNumElements() > MaxVectorSize) {
555 SrcNeedsLegalization = true;
556 }
557 }
558
559 // If an spv_bitcast needs to be legalized, we convert it to G_BITCAST to
560 // allow using the generic legalization rules.
561 if (DstNeedsLegalization || SrcNeedsLegalization) {
562 LLVM_DEBUG(dbgs() << "Replacing with a G_BITCAST\n");
563 MIRBuilder.buildBitcast(DstReg, SrcReg);
564 MI.eraseFromParent();
565 }
566 return true;
567 }
568 return true;
569}
570
571bool SPIRVLegalizerInfo::legalizeBitcast(LegalizerHelper &Helper,
572 MachineInstr &MI) const {
573 // Once the G_BITCAST is using vectors that are allowed, we turn it back into
574 // an spv_bitcast to avoid verifier problems when the register types are the
575 // same for the source and the result. Note that the SPIR-V types associated
576 // with the bitcast can be different even if the register types are the same.
577 MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
578 Register DstReg = MI.getOperand(0).getReg();
579 Register SrcReg = MI.getOperand(1).getReg();
580 SmallVector<Register, 1> DstRegs = {DstReg};
581 MIRBuilder.buildIntrinsic(Intrinsic::spv_bitcast, DstRegs).addUse(SrcReg);
582 MI.eraseFromParent();
583 return true;
584}
585
586// Note this code was copied from LegalizerHelper::lowerISFPCLASS and adjusted
587// to ensure that all instructions created during the lowering have SPIR-V types
588// assigned to them.
589bool SPIRVLegalizerInfo::legalizeIsFPClass(
591 LostDebugLocObserver &LocObserver) const {
592 auto [DstReg, DstTy, SrcReg, SrcTy] = MI.getFirst2RegLLTs();
593 FPClassTest Mask = static_cast<FPClassTest>(MI.getOperand(2).getImm());
594
595 auto &MIRBuilder = Helper.MIRBuilder;
596 auto &MF = MIRBuilder.getMF();
597 MachineRegisterInfo &MRI = MF.getRegInfo();
598
599 Type *LLVMDstTy =
600 IntegerType::get(MIRBuilder.getContext(), DstTy.getScalarSizeInBits());
601 if (DstTy.isVector())
602 LLVMDstTy = VectorType::get(LLVMDstTy, DstTy.getElementCount());
603 SPIRVType *SPIRVDstTy = GR->getOrCreateSPIRVType(
604 LLVMDstTy, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
605 /*EmitIR*/ true);
606
607 unsigned BitSize = SrcTy.getScalarSizeInBits();
608 const fltSemantics &Semantics = getFltSemanticForLLT(SrcTy.getScalarType());
609
610 LLT IntTy = LLT::scalar(BitSize);
611 Type *LLVMIntTy = IntegerType::get(MIRBuilder.getContext(), BitSize);
612 if (SrcTy.isVector()) {
613 IntTy = LLT::vector(SrcTy.getElementCount(), IntTy);
614 LLVMIntTy = VectorType::get(LLVMIntTy, SrcTy.getElementCount());
615 }
616 SPIRVType *SPIRVIntTy = GR->getOrCreateSPIRVType(
617 LLVMIntTy, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
618 /*EmitIR*/ true);
619
620 // Clang doesn't support capture of structured bindings:
621 LLT DstTyCopy = DstTy;
622 const auto assignSPIRVTy = [&](MachineInstrBuilder &&MI) {
623 // Assign this MI's (assumed only) destination to one of the two types we
624 // expect: either the G_IS_FPCLASS's destination type, or the integer type
625 // bitcast from the source type.
626 LLT MITy = MRI.getType(MI.getReg(0));
627 assert((MITy == IntTy || MITy == DstTyCopy) &&
628 "Unexpected LLT type while lowering G_IS_FPCLASS");
629 auto *SPVTy = MITy == IntTy ? SPIRVIntTy : SPIRVDstTy;
630 GR->assignSPIRVTypeToVReg(SPVTy, MI.getReg(0), MF);
631 return MI;
632 };
633
634 // Helper to build and assign a constant in one go
635 const auto buildSPIRVConstant = [&](LLT Ty, auto &&C) -> MachineInstrBuilder {
636 if (!Ty.isFixedVector())
637 return assignSPIRVTy(MIRBuilder.buildConstant(Ty, C));
638 auto ScalarC = MIRBuilder.buildConstant(Ty.getScalarType(), C);
639 assert((Ty == IntTy || Ty == DstTyCopy) &&
640 "Unexpected LLT type while lowering constant for G_IS_FPCLASS");
641 SPIRVType *VecEltTy = GR->getOrCreateSPIRVType(
642 (Ty == IntTy ? LLVMIntTy : LLVMDstTy)->getScalarType(), MIRBuilder,
643 SPIRV::AccessQualifier::ReadWrite,
644 /*EmitIR*/ true);
645 GR->assignSPIRVTypeToVReg(VecEltTy, ScalarC.getReg(0), MF);
646 return assignSPIRVTy(MIRBuilder.buildSplatBuildVector(Ty, ScalarC));
647 };
648
649 if (Mask == fcNone) {
650 MIRBuilder.buildCopy(DstReg, buildSPIRVConstant(DstTy, 0));
651 MI.eraseFromParent();
652 return true;
653 }
654 if (Mask == fcAllFlags) {
655 MIRBuilder.buildCopy(DstReg, buildSPIRVConstant(DstTy, 1));
656 MI.eraseFromParent();
657 return true;
658 }
659
660 // Note that rather than creating a COPY here (between a floating-point and
661 // integer type of the same size) we create a SPIR-V bitcast immediately. We
662 // can't create a G_BITCAST because the LLTs are the same, and we can't seem
663 // to correctly lower COPYs to SPIR-V bitcasts at this moment.
664 Register ResVReg = MRI.createGenericVirtualRegister(IntTy);
665 MRI.setRegClass(ResVReg, GR->getRegClass(SPIRVIntTy));
666 GR->assignSPIRVTypeToVReg(SPIRVIntTy, ResVReg, Helper.MIRBuilder.getMF());
667 auto AsInt = MIRBuilder.buildInstr(SPIRV::OpBitcast)
668 .addDef(ResVReg)
669 .addUse(GR->getSPIRVTypeID(SPIRVIntTy))
670 .addUse(SrcReg);
671 AsInt = assignSPIRVTy(std::move(AsInt));
672
673 // Various masks.
674 APInt SignBit = APInt::getSignMask(BitSize);
675 APInt ValueMask = APInt::getSignedMaxValue(BitSize); // All bits but sign.
676 APInt Inf = APFloat::getInf(Semantics).bitcastToAPInt(); // Exp and int bit.
677 APInt ExpMask = Inf;
678 APInt AllOneMantissa = APFloat::getLargest(Semantics).bitcastToAPInt() & ~Inf;
679 APInt QNaNBitMask =
680 APInt::getOneBitSet(BitSize, AllOneMantissa.getActiveBits() - 1);
681 APInt InversionMask = APInt::getAllOnes(DstTy.getScalarSizeInBits());
682
683 auto SignBitC = buildSPIRVConstant(IntTy, SignBit);
684 auto ValueMaskC = buildSPIRVConstant(IntTy, ValueMask);
685 auto InfC = buildSPIRVConstant(IntTy, Inf);
686 auto ExpMaskC = buildSPIRVConstant(IntTy, ExpMask);
687 auto ZeroC = buildSPIRVConstant(IntTy, 0);
688
689 auto Abs = assignSPIRVTy(MIRBuilder.buildAnd(IntTy, AsInt, ValueMaskC));
690 auto Sign = assignSPIRVTy(
691 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_NE, DstTy, AsInt, Abs));
692
693 auto Res = buildSPIRVConstant(DstTy, 0);
694
695 const auto appendToRes = [&](MachineInstrBuilder &&ToAppend) {
696 Res = assignSPIRVTy(
697 MIRBuilder.buildOr(DstTyCopy, Res, assignSPIRVTy(std::move(ToAppend))));
698 };
699
700 // Tests that involve more than one class should be processed first.
701 if ((Mask & fcFinite) == fcFinite) {
702 // finite(V) ==> abs(V) u< exp_mask
703 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, Abs,
704 ExpMaskC));
705 Mask &= ~fcFinite;
706 } else if ((Mask & fcFinite) == fcPosFinite) {
707 // finite(V) && V > 0 ==> V u< exp_mask
708 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, AsInt,
709 ExpMaskC));
710 Mask &= ~fcPosFinite;
711 } else if ((Mask & fcFinite) == fcNegFinite) {
712 // finite(V) && V < 0 ==> abs(V) u< exp_mask && signbit == 1
713 auto Cmp = assignSPIRVTy(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT,
714 DstTy, Abs, ExpMaskC));
715 appendToRes(MIRBuilder.buildAnd(DstTy, Cmp, Sign));
716 Mask &= ~fcNegFinite;
717 }
718
719 if (FPClassTest PartialCheck = Mask & (fcZero | fcSubnormal)) {
720 // fcZero | fcSubnormal => test all exponent bits are 0
721 // TODO: Handle sign bit specific cases
722 // TODO: Handle inverted case
723 if (PartialCheck == (fcZero | fcSubnormal)) {
724 auto ExpBits = assignSPIRVTy(MIRBuilder.buildAnd(IntTy, AsInt, ExpMaskC));
725 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
726 ExpBits, ZeroC));
727 Mask &= ~PartialCheck;
728 }
729 }
730
731 // Check for individual classes.
732 if (FPClassTest PartialCheck = Mask & fcZero) {
733 if (PartialCheck == fcPosZero)
734 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
735 AsInt, ZeroC));
736 else if (PartialCheck == fcZero)
737 appendToRes(
738 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy, Abs, ZeroC));
739 else // fcNegZero
740 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
741 AsInt, SignBitC));
742 }
743
744 if (FPClassTest PartialCheck = Mask & fcSubnormal) {
745 // issubnormal(V) ==> unsigned(abs(V) - 1) u< (all mantissa bits set)
746 // issubnormal(V) && V>0 ==> unsigned(V - 1) u< (all mantissa bits set)
747 auto V = (PartialCheck == fcPosSubnormal) ? AsInt : Abs;
748 auto OneC = buildSPIRVConstant(IntTy, 1);
749 auto VMinusOne = MIRBuilder.buildSub(IntTy, V, OneC);
750 auto SubnormalRes = assignSPIRVTy(
751 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, VMinusOne,
752 buildSPIRVConstant(IntTy, AllOneMantissa)));
753 if (PartialCheck == fcNegSubnormal)
754 SubnormalRes = MIRBuilder.buildAnd(DstTy, SubnormalRes, Sign);
755 appendToRes(std::move(SubnormalRes));
756 }
757
758 if (FPClassTest PartialCheck = Mask & fcInf) {
759 if (PartialCheck == fcPosInf)
760 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
761 AsInt, InfC));
762 else if (PartialCheck == fcInf)
763 appendToRes(
764 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy, Abs, InfC));
765 else { // fcNegInf
766 APInt NegInf = APFloat::getInf(Semantics, true).bitcastToAPInt();
767 auto NegInfC = buildSPIRVConstant(IntTy, NegInf);
768 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_EQ, DstTy,
769 AsInt, NegInfC));
770 }
771 }
772
773 if (FPClassTest PartialCheck = Mask & fcNan) {
774 auto InfWithQnanBitC =
775 buildSPIRVConstant(IntTy, std::move(Inf) | QNaNBitMask);
776 if (PartialCheck == fcNan) {
777 // isnan(V) ==> abs(V) u> int(inf)
778 appendToRes(
779 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGT, DstTy, Abs, InfC));
780 } else if (PartialCheck == fcQNan) {
781 // isquiet(V) ==> abs(V) u>= (unsigned(Inf) | quiet_bit)
782 appendToRes(MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGE, DstTy, Abs,
783 InfWithQnanBitC));
784 } else { // fcSNan
785 // issignaling(V) ==> abs(V) u> unsigned(Inf) &&
786 // abs(V) u< (unsigned(Inf) | quiet_bit)
787 auto IsNan = assignSPIRVTy(
788 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_UGT, DstTy, Abs, InfC));
789 auto IsNotQnan = assignSPIRVTy(MIRBuilder.buildICmp(
790 CmpInst::Predicate::ICMP_ULT, DstTy, Abs, InfWithQnanBitC));
791 appendToRes(MIRBuilder.buildAnd(DstTy, IsNan, IsNotQnan));
792 }
793 }
794
795 if (FPClassTest PartialCheck = Mask & fcNormal) {
796 // isnormal(V) ==> (0 u< exp u< max_exp) ==> (unsigned(exp-1) u<
797 // (max_exp-1))
798 APInt ExpLSB = ExpMask & ~(ExpMask.shl(1));
799 auto ExpMinusOne = assignSPIRVTy(
800 MIRBuilder.buildSub(IntTy, Abs, buildSPIRVConstant(IntTy, ExpLSB)));
801 APInt MaxExpMinusOne = std::move(ExpMask) - ExpLSB;
802 auto NormalRes = assignSPIRVTy(
803 MIRBuilder.buildICmp(CmpInst::Predicate::ICMP_ULT, DstTy, ExpMinusOne,
804 buildSPIRVConstant(IntTy, MaxExpMinusOne)));
805 if (PartialCheck == fcNegNormal)
806 NormalRes = MIRBuilder.buildAnd(DstTy, NormalRes, Sign);
807 else if (PartialCheck == fcPosNormal) {
808 auto PosSign = assignSPIRVTy(MIRBuilder.buildXor(
809 DstTy, Sign, buildSPIRVConstant(DstTy, InversionMask)));
810 NormalRes = MIRBuilder.buildAnd(DstTy, NormalRes, PosSign);
811 }
812 appendToRes(std::move(NormalRes));
813 }
814
815 MIRBuilder.buildCopy(DstReg, Res);
816 MI.eraseFromParent();
817 return true;
818}
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...