LLVM 22.0.0git
VPlanUtils.cpp
Go to the documentation of this file.
1//===- VPlanUtils.cpp - VPlan-related utilities ---------------------------===//
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#include "VPlanUtils.h"
10#include "VPlanCFG.h"
11#include "VPlanDominatorTree.h"
12#include "VPlanPatternMatch.h"
13#include "llvm/ADT/TypeSwitch.h"
17
18using namespace llvm;
19using namespace llvm::VPlanPatternMatch;
20using namespace llvm::SCEVPatternMatch;
21
23 return all_of(Def->users(),
24 [Def](const VPUser *U) { return U->usesFirstLaneOnly(Def); });
25}
26
28 return all_of(Def->users(),
29 [Def](const VPUser *U) { return U->usesFirstPartOnly(Def); });
30}
31
33 return all_of(Def->users(),
34 [Def](const VPUser *U) { return U->usesScalars(Def); });
35}
36
38 if (auto *E = dyn_cast<SCEVConstant>(Expr))
39 return Plan.getOrAddLiveIn(E->getValue());
40 // Skip SCEV expansion if Expr is a SCEVUnknown wrapping a non-instruction
41 // value. Otherwise the value may be defined in a loop and using it directly
42 // will break LCSSA form. The SCEV expansion takes care of preserving LCSSA
43 // form.
44 auto *U = dyn_cast<SCEVUnknown>(Expr);
45 if (U && !isa<Instruction>(U->getValue()))
46 return Plan.getOrAddLiveIn(U->getValue());
47 auto *Expanded = new VPExpandSCEVRecipe(Expr);
48 Plan.getEntry()->appendRecipe(Expanded);
49 return Expanded;
50}
51
52bool vputils::isHeaderMask(const VPValue *V, const VPlan &Plan) {
54 return true;
55
56 auto IsWideCanonicalIV = [](VPValue *A) {
60 };
61
62 VPValue *A, *B;
63
64 auto m_CanonicalScalarIVSteps =
66 m_One(), m_Specific(&Plan.getVF()));
67
69 return B == Plan.getTripCount() &&
70 (match(A, m_CanonicalScalarIVSteps) || IsWideCanonicalIV(A));
71
72 // For scalar plans, the header mask uses the scalar steps.
73 if (match(V, m_ICmp(m_CanonicalScalarIVSteps,
75 assert(Plan.hasScalarVFOnly() &&
76 "Non-scalar VF using scalar IV steps for header mask?");
77 return true;
78 }
79
80 return match(V, m_ICmp(m_VPValue(A), m_VPValue(B))) && IsWideCanonicalIV(A) &&
81 B == Plan.getBackedgeTakenCount();
82}
83
86 const Loop *L) {
87 ScalarEvolution &SE = *PSE.getSE();
88 if (V->isLiveIn()) {
89 Value *LiveIn = V->getLiveInIRValue();
90 if (LiveIn && SE.isSCEVable(LiveIn->getType()))
91 return SE.getSCEV(LiveIn);
92 return SE.getCouldNotCompute();
93 }
94
95 // Helper to create SCEVs for binary and unary operations.
96 auto CreateSCEV =
98 function_ref<const SCEV *(ArrayRef<const SCEV *>)> CreateFn)
99 -> const SCEV * {
101 for (VPValue *Op : Ops) {
102 const SCEV *S = getSCEVExprForVPValue(Op, PSE, L);
104 return SE.getCouldNotCompute();
105 SCEVOps.push_back(S);
106 }
107 return CreateFn(SCEVOps);
108 };
109
110 VPValue *LHSVal, *RHSVal;
111 if (match(V, m_Add(m_VPValue(LHSVal), m_VPValue(RHSVal))))
112 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<const SCEV *> Ops) {
113 return SE.getAddExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
114 });
115 if (match(V, m_Sub(m_VPValue(LHSVal), m_VPValue(RHSVal))))
116 return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<const SCEV *> Ops) {
117 return SE.getMinusSCEV(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
118 });
119
120 // TODO: Support constructing SCEVs for more recipes as needed.
121 const VPRecipeBase *DefR = V->getDefiningRecipe();
124 [](const VPExpandSCEVRecipe *R) { return R->getSCEV(); })
125 .Case<VPCanonicalIVPHIRecipe>([&SE, &PSE,
126 L](const VPCanonicalIVPHIRecipe *R) {
127 if (!L)
128 return SE.getCouldNotCompute();
129 const SCEV *Start = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
130 return SE.getAddRecExpr(Start, SE.getOne(Start->getType()), L,
132 })
133 .Case<VPWidenIntOrFpInductionRecipe>(
134 [&SE, &PSE, L](const VPWidenIntOrFpInductionRecipe *R) {
135 const SCEV *Step = getSCEVExprForVPValue(R->getStepValue(), PSE, L);
136 if (!L || isa<SCEVCouldNotCompute>(Step))
137 return SE.getCouldNotCompute();
138 const SCEV *Start =
139 getSCEVExprForVPValue(R->getStartValue(), PSE, L);
140 return SE.getAddRecExpr(Start, Step, L, SCEV::FlagAnyWrap);
141 })
142 .Case<VPDerivedIVRecipe>([&SE, &PSE, L](const VPDerivedIVRecipe *R) {
143 const SCEV *Start = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
144 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
145 const SCEV *Scale = getSCEVExprForVPValue(R->getOperand(2), PSE, L);
146 if (any_of(ArrayRef({Start, IV, Scale}), IsaPred<SCEVCouldNotCompute>))
147 return SE.getCouldNotCompute();
148
149 return SE.getAddExpr(SE.getTruncateOrSignExtend(Start, IV->getType()),
151 Scale, IV->getType())));
152 })
153 .Case<VPScalarIVStepsRecipe>([&SE, &PSE,
154 L](const VPScalarIVStepsRecipe *R) {
155 const SCEV *IV = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
156 const SCEV *Step = getSCEVExprForVPValue(R->getOperand(1), PSE, L);
158 !Step->isOne())
159 return SE.getCouldNotCompute();
160 return SE.getMulExpr(SE.getTruncateOrSignExtend(IV, Step->getType()),
161 Step);
162 })
163 .Case<VPReplicateRecipe>([&SE, &PSE, L](const VPReplicateRecipe *R) {
164 if (R->getOpcode() != Instruction::GetElementPtr)
165 return SE.getCouldNotCompute();
166
167 const SCEV *Base = getSCEVExprForVPValue(R->getOperand(0), PSE, L);
169 return SE.getCouldNotCompute();
170
171 SmallVector<const SCEV *> IndexExprs;
172 for (VPValue *Index : drop_begin(R->operands())) {
173 const SCEV *IndexExpr = getSCEVExprForVPValue(Index, PSE, L);
174 if (isa<SCEVCouldNotCompute>(IndexExpr))
175 return SE.getCouldNotCompute();
176 IndexExprs.push_back(IndexExpr);
177 }
178
179 Type *SrcElementTy = cast<GetElementPtrInst>(R->getUnderlyingInstr())
180 ->getSourceElementType();
181 return SE.getGEPExpr(Base, IndexExprs, SrcElementTy);
182 })
183 .Default(
184 [&SE](const VPRecipeBase *) { return SE.getCouldNotCompute(); });
185
186 return PSE.getPredicatedSCEV(Expr);
187}
188
190 const Loop *L) {
191 // If address is an SCEVAddExpr, we require that all operands must be either
192 // be invariant or a (possibly sign-extend) affine AddRec.
193 if (auto *PtrAdd = dyn_cast<SCEVAddExpr>(Addr)) {
194 return all_of(PtrAdd->operands(), [&SE, L](const SCEV *Op) {
195 return SE.isLoopInvariant(Op, L) ||
196 match(Op, m_scev_SExt(m_scev_AffineAddRec(m_SCEV(), m_SCEV()))) ||
197 match(Op, m_scev_AffineAddRec(m_SCEV(), m_SCEV()));
198 });
199 }
200
201 // Otherwise, check if address is loop invariant or an affine add recurrence.
202 return SE.isLoopInvariant(Addr, L) ||
204}
205
206/// Returns true if \p Opcode preserves uniformity, i.e., if all operands are
207/// uniform, the result will also be uniform.
208static bool preservesUniformity(unsigned Opcode) {
209 if (Instruction::isBinaryOp(Opcode) || Instruction::isCast(Opcode))
210 return true;
211 switch (Opcode) {
212 case Instruction::GetElementPtr:
213 case Instruction::ICmp:
214 case Instruction::FCmp:
215 case Instruction::Select:
219 return true;
220 default:
221 return false;
222 }
223}
224
226 // A live-in must be uniform across the scope of VPlan.
227 if (VPV->isLiveIn())
228 return true;
229
230 if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV)) {
231 const VPRegionBlock *RegionOfR = Rep->getRegion();
232 // Don't consider recipes in replicate regions as uniform yet; their first
233 // lane cannot be accessed when executing the replicate region for other
234 // lanes.
235 if (RegionOfR && RegionOfR->isReplicator())
236 return false;
237 return Rep->isSingleScalar() || (preservesUniformity(Rep->getOpcode()) &&
238 all_of(Rep->operands(), isSingleScalar));
239 }
243 if (auto *WidenR = dyn_cast<VPWidenRecipe>(VPV)) {
244 return preservesUniformity(WidenR->getOpcode()) &&
245 all_of(WidenR->operands(), isSingleScalar);
246 }
247 if (auto *VPI = dyn_cast<VPInstruction>(VPV))
248 return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
249 (preservesUniformity(VPI->getOpcode()) &&
250 all_of(VPI->operands(), isSingleScalar));
251 if (auto *RR = dyn_cast<VPReductionRecipe>(VPV))
252 return !RR->isPartialReduction();
255 return true;
256 if (auto *Expr = dyn_cast<VPExpressionRecipe>(VPV))
257 return Expr->isSingleScalar();
258
259 // VPExpandSCEVRecipes must be placed in the entry and are always uniform.
260 return isa<VPExpandSCEVRecipe>(VPV);
261}
262
264 // Live-ins are uniform.
265 if (V->isLiveIn())
266 return true;
267
268 VPRecipeBase *R = V->getDefiningRecipe();
269 if (R && V->isDefinedOutsideLoopRegions()) {
270 if (match(V->getDefiningRecipe(),
272 return false;
273 return all_of(R->operands(), isUniformAcrossVFsAndUFs);
274 }
275
276 auto *CanonicalIV =
277 R->getParent()->getEnclosingLoopRegion()->getCanonicalIV();
278 // Canonical IV chain is uniform.
279 if (V == CanonicalIV || V == CanonicalIV->getBackedgeValue())
280 return true;
281
283 .Case<VPDerivedIVRecipe>([](const auto *R) { return true; })
284 .Case<VPReplicateRecipe>([](const auto *R) {
285 // Be conservative about side-effects, except for the
286 // known-side-effecting assumes and stores, which we know will be
287 // uniform.
288 return R->isSingleScalar() &&
289 (!R->mayHaveSideEffects() ||
290 isa<AssumeInst, StoreInst>(R->getUnderlyingInstr())) &&
291 all_of(R->operands(), isUniformAcrossVFsAndUFs);
292 })
293 .Case<VPWidenRecipe>([](const auto *R) {
294 return preservesUniformity(R->getOpcode()) &&
295 all_of(R->operands(), isUniformAcrossVFsAndUFs);
296 })
297 .Case<VPInstruction>([](const auto *VPI) {
298 return (VPI->isScalarCast() &&
299 isUniformAcrossVFsAndUFs(VPI->getOperand(0))) ||
300 (preservesUniformity(VPI->getOpcode()) &&
301 all_of(VPI->operands(), isUniformAcrossVFsAndUFs));
302 })
303 .Case<VPWidenCastRecipe>([](const auto *R) {
304 // A cast is uniform according to its operand.
305 return isUniformAcrossVFsAndUFs(R->getOperand(0));
306 })
307 .Default([](const VPRecipeBase *) { // A value is considered non-uniform
308 // unless proven otherwise.
309 return false;
310 });
311}
312
314 auto DepthFirst = vp_depth_first_shallow(Plan.getEntry());
315 auto I = find_if(DepthFirst, [&VPDT](VPBlockBase *VPB) {
316 return VPBlockUtils::isHeader(VPB, VPDT);
317 });
318 return I == DepthFirst.end() ? nullptr : cast<VPBasicBlock>(*I);
319}
320
322 if (!R)
323 return 1;
324 if (auto *RR = dyn_cast<VPReductionPHIRecipe>(R))
325 return RR->getVFScaleFactor();
326 if (auto *RR = dyn_cast<VPReductionRecipe>(R))
327 return RR->getVFScaleFactor();
328 if (auto *ER = dyn_cast<VPExpressionRecipe>(R))
329 return ER->getVFScaleFactor();
330 assert(
333 "getting scaling factor of reduction-start-vector not implemented yet");
334 return 1;
335}
336
337std::optional<VPValue *>
341 // Given a VPlan like the following (just including the recipes contributing
342 // to loop control exiting here, not the actual work), we're looking to match
343 // the recipes contributing to the uncountable exit condition comparison
344 // (here, vp<%4>) back to either live-ins or the address nodes for the load
345 // used as part of the uncountable exit comparison so that we can copy them
346 // to a preheader and rotate the address in the loop to the next vector
347 // iteration.
348 //
349 // Currently, the address of the load is restricted to a GEP with 2 operands
350 // and a live-in base address. This constraint may be relaxed later.
351 //
352 // VPlan ' for UF>=1' {
353 // Live-in vp<%0> = VF
354 // Live-in ir<64> = original trip-count
355 //
356 // entry:
357 // Successor(s): preheader, vector.ph
358 //
359 // vector.ph:
360 // Successor(s): vector loop
361 //
362 // <x1> vector loop: {
363 // vector.body:
364 // EMIT vp<%2> = CANONICAL-INDUCTION ir<0>
365 // vp<%3> = SCALAR-STEPS vp<%2>, ir<1>, vp<%0>
366 // CLONE ir<%ee.addr> = getelementptr ir<0>, vp<%3>
367 // WIDEN ir<%ee.load> = load ir<%ee.addr>
368 // WIDEN vp<%4> = icmp eq ir<%ee.load>, ir<0>
369 // EMIT vp<%5> = any-of vp<%4>
370 // EMIT vp<%6> = add vp<%2>, vp<%0>
371 // EMIT vp<%7> = icmp eq vp<%6>, ir<64>
372 // EMIT vp<%8> = or vp<%5>, vp<%7>
373 // EMIT branch-on-cond vp<%8>
374 // No successors
375 // }
376 // Successor(s): middle.block
377 //
378 // middle.block:
379 // Successor(s): preheader
380 //
381 // preheader:
382 // No successors
383 // }
384
385 // Find the uncountable loop exit condition.
386 auto *Region = Plan.getVectorLoopRegion();
387 VPValue *UncountableCondition = nullptr;
388 if (!match(Region->getExitingBasicBlock()->getTerminator(),
390 m_AnyOf(m_VPValue(UncountableCondition)), m_VPValue())))))
391 return std::nullopt;
392
394 Worklist.push_back(UncountableCondition);
395 while (!Worklist.empty()) {
396 VPValue *V = Worklist.pop_back_val();
397
398 // Any value defined outside the loop does not need to be copied.
399 if (V->isDefinedOutsideLoopRegions())
400 continue;
401
402 // FIXME: Remove the single user restriction; it's here because we're
403 // starting with the simplest set of loops we can, and multiple
404 // users means needing to add PHI nodes in the transform.
405 if (V->getNumUsers() > 1)
406 return std::nullopt;
407
408 VPValue *Op1, *Op2;
409 // Walk back through recipes until we find at least one load from memory.
410 if (match(V, m_ICmp(m_VPValue(Op1), m_VPValue(Op2)))) {
411 Worklist.push_back(Op1);
412 Worklist.push_back(Op2);
413 Recipes.push_back(V->getDefiningRecipe());
414 } else if (auto *Load = dyn_cast<VPWidenLoadRecipe>(V)) {
415 // Reject masked loads for the time being; they make the exit condition
416 // more complex.
417 if (Load->isMasked())
418 return std::nullopt;
419
420 VPValue *GEP = Load->getAddr();
422 return std::nullopt;
423
424 Recipes.push_back(Load);
425 Recipes.push_back(GEP->getDefiningRecipe());
426 GEPs.push_back(GEP->getDefiningRecipe());
427 } else
428 return std::nullopt;
429 }
430
431 return UncountableCondition;
432}
433
435 const VPDominatorTree &VPDT) {
436 auto *VPBB = dyn_cast<VPBasicBlock>(VPB);
437 if (!VPBB)
438 return false;
439
440 // If VPBB is in a region R, VPBB is a loop header if R is a loop region with
441 // VPBB as its entry, i.e., free of predecessors.
442 if (auto *R = VPBB->getParent())
443 return !R->isReplicator() && !VPBB->hasPredecessors();
444
445 // A header dominates its second predecessor (the latch), with the other
446 // predecessor being the preheader
447 return VPB->getPredecessors().size() == 2 &&
448 VPDT.dominates(VPB, VPB->getPredecessors()[1]);
449}
450
452 const VPDominatorTree &VPDT) {
453 // A latch has a header as its second successor, with its other successor
454 // leaving the loop. A preheader OTOH has a header as its first (and only)
455 // successor.
456 return VPB->getNumSuccessors() == 2 &&
457 VPBlockUtils::isHeader(VPB->getSuccessors()[1], VPDT);
458}
459
460std::optional<MemoryLocation>
462 auto *M = dyn_cast<VPIRMetadata>(&R);
463 if (!M)
464 return std::nullopt;
466 // Populate noalias metadata from VPIRMetadata.
467 if (MDNode *NoAliasMD = M->getMetadata(LLVMContext::MD_noalias))
468 Loc.AATags.NoAlias = NoAliasMD;
469 if (MDNode *AliasScopeMD = M->getMetadata(LLVMContext::MD_alias_scope))
470 Loc.AATags.Scope = AliasScopeMD;
471 return Loc;
472}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Hexagon Common GEP
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define I(x, y, z)
Definition MD5.cpp:57
This file provides utility analysis objects describing memory locations.
This file implements the TypeSwitch template, which mimics a switch() statement whose cases are type ...
This file implements dominator tree analysis for a single level of a VPlan's H-CFG.
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
Definition VPlanSLP.cpp:247
static bool preservesUniformity(unsigned Opcode)
Returns true if Opcode preserves uniformity, i.e., if all operands are uniform, the result will also ...
static const uint32_t IV[8]
Definition blake3_impl.h:83
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
bool isCast() const
bool isBinaryOp() const
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Metadata node.
Definition Metadata.h:1078
Representation for a specific memory location.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
LLVM_ABI const SCEV * getPredicatedSCEV(const SCEV *Expr)
Returns the rewritten SCEV for Expr in the context of the current SCEV predicate.
This class represents an analyzed expression in the program.
LLVM_ABI bool isOne() const
Return true if the expression is a constant one.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI const SCEV * getCouldNotCompute()
LLVM_ABI const SCEV * getGEPExpr(GEPOperator *GEP, ArrayRef< const SCEV * > IndexExprs)
Returns an expression for a GEP.
LLVM_ABI const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
LLVM_ABI const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI const SCEV * getTruncateOrSignExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionalit...
Definition TypeSwitch.h:88
TypeSwitch< T, ResultT > & Case(CallableT &&caseFn)
Add a case on the given type.
Definition TypeSwitch.h:97
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:3982
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition VPlan.h:4057
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2530
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:81
size_t getNumSuccessors() const
Definition VPlan.h:219
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:204
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:198
static bool isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop latch, using isHeader().
static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop header, based on regions or VPDT in their absence.
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3565
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3732
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
Recipe to expand a SCEV expression.
Definition VPlan.h:3527
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1125
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:387
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4170
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4238
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the region.
Definition VPlan.h:4268
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2953
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3802
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:202
operand_range operands()
Definition VPlanValue.h:270
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:46
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition VPlan.cpp:131
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition VPlanValue.h:176
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:1915
A recipe to compute the pointers for widened memory accesses of SourceElementTy.
Definition VPlan.h:1976
A recipe for handling GEP instructions.
Definition VPlan.h:1852
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition VPlan.h:2199
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4300
VPBasicBlock * getEntry()
Definition VPlan.h:4389
VPValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4483
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4451
VPValue * getBackedgeTakenCount() const
Definition VPlan.h:4477
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1010
VPValue * getOrAddLiveIn(Value *V)
Gets the live-in VPValue for V or adds a new live-in (if none exists yet) for V.
Definition VPlan.h:4543
bool hasScalarVFOnly() const
Definition VPlan.h:4512
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
An efficient, type-erasing, non-owning reference to a callable.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
SCEVAffineAddRec_match< Op0_t, Op1_t, class_match< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)
bool match(const SCEV *S, const Pattern &P)
class_match< const SCEV > m_SCEV()
VPInstruction_match< VPInstruction::AnyOf > m_AnyOf()
AllRecipe_commutative_match< Instruction::Or, Op0_t, Op1_t > m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
VPScalarIVSteps_match< Op0_t, Op1_t, Op2_t > m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
GEPLikeRecipe_match< Op0_t, Op1_t > m_GetElementPtr(const Op0_t &Op0, const Op1_t &Op1)
VPInstruction_match< VPInstruction::ActiveLaneMask, Op0_t, Op1_t, Op2_t > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
bind_ty< VPInstruction > m_VPInstruction(VPInstruction *&V)
Match a VPInstruction, capturing if we match.
VPInstruction_match< VPInstruction::BranchOnCond > m_BranchOnCond()
bool isSingleScalar(const VPValue *VPV)
Returns true if VPV is a single scalar, either because it produces the same value for all lanes or on...
bool isUniformAcrossVFsAndUFs(VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr)
Get or create a VPValue that corresponds to the expansion of Expr.
VPBasicBlock * getFirstLoopHeader(VPlan &Plan, VPDominatorTree &VPDT)
Returns the header block of the first, top-level loop, or null if none exist.
bool isAddressSCEVForCost(const SCEV *Addr, ScalarEvolution &SE, const Loop *L)
Returns true if Addr is an address SCEV that can be passed to TTI::getAddressComputationCost,...
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
std::optional< MemoryLocation > getMemoryLocation(const VPRecipeBase &R)
Return a MemoryLocation for R with noalias metadata populated from R, if the recipe is supported and ...
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
const SCEV * getSCEVExprForVPValue(const VPValue *V, PredicatedScalarEvolution &PSE, const Loop *L=nullptr)
Return the SCEV expression for V.
unsigned getVFScaleFactor(VPRecipeBase *R)
Get the VF scaling factor applied to the recipe's output, if the recipe has one.
bool isHeaderMask(const VPValue *V, const VPlan &Plan)
Return true if V is a header mask in Plan.
LLVM_ABI_FOR_TEST std::optional< VPValue * > getRecipesForUncountableExit(VPlan &Plan, SmallVectorImpl< VPRecipeBase * > &Recipes, SmallVectorImpl< VPRecipeBase * > &GEPs)
Returns the VPValue representing the uncountable exit comparison used by AnyOf if the recipes it depe...
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1737
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< df_iterator< VPBlockShallowTraversalWrapper< VPBlockBase * > > > vp_depth_first_shallow(VPBlockBase *G)
Returns an iterator range to traverse the graph starting at G in depth-first order.
Definition VPlanCFG.h:216
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1744
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
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1770
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
A recipe for widening select instructions.
Definition VPlan.h:1805