LLVM 22.0.0git
VPlan.h
Go to the documentation of this file.
1//===- VPlan.h - Represent A Vectorizer Plan --------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file contains the declarations of the Vectorization Plan base classes:
11/// 1. VPBasicBlock and VPRegionBlock that inherit from a common pure virtual
12/// VPBlockBase, together implementing a Hierarchical CFG;
13/// 2. Pure virtual VPRecipeBase serving as the base class for recipes contained
14/// within VPBasicBlocks;
15/// 3. Pure virtual VPSingleDefRecipe serving as a base class for recipes that
16/// also inherit from VPValue.
17/// 4. VPInstruction, a concrete Recipe and VPUser modeling a single planned
18/// instruction;
19/// 5. The VPlan class holding a candidate for vectorization;
20/// These are documented in docs/VectorizationPlan.rst.
21//
22//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
25#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
26
27#include "VPlanAnalysis.h"
28#include "VPlanValue.h"
29#include "llvm/ADT/DenseMap.h"
33#include "llvm/ADT/Twine.h"
34#include "llvm/ADT/ilist.h"
35#include "llvm/ADT/ilist_node.h"
38#include "llvm/IR/DebugLoc.h"
39#include "llvm/IR/FMF.h"
40#include "llvm/IR/Operator.h"
43#include <algorithm>
44#include <cassert>
45#include <cstddef>
46#include <string>
47
48namespace llvm {
49
50class BasicBlock;
51class DominatorTree;
53class IRBuilderBase;
54struct VPTransformState;
55class raw_ostream;
57class SCEV;
58class Type;
59class VPBasicBlock;
60class VPBuilder;
61class VPDominatorTree;
62class VPRegionBlock;
63class VPlan;
64class VPLane;
66class VPlanSlp;
67class Value;
69class LoopVersioning;
70
71struct VPCostContext;
72
73namespace Intrinsic {
74typedef unsigned ID;
75}
76
77using VPlanPtr = std::unique_ptr<VPlan>;
78
79/// VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
80/// A VPBlockBase can be either a VPBasicBlock or a VPRegionBlock.
82 friend class VPBlockUtils;
83
84 const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
85
86 /// An optional name for the block.
87 std::string Name;
88
89 /// The immediate VPRegionBlock which this VPBlockBase belongs to, or null if
90 /// it is a topmost VPBlockBase.
91 VPRegionBlock *Parent = nullptr;
92
93 /// List of predecessor blocks.
95
96 /// List of successor blocks.
98
99 /// VPlan containing the block. Can only be set on the entry block of the
100 /// plan.
101 VPlan *Plan = nullptr;
102
103 /// Add \p Successor as the last successor to this block.
104 void appendSuccessor(VPBlockBase *Successor) {
105 assert(Successor && "Cannot add nullptr successor!");
106 Successors.push_back(Successor);
107 }
108
109 /// Add \p Predecessor as the last predecessor to this block.
110 void appendPredecessor(VPBlockBase *Predecessor) {
111 assert(Predecessor && "Cannot add nullptr predecessor!");
112 Predecessors.push_back(Predecessor);
113 }
114
115 /// Remove \p Predecessor from the predecessors of this block.
116 void removePredecessor(VPBlockBase *Predecessor) {
117 auto Pos = find(Predecessors, Predecessor);
118 assert(Pos && "Predecessor does not exist");
119 Predecessors.erase(Pos);
120 }
121
122 /// Remove \p Successor from the successors of this block.
123 void removeSuccessor(VPBlockBase *Successor) {
124 auto Pos = find(Successors, Successor);
125 assert(Pos && "Successor does not exist");
126 Successors.erase(Pos);
127 }
128
129 /// This function replaces one predecessor with another, useful when
130 /// trying to replace an old block in the CFG with a new one.
131 void replacePredecessor(VPBlockBase *Old, VPBlockBase *New) {
132 auto I = find(Predecessors, Old);
133 assert(I != Predecessors.end());
134 assert(Old->getParent() == New->getParent() &&
135 "replaced predecessor must have the same parent");
136 *I = New;
137 }
138
139 /// This function replaces one successor with another, useful when
140 /// trying to replace an old block in the CFG with a new one.
141 void replaceSuccessor(VPBlockBase *Old, VPBlockBase *New) {
142 auto I = find(Successors, Old);
143 assert(I != Successors.end());
144 assert(Old->getParent() == New->getParent() &&
145 "replaced successor must have the same parent");
146 *I = New;
147 }
148
149protected:
150 VPBlockBase(const unsigned char SC, const std::string &N)
151 : SubclassID(SC), Name(N) {}
152
153public:
154 /// An enumeration for keeping track of the concrete subclass of VPBlockBase
155 /// that are actually instantiated. Values of this enumeration are kept in the
156 /// SubclassID field of the VPBlockBase objects. They are used for concrete
157 /// type identification.
158 using VPBlockTy = enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC };
159
161
162 virtual ~VPBlockBase() = default;
163
164 const std::string &getName() const { return Name; }
165
166 void setName(const Twine &newName) { Name = newName.str(); }
167
168 /// \return an ID for the concrete type of this object.
169 /// This is used to implement the classof checks. This should not be used
170 /// for any other purpose, as the values may change as LLVM evolves.
171 unsigned getVPBlockID() const { return SubclassID; }
172
173 VPRegionBlock *getParent() { return Parent; }
174 const VPRegionBlock *getParent() const { return Parent; }
175
176 /// \return A pointer to the plan containing the current block.
177 VPlan *getPlan();
178 const VPlan *getPlan() const;
179
180 /// Sets the pointer of the plan containing the block. The block must be the
181 /// entry block into the VPlan.
182 void setPlan(VPlan *ParentPlan);
183
184 void setParent(VPRegionBlock *P) { Parent = P; }
185
186 /// \return the VPBasicBlock that is the entry of this VPBlockBase,
187 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
188 /// VPBlockBase is a VPBasicBlock, it is returned.
189 const VPBasicBlock *getEntryBasicBlock() const;
190 VPBasicBlock *getEntryBasicBlock();
191
192 /// \return the VPBasicBlock that is the exiting this VPBlockBase,
193 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
194 /// VPBlockBase is a VPBasicBlock, it is returned.
195 const VPBasicBlock *getExitingBasicBlock() const;
196 VPBasicBlock *getExitingBasicBlock();
197
198 const VPBlocksTy &getSuccessors() const { return Successors; }
199 VPBlocksTy &getSuccessors() { return Successors; }
200
203
204 const VPBlocksTy &getPredecessors() const { return Predecessors; }
205 VPBlocksTy &getPredecessors() { return Predecessors; }
206
207 /// \return the successor of this VPBlockBase if it has a single successor.
208 /// Otherwise return a null pointer.
210 return (Successors.size() == 1 ? *Successors.begin() : nullptr);
211 }
212
213 /// \return the predecessor of this VPBlockBase if it has a single
214 /// predecessor. Otherwise return a null pointer.
216 return (Predecessors.size() == 1 ? *Predecessors.begin() : nullptr);
217 }
218
219 size_t getNumSuccessors() const { return Successors.size(); }
220 size_t getNumPredecessors() const { return Predecessors.size(); }
221
222 /// Returns true if this block has any predecessors.
223 bool hasPredecessors() const { return !Predecessors.empty(); }
224
225 /// An Enclosing Block of a block B is any block containing B, including B
226 /// itself. \return the closest enclosing block starting from "this", which
227 /// has successors. \return the root enclosing block if all enclosing blocks
228 /// have no successors.
229 VPBlockBase *getEnclosingBlockWithSuccessors();
230
231 /// \return the closest enclosing block starting from "this", which has
232 /// predecessors. \return the root enclosing block if all enclosing blocks
233 /// have no predecessors.
234 VPBlockBase *getEnclosingBlockWithPredecessors();
235
236 /// \return the successors either attached directly to this VPBlockBase or, if
237 /// this VPBlockBase is the exit block of a VPRegionBlock and has no
238 /// successors of its own, search recursively for the first enclosing
239 /// VPRegionBlock that has successors and return them. If no such
240 /// VPRegionBlock exists, return the (empty) successors of the topmost
241 /// VPBlockBase reached.
243 return getEnclosingBlockWithSuccessors()->getSuccessors();
244 }
245
246 /// \return the hierarchical successor of this VPBlockBase if it has a single
247 /// hierarchical successor. Otherwise return a null pointer.
249 return getEnclosingBlockWithSuccessors()->getSingleSuccessor();
250 }
251
252 /// \return the predecessors either attached directly to this VPBlockBase or,
253 /// if this VPBlockBase is the entry block of a VPRegionBlock and has no
254 /// predecessors of its own, search recursively for the first enclosing
255 /// VPRegionBlock that has predecessors and return them. If no such
256 /// VPRegionBlock exists, return the (empty) predecessors of the topmost
257 /// VPBlockBase reached.
259 return getEnclosingBlockWithPredecessors()->getPredecessors();
260 }
261
262 /// \return the hierarchical predecessor of this VPBlockBase if it has a
263 /// single hierarchical predecessor. Otherwise return a null pointer.
267
268 /// Set a given VPBlockBase \p Successor as the single successor of this
269 /// VPBlockBase. This VPBlockBase is not added as predecessor of \p Successor.
270 /// This VPBlockBase must have no successors.
272 assert(Successors.empty() && "Setting one successor when others exist.");
273 assert(Successor->getParent() == getParent() &&
274 "connected blocks must have the same parent");
275 appendSuccessor(Successor);
276 }
277
278 /// Set two given VPBlockBases \p IfTrue and \p IfFalse to be the two
279 /// successors of this VPBlockBase. This VPBlockBase is not added as
280 /// predecessor of \p IfTrue or \p IfFalse. This VPBlockBase must have no
281 /// successors.
282 void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse) {
283 assert(Successors.empty() && "Setting two successors when others exist.");
284 appendSuccessor(IfTrue);
285 appendSuccessor(IfFalse);
286 }
287
288 /// Set each VPBasicBlock in \p NewPreds as predecessor of this VPBlockBase.
289 /// This VPBlockBase must have no predecessors. This VPBlockBase is not added
290 /// as successor of any VPBasicBlock in \p NewPreds.
292 assert(Predecessors.empty() && "Block predecessors already set.");
293 for (auto *Pred : NewPreds)
294 appendPredecessor(Pred);
295 }
296
297 /// Set each VPBasicBlock in \p NewSuccss as successor of this VPBlockBase.
298 /// This VPBlockBase must have no successors. This VPBlockBase is not added
299 /// as predecessor of any VPBasicBlock in \p NewSuccs.
301 assert(Successors.empty() && "Block successors already set.");
302 for (auto *Succ : NewSuccs)
303 appendSuccessor(Succ);
304 }
305
306 /// Remove all the predecessor of this block.
307 void clearPredecessors() { Predecessors.clear(); }
308
309 /// Remove all the successors of this block.
310 void clearSuccessors() { Successors.clear(); }
311
312 /// Swap predecessors of the block. The block must have exactly 2
313 /// predecessors.
315 assert(Predecessors.size() == 2 && "must have 2 predecessors to swap");
316 std::swap(Predecessors[0], Predecessors[1]);
317 }
318
319 /// Swap successors of the block. The block must have exactly 2 successors.
320 // TODO: This should be part of introducing conditional branch recipes rather
321 // than being independent.
323 assert(Successors.size() == 2 && "must have 2 successors to swap");
324 std::swap(Successors[0], Successors[1]);
325 }
326
327 /// Returns the index for \p Pred in the blocks predecessors list.
328 unsigned getIndexForPredecessor(const VPBlockBase *Pred) const {
329 assert(count(Predecessors, Pred) == 1 &&
330 "must have Pred exactly once in Predecessors");
331 return std::distance(Predecessors.begin(), find(Predecessors, Pred));
332 }
333
334 /// Returns the index for \p Succ in the blocks successor list.
335 unsigned getIndexForSuccessor(const VPBlockBase *Succ) const {
336 assert(count(Successors, Succ) == 1 &&
337 "must have Succ exactly once in Successors");
338 return std::distance(Successors.begin(), find(Successors, Succ));
339 }
340
341 /// The method which generates the output IR that correspond to this
342 /// VPBlockBase, thereby "executing" the VPlan.
343 virtual void execute(VPTransformState *State) = 0;
344
345 /// Return the cost of the block.
347
348 /// Return true if it is legal to hoist instructions into this block.
350 // There are currently no constraints that prevent an instruction to be
351 // hoisted into a VPBlockBase.
352 return true;
353 }
354
355#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
356 void printAsOperand(raw_ostream &OS, bool PrintType = false) const {
357 OS << getName();
358 }
359
360 /// Print plain-text dump of this VPBlockBase to \p O, prefixing all lines
361 /// with \p Indent. \p SlotTracker is used to print unnamed VPValue's using
362 /// consequtive numbers.
363 ///
364 /// Note that the numbering is applied to the whole VPlan, so printing
365 /// individual blocks is consistent with the whole VPlan printing.
366 virtual void print(raw_ostream &O, const Twine &Indent,
367 VPSlotTracker &SlotTracker) const = 0;
368
369 /// Print plain-text dump of this VPlan to \p O.
370 void print(raw_ostream &O) const;
371
372 /// Print the successors of this block to \p O, prefixing all lines with \p
373 /// Indent.
374 void printSuccessors(raw_ostream &O, const Twine &Indent) const;
375
376 /// Dump this VPBlockBase to dbgs().
377 LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
378#endif
379
380 /// Clone the current block and it's recipes without updating the operands of
381 /// the cloned recipes, including all blocks in the single-entry single-exit
382 /// region for VPRegionBlocks.
383 virtual VPBlockBase *clone() = 0;
384};
385
386/// VPRecipeBase is a base class modeling a sequence of one or more output IR
387/// instructions. VPRecipeBase owns the VPValues it defines through VPDef
388/// and is responsible for deleting its defined values. Single-value
389/// recipes must inherit from VPSingleDef instead of inheriting from both
390/// VPRecipeBase and VPValue separately.
392 : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock>,
393 public VPDef,
394 public VPUser {
395 friend VPBasicBlock;
396 friend class VPBlockUtils;
397
398 /// Each VPRecipe belongs to a single VPBasicBlock.
399 VPBasicBlock *Parent = nullptr;
400
401 /// The debug location for the recipe.
402 DebugLoc DL;
403
404public:
405 VPRecipeBase(const unsigned char SC, ArrayRef<VPValue *> Operands,
407 : VPDef(SC), VPUser(Operands), DL(DL) {}
408
409 virtual ~VPRecipeBase() = default;
410
411 /// Clone the current recipe.
412 virtual VPRecipeBase *clone() = 0;
413
414 /// \return the VPBasicBlock which this VPRecipe belongs to.
415 VPBasicBlock *getParent() { return Parent; }
416 const VPBasicBlock *getParent() const { return Parent; }
417
418 /// The method which generates the output IR instructions that correspond to
419 /// this VPRecipe, thereby "executing" the VPlan.
420 virtual void execute(VPTransformState &State) = 0;
421
422 /// Return the cost of this recipe, taking into account if the cost
423 /// computation should be skipped and the ForceTargetInstructionCost flag.
424 /// Also takes care of printing the cost for debugging.
426
427 /// Insert an unlinked recipe into a basic block immediately before
428 /// the specified recipe.
429 void insertBefore(VPRecipeBase *InsertPos);
430 /// Insert an unlinked recipe into \p BB immediately before the insertion
431 /// point \p IP;
432 void insertBefore(VPBasicBlock &BB, iplist<VPRecipeBase>::iterator IP);
433
434 /// Insert an unlinked Recipe into a basic block immediately after
435 /// the specified Recipe.
436 void insertAfter(VPRecipeBase *InsertPos);
437
438 /// Unlink this recipe from its current VPBasicBlock and insert it into
439 /// the VPBasicBlock that MovePos lives in, right after MovePos.
440 void moveAfter(VPRecipeBase *MovePos);
441
442 /// Unlink this recipe and insert into BB before I.
443 ///
444 /// \pre I is a valid iterator into BB.
445 void moveBefore(VPBasicBlock &BB, iplist<VPRecipeBase>::iterator I);
446
447 /// This method unlinks 'this' from the containing basic block, but does not
448 /// delete it.
449 void removeFromParent();
450
451 /// This method unlinks 'this' from the containing basic block and deletes it.
452 ///
453 /// \returns an iterator pointing to the element after the erased one
455
456 /// Method to support type inquiry through isa, cast, and dyn_cast.
457 static inline bool classof(const VPDef *D) {
458 // All VPDefs are also VPRecipeBases.
459 return true;
460 }
461
462 static inline bool classof(const VPUser *U) { return true; }
463
464 /// Returns true if the recipe may have side-effects.
465 bool mayHaveSideEffects() const;
466
467 /// Returns true for PHI-like recipes.
468 bool isPhi() const;
469
470 /// Returns true if the recipe may read from memory.
471 bool mayReadFromMemory() const;
472
473 /// Returns true if the recipe may write to memory.
474 bool mayWriteToMemory() const;
475
476 /// Returns true if the recipe may read from or write to memory.
477 bool mayReadOrWriteMemory() const {
479 }
480
481 /// Returns the debug location of the recipe.
482 DebugLoc getDebugLoc() const { return DL; }
483
484 /// Return true if the recipe is a scalar cast.
485 bool isScalarCast() const;
486
487 /// Set the recipe's debug location to \p NewDL.
488 void setDebugLoc(DebugLoc NewDL) { DL = NewDL; }
489
490protected:
491 /// Compute the cost of this recipe either using a recipe's specialized
492 /// implementation or using the legacy cost model and the underlying
493 /// instructions.
494 virtual InstructionCost computeCost(ElementCount VF,
495 VPCostContext &Ctx) const;
496};
497
498// Helper macro to define common classof implementations for recipes.
499#define VP_CLASSOF_IMPL(VPDefID) \
500 static inline bool classof(const VPDef *D) { \
501 return D->getVPDefID() == VPDefID; \
502 } \
503 static inline bool classof(const VPValue *V) { \
504 auto *R = V->getDefiningRecipe(); \
505 return R && R->getVPDefID() == VPDefID; \
506 } \
507 static inline bool classof(const VPUser *U) { \
508 auto *R = dyn_cast<VPRecipeBase>(U); \
509 return R && R->getVPDefID() == VPDefID; \
510 } \
511 static inline bool classof(const VPRecipeBase *R) { \
512 return R->getVPDefID() == VPDefID; \
513 } \
514 static inline bool classof(const VPSingleDefRecipe *R) { \
515 return R->getVPDefID() == VPDefID; \
516 }
517
518/// VPSingleDef is a base class for recipes for modeling a sequence of one or
519/// more output IR that define a single result VPValue.
520/// Note that VPRecipeBase must be inherited from before VPValue.
521class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
522public:
523 VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
525 : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
526
527 VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
529 : VPRecipeBase(SC, Operands, DL), VPValue(this, UV) {}
530
531 static inline bool classof(const VPRecipeBase *R) {
532 switch (R->getVPDefID()) {
533 case VPRecipeBase::VPDerivedIVSC:
534 case VPRecipeBase::VPEVLBasedIVPHISC:
535 case VPRecipeBase::VPExpandSCEVSC:
536 case VPRecipeBase::VPExpressionSC:
537 case VPRecipeBase::VPInstructionSC:
538 case VPRecipeBase::VPReductionEVLSC:
539 case VPRecipeBase::VPReductionSC:
540 case VPRecipeBase::VPReplicateSC:
541 case VPRecipeBase::VPScalarIVStepsSC:
542 case VPRecipeBase::VPVectorPointerSC:
543 case VPRecipeBase::VPVectorEndPointerSC:
544 case VPRecipeBase::VPWidenCallSC:
545 case VPRecipeBase::VPWidenCanonicalIVSC:
546 case VPRecipeBase::VPWidenCastSC:
547 case VPRecipeBase::VPWidenGEPSC:
548 case VPRecipeBase::VPWidenIntrinsicSC:
549 case VPRecipeBase::VPWidenSC:
550 case VPRecipeBase::VPWidenSelectSC:
551 case VPRecipeBase::VPBlendSC:
552 case VPRecipeBase::VPPredInstPHISC:
553 case VPRecipeBase::VPCanonicalIVPHISC:
554 case VPRecipeBase::VPActiveLaneMaskPHISC:
555 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
556 case VPRecipeBase::VPWidenPHISC:
557 case VPRecipeBase::VPWidenIntOrFpInductionSC:
558 case VPRecipeBase::VPWidenPointerInductionSC:
559 case VPRecipeBase::VPReductionPHISC:
560 case VPRecipeBase::VPPartialReductionSC:
561 return true;
562 case VPRecipeBase::VPBranchOnMaskSC:
563 case VPRecipeBase::VPInterleaveEVLSC:
564 case VPRecipeBase::VPInterleaveSC:
565 case VPRecipeBase::VPIRInstructionSC:
566 case VPRecipeBase::VPWidenLoadEVLSC:
567 case VPRecipeBase::VPWidenLoadSC:
568 case VPRecipeBase::VPWidenStoreEVLSC:
569 case VPRecipeBase::VPWidenStoreSC:
570 case VPRecipeBase::VPHistogramSC:
571 // TODO: Widened stores don't define a value, but widened loads do. Split
572 // the recipes to be able to make widened loads VPSingleDefRecipes.
573 return false;
574 }
575 llvm_unreachable("Unhandled VPDefID");
576 }
577
578 static inline bool classof(const VPUser *U) {
579 auto *R = dyn_cast<VPRecipeBase>(U);
580 return R && classof(R);
581 }
582
583 virtual VPSingleDefRecipe *clone() override = 0;
584
585 /// Returns the underlying instruction.
592
593#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
594 /// Print this VPSingleDefRecipe to dbgs() (for debugging).
595 LLVM_DUMP_METHOD void dump() const;
596#endif
597};
598
599/// Class to record and manage LLVM IR flags.
601 enum class OperationType : unsigned char {
602 Cmp,
603 OverflowingBinOp,
604 Trunc,
605 DisjointOp,
606 PossiblyExactOp,
607 GEPOp,
608 FPMathOp,
609 NonNegOp,
610 Other
611 };
612
613public:
614 struct WrapFlagsTy {
615 char HasNUW : 1;
616 char HasNSW : 1;
617
619 };
620
622 char HasNUW : 1;
623 char HasNSW : 1;
624
626 };
627
632
634 char NonNeg : 1;
635 NonNegFlagsTy(bool IsNonNeg) : NonNeg(IsNonNeg) {}
636 };
637
638private:
639 struct ExactFlagsTy {
640 char IsExact : 1;
641 };
642 struct FastMathFlagsTy {
643 char AllowReassoc : 1;
644 char NoNaNs : 1;
645 char NoInfs : 1;
646 char NoSignedZeros : 1;
647 char AllowReciprocal : 1;
648 char AllowContract : 1;
649 char ApproxFunc : 1;
650
651 LLVM_ABI_FOR_TEST FastMathFlagsTy(const FastMathFlags &FMF);
652 };
653
654 OperationType OpType;
655
656 union {
661 ExactFlagsTy ExactFlags;
664 FastMathFlagsTy FMFs;
665 unsigned AllFlags;
666 };
667
668public:
669 VPIRFlags() : OpType(OperationType::Other), AllFlags(0) {}
670
672 if (auto *Op = dyn_cast<CmpInst>(&I)) {
673 OpType = OperationType::Cmp;
674 CmpPredicate = Op->getPredicate();
675 } else if (auto *Op = dyn_cast<PossiblyDisjointInst>(&I)) {
676 OpType = OperationType::DisjointOp;
677 DisjointFlags.IsDisjoint = Op->isDisjoint();
678 } else if (auto *Op = dyn_cast<OverflowingBinaryOperator>(&I)) {
679 OpType = OperationType::OverflowingBinOp;
680 WrapFlags = {Op->hasNoUnsignedWrap(), Op->hasNoSignedWrap()};
681 } else if (auto *Op = dyn_cast<TruncInst>(&I)) {
682 OpType = OperationType::Trunc;
683 TruncFlags = {Op->hasNoUnsignedWrap(), Op->hasNoSignedWrap()};
684 } else if (auto *Op = dyn_cast<PossiblyExactOperator>(&I)) {
685 OpType = OperationType::PossiblyExactOp;
686 ExactFlags.IsExact = Op->isExact();
687 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
688 OpType = OperationType::GEPOp;
689 GEPFlags = GEP->getNoWrapFlags();
690 } else if (auto *PNNI = dyn_cast<PossiblyNonNegInst>(&I)) {
691 OpType = OperationType::NonNegOp;
692 NonNegFlags.NonNeg = PNNI->hasNonNeg();
693 } else if (auto *Op = dyn_cast<FPMathOperator>(&I)) {
694 OpType = OperationType::FPMathOp;
695 FMFs = Op->getFastMathFlags();
696 } else {
697 OpType = OperationType::Other;
698 AllFlags = 0;
699 }
700 }
701
703 : OpType(OperationType::Cmp), CmpPredicate(Pred) {}
704
706 : OpType(OperationType::OverflowingBinOp), WrapFlags(WrapFlags) {}
707
708 VPIRFlags(FastMathFlags FMFs) : OpType(OperationType::FPMathOp), FMFs(FMFs) {}
709
711 : OpType(OperationType::DisjointOp), DisjointFlags(DisjointFlags) {}
712
714 : OpType(OperationType::NonNegOp), NonNegFlags(NonNegFlags) {}
715
717 : OpType(OperationType::GEPOp), GEPFlags(GEPFlags) {}
718
720 OpType = Other.OpType;
721 AllFlags = Other.AllFlags;
722 }
723
724 /// Only keep flags also present in \p Other. \p Other must have the same
725 /// OpType as the current object.
726 void intersectFlags(const VPIRFlags &Other);
727
728 /// Drop all poison-generating flags.
730 // NOTE: This needs to be kept in-sync with
731 // Instruction::dropPoisonGeneratingFlags.
732 switch (OpType) {
733 case OperationType::OverflowingBinOp:
734 WrapFlags.HasNUW = false;
735 WrapFlags.HasNSW = false;
736 break;
737 case OperationType::Trunc:
738 TruncFlags.HasNUW = false;
739 TruncFlags.HasNSW = false;
740 break;
741 case OperationType::DisjointOp:
742 DisjointFlags.IsDisjoint = false;
743 break;
744 case OperationType::PossiblyExactOp:
745 ExactFlags.IsExact = false;
746 break;
747 case OperationType::GEPOp:
749 break;
750 case OperationType::FPMathOp:
751 FMFs.NoNaNs = false;
752 FMFs.NoInfs = false;
753 break;
754 case OperationType::NonNegOp:
755 NonNegFlags.NonNeg = false;
756 break;
757 case OperationType::Cmp:
758 case OperationType::Other:
759 break;
760 }
761 }
762
763 /// Apply the IR flags to \p I.
764 void applyFlags(Instruction &I) const {
765 switch (OpType) {
766 case OperationType::OverflowingBinOp:
767 I.setHasNoUnsignedWrap(WrapFlags.HasNUW);
768 I.setHasNoSignedWrap(WrapFlags.HasNSW);
769 break;
770 case OperationType::Trunc:
771 I.setHasNoUnsignedWrap(TruncFlags.HasNUW);
772 I.setHasNoSignedWrap(TruncFlags.HasNSW);
773 break;
774 case OperationType::DisjointOp:
775 cast<PossiblyDisjointInst>(&I)->setIsDisjoint(DisjointFlags.IsDisjoint);
776 break;
777 case OperationType::PossiblyExactOp:
778 I.setIsExact(ExactFlags.IsExact);
779 break;
780 case OperationType::GEPOp:
781 cast<GetElementPtrInst>(&I)->setNoWrapFlags(GEPFlags);
782 break;
783 case OperationType::FPMathOp:
784 I.setHasAllowReassoc(FMFs.AllowReassoc);
785 I.setHasNoNaNs(FMFs.NoNaNs);
786 I.setHasNoInfs(FMFs.NoInfs);
787 I.setHasNoSignedZeros(FMFs.NoSignedZeros);
788 I.setHasAllowReciprocal(FMFs.AllowReciprocal);
789 I.setHasAllowContract(FMFs.AllowContract);
790 I.setHasApproxFunc(FMFs.ApproxFunc);
791 break;
792 case OperationType::NonNegOp:
793 I.setNonNeg(NonNegFlags.NonNeg);
794 break;
795 case OperationType::Cmp:
796 case OperationType::Other:
797 break;
798 }
799 }
800
802 assert(OpType == OperationType::Cmp &&
803 "recipe doesn't have a compare predicate");
804 return CmpPredicate;
805 }
806
808 assert(OpType == OperationType::Cmp &&
809 "recipe doesn't have a compare predicate");
810 CmpPredicate = Pred;
811 }
812
814
815 /// Returns true if the recipe has a comparison predicate.
816 bool hasPredicate() const { return OpType == OperationType::Cmp; }
817
818 /// Returns true if the recipe has fast-math flags.
819 bool hasFastMathFlags() const { return OpType == OperationType::FPMathOp; }
820
822
823 /// Returns true if the recipe has non-negative flag.
824 bool hasNonNegFlag() const { return OpType == OperationType::NonNegOp; }
825
826 bool isNonNeg() const {
827 assert(OpType == OperationType::NonNegOp &&
828 "recipe doesn't have a NNEG flag");
829 return NonNegFlags.NonNeg;
830 }
831
832 bool hasNoUnsignedWrap() const {
833 switch (OpType) {
834 case OperationType::OverflowingBinOp:
835 return WrapFlags.HasNUW;
836 case OperationType::Trunc:
837 return TruncFlags.HasNUW;
838 default:
839 llvm_unreachable("recipe doesn't have a NUW flag");
840 }
841 }
842
843 bool hasNoSignedWrap() const {
844 switch (OpType) {
845 case OperationType::OverflowingBinOp:
846 return WrapFlags.HasNSW;
847 case OperationType::Trunc:
848 return TruncFlags.HasNSW;
849 default:
850 llvm_unreachable("recipe doesn't have a NSW flag");
851 }
852 }
853
854 bool isDisjoint() const {
855 assert(OpType == OperationType::DisjointOp &&
856 "recipe cannot have a disjoing flag");
857 return DisjointFlags.IsDisjoint;
858 }
859
860#if !defined(NDEBUG)
861 /// Returns true if the set flags are valid for \p Opcode.
862 bool flagsValidForOpcode(unsigned Opcode) const;
863#endif
864
865#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
866 void printFlags(raw_ostream &O) const;
867#endif
868};
869
870/// A pure-virtual common base class for recipes defining a single VPValue and
871/// using IR flags.
873 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
875 : VPSingleDefRecipe(SC, Operands, DL), VPIRFlags() {}
876
877 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
878 Instruction &I)
879 : VPSingleDefRecipe(SC, Operands, &I, I.getDebugLoc()), VPIRFlags(I) {}
880
881 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
882 const VPIRFlags &Flags,
884 : VPSingleDefRecipe(SC, Operands, DL), VPIRFlags(Flags) {}
885
886 static inline bool classof(const VPRecipeBase *R) {
887 return R->getVPDefID() == VPRecipeBase::VPInstructionSC ||
888 R->getVPDefID() == VPRecipeBase::VPWidenSC ||
889 R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
890 R->getVPDefID() == VPRecipeBase::VPWidenCallSC ||
891 R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
892 R->getVPDefID() == VPRecipeBase::VPWidenIntrinsicSC ||
893 R->getVPDefID() == VPRecipeBase::VPWidenSelectSC ||
894 R->getVPDefID() == VPRecipeBase::VPReductionSC ||
895 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC ||
896 R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
897 R->getVPDefID() == VPRecipeBase::VPVectorEndPointerSC ||
898 R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
899 }
900
901 static inline bool classof(const VPUser *U) {
902 auto *R = dyn_cast<VPRecipeBase>(U);
903 return R && classof(R);
904 }
905
906 static inline bool classof(const VPValue *V) {
907 auto *R = dyn_cast_or_null<VPRecipeBase>(V->getDefiningRecipe());
908 return R && classof(R);
909 }
910
911 virtual VPRecipeWithIRFlags *clone() override = 0;
912
913 static inline bool classof(const VPSingleDefRecipe *U) {
914 auto *R = dyn_cast<VPRecipeBase>(U);
915 return R && classof(R);
916 }
917
918 void execute(VPTransformState &State) override = 0;
919
920 /// Compute the cost for this recipe for \p VF, using \p Opcode and \p Ctx.
921 std::optional<InstructionCost>
922 getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
923 VPCostContext &Ctx) const;
924};
925
926/// Helper to access the operand that contains the unroll part for this recipe
927/// after unrolling.
928template <unsigned PartOpIdx> class LLVM_ABI_FOR_TEST VPUnrollPartAccessor {
929protected:
930 /// Return the VPValue operand containing the unroll part or null if there is
931 /// no such operand.
932 VPValue *getUnrollPartOperand(const VPUser &U) const;
933
934 /// Return the unroll part.
935 unsigned getUnrollPart(const VPUser &U) const;
936};
937
938/// Helper to manage IR metadata for recipes. It filters out metadata that
939/// cannot be propagated.
942
943public:
945
946 /// Adds metatadata that can be preserved from the original instruction
947 /// \p I.
949
950 /// Adds metatadata that can be preserved from the original instruction
951 /// \p I and noalias metadata guaranteed by runtime checks using \p LVer.
953
954 /// Copy constructor for cloning.
955 VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
956
958 Metadata = Other.Metadata;
959 return *this;
960 }
961
962 /// Add all metadata to \p I.
963 void applyMetadata(Instruction &I) const;
964
965 /// Add metadata with kind \p Kind and \p Node.
966 void addMetadata(unsigned Kind, MDNode *Node) {
967 Metadata.emplace_back(Kind, Node);
968 }
969
970 /// Intersect this VPIRMetada object with \p MD, keeping only metadata
971 /// nodes that are common to both.
972 void intersect(const VPIRMetadata &MD);
973};
974
975/// This is a concrete Recipe that models a single VPlan-level instruction.
976/// While as any Recipe it may generate a sequence of IR instructions when
977/// executed, these instructions would always form a single-def expression as
978/// the VPInstruction is also a single def-use vertex.
980 public VPIRMetadata,
981 public VPUnrollPartAccessor<1> {
982 friend class VPlanSlp;
983
984public:
985 /// VPlan opcodes, extending LLVM IR with idiomatics instructions.
986 enum {
988 Instruction::OtherOpsEnd + 1, // Combines the incoming and previous
989 // values of a first-order recurrence.
993 // Creates a mask where each lane is active (true) whilst the current
994 // counter (first operand + index) is less than the second operand. i.e.
995 // mask[i] = icmpt ult (op0 + i), op1
996 // The size of the mask returned is VF * Multiplier (UF, third op).
1000 // Increment the canonical IV separately for each unrolled part.
1005 /// Given operands of (the same) struct type, creates a struct of fixed-
1006 /// width vectors each containing a struct field of all operands. The
1007 /// number of operands matches the element count of every vector.
1009 /// Creates a fixed-width vector containing all operands. The number of
1010 /// operands matches the vector element count.
1012 /// Compute the final result of a AnyOf reduction with select(cmp(),x,y),
1013 /// where one of (x,y) is loop invariant, and both x and y are integer type.
1017 // Extracts the last lane from its operand if it is a vector, or the last
1018 // part if scalar. In the latter case, the recipe will be removed during
1019 // unrolling.
1021 // Extracts the second-to-last lane from its operand or the second-to-last
1022 // part if it is scalar. In the latter case, the recipe will be removed
1023 // during unrolling.
1025 LogicalAnd, // Non-poison propagating logical And.
1026 // Add an offset in bytes (second operand) to a base pointer (first
1027 // operand). Only generates scalar values (either for the first lane only or
1028 // for all lanes, depending on its uses).
1030 // Add a vector offset in bytes (second operand) to a scalar base pointer
1031 // (first operand).
1033 // Returns a scalar boolean value, which is true if any lane of its
1034 // (boolean) vector operands is true. It produces the reduced value across
1035 // all unrolled iterations. Unrolling will add all copies of its original
1036 // operand as additional operands. AnyOf is poison-safe as all operands
1037 // will be frozen.
1039 // Calculates the first active lane index of the vector predicate operands.
1040 // It produces the lane index across all unrolled iterations. Unrolling will
1041 // add all copies of its original operand as additional operands.
1043
1044 // The opcodes below are used for VPInstructionWithType.
1045 //
1046 /// Scale the first operand (vector step) by the second operand
1047 /// (scalar-step). Casts both operands to the result type if needed.
1049 /// Start vector for reductions with 3 operands: the original start value,
1050 /// the identity value for the reduction and an integer indicating the
1051 /// scaling factor.
1053 // Creates a step vector starting from 0 to VF with a step of 1.
1055 /// Extracts a single lane (first operand) from a set of vector operands.
1056 /// The lane specifies an index into a vector formed by combining all vector
1057 /// operands (all operands after the first one).
1059 /// Explicit user for the resume phi of the canonical induction in the main
1060 /// VPlan, used by the epilogue vector loop.
1062 /// Returns the value for vscale.
1064 };
1065
1066 /// Returns true if this VPInstruction generates scalar values for all lanes.
1067 /// Most VPInstructions generate a single value per part, either vector or
1068 /// scalar. VPReplicateRecipe takes care of generating multiple (scalar)
1069 /// values per all lanes, stemming from an original ingredient. This method
1070 /// identifies the (rare) cases of VPInstructions that do so as well, w/o an
1071 /// underlying ingredient.
1072 bool doesGeneratePerAllLanes() const;
1073
1074private:
1075 typedef unsigned char OpcodeTy;
1076 OpcodeTy Opcode;
1077
1078 /// An optional name that can be used for the generated IR instruction.
1079 const std::string Name;
1080
1081 /// Returns true if we can generate a scalar for the first lane only if
1082 /// needed.
1083 bool canGenerateScalarForFirstLane() const;
1084
1085 /// Utility methods serving execute(): generates a single vector instance of
1086 /// the modeled instruction. \returns the generated value. . In some cases an
1087 /// existing value is returned rather than a generated one.
1088 Value *generate(VPTransformState &State);
1089
1090#if !defined(NDEBUG)
1091 /// Return the number of operands determined by the opcode of the
1092 /// VPInstruction. Returns -1u if the number of operands cannot be determined
1093 /// directly by the opcode.
1094 static unsigned getNumOperandsForOpcode(unsigned Opcode);
1095#endif
1096
1097public:
1099 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
1100 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DL),
1101 VPIRMetadata(), Opcode(Opcode), Name(Name.str()) {}
1102
1104 const VPIRFlags &Flags, DebugLoc DL = DebugLoc::getUnknown(),
1105 const Twine &Name = "");
1106
1107 VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
1108
1109 VPInstruction *clone() override {
1111 auto *New = new VPInstruction(Opcode, Operands, *this, getDebugLoc(), Name);
1112 if (getUnderlyingValue())
1113 New->setUnderlyingValue(getUnderlyingInstr());
1114 return New;
1115 }
1116
1117 unsigned getOpcode() const { return Opcode; }
1118
1119 /// Generate the instruction.
1120 /// TODO: We currently execute only per-part unless a specific instance is
1121 /// provided.
1122 void execute(VPTransformState &State) override;
1123
1124 /// Return the cost of this VPInstruction.
1125 InstructionCost computeCost(ElementCount VF,
1126 VPCostContext &Ctx) const override;
1127
1128#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1129 /// Print the VPInstruction to \p O.
1130 void print(raw_ostream &O, const Twine &Indent,
1131 VPSlotTracker &SlotTracker) const override;
1132
1133 /// Print the VPInstruction to dbgs() (for debugging).
1134 LLVM_DUMP_METHOD void dump() const;
1135#endif
1136
1137 bool hasResult() const {
1138 // CallInst may or may not have a result, depending on the called function.
1139 // Conservatively return calls have results for now.
1140 switch (getOpcode()) {
1141 case Instruction::Ret:
1142 case Instruction::Br:
1143 case Instruction::Store:
1144 case Instruction::Switch:
1145 case Instruction::IndirectBr:
1146 case Instruction::Resume:
1147 case Instruction::CatchRet:
1148 case Instruction::Unreachable:
1149 case Instruction::Fence:
1150 case Instruction::AtomicRMW:
1153 return false;
1154 default:
1155 return true;
1156 }
1157 }
1158
1159 /// Returns true if the underlying opcode may read from or write to memory.
1160 bool opcodeMayReadOrWriteFromMemory() const;
1161
1162 /// Returns true if the recipe only uses the first lane of operand \p Op.
1163 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1164
1165 /// Returns true if the recipe only uses the first part of operand \p Op.
1166 bool onlyFirstPartUsed(const VPValue *Op) const override;
1167
1168 /// Returns true if this VPInstruction produces a scalar value from a vector,
1169 /// e.g. by performing a reduction or extracting a lane.
1170 bool isVectorToScalar() const;
1171
1172 /// Returns true if this VPInstruction's operands are single scalars and the
1173 /// result is also a single scalar.
1174 bool isSingleScalar() const;
1175
1176 /// Returns the symbolic name assigned to the VPInstruction.
1177 StringRef getName() const { return Name; }
1178};
1179
1180/// A specialization of VPInstruction augmenting it with a dedicated result
1181/// type, to be used when the opcode and operands of the VPInstruction don't
1182/// directly determine the result type. Note that there is no separate VPDef ID
1183/// for VPInstructionWithType; it shares the same ID as VPInstruction and is
1184/// distinguished purely by the opcode.
1186 /// Scalar result type produced by the recipe.
1187 Type *ResultTy;
1188
1189public:
1191 Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL,
1192 const Twine &Name = "")
1193 : VPInstruction(Opcode, Operands, Flags, DL, Name), ResultTy(ResultTy) {}
1194
1195 static inline bool classof(const VPRecipeBase *R) {
1196 // VPInstructionWithType are VPInstructions with specific opcodes requiring
1197 // type information.
1198 if (R->isScalarCast())
1199 return true;
1200 auto *VPI = dyn_cast<VPInstruction>(R);
1201 if (!VPI)
1202 return false;
1203 switch (VPI->getOpcode()) {
1207 return true;
1208 default:
1209 return false;
1210 }
1211 }
1212
1213 static inline bool classof(const VPUser *R) {
1215 }
1216
1217 VPInstruction *clone() override {
1219 auto *New =
1221 getDebugLoc(), getName());
1222 New->setUnderlyingValue(getUnderlyingValue());
1223 return New;
1224 }
1225
1226 void execute(VPTransformState &State) override;
1227
1228 /// Return the cost of this VPInstruction.
1230 VPCostContext &Ctx) const override {
1231 // TODO: Compute accurate cost after retiring the legacy cost model.
1232 return 0;
1233 }
1234
1235 Type *getResultType() const { return ResultTy; }
1236
1237#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1238 /// Print the recipe.
1239 void print(raw_ostream &O, const Twine &Indent,
1240 VPSlotTracker &SlotTracker) const override;
1241#endif
1242};
1243
1244/// Helper type to provide functions to access incoming values and blocks for
1245/// phi-like recipes.
1247protected:
1248 /// Return a VPRecipeBase* to the current object.
1249 virtual const VPRecipeBase *getAsRecipe() const = 0;
1250
1251public:
1252 virtual ~VPPhiAccessors() = default;
1253
1254 /// Returns the incoming VPValue with index \p Idx.
1255 VPValue *getIncomingValue(unsigned Idx) const {
1256 return getAsRecipe()->getOperand(Idx);
1257 }
1258
1259 /// Returns the incoming block with index \p Idx.
1260 const VPBasicBlock *getIncomingBlock(unsigned Idx) const;
1261
1262 /// Returns the number of incoming values, also number of incoming blocks.
1263 virtual unsigned getNumIncoming() const {
1264 return getAsRecipe()->getNumOperands();
1265 }
1266
1267 /// Returns an interator range over the incoming values.
1269 return make_range(getAsRecipe()->op_begin(),
1270 getAsRecipe()->op_begin() + getNumIncoming());
1271 }
1272
1274 detail::index_iterator, std::function<const VPBasicBlock *(size_t)>>>;
1275
1276 /// Returns an iterator range over the incoming blocks.
1278 std::function<const VPBasicBlock *(size_t)> GetBlock = [this](size_t Idx) {
1279 return getIncomingBlock(Idx);
1280 };
1281 return map_range(index_range(0, getNumIncoming()), GetBlock);
1282 }
1283
1284 /// Returns an iterator range over pairs of incoming values and corresponding
1285 /// incoming blocks.
1291
1292 /// Removes the incoming value for \p IncomingBlock, which must be a
1293 /// predecessor.
1294 void removeIncomingValueFor(VPBlockBase *IncomingBlock) const;
1295
1296#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1297 /// Print the recipe.
1299#endif
1300};
1301
1305
1306 static inline bool classof(const VPUser *U) {
1307 auto *VPI = dyn_cast<VPInstruction>(U);
1308 return VPI && VPI->getOpcode() == Instruction::PHI;
1309 }
1310
1311 static inline bool classof(const VPValue *V) {
1312 auto *VPI = dyn_cast<VPInstruction>(V);
1313 return VPI && VPI->getOpcode() == Instruction::PHI;
1314 }
1315
1316 static inline bool classof(const VPSingleDefRecipe *SDR) {
1317 auto *VPI = dyn_cast<VPInstruction>(SDR);
1318 return VPI && VPI->getOpcode() == Instruction::PHI;
1319 }
1320
1321 VPPhi *clone() override {
1322 auto *PhiR = new VPPhi(operands(), getDebugLoc(), getName());
1323 PhiR->setUnderlyingValue(getUnderlyingValue());
1324 return PhiR;
1325 }
1326
1327 void execute(VPTransformState &State) override;
1328
1329#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1330 /// Print the recipe.
1331 void print(raw_ostream &O, const Twine &Indent,
1332 VPSlotTracker &SlotTracker) const override;
1333#endif
1334
1335protected:
1336 const VPRecipeBase *getAsRecipe() const override { return this; }
1337};
1338
1339/// A recipe to wrap on original IR instruction not to be modified during
1340/// execution, except for PHIs. PHIs are modeled via the VPIRPhi subclass.
1341/// Expect PHIs, VPIRInstructions cannot have any operands.
1343 Instruction &I;
1344
1345protected:
1346 /// VPIRInstruction::create() should be used to create VPIRInstructions, as
1347 /// subclasses may need to be created, e.g. VPIRPhi.
1349 : VPRecipeBase(VPDef::VPIRInstructionSC, ArrayRef<VPValue *>()), I(I) {}
1350
1351public:
1352 ~VPIRInstruction() override = default;
1353
1354 /// Create a new VPIRPhi for \p \I, if it is a PHINode, otherwise create a
1355 /// VPIRInstruction.
1357
1358 VP_CLASSOF_IMPL(VPDef::VPIRInstructionSC)
1359
1361 auto *R = create(I);
1362 for (auto *Op : operands())
1363 R->addOperand(Op);
1364 return R;
1365 }
1366
1367 void execute(VPTransformState &State) override;
1368
1369 /// Return the cost of this VPIRInstruction.
1371 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
1372
1373 Instruction &getInstruction() const { return I; }
1374
1375#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1376 /// Print the recipe.
1377 void print(raw_ostream &O, const Twine &Indent,
1378 VPSlotTracker &SlotTracker) const override;
1379#endif
1380
1381 bool usesScalars(const VPValue *Op) const override {
1383 "Op must be an operand of the recipe");
1384 return true;
1385 }
1386
1387 bool onlyFirstPartUsed(const VPValue *Op) const override {
1389 "Op must be an operand of the recipe");
1390 return true;
1391 }
1392
1393 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1395 "Op must be an operand of the recipe");
1396 return true;
1397 }
1398
1399 /// Update the recipes first operand to the last lane of the operand using \p
1400 /// Builder. Must only be used for VPIRInstructions with at least one operand
1401 /// wrapping a PHINode.
1403};
1404
1405/// An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use
1406/// cast/dyn_cast/isa and execute() implementation. A single VPValue operand is
1407/// allowed, and it is used to add a new incoming value for the single
1408/// predecessor VPBB.
1410 public VPPhiAccessors {
1412
1413 static inline bool classof(const VPRecipeBase *U) {
1414 auto *R = dyn_cast<VPIRInstruction>(U);
1415 return R && isa<PHINode>(R->getInstruction());
1416 }
1417
1419
1420 void execute(VPTransformState &State) override;
1421
1422#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1423 /// Print the recipe.
1424 void print(raw_ostream &O, const Twine &Indent,
1425 VPSlotTracker &SlotTracker) const override;
1426#endif
1427
1428protected:
1429 const VPRecipeBase *getAsRecipe() const override { return this; }
1430};
1431
1432/// VPWidenRecipe is a recipe for producing a widened instruction using the
1433/// opcode and operands of the recipe. This recipe covers most of the
1434/// traditional vectorization cases where each recipe transforms into a
1435/// vectorized version of itself.
1437 public VPIRMetadata {
1438 unsigned Opcode;
1439
1440public:
1442 const VPIRFlags &Flags, const VPIRMetadata &Metadata,
1443 DebugLoc DL)
1444 : VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, Flags, DL),
1445 VPIRMetadata(Metadata), Opcode(Opcode) {}
1446
1450
1451 ~VPWidenRecipe() override = default;
1452
1453 VPWidenRecipe *clone() override {
1454 auto *R =
1455 new VPWidenRecipe(getOpcode(), operands(), *this, *this, getDebugLoc());
1456 R->setUnderlyingValue(getUnderlyingValue());
1457 return R;
1458 }
1459
1460 VP_CLASSOF_IMPL(VPDef::VPWidenSC)
1461
1462 /// Produce a widened instruction using the opcode and operands of the recipe,
1463 /// processing State.VF elements.
1464 void execute(VPTransformState &State) override;
1465
1466 /// Return the cost of this VPWidenRecipe.
1467 InstructionCost computeCost(ElementCount VF,
1468 VPCostContext &Ctx) const override;
1469
1470 unsigned getOpcode() const { return Opcode; }
1471
1472#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1473 /// Print the recipe.
1474 void print(raw_ostream &O, const Twine &Indent,
1475 VPSlotTracker &SlotTracker) const override;
1476#endif
1477};
1478
1479/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1481 /// Cast instruction opcode.
1482 Instruction::CastOps Opcode;
1483
1484 /// Result type for the cast.
1485 Type *ResultTy;
1486
1487public:
1489 CastInst &UI)
1490 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), VPIRMetadata(UI),
1491 Opcode(Opcode), ResultTy(ResultTy) {
1492 assert(UI.getOpcode() == Opcode &&
1493 "opcode of underlying cast doesn't match");
1494 }
1495
1497 const VPIRFlags &Flags = {},
1499 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, Flags, DL),
1500 VPIRMetadata(), Opcode(Opcode), ResultTy(ResultTy) {
1501 assert(flagsValidForOpcode(Opcode) &&
1502 "Set flags not supported for the provided opcode");
1503 }
1504
1505 ~VPWidenCastRecipe() override = default;
1506
1508 if (auto *UV = getUnderlyingValue())
1509 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1510 *cast<CastInst>(UV));
1511
1512 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
1513 }
1514
1515 VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
1516
1517 /// Produce widened copies of the cast.
1518 void execute(VPTransformState &State) override;
1519
1520 /// Return the cost of this VPWidenCastRecipe.
1522 VPCostContext &Ctx) const override;
1523
1524#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1525 /// Print the recipe.
1526 void print(raw_ostream &O, const Twine &Indent,
1527 VPSlotTracker &SlotTracker) const override;
1528#endif
1529
1530 Instruction::CastOps getOpcode() const { return Opcode; }
1531
1532 /// Returns the result type of the cast.
1533 Type *getResultType() const { return ResultTy; }
1534};
1535
1536/// A recipe for widening vector intrinsics.
1538 /// ID of the vector intrinsic to widen.
1539 Intrinsic::ID VectorIntrinsicID;
1540
1541 /// Scalar return type of the intrinsic.
1542 Type *ResultTy;
1543
1544 /// True if the intrinsic may read from memory.
1545 bool MayReadFromMemory;
1546
1547 /// True if the intrinsic may read write to memory.
1548 bool MayWriteToMemory;
1549
1550 /// True if the intrinsic may have side-effects.
1551 bool MayHaveSideEffects;
1552
1553public:
1555 ArrayRef<VPValue *> CallArguments, Type *Ty,
1557 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1558 VPIRMetadata(CI), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1559 MayReadFromMemory(CI.mayReadFromMemory()),
1560 MayWriteToMemory(CI.mayWriteToMemory()),
1561 MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1562
1564 ArrayRef<VPValue *> CallArguments, Type *Ty,
1566 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1567 VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1568 LLVMContext &Ctx = Ty->getContext();
1569 AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
1570 MemoryEffects ME = Attrs.getMemoryEffects();
1571 MayReadFromMemory = !ME.onlyWritesMemory();
1572 MayWriteToMemory = !ME.onlyReadsMemory();
1573 MayHaveSideEffects = MayWriteToMemory ||
1574 !Attrs.hasAttribute(Attribute::NoUnwind) ||
1575 !Attrs.hasAttribute(Attribute::WillReturn);
1576 }
1577
1578 ~VPWidenIntrinsicRecipe() override = default;
1579
1581 if (Value *CI = getUnderlyingValue())
1582 return new VPWidenIntrinsicRecipe(*cast<CallInst>(CI), VectorIntrinsicID,
1583 operands(), ResultTy, getDebugLoc());
1584 return new VPWidenIntrinsicRecipe(VectorIntrinsicID, operands(), ResultTy,
1585 getDebugLoc());
1586 }
1587
1588 VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
1589
1590 /// Produce a widened version of the vector intrinsic.
1591 void execute(VPTransformState &State) override;
1592
1593 /// Return the cost of this vector intrinsic.
1595 VPCostContext &Ctx) const override;
1596
1597 /// Return the ID of the intrinsic.
1598 Intrinsic::ID getVectorIntrinsicID() const { return VectorIntrinsicID; }
1599
1600 /// Return the scalar return type of the intrinsic.
1601 Type *getResultType() const { return ResultTy; }
1602
1603 /// Return to name of the intrinsic as string.
1605
1606 /// Returns true if the intrinsic may read from memory.
1607 bool mayReadFromMemory() const { return MayReadFromMemory; }
1608
1609 /// Returns true if the intrinsic may write to memory.
1610 bool mayWriteToMemory() const { return MayWriteToMemory; }
1611
1612 /// Returns true if the intrinsic may have side-effects.
1613 bool mayHaveSideEffects() const { return MayHaveSideEffects; }
1614
1615#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1616 /// Print the recipe.
1617 void print(raw_ostream &O, const Twine &Indent,
1618 VPSlotTracker &SlotTracker) const override;
1619#endif
1620
1621 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1622};
1623
1624/// A recipe for widening Call instructions using library calls.
1626 public VPIRMetadata {
1627 /// Variant stores a pointer to the chosen function. There is a 1:1 mapping
1628 /// between a given VF and the chosen vectorized variant, so there will be a
1629 /// different VPlan for each VF with a valid variant.
1630 Function *Variant;
1631
1632public:
1634 ArrayRef<VPValue *> CallArguments,
1636 : VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
1637 *cast<Instruction>(UV)),
1638 VPIRMetadata(*cast<Instruction>(UV)), Variant(Variant) {
1639 assert(
1641 "last operand must be the called function");
1642 }
1643
1644 ~VPWidenCallRecipe() override = default;
1645
1647 return new VPWidenCallRecipe(getUnderlyingValue(), Variant, operands(),
1648 getDebugLoc());
1649 }
1650
1651 VP_CLASSOF_IMPL(VPDef::VPWidenCallSC)
1652
1653 /// Produce a widened version of the call instruction.
1654 void execute(VPTransformState &State) override;
1655
1656 /// Return the cost of this VPWidenCallRecipe.
1657 InstructionCost computeCost(ElementCount VF,
1658 VPCostContext &Ctx) const override;
1659
1663
1666
1667#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1668 /// Print the recipe.
1669 void print(raw_ostream &O, const Twine &Indent,
1670 VPSlotTracker &SlotTracker) const override;
1671#endif
1672};
1673
1674/// A recipe representing a sequence of load -> update -> store as part of
1675/// a histogram operation. This means there may be aliasing between vector
1676/// lanes, which is handled by the llvm.experimental.vector.histogram family
1677/// of intrinsics. The only update operations currently supported are
1678/// 'add' and 'sub' where the other term is loop-invariant.
1680 /// Opcode of the update operation, currently either add or sub.
1681 unsigned Opcode;
1682
1683public:
1684 VPHistogramRecipe(unsigned Opcode, ArrayRef<VPValue *> Operands,
1686 : VPRecipeBase(VPDef::VPHistogramSC, Operands, DL), Opcode(Opcode) {}
1687
1688 ~VPHistogramRecipe() override = default;
1689
1691 return new VPHistogramRecipe(Opcode, operands(), getDebugLoc());
1692 }
1693
1694 VP_CLASSOF_IMPL(VPDef::VPHistogramSC);
1695
1696 /// Produce a vectorized histogram operation.
1697 void execute(VPTransformState &State) override;
1698
1699 /// Return the cost of this VPHistogramRecipe.
1701 VPCostContext &Ctx) const override;
1702
1703 unsigned getOpcode() const { return Opcode; }
1704
1705 /// Return the mask operand if one was provided, or a null pointer if all
1706 /// lanes should be executed unconditionally.
1707 VPValue *getMask() const {
1708 return getNumOperands() == 3 ? getOperand(2) : nullptr;
1709 }
1710
1711#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1712 /// Print the recipe
1713 void print(raw_ostream &O, const Twine &Indent,
1714 VPSlotTracker &SlotTracker) const override;
1715#endif
1716};
1717
1718/// A recipe for widening select instructions.
1720 public VPIRMetadata {
1724
1725 ~VPWidenSelectRecipe() override = default;
1726
1731
1732 VP_CLASSOF_IMPL(VPDef::VPWidenSelectSC)
1733
1734 /// Produce a widened version of the select instruction.
1735 void execute(VPTransformState &State) override;
1736
1737 /// Return the cost of this VPWidenSelectRecipe.
1738 InstructionCost computeCost(ElementCount VF,
1739 VPCostContext &Ctx) const override;
1740
1741#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1742 /// Print the recipe.
1743 void print(raw_ostream &O, const Twine &Indent,
1744 VPSlotTracker &SlotTracker) const override;
1745#endif
1746
1747 unsigned getOpcode() const { return Instruction::Select; }
1748
1749 VPValue *getCond() const {
1750 return getOperand(0);
1751 }
1752
1753 bool isInvariantCond() const {
1754 return getCond()->isDefinedOutsideLoopRegions();
1755 }
1756
1757 /// Returns true if the recipe only uses the first lane of operand \p Op.
1758 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1760 "Op must be an operand of the recipe");
1761 return Op == getCond() && isInvariantCond();
1762 }
1763};
1764
1765/// A recipe for handling GEP instructions.
1767 bool isPointerLoopInvariant() const {
1768 return getOperand(0)->isDefinedOutsideLoopRegions();
1769 }
1770
1771 bool isIndexLoopInvariant(unsigned I) const {
1772 return getOperand(I + 1)->isDefinedOutsideLoopRegions();
1773 }
1774
1775 bool areAllOperandsInvariant() const {
1776 return all_of(operands(), [](VPValue *Op) {
1777 return Op->isDefinedOutsideLoopRegions();
1778 });
1779 }
1780
1781public:
1789
1790 ~VPWidenGEPRecipe() override = default;
1791
1796
1797 VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
1798
1799 /// Generate the gep nodes.
1800 void execute(VPTransformState &State) override;
1801
1802 /// Return the cost of this VPWidenGEPRecipe.
1804 VPCostContext &Ctx) const override {
1805 // TODO: Compute accurate cost after retiring the legacy cost model.
1806 return 0;
1807 }
1808
1809#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1810 /// Print the recipe.
1811 void print(raw_ostream &O, const Twine &Indent,
1812 VPSlotTracker &SlotTracker) const override;
1813#endif
1814
1815 /// Returns true if the recipe only uses the first lane of operand \p Op.
1816 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1818 "Op must be an operand of the recipe");
1819 if (Op == getOperand(0))
1820 return isPointerLoopInvariant();
1821 else
1822 return !isPointerLoopInvariant() && Op->isDefinedOutsideLoopRegions();
1823 }
1824};
1825
1826/// A recipe to compute a pointer to the last element of each part of a widened
1827/// memory access for widened memory accesses of IndexedTy. Used for
1828/// VPWidenMemoryRecipes or VPInterleaveRecipes that are reversed.
1830 public VPUnrollPartAccessor<2> {
1831 Type *IndexedTy;
1832
1833 /// The constant stride of the pointer computed by this recipe, expressed in
1834 /// units of IndexedTy.
1835 int64_t Stride;
1836
1837public:
1839 int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
1840 : VPRecipeWithIRFlags(VPDef::VPVectorEndPointerSC,
1841 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
1842 IndexedTy(IndexedTy), Stride(Stride) {
1843 assert(Stride < 0 && "Stride must be negative");
1844 }
1845
1846 VP_CLASSOF_IMPL(VPDef::VPVectorEndPointerSC)
1847
1849 const VPValue *getVFValue() const { return getOperand(1); }
1850
1851 void execute(VPTransformState &State) override;
1852
1853 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1855 "Op must be an operand of the recipe");
1856 return true;
1857 }
1858
1859 /// Return the cost of this VPVectorPointerRecipe.
1861 VPCostContext &Ctx) const override {
1862 // TODO: Compute accurate cost after retiring the legacy cost model.
1863 return 0;
1864 }
1865
1866 /// Returns true if the recipe only uses the first part of operand \p Op.
1867 bool onlyFirstPartUsed(const VPValue *Op) const override {
1869 "Op must be an operand of the recipe");
1870 assert(getNumOperands() <= 2 && "must have at most two operands");
1871 return true;
1872 }
1873
1875 return new VPVectorEndPointerRecipe(getOperand(0), getVFValue(), IndexedTy,
1876 Stride, getGEPNoWrapFlags(),
1877 getDebugLoc());
1878 }
1879
1880#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1881 /// Print the recipe.
1882 void print(raw_ostream &O, const Twine &Indent,
1883 VPSlotTracker &SlotTracker) const override;
1884#endif
1885};
1886
1887/// A recipe to compute the pointers for widened memory accesses of IndexTy.
1889 public VPUnrollPartAccessor<1> {
1890 Type *IndexedTy;
1891
1892public:
1894 DebugLoc DL)
1895 : VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
1896 GEPFlags, DL),
1897 IndexedTy(IndexedTy) {}
1898
1899 VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
1900
1901 void execute(VPTransformState &State) override;
1902
1903 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1905 "Op must be an operand of the recipe");
1906 return true;
1907 }
1908
1909 /// Returns true if the recipe only uses the first part of operand \p Op.
1910 bool onlyFirstPartUsed(const VPValue *Op) const override {
1912 "Op must be an operand of the recipe");
1913 assert(getNumOperands() <= 2 && "must have at most two operands");
1914 return true;
1915 }
1916
1918 return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1920 }
1921
1922 /// Return true if this VPVectorPointerRecipe corresponds to part 0. Note that
1923 /// this is only accurate after the VPlan has been unrolled.
1924 bool isFirstPart() const { return getUnrollPart(*this) == 0; }
1925
1926 /// Return the cost of this VPHeaderPHIRecipe.
1928 VPCostContext &Ctx) const override {
1929 // TODO: Compute accurate cost after retiring the legacy cost model.
1930 return 0;
1931 }
1932
1933#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1934 /// Print the recipe.
1935 void print(raw_ostream &O, const Twine &Indent,
1936 VPSlotTracker &SlotTracker) const override;
1937#endif
1938};
1939
1940/// A pure virtual base class for all recipes modeling header phis, including
1941/// phis for first order recurrences, pointer inductions and reductions. The
1942/// start value is the first operand of the recipe and the incoming value from
1943/// the backedge is the second operand.
1944///
1945/// Inductions are modeled using the following sub-classes:
1946/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
1947/// starting at a specified value (zero for the main vector loop, the resume
1948/// value for the epilogue vector loop) and stepping by 1. The induction
1949/// controls exiting of the vector loop by comparing against the vector trip
1950/// count. Produces a single scalar PHI for the induction value per
1951/// iteration.
1952/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
1953/// floating point inductions with arbitrary start and step values. Produces
1954/// a vector PHI per-part.
1955/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
1956/// value of an IV with different start and step values. Produces a single
1957/// scalar value per iteration
1958/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
1959/// canonical or derived induction.
1960/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
1961/// pointer induction. Produces either a vector PHI per-part or scalar values
1962/// per-lane based on the canonical induction.
1964 public VPPhiAccessors {
1965protected:
1966 VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
1967 VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
1968 : VPSingleDefRecipe(VPDefID, ArrayRef<VPValue *>({Start}),
1969 UnderlyingInstr, DL) {}
1970
1971 const VPRecipeBase *getAsRecipe() const override { return this; }
1972
1973public:
1974 ~VPHeaderPHIRecipe() override = default;
1975
1976 /// Method to support type inquiry through isa, cast, and dyn_cast.
1977 static inline bool classof(const VPRecipeBase *B) {
1978 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
1979 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
1980 }
1981 static inline bool classof(const VPValue *V) {
1982 auto *B = V->getDefiningRecipe();
1983 return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
1984 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
1985 }
1986
1987 /// Generate the phi nodes.
1988 void execute(VPTransformState &State) override = 0;
1989
1990 /// Return the cost of this header phi recipe.
1992 VPCostContext &Ctx) const override;
1993
1994#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1995 /// Print the recipe.
1996 void print(raw_ostream &O, const Twine &Indent,
1997 VPSlotTracker &SlotTracker) const override = 0;
1998#endif
1999
2000 /// Returns the start value of the phi, if one is set.
2002 return getNumOperands() == 0 ? nullptr : getOperand(0);
2003 }
2005 return getNumOperands() == 0 ? nullptr : getOperand(0);
2006 }
2007
2008 /// Update the start value of the recipe.
2010
2011 /// Returns the incoming value from the loop backedge.
2013 return getOperand(1);
2014 }
2015
2016 /// Update the incoming value from the loop backedge.
2018
2019 /// Returns the backedge value as a recipe. The backedge value is guaranteed
2020 /// to be a recipe.
2022 return *getBackedgeValue()->getDefiningRecipe();
2023 }
2024};
2025
2026/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2027/// VPWidenPointerInductionRecipe), providing shared functionality, including
2028/// retrieving the step value, induction descriptor and original phi node.
2030 const InductionDescriptor &IndDesc;
2031
2032public:
2033 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
2034 VPValue *Step, const InductionDescriptor &IndDesc,
2035 DebugLoc DL)
2036 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2037 addOperand(Step);
2038 }
2039
2040 static inline bool classof(const VPRecipeBase *R) {
2041 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
2042 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
2043 }
2044
2045 static inline bool classof(const VPValue *V) {
2046 auto *R = V->getDefiningRecipe();
2047 return R && classof(R);
2048 }
2049
2050 static inline bool classof(const VPHeaderPHIRecipe *R) {
2051 return classof(static_cast<const VPRecipeBase *>(R));
2052 }
2053
2054 virtual void execute(VPTransformState &State) override = 0;
2055
2056 /// Returns the step value of the induction.
2058 const VPValue *getStepValue() const { return getOperand(1); }
2059
2060 /// Update the step value of the recipe.
2061 void setStepValue(VPValue *V) { setOperand(1, V); }
2062
2064 const VPValue *getVFValue() const { return getOperand(2); }
2065
2066 /// Returns the number of incoming values, also number of incoming blocks.
2067 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2068 /// incoming value, its start value.
2069 unsigned getNumIncoming() const override { return 1; }
2070
2072
2073 /// Returns the induction descriptor for the recipe.
2074 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
2075
2077 // TODO: All operands of base recipe must exist and be at same index in
2078 // derived recipe.
2080 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2081 }
2082
2084 // TODO: All operands of base recipe must exist and be at same index in
2085 // derived recipe.
2087 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2088 }
2089
2090 /// Returns true if the recipe only uses the first lane of operand \p Op.
2091 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2093 "Op must be an operand of the recipe");
2094 // The recipe creates its own wide start value, so it only requests the
2095 // first lane of the operand.
2096 // TODO: Remove once creating the start value is modeled separately.
2097 return Op == getStartValue() || Op == getStepValue();
2098 }
2099};
2100
2101/// A recipe for handling phi nodes of integer and floating-point inductions,
2102/// producing their vector values. This is an abstract recipe and must be
2103/// converted to concrete recipes before executing.
2105 TruncInst *Trunc;
2106
2107 // If this recipe is unrolled it will have 2 additional operands.
2108 bool isUnrolled() const { return getNumOperands() == 5; }
2109
2110public:
2112 VPValue *VF, const InductionDescriptor &IndDesc,
2113 DebugLoc DL)
2114 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2115 Step, IndDesc, DL),
2116 Trunc(nullptr) {
2117 addOperand(VF);
2118 }
2119
2121 VPValue *VF, const InductionDescriptor &IndDesc,
2122 TruncInst *Trunc, DebugLoc DL)
2123 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2124 Step, IndDesc, DL),
2125 Trunc(Trunc) {
2126 addOperand(VF);
2128 (void)Metadata;
2129 if (Trunc)
2131 assert(Metadata.empty() && "unexpected metadata on Trunc");
2132 }
2133
2135
2141
2142 VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
2143
2144 void execute(VPTransformState &State) override {
2145 llvm_unreachable("cannot execute this recipe, should be expanded via "
2146 "expandVPWidenIntOrFpInductionRecipe");
2147 }
2148
2149#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2150 /// Print the recipe.
2151 void print(raw_ostream &O, const Twine &Indent,
2152 VPSlotTracker &SlotTracker) const override;
2153#endif
2154
2156 // If the recipe has been unrolled return the VPValue for the induction
2157 // increment.
2158 return isUnrolled() ? getOperand(getNumOperands() - 2) : nullptr;
2159 }
2160
2161 /// Returns the number of incoming values, also number of incoming blocks.
2162 /// Note that at the moment, VPWidenIntOrFpInductionRecipes only have a single
2163 /// incoming value, its start value.
2164 unsigned getNumIncoming() const override { return 1; }
2165
2166 /// Returns the first defined value as TruncInst, if it is one or nullptr
2167 /// otherwise.
2168 TruncInst *getTruncInst() { return Trunc; }
2169 const TruncInst *getTruncInst() const { return Trunc; }
2170
2171 /// Returns true if the induction is canonical, i.e. starting at 0 and
2172 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
2173 /// same type as the canonical induction.
2174 bool isCanonical() const;
2175
2176 /// Returns the scalar type of the induction.
2178 return Trunc ? Trunc->getType()
2180 }
2181
2182 /// Returns the VPValue representing the value of this induction at
2183 /// the last unrolled part, if it exists. Returns itself if unrolling did not
2184 /// take place.
2186 return isUnrolled() ? getOperand(getNumOperands() - 1) : this;
2187 }
2188};
2189
2191 bool IsScalarAfterVectorization;
2192
2193public:
2194 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2195 /// Start and the number of elements unrolled \p NumUnrolledElems, typically
2196 /// VF*UF.
2198 VPValue *NumUnrolledElems,
2199 const InductionDescriptor &IndDesc,
2200 bool IsScalarAfterVectorization, DebugLoc DL)
2201 : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
2202 Step, IndDesc, DL),
2203 IsScalarAfterVectorization(IsScalarAfterVectorization) {
2204 addOperand(NumUnrolledElems);
2205 }
2206
2208
2212 getOperand(2), getInductionDescriptor(), IsScalarAfterVectorization,
2213 getDebugLoc());
2214 }
2215
2216 VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
2217
2218 /// Generate vector values for the pointer induction.
2219 void execute(VPTransformState &State) override {
2220 llvm_unreachable("cannot execute this recipe, should be expanded via "
2221 "expandVPWidenPointerInduction");
2222 };
2223
2224 /// Returns true if only scalar values will be generated.
2225 bool onlyScalarsGenerated(bool IsScalable);
2226
2227#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2228 /// Print the recipe.
2229 void print(raw_ostream &O, const Twine &Indent,
2230 VPSlotTracker &SlotTracker) const override;
2231#endif
2232};
2233
2234/// A recipe for widened phis. Incoming values are operands of the recipe and
2235/// their operand index corresponds to the incoming predecessor block. If the
2236/// recipe is placed in an entry block to a (non-replicate) region, it must have
2237/// exactly 2 incoming values, the first from the predecessor of the region and
2238/// the second from the exiting block of the region.
2240 public VPPhiAccessors {
2241 /// Name to use for the generated IR instruction for the widened phi.
2242 std::string Name;
2243
2244protected:
2245 const VPRecipeBase *getAsRecipe() const override { return this; }
2246
2247public:
2248 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
2249 /// debug location \p DL.
2250 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
2251 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
2252 : VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi, DL),
2253 Name(Name.str()) {
2254 if (Start)
2255 addOperand(Start);
2256 }
2257
2260 getOperand(0), getDebugLoc(), Name);
2262 C->addOperand(Op);
2263 return C;
2264 }
2265
2266 ~VPWidenPHIRecipe() override = default;
2267
2268 VP_CLASSOF_IMPL(VPDef::VPWidenPHISC)
2269
2270 /// Generate the phi/select nodes.
2271 void execute(VPTransformState &State) override;
2272
2273#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2274 /// Print the recipe.
2275 void print(raw_ostream &O, const Twine &Indent,
2276 VPSlotTracker &SlotTracker) const override;
2277#endif
2278};
2279
2280/// A recipe for handling first-order recurrence phis. The start value is the
2281/// first operand of the recipe and the incoming value from the backedge is the
2282/// second operand.
2285 : VPHeaderPHIRecipe(VPDef::VPFirstOrderRecurrencePHISC, Phi, &Start) {}
2286
2287 VP_CLASSOF_IMPL(VPDef::VPFirstOrderRecurrencePHISC)
2288
2293
2294 void execute(VPTransformState &State) override;
2295
2296 /// Return the cost of this first-order recurrence phi recipe.
2298 VPCostContext &Ctx) const override;
2299
2300#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2301 /// Print the recipe.
2302 void print(raw_ostream &O, const Twine &Indent,
2303 VPSlotTracker &SlotTracker) const override;
2304#endif
2305
2306 /// Returns true if the recipe only uses the first lane of operand \p Op.
2307 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2309 "Op must be an operand of the recipe");
2310 return Op == getStartValue();
2311 }
2312};
2313
2314/// A recipe for handling reduction phis. The start value is the first operand
2315/// of the recipe and the incoming value from the backedge is the second
2316/// operand.
2318 public VPUnrollPartAccessor<2> {
2319 /// The recurrence kind of the reduction.
2320 const RecurKind Kind;
2321
2322 /// The phi is part of an in-loop reduction.
2323 bool IsInLoop;
2324
2325 /// The phi is part of an ordered reduction. Requires IsInLoop to be true.
2326 bool IsOrdered;
2327
2328 /// When expanding the reduction PHI, the plan's VF element count is divided
2329 /// by this factor to form the reduction phi's VF.
2330 unsigned VFScaleFactor = 1;
2331
2332public:
2333 /// Create a new VPReductionPHIRecipe for the reduction \p Phi.
2335 bool IsInLoop = false, bool IsOrdered = false,
2336 unsigned VFScaleFactor = 1)
2337 : VPHeaderPHIRecipe(VPDef::VPReductionPHISC, Phi, &Start), Kind(Kind),
2338 IsInLoop(IsInLoop), IsOrdered(IsOrdered), VFScaleFactor(VFScaleFactor) {
2339 assert((!IsOrdered || IsInLoop) && "IsOrdered requires IsInLoop");
2340 }
2341
2342 ~VPReductionPHIRecipe() override = default;
2343
2345 auto *R = new VPReductionPHIRecipe(
2347 *getOperand(0), IsInLoop, IsOrdered, VFScaleFactor);
2348 R->addOperand(getBackedgeValue());
2349 return R;
2350 }
2351
2352 VP_CLASSOF_IMPL(VPDef::VPReductionPHISC)
2353
2354 /// Generate the phi/select nodes.
2355 void execute(VPTransformState &State) override;
2356
2357 /// Get the factor that the VF of this recipe's output should be scaled by.
2358 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2359
2360#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2361 /// Print the recipe.
2362 void print(raw_ostream &O, const Twine &Indent,
2363 VPSlotTracker &SlotTracker) const override;
2364#endif
2365
2366 /// Returns the number of incoming values, also number of incoming blocks.
2367 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2368 /// incoming value, its start value.
2369 unsigned getNumIncoming() const override { return 2; }
2370
2371 /// Returns the recurrence kind of the reduction.
2372 RecurKind getRecurrenceKind() const { return Kind; }
2373
2374 /// Returns true, if the phi is part of an ordered reduction.
2375 bool isOrdered() const { return IsOrdered; }
2376
2377 /// Returns true, if the phi is part of an in-loop reduction.
2378 bool isInLoop() const { return IsInLoop; }
2379
2380 /// Returns true if the recipe only uses the first lane of operand \p Op.
2381 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2383 "Op must be an operand of the recipe");
2384 return isOrdered() || isInLoop();
2385 }
2386};
2387
2388/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2389/// instructions.
2391public:
2392 /// The blend operation is a User of the incoming values and of their
2393 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2394 /// be omitted (implied by passing an odd number of operands) in which case
2395 /// all other incoming values are merged into it.
2397 : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, DL) {
2398 assert(Operands.size() > 0 && "Expected at least one operand!");
2399 }
2400
2405
2406 VP_CLASSOF_IMPL(VPDef::VPBlendSC)
2407
2408 /// A normalized blend is one that has an odd number of operands, whereby the
2409 /// first operand does not have an associated mask.
2410 bool isNormalized() const { return getNumOperands() % 2; }
2411
2412 /// Return the number of incoming values, taking into account when normalized
2413 /// the first incoming value will have no mask.
2414 unsigned getNumIncomingValues() const {
2415 return (getNumOperands() + isNormalized()) / 2;
2416 }
2417
2418 /// Return incoming value number \p Idx.
2419 VPValue *getIncomingValue(unsigned Idx) const {
2420 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2421 }
2422
2423 /// Return mask number \p Idx.
2424 VPValue *getMask(unsigned Idx) const {
2425 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2426 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2427 }
2428
2429 /// Set mask number \p Idx to \p V.
2430 void setMask(unsigned Idx, VPValue *V) {
2431 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2432 Idx == 0 ? setOperand(1, V) : setOperand(Idx * 2 + !isNormalized(), V);
2433 }
2434
2435 void execute(VPTransformState &State) override {
2436 llvm_unreachable("VPBlendRecipe should be expanded by simplifyBlends");
2437 }
2438
2439 /// Return the cost of this VPWidenMemoryRecipe.
2440 InstructionCost computeCost(ElementCount VF,
2441 VPCostContext &Ctx) const override;
2442
2443#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2444 /// Print the recipe.
2445 void print(raw_ostream &O, const Twine &Indent,
2446 VPSlotTracker &SlotTracker) const override;
2447#endif
2448
2449 /// Returns true if the recipe only uses the first lane of operand \p Op.
2450 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2452 "Op must be an operand of the recipe");
2453 // Recursing through Blend recipes only, must terminate at header phi's the
2454 // latest.
2455 return all_of(users(),
2456 [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
2457 }
2458};
2459
2460/// A common base class for interleaved memory operations.
2461/// An Interleaved memory operation is a memory access method that combines
2462/// multiple strided loads/stores into a single wide load/store with shuffles.
2463/// The first operand is the start address. The optional operands are, in order,
2464/// the stored values and the mask.
2466 public VPIRMetadata {
2468
2469 /// Indicates if the interleave group is in a conditional block and requires a
2470 /// mask.
2471 bool HasMask = false;
2472
2473 /// Indicates if gaps between members of the group need to be masked out or if
2474 /// unusued gaps can be loaded speculatively.
2475 bool NeedsMaskForGaps = false;
2476
2477protected:
2478 VPInterleaveBase(const unsigned char SC,
2480 ArrayRef<VPValue *> Operands,
2481 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2482 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2483 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(MD), IG(IG),
2484 NeedsMaskForGaps(NeedsMaskForGaps) {
2485 // TODO: extend the masked interleaved-group support to reversed access.
2486 assert((!Mask || !IG->isReverse()) &&
2487 "Reversed masked interleave-group not supported.");
2488 for (unsigned I = 0; I < IG->getFactor(); ++I)
2489 if (Instruction *Inst = IG->getMember(I)) {
2490 if (Inst->getType()->isVoidTy())
2491 continue;
2492 new VPValue(Inst, this);
2493 }
2494
2495 for (auto *SV : StoredValues)
2496 addOperand(SV);
2497 if (Mask) {
2498 HasMask = true;
2499 addOperand(Mask);
2500 }
2501 }
2502
2503public:
2504 VPInterleaveBase *clone() override = 0;
2505
2506 static inline bool classof(const VPRecipeBase *R) {
2507 return R->getVPDefID() == VPRecipeBase::VPInterleaveSC ||
2508 R->getVPDefID() == VPRecipeBase::VPInterleaveEVLSC;
2509 }
2510
2511 static inline bool classof(const VPUser *U) {
2512 auto *R = dyn_cast<VPRecipeBase>(U);
2513 return R && classof(R);
2514 }
2515
2516 /// Return the address accessed by this recipe.
2517 VPValue *getAddr() const {
2518 return getOperand(0); // Address is the 1st, mandatory operand.
2519 }
2520
2521 /// Return the mask used by this recipe. Note that a full mask is represented
2522 /// by a nullptr.
2523 VPValue *getMask() const {
2524 // Mask is optional and the last operand.
2525 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2526 }
2527
2528 /// Return true if the access needs a mask because of the gaps.
2529 bool needsMaskForGaps() const { return NeedsMaskForGaps; }
2530
2532
2533 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2534
2535 void execute(VPTransformState &State) override {
2536 llvm_unreachable("VPInterleaveBase should not be instantiated.");
2537 }
2538
2539 /// Return the cost of this recipe.
2540 InstructionCost computeCost(ElementCount VF,
2541 VPCostContext &Ctx) const override;
2542
2543 /// Returns true if the recipe only uses the first lane of operand \p Op.
2544 virtual bool onlyFirstLaneUsed(const VPValue *Op) const override = 0;
2545
2546 /// Returns the number of stored operands of this interleave group. Returns 0
2547 /// for load interleave groups.
2548 virtual unsigned getNumStoreOperands() const = 0;
2549
2550 /// Return the VPValues stored by this interleave group. If it is a load
2551 /// interleave group, return an empty ArrayRef.
2553 return ArrayRef<VPValue *>(op_end() -
2554 (getNumStoreOperands() + (HasMask ? 1 : 0)),
2556 }
2557};
2558
2559/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2560/// or stores into one wide load/store and shuffles. The first operand of a
2561/// VPInterleave recipe is the address, followed by the stored values, followed
2562/// by an optional mask.
2564public:
2566 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2567 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2568 : VPInterleaveBase(VPDef::VPInterleaveSC, IG, Addr, StoredValues, Mask,
2569 NeedsMaskForGaps, MD, DL) {}
2570
2571 ~VPInterleaveRecipe() override = default;
2572
2576 needsMaskForGaps(), *this, getDebugLoc());
2577 }
2578
2579 VP_CLASSOF_IMPL(VPDef::VPInterleaveSC)
2580
2581 /// Generate the wide load or store, and shuffles.
2582 void execute(VPTransformState &State) override;
2583
2584#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2585 /// Print the recipe.
2586 void print(raw_ostream &O, const Twine &Indent,
2587 VPSlotTracker &SlotTracker) const override;
2588#endif
2589
2590 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2592 "Op must be an operand of the recipe");
2593 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2594 }
2595
2596 unsigned getNumStoreOperands() const override {
2597 return getNumOperands() - (getMask() ? 2 : 1);
2598 }
2599};
2600
2601/// A recipe for interleaved memory operations with vector-predication
2602/// intrinsics. The first operand is the address, the second operand is the
2603/// explicit vector length. Stored values and mask are optional operands.
2605public:
2607 : VPInterleaveBase(VPDef::VPInterleaveEVLSC, R.getInterleaveGroup(),
2608 ArrayRef<VPValue *>({R.getAddr(), &EVL}),
2609 R.getStoredValues(), Mask, R.needsMaskForGaps(), R,
2610 R.getDebugLoc()) {
2611 assert(!getInterleaveGroup()->isReverse() &&
2612 "Reversed interleave-group with tail folding is not supported.");
2613 assert(!needsMaskForGaps() && "Interleaved access with gap mask is not "
2614 "supported for scalable vector.");
2615 }
2616
2617 ~VPInterleaveEVLRecipe() override = default;
2618
2620 llvm_unreachable("cloning not implemented yet");
2621 }
2622
2623 VP_CLASSOF_IMPL(VPDef::VPInterleaveEVLSC)
2624
2625 /// The VPValue of the explicit vector length.
2626 VPValue *getEVL() const { return getOperand(1); }
2627
2628 /// Generate the wide load or store, and shuffles.
2629 void execute(VPTransformState &State) override;
2630
2631#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2632 /// Print the recipe.
2633 void print(raw_ostream &O, const Twine &Indent,
2634 VPSlotTracker &SlotTracker) const override;
2635#endif
2636
2637 /// The recipe only uses the first lane of the address, and EVL operand.
2638 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2640 "Op must be an operand of the recipe");
2641 return (Op == getAddr() && !llvm::is_contained(getStoredValues(), Op)) ||
2642 Op == getEVL();
2643 }
2644
2645 unsigned getNumStoreOperands() const override {
2646 return getNumOperands() - (getMask() ? 3 : 2);
2647 }
2648};
2649
2650/// A recipe to represent inloop reduction operations, performing a reduction on
2651/// a vector operand into a scalar value, and adding the result to a chain.
2652/// The Operands are {ChainOp, VecOp, [Condition]}.
2654 /// The recurrence kind for the reduction in question.
2655 RecurKind RdxKind;
2656 bool IsOrdered;
2657 /// Whether the reduction is conditional.
2658 bool IsConditional = false;
2659
2660protected:
2661 VPReductionRecipe(const unsigned char SC, RecurKind RdxKind,
2664 bool IsOrdered, DebugLoc DL)
2665 : VPRecipeWithIRFlags(SC, Operands, FMFs, DL), RdxKind(RdxKind),
2666 IsOrdered(IsOrdered) {
2667 if (CondOp) {
2668 IsConditional = true;
2669 addOperand(CondOp);
2670 }
2672 }
2673
2674public:
2676 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2677 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2678 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, I,
2679 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2680 IsOrdered, DL) {}
2681
2683 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2684 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2685 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, nullptr,
2686 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2687 IsOrdered, DL) {}
2688
2689 ~VPReductionRecipe() override = default;
2690
2692 return new VPReductionRecipe(RdxKind, getFastMathFlags(),
2694 getCondOp(), IsOrdered, getDebugLoc());
2695 }
2696
2697 static inline bool classof(const VPRecipeBase *R) {
2698 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2699 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC;
2700 }
2701
2702 static inline bool classof(const VPUser *U) {
2703 auto *R = dyn_cast<VPRecipeBase>(U);
2704 return R && classof(R);
2705 }
2706
2707 /// Generate the reduction in the loop.
2708 void execute(VPTransformState &State) override;
2709
2710 /// Return the cost of VPReductionRecipe.
2711 InstructionCost computeCost(ElementCount VF,
2712 VPCostContext &Ctx) const override;
2713
2714#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2715 /// Print the recipe.
2716 void print(raw_ostream &O, const Twine &Indent,
2717 VPSlotTracker &SlotTracker) const override;
2718#endif
2719
2720 /// Return the recurrence kind for the in-loop reduction.
2721 RecurKind getRecurrenceKind() const { return RdxKind; }
2722 /// Return true if the in-loop reduction is ordered.
2723 bool isOrdered() const { return IsOrdered; };
2724 /// Return true if the in-loop reduction is conditional.
2725 bool isConditional() const { return IsConditional; };
2726 /// The VPValue of the scalar Chain being accumulated.
2727 VPValue *getChainOp() const { return getOperand(0); }
2728 /// The VPValue of the vector value to be reduced.
2729 VPValue *getVecOp() const { return getOperand(1); }
2730 /// The VPValue of the condition for the block.
2732 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2733 }
2734};
2735
2736/// A recipe for forming partial reductions. In the loop, an accumulator and
2737/// vector operand are added together and passed to the next iteration as the
2738/// next accumulator. After the loop body, the accumulator is reduced to a
2739/// scalar value.
2741 unsigned Opcode;
2742
2743 /// The divisor by which the VF of this recipe's output should be divided
2744 /// during execution.
2745 unsigned VFScaleFactor;
2746
2747public:
2749 VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
2750 : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1, Cond,
2751 VFScaleFactor, ReductionInst) {}
2752 VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
2753 VPValue *Cond, unsigned ScaleFactor,
2754 Instruction *ReductionInst = nullptr)
2755 : VPReductionRecipe(VPDef::VPPartialReductionSC, RecurKind::Add,
2756 FastMathFlags(), ReductionInst,
2757 ArrayRef<VPValue *>({Op0, Op1}), Cond, false, {}),
2758 Opcode(Opcode), VFScaleFactor(ScaleFactor) {
2759 [[maybe_unused]] auto *AccumulatorRecipe =
2761 assert((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2762 isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2763 "Unexpected operand order for partial reduction recipe");
2764 }
2765 ~VPPartialReductionRecipe() override = default;
2766
2768 return new VPPartialReductionRecipe(Opcode, getOperand(0), getOperand(1),
2769 getCondOp(), VFScaleFactor,
2771 }
2772
2773 VP_CLASSOF_IMPL(VPDef::VPPartialReductionSC)
2774
2775 /// Generate the reduction in the loop.
2776 void execute(VPTransformState &State) override;
2777
2778 /// Return the cost of this VPPartialReductionRecipe.
2780 VPCostContext &Ctx) const override;
2781
2782 /// Get the binary op's opcode.
2783 unsigned getOpcode() const { return Opcode; }
2784
2785 /// Get the factor that the VF of this recipe's output should be scaled by.
2786 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2787
2788#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2789 /// Print the recipe.
2790 void print(raw_ostream &O, const Twine &Indent,
2791 VPSlotTracker &SlotTracker) const override;
2792#endif
2793};
2794
2795/// A recipe to represent inloop reduction operations with vector-predication
2796/// intrinsics, performing a reduction on a vector operand with the explicit
2797/// vector length (EVL) into a scalar value, and adding the result to a chain.
2798/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2800public:
2804 VPDef::VPReductionEVLSC, R.getRecurrenceKind(),
2805 R.getFastMathFlags(),
2807 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2808 R.isOrdered(), DL) {}
2809
2810 ~VPReductionEVLRecipe() override = default;
2811
2813 llvm_unreachable("cloning not implemented yet");
2814 }
2815
2816 VP_CLASSOF_IMPL(VPDef::VPReductionEVLSC)
2817
2818 /// Generate the reduction in the loop
2819 void execute(VPTransformState &State) override;
2820
2821#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2822 /// Print the recipe.
2823 void print(raw_ostream &O, const Twine &Indent,
2824 VPSlotTracker &SlotTracker) const override;
2825#endif
2826
2827 /// The VPValue of the explicit vector length.
2828 VPValue *getEVL() const { return getOperand(2); }
2829
2830 /// Returns true if the recipe only uses the first lane of operand \p Op.
2831 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2833 "Op must be an operand of the recipe");
2834 return Op == getEVL();
2835 }
2836};
2837
2838/// VPReplicateRecipe replicates a given instruction producing multiple scalar
2839/// copies of the original scalar type, one per lane, instead of producing a
2840/// single copy of widened type for all lanes. If the instruction is known to be
2841/// a single scalar, only one copy, per lane zero, will be generated.
2843 public VPIRMetadata {
2844 /// Indicator if only a single replica per lane is needed.
2845 bool IsSingleScalar;
2846
2847 /// Indicator if the replicas are also predicated.
2848 bool IsPredicated;
2849
2850public:
2852 bool IsSingleScalar, VPValue *Mask = nullptr,
2853 VPIRMetadata Metadata = {})
2854 : VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
2855 VPIRMetadata(Metadata), IsSingleScalar(IsSingleScalar),
2856 IsPredicated(Mask) {
2857 if (Mask)
2858 addOperand(Mask);
2859 }
2860
2861 ~VPReplicateRecipe() override = default;
2862
2864 auto *Copy =
2865 new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsSingleScalar,
2866 isPredicated() ? getMask() : nullptr, *this);
2867 Copy->transferFlags(*this);
2868 return Copy;
2869 }
2870
2871 VP_CLASSOF_IMPL(VPDef::VPReplicateSC)
2872
2873 /// Generate replicas of the desired Ingredient. Replicas will be generated
2874 /// for all parts and lanes unless a specific part and lane are specified in
2875 /// the \p State.
2876 void execute(VPTransformState &State) override;
2877
2878 /// Return the cost of this VPReplicateRecipe.
2879 InstructionCost computeCost(ElementCount VF,
2880 VPCostContext &Ctx) const override;
2881
2882#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2883 /// Print the recipe.
2884 void print(raw_ostream &O, const Twine &Indent,
2885 VPSlotTracker &SlotTracker) const override;
2886#endif
2887
2888 bool isSingleScalar() const { return IsSingleScalar; }
2889
2890 bool isPredicated() const { return IsPredicated; }
2891
2892 /// Returns true if the recipe only uses the first lane of operand \p Op.
2893 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2895 "Op must be an operand of the recipe");
2896 return isSingleScalar();
2897 }
2898
2899 /// Returns true if the recipe uses scalars of operand \p Op.
2900 bool usesScalars(const VPValue *Op) const override {
2902 "Op must be an operand of the recipe");
2903 return true;
2904 }
2905
2906 /// Returns true if the recipe is used by a widened recipe via an intervening
2907 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
2908 /// in a vector.
2909 bool shouldPack() const;
2910
2911 /// Return the mask of a predicated VPReplicateRecipe.
2913 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
2914 return getOperand(getNumOperands() - 1);
2915 }
2916
2917 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
2918};
2919
2920/// A recipe for generating conditional branches on the bits of a mask.
2922public:
2924 : VPRecipeBase(VPDef::VPBranchOnMaskSC, {BlockInMask}, DL) {}
2925
2928 }
2929
2930 VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)
2931
2932 /// Generate the extraction of the appropriate bit from the block mask and the
2933 /// conditional branch.
2934 void execute(VPTransformState &State) override;
2935
2936 /// Return the cost of this VPBranchOnMaskRecipe.
2937 InstructionCost computeCost(ElementCount VF,
2938 VPCostContext &Ctx) const override;
2939
2940#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2941 /// Print the recipe.
2942 void print(raw_ostream &O, const Twine &Indent,
2943 VPSlotTracker &SlotTracker) const override {
2944 O << Indent << "BRANCH-ON-MASK ";
2946 }
2947#endif
2948
2949 /// Returns true if the recipe uses scalars of operand \p Op.
2950 bool usesScalars(const VPValue *Op) const override {
2952 "Op must be an operand of the recipe");
2953 return true;
2954 }
2955};
2956
2957/// A recipe to combine multiple recipes into a single 'expression' recipe,
2958/// which should be considered a single entity for cost-modeling and transforms.
2959/// The recipe needs to be 'decomposed', i.e. replaced by its individual
2960/// expression recipes, before execute. The individual expression recipes are
2961/// completely disconnected from the def-use graph of other recipes not part of
2962/// the expression. Def-use edges between pairs of expression recipes remain
2963/// intact, whereas every edge between an expression recipe and a recipe outside
2964/// the expression is elevated to connect the non-expression recipe with the
2965/// VPExpressionRecipe itself.
2966class VPExpressionRecipe : public VPSingleDefRecipe {
2967 /// Recipes included in this VPExpressionRecipe.
2968 SmallVector<VPSingleDefRecipe *> ExpressionRecipes;
2969
2970 /// Temporary VPValues used for external operands of the expression, i.e.
2971 /// operands not defined by recipes in the expression.
2972 SmallVector<VPValue *> LiveInPlaceholders;
2973
2974 enum class ExpressionTypes {
2975 /// Represents an inloop extended reduction operation, performing a
2976 /// reduction on an extended vector operand into a scalar value, and adding
2977 /// the result to a chain.
2978 ExtendedReduction,
2979 /// Represent an inloop multiply-accumulate reduction, multiplying the
2980 /// extended vector operands, performing a reduction.add on the result, and
2981 /// adding the scalar result to a chain.
2982 ExtMulAccReduction,
2983 /// Represent an inloop multiply-accumulate reduction, multiplying the
2984 /// vector operands, performing a reduction.add on the result, and adding
2985 /// the scalar result to a chain.
2986 MulAccReduction,
2987 };
2988
2989 /// Type of the expression.
2990 ExpressionTypes ExpressionType;
2991
2992 /// Construct a new VPExpressionRecipe by internalizing recipes in \p
2993 /// ExpressionRecipes. External operands (i.e. not defined by another recipe
2994 /// in the expression) are replaced by temporary VPValues and the original
2995 /// operands are transferred to the VPExpressionRecipe itself. Clone recipes
2996 /// as needed (excluding last) to ensure they are only used by other recipes
2997 /// in the expression.
2998 VPExpressionRecipe(ExpressionTypes ExpressionType,
2999 ArrayRef<VPSingleDefRecipe *> ExpressionRecipes);
3000
3001public:
3003 : VPExpressionRecipe(ExpressionTypes::ExtendedReduction, {Ext, Red}) {}
3005 : VPExpressionRecipe(ExpressionTypes::MulAccReduction, {Mul, Red}) {}
3008 : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction,
3009 {Ext0, Ext1, Mul, Red}) {}
3010
3012 for (auto *R : reverse(ExpressionRecipes))
3013 delete R;
3014 for (VPValue *T : LiveInPlaceholders)
3015 delete T;
3016 }
3017
3018 VP_CLASSOF_IMPL(VPDef::VPExpressionSC)
3019
3020 VPExpressionRecipe *clone() override {
3021 assert(!ExpressionRecipes.empty() && "empty expressions should be removed");
3022 SmallVector<VPSingleDefRecipe *> NewExpressiondRecipes;
3023 for (auto *R : ExpressionRecipes)
3024 NewExpressiondRecipes.push_back(R->clone());
3025 for (auto *New : NewExpressiondRecipes) {
3026 for (const auto &[Idx, Old] : enumerate(ExpressionRecipes))
3027 New->replaceUsesOfWith(Old, NewExpressiondRecipes[Idx]);
3028 // Update placeholder operands in the cloned recipe to use the external
3029 // operands, to be internalized when the cloned expression is constructed.
3030 for (const auto &[Placeholder, OutsideOp] :
3031 zip(LiveInPlaceholders, operands()))
3032 New->replaceUsesOfWith(Placeholder, OutsideOp);
3033 }
3034 return new VPExpressionRecipe(ExpressionType, NewExpressiondRecipes);
3035 }
3036
3037 /// Return the VPValue to use to infer the result type of the recipe.
3039 unsigned OpIdx =
3040 cast<VPReductionRecipe>(ExpressionRecipes.back())->isConditional() ? 2
3041 : 1;
3042 return getOperand(getNumOperands() - OpIdx);
3043 }
3044
3045 /// Insert the recipes of the expression back into the VPlan, directly before
3046 /// the current recipe. Leaves the expression recipe empty, which must be
3047 /// removed before codegen.
3048 void decompose();
3049
3050 /// Method for generating code, must not be called as this recipe is abstract.
3051 void execute(VPTransformState &State) override {
3052 llvm_unreachable("recipe must be removed before execute");
3053 }
3054
3056 VPCostContext &Ctx) const override;
3057
3058#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3059 /// Print the recipe.
3060 void print(raw_ostream &O, const Twine &Indent,
3061 VPSlotTracker &SlotTracker) const override;
3062#endif
3063
3064 /// Returns true if this expression contains recipes that may read from or
3065 /// write to memory.
3066 bool mayReadOrWriteMemory() const;
3067
3068 /// Returns true if this expression contains recipes that may have side
3069 /// effects.
3070 bool mayHaveSideEffects() const;
3071};
3072
3073/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
3074/// control converges back from a Branch-on-Mask. The phi nodes are needed in
3075/// order to merge values that are set under such a branch and feed their uses.
3076/// The phi nodes can be scalar or vector depending on the users of the value.
3077/// This recipe works in concert with VPBranchOnMaskRecipe.
3079public:
3080 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
3081 /// nodes after merging back from a Branch-on-Mask.
3083 : VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
3084 ~VPPredInstPHIRecipe() override = default;
3085
3087 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
3088 }
3089
3090 VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)
3091
3092 /// Generates phi nodes for live-outs (from a replicate region) as needed to
3093 /// retain SSA form.
3094 void execute(VPTransformState &State) override;
3095
3096 /// Return the cost of this VPPredInstPHIRecipe.
3098 VPCostContext &Ctx) const override {
3099 // TODO: Compute accurate cost after retiring the legacy cost model.
3100 return 0;
3101 }
3102
3103#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3104 /// Print the recipe.
3105 void print(raw_ostream &O, const Twine &Indent,
3106 VPSlotTracker &SlotTracker) const override;
3107#endif
3108
3109 /// Returns true if the recipe uses scalars of operand \p Op.
3110 bool usesScalars(const VPValue *Op) const override {
3112 "Op must be an operand of the recipe");
3113 return true;
3114 }
3115};
3116
3117/// A common base class for widening memory operations. An optional mask can be
3118/// provided as the last operand.
3120 public VPIRMetadata {
3121protected:
3123
3124 /// Whether the accessed addresses are consecutive.
3126
3127 /// Whether the consecutive accessed addresses are in reverse order.
3129
3130 /// Whether the memory access is masked.
3131 bool IsMasked = false;
3132
3133 void setMask(VPValue *Mask) {
3134 assert(!IsMasked && "cannot re-set mask");
3135 if (!Mask)
3136 return;
3137 addOperand(Mask);
3138 IsMasked = true;
3139 }
3140
3141 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
3142 std::initializer_list<VPValue *> Operands,
3143 bool Consecutive, bool Reverse,
3144 const VPIRMetadata &Metadata, DebugLoc DL)
3145 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
3147 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
3148 }
3149
3150public:
3152 llvm_unreachable("cloning not supported");
3153 }
3154
3155 static inline bool classof(const VPRecipeBase *R) {
3156 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
3157 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
3158 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
3159 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
3160 }
3161
3162 static inline bool classof(const VPUser *U) {
3163 auto *R = dyn_cast<VPRecipeBase>(U);
3164 return R && classof(R);
3165 }
3166
3167 /// Return whether the loaded-from / stored-to addresses are consecutive.
3168 bool isConsecutive() const { return Consecutive; }
3169
3170 /// Return whether the consecutive loaded/stored addresses are in reverse
3171 /// order.
3172 bool isReverse() const { return Reverse; }
3173
3174 /// Return the address accessed by this recipe.
3175 VPValue *getAddr() const { return getOperand(0); }
3176
3177 /// Returns true if the recipe is masked.
3178 bool isMasked() const { return IsMasked; }
3179
3180 /// Return the mask used by this recipe. Note that a full mask is represented
3181 /// by a nullptr.
3182 VPValue *getMask() const {
3183 // Mask is optional and therefore the last operand.
3184 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
3185 }
3186
3187 /// Generate the wide load/store.
3188 void execute(VPTransformState &State) override {
3189 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
3190 }
3191
3192 /// Return the cost of this VPWidenMemoryRecipe.
3193 InstructionCost computeCost(ElementCount VF,
3194 VPCostContext &Ctx) const override;
3195
3197};
3198
3199/// A recipe for widening load operations, using the address to load from and an
3200/// optional mask.
3202 public VPValue {
3204 bool Consecutive, bool Reverse,
3205 const VPIRMetadata &Metadata, DebugLoc DL)
3206 : VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
3207 Reverse, Metadata, DL),
3208 VPValue(this, &Load) {
3209 setMask(Mask);
3210 }
3211
3214 getMask(), Consecutive, Reverse, *this,
3215 getDebugLoc());
3216 }
3217
3218 VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC);
3219
3220 /// Generate a wide load or gather.
3221 void execute(VPTransformState &State) override;
3222
3223#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3224 /// Print the recipe.
3225 void print(raw_ostream &O, const Twine &Indent,
3226 VPSlotTracker &SlotTracker) const override;
3227#endif
3228
3229 /// Returns true if the recipe only uses the first lane of operand \p Op.
3230 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3232 "Op must be an operand of the recipe");
3233 // Widened, consecutive loads operations only demand the first lane of
3234 // their address.
3235 return Op == getAddr() && isConsecutive();
3236 }
3237};
3238
3239/// A recipe for widening load operations with vector-predication intrinsics,
3240/// using the address to load from, the explicit vector length and an optional
3241/// mask.
3242struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
3244 VPValue *Mask)
3245 : VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
3246 {Addr, &EVL}, L.isConsecutive(), L.isReverse(), L,
3247 L.getDebugLoc()),
3248 VPValue(this, &getIngredient()) {
3249 setMask(Mask);
3250 }
3251
3252 VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
3253
3254 /// Return the EVL operand.
3255 VPValue *getEVL() const { return getOperand(1); }
3256
3257 /// Generate the wide load or gather.
3258 void execute(VPTransformState &State) override;
3259
3260 /// Return the cost of this VPWidenLoadEVLRecipe.
3262 VPCostContext &Ctx) const override;
3263
3264#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3265 /// Print the recipe.
3266 void print(raw_ostream &O, const Twine &Indent,
3267 VPSlotTracker &SlotTracker) const override;
3268#endif
3269
3270 /// Returns true if the recipe only uses the first lane of operand \p Op.
3271 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3273 "Op must be an operand of the recipe");
3274 // Widened loads only demand the first lane of EVL and consecutive loads
3275 // only demand the first lane of their address.
3276 return Op == getEVL() || (Op == getAddr() && isConsecutive());
3277 }
3278};
3279
3280/// A recipe for widening store operations, using the stored value, the address
3281/// to store to and an optional mask.
3283 VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
3284 VPValue *Mask, bool Consecutive, bool Reverse,
3285 const VPIRMetadata &Metadata, DebugLoc DL)
3286 : VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
3287 Consecutive, Reverse, Metadata, DL) {
3288 setMask(Mask);
3289 }
3290
3296
3297 VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
3298
3299 /// Return the value stored by this recipe.
3300 VPValue *getStoredValue() const { return getOperand(1); }
3301
3302 /// Generate a wide store or scatter.
3303 void execute(VPTransformState &State) override;
3304
3305#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3306 /// Print the recipe.
3307 void print(raw_ostream &O, const Twine &Indent,
3308 VPSlotTracker &SlotTracker) const override;
3309#endif
3310
3311 /// Returns true if the recipe only uses the first lane of operand \p Op.
3312 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3314 "Op must be an operand of the recipe");
3315 // Widened, consecutive stores only demand the first lane of their address,
3316 // unless the same operand is also stored.
3317 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3318 }
3319};
3320
3321/// A recipe for widening store operations with vector-predication intrinsics,
3322/// using the value to store, the address to store to, the explicit vector
3323/// length and an optional mask.
3326 VPValue *Mask)
3327 : VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
3328 {Addr, S.getStoredValue(), &EVL}, S.isConsecutive(),
3329 S.isReverse(), S, S.getDebugLoc()) {
3330 setMask(Mask);
3331 }
3332
3333 VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
3334
3335 /// Return the address accessed by this recipe.
3336 VPValue *getStoredValue() const { return getOperand(1); }
3337
3338 /// Return the EVL operand.
3339 VPValue *getEVL() const { return getOperand(2); }
3340
3341 /// Generate the wide store or scatter.
3342 void execute(VPTransformState &State) override;
3343
3344 /// Return the cost of this VPWidenStoreEVLRecipe.
3346 VPCostContext &Ctx) const override;
3347
3348#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3349 /// Print the recipe.
3350 void print(raw_ostream &O, const Twine &Indent,
3351 VPSlotTracker &SlotTracker) const override;
3352#endif
3353
3354 /// Returns true if the recipe only uses the first lane of operand \p Op.
3355 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3357 "Op must be an operand of the recipe");
3358 if (Op == getEVL()) {
3359 assert(getStoredValue() != Op && "unexpected store of EVL");
3360 return true;
3361 }
3362 // Widened, consecutive memory operations only demand the first lane of
3363 // their address, unless the same operand is also stored. That latter can
3364 // happen with opaque pointers.
3365 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3366 }
3367};
3368
3369/// Recipe to expand a SCEV expression.
3371 const SCEV *Expr;
3372
3373public:
3375 : VPSingleDefRecipe(VPDef::VPExpandSCEVSC, {}), Expr(Expr) {}
3376
3377 ~VPExpandSCEVRecipe() override = default;
3378
3379 VPExpandSCEVRecipe *clone() override { return new VPExpandSCEVRecipe(Expr); }
3380
3381 VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)
3382
3383 void execute(VPTransformState &State) override {
3384 llvm_unreachable("SCEV expressions must be expanded before final execute");
3385 }
3386
3387 /// Return the cost of this VPExpandSCEVRecipe.
3389 VPCostContext &Ctx) const override {
3390 // TODO: Compute accurate cost after retiring the legacy cost model.
3391 return 0;
3392 }
3393
3394#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3395 /// Print the recipe.
3396 void print(raw_ostream &O, const Twine &Indent,
3397 VPSlotTracker &SlotTracker) const override;
3398#endif
3399
3400 const SCEV *getSCEV() const { return Expr; }
3401};
3402
3403/// Canonical scalar induction phi of the vector loop. Starting at the specified
3404/// start value (either 0 or the resume value when vectorizing the epilogue
3405/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
3406/// canonical induction variable.
3408public:
3410 : VPHeaderPHIRecipe(VPDef::VPCanonicalIVPHISC, nullptr, StartV, DL) {}
3411
3412 ~VPCanonicalIVPHIRecipe() override = default;
3413
3415 auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
3416 R->addOperand(getBackedgeValue());
3417 return R;
3418 }
3419
3420 VP_CLASSOF_IMPL(VPDef::VPCanonicalIVPHISC)
3421
3422 void execute(VPTransformState &State) override {
3423 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3424 "scalar phi recipe");
3425 }
3426
3427#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3428 /// Print the recipe.
3429 void print(raw_ostream &O, const Twine &Indent,
3430 VPSlotTracker &SlotTracker) const override;
3431#endif
3432
3433 /// Returns the scalar type of the induction.
3435 return getStartValue()->getLiveInIRValue()->getType();
3436 }
3437
3438 /// Returns true if the recipe only uses the first lane of operand \p Op.
3439 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3441 "Op must be an operand of the recipe");
3442 return true;
3443 }
3444
3445 /// Returns true if the recipe only uses the first part of operand \p Op.
3446 bool onlyFirstPartUsed(const VPValue *Op) const override {
3448 "Op must be an operand of the recipe");
3449 return true;
3450 }
3451
3452 /// Return the cost of this VPCanonicalIVPHIRecipe.
3454 VPCostContext &Ctx) const override {
3455 // For now, match the behavior of the legacy cost model.
3456 return 0;
3457 }
3458};
3459
3460/// A recipe for generating the active lane mask for the vector loop that is
3461/// used to predicate the vector operations.
3462/// TODO: It would be good to use the existing VPWidenPHIRecipe instead and
3463/// remove VPActiveLaneMaskPHIRecipe.
3465public:
3467 : VPHeaderPHIRecipe(VPDef::VPActiveLaneMaskPHISC, nullptr, StartMask,
3468 DL) {}
3469
3470 ~VPActiveLaneMaskPHIRecipe() override = default;
3471
3474 if (getNumOperands() == 2)
3475 R->addOperand(getOperand(1));
3476 return R;
3477 }
3478
3479 VP_CLASSOF_IMPL(VPDef::VPActiveLaneMaskPHISC)
3480
3481 /// Generate the active lane mask phi of the vector loop.
3482 void execute(VPTransformState &State) override;
3483
3484#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3485 /// Print the recipe.
3486 void print(raw_ostream &O, const Twine &Indent,
3487 VPSlotTracker &SlotTracker) const override;
3488#endif
3489};
3490
3491/// A recipe for generating the phi node for the current index of elements,
3492/// adjusted in accordance with EVL value. It starts at the start value of the
3493/// canonical induction and gets incremented by EVL in each iteration of the
3494/// vector loop.
3496public:
3498 : VPHeaderPHIRecipe(VPDef::VPEVLBasedIVPHISC, nullptr, StartIV, DL) {}
3499
3500 ~VPEVLBasedIVPHIRecipe() override = default;
3501
3503 llvm_unreachable("cloning not implemented yet");
3504 }
3505
3506 VP_CLASSOF_IMPL(VPDef::VPEVLBasedIVPHISC)
3507
3508 void execute(VPTransformState &State) override {
3509 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3510 "scalar phi recipe");
3511 }
3512
3513 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3515 VPCostContext &Ctx) const override {
3516 // For now, match the behavior of the legacy cost model.
3517 return 0;
3518 }
3519
3520 /// Returns true if the recipe only uses the first lane of operand \p Op.
3521 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3523 "Op must be an operand of the recipe");
3524 return true;
3525 }
3526
3527#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3528 /// Print the recipe.
3529 void print(raw_ostream &O, const Twine &Indent,
3530 VPSlotTracker &SlotTracker) const override;
3531#endif
3532};
3533
3534/// A Recipe for widening the canonical induction variable of the vector loop.
3536 public VPUnrollPartAccessor<1> {
3537public:
3539 : VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3540
3541 ~VPWidenCanonicalIVRecipe() override = default;
3542
3547
3548 VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC)
3549
3550 /// Generate a canonical vector induction variable of the vector loop, with
3551 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3552 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3553 void execute(VPTransformState &State) override;
3554
3555 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3557 VPCostContext &Ctx) const override {
3558 // TODO: Compute accurate cost after retiring the legacy cost model.
3559 return 0;
3560 }
3561
3562#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3563 /// Print the recipe.
3564 void print(raw_ostream &O, const Twine &Indent,
3565 VPSlotTracker &SlotTracker) const override;
3566#endif
3567};
3568
3569/// A recipe for converting the input value \p IV value to the corresponding
3570/// value of an IV with different start and step values, using Start + IV *
3571/// Step.
3573 /// Kind of the induction.
3575 /// If not nullptr, the floating point induction binary operator. Must be set
3576 /// for floating point inductions.
3577 const FPMathOperator *FPBinOp;
3578
3579 /// Name to use for the generated IR instruction for the derived IV.
3580 std::string Name;
3581
3582public:
3584 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3585 const Twine &Name = "")
3587 IndDesc.getKind(),
3588 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3589 Start, CanonicalIV, Step, Name) {}
3590
3592 const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3593 VPValue *Step, const Twine &Name = "")
3594 : VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3595 FPBinOp(FPBinOp), Name(Name.str()) {}
3596
3597 ~VPDerivedIVRecipe() override = default;
3598
3600 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3601 getStepValue());
3602 }
3603
3604 VP_CLASSOF_IMPL(VPDef::VPDerivedIVSC)
3605
3606 /// Generate the transformed value of the induction at offset StartValue (1.
3607 /// operand) + IV (2. operand) * StepValue (3, operand).
3608 void execute(VPTransformState &State) override;
3609
3610 /// Return the cost of this VPDerivedIVRecipe.
3612 VPCostContext &Ctx) const override {
3613 // TODO: Compute accurate cost after retiring the legacy cost model.
3614 return 0;
3615 }
3616
3617#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3618 /// Print the recipe.
3619 void print(raw_ostream &O, const Twine &Indent,
3620 VPSlotTracker &SlotTracker) const override;
3621#endif
3622
3624 return getStartValue()->getLiveInIRValue()->getType();
3625 }
3626
3627 VPValue *getStartValue() const { return getOperand(0); }
3628 VPValue *getStepValue() const { return getOperand(2); }
3629
3630 /// Returns true if the recipe only uses the first lane of operand \p Op.
3631 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3633 "Op must be an operand of the recipe");
3634 return true;
3635 }
3636};
3637
3638/// A recipe for handling phi nodes of integer and floating-point inductions,
3639/// producing their scalar values.
3641 public VPUnrollPartAccessor<3> {
3642 Instruction::BinaryOps InductionOpcode;
3643
3644public:
3647 DebugLoc DL)
3648 : VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
3649 ArrayRef<VPValue *>({IV, Step, VF}), FMFs, DL),
3650 InductionOpcode(Opcode) {}
3651
3653 VPValue *Step, VPValue *VF,
3656 IV, Step, VF, IndDesc.getInductionOpcode(),
3657 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3658 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3659 : FastMathFlags(),
3660 DL) {}
3661
3662 ~VPScalarIVStepsRecipe() override = default;
3663
3665 return new VPScalarIVStepsRecipe(
3666 getOperand(0), getOperand(1), getOperand(2), InductionOpcode,
3668 getDebugLoc());
3669 }
3670
3671 /// Return true if this VPScalarIVStepsRecipe corresponds to part 0. Note that
3672 /// this is only accurate after the VPlan has been unrolled.
3673 bool isPart0() const { return getUnrollPart(*this) == 0; }
3674
3675 VP_CLASSOF_IMPL(VPDef::VPScalarIVStepsSC)
3676
3677 /// Generate the scalarized versions of the phi node as needed by their users.
3678 void execute(VPTransformState &State) override;
3679
3680 /// Return the cost of this VPScalarIVStepsRecipe.
3682 VPCostContext &Ctx) const override {
3683 // TODO: Compute accurate cost after retiring the legacy cost model.
3684 return 0;
3685 }
3686
3687#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3688 /// Print the recipe.
3689 void print(raw_ostream &O, const Twine &Indent,
3690 VPSlotTracker &SlotTracker) const override;
3691#endif
3692
3693 VPValue *getStepValue() const { return getOperand(1); }
3694
3695 /// Returns true if the recipe only uses the first lane of operand \p Op.
3696 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3698 "Op must be an operand of the recipe");
3699 return true;
3700 }
3701};
3702
3703/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
3704/// types implementing VPPhiAccessors. Used by isa<> & co.
3706 static inline bool isPossible(const VPRecipeBase *f) {
3707 // TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
3709 }
3710};
3711/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
3712/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
3713template <typename SrcTy>
3714struct CastInfoVPPhiAccessors : public CastIsPossible<VPPhiAccessors, SrcTy> {
3715
3717
3718 /// doCast is used by cast<>.
3719 static inline VPPhiAccessors *doCast(SrcTy R) {
3720 return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
3721 switch (R->getVPDefID()) {
3722 case VPDef::VPInstructionSC:
3723 return cast<VPPhi>(R);
3724 case VPDef::VPIRInstructionSC:
3725 return cast<VPIRPhi>(R);
3726 case VPDef::VPWidenPHISC:
3727 return cast<VPWidenPHIRecipe>(R);
3728 default:
3729 return cast<VPHeaderPHIRecipe>(R);
3730 }
3731 }());
3732 }
3733
3734 /// doCastIfPossible is used by dyn_cast<>.
3735 static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
3736 if (!Self::isPossible(f))
3737 return nullptr;
3738 return doCast(f);
3739 }
3740};
3741template <>
3744template <>
3747
3748/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
3749/// holds a sequence of zero or more VPRecipe's each representing a sequence of
3750/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
3751class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
3752 friend class VPlan;
3753
3754 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3755 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3756 : VPBlockBase(VPBasicBlockSC, Name.str()) {
3757 if (Recipe)
3758 appendRecipe(Recipe);
3759 }
3760
3761public:
3763
3764protected:
3765 /// The VPRecipes held in the order of output instructions to generate.
3767
3768 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
3769 : VPBlockBase(BlockSC, Name.str()) {}
3770
3771public:
3772 ~VPBasicBlock() override {
3773 while (!Recipes.empty())
3774 Recipes.pop_back();
3775 }
3776
3777 /// Instruction iterators...
3782
3783 //===--------------------------------------------------------------------===//
3784 /// Recipe iterator methods
3785 ///
3786 inline iterator begin() { return Recipes.begin(); }
3787 inline const_iterator begin() const { return Recipes.begin(); }
3788 inline iterator end() { return Recipes.end(); }
3789 inline const_iterator end() const { return Recipes.end(); }
3790
3791 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
3792 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
3793 inline reverse_iterator rend() { return Recipes.rend(); }
3794 inline const_reverse_iterator rend() const { return Recipes.rend(); }
3795
3796 inline size_t size() const { return Recipes.size(); }
3797 inline bool empty() const { return Recipes.empty(); }
3798 inline const VPRecipeBase &front() const { return Recipes.front(); }
3799 inline VPRecipeBase &front() { return Recipes.front(); }
3800 inline const VPRecipeBase &back() const { return Recipes.back(); }
3801 inline VPRecipeBase &back() { return Recipes.back(); }
3802
3803 /// Returns a reference to the list of recipes.
3805
3806 /// Returns a pointer to a member of the recipe list.
3807 static RecipeListTy VPBasicBlock::*getSublistAccess(VPRecipeBase *) {
3808 return &VPBasicBlock::Recipes;
3809 }
3810
3811 /// Method to support type inquiry through isa, cast, and dyn_cast.
3812 static inline bool classof(const VPBlockBase *V) {
3813 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3814 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3815 }
3816
3817 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
3818 assert(Recipe && "No recipe to append.");
3819 assert(!Recipe->Parent && "Recipe already in VPlan");
3820 Recipe->Parent = this;
3821 Recipes.insert(InsertPt, Recipe);
3822 }
3823
3824 /// Augment the existing recipes of a VPBasicBlock with an additional
3825 /// \p Recipe as the last recipe.
3826 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
3827
3828 /// The method which generates the output IR instructions that correspond to
3829 /// this VPBasicBlock, thereby "executing" the VPlan.
3830 void execute(VPTransformState *State) override;
3831
3832 /// Return the cost of this VPBasicBlock.
3833 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
3834
3835 /// Return the position of the first non-phi node recipe in the block.
3836 iterator getFirstNonPhi();
3837
3838 /// Returns an iterator range over the PHI-like recipes in the block.
3842
3843 /// Split current block at \p SplitAt by inserting a new block between the
3844 /// current block and its successors and moving all recipes starting at
3845 /// SplitAt to the new block. Returns the new block.
3846 VPBasicBlock *splitAt(iterator SplitAt);
3847
3848 VPRegionBlock *getEnclosingLoopRegion();
3849 const VPRegionBlock *getEnclosingLoopRegion() const;
3850
3851#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3852 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
3853 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
3854 ///
3855 /// Note that the numbering is applied to the whole VPlan, so printing
3856 /// individual blocks is consistent with the whole VPlan printing.
3857 void print(raw_ostream &O, const Twine &Indent,
3858 VPSlotTracker &SlotTracker) const override;
3859 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3860#endif
3861
3862 /// If the block has multiple successors, return the branch recipe terminating
3863 /// the block. If there are no or only a single successor, return nullptr;
3864 VPRecipeBase *getTerminator();
3865 const VPRecipeBase *getTerminator() const;
3866
3867 /// Returns true if the block is exiting it's parent region.
3868 bool isExiting() const;
3869
3870 /// Clone the current block and it's recipes, without updating the operands of
3871 /// the cloned recipes.
3872 VPBasicBlock *clone() override;
3873
3874 /// Returns the predecessor block at index \p Idx with the predecessors as per
3875 /// the corresponding plain CFG. If the block is an entry block to a region,
3876 /// the first predecessor is the single predecessor of a region, and the
3877 /// second predecessor is the exiting block of the region.
3878 const VPBasicBlock *getCFGPredecessor(unsigned Idx) const;
3879
3880protected:
3881 /// Execute the recipes in the IR basic block \p BB.
3882 void executeRecipes(VPTransformState *State, BasicBlock *BB);
3883
3884 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
3885 /// generated for this VPBB.
3886 void connectToPredecessors(VPTransformState &State);
3887
3888private:
3889 /// Create an IR BasicBlock to hold the output instructions generated by this
3890 /// VPBasicBlock, and return it. Update the CFGState accordingly.
3891 BasicBlock *createEmptyBasicBlock(VPTransformState &State);
3892};
3893
3894inline const VPBasicBlock *
3896 return getAsRecipe()->getParent()->getCFGPredecessor(Idx);
3897}
3898
3899/// A special type of VPBasicBlock that wraps an existing IR basic block.
3900/// Recipes of the block get added before the first non-phi instruction in the
3901/// wrapped block.
3902/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
3903/// preheader block.
3904class VPIRBasicBlock : public VPBasicBlock {
3905 friend class VPlan;
3906
3907 BasicBlock *IRBB;
3908
3909 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
3910 VPIRBasicBlock(BasicBlock *IRBB)
3911 : VPBasicBlock(VPIRBasicBlockSC,
3912 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
3913 IRBB(IRBB) {}
3914
3915public:
3916 ~VPIRBasicBlock() override {}
3917
3918 static inline bool classof(const VPBlockBase *V) {
3919 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3920 }
3921
3922 /// The method which generates the output IR instructions that correspond to
3923 /// this VPBasicBlock, thereby "executing" the VPlan.
3924 void execute(VPTransformState *State) override;
3925
3926 VPIRBasicBlock *clone() override;
3927
3928 BasicBlock *getIRBasicBlock() const { return IRBB; }
3929};
3930
3931/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
3932/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
3933/// A VPRegionBlock may indicate that its contents are to be replicated several
3934/// times. This is designed to support predicated scalarization, in which a
3935/// scalar if-then code structure needs to be generated VF * UF times. Having
3936/// this replication indicator helps to keep a single model for multiple
3937/// candidate VF's. The actual replication takes place only once the desired VF
3938/// and UF have been determined.
3939class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
3940 friend class VPlan;
3941
3942 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
3943 VPBlockBase *Entry;
3944
3945 /// Hold the Single Exiting block of the SESE region modelled by the
3946 /// VPRegionBlock.
3947 VPBlockBase *Exiting;
3948
3949 /// An indicator whether this region is to generate multiple replicated
3950 /// instances of output IR corresponding to its VPBlockBases.
3951 bool IsReplicator;
3952
3953 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
3954 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
3955 const std::string &Name = "", bool IsReplicator = false)
3956 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
3957 IsReplicator(IsReplicator) {
3958 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
3959 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
3960 Entry->setParent(this);
3961 Exiting->setParent(this);
3962 }
3963 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
3964 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3965 IsReplicator(IsReplicator) {}
3966
3967public:
3968 ~VPRegionBlock() override {}
3969
3970 /// Method to support type inquiry through isa, cast, and dyn_cast.
3971 static inline bool classof(const VPBlockBase *V) {
3972 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
3973 }
3974
3975 const VPBlockBase *getEntry() const { return Entry; }
3976 VPBlockBase *getEntry() { return Entry; }
3977
3978 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
3979 /// EntryBlock must have no predecessors.
3980 void setEntry(VPBlockBase *EntryBlock) {
3981 assert(EntryBlock->getPredecessors().empty() &&
3982 "Entry block cannot have predecessors.");
3983 Entry = EntryBlock;
3984 EntryBlock->setParent(this);
3985 }
3986
3987 const VPBlockBase *getExiting() const { return Exiting; }
3988 VPBlockBase *getExiting() { return Exiting; }
3989
3990 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
3991 /// ExitingBlock must have no successors.
3992 void setExiting(VPBlockBase *ExitingBlock) {
3993 assert(ExitingBlock->getSuccessors().empty() &&
3994 "Exit block cannot have successors.");
3995 Exiting = ExitingBlock;
3996 ExitingBlock->setParent(this);
3997 }
3998
3999 /// Returns the pre-header VPBasicBlock of the loop region.
4001 assert(!isReplicator() && "should only get pre-header of loop regions");
4002 return getSinglePredecessor()->getExitingBasicBlock();
4003 }
4004
4005 /// An indicator whether this region is to generate multiple replicated
4006 /// instances of output IR corresponding to its VPBlockBases.
4007 bool isReplicator() const { return IsReplicator; }
4008
4009 /// The method which generates the output IR instructions that correspond to
4010 /// this VPRegionBlock, thereby "executing" the VPlan.
4011 void execute(VPTransformState *State) override;
4012
4013 // Return the cost of this region.
4014 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
4015
4016#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4017 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
4018 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
4019 /// consequtive numbers.
4020 ///
4021 /// Note that the numbering is applied to the whole VPlan, so printing
4022 /// individual regions is consistent with the whole VPlan printing.
4023 void print(raw_ostream &O, const Twine &Indent,
4024 VPSlotTracker &SlotTracker) const override;
4025 using VPBlockBase::print; // Get the print(raw_stream &O) version.
4026#endif
4027
4028 /// Clone all blocks in the single-entry single-exit region of the block and
4029 /// their recipes without updating the operands of the cloned recipes.
4030 VPRegionBlock *clone() override;
4031
4032 /// Remove the current region from its VPlan, connecting its predecessor to
4033 /// its entry, and its exiting block to its successor.
4034 void dissolveToCFGLoop();
4035};
4036
4037/// VPlan models a candidate for vectorization, encoding various decisions take
4038/// to produce efficient output IR, including which branches, basic-blocks and
4039/// output IR instructions to generate, and their cost. VPlan holds a
4040/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
4041/// VPBasicBlock.
4042class VPlan {
4043 friend class VPlanPrinter;
4044 friend class VPSlotTracker;
4045
4046 /// VPBasicBlock corresponding to the original preheader. Used to place
4047 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
4048 /// rest of VPlan execution.
4049 /// When this VPlan is used for the epilogue vector loop, the entry will be
4050 /// replaced by a new entry block created during skeleton creation.
4051 VPBasicBlock *Entry;
4052
4053 /// VPIRBasicBlock wrapping the header of the original scalar loop.
4054 VPIRBasicBlock *ScalarHeader;
4055
4056 /// Immutable list of VPIRBasicBlocks wrapping the exit blocks of the original
4057 /// scalar loop. Note that some exit blocks may be unreachable at the moment,
4058 /// e.g. if the scalar epilogue always executes.
4060
4061 /// Holds the VFs applicable to this VPlan.
4063
4064 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
4065 /// any UF.
4067
4068 /// Holds the name of the VPlan, for printing.
4069 std::string Name;
4070
4071 /// Represents the trip count of the original loop, for folding
4072 /// the tail.
4073 VPValue *TripCount = nullptr;
4074
4075 /// Represents the backedge taken count of the original loop, for folding
4076 /// the tail. It equals TripCount - 1.
4077 VPValue *BackedgeTakenCount = nullptr;
4078
4079 /// Represents the vector trip count.
4080 VPValue VectorTripCount;
4081
4082 /// Represents the vectorization factor of the loop.
4083 VPValue VF;
4084
4085 /// Represents the loop-invariant VF * UF of the vector loop region.
4086 VPValue VFxUF;
4087
4088 /// Holds a mapping between Values and their corresponding VPValue inside
4089 /// VPlan.
4090 Value2VPValueTy Value2VPValue;
4091
4092 /// Contains all the external definitions created for this VPlan. External
4093 /// definitions are VPValues that hold a pointer to their underlying IR.
4095
4096 /// Mapping from SCEVs to the VPValues representing their expansions.
4097 /// NOTE: This mapping is temporary and will be removed once all users have
4098 /// been modeled in VPlan directly.
4099 DenseMap<const SCEV *, VPValue *> SCEVToExpansion;
4100
4101 /// Blocks allocated and owned by the VPlan. They will be deleted once the
4102 /// VPlan is destroyed.
4103 SmallVector<VPBlockBase *> CreatedBlocks;
4104
4105 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
4106 /// wrapping the original header of the scalar loop.
4107 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
4108 : Entry(Entry), ScalarHeader(ScalarHeader) {
4109 Entry->setPlan(this);
4110 assert(ScalarHeader->getNumSuccessors() == 0 &&
4111 "scalar header must be a leaf node");
4112 }
4113
4114public:
4115 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
4116 /// original preheader and scalar header of \p L, to be used as entry and
4117 /// scalar header blocks of the new VPlan.
4118 VPlan(Loop *L);
4119
4120 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
4121 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
4122 VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
4123 setEntry(createVPBasicBlock("preheader"));
4124 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
4125 TripCount = TC;
4126 }
4127
4129
4131 Entry = VPBB;
4132 VPBB->setPlan(this);
4133 }
4134
4135 /// Generate the IR code for this VPlan.
4136 void execute(VPTransformState *State);
4137
4138 /// Return the cost of this plan.
4140
4141 VPBasicBlock *getEntry() { return Entry; }
4142 const VPBasicBlock *getEntry() const { return Entry; }
4143
4144 /// Returns the preheader of the vector loop region, if one exists, or null
4145 /// otherwise.
4147 VPRegionBlock *VectorRegion = getVectorLoopRegion();
4148 return VectorRegion
4149 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
4150 : nullptr;
4151 }
4152
4153 /// Returns the VPRegionBlock of the vector loop.
4156
4157 /// Returns the 'middle' block of the plan, that is the block that selects
4158 /// whether to execute the scalar tail loop or the exit block from the loop
4159 /// latch. If there is an early exit from the vector loop, the middle block
4160 /// conceptully has the early exit block as third successor, split accross 2
4161 /// VPBBs. In that case, the second VPBB selects whether to execute the scalar
4162 /// tail loop or the exit bock. If the scalar tail loop or exit block are
4163 /// known to always execute, the middle block may branch directly to that
4164 /// block. This function cannot be called once the vector loop region has been
4165 /// removed.
4167 VPRegionBlock *LoopRegion = getVectorLoopRegion();
4168 assert(
4169 LoopRegion &&
4170 "cannot call the function after vector loop region has been removed");
4171 auto *RegionSucc = cast<VPBasicBlock>(LoopRegion->getSingleSuccessor());
4172 if (RegionSucc->getSingleSuccessor() ||
4173 is_contained(RegionSucc->getSuccessors(), getScalarPreheader()))
4174 return RegionSucc;
4175 // There is an early exit. The successor of RegionSucc is the middle block.
4176 return cast<VPBasicBlock>(RegionSucc->getSuccessors()[1]);
4177 }
4178
4180 return const_cast<VPlan *>(this)->getMiddleBlock();
4181 }
4182
4183 /// Return the VPBasicBlock for the preheader of the scalar loop.
4185 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
4186 }
4187
4188 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
4189 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
4190
4191 /// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
4192 /// the original scalar loop.
4193 ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }
4194
4195 /// Return the VPIRBasicBlock corresponding to \p IRBB. \p IRBB must be an
4196 /// exit block.
4198
4199 /// Returns true if \p VPBB is an exit block.
4200 bool isExitBlock(VPBlockBase *VPBB);
4201
4202 /// The trip count of the original loop.
4204 assert(TripCount && "trip count needs to be set before accessing it");
4205 return TripCount;
4206 }
4207
4208 /// Set the trip count assuming it is currently null; if it is not - use
4209 /// resetTripCount().
4210 void setTripCount(VPValue *NewTripCount) {
4211 assert(!TripCount && NewTripCount && "TripCount should not be set yet.");
4212 TripCount = NewTripCount;
4213 }
4214
4215 /// Resets the trip count for the VPlan. The caller must make sure all uses of
4216 /// the original trip count have been replaced.
4217 void resetTripCount(VPValue *NewTripCount) {
4218 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
4219 "TripCount must be set when resetting");
4220 TripCount = NewTripCount;
4221 }
4222
4223 /// The backedge taken count of the original loop.
4225 if (!BackedgeTakenCount)
4226 BackedgeTakenCount = new VPValue();
4227 return BackedgeTakenCount;
4228 }
4229
4230 /// The vector trip count.
4231 VPValue &getVectorTripCount() { return VectorTripCount; }
4232
4233 /// Returns the VF of the vector loop region.
4234 VPValue &getVF() { return VF; };
4235
4236 /// Returns VF * UF of the vector loop region.
4237 VPValue &getVFxUF() { return VFxUF; }
4238
4241 }
4242
4243 void addVF(ElementCount VF) { VFs.insert(VF); }
4244
4246 assert(hasVF(VF) && "Cannot set VF not already in plan");
4247 VFs.clear();
4248 VFs.insert(VF);
4249 }
4250
4251 bool hasVF(ElementCount VF) const { return VFs.count(VF); }
4252 bool hasScalableVF() const {
4253 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
4254 }
4255
4256 /// Returns an iterator range over all VFs of the plan.
4259 return VFs;
4260 }
4261
4262 bool hasScalarVFOnly() const {
4263 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
4264 assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
4265 "Plan with scalar VF should only have a single VF");
4266 return HasScalarVFOnly;
4267 }
4268
4269 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
4270
4271 unsigned getUF() const {
4272 assert(UFs.size() == 1 && "Expected a single UF");
4273 return UFs[0];
4274 }
4275
4276 void setUF(unsigned UF) {
4277 assert(hasUF(UF) && "Cannot set the UF not already in plan");
4278 UFs.clear();
4279 UFs.insert(UF);
4280 }
4281
4282 /// Returns true if the VPlan already has been unrolled, i.e. it has a single
4283 /// concrete UF.
4284 bool isUnrolled() const { return UFs.size() == 1; }
4285
4286 /// Return a string with the name of the plan and the applicable VFs and UFs.
4287 std::string getName() const;
4288
4289 void setName(const Twine &newName) { Name = newName.str(); }
4290
4291 /// Gets the live-in VPValue for \p V or adds a new live-in (if none exists
4292 /// yet) for \p V.
4294 assert(V && "Trying to get or add the VPValue of a null Value");
4295 auto [It, Inserted] = Value2VPValue.try_emplace(V);
4296 if (Inserted) {
4297 VPValue *VPV = new VPValue(V);
4298 VPLiveIns.push_back(VPV);
4299 assert(VPV->isLiveIn() && "VPV must be a live-in.");
4300 It->second = VPV;
4301 }
4302
4303 assert(It->second->isLiveIn() && "Only live-ins should be in mapping");
4304 return It->second;
4305 }
4306
4307 /// Return a VPValue wrapping i1 true.
4309 LLVMContext &Ctx = getContext();
4311 }
4312
4313 /// Return a VPValue wrapping i1 false.
4315 LLVMContext &Ctx = getContext();
4317 }
4318
4319 /// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
4320 VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
4321
4322 /// Return the list of live-in VPValues available in the VPlan.
4324 assert(all_of(Value2VPValue,
4325 [this](const auto &P) {
4326 return is_contained(VPLiveIns, P.second);
4327 }) &&
4328 "all VPValues in Value2VPValue must also be in VPLiveIns");
4329 return VPLiveIns;
4330 }
4331
4332#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4333 /// Print the live-ins of this VPlan to \p O.
4334 void printLiveIns(raw_ostream &O) const;
4335
4336 /// Print this VPlan to \p O.
4337 void print(raw_ostream &O) const;
4338
4339 /// Print this VPlan in DOT format to \p O.
4340 void printDOT(raw_ostream &O) const;
4341
4342 /// Dump the plan to stderr (for debugging).
4343 LLVM_DUMP_METHOD void dump() const;
4344#endif
4345
4346 /// Returns the canonical induction recipe of the vector loop.
4349 if (EntryVPBB->empty()) {
4350 // VPlan native path.
4351 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
4352 }
4353 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
4354 }
4355
4356 VPValue *getSCEVExpansion(const SCEV *S) const {
4357 return SCEVToExpansion.lookup(S);
4358 }
4359
4360 void addSCEVExpansion(const SCEV *S, VPValue *V) {
4361 assert(!SCEVToExpansion.contains(S) && "SCEV already expanded");
4362 SCEVToExpansion[S] = V;
4363 }
4364
4365 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
4366 /// recipes to refer to the clones, and return it.
4367 VPlan *duplicate();
4368
4369 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
4370 /// present. The returned block is owned by the VPlan and deleted once the
4371 /// VPlan is destroyed.
4373 VPRecipeBase *Recipe = nullptr) {
4374 auto *VPB = new VPBasicBlock(Name, Recipe);
4375 CreatedBlocks.push_back(VPB);
4376 return VPB;
4377 }
4378
4379 /// Create a new VPRegionBlock with \p Entry, \p Exiting and \p Name. If \p
4380 /// IsReplicator is true, the region is a replicate region. The returned block
4381 /// is owned by the VPlan and deleted once the VPlan is destroyed.
4383 const std::string &Name = "",
4384 bool IsReplicator = false) {
4385 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, IsReplicator);
4386 CreatedBlocks.push_back(VPB);
4387 return VPB;
4388 }
4389
4390 /// Create a new loop VPRegionBlock with \p Name and entry and exiting blocks set
4391 /// to nullptr. The returned block is owned by the VPlan and deleted once the
4392 /// VPlan is destroyed.
4393 VPRegionBlock *createVPRegionBlock(const std::string &Name = "") {
4394 auto *VPB = new VPRegionBlock(Name);
4395 CreatedBlocks.push_back(VPB);
4396 return VPB;
4397 }
4398
4399 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
4400 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
4401 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
4403
4404 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
4405 /// instructions in \p IRBB, except its terminator which is managed by the
4406 /// successors of the block in VPlan. The returned block is owned by the VPlan
4407 /// and deleted once the VPlan is destroyed.
4409
4410 /// Returns true if the VPlan is based on a loop with an early exit. That is
4411 /// the case if the VPlan has either more than one exit block or a single exit
4412 /// block with multiple predecessors (one for the exit via the latch and one
4413 /// via the other early exit).
4414 bool hasEarlyExit() const {
4415 return count_if(ExitBlocks,
4416 [](VPIRBasicBlock *EB) { return EB->hasPredecessors(); }) >
4417 1 ||
4418 (ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
4419 }
4420
4421 /// Returns true if the scalar tail may execute after the vector loop. Note
4422 /// that this relies on unneeded branches to the scalar tail loop being
4423 /// removed.
4424 bool hasScalarTail() const {
4425 return !(!getScalarPreheader()->hasPredecessors() ||
4427 }
4428};
4429
4430#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4431inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
4432 Plan.print(OS);
4433 return OS;
4434}
4435#endif
4436
4437} // end namespace llvm
4438
4439#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
This file defines the DenseMap class.
Hexagon Common GEP
iv users
Definition IVUsers.cpp:48
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
#define I(x, y, z)
Definition MD5.cpp:58
mir Rename Register Operands
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
#define T
MachineInstr unsigned OpIdx
#define P(N)
static StringRef getName(Value *V)
const SmallVectorImpl< MachineOperand > & Cond
static bool mayHaveSideEffects(MachineInstr &MI)
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static const BasicSubtargetSubTypeKV * find(StringRef S, ArrayRef< BasicSubtargetSubTypeKV > A)
Find KV in array using binary search.
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
This file contains the declarations of the entities induced by Vectorization Plans,...
#define VP_CLASSOF_IMPL(VPDefID)
Definition VPlan.h:499
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:41
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361
LLVM Basic Block Representation.
Definition BasicBlock.h:62
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
Definition InstrTypes.h:448
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition InstrTypes.h:612
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:678
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
A debug info location.
Definition DebugLoc.h:124
static DebugLoc getUnknown()
Definition DebugLoc.h:162
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:165
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition Operator.h:200
Convenience struct for specifying and reasoning about fast-math flags.
Definition FMF.h:22
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
A struct for saving information about induction variables.
InductionKind
This enum represents the kinds of inductions that we support.
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
The group of interleaved loads/stores sharing the same stride and close to each other.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Metadata node.
Definition Metadata.h:1077
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
Definition ModRef.h:221
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition ModRef.h:218
Root of the metadata hierarchy.
Definition Metadata.h:63
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
This class represents an analyzed expression in the program.
This class represents the LLVM 'select' instruction.
This class provides computation of slot numbers for LLVM Assembly writing.
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:356
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
void execute(VPTransformState &State) override
Generate the active lane mask phi of the vector loop.
VPActiveLaneMaskPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3472
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition VPlan.h:3466
~VPActiveLaneMaskPHIRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:3751
RecipeListTy::const_iterator const_iterator
Definition VPlan.h:3779
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition VPlan.h:3826
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition VPlan.h:3781
RecipeListTy::iterator iterator
Instruction iterators...
Definition VPlan.h:3778
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition VPlan.h:3804
iplist< VPRecipeBase > RecipeListTy
Definition VPlan.h:3762
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition VPlan.h:3768
iterator end()
Definition VPlan.h:3788
iterator begin()
Recipe iterator methods.
Definition VPlan.h:3786
RecipeListTy::reverse_iterator reverse_iterator
Definition VPlan.h:3780
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:3839
const VPBasicBlock * getCFGPredecessor(unsigned Idx) const
Returns the predecessor block at index Idx with the predecessors as per the corresponding plain CFG.
Definition VPlan.cpp:807
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition VPlan.cpp:246
~VPBasicBlock() override
Definition VPlan.h:3772
const_reverse_iterator rbegin() const
Definition VPlan.h:3792
reverse_iterator rend()
Definition VPlan.h:3793
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition VPlan.h:3766
VPRecipeBase & back()
Definition VPlan.h:3801
const VPRecipeBase & front() const
Definition VPlan.h:3798
const_iterator begin() const
Definition VPlan.h:3787
VPRecipeBase & front()
Definition VPlan.h:3799
const VPRecipeBase & back() const
Definition VPlan.h:3800
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:3817
bool empty() const
Definition VPlan.h:3797
const_iterator end() const
Definition VPlan.h:3789
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3812
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition VPlan.h:3807
reverse_iterator rbegin()
Definition VPlan.h:3791
friend class VPlan
Definition VPlan.h:3752
size_t size() const
Definition VPlan.h:3796
const_reverse_iterator rend() const
Definition VPlan.h:3794
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2450
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition VPlan.h:2419
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition VPlan.h:2424
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition VPlan.h:2414
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2435
VPBlendRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2401
VPBlendRecipe(PHINode *Phi, ArrayRef< VPValue * > Operands, DebugLoc DL)
The blend operation is a User of the incoming values and of their respective masks,...
Definition VPlan.h:2396
void setMask(unsigned Idx, VPValue *V)
Set mask number Idx to V.
Definition VPlan.h:2430
bool isNormalized() const
A normalized blend is one that has an odd number of operands, whereby the first operand does not have...
Definition VPlan.h:2410
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:81
void setSuccessors(ArrayRef< VPBlockBase * > NewSuccs)
Set each VPBasicBlock in NewSuccss as successor of this VPBlockBase.
Definition VPlan.h:300
VPRegionBlock * getParent()
Definition VPlan.h:173
VPBlocksTy & getPredecessors()
Definition VPlan.h:205
iterator_range< VPBlockBase ** > predecessors()
Definition VPlan.h:202
LLVM_DUMP_METHOD void dump() const
Dump this VPBlockBase to dbgs().
Definition VPlan.h:377
void setName(const Twine &newName)
Definition VPlan.h:166
size_t getNumSuccessors() const
Definition VPlan.h:219
iterator_range< VPBlockBase ** > successors()
Definition VPlan.h:201
virtual void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const =0
Print plain-text dump of this VPBlockBase to O, prefixing all lines with Indent.
bool hasPredecessors() const
Returns true if this block has any predecessors.
Definition VPlan.h:223
void swapSuccessors()
Swap successors of the block. The block must have exactly 2 successors.
Definition VPlan.h:322
void printSuccessors(raw_ostream &O, const Twine &Indent) const
Print the successors of this block to O, prefixing all lines with Indent.
Definition VPlan.cpp:686
SmallVectorImpl< VPBlockBase * > VPBlocksTy
Definition VPlan.h:160
bool isLegalToHoistInto()
Return true if it is legal to hoist instructions into this block.
Definition VPlan.h:349
virtual ~VPBlockBase()=default
const VPBlocksTy & getHierarchicalPredecessors()
Definition VPlan.h:258
unsigned getIndexForSuccessor(const VPBlockBase *Succ) const
Returns the index for Succ in the blocks successor list.
Definition VPlan.h:335
size_t getNumPredecessors() const
Definition VPlan.h:220
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition VPlan.h:291
VPBlockBase * getEnclosingBlockWithPredecessors()
Definition VPlan.cpp:212
unsigned getIndexForPredecessor(const VPBlockBase *Pred) const
Returns the index for Pred in the blocks predecessors list.
Definition VPlan.h:328
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:204
virtual VPBlockBase * clone()=0
Clone the current block and it's recipes without updating the operands of the cloned recipes,...
enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC } VPBlockTy
An enumeration for keeping track of the concrete subclass of VPBlockBase that are actually instantiat...
Definition VPlan.h:158
virtual InstructionCost cost(ElementCount VF, VPCostContext &Ctx)=0
Return the cost of the block.
void setPlan(VPlan *ParentPlan)
Sets the pointer of the plan containing the block.
Definition VPlan.cpp:184
const VPRegionBlock * getParent() const
Definition VPlan.h:174
const std::string & getName() const
Definition VPlan.h:164
void clearSuccessors()
Remove all the successors of this block.
Definition VPlan.h:310
VPBlockBase * getSingleHierarchicalSuccessor()
Definition VPlan.h:248
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
Definition VPlan.h:282
VPBlockBase * getSinglePredecessor() const
Definition VPlan.h:215
virtual void execute(VPTransformState *State)=0
The method which generates the output IR that correspond to this VPBlockBase, thereby "executing" the...
const VPBlocksTy & getHierarchicalSuccessors()
Definition VPlan.h:242
void clearPredecessors()
Remove all the predecessor of this block.
Definition VPlan.h:307
friend class VPBlockUtils
Definition VPlan.h:82
unsigned getVPBlockID() const
Definition VPlan.h:171
void printAsOperand(raw_ostream &OS, bool PrintType=false) const
Definition VPlan.h:356
void swapPredecessors()
Swap predecessors of the block.
Definition VPlan.h:314
VPBlockBase(const unsigned char SC, const std::string &N)
Definition VPlan.h:150
VPBlocksTy & getSuccessors()
Definition VPlan.h:199
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
Definition VPlan.cpp:204
const VPBasicBlock * getEntryBasicBlock() const
Definition VPlan.cpp:170
void setOneSuccessor(VPBlockBase *Successor)
Set a given VPBlockBase Successor as the single successor of this VPBlockBase.
Definition VPlan.h:271
void setParent(VPRegionBlock *P)
Definition VPlan.h:184
VPBlockBase * getSingleHierarchicalPredecessor()
Definition VPlan.h:264
VPBlockBase * getSingleSuccessor() const
Definition VPlan.h:209
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:198
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Definition VPlan.h:2942
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2926
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2950
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
Definition VPlan.h:2923
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3407
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:3446
~VPCanonicalIVPHIRecipe() override=default
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3414
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
Definition VPlan.h:3409
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3439
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:3434
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3422
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPCanonicalIVPHIRecipe.
Definition VPlan.h:3453
This class augments a recipe with a set of VPValues defined by the recipe.
Definition VPlanValue.h:300
friend class VPValue
Definition VPlanValue.h:301
VPDef(const unsigned char SC)
Definition VPlanValue.h:380
void execute(VPTransformState &State) override
Generate the transformed value of the induction at offset StartValue (1.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPDerivedIVRecipe.
Definition VPlan.h:3611
VPValue * getStepValue() const
Definition VPlan.h:3628
Type * getScalarType() const
Definition VPlan.h:3623
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3599
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3591
~VPDerivedIVRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3631
VPValue * getStartValue() const
Definition VPlan.h:3627
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3583
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPEVLBasedIVPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3502
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3508
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition VPlan.h:3514
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition VPlan.h:3497
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3521
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:3383
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
Definition VPlan.h:3388
VPExpandSCEVRecipe(const SCEV *Expr)
Definition VPlan.h:3374
const SCEV * getSCEV() const
Definition VPlan.h:3400
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpandSCEVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3379
~VPExpandSCEVRecipe() override=default
void execute(VPTransformState &State) override
Method for generating code, must not be called as this recipe is abstract.
Definition VPlan.h:3051
VPValue * getOperandOfResultType() const
Return the VPValue to use to infer the result type of the recipe.
Definition VPlan.h:3038
VPExpressionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3020
void decompose()
Insert the recipes of the expression back into the VPlan, directly before the current recipe.
~VPExpressionRecipe() override
Definition VPlan.h:3011
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpressionRecipe(VPWidenCastRecipe *Ext, VPReductionRecipe *Red)
Definition VPlan.h:3002
bool mayHaveSideEffects() const
Returns true if this expression contains recipes that may have side effects.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Compute the cost of this recipe either using a recipe's specialized implementation or using the legac...
bool mayReadOrWriteMemory() const
Returns true if this expression contains recipes that may read from or write to memory.
VPExpressionRecipe(VPWidenCastRecipe *Ext0, VPWidenCastRecipe *Ext1, VPWidenRecipe *Mul, VPReductionRecipe *Red)
Definition VPlan.h:3006
VPExpressionRecipe(VPWidenRecipe *Mul, VPReductionRecipe *Red)
Definition VPlan.h:3004
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this header phi recipe.
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:1971
static bool classof(const VPValue *V)
Definition VPlan.h:1981
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override=0
Print the recipe.
virtual VPValue * getBackedgeValue()
Returns the incoming value from the loop backedge.
Definition VPlan.h:2012
void setBackedgeValue(VPValue *V)
Update the incoming value from the loop backedge.
Definition VPlan.h:2017
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition VPlan.h:2001
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition VPlan.h:2009
VPValue * getStartValue() const
Definition VPlan.h:2004
static bool classof(const VPRecipeBase *B)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:1977
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition VPlan.h:2021
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, VPValue *Start, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1966
~VPHeaderPHIRecipe() override=default
void execute(VPTransformState &State) override
Produce a vectorized histogram operation.
VP_CLASSOF_IMPL(VPDef::VPHistogramSC)
VPHistogramRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1690
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHistogramRecipe.
VPValue * getMask() const
Return the mask operand if one was provided, or a null pointer if all lanes should be executed uncond...
Definition VPlan.h:1707
unsigned getOpcode() const
Definition VPlan.h:1703
VPHistogramRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1684
~VPHistogramRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
A special type of VPBasicBlock that wraps an existing IR basic block.
Definition VPlan.h:3904
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition VPlan.cpp:487
BasicBlock * getIRBasicBlock() const
Definition VPlan.h:3928
~VPIRBasicBlock() override
Definition VPlan.h:3916
static bool classof(const VPBlockBase *V)
Definition VPlan.h:3918
friend class VPlan
Definition VPlan.h:3905
VPIRBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition VPlan.cpp:512
Class to record and manage LLVM IR flags.
Definition VPlan.h:600
FastMathFlagsTy FMFs
Definition VPlan.h:664
bool flagsValidForOpcode(unsigned Opcode) const
Returns true if the set flags are valid for Opcode.
VPIRFlags(DisjointFlagsTy DisjointFlags)
Definition VPlan.h:710
VPIRFlags(WrapFlagsTy WrapFlags)
Definition VPlan.h:705
WrapFlagsTy WrapFlags
Definition VPlan.h:658
CmpInst::Predicate CmpPredicate
Definition VPlan.h:657
void printFlags(raw_ostream &O) const
GEPNoWrapFlags GEPFlags
Definition VPlan.h:662
bool hasFastMathFlags() const
Returns true if the recipe has fast-math flags.
Definition VPlan.h:819
LLVM_ABI_FOR_TEST FastMathFlags getFastMathFlags() const
TruncFlagsTy TruncFlags
Definition VPlan.h:659
CmpInst::Predicate getPredicate() const
Definition VPlan.h:801
bool hasNonNegFlag() const
Returns true if the recipe has non-negative flag.
Definition VPlan.h:824
void transferFlags(VPIRFlags &Other)
Definition VPlan.h:719
ExactFlagsTy ExactFlags
Definition VPlan.h:661
bool hasNoSignedWrap() const
Definition VPlan.h:843
void intersectFlags(const VPIRFlags &Other)
Only keep flags also present in Other.
bool isDisjoint() const
Definition VPlan.h:854
VPIRFlags(FastMathFlags FMFs)
Definition VPlan.h:708
VPIRFlags(NonNegFlagsTy NonNegFlags)
Definition VPlan.h:713
VPIRFlags(CmpInst::Predicate Pred)
Definition VPlan.h:702
bool isNonNeg() const
Definition VPlan.h:826
GEPNoWrapFlags getGEPNoWrapFlags() const
Definition VPlan.h:813
bool hasPredicate() const
Returns true if the recipe has a comparison predicate.
Definition VPlan.h:816
DisjointFlagsTy DisjointFlags
Definition VPlan.h:660
unsigned AllFlags
Definition VPlan.h:665
void setPredicate(CmpInst::Predicate Pred)
Definition VPlan.h:807
bool hasNoUnsignedWrap() const
Definition VPlan.h:832
NonNegFlagsTy NonNegFlags
Definition VPlan.h:663
void dropPoisonGeneratingFlags()
Drop all poison-generating flags.
Definition VPlan.h:729
void applyFlags(Instruction &I) const
Apply the IR flags to I.
Definition VPlan.h:764
VPIRFlags(GEPNoWrapFlags GEPFlags)
Definition VPlan.h:716
VPIRFlags(Instruction &I)
Definition VPlan.h:671
Instruction & getInstruction() const
Definition VPlan.h:1373
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first part of operand Op.
Definition VPlan.h:1387
~VPIRInstruction() override=default
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
void extractLastLaneOfFirstOperand(VPBuilder &Builder)
Update the recipes first operand to the last lane of the operand using Builder.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1393
VPIRInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1360
static LLVM_ABI_FOR_TEST VPIRInstruction * create(Instruction &I)
Create a new VPIRPhi for \I , if it is a PHINode, otherwise create a VPIRInstruction.
LLVM_ABI_FOR_TEST InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPIRInstruction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool usesScalars(const VPValue *Op) const override
Returns true if the VPUser uses scalars of operand Op.
Definition VPlan.h:1381
VPIRInstruction(Instruction &I)
VPIRInstruction::create() should be used to create VPIRInstructions, as subclasses may need to be cre...
Definition VPlan.h:1348
Helper to manage IR metadata for recipes.
Definition VPlan.h:940
VPIRMetadata(Instruction &I)
Adds metatadata that can be preserved from the original instruction I.
Definition VPlan.h:948
void intersect(const VPIRMetadata &MD)
Intersect this VPIRMetada object with MD, keeping only metadata nodes that are common to both.
VPIRMetadata & operator=(const VPIRMetadata &Other)
Definition VPlan.h:957
VPIRMetadata(const VPIRMetadata &Other)
Copy constructor for cloning.
Definition VPlan.h:955
void addMetadata(unsigned Kind, MDNode *Node)
Add metadata with kind Kind and Node.
Definition VPlan.h:966
void applyMetadata(Instruction &I) const
Add all metadata to I.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInstruction.
Definition VPlan.h:1229
static bool classof(const VPUser *R)
Definition VPlan.h:1213
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:1195
Type * getResultType() const
Definition VPlan.h:1235
VPInstructionWithType(unsigned Opcode, ArrayRef< VPValue * > Operands, Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL, const Twine &Name="")
Definition VPlan.h:1190
VPInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1217
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the instruction.
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:981
VPInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
Definition VPlan.h:1098
VPInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1109
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1058
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
Definition VPlan.h:1014
@ WideIVStep
Scale the first operand (vector step) by the second operand (scalar-step).
Definition VPlan.h:1048
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1061
@ FirstOrderRecurrenceSplice
Definition VPlan.h:987
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1052
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1011
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1008
@ VScale
Returns the value for vscale.
Definition VPlan.h:1063
@ CanonicalIVIncrementForPart
Definition VPlan.h:1001
@ CalculateTripCountMinusVF
Definition VPlan.h:999
bool hasResult() const
Definition VPlan.h:1137
StringRef getName() const
Returns the symbolic name assigned to the VPInstruction.
Definition VPlan.h:1177
unsigned getOpcode() const
Definition VPlan.h:1117
friend class VPlanSlp
Definition VPlan.h:982
virtual unsigned getNumStoreOperands() const =0
Returns the number of stored operands of this interleave group.
bool needsMaskForGaps() const
Return true if the access needs a mask because of the gaps.
Definition VPlan.h:2529
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2535
static bool classof(const VPUser *U)
Definition VPlan.h:2511
virtual bool onlyFirstLaneUsed(const VPValue *Op) const override=0
Returns true if the recipe only uses the first lane of operand Op.
VPInterleaveBase(const unsigned char SC, const InterleaveGroup< Instruction > *IG, ArrayRef< VPValue * > Operands, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Definition VPlan.h:2478
Instruction * getInsertPos() const
Definition VPlan.h:2533
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2506
const InterleaveGroup< Instruction > * getInterleaveGroup() const
Definition VPlan.h:2531
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:2523
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition VPlan.h:2552
VPInterleaveBase * clone() override=0
Clone the current recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:2517
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2626
~VPInterleaveEVLRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
The recipe only uses the first lane of the address, and EVL operand.
Definition VPlan.h:2638
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2645
VPInterleaveEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2619
VPInterleaveEVLRecipe(VPInterleaveRecipe &R, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:2606
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition VPlan.h:2563
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2596
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2590
~VPInterleaveRecipe() override=default
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2573
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Definition VPlan.h:2565
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
Definition VPlan.h:2748
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned ScaleFactor, Instruction *ReductionInst=nullptr)
Definition VPlan.h:2752
~VPPartialReductionRecipe() override=default
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2786
void execute(VPTransformState &State) override
Generate the reduction in the loop.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPartialReductionRecipe.
unsigned getOpcode() const
Get the binary op's opcode.
Definition VPlan.h:2783
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2767
Helper type to provide functions to access incoming values and blocks for phi-like recipes.
Definition VPlan.h:1246
virtual const VPRecipeBase * getAsRecipe() const =0
Return a VPRecipeBase* to the current object.
VPUser::const_operand_range incoming_values() const
Returns an interator range over the incoming values.
Definition VPlan.h:1268
virtual unsigned getNumIncoming() const
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:1263
void removeIncomingValueFor(VPBlockBase *IncomingBlock) const
Removes the incoming value for IncomingBlock, which must be a predecessor.
const VPBasicBlock * getIncomingBlock(unsigned Idx) const
Returns the incoming block with index Idx.
Definition VPlan.h:3895
detail::zippy< llvm::detail::zip_first, VPUser::const_operand_range, const_incoming_blocks_range > incoming_values_and_blocks() const
Returns an iterator range over pairs of incoming values and corresponding incoming blocks.
Definition VPlan.h:1288
VPValue * getIncomingValue(unsigned Idx) const
Returns the incoming VPValue with index Idx.
Definition VPlan.h:1255
virtual ~VPPhiAccessors()=default
void printPhiOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the recipe.
iterator_range< mapped_iterator< detail::index_iterator, std::function< const VPBasicBlock *(size_t)> > > const_incoming_blocks_range
Definition VPlan.h:1273
const_incoming_blocks_range incoming_blocks() const
Returns an iterator range over the incoming blocks.
Definition VPlan.h:1277
~VPPredInstPHIRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:3110
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3086
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
Definition VPlan.h:3097
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition VPlan.h:3082
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:394
bool mayReadFromMemory() const
Returns true if the recipe may read from memory.
bool mayReadOrWriteMemory() const
Returns true if the recipe may read from or write to memory.
Definition VPlan.h:477
void setDebugLoc(DebugLoc NewDL)
Set the recipe's debug location to NewDL.
Definition VPlan.h:488
bool mayWriteToMemory() const
Returns true if the recipe may write to memory.
virtual ~VPRecipeBase()=default
VPBasicBlock * getParent()
Definition VPlan.h:415
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
Definition VPlan.h:482
virtual void execute(VPTransformState &State)=0
The method which generates the output IR instructions that correspond to this VPRecipe,...
void moveBefore(VPBasicBlock &BB, iplist< VPRecipeBase >::iterator I)
Unlink this recipe and insert into BB before I.
void insertBefore(VPRecipeBase *InsertPos)
Insert an unlinked recipe into a basic block immediately before the specified recipe.
void insertAfter(VPRecipeBase *InsertPos)
Insert an unlinked Recipe into a basic block immediately after the specified Recipe.
static bool classof(const VPDef *D)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:457
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
virtual VPRecipeBase * clone()=0
Clone the current recipe.
friend class VPBlockUtils
Definition VPlan.h:396
const VPBasicBlock * getParent() const
Definition VPlan.h:416
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this recipe, taking into account if the cost computation should be skipped and the...
static bool classof(const VPUser *U)
Definition VPlan.h:462
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
void moveAfter(VPRecipeBase *MovePos)
Unlink this recipe from its current VPBasicBlock and insert it into the VPBasicBlock that MovePos liv...
VPRecipeBase(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:405
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2831
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2828
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2801
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2812
~VPReductionEVLRecipe() override=default
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition VPlan.h:2375
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2344
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2358
~VPReductionPHIRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2381
VPReductionPHIRecipe(PHINode *Phi, RecurKind Kind, VPValue &Start, bool IsInLoop=false, bool IsOrdered=false, unsigned VFScaleFactor=1)
Create a new VPReductionPHIRecipe for the reduction Phi.
Definition VPlan.h:2334
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2369
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
Definition VPlan.h:2378
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
RecurKind getRecurrenceKind() const
Returns the recurrence kind of the reduction.
Definition VPlan.h:2372
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition VPlan.h:2653
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition VPlan.h:2725
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2697
VPReductionRecipe(const RecurKind RdxKind, FastMathFlags FMFs, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2682
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition VPlan.h:2729
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition VPlan.h:2731
RecurKind getRecurrenceKind() const
Return the recurrence kind for the in-loop reduction.
Definition VPlan.h:2721
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition VPlan.h:2723
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition VPlan.h:2727
VPReductionRecipe(RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2675
VPReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2691
VPReductionRecipe(const unsigned char SC, RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
Definition VPlan.h:2661
static bool classof(const VPUser *U)
Definition VPlan.h:2702
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:3939
const VPBlockBase * getEntry() const
Definition VPlan.h:3975
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4007
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition VPlan.h:3992
VPBlockBase * getExiting()
Definition VPlan.h:3988
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition VPlan.h:3980
const VPBlockBase * getExiting() const
Definition VPlan.h:3987
VPBlockBase * getEntry()
Definition VPlan.h:3976
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition VPlan.h:4000
~VPRegionBlock() override
Definition VPlan.h:3968
friend class VPlan
Definition VPlan.h:3940
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3971
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2843
VPReplicateRecipe(Instruction *I, ArrayRef< VPValue * > Operands, bool IsSingleScalar, VPValue *Mask=nullptr, VPIRMetadata Metadata={})
Definition VPlan.h:2851
bool isSingleScalar() const
Definition VPlan.h:2888
~VPReplicateRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2893
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2900
bool isPredicated() const
Definition VPlan.h:2890
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2863
unsigned getOpcode() const
Definition VPlan.h:2917
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition VPlan.h:2912
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3696
VPValue * getStepValue() const
Definition VPlan.h:3693
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition VPlan.h:3681
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step, VPValue *VF, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:3652
bool isPart0() const
Return true if this VPScalarIVStepsRecipe corresponds to part 0.
Definition VPlan.h:3673
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3664
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, VPValue *VF, Instruction::BinaryOps Opcode, FastMathFlags FMFs, DebugLoc DL)
Definition VPlan.h:3645
~VPScalarIVStepsRecipe() override=default
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition VPlan.h:521
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, Value *UV, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:527
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
Definition VPlan.h:586
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:531
const Instruction * getUnderlyingInstr() const
Definition VPlan.h:589
static bool classof(const VPUser *U)
Definition VPlan.h:578
LLVM_DUMP_METHOD void dump() const
Print this VPSingleDefRecipe to dbgs() (for debugging).
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:523
virtual VPSingleDefRecipe * clone() override=0
Clone the current recipe.
This class can be used to assign names to VPValues.
Helper to access the operand that contains the unroll part for this recipe after unrolling.
Definition VPlan.h:928
VPValue * getUnrollPartOperand(const VPUser &U) const
Return the VPValue operand containing the unroll part or null if there is no such operand.
unsigned getUnrollPart(const VPUser &U) const
Return the unroll part.
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:197
void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the operands to O.
Definition VPlan.cpp:1443
operand_range operands()
Definition VPlanValue.h:265
void setOperand(unsigned I, VPValue *New)
Definition VPlanValue.h:241
unsigned getNumOperands() const
Definition VPlanValue.h:235
operand_iterator op_end()
Definition VPlanValue.h:263
VPValue * getOperand(unsigned N) const
Definition VPlanValue.h:236
VPUser(ArrayRef< VPValue * > Operands)
Definition VPlanValue.h:216
iterator_range< const_operand_iterator > const_operand_range
Definition VPlanValue.h:259
iterator_range< operand_iterator > operand_range
Definition VPlanValue.h:258
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition VPlan.cpp:135
friend class VPExpressionRecipe
Definition VPlanValue.h:53
Value * getLiveInIRValue() const
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition VPlanValue.h:174
friend class VPDef
Definition VPlanValue.h:49
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
Definition VPlanValue.h:85
VPValue(const unsigned char SC, Value *UV=nullptr, VPDef *Def=nullptr)
Definition VPlan.cpp:98
void setUnderlyingValue(Value *Val)
Definition VPlanValue.h:184
unsigned getNumUsers() const
Definition VPlanValue.h:113
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition VPlanValue.h:169
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:1867
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1853
VPVectorEndPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1874
const VPValue * getVFValue() const
Definition VPlan.h:1849
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPVectorPointerRecipe.
Definition VPlan.h:1860
VPVectorEndPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1838
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool isFirstPart() const
Return true if this VPVectorPointerRecipe corresponds to part 0.
Definition VPlan.h:1924
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1893
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:1910
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1903
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition VPlan.h:1927
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1917
const_operand_range args() const
Definition VPlan.h:1665
VPWidenCallRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1646
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1633
operand_range args()
Definition VPlan.h:1664
Function * getCalledScalarFunction() const
Definition VPlan.h:1660
~VPWidenCallRecipe() override=default
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with start = {<Part*VF,...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPWidenCanonicalIVRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCanonicalIVPHIRecipe.
Definition VPlan.h:3556
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3543
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition VPlan.h:3538
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1480
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, CastInst &UI)
Definition VPlan.h:1488
Instruction::CastOps getOpcode() const
Definition VPlan.h:1530
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, const VPIRFlags &Flags={}, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1496
Type * getResultType() const
Returns the result type of the cast.
Definition VPlan.h:1533
void execute(VPTransformState &State) override
Produce widened copies of the cast.
~VPWidenCastRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCastRecipe.
VPWidenCastRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1507
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1816
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1782
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition VPlan.h:1803
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1792
~VPWidenGEPRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2091
static bool classof(const VPValue *V)
Definition VPlan.h:2045
void setStepValue(VPValue *V)
Update the step value of the recipe.
Definition VPlan.h:2061
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition VPlan.h:2076
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2069
PHINode * getPHINode() const
Definition VPlan.h:2071
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2033
VPValue * getStepValue()
Returns the step value of the induction.
Definition VPlan.h:2057
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition VPlan.h:2074
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition VPlan.h:2083
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2040
static bool classof(const VPHeaderPHIRecipe *R)
Definition VPlan.h:2050
const VPValue * getVFValue() const
Definition VPlan.h:2064
const VPValue * getStepValue() const
Definition VPlan.h:2058
virtual void execute(VPTransformState &State) override=0
Generate the phi nodes.
const TruncInst * getTruncInst() const
Definition VPlan.h:2169
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:2144
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
Definition VPlan.h:2120
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2136
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition VPlan.h:2168
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2111
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition VPlan.h:2185
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2164
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:2177
bool isCanonical() const
Returns true if the induction is canonical, i.e.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1563
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
Definition VPlan.h:1598
bool mayReadFromMemory() const
Returns true if the intrinsic may read from memory.
Definition VPlan.h:1607
StringRef getIntrinsicName() const
Return to name of the intrinsic as string.
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1554
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
Definition VPlan.h:1613
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1580
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
Definition VPlan.h:1610
~VPWidenIntrinsicRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Return the scalar return type of the intrinsic.
Definition VPlan.h:1601
void execute(VPTransformState &State) override
Produce a widened version of the vector intrinsic.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this vector intrinsic.
bool IsMasked
Whether the memory access is masked.
Definition VPlan.h:3131
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition VPlan.h:3128
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition VPlan.h:3168
static bool classof(const VPUser *U)
Definition VPlan.h:3162
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition VPlan.h:3188
Instruction & Ingredient
Definition VPlan.h:3122
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3151
Instruction & getIngredient() const
Definition VPlan.h:3196
bool Consecutive
Whether the accessed addresses are consecutive.
Definition VPlan.h:3125
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:3155
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:3182
bool isMasked() const
Returns true if the recipe is masked.
Definition VPlan.h:3178
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3141
void setMask(VPValue *Mask)
Definition VPlan.h:3133
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:3175
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition VPlan.h:3172
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:2245
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start=nullptr, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
Create a new VPWidenPHIRecipe for Phi with start value Start and debug location DL.
Definition VPlan.h:2250
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2258
~VPWidenPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2209
~VPWidenPointerInductionRecipe() override=default
bool onlyScalarsGenerated(bool IsScalable)
Returns true if only scalar values will be generated.
void execute(VPTransformState &State) override
Generate vector values for the pointer induction.
Definition VPlan.h:2219
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step, VPValue *NumUnrolledElems, const InductionDescriptor &IndDesc, bool IsScalarAfterVectorization, DebugLoc DL)
Create a new VPWidenPointerInductionRecipe for Phi with start value Start and the number of elements ...
Definition VPlan.h:2197
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1437
VPWidenRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1453
VPWidenRecipe(Instruction &I, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1447
VPWidenRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:1441
~VPWidenRecipe() override=default
unsigned getOpcode() const
Definition VPlan.h:1470
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
Definition VPlanSLP.h:74
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4042
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition VPlan.cpp:1129
friend class VPSlotTracker
Definition VPlan.h:4044
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition VPlan.cpp:1105
bool hasVF(ElementCount VF) const
Definition VPlan.h:4251
LLVMContext & getContext() const
Definition VPlan.h:4239
VPBasicBlock * getEntry()
Definition VPlan.h:4141
VPRegionBlock * createVPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting, const std::string &Name="", bool IsReplicator=false)
Create a new VPRegionBlock with Entry, Exiting and Name.
Definition VPlan.h:4382
VPValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4231
void setName(const Twine &newName)
Definition VPlan.h:4289
bool hasScalableVF() const
Definition VPlan.h:4252
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:4237
VPValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4234
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4203
VPValue * getTrue()
Return a VPValue wrapping i1 true.
Definition VPlan.h:4308
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition VPlan.h:4224
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition VPlan.h:4258
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
Definition VPlan.h:4122
VPIRBasicBlock * getExitBlock(BasicBlock *IRBB) const
Return the VPIRBasicBlock corresponding to IRBB.
Definition VPlan.cpp:937
LLVM_ABI_FOR_TEST ~VPlan()
Definition VPlan.cpp:914
bool isExitBlock(VPBlockBase *VPBB)
Returns true if VPBB is an exit block.
Definition VPlan.cpp:945
const VPBasicBlock * getEntry() const
Definition VPlan.h:4142
friend class VPlanPrinter
Definition VPlan.h:4043
unsigned getUF() const
Definition VPlan.h:4271
VPRegionBlock * createVPRegionBlock(const std::string &Name="")
Create a new loop VPRegionBlock with Name and entry and exiting blocks set to nullptr.
Definition VPlan.h:4393
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
Definition VPlan.cpp:1243
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition VPlan.h:4360
bool hasUF(unsigned UF) const
Definition VPlan.h:4269
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
Definition VPlan.h:4193
void setVF(ElementCount VF)
Definition VPlan.h:4245
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
Definition VPlan.h:4284
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1034
bool hasEarlyExit() const
Returns true if the VPlan is based on a loop with an early exit.
Definition VPlan.h:4414
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition VPlan.cpp:1016
const VPBasicBlock * getMiddleBlock() const
Definition VPlan.h:4179
void setTripCount(VPValue *NewTripCount)
Set the trip count assuming it is currently null; if it is not - use resetTripCount().
Definition VPlan.h:4210
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition VPlan.h:4217
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition VPlan.h:4166
void setEntry(VPBasicBlock *VPBB)
Definition VPlan.h:4130
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition VPlan.h:4372
LLVM_ABI_FOR_TEST VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
Definition VPlan.cpp:1249
VPValue * getFalse()
Return a VPValue wrapping i1 false.
Definition VPlan.h:4314
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:4293
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition VPlan.cpp:1135
bool hasScalarVFOnly() const
Definition VPlan.h:4262
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4184
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
Definition VPlan.cpp:952
ArrayRef< VPValue * > getLiveIns() const
Return the list of live-in VPValues available in the VPlan.
Definition VPlan.h:4323
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition VPlan.h:4347
void print(raw_ostream &O) const
Print this VPlan to O.
Definition VPlan.cpp:1088
void addVF(ElementCount VF)
Definition VPlan.h:4243
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition VPlan.h:4189
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
Definition VPlan.h:4320
VPValue * getSCEVExpansion(const SCEV *S) const
Definition VPlan.h:4356
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition VPlan.cpp:1050
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition VPlan.h:4146
void setUF(unsigned UF)
Definition VPlan.h:4276
bool hasScalarTail() const
Returns true if the scalar tail may execute after the vector loop.
Definition VPlan.h:4424
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition VPlan.cpp:1176
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
Increasing range of size_t indices.
Definition STLExtras.h:2407
base_list_type::const_reverse_iterator const_reverse_iterator
Definition ilist.h:125
base_list_type::reverse_iterator reverse_iterator
Definition ilist.h:123
base_list_type::const_iterator const_iterator
Definition ilist.h:122
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
Definition ilist.h:328
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
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:310
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition STLExtras.h:823
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1733
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:1707
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
Definition STLExtras.h:833
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2454
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
LLVM_ABI void getMetadataToPropagate(Instruction *Inst, SmallVectorImpl< std::pair< unsigned, MDNode * > > &Metadata)
Add metadata from Inst to Metadata, if it can be preserved after vectorization.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto cast_or_null(const Y &Val)
Definition Casting.h:720
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:296
auto map_range(ContainerTy &&C, FuncTy F)
Definition STLExtras.h:358
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:759
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:1714
auto reverse(ContainerTy &&C)
Definition STLExtras.h:400
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
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:548
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
Definition STLExtras.h:317
@ Other
Any other memory.
Definition ModRef.h:68
RecurKind
These are the kinds of recurrences that we support.
@ Mul
Product of integers.
@ Add
Sum of integers.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition STLExtras.h:1936
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:1943
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:565
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1879
DenseMap< Value *, VPValue * > Value2VPValueTy
Definition VPlanValue.h:190
std::unique_ptr< VPlan > VPlanPtr
Definition VPlan.h:77
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:853
#define N
Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the recipe types implementing...
Definition VPlan.h:3714
static VPPhiAccessors * doCastIfPossible(SrcTy f)
doCastIfPossible is used by dyn_cast<>.
Definition VPlan.h:3735
CastInfo< VPPhiAccessors, SrcTy > Self
Definition VPlan.h:3716
static VPPhiAccessors * doCast(SrcTy R)
doCast is used by cast<>.
Definition VPlan.h:3719
This struct provides a method for customizing the way a cast is performed.
Definition Casting.h:476
static bool isPossible(const VPRecipeBase *f)
Definition VPlan.h:3706
This struct provides a way to check if a given cast is possible.
Definition Casting.h:253
static bool isPossible(const SrcTy &f)
Definition Casting.h:254
Struct to hold various analysis needed for cost computations.
void execute(VPTransformState &State) override
Generate the phi nodes.
VPFirstOrderRecurrencePHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2289
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
Definition VPlan.h:2284
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this first-order recurrence phi recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2307
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
DisjointFlagsTy(bool IsDisjoint)
Definition VPlan.h:630
NonNegFlagsTy(bool IsNonNeg)
Definition VPlan.h:635
TruncFlagsTy(bool HasNUW, bool HasNSW)
Definition VPlan.h:625
WrapFlagsTy(bool HasNUW, bool HasNSW)
Definition VPlan.h:618
PHINode & getIRPhi()
Definition VPlan.h:1418
VPIRPhi(PHINode &PN)
Definition VPlan.h:1411
static bool classof(const VPRecipeBase *U)
Definition VPlan.h:1413
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:1429
static bool classof(const VPUser *U)
Definition VPlan.h:1306
VPPhi * clone() override
Clone the current recipe.
Definition VPlan.h:1321
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:1336
VPPhi(ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
Definition VPlan.h:1303
static bool classof(const VPSingleDefRecipe *SDR)
Definition VPlan.h:1316
static bool classof(const VPValue *V)
Definition VPlan.h:1311
A pure-virtual common base class for recipes defining a single VPValue and using IR flags.
Definition VPlan.h:872
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:886
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, Instruction &I)
Definition VPlan.h:877
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:881
virtual VPRecipeWithIRFlags * clone() override=0
Clone the current recipe.
std::optional< InstructionCost > getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF, VPCostContext &Ctx) const
Compute the cost for this recipe for VF, using Opcode and Ctx.
static bool classof(const VPValue *V)
Definition VPlan.h:906
static bool classof(const VPSingleDefRecipe *U)
Definition VPlan.h:913
void execute(VPTransformState &State) override=0
The method which generates the output IR instructions that correspond to this VPRecipe,...
static bool classof(const VPUser *U)
Definition VPlan.h:901
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:873
VPTransformState holds information passed down when "executing" a VPlan, needed for generating the ou...
void execute(VPTransformState &State) override
Generate the wide load or gather.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenLoadEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition VPlan.h:3255
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue *Addr, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:3243
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3271
A recipe for widening load operations, using the address to load from and an optional mask.
Definition VPlan.h:3202
VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3230
void execute(VPTransformState &State) override
Generate a wide load or gather.
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3203
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3212
bool isInvariantCond() const
Definition VPlan.h:1753
VPWidenSelectRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1727
VPWidenSelectRecipe(SelectInst &I, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1721
VPValue * getCond() const
Definition VPlan.h:1749
unsigned getOpcode() const
Definition VPlan.h:1747
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1758
~VPWidenSelectRecipe() override=default
VPValue * getStoredValue() const
Return the address accessed by this recipe.
Definition VPlan.h:3336
void execute(VPTransformState &State) override
Generate the wide store or scatter.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3355
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue *Addr, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:3325
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition VPlan.h:3339
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition VPlan.h:3282
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3312
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition VPlan.h:3300
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3291
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3283