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.
242 Value *SafeDivisor = getSafeDivisor(VPI.getType());
243 Op1 = Builder.CreateSelect(Mask, Op1, SafeDivisor);
244 }
245 }
246
247 Value *NewBinOp = Builder.CreateBinOp(OC, Op0, Op1);
248
249 replaceOperation(*NewBinOp, VPI);
250 return true;
251}
252
253static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI,
254 Type *EltTy) {
256 return getReductionIdentity(RdxID, EltTy, VPI.getFastMathFlagsOrNone());
257}
258
259bool CachingVPExpander::expandPredicationInReduction(
260 IRBuilder<> &Builder, VPReductionIntrinsic &VPI) {
262 "Implicitly dropping %evl in non-speculatable operator!");
263
264 Value *Mask = VPI.getMaskParam();
265 Value *RedOp = VPI.getOperand(VPI.getVectorParamPos());
266
267 // Insert neutral element in masked-out positions
268 if (Mask && !isAllTrueMask(Mask)) {
269 auto *NeutralElt = getNeutralReductionElement(VPI, VPI.getType());
270 auto *NeutralVector = Builder.CreateVectorSplat(
271 cast<VectorType>(RedOp->getType())->getElementCount(), NeutralElt);
272 RedOp = Builder.CreateSelect(Mask, RedOp, NeutralVector);
273 }
274
277
278 switch (VPI.getIntrinsicID()) {
279 default:
280 llvm_unreachable("Impossible reduction kind");
281 case Intrinsic::vp_reduce_add:
282 case Intrinsic::vp_reduce_mul:
283 case Intrinsic::vp_reduce_and:
284 case Intrinsic::vp_reduce_or:
285 case Intrinsic::vp_reduce_xor: {
287 unsigned Opc = getArithmeticReductionInstruction(RedID);
289 Reduction = Builder.CreateUnaryIntrinsic(RedID, RedOp);
290 Reduction =
292 break;
293 }
294 case Intrinsic::vp_reduce_smax:
295 case Intrinsic::vp_reduce_smin:
296 case Intrinsic::vp_reduce_umax:
297 case Intrinsic::vp_reduce_umin:
298 case Intrinsic::vp_reduce_fmax:
299 case Intrinsic::vp_reduce_fmin:
300 case Intrinsic::vp_reduce_fmaximum:
301 case Intrinsic::vp_reduce_fminimum: {
304 Reduction = Builder.CreateUnaryIntrinsic(RedID, RedOp);
306 Reduction = Builder.CreateBinaryIntrinsic(ScalarID, Reduction, Start);
307 break;
308 }
309 case Intrinsic::vp_reduce_fadd:
310 Reduction = Builder.CreateFAddReduce(Start, RedOp);
311 break;
312 case Intrinsic::vp_reduce_fmul:
313 Reduction = Builder.CreateFMulReduce(Start, RedOp);
314 break;
315 }
316
318 return true;
319}
320
321bool CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder,
322 VPIntrinsic &VPI) {
324
325 const auto &DL = VPI.getDataLayout();
326
327 Value *MaskParam = VPI.getMaskParam();
328 Value *PtrParam = VPI.getMemoryPointerParam();
329 Value *DataParam = VPI.getMemoryDataParam();
330 bool IsUnmasked = isAllTrueMask(MaskParam);
331
332 MaybeAlign AlignOpt = VPI.getPointerAlignment();
333
334 Value *NewMemoryInst = nullptr;
335 switch (VPI.getIntrinsicID()) {
336 default:
337 llvm_unreachable("Not a VP memory intrinsic");
338 case Intrinsic::vp_store:
339 if (IsUnmasked) {
340 StoreInst *NewStore =
341 Builder.CreateStore(DataParam, PtrParam, /*IsVolatile*/ false);
342 if (AlignOpt.has_value())
343 NewStore->setAlignment(*AlignOpt);
344 NewMemoryInst = NewStore;
345 } else
346 NewMemoryInst = Builder.CreateMaskedStore(
347 DataParam, PtrParam, AlignOpt.valueOrOne(), MaskParam);
348
349 break;
350 case Intrinsic::vp_load:
351 if (IsUnmasked) {
352 LoadInst *NewLoad =
353 Builder.CreateLoad(VPI.getType(), PtrParam, /*IsVolatile*/ false);
354 if (AlignOpt.has_value())
355 NewLoad->setAlignment(*AlignOpt);
356 NewMemoryInst = NewLoad;
357 } else
358 NewMemoryInst = Builder.CreateMaskedLoad(
359 VPI.getType(), PtrParam, AlignOpt.valueOrOne(), MaskParam);
360
361 break;
362 case Intrinsic::vp_scatter: {
363 auto *ElementType =
364 cast<VectorType>(DataParam->getType())->getElementType();
365 NewMemoryInst = Builder.CreateMaskedScatter(
366 DataParam, PtrParam,
367 AlignOpt.value_or(DL.getPrefTypeAlign(ElementType)), MaskParam);
368 break;
369 }
370 case Intrinsic::vp_gather: {
371 auto *ElementType = cast<VectorType>(VPI.getType())->getElementType();
372 NewMemoryInst = Builder.CreateMaskedGather(
373 VPI.getType(), PtrParam,
374 AlignOpt.value_or(DL.getPrefTypeAlign(ElementType)), MaskParam,
375 nullptr);
376 break;
377 }
378 }
379
380 assert(NewMemoryInst);
381 replaceOperation(*NewMemoryInst, VPI);
382 return true;
383}
384
385bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
386 LLVM_DEBUG(dbgs() << "Discard EVL parameter in " << VPI << "\n");
387
389 return false;
390
391 Value *EVLParam = VPI.getVectorLengthParam();
392 if (!EVLParam)
393 return false;
394
395 ElementCount StaticElemCount = VPI.getStaticVectorLength();
396 Value *MaxEVL = nullptr;
397 Type *Int32Ty = Type::getInt32Ty(VPI.getContext());
398 if (StaticElemCount.isScalable()) {
399 // TODO add caching
400 IRBuilder<> Builder(VPI.getParent(), VPI.getIterator());
401 Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue());
402 Value *VScale = Builder.CreateVScale(Int32Ty, "vscale");
403 MaxEVL = Builder.CreateNUWMul(VScale, FactorConst, "scalable_size");
404 } else {
405 MaxEVL = ConstantInt::get(Int32Ty, StaticElemCount.getFixedValue(), false);
406 }
407 VPI.setVectorLengthParam(MaxEVL);
408 return true;
409}
410
411bool CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
412 LLVM_DEBUG(dbgs() << "Folding vlen for " << VPI << '\n');
413
414 IRBuilder<> Builder(&VPI);
415
416 // Ineffective %evl parameter and so nothing to do here.
418 return false;
419
420 // Only VP intrinsics can have an %evl parameter.
421 Value *OldMaskParam = VPI.getMaskParam();
422 if (!OldMaskParam) {
423 assert((VPI.getIntrinsicID() == Intrinsic::vp_merge) &&
424 "Unexpected VP intrinsic without mask operand");
425 OldMaskParam = VPI.getArgOperand(0);
426 }
427
428 Value *OldEVLParam = VPI.getVectorLengthParam();
429 assert(OldMaskParam && "no mask param to fold the vl param into");
430 assert(OldEVLParam && "no EVL param to fold away");
431
432 LLVM_DEBUG(dbgs() << "OLD evl: " << *OldEVLParam << '\n');
433 LLVM_DEBUG(dbgs() << "OLD mask: " << *OldMaskParam << '\n');
434
435 // Convert the %evl predication into vector mask predication.
436 ElementCount ElemCount = VPI.getStaticVectorLength();
437 Value *VLMask = convertEVLToMask(Builder, OldEVLParam, ElemCount);
438 Value *NewMaskParam = Builder.CreateAnd(VLMask, OldMaskParam);
439 if (VPI.getIntrinsicID() == Intrinsic::vp_merge)
440 VPI.setArgOperand(0, NewMaskParam);
441 else
442 VPI.setMaskParam(NewMaskParam);
443
444 // Drop the %evl parameter.
445 discardEVLParameter(VPI);
447 "transformation did not render the evl param ineffective!");
448
449 // Reassess the modified instruction.
450 return true;
451}
452
453bool CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
454 LLVM_DEBUG(dbgs() << "Lowering to unpredicated op: " << VPI << '\n');
455
456 IRBuilder<> Builder(&VPI);
457
458 // Try lowering to a LLVM instruction first.
459 auto OC = VPI.getFunctionalOpcode();
460
461 if (OC && Instruction::isBinaryOp(*OC))
462 return expandPredicationInBinaryOperator(Builder, VPI);
463
464 if (auto *VPRI = dyn_cast<VPReductionIntrinsic>(&VPI))
465 return expandPredicationInReduction(Builder, *VPRI);
466
467 switch (VPI.getIntrinsicID()) {
468 default:
469 break;
470 case Intrinsic::vp_merge: {
472 Value *NewSelectOp = Builder.CreateSelect(
473 VPI.getOperand(0), VPI.getOperand(1), VPI.getOperand(2));
474 replaceOperation(*NewSelectOp, VPI);
475 return NewSelectOp;
476 }
477 case Intrinsic::vp_load:
478 case Intrinsic::vp_store:
479 case Intrinsic::vp_gather:
480 case Intrinsic::vp_scatter:
481 return expandPredicationInMemoryIntrinsic(Builder, VPI);
482 }
483
484 return false;
485}
486
487//// } CachingVPExpander
488
489void sanitizeStrategy(VPIntrinsic &VPI, VPLegalization &LegalizeStrat) {
490 // Operations with speculatable lanes do not strictly need predication.
491 if (maySpeculateLanes(VPI)) {
492 // Converting a speculatable VP intrinsic means dropping %mask and %evl.
493 // No need to expand %evl into the %mask only to ignore that code.
494 if (LegalizeStrat.OpStrategy == VPLegalization::Convert)
496 return;
497 }
498
499 // We have to preserve the predicating effect of %evl for this
500 // non-speculatable VP intrinsic.
501 // 1) Never discard %evl.
502 // 2) If this VP intrinsic will be expanded to non-VP code, make sure that
503 // %evl gets folded into %mask.
504 if ((LegalizeStrat.EVLParamStrategy == VPLegalization::Discard) ||
505 (LegalizeStrat.OpStrategy == VPLegalization::Convert)) {
507 }
508}
509
511CachingVPExpander::getVPLegalizationStrategy(const VPIntrinsic &VPI) const {
512 auto VPStrat = TTI.getVPLegalizationStrategy(VPI);
513 if (LLVM_LIKELY(!UsingTTIOverrides)) {
514 // No overrides - we are in production.
515 return VPStrat;
516 }
517
518 // Overrides set - we are in testing, the following does not need to be
519 // efficient.
521 VPStrat.OpStrategy = parseOverrideOption(MaskTransformOverride);
522 return VPStrat;
523}
524
526CachingVPExpander::expandVectorPredication(VPIntrinsic &VPI) {
527 auto Strategy = getVPLegalizationStrategy(VPI);
528 sanitizeStrategy(VPI, Strategy);
529
530 VPExpansionDetails Changed = VPExpansionDetails::IntrinsicUnchanged;
531
532 // Transform the EVL parameter.
533 switch (Strategy.EVLParamStrategy) {
535 break;
537 if (discardEVLParameter(VPI))
538 Changed = VPExpansionDetails::IntrinsicUpdated;
539 break;
541 if (foldEVLIntoMask(VPI)) {
542 Changed = VPExpansionDetails::IntrinsicUpdated;
543 ++NumFoldedVL;
544 }
545 break;
546 }
547
548 // Replace with a non-predicated operation.
549 switch (Strategy.OpStrategy) {
551 break;
553 llvm_unreachable("Invalid strategy for operators.");
555 if (expandPredication(VPI)) {
556 ++NumLoweredVPOps;
557 Changed = VPExpansionDetails::IntrinsicReplaced;
558 }
559 break;
560 }
561
562 return Changed;
563}
564} // namespace
565
568 const TargetTransformInfo &TTI) {
569 return CachingVPExpander(TTI).expandVectorPredication(VPI);
570}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_LIKELY(EXPR)
Definition Compiler.h:343
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:43
Value * CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1469
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:519
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 * CreateVScale(Type *Ty, const Twine &Name="")
Create a call to llvm.vscale.<Ty>().
Definition IRBuilder.h:936
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:477
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:1906
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition IRBuilder.h:1570
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:1925
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:1731
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:2485
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:2893
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:263
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:255
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
bool hasName() const
Definition Value.h:261
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Definition Value.cpp:400
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:200
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:168
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
const ParentTy * getParent() const
Definition ilist_node.h:34
self_iterator getIterator()
Definition ilist_node.h:123
Changed
#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
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
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
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:130