LLVM 21.0.0git
LoopVectorizationPlanner.h
Go to the documentation of this file.
1//===- LoopVectorizationPlanner.h - Planner for LoopVectorization ---------===//
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/// \file
10/// This file provides a LoopVectorizationPlanner class.
11/// InnerLoopVectorizer vectorizes loops which contain only one basic
12/// LoopVectorizationPlanner - drives the vectorization process after having
13/// passed Legality checks.
14/// The planner builds and optimizes the Vectorization Plans which record the
15/// decisions how to vectorize the given loop. In particular, represent the
16/// control-flow of the vectorized version, the replication of instructions that
17/// are to be scalarized, and interleave access groups.
18///
19/// Also provides a VPlan-based builder utility analogous to IRBuilder.
20/// It provides an instruction-level API for generating VPInstructions while
21/// abstracting away the Recipe manipulation details.
22//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONPLANNER_H
25#define LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONPLANNER_H
26
27#include "VPlan.h"
28#include "llvm/ADT/SmallSet.h"
30
31namespace llvm {
32
33class LoopInfo;
34class DominatorTree;
35class LoopVectorizationLegality;
36class LoopVectorizationCostModel;
37class PredicatedScalarEvolution;
38class LoopVectorizeHints;
39class OptimizationRemarkEmitter;
40class TargetTransformInfo;
41class TargetLibraryInfo;
42class VPRecipeBuilder;
43struct VFRange;
44
45/// VPlan-based builder utility analogous to IRBuilder.
46class VPBuilder {
47 VPBasicBlock *BB = nullptr;
49
50 /// Insert \p VPI in BB at InsertPt if BB is set.
51 template <typename T> T *tryInsertInstruction(T *R) {
52 if (BB)
53 BB->insert(R, InsertPt);
54 return R;
55 }
56
57 VPInstruction *createInstruction(unsigned Opcode,
59 const Twine &Name = "") {
60 return tryInsertInstruction(new VPInstruction(Opcode, Operands, DL, Name));
61 }
62
63 VPInstruction *createInstruction(unsigned Opcode,
64 std::initializer_list<VPValue *> Operands,
65 DebugLoc DL, const Twine &Name = "") {
66 return createInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL, Name);
67 }
68
69public:
70 VPBuilder() = default;
71 VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); }
72 VPBuilder(VPRecipeBase *InsertPt) { setInsertPoint(InsertPt); }
74 setInsertPoint(TheBB, IP);
75 }
76
77 /// Clear the insertion point: created instructions will not be inserted into
78 /// a block.
80 BB = nullptr;
81 InsertPt = VPBasicBlock::iterator();
82 }
83
84 VPBasicBlock *getInsertBlock() const { return BB; }
85 VPBasicBlock::iterator getInsertPoint() const { return InsertPt; }
86
87 /// Create a VPBuilder to insert after \p R.
90 B.setInsertPoint(R->getParent(), std::next(R->getIterator()));
91 return B;
92 }
93
94 /// InsertPoint - A saved insertion point.
96 VPBasicBlock *Block = nullptr;
98
99 public:
100 /// Creates a new insertion point which doesn't point to anything.
101 VPInsertPoint() = default;
102
103 /// Creates a new insertion point at the given location.
105 : Block(InsertBlock), Point(InsertPoint) {}
106
107 /// Returns true if this insert point is set.
108 bool isSet() const { return Block != nullptr; }
109
110 VPBasicBlock *getBlock() const { return Block; }
111 VPBasicBlock::iterator getPoint() const { return Point; }
112 };
113
114 /// Sets the current insert point to a previously-saved location.
116 if (IP.isSet())
117 setInsertPoint(IP.getBlock(), IP.getPoint());
118 else
120 }
121
122 /// This specifies that created VPInstructions should be appended to the end
123 /// of the specified block.
125 assert(TheBB && "Attempting to set a null insert point");
126 BB = TheBB;
127 InsertPt = BB->end();
128 }
129
130 /// This specifies that created instructions should be inserted at the
131 /// specified point.
133 BB = TheBB;
134 InsertPt = IP;
135 }
136
137 /// This specifies that created instructions should be inserted at the
138 /// specified point.
140 BB = IP->getParent();
141 InsertPt = IP->getIterator();
142 }
143
144 /// Insert \p R at the current insertion point.
145 void insert(VPRecipeBase *R) { BB->insert(R, InsertPt); }
146
147 /// Create an N-ary operation with \p Opcode, \p Operands and set \p Inst as
148 /// its underlying Instruction.
150 Instruction *Inst = nullptr,
151 const Twine &Name = "") {
152 DebugLoc DL;
153 if (Inst)
154 DL = Inst->getDebugLoc();
155 VPInstruction *NewVPInst = createInstruction(Opcode, Operands, DL, Name);
156 NewVPInst->setUnderlyingValue(Inst);
157 return NewVPInst;
158 }
160 DebugLoc DL, const Twine &Name = "") {
161 return createInstruction(Opcode, Operands, DL, Name);
162 }
163 VPInstruction *createNaryOp(unsigned Opcode,
164 std::initializer_list<VPValue *> Operands,
165 std::optional<FastMathFlags> FMFs = {},
166 DebugLoc DL = {}, const Twine &Name = "") {
167 if (FMFs)
168 return tryInsertInstruction(
169 new VPInstruction(Opcode, Operands, *FMFs, DL, Name));
170 return createInstruction(Opcode, Operands, DL, Name);
171 }
172
174 std::initializer_list<VPValue *> Operands,
176 DebugLoc DL = {}, const Twine &Name = "") {
177 return tryInsertInstruction(
178 new VPInstruction(Opcode, Operands, WrapFlags, DL, Name));
179 }
180
182 const Twine &Name = "") {
183 return createInstruction(VPInstruction::Not, {Operand}, DL, Name);
184 }
185
187 const Twine &Name = "") {
188 return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL, Name);
189 }
190
192 const Twine &Name = "") {
193
194 return tryInsertInstruction(new VPInstruction(
195 Instruction::BinaryOps::Or, {LHS, RHS},
196 VPRecipeWithIRFlags::DisjointFlagsTy(false), DL, Name));
197 }
198
200 const Twine &Name = "") {
201 return tryInsertInstruction(
203 }
204
206 DebugLoc DL = {}, const Twine &Name = "",
207 std::optional<FastMathFlags> FMFs = std::nullopt) {
208 auto *Select =
209 FMFs ? new VPInstruction(Instruction::Select, {Cond, TrueVal, FalseVal},
210 *FMFs, DL, Name)
211 : new VPInstruction(Instruction::Select, {Cond, TrueVal, FalseVal},
212 DL, Name);
213 return tryInsertInstruction(Select);
214 }
215
216 /// Create a new ICmp VPInstruction with predicate \p Pred and operands \p A
217 /// and \p B.
218 /// TODO: add createFCmp when needed.
220 DebugLoc DL = {}, const Twine &Name = "") {
222 Pred <= CmpInst::LAST_ICMP_PREDICATE && "invalid predicate");
223 return tryInsertInstruction(
224 new VPInstruction(Instruction::ICmp, Pred, A, B, DL, Name));
225 }
226
228 const Twine &Name = "") {
229 return tryInsertInstruction(
231 }
233 const Twine &Name = "") {
234 return tryInsertInstruction(
236 }
237
238 /// Convert the input value \p Current to the corresponding value of an
239 /// induction with \p Start and \p Step values, using \p Start + \p Current *
240 /// \p Step.
242 FPMathOperator *FPBinOp, VPValue *Start,
243 VPValue *Current, VPValue *Step,
244 const Twine &Name = "") {
245 return tryInsertInstruction(
246 new VPDerivedIVRecipe(Kind, FPBinOp, Start, Current, Step, Name));
247 }
248
250 Type *ResultTy, DebugLoc DL) {
251 return tryInsertInstruction(
252 new VPScalarCastRecipe(Opcode, Op, ResultTy, DL));
253 }
254
256 Type *ResultTy) {
257 return tryInsertInstruction(new VPWidenCastRecipe(Opcode, Op, ResultTy));
258 }
259
262 FPMathOperator *FPBinOp, VPValue *IV, VPValue *Step) {
263 return tryInsertInstruction(new VPScalarIVStepsRecipe(
264 IV, Step, InductionOpcode,
265 FPBinOp ? FPBinOp->getFastMathFlags() : FastMathFlags()));
266 }
267
268 //===--------------------------------------------------------------------===//
269 // RAII helpers.
270 //===--------------------------------------------------------------------===//
271
272 /// RAII object that stores the current insertion point and restores it when
273 /// the object is destroyed.
275 VPBuilder &Builder;
276 VPBasicBlock *Block;
278
279 public:
281 : Builder(B), Block(B.getInsertBlock()), Point(B.getInsertPoint()) {}
282
285
286 ~InsertPointGuard() { Builder.restoreIP(VPInsertPoint(Block, Point)); }
287 };
288};
289
290/// TODO: The following VectorizationFactor was pulled out of
291/// LoopVectorizationCostModel class. LV also deals with
292/// VectorizerParams::VectorizationFactor.
293/// We need to streamline them.
294
295/// Information about vectorization costs.
297 /// Vector width with best cost.
299
300 /// Cost of the loop with that width.
302
303 /// Cost of the scalar loop.
305
306 /// The minimum trip count required to make vectorization profitable, e.g. due
307 /// to runtime checks.
309
313
314 /// Width 1 means no vectorization, cost 0 means uncomputed cost.
316 return {ElementCount::getFixed(1), 0, 0};
317 }
318
319 bool operator==(const VectorizationFactor &rhs) const {
320 return Width == rhs.Width && Cost == rhs.Cost;
321 }
322
323 bool operator!=(const VectorizationFactor &rhs) const {
324 return !(*this == rhs);
325 }
326};
327
328/// A class that represents two vectorization factors (initialized with 0 by
329/// default). One for fixed-width vectorization and one for scalable
330/// vectorization. This can be used by the vectorizer to choose from a range of
331/// fixed and/or scalable VFs in order to find the most cost-effective VF to
332/// vectorize with.
336
338 : FixedVF(ElementCount::getFixed(0)),
339 ScalableVF(ElementCount::getScalable(0)) {}
341 *(Max.isScalable() ? &ScalableVF : &FixedVF) = Max;
342 }
347 "Invalid scalable properties");
348 }
349
351
352 /// \return true if either fixed- or scalable VF is non-zero.
353 explicit operator bool() const { return FixedVF || ScalableVF; }
354
355 /// \return true if either fixed- or scalable VF is a valid vector VF.
356 bool hasVector() const { return FixedVF.isVector() || ScalableVF.isVector(); }
357};
358
359/// Planner drives the vectorization process after having passed
360/// Legality checks.
362 /// The loop that we evaluate.
363 Loop *OrigLoop;
364
365 /// Loop Info analysis.
366 LoopInfo *LI;
367
368 /// The dominator tree.
369 DominatorTree *DT;
370
371 /// Target Library Info.
372 const TargetLibraryInfo *TLI;
373
374 /// Target Transform Info.
376
377 /// The legality analysis.
379
380 /// The profitability analysis.
382
383 /// The interleaved access analysis.
385
387
388 const LoopVectorizeHints &Hints;
389
391
393
394 /// Profitable vector factors.
396
397 /// A builder used to construct the current plan.
398 VPBuilder Builder;
399
400 /// Computes the cost of \p Plan for vectorization factor \p VF.
401 ///
402 /// The current implementation requires access to the
403 /// LoopVectorizationLegality to handle inductions and reductions, which is
404 /// why it is kept separate from the VPlan-only cost infrastructure.
405 ///
406 /// TODO: Move to VPlan::cost once the use of LoopVectorizationLegality has
407 /// been retired.
408 InstructionCost cost(VPlan &Plan, ElementCount VF) const;
409
410 /// Precompute costs for certain instructions using the legacy cost model. The
411 /// function is used to bring up the VPlan-based cost model to initially avoid
412 /// taking different decisions due to inaccuracies in the legacy cost model.
413 InstructionCost precomputeCosts(VPlan &Plan, ElementCount VF,
414 VPCostContext &CostCtx) const;
415
416public:
418 Loop *L, LoopInfo *LI, DominatorTree *DT, const TargetLibraryInfo *TLI,
423 : OrigLoop(L), LI(LI), DT(DT), TLI(TLI), TTI(TTI), Legal(Legal), CM(CM),
424 IAI(IAI), PSE(PSE), Hints(Hints), ORE(ORE) {}
425
426 /// Build VPlans for the specified \p UserVF and \p UserIC if they are
427 /// non-zero or all applicable candidate VFs otherwise. If vectorization and
428 /// interleaving should be avoided up-front, no plans are generated.
429 void plan(ElementCount UserVF, unsigned UserIC);
430
431 /// Use the VPlan-native path to plan how to best vectorize, return the best
432 /// VF and its cost.
434
435 /// Return the VPlan for \p VF. At the moment, there is always a single VPlan
436 /// for each VF.
437 VPlan &getPlanFor(ElementCount VF) const;
438
439 /// Compute and return the most profitable vectorization factor. Also collect
440 /// all profitable VFs in ProfitableVFs.
442
443 /// Generate the IR code for the vectorized loop captured in VPlan \p BestPlan
444 /// according to the best selected \p VF and \p UF.
445 ///
446 /// TODO: \p VectorizingEpilogue indicates if the executed VPlan is for the
447 /// epilogue vector loop. It should be removed once the re-use issue has been
448 /// fixed.
449 /// \p ExpandedSCEVs is passed during execution of the plan for epilogue loop
450 /// to re-use expansion results generated during main plan execution.
451 ///
452 /// Returns a mapping of SCEVs to their expanded IR values.
453 /// Note that this is a temporary workaround needed due to the current
454 /// epilogue handling.
456 executePlan(ElementCount VF, unsigned UF, VPlan &BestPlan,
458 bool VectorizingEpilogue,
459 const DenseMap<const SCEV *, Value *> *ExpandedSCEVs = nullptr);
460
461#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
462 void printPlans(raw_ostream &O);
463#endif
464
465 /// Look through the existing plans and return true if we have one with
466 /// vectorization factor \p VF.
468 return any_of(VPlans,
469 [&](const VPlanPtr &Plan) { return Plan->hasVF(VF); });
470 }
471
472 /// Test a \p Predicate on a \p Range of VF's. Return the value of applying
473 /// \p Predicate on Range.Start, possibly decreasing Range.End such that the
474 /// returned value holds for the entire \p Range.
475 static bool
476 getDecisionAndClampRange(const std::function<bool(ElementCount)> &Predicate,
477 VFRange &Range);
478
479 /// \return The most profitable vectorization factor and the cost of that VF
480 /// for vectorizing the epilogue. Returns VectorizationFactor::Disabled if
481 /// epilogue vectorization is not supported for the loop.
483 selectEpilogueVectorizationFactor(const ElementCount MaxVF, unsigned IC);
484
485 /// Emit remarks for recipes with invalid costs in the available VPlans.
487
488protected:
489 /// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
490 /// according to the information gathered by Legal when it checked if it is
491 /// legal to vectorize the loop.
492 void buildVPlans(ElementCount MinVF, ElementCount MaxVF);
493
494private:
495 /// Build a VPlan according to the information gathered by Legal. \return a
496 /// VPlan for vectorization factors \p Range.Start and up to \p Range.End
497 /// exclusive, possibly decreasing \p Range.End.
498 VPlanPtr buildVPlan(VFRange &Range);
499
500 /// Build a VPlan using VPRecipes according to the information gather by
501 /// Legal. This method is only used for the legacy inner loop vectorizer.
502 /// \p Range's largest included VF is restricted to the maximum VF the
503 /// returned VPlan is valid for. If no VPlan can be built for the input range,
504 /// set the largest included VF to the maximum VF for which no plan could be
505 /// built.
506 VPlanPtr tryToBuildVPlanWithVPRecipes(VFRange &Range);
507
508 /// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
509 /// according to the information gathered by Legal when it checked if it is
510 /// legal to vectorize the loop. This method creates VPlans using VPRecipes.
511 void buildVPlansWithVPRecipes(ElementCount MinVF, ElementCount MaxVF);
512
513 // Adjust the recipes for reductions. For in-loop reductions the chain of
514 // instructions leading from the loop exit instr to the phi need to be
515 // converted to reductions, with one operand being vector and the other being
516 // the scalar reduction chain. For other reductions, a select is introduced
517 // between the phi and users outside the vector region when folding the tail.
518 void adjustRecipesForReductions(VPlanPtr &Plan,
519 VPRecipeBuilder &RecipeBuilder,
520 ElementCount MinVF);
521
522#ifndef NDEBUG
523 /// \return The most profitable vectorization factor for the available VPlans
524 /// and the cost of that VF.
525 /// This is now only used to verify the decisions by the new VPlan-based
526 /// cost-model and will be retired once the VPlan-based cost-model is
527 /// stabilized.
528 VectorizationFactor selectVectorizationFactor();
529#endif
530
531 /// Returns true if the per-lane cost of VectorizationFactor A is lower than
532 /// that of B.
533 bool isMoreProfitable(const VectorizationFactor &A,
534 const VectorizationFactor &B) const;
535
536 /// Returns true if the per-lane cost of VectorizationFactor A is lower than
537 /// that of B in the context of vectorizing a loop with known \p MaxTripCount.
538 bool isMoreProfitable(const VectorizationFactor &A,
539 const VectorizationFactor &B,
540 const unsigned MaxTripCount) const;
541
542 /// Determines if we have the infrastructure to vectorize the loop and its
543 /// epilogue, assuming the main loop is vectorized by \p VF.
544 bool isCandidateForEpilogueVectorization(const ElementCount VF) const;
545};
546
547} // namespace llvm
548
549#endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZATIONPLANNER_H
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
mir Rename Register Operands
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file contains the declarations of the Vectorization Plan base classes:
Value * RHS
Value * LHS
static const uint32_t IV[8]
Definition: blake3_impl.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
@ FIRST_ICMP_PREDICATE
Definition: InstrTypes.h:704
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:33
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
constexpr bool isVector() const
One or more elements.
Definition: TypeSize.h:326
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:311
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:205
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Definition: Operator.h:338
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags none()
InductionKind
This enum represents the kinds of inductions that we support.
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:630
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor...
Planner drives the vectorization process after having passed Legality checks.
VectorizationFactor selectEpilogueVectorizationFactor(const ElementCount MaxVF, unsigned IC)
VPlan & getPlanFor(ElementCount VF) const
Return the VPlan for VF.
Definition: VPlan.cpp:1606
LoopVectorizationPlanner(Loop *L, LoopInfo *LI, DominatorTree *DT, const TargetLibraryInfo *TLI, const TargetTransformInfo &TTI, LoopVectorizationLegality *Legal, LoopVectorizationCostModel &CM, InterleavedAccessInfo &IAI, PredicatedScalarEvolution &PSE, const LoopVectorizeHints &Hints, OptimizationRemarkEmitter *ORE)
VectorizationFactor planInVPlanNativePath(ElementCount UserVF)
Use the VPlan-native path to plan how to best vectorize, return the best VF and its cost.
void buildVPlans(ElementCount MinVF, ElementCount MaxVF)
Build VPlans for power-of-2 VF's between MinVF and MaxVF inclusive, according to the information gath...
Definition: VPlan.cpp:1591
VectorizationFactor computeBestVF()
Compute and return the most profitable vectorization factor.
void emitInvalidCostRemarks(OptimizationRemarkEmitter *ORE)
Emit remarks for recipes with invalid costs in the available VPlans.
static bool getDecisionAndClampRange(const std::function< bool(ElementCount)> &Predicate, VFRange &Range)
Test a Predicate on a Range of VF's.
Definition: VPlan.cpp:1572
void printPlans(raw_ostream &O)
Definition: VPlan.cpp:1620
void plan(ElementCount UserVF, unsigned UserIC)
Build VPlans for the specified UserVF and UserIC if they are non-zero or all applicable candidate VFs...
DenseMap< const SCEV *, Value * > executePlan(ElementCount VF, unsigned UF, VPlan &BestPlan, InnerLoopVectorizer &LB, DominatorTree *DT, bool VectorizingEpilogue, const DenseMap< const SCEV *, Value * > *ExpandedSCEVs=nullptr)
Generate the IR code for the vectorized loop captured in VPlan BestPlan according to the best selecte...
bool hasPlanWithVF(ElementCount VF) const
Look through the existing plans and return true if we have one with vectorization factor VF.
Utility class for getting and setting loop vectorizer hints in the form of loop metadata.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
The optimization diagnostic interface.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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:3200
RecipeListTy::iterator iterator
Instruction iterators...
Definition: VPlan.h:3227
iterator end()
Definition: VPlan.h:3237
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition: VPlan.h:3266
RAII object that stores the current insertion point and restores it when the object is destroyed.
InsertPointGuard(const InsertPointGuard &)=delete
InsertPointGuard & operator=(const InsertPointGuard &)=delete
InsertPoint - A saved insertion point.
VPInsertPoint(VPBasicBlock *InsertBlock, VPBasicBlock::iterator InsertPoint)
Creates a new insertion point at the given location.
VPBasicBlock::iterator getPoint() const
VPInsertPoint()=default
Creates a new insertion point which doesn't point to anything.
bool isSet() const
Returns true if this insert point is set.
VPlan-based builder utility analogous to IRBuilder.
VPValue * createICmp(CmpInst::Predicate Pred, VPValue *A, VPValue *B, DebugLoc DL={}, const Twine &Name="")
Create a new ICmp VPInstruction with predicate Pred and operands A and B.
void setInsertPoint(VPBasicBlock *TheBB, VPBasicBlock::iterator IP)
This specifies that created instructions should be inserted at the specified point.
void setInsertPoint(VPRecipeBase *IP)
This specifies that created instructions should be inserted at the specified point.
void restoreIP(VPInsertPoint IP)
Sets the current insert point to a previously-saved location.
VPValue * createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL={}, const Twine &Name="")
VPBasicBlock * getInsertBlock() const
VPDerivedIVRecipe * createDerivedIV(InductionDescriptor::InductionKind Kind, FPMathOperator *FPBinOp, VPValue *Start, VPValue *Current, VPValue *Step, const Twine &Name="")
Convert the input value Current to the corresponding value of an induction with Start and Step values...
void insert(VPRecipeBase *R)
Insert R at the current insertion point.
VPBasicBlock::iterator getInsertPoint() const
VPInstruction * createPtrAdd(VPValue *Ptr, VPValue *Offset, DebugLoc DL={}, const Twine &Name="")
VPValue * createInBoundsPtrAdd(VPValue *Ptr, VPValue *Offset, DebugLoc DL={}, const Twine &Name="")
VPBuilder(VPBasicBlock *InsertBB)
VPScalarCastRecipe * createScalarCast(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, DebugLoc DL)
static VPBuilder getToInsertAfter(VPRecipeBase *R)
Create a VPBuilder to insert after R.
VPInstruction * createNaryOp(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
VPScalarIVStepsRecipe * createScalarIVSteps(Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, VPValue *IV, VPValue *Step)
VPBuilder(VPRecipeBase *InsertPt)
VPInstruction * createOverflowingOp(unsigned Opcode, std::initializer_list< VPValue * > Operands, VPRecipeWithIRFlags::WrapFlagsTy WrapFlags, DebugLoc DL={}, const Twine &Name="")
VPWidenCastRecipe * createWidenCast(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
VPValue * createAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL={}, const Twine &Name="")
void clearInsertionPoint()
Clear the insertion point: created instructions will not be inserted into a block.
VPInstruction * createNaryOp(unsigned Opcode, ArrayRef< VPValue * > Operands, Instruction *Inst=nullptr, const Twine &Name="")
Create an N-ary operation with Opcode, Operands and set Inst as its underlying Instruction.
VPValue * createNot(VPValue *Operand, DebugLoc DL={}, const Twine &Name="")
VPBuilder()=default
VPInstruction * createNaryOp(unsigned Opcode, std::initializer_list< VPValue * > Operands, std::optional< FastMathFlags > FMFs={}, DebugLoc DL={}, const Twine &Name="")
VPValue * createLogicalAnd(VPValue *LHS, VPValue *RHS, DebugLoc DL={}, const Twine &Name="")
VPBuilder(VPBasicBlock *TheBB, VPBasicBlock::iterator IP)
VPValue * createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal, DebugLoc DL={}, const Twine &Name="", std::optional< FastMathFlags > FMFs=std::nullopt)
void setInsertPoint(VPBasicBlock *TheBB)
This specifies that created VPInstructions should be appended to the end of the specified block.
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition: VPlan.h:3074
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:845
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:366
VPBasicBlock * getParent()
Definition: VPlan.h:391
Helper class to create VPRecipies from IR instructions.
VPScalarCastRecipe is a recipe to create scalar cast instructions.
Definition: VPlan.h:1246
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition: VPlan.h:3143
void setUnderlyingValue(Value *Val)
Definition: VPlanValue.h:193
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition: VPlan.h:1194
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3476
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
self_iterator getIterator()
Definition: ilist_node.h:132
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
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:1746
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:74
A class that represents two vectorization factors (initialized with 0 by default).
FixedScalableVFPair(const ElementCount &FixedVF, const ElementCount &ScalableVF)
FixedScalableVFPair(const ElementCount &Max)
static FixedScalableVFPair getNone()
A range of powers-of-2 vectorization factors with fixed start and adjustable end.
Definition: VPlanHelpers.h:62
Struct to hold various analysis needed for cost computations.
Definition: VPlanHelpers.h:356
TODO: The following VectorizationFactor was pulled out of LoopVectorizationCostModel class.
InstructionCost Cost
Cost of the loop with that width.
ElementCount MinProfitableTripCount
The minimum trip count required to make vectorization profitable, e.g.
bool operator==(const VectorizationFactor &rhs) const
ElementCount Width
Vector width with best cost.
InstructionCost ScalarCost
Cost of the scalar loop.
bool operator!=(const VectorizationFactor &rhs) const
static VectorizationFactor Disabled()
Width 1 means no vectorization, cost 0 means uncomputed cost.
VectorizationFactor(ElementCount Width, InstructionCost Cost, InstructionCost ScalarCost)