LLVM 24.0.0git
ExpandVectorPredication.cpp
Go to the documentation of this file.
1//===----- CodeGen/ExpandVectorPredication.cpp - Expand VP intrinsics -----===//
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 IR expansion for vector predication intrinsics, allowing
10// targets to enable vector predication until just before codegen.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/Statistic.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/Intrinsics.h"
27#include "llvm/Support/Debug.h"
29#include <optional>
30
31using namespace llvm;
32
35
36// Keep this in sync with TargetTransformInfo::VPLegalization.
37#define VPINTERNAL_VPLEGAL_CASES \
38 VPINTERNAL_CASE(Legal) \
39 VPINTERNAL_CASE(Discard) \
40 VPINTERNAL_CASE(Convert)
41
42#define VPINTERNAL_CASE(X) "|" #X
43
44// Override options.
46 "expandvp-override-evl-transform", cl::init(""), cl::Hidden,
47 cl::desc("Options: <empty>" VPINTERNAL_VPLEGAL_CASES
48 ". If non-empty, ignore "
49 "TargetTransformInfo and "
50 "always use this transformation for the %evl parameter (Used in "
51 "testing)."));
52
54 "expandvp-override-mask-transform", cl::init(""), cl::Hidden,
55 cl::desc("Options: <empty>" VPINTERNAL_VPLEGAL_CASES
56 ". If non-empty, Ignore "
57 "TargetTransformInfo and "
58 "always use this transformation for the %mask parameter (Used in "
59 "testing)."));
60
61#undef VPINTERNAL_CASE
62#define VPINTERNAL_CASE(X) .Case(#X, VPLegalization::X)
63
64static VPTransform parseOverrideOption(const std::string &TextOpt) {
66}
67
68#undef VPINTERNAL_VPLEGAL_CASES
69
70// Whether any override options are set.
72 return !EVLTransformOverride.empty() || !MaskTransformOverride.empty();
73}
74
75#define DEBUG_TYPE "expandvp"
76
77STATISTIC(NumFoldedVL, "Number of folded vector length params");
78STATISTIC(NumLoweredVPOps, "Number of folded vector predication operations");
79
80///// Helpers {
81
82/// \returns Whether the vector mask \p MaskVal has all lane bits set.
83static bool isAllTrueMask(Value *MaskVal) {
84 if (Value *SplattedVal = getSplatValue(MaskVal))
85 if (auto *ConstValue = dyn_cast<Constant>(SplattedVal))
86 return ConstValue->isAllOnesValue();
87
88 return false;
89}
90
91/// \returns A non-excepting divisor constant for this type.
92static Constant *getSafeDivisor(Type *DivTy) {
93 assert(DivTy->isIntOrIntVectorTy() && "Unsupported divisor type");
94 return ConstantInt::get(DivTy, 1u, false);
95}
96
97/// Transfer operation properties from \p OldVPI to \p NewVal.
98static void transferDecorations(Value &NewVal, VPIntrinsic &VPI) {
99 auto *NewInst = dyn_cast<Instruction>(&NewVal);
100 if (!NewInst || !isa<FPMathOperator>(NewVal))
101 return;
102
103 auto *OldFMOp = dyn_cast<FPMathOperator>(&VPI);
104 if (!OldFMOp)
105 return;
106
107 NewInst->setFastMathFlags(OldFMOp->getFastMathFlags());
108}
109
110/// Transfer all properties from \p OldOp to \p NewOp and replace all uses.
111/// OldVP gets erased.
112static void replaceOperation(Value &NewOp, VPIntrinsic &OldOp) {
113 transferDecorations(NewOp, OldOp);
114
115 if (isa<Instruction>(NewOp) && !NewOp.hasName() && OldOp.hasName())
116 NewOp.takeName(&OldOp);
117
118 OldOp.replaceAllUsesWith(&NewOp);
119 OldOp.eraseFromParent();
120}
121
123 // The result of VP reductions depends on the mask and evl.
125 return false;
126 // Fallback to whether the intrinsic is speculatable.
127 if (auto IntrID = VPI.getFunctionalIntrinsicID())
128 return Intrinsic::getFnAttributes(VPI.getContext(), *IntrID)
129 .hasAttribute(Attribute::AttrKind::Speculatable);
130 if (auto Opc = VPI.getFunctionalOpcode())
132 return false;
133}
134
135//// } Helpers
136
137namespace {
138
139// Expansion pass state at function scope.
140struct CachingVPExpander {
141 const TargetTransformInfo &TTI;
142
143 /// \returns A bitmask that is true where the lane position is less-than \p
144 /// EVLParam
145 ///
146 /// \p Builder
147 /// Used for instruction creation.
148 /// \p VLParam
149 /// The explicit vector length parameter to test against the lane
150 /// positions.
151 /// \p ElemCount
152 /// Static (potentially scalable) number of vector elements.
153 Value *convertEVLToMask(IRBuilder<> &Builder, Value *EVLParam,
154 ElementCount ElemCount);
155
156 /// If needed, folds the EVL in the mask operand and discards the EVL
157 /// parameter. Returns true if the mask was actually folded.
158 bool foldEVLIntoMask(VPIntrinsic &VPI);
159
160 /// "Remove" the %evl parameter of \p PI by setting it to the static vector
161 /// length of the operation. Returns true if the %evl (if any) was effectively
162 /// changed.
163 bool discardEVLParameter(VPIntrinsic &PI);
164
165 /// Lower this VP binary operator to a unpredicated binary operator.
166 bool expandPredicationInBinaryOperator(IRBuilder<> &Builder, VPIntrinsic &PI);
167
168 /// Lower this VP reduction to a call to an unpredicated reduction intrinsic.
169 bool expandPredicationInReduction(IRBuilder<> &Builder,
170 VPReductionIntrinsic &PI);
171
172 /// Lower this VP memory operation to a non-VP intrinsic.
173 bool expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
174 VPIntrinsic &VPI);
175
176 /// Query TTI and expand the vector predication in \p P accordingly.
177 bool expandPredication(VPIntrinsic &PI);
178
179 /// Determine how and whether the VPIntrinsic \p VPI shall be expanded. This
180 /// overrides TTI with the cl::opts listed at the top of this file.
181 VPLegalization getVPLegalizationStrategy(const VPIntrinsic &VPI) const;
182 bool UsingTTIOverrides;
183
184public:
185 CachingVPExpander(const TargetTransformInfo &TTI)
186 : TTI(TTI), UsingTTIOverrides(anyExpandVPOverridesSet()) {}
187
188 /// Expand llvm.vp.* intrinsics as requested by \p TTI.
189 /// Returns the details of the expansion.
190 VPExpansionDetails expandVectorPredication(VPIntrinsic &VPI);
191};
192
193//// CachingVPExpander {
194
195Value *CachingVPExpander::convertEVLToMask(IRBuilder<> &Builder,
196 Value *EVLParam,
197 ElementCount ElemCount) {
198 // TODO add caching
199 // Scalable vector %evl conversion.
200 if (ElemCount.isScalable()) {
201 Type *BoolVecTy = VectorType::get(Builder.getInt1Ty(), ElemCount);
202 // `get_active_lane_mask` performs an implicit less-than comparison.
203 Value *ConstZero = Builder.getInt32(0);
204 return Builder.CreateIntrinsic(Intrinsic::get_active_lane_mask,
205 {BoolVecTy, EVLParam->getType()},
206 {ConstZero, EVLParam});
207 }
208
209 // Fixed vector %evl conversion.
210 Type *LaneTy = EVLParam->getType();
211 unsigned NumElems = ElemCount.getFixedValue();
212 Value *VLSplat = Builder.CreateVectorSplat(NumElems, EVLParam);
213 Value *IdxVec = Builder.CreateStepVector(VectorType::get(LaneTy, ElemCount));
214 return Builder.CreateICmp(CmpInst::ICMP_ULT, IdxVec, VLSplat);
215}
216
217bool CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
218 VPIntrinsic &VPI) {
220 "Implicitly dropping %evl in non-speculatable operator!");
221
222 auto OC = static_cast<Instruction::BinaryOps>(*VPI.getFunctionalOpcode());
224
225 Value *Op0 = VPI.getOperand(0);
226 Value *Op1 = VPI.getOperand(1);
227 Value *Mask = VPI.getMaskParam();
228
229 // Blend in safe operands.
230 if (Mask && !isAllTrueMask(Mask)) {
231 switch (OC) {
232 default:
233 // Can safely ignore the predicate.
234 break;
235
236 // Division operators need a safe divisor on masked-off lanes (1).
237 case Instruction::UDiv:
238 case Instruction::SDiv:
239 case Instruction::URem:
240 case Instruction::SRem:
241 // 2nd operand must not be zero. The mask needs to be frozen as it may
242 // have poison lanes, and a poison divisor would introduce UB even if Op1
243 // didn't cause UB to begin with.
244 Value *SafeDivisor = getSafeDivisor(VPI.getType());
245 Op1 = Builder.CreateSelect(Builder.CreateFreeze(Mask), Op1, SafeDivisor);
246 }
247 }
248
249 Value *NewBinOp = Builder.CreateBinOp(OC, Op0, Op1);
250
251 replaceOperation(*NewBinOp, VPI);
252 return true;
253}
254
255static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI,
256 Type *EltTy) {
258 return getReductionIdentity(RdxID, EltTy, VPI.getFastMathFlagsOrNone());
259}
260
261bool CachingVPExpander::expandPredicationInReduction(
262 IRBuilder<> &Builder, VPReductionIntrinsic &VPI) {
264 "Implicitly dropping %evl in non-speculatable operator!");
265
266 Value *Mask = VPI.getMaskParam();
267 Value *RedOp = VPI.getOperand(VPI.getVectorParamPos());
268
269 // Insert neutral element in masked-out positions
270 if (Mask && !isAllTrueMask(Mask)) {
271 auto *NeutralElt = getNeutralReductionElement(VPI, VPI.getType());
272 auto *NeutralVector = Builder.CreateVectorSplat(
273 cast<VectorType>(RedOp->getType())->getElementCount(), NeutralElt);
274 RedOp = Builder.CreateSelect(Mask, RedOp, NeutralVector);
275 }
276
279
280 switch (VPI.getIntrinsicID()) {
281 default:
282 llvm_unreachable("Impossible reduction kind");
283 case Intrinsic::vp_reduce_add:
284 case Intrinsic::vp_reduce_mul:
285 case Intrinsic::vp_reduce_and:
286 case Intrinsic::vp_reduce_or:
287 case Intrinsic::vp_reduce_xor: {
289 unsigned Opc = getArithmeticReductionInstruction(RedID);
291 Reduction = Builder.CreateUnaryIntrinsic(RedID, RedOp);
292 Reduction =
294 break;
295 }
296 case Intrinsic::vp_reduce_smax:
297 case Intrinsic::vp_reduce_smin:
298 case Intrinsic::vp_reduce_umax:
299 case Intrinsic::vp_reduce_umin:
300 case Intrinsic::vp_reduce_fmax:
301 case Intrinsic::vp_reduce_fmin:
302 case Intrinsic::vp_reduce_fmaximum:
303 case Intrinsic::vp_reduce_fminimum: {
306 Reduction = Builder.CreateUnaryIntrinsic(RedID, RedOp);
308 Reduction = Builder.CreateBinaryIntrinsic(ScalarID, Reduction, Start);
309 break;
310 }
311 case Intrinsic::vp_reduce_fadd:
312 Reduction = Builder.CreateFAddReduce(Start, RedOp);
313 break;
314 case Intrinsic::vp_reduce_fmul:
315 Reduction = Builder.CreateFMulReduce(Start, RedOp);
316 break;
317 }
318
320 return true;
321}
322
323bool CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
324 VPIntrinsic &VPI) {
326
327 const auto &DL = VPI.getDataLayout();
328
329 Value *MaskParam = VPI.getMaskParam();
330 Value *PtrParam = VPI.getMemoryPointerParam();
331 Value *DataParam = VPI.getMemoryDataParam();
332 bool IsUnmasked = isAllTrueMask(MaskParam);
333
334 MaybeAlign AlignOpt = VPI.getPointerAlignment();
335
336 Value *NewMemoryInst = nullptr;
337 switch (VPI.getIntrinsicID()) {
338 default:
339 llvm_unreachable("Not a VP memory intrinsic");
340 case Intrinsic::vp_store:
341 if (IsUnmasked) {
342 StoreInst *NewStore =
343 Builder.CreateStore(DataParam, PtrParam, /*IsVolatile*/ false);
344 if (AlignOpt.has_value())
345 NewStore->setAlignment(*AlignOpt);
346 NewMemoryInst = NewStore;
347 } else
348 NewMemoryInst = Builder.CreateMaskedStore(
349 DataParam, PtrParam, AlignOpt.valueOrOne(), MaskParam);
350
351 break;
352 case Intrinsic::vp_load:
353 if (IsUnmasked) {
354 LoadInst *NewLoad =
355 Builder.CreateLoad(VPI.getType(), PtrParam, /*IsVolatile*/ false);
356 if (AlignOpt.has_value())
357 NewLoad->setAlignment(*AlignOpt);
358 NewMemoryInst = NewLoad;
359 } else
360 NewMemoryInst = Builder.CreateMaskedLoad(
361 VPI.getType(), PtrParam, AlignOpt.valueOrOne(), MaskParam);
362
363 break;
364 case Intrinsic::vp_scatter: {
365 auto *ElementType =
366 cast<VectorType>(DataParam->getType())->getElementType();
367 NewMemoryInst = Builder.CreateMaskedScatter(
368 DataParam, PtrParam,
369 AlignOpt.value_or(DL.getPrefTypeAlign(ElementType)), MaskParam);
370 break;
371 }
372 case Intrinsic::vp_gather: {
373 auto *ElementType = cast<VectorType>(VPI.getType())->getElementType();
374 NewMemoryInst = Builder.CreateMaskedGather(
375 VPI.getType(), PtrParam,
376 AlignOpt.value_or(DL.getPrefTypeAlign(ElementType)), MaskParam,
377 nullptr);
378 break;
379 }
380 }
381
382 assert(NewMemoryInst);
383 replaceOperation(*NewMemoryInst, VPI);
384 return true;
385}
386
387bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
388 LLVM_DEBUG(dbgs() << "Discard EVL parameter in " << VPI << "\n");
389
391 return false;
392
393 Value *EVLParam = VPI.getVectorLengthParam();
394 if (!EVLParam)
395 return false;
396
397 ElementCount StaticElemCount = VPI.getStaticVectorLength();
398 Value *MaxEVL = nullptr;
399 Type *Int32Ty = Type::getInt32Ty(VPI.getContext());
400 if (StaticElemCount.isScalable()) {
401 // TODO add caching
402 IRBuilder<> Builder(VPI.getIterator());
403 Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue());
404 Value *VScale = Builder.CreateVScale(Int32Ty, "vscale");
405 MaxEVL = Builder.CreateNUWMul(VScale, FactorConst, "scalable_size");
406 } else {
407 MaxEVL = ConstantInt::get(Int32Ty, StaticElemCount.getFixedValue(), false);
408 }
409 VPI.setVectorLengthParam(MaxEVL);
410 return true;
411}
412
413bool CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
414 LLVM_DEBUG(dbgs() << "Folding vlen for " << VPI << '\n');
415
416 IRBuilder<> Builder(&VPI);
417
418 // Ineffective %evl parameter and so nothing to do here.
420 return false;
421
422 // Only VP intrinsics can have an %evl parameter.
423 Value *OldMaskParam = VPI.getMaskParam();
424 if (!OldMaskParam) {
425 assert((VPI.getIntrinsicID() == Intrinsic::vp_merge) &&
426 "Unexpected VP intrinsic without mask operand");
427 OldMaskParam = VPI.getArgOperand(0);
428 }
429
430 Value *OldEVLParam = VPI.getVectorLengthParam();
431 assert(OldMaskParam && "no mask param to fold the vl param into");
432 assert(OldEVLParam && "no EVL param to fold away");
433
434 LLVM_DEBUG(dbgs() << "OLD evl: " << *OldEVLParam << '\n');
435 LLVM_DEBUG(dbgs() << "OLD mask: " << *OldMaskParam << '\n');
436
437 // Convert the %evl predication into vector mask predication.
438 ElementCount ElemCount = VPI.getStaticVectorLength();
439 Value *VLMask = convertEVLToMask(Builder, OldEVLParam, ElemCount);
440 Value *NewMaskParam = Builder.CreateLogicalAnd(VLMask, OldMaskParam);
441 if (VPI.getIntrinsicID() == Intrinsic::vp_merge)
442 VPI.setArgOperand(0, NewMaskParam);
443 else
444 VPI.setMaskParam(NewMaskParam);
445
446 // Drop the %evl parameter.
447 discardEVLParameter(VPI);
449 "transformation did not render the evl param ineffective!");
450
451 // Reassess the modified instruction.
452 return true;
453}
454
455bool CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
456 LLVM_DEBUG(dbgs() << "Lowering to unpredicated op: " << VPI << '\n');
457
458 IRBuilder<> Builder(&VPI);
459
460 // Try lowering to a LLVM instruction first.
461 auto OC = VPI.getFunctionalOpcode();
462
463 if (OC && Instruction::isBinaryOp(*OC))
464 return expandPredicationInBinaryOperator(Builder, VPI);
465
466 if (auto *VPRI = dyn_cast<VPReductionIntrinsic>(&VPI))
467 return expandPredicationInReduction(Builder, *VPRI);
468
469 switch (VPI.getIntrinsicID()) {
470 default:
471 break;
472 case Intrinsic::vp_merge: {
474 Value *NewSelectOp = Builder.CreateSelect(
475 VPI.getOperand(0), VPI.getOperand(1), VPI.getOperand(2));
476 replaceOperation(*NewSelectOp, VPI);
477 return NewSelectOp;
478 }
479 case Intrinsic::vp_load:
480 case Intrinsic::vp_store:
481 case Intrinsic::vp_gather:
482 case Intrinsic::vp_scatter:
483 return expandPredicationInMemoryIntrinsic(Builder, VPI);
484 }
485
486 return false;
487}
488
489//// } CachingVPExpander
490
491void sanitizeStrategy(VPIntrinsic &VPI, VPLegalization &LegalizeStrat) {
492 // Operations with speculatable lanes do not strictly need predication.
493 if (maySpeculateLanes(VPI)) {
494 // Converting a speculatable VP intrinsic means dropping %mask and %evl.
495 // No need to expand %evl into the %mask only to ignore that code.
496 if (LegalizeStrat.OpStrategy == VPLegalization::Convert)
498 return;
499 }
500
501 // We have to preserve the predicating effect of %evl for this
502 // non-speculatable VP intrinsic.
503 // 1) Never discard %evl.
504 // 2) If this VP intrinsic will be expanded to non-VP code, make sure that
505 // %evl gets folded into %mask.
506 if ((LegalizeStrat.EVLParamStrategy == VPLegalization::Discard) ||
507 (LegalizeStrat.OpStrategy == VPLegalization::Convert)) {
509 }
510}
511
513CachingVPExpander::getVPLegalizationStrategy(const VPIntrinsic &VPI) const {
514 auto VPStrat = TTI.getVPLegalizationStrategy(VPI);
515 if (LLVM_LIKELY(!UsingTTIOverrides)) {
516 // No overrides - we are in production.
517 return VPStrat;
518 }
519
520 // Overrides set - we are in testing, the following does not need to be
521 // efficient.
523 VPStrat.OpStrategy = parseOverrideOption(MaskTransformOverride);
524 return VPStrat;
525}
526
528CachingVPExpander::expandVectorPredication(VPIntrinsic &VPI) {
529 auto Strategy = getVPLegalizationStrategy(VPI);
530 sanitizeStrategy(VPI, Strategy);
531
532 VPExpansionDetails Changed = VPExpansionDetails::IntrinsicUnchanged;
533
534 // Transform the EVL parameter.
535 switch (Strategy.EVLParamStrategy) {
537 break;
539 if (discardEVLParameter(VPI))
540 Changed = VPExpansionDetails::IntrinsicUpdated;
541 break;
543 if (foldEVLIntoMask(VPI)) {
544 Changed = VPExpansionDetails::IntrinsicUpdated;
545 ++NumFoldedVL;
546 }
547 break;
548 }
549
550 // Replace with a non-predicated operation.
551 switch (Strategy.OpStrategy) {
553 break;
555 llvm_unreachable("Invalid strategy for operators.");
557 if (expandPredication(VPI)) {
558 ++NumLoweredVPOps;
559 Changed = VPExpansionDetails::IntrinsicReplaced;
560 }
561 break;
562 }
563
564 return Changed;
565}
566} // namespace
567
570 const TargetTransformInfo &TTI) {
571 return CachingVPExpander(TTI).expandVectorPredication(VPI);
572}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_LIKELY(EXPR)
Definition Compiler.h:347
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static VPTransform parseOverrideOption(const std::string &TextOpt)
static cl::opt< std::string > MaskTransformOverride("expandvp-override-mask-transform", cl::init(""), cl::Hidden, cl::desc("Options: <empty>" VPINTERNAL_VPLEGAL_CASES ". If non-empty, Ignore " "TargetTransformInfo and " "always use this transformation for the %mask parameter (Used in " "testing)."))
static cl::opt< std::string > EVLTransformOverride("expandvp-override-evl-transform", cl::init(""), cl::Hidden, cl::desc("Options: <empty>" VPINTERNAL_VPLEGAL_CASES ". If non-empty, ignore " "TargetTransformInfo and " "always use this transformation for the %evl parameter (Used in " "testing)."))
static void replaceOperation(Value &NewOp, VPIntrinsic &OldOp)
Transfer all properties from OldOp to NewOp and replace all uses.
static bool isAllTrueMask(Value *MaskVal)
static void transferDecorations(Value &NewVal, VPIntrinsic &VPI)
Transfer operation properties from OldVPI to NewVal.
TargetTransformInfo::VPLegalization VPLegalization
TargetTransformInfo::VPLegalization::VPTransform VPTransform
static bool anyExpandVPOverridesSet()
static bool maySpeculateLanes(VPIntrinsic &VPI)
static Constant * getSafeDivisor(Type *DivTy)
#define VPINTERNAL_VPLEGAL_CASES
loop Loop Strength Reduction
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
This pass exposes codegen information to IR-level passes.
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
This is an important base class in LLVM.
Definition Constant.h:44
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1471
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:513
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
LLVM_ABI CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Value * CreateFreeze(Value *V, const Twine &Name="")
Definition IRBuilder.h:2811
Value * CreateVScale(Type *Ty, const Twine &Name="")
Create a call to llvm.vscale.<Ty>().
Definition IRBuilder.h:938
Value * CreateLogicalAnd(Value *Cond1, Value *Cond2, const Twine &Name="", Instruction *MDFrom=nullptr)
Definition IRBuilder.h:1772
LLVM_ABI Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Definition IRBuilder.h:471
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1913
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1931
LLVM_ABI CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition IRBuilder.h:1733
LLVM_ABI Value * CreateFAddReduce(Value *Acc, Value *Src)
Create a sequential vector fadd reduction intrinsic of the source vector.
LLVM_ABI Value * CreateFMulReduce(Value *Acc, Value *Src)
Create a sequential vector fmul reduction intrinsic of the source vector.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:2568
LLVM_ABI Value * CreateStepVector(Type *DstType, const Twine &Name="")
Creates a vector of type DstType with the linear sequence <0, 1, ...>
LLVM_ABI CallInst * CreateMaskedScatter(Value *Val, Value *Ptrs, Align Alignment, Value *Mask=nullptr)
Create a call to Masked Scatter intrinsic.
LLVM_ABI Value * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *Op, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
LLVM_ABI CallInst * CreateMaskedGather(Type *Ty, Value *Ptrs, Align Alignment, Value *Mask=nullptr, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Gather intrinsic.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2987
LLVM_ABI FastMathFlags getFastMathFlagsOrNone() const LLVM_READONLY
Convenience function for getting fast-math flags, or default-constructed FastMathFlags when not a FPM...
bool isBinaryOp() const
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
void setAlignment(Align Align)
void setAlignment(Align Align)
A switch()-like statement whose cases are string literals.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
LLVM_ABI VPLegalization getVPLegalizationStrategy(const VPIntrinsic &PI) const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
Value * getOperand(unsigned i) const
Definition User.h:207
This is the common base class for vector predication intrinsics.
std::optional< unsigned > getFunctionalIntrinsicID() const
LLVM_ABI bool canIgnoreVectorLengthParam() const
LLVM_ABI void setMaskParam(Value *)
LLVM_ABI Value * getVectorLengthParam() const
LLVM_ABI void setVectorLengthParam(Value *)
LLVM_ABI Value * getMemoryDataParam() const
LLVM_ABI Value * getMemoryPointerParam() const
LLVM_ABI MaybeAlign getPointerAlignment() const
LLVM_ABI Value * getMaskParam() const
LLVM_ABI ElementCount getStaticVectorLength() const
std::optional< unsigned > getFunctionalOpcode() const
LLVM_ABI unsigned getStartParamPos() const
LLVM_ABI unsigned getVectorParamPos() const
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:548
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
bool hasName() const
Definition Value.h:263
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Definition Value.cpp:395
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:166
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
initializer< Ty > init(const Ty &Val)
ElementType
The element type of an SRV or UAV resource.
Definition DXILABI.h:68
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Intrinsic::ID getMinMaxReductionIntrinsicOp(Intrinsic::ID RdxID)
Returns the min/max intrinsic used when expanding a min/max reduction.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI Value * getReductionIdentity(Intrinsic::ID RdxID, Type *Ty, FastMathFlags FMF)
Given information about an @llvm.vector.reduce.
LLVM_ABI unsigned getArithmeticReductionInstruction(Intrinsic::ID RdxID)
Returns the arithmetic instruction opcode used when expanding a reduction.
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI VPExpansionDetails expandVectorPredicationIntrinsic(VPIntrinsic &VPI, const TargetTransformInfo &TTI)
Expand a vector predication intrinsic.
LLVM_ABI bool isSafeToSpeculativelyExecuteWithOpcode(unsigned Opcode, const Instruction *Inst, const Instruction *CtxI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr, bool UseVariableInfo=true, bool IgnoreUBImplyingAttrs=true)
This returns the same result as isSafeToSpeculativelyExecute if Opcode is the actual opcode of Inst.
TargetTransformInfo TTI
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
VPExpansionDetails
Represents the details the expansion of a VP intrinsic.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:135