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 /// Drop all poison-generating flags.
726 // NOTE: This needs to be kept in-sync with
727 // Instruction::dropPoisonGeneratingFlags.
728 switch (OpType) {
729 case OperationType::OverflowingBinOp:
730 WrapFlags.HasNUW = false;
731 WrapFlags.HasNSW = false;
732 break;
733 case OperationType::Trunc:
734 TruncFlags.HasNUW = false;
735 TruncFlags.HasNSW = false;
736 break;
737 case OperationType::DisjointOp:
738 DisjointFlags.IsDisjoint = false;
739 break;
740 case OperationType::PossiblyExactOp:
741 ExactFlags.IsExact = false;
742 break;
743 case OperationType::GEPOp:
745 break;
746 case OperationType::FPMathOp:
747 FMFs.NoNaNs = false;
748 FMFs.NoInfs = false;
749 break;
750 case OperationType::NonNegOp:
751 NonNegFlags.NonNeg = false;
752 break;
753 case OperationType::Cmp:
754 case OperationType::Other:
755 break;
756 }
757 }
758
759 /// Apply the IR flags to \p I.
760 void applyFlags(Instruction &I) const {
761 switch (OpType) {
762 case OperationType::OverflowingBinOp:
763 I.setHasNoUnsignedWrap(WrapFlags.HasNUW);
764 I.setHasNoSignedWrap(WrapFlags.HasNSW);
765 break;
766 case OperationType::Trunc:
767 I.setHasNoUnsignedWrap(TruncFlags.HasNUW);
768 I.setHasNoSignedWrap(TruncFlags.HasNSW);
769 break;
770 case OperationType::DisjointOp:
771 cast<PossiblyDisjointInst>(&I)->setIsDisjoint(DisjointFlags.IsDisjoint);
772 break;
773 case OperationType::PossiblyExactOp:
774 I.setIsExact(ExactFlags.IsExact);
775 break;
776 case OperationType::GEPOp:
777 cast<GetElementPtrInst>(&I)->setNoWrapFlags(GEPFlags);
778 break;
779 case OperationType::FPMathOp:
780 I.setHasAllowReassoc(FMFs.AllowReassoc);
781 I.setHasNoNaNs(FMFs.NoNaNs);
782 I.setHasNoInfs(FMFs.NoInfs);
783 I.setHasNoSignedZeros(FMFs.NoSignedZeros);
784 I.setHasAllowReciprocal(FMFs.AllowReciprocal);
785 I.setHasAllowContract(FMFs.AllowContract);
786 I.setHasApproxFunc(FMFs.ApproxFunc);
787 break;
788 case OperationType::NonNegOp:
789 I.setNonNeg(NonNegFlags.NonNeg);
790 break;
791 case OperationType::Cmp:
792 case OperationType::Other:
793 break;
794 }
795 }
796
798 assert(OpType == OperationType::Cmp &&
799 "recipe doesn't have a compare predicate");
800 return CmpPredicate;
801 }
802
804 assert(OpType == OperationType::Cmp &&
805 "recipe doesn't have a compare predicate");
806 CmpPredicate = Pred;
807 }
808
810
811 /// Returns true if the recipe has a comparison predicate.
812 bool hasPredicate() const { return OpType == OperationType::Cmp; }
813
814 /// Returns true if the recipe has fast-math flags.
815 bool hasFastMathFlags() const { return OpType == OperationType::FPMathOp; }
816
818
819 /// Returns true if the recipe has non-negative flag.
820 bool hasNonNegFlag() const { return OpType == OperationType::NonNegOp; }
821
822 bool isNonNeg() const {
823 assert(OpType == OperationType::NonNegOp &&
824 "recipe doesn't have a NNEG flag");
825 return NonNegFlags.NonNeg;
826 }
827
828 bool hasNoUnsignedWrap() const {
829 switch (OpType) {
830 case OperationType::OverflowingBinOp:
831 return WrapFlags.HasNUW;
832 case OperationType::Trunc:
833 return TruncFlags.HasNUW;
834 default:
835 llvm_unreachable("recipe doesn't have a NUW flag");
836 }
837 }
838
839 bool hasNoSignedWrap() const {
840 switch (OpType) {
841 case OperationType::OverflowingBinOp:
842 return WrapFlags.HasNSW;
843 case OperationType::Trunc:
844 return TruncFlags.HasNSW;
845 default:
846 llvm_unreachable("recipe doesn't have a NSW flag");
847 }
848 }
849
850 bool isDisjoint() const {
851 assert(OpType == OperationType::DisjointOp &&
852 "recipe cannot have a disjoing flag");
853 return DisjointFlags.IsDisjoint;
854 }
855
856#if !defined(NDEBUG)
857 /// Returns true if the set flags are valid for \p Opcode.
858 bool flagsValidForOpcode(unsigned Opcode) const;
859#endif
860
861#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
862 void printFlags(raw_ostream &O) const;
863#endif
864};
865
866/// A pure-virtual common base class for recipes defining a single VPValue and
867/// using IR flags.
869 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
871 : VPSingleDefRecipe(SC, Operands, DL), VPIRFlags() {}
872
873 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
874 Instruction &I)
875 : VPSingleDefRecipe(SC, Operands, &I, I.getDebugLoc()), VPIRFlags(I) {}
876
877 VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
878 const VPIRFlags &Flags,
880 : VPSingleDefRecipe(SC, Operands, DL), VPIRFlags(Flags) {}
881
882 static inline bool classof(const VPRecipeBase *R) {
883 return R->getVPDefID() == VPRecipeBase::VPInstructionSC ||
884 R->getVPDefID() == VPRecipeBase::VPWidenSC ||
885 R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
886 R->getVPDefID() == VPRecipeBase::VPWidenCallSC ||
887 R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
888 R->getVPDefID() == VPRecipeBase::VPWidenIntrinsicSC ||
889 R->getVPDefID() == VPRecipeBase::VPWidenSelectSC ||
890 R->getVPDefID() == VPRecipeBase::VPReductionSC ||
891 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC ||
892 R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
893 R->getVPDefID() == VPRecipeBase::VPVectorEndPointerSC ||
894 R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
895 }
896
897 static inline bool classof(const VPUser *U) {
898 auto *R = dyn_cast<VPRecipeBase>(U);
899 return R && classof(R);
900 }
901
902 static inline bool classof(const VPValue *V) {
903 auto *R = dyn_cast_or_null<VPRecipeBase>(V->getDefiningRecipe());
904 return R && classof(R);
905 }
906
907 static inline bool classof(const VPSingleDefRecipe *U) {
908 auto *R = dyn_cast<VPRecipeBase>(U);
909 return R && classof(R);
910 }
911
912 void execute(VPTransformState &State) override = 0;
913
914 /// Compute the cost for this recipe for \p VF, using \p Opcode and \p Ctx.
915 std::optional<InstructionCost>
916 getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF,
917 VPCostContext &Ctx) const;
918};
919
920/// Helper to access the operand that contains the unroll part for this recipe
921/// after unrolling.
922template <unsigned PartOpIdx> class LLVM_ABI_FOR_TEST VPUnrollPartAccessor {
923protected:
924 /// Return the VPValue operand containing the unroll part or null if there is
925 /// no such operand.
926 VPValue *getUnrollPartOperand(const VPUser &U) const;
927
928 /// Return the unroll part.
929 unsigned getUnrollPart(const VPUser &U) const;
930};
931
932/// Helper to manage IR metadata for recipes. It filters out metadata that
933/// cannot be propagated.
936
937public:
939
940 /// Adds metatadata that can be preserved from the original instruction
941 /// \p I.
943
944 /// Adds metatadata that can be preserved from the original instruction
945 /// \p I and noalias metadata guaranteed by runtime checks using \p LVer.
947
948 /// Copy constructor for cloning.
949 VPIRMetadata(const VPIRMetadata &Other) : Metadata(Other.Metadata) {}
950
952 Metadata = Other.Metadata;
953 return *this;
954 }
955
956 /// Add all metadata to \p I.
957 void applyMetadata(Instruction &I) const;
958
959 /// Add metadata with kind \p Kind and \p Node.
960 void addMetadata(unsigned Kind, MDNode *Node) {
961 Metadata.emplace_back(Kind, Node);
962 }
963
964 /// Intersect this VPIRMetada object with \p MD, keeping only metadata
965 /// nodes that are common to both.
966 void intersect(const VPIRMetadata &MD);
967};
968
969/// This is a concrete Recipe that models a single VPlan-level instruction.
970/// While as any Recipe it may generate a sequence of IR instructions when
971/// executed, these instructions would always form a single-def expression as
972/// the VPInstruction is also a single def-use vertex.
974 public VPIRMetadata,
975 public VPUnrollPartAccessor<1> {
976 friend class VPlanSlp;
977
978public:
979 /// VPlan opcodes, extending LLVM IR with idiomatics instructions.
980 enum {
982 Instruction::OtherOpsEnd + 1, // Combines the incoming and previous
983 // values of a first-order recurrence.
987 // Creates a mask where each lane is active (true) whilst the current
988 // counter (first operand + index) is less than the second operand. i.e.
989 // mask[i] = icmpt ult (op0 + i), op1
990 // The size of the mask returned is VF * Multiplier (UF, third op).
994 // Increment the canonical IV separately for each unrolled part.
999 /// Given operands of (the same) struct type, creates a struct of fixed-
1000 /// width vectors each containing a struct field of all operands. The
1001 /// number of operands matches the element count of every vector.
1003 /// Creates a fixed-width vector containing all operands. The number of
1004 /// operands matches the vector element count.
1006 /// Compute the final result of a AnyOf reduction with select(cmp(),x,y),
1007 /// where one of (x,y) is loop invariant, and both x and y are integer type.
1011 // Extracts the last lane from its operand if it is a vector, or the last
1012 // part if scalar. In the latter case, the recipe will be removed during
1013 // unrolling.
1015 // Extracts the second-to-last lane from its operand or the second-to-last
1016 // part if it is scalar. In the latter case, the recipe will be removed
1017 // during unrolling.
1019 LogicalAnd, // Non-poison propagating logical And.
1020 // Add an offset in bytes (second operand) to a base pointer (first
1021 // operand). Only generates scalar values (either for the first lane only or
1022 // for all lanes, depending on its uses).
1024 // Add a vector offset in bytes (second operand) to a scalar base pointer
1025 // (first operand).
1027 // Returns a scalar boolean value, which is true if any lane of its
1028 // (boolean) vector operands is true. It produces the reduced value across
1029 // all unrolled iterations. Unrolling will add all copies of its original
1030 // operand as additional operands. AnyOf is poison-safe as all operands
1031 // will be frozen.
1033 // Calculates the first active lane index of the vector predicate operands.
1034 // It produces the lane index across all unrolled iterations. Unrolling will
1035 // add all copies of its original operand as additional operands.
1037
1038 // The opcodes below are used for VPInstructionWithType.
1039 //
1040 /// Scale the first operand (vector step) by the second operand
1041 /// (scalar-step). Casts both operands to the result type if needed.
1043 /// Start vector for reductions with 3 operands: the original start value,
1044 /// the identity value for the reduction and an integer indicating the
1045 /// scaling factor.
1047 // Creates a step vector starting from 0 to VF with a step of 1.
1049 /// Extracts a single lane (first operand) from a set of vector operands.
1050 /// The lane specifies an index into a vector formed by combining all vector
1051 /// operands (all operands after the first one).
1053 /// Explicit user for the resume phi of the canonical induction in the main
1054 /// VPlan, used by the epilogue vector loop.
1056 /// Returns the value for vscale.
1058 };
1059
1060private:
1061 typedef unsigned char OpcodeTy;
1062 OpcodeTy Opcode;
1063
1064 /// An optional name that can be used for the generated IR instruction.
1065 const std::string Name;
1066
1067 /// Returns true if this VPInstruction generates scalar values for all lanes.
1068 /// Most VPInstructions generate a single value per part, either vector or
1069 /// scalar. VPReplicateRecipe takes care of generating multiple (scalar)
1070 /// values per all lanes, stemming from an original ingredient. This method
1071 /// identifies the (rare) cases of VPInstructions that do so as well, w/o an
1072 /// underlying ingredient.
1073 bool doesGeneratePerAllLanes() const;
1074
1075 /// Returns true if we can generate a scalar for the first lane only if
1076 /// needed.
1077 bool canGenerateScalarForFirstLane() const;
1078
1079 /// Utility methods serving execute(): generates a single vector instance of
1080 /// the modeled instruction. \returns the generated value. . In some cases an
1081 /// existing value is returned rather than a generated one.
1082 Value *generate(VPTransformState &State);
1083
1084 /// Utility methods serving execute(): generates a scalar single instance of
1085 /// the modeled instruction for a given lane. \returns the scalar generated
1086 /// value for lane \p Lane.
1087 Value *generatePerLane(VPTransformState &State, const VPLane &Lane);
1088
1089#if !defined(NDEBUG)
1090 /// Return the number of operands determined by the opcode of the
1091 /// VPInstruction. Returns -1u if the number of operands cannot be determined
1092 /// directly by the opcode.
1093 static unsigned getNumOperandsForOpcode(unsigned Opcode);
1094#endif
1095
1096public:
1098 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
1099 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DL),
1100 VPIRMetadata(), Opcode(Opcode), Name(Name.str()) {}
1101
1103 const VPIRFlags &Flags, DebugLoc DL = DebugLoc::getUnknown(),
1104 const Twine &Name = "");
1105
1106 VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
1107
1108 VPInstruction *clone() override {
1110 auto *New = new VPInstruction(Opcode, Operands, *this, getDebugLoc(), Name);
1111 if (getUnderlyingValue())
1112 New->setUnderlyingValue(getUnderlyingInstr());
1113 return New;
1114 }
1115
1116 unsigned getOpcode() const { return Opcode; }
1117
1118 /// Generate the instruction.
1119 /// TODO: We currently execute only per-part unless a specific instance is
1120 /// provided.
1121 void execute(VPTransformState &State) override;
1122
1123 /// Return the cost of this VPInstruction.
1124 InstructionCost computeCost(ElementCount VF,
1125 VPCostContext &Ctx) const override;
1126
1127#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1128 /// Print the VPInstruction to \p O.
1129 void print(raw_ostream &O, const Twine &Indent,
1130 VPSlotTracker &SlotTracker) const override;
1131
1132 /// Print the VPInstruction to dbgs() (for debugging).
1133 LLVM_DUMP_METHOD void dump() const;
1134#endif
1135
1136 bool hasResult() const {
1137 // CallInst may or may not have a result, depending on the called function.
1138 // Conservatively return calls have results for now.
1139 switch (getOpcode()) {
1140 case Instruction::Ret:
1141 case Instruction::Br:
1142 case Instruction::Store:
1143 case Instruction::Switch:
1144 case Instruction::IndirectBr:
1145 case Instruction::Resume:
1146 case Instruction::CatchRet:
1147 case Instruction::Unreachable:
1148 case Instruction::Fence:
1149 case Instruction::AtomicRMW:
1152 return false;
1153 default:
1154 return true;
1155 }
1156 }
1157
1158 /// Returns true if the underlying opcode may read from or write to memory.
1159 bool opcodeMayReadOrWriteFromMemory() const;
1160
1161 /// Returns true if the recipe only uses the first lane of operand \p Op.
1162 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1163
1164 /// Returns true if the recipe only uses the first part of operand \p Op.
1165 bool onlyFirstPartUsed(const VPValue *Op) const override;
1166
1167 /// Returns true if this VPInstruction produces a scalar value from a vector,
1168 /// e.g. by performing a reduction or extracting a lane.
1169 bool isVectorToScalar() const;
1170
1171 /// Returns true if this VPInstruction's operands are single scalars and the
1172 /// result is also a single scalar.
1173 bool isSingleScalar() const;
1174
1175 /// Returns the symbolic name assigned to the VPInstruction.
1176 StringRef getName() const { return Name; }
1177};
1178
1179/// A specialization of VPInstruction augmenting it with a dedicated result
1180/// type, to be used when the opcode and operands of the VPInstruction don't
1181/// directly determine the result type. Note that there is no separate VPDef ID
1182/// for VPInstructionWithType; it shares the same ID as VPInstruction and is
1183/// distinguished purely by the opcode.
1185 /// Scalar result type produced by the recipe.
1186 Type *ResultTy;
1187
1188public:
1190 Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL,
1191 const Twine &Name = "")
1192 : VPInstruction(Opcode, Operands, Flags, DL, Name), ResultTy(ResultTy) {}
1193
1194 static inline bool classof(const VPRecipeBase *R) {
1195 // VPInstructionWithType are VPInstructions with specific opcodes requiring
1196 // type information.
1197 if (R->isScalarCast())
1198 return true;
1199 auto *VPI = dyn_cast<VPInstruction>(R);
1200 if (!VPI)
1201 return false;
1202 switch (VPI->getOpcode()) {
1206 return true;
1207 default:
1208 return false;
1209 }
1210 }
1211
1212 static inline bool classof(const VPUser *R) {
1214 }
1215
1216 VPInstruction *clone() override {
1218 auto *New =
1220 getDebugLoc(), getName());
1221 New->setUnderlyingValue(getUnderlyingValue());
1222 return New;
1223 }
1224
1225 void execute(VPTransformState &State) override;
1226
1227 /// Return the cost of this VPInstruction.
1229 VPCostContext &Ctx) const override {
1230 // TODO: Compute accurate cost after retiring the legacy cost model.
1231 return 0;
1232 }
1233
1234 Type *getResultType() const { return ResultTy; }
1235
1236#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1237 /// Print the recipe.
1238 void print(raw_ostream &O, const Twine &Indent,
1239 VPSlotTracker &SlotTracker) const override;
1240#endif
1241};
1242
1243/// Helper type to provide functions to access incoming values and blocks for
1244/// phi-like recipes.
1246protected:
1247 /// Return a VPRecipeBase* to the current object.
1248 virtual const VPRecipeBase *getAsRecipe() const = 0;
1249
1250public:
1251 virtual ~VPPhiAccessors() = default;
1252
1253 /// Returns the incoming VPValue with index \p Idx.
1254 VPValue *getIncomingValue(unsigned Idx) const {
1255 return getAsRecipe()->getOperand(Idx);
1256 }
1257
1258 /// Returns the incoming block with index \p Idx.
1259 const VPBasicBlock *getIncomingBlock(unsigned Idx) const;
1260
1261 /// Returns the number of incoming values, also number of incoming blocks.
1262 virtual unsigned getNumIncoming() const {
1263 return getAsRecipe()->getNumOperands();
1264 }
1265
1266 /// Returns an interator range over the incoming values.
1268 return make_range(getAsRecipe()->op_begin(),
1269 getAsRecipe()->op_begin() + getNumIncoming());
1270 }
1271
1273 detail::index_iterator, std::function<const VPBasicBlock *(size_t)>>>;
1274
1275 /// Returns an iterator range over the incoming blocks.
1277 std::function<const VPBasicBlock *(size_t)> GetBlock = [this](size_t Idx) {
1278 return getIncomingBlock(Idx);
1279 };
1280 return map_range(index_range(0, getNumIncoming()), GetBlock);
1281 }
1282
1283 /// Returns an iterator range over pairs of incoming values and corresponding
1284 /// incoming blocks.
1290
1291 /// Removes the incoming value for \p IncomingBlock, which must be a
1292 /// predecessor.
1293 void removeIncomingValueFor(VPBlockBase *IncomingBlock) const;
1294
1295#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1296 /// Print the recipe.
1298#endif
1299};
1300
1304
1305 static inline bool classof(const VPUser *U) {
1306 auto *VPI = dyn_cast<VPInstruction>(U);
1307 return VPI && VPI->getOpcode() == Instruction::PHI;
1308 }
1309
1310 static inline bool classof(const VPValue *V) {
1311 auto *VPI = dyn_cast<VPInstruction>(V);
1312 return VPI && VPI->getOpcode() == Instruction::PHI;
1313 }
1314
1315 static inline bool classof(const VPSingleDefRecipe *SDR) {
1316 auto *VPI = dyn_cast<VPInstruction>(SDR);
1317 return VPI && VPI->getOpcode() == Instruction::PHI;
1318 }
1319
1320 VPPhi *clone() override {
1321 auto *PhiR = new VPPhi(operands(), getDebugLoc(), getName());
1322 PhiR->setUnderlyingValue(getUnderlyingValue());
1323 return PhiR;
1324 }
1325
1326 void execute(VPTransformState &State) override;
1327
1328#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1329 /// Print the recipe.
1330 void print(raw_ostream &O, const Twine &Indent,
1331 VPSlotTracker &SlotTracker) const override;
1332#endif
1333
1334protected:
1335 const VPRecipeBase *getAsRecipe() const override { return this; }
1336};
1337
1338/// A recipe to wrap on original IR instruction not to be modified during
1339/// execution, except for PHIs. PHIs are modeled via the VPIRPhi subclass.
1340/// Expect PHIs, VPIRInstructions cannot have any operands.
1342 Instruction &I;
1343
1344protected:
1345 /// VPIRInstruction::create() should be used to create VPIRInstructions, as
1346 /// subclasses may need to be created, e.g. VPIRPhi.
1348 : VPRecipeBase(VPDef::VPIRInstructionSC, ArrayRef<VPValue *>()), I(I) {}
1349
1350public:
1351 ~VPIRInstruction() override = default;
1352
1353 /// Create a new VPIRPhi for \p \I, if it is a PHINode, otherwise create a
1354 /// VPIRInstruction.
1356
1357 VP_CLASSOF_IMPL(VPDef::VPIRInstructionSC)
1358
1360 auto *R = create(I);
1361 for (auto *Op : operands())
1362 R->addOperand(Op);
1363 return R;
1364 }
1365
1366 void execute(VPTransformState &State) override;
1367
1368 /// Return the cost of this VPIRInstruction.
1370 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
1371
1372 Instruction &getInstruction() const { return I; }
1373
1374#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1375 /// Print the recipe.
1376 void print(raw_ostream &O, const Twine &Indent,
1377 VPSlotTracker &SlotTracker) const override;
1378#endif
1379
1380 bool usesScalars(const VPValue *Op) const override {
1382 "Op must be an operand of the recipe");
1383 return true;
1384 }
1385
1386 bool onlyFirstPartUsed(const VPValue *Op) const override {
1388 "Op must be an operand of the recipe");
1389 return true;
1390 }
1391
1392 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1394 "Op must be an operand of the recipe");
1395 return true;
1396 }
1397
1398 /// Update the recipes first operand to the last lane of the operand using \p
1399 /// Builder. Must only be used for VPIRInstructions with at least one operand
1400 /// wrapping a PHINode.
1402};
1403
1404/// An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use
1405/// cast/dyn_cast/isa and execute() implementation. A single VPValue operand is
1406/// allowed, and it is used to add a new incoming value for the single
1407/// predecessor VPBB.
1409 public VPPhiAccessors {
1411
1412 static inline bool classof(const VPRecipeBase *U) {
1413 auto *R = dyn_cast<VPIRInstruction>(U);
1414 return R && isa<PHINode>(R->getInstruction());
1415 }
1416
1418
1419 void execute(VPTransformState &State) override;
1420
1421#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1422 /// Print the recipe.
1423 void print(raw_ostream &O, const Twine &Indent,
1424 VPSlotTracker &SlotTracker) const override;
1425#endif
1426
1427protected:
1428 const VPRecipeBase *getAsRecipe() const override { return this; }
1429};
1430
1431/// VPWidenRecipe is a recipe for producing a widened instruction using the
1432/// opcode and operands of the recipe. This recipe covers most of the
1433/// traditional vectorization cases where each recipe transforms into a
1434/// vectorized version of itself.
1436 public VPIRMetadata {
1437 unsigned Opcode;
1438
1439public:
1441 const VPIRFlags &Flags, const VPIRMetadata &Metadata,
1442 DebugLoc DL)
1443 : VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, Flags, DL),
1444 VPIRMetadata(Metadata), Opcode(Opcode) {}
1445
1449
1450 ~VPWidenRecipe() override = default;
1451
1452 VPWidenRecipe *clone() override {
1453 auto *R =
1454 new VPWidenRecipe(getOpcode(), operands(), *this, *this, getDebugLoc());
1455 R->setUnderlyingValue(getUnderlyingValue());
1456 return R;
1457 }
1458
1459 VP_CLASSOF_IMPL(VPDef::VPWidenSC)
1460
1461 /// Produce a widened instruction using the opcode and operands of the recipe,
1462 /// processing State.VF elements.
1463 void execute(VPTransformState &State) override;
1464
1465 /// Return the cost of this VPWidenRecipe.
1466 InstructionCost computeCost(ElementCount VF,
1467 VPCostContext &Ctx) const override;
1468
1469 unsigned getOpcode() const { return Opcode; }
1470
1471#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1472 /// Print the recipe.
1473 void print(raw_ostream &O, const Twine &Indent,
1474 VPSlotTracker &SlotTracker) const override;
1475#endif
1476};
1477
1478/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1480 /// Cast instruction opcode.
1481 Instruction::CastOps Opcode;
1482
1483 /// Result type for the cast.
1484 Type *ResultTy;
1485
1486public:
1488 CastInst &UI)
1489 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), VPIRMetadata(UI),
1490 Opcode(Opcode), ResultTy(ResultTy) {
1491 assert(UI.getOpcode() == Opcode &&
1492 "opcode of underlying cast doesn't match");
1493 }
1494
1496 const VPIRFlags &Flags = {},
1498 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, Flags, DL),
1499 VPIRMetadata(), Opcode(Opcode), ResultTy(ResultTy) {
1500 assert(flagsValidForOpcode(Opcode) &&
1501 "Set flags not supported for the provided opcode");
1502 }
1503
1504 ~VPWidenCastRecipe() override = default;
1505
1507 if (auto *UV = getUnderlyingValue())
1508 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1509 *cast<CastInst>(UV));
1510
1511 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
1512 }
1513
1514 VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
1515
1516 /// Produce widened copies of the cast.
1517 void execute(VPTransformState &State) override;
1518
1519 /// Return the cost of this VPWidenCastRecipe.
1521 VPCostContext &Ctx) const override;
1522
1523#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1524 /// Print the recipe.
1525 void print(raw_ostream &O, const Twine &Indent,
1526 VPSlotTracker &SlotTracker) const override;
1527#endif
1528
1529 Instruction::CastOps getOpcode() const { return Opcode; }
1530
1531 /// Returns the result type of the cast.
1532 Type *getResultType() const { return ResultTy; }
1533};
1534
1535/// A recipe for widening vector intrinsics.
1537 /// ID of the vector intrinsic to widen.
1538 Intrinsic::ID VectorIntrinsicID;
1539
1540 /// Scalar return type of the intrinsic.
1541 Type *ResultTy;
1542
1543 /// True if the intrinsic may read from memory.
1544 bool MayReadFromMemory;
1545
1546 /// True if the intrinsic may read write to memory.
1547 bool MayWriteToMemory;
1548
1549 /// True if the intrinsic may have side-effects.
1550 bool MayHaveSideEffects;
1551
1552public:
1554 ArrayRef<VPValue *> CallArguments, Type *Ty,
1556 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1557 VPIRMetadata(CI), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1558 MayReadFromMemory(CI.mayReadFromMemory()),
1559 MayWriteToMemory(CI.mayWriteToMemory()),
1560 MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1561
1563 ArrayRef<VPValue *> CallArguments, Type *Ty,
1565 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1566 VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1567 LLVMContext &Ctx = Ty->getContext();
1568 AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
1569 MemoryEffects ME = Attrs.getMemoryEffects();
1570 MayReadFromMemory = !ME.onlyWritesMemory();
1571 MayWriteToMemory = !ME.onlyReadsMemory();
1572 MayHaveSideEffects = MayWriteToMemory ||
1573 !Attrs.hasAttribute(Attribute::NoUnwind) ||
1574 !Attrs.hasAttribute(Attribute::WillReturn);
1575 }
1576
1577 ~VPWidenIntrinsicRecipe() override = default;
1578
1580 if (Value *CI = getUnderlyingValue())
1581 return new VPWidenIntrinsicRecipe(*cast<CallInst>(CI), VectorIntrinsicID,
1582 operands(), ResultTy, getDebugLoc());
1583 return new VPWidenIntrinsicRecipe(VectorIntrinsicID, operands(), ResultTy,
1584 getDebugLoc());
1585 }
1586
1587 VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
1588
1589 /// Produce a widened version of the vector intrinsic.
1590 void execute(VPTransformState &State) override;
1591
1592 /// Return the cost of this vector intrinsic.
1594 VPCostContext &Ctx) const override;
1595
1596 /// Return the ID of the intrinsic.
1597 Intrinsic::ID getVectorIntrinsicID() const { return VectorIntrinsicID; }
1598
1599 /// Return the scalar return type of the intrinsic.
1600 Type *getResultType() const { return ResultTy; }
1601
1602 /// Return to name of the intrinsic as string.
1604
1605 /// Returns true if the intrinsic may read from memory.
1606 bool mayReadFromMemory() const { return MayReadFromMemory; }
1607
1608 /// Returns true if the intrinsic may write to memory.
1609 bool mayWriteToMemory() const { return MayWriteToMemory; }
1610
1611 /// Returns true if the intrinsic may have side-effects.
1612 bool mayHaveSideEffects() const { return MayHaveSideEffects; }
1613
1614#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1615 /// Print the recipe.
1616 void print(raw_ostream &O, const Twine &Indent,
1617 VPSlotTracker &SlotTracker) const override;
1618#endif
1619
1620 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1621};
1622
1623/// A recipe for widening Call instructions using library calls.
1625 public VPIRMetadata {
1626 /// Variant stores a pointer to the chosen function. There is a 1:1 mapping
1627 /// between a given VF and the chosen vectorized variant, so there will be a
1628 /// different VPlan for each VF with a valid variant.
1629 Function *Variant;
1630
1631public:
1633 ArrayRef<VPValue *> CallArguments,
1635 : VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
1636 *cast<Instruction>(UV)),
1637 VPIRMetadata(*cast<Instruction>(UV)), Variant(Variant) {
1638 assert(
1640 "last operand must be the called function");
1641 }
1642
1643 ~VPWidenCallRecipe() override = default;
1644
1646 return new VPWidenCallRecipe(getUnderlyingValue(), Variant, operands(),
1647 getDebugLoc());
1648 }
1649
1650 VP_CLASSOF_IMPL(VPDef::VPWidenCallSC)
1651
1652 /// Produce a widened version of the call instruction.
1653 void execute(VPTransformState &State) override;
1654
1655 /// Return the cost of this VPWidenCallRecipe.
1656 InstructionCost computeCost(ElementCount VF,
1657 VPCostContext &Ctx) const override;
1658
1662
1665
1666#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1667 /// Print the recipe.
1668 void print(raw_ostream &O, const Twine &Indent,
1669 VPSlotTracker &SlotTracker) const override;
1670#endif
1671};
1672
1673/// A recipe representing a sequence of load -> update -> store as part of
1674/// a histogram operation. This means there may be aliasing between vector
1675/// lanes, which is handled by the llvm.experimental.vector.histogram family
1676/// of intrinsics. The only update operations currently supported are
1677/// 'add' and 'sub' where the other term is loop-invariant.
1679 /// Opcode of the update operation, currently either add or sub.
1680 unsigned Opcode;
1681
1682public:
1683 VPHistogramRecipe(unsigned Opcode, ArrayRef<VPValue *> Operands,
1685 : VPRecipeBase(VPDef::VPHistogramSC, Operands, DL), Opcode(Opcode) {}
1686
1687 ~VPHistogramRecipe() override = default;
1688
1690 return new VPHistogramRecipe(Opcode, operands(), getDebugLoc());
1691 }
1692
1693 VP_CLASSOF_IMPL(VPDef::VPHistogramSC);
1694
1695 /// Produce a vectorized histogram operation.
1696 void execute(VPTransformState &State) override;
1697
1698 /// Return the cost of this VPHistogramRecipe.
1700 VPCostContext &Ctx) const override;
1701
1702 unsigned getOpcode() const { return Opcode; }
1703
1704 /// Return the mask operand if one was provided, or a null pointer if all
1705 /// lanes should be executed unconditionally.
1706 VPValue *getMask() const {
1707 return getNumOperands() == 3 ? getOperand(2) : nullptr;
1708 }
1709
1710#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1711 /// Print the recipe
1712 void print(raw_ostream &O, const Twine &Indent,
1713 VPSlotTracker &SlotTracker) const override;
1714#endif
1715};
1716
1717/// A recipe for widening select instructions.
1719 public VPIRMetadata {
1723
1724 ~VPWidenSelectRecipe() override = default;
1725
1730
1731 VP_CLASSOF_IMPL(VPDef::VPWidenSelectSC)
1732
1733 /// Produce a widened version of the select instruction.
1734 void execute(VPTransformState &State) override;
1735
1736 /// Return the cost of this VPWidenSelectRecipe.
1737 InstructionCost computeCost(ElementCount VF,
1738 VPCostContext &Ctx) const override;
1739
1740#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1741 /// Print the recipe.
1742 void print(raw_ostream &O, const Twine &Indent,
1743 VPSlotTracker &SlotTracker) const override;
1744#endif
1745
1746 unsigned getOpcode() const { return Instruction::Select; }
1747
1748 VPValue *getCond() const {
1749 return getOperand(0);
1750 }
1751
1752 bool isInvariantCond() const {
1753 return getCond()->isDefinedOutsideLoopRegions();
1754 }
1755
1756 /// Returns true if the recipe only uses the first lane of operand \p Op.
1757 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1759 "Op must be an operand of the recipe");
1760 return Op == getCond() && isInvariantCond();
1761 }
1762};
1763
1764/// A recipe for handling GEP instructions.
1766 bool isPointerLoopInvariant() const {
1767 return getOperand(0)->isDefinedOutsideLoopRegions();
1768 }
1769
1770 bool isIndexLoopInvariant(unsigned I) const {
1771 return getOperand(I + 1)->isDefinedOutsideLoopRegions();
1772 }
1773
1774 bool areAllOperandsInvariant() const {
1775 return all_of(operands(), [](VPValue *Op) {
1776 return Op->isDefinedOutsideLoopRegions();
1777 });
1778 }
1779
1780public:
1788
1789 ~VPWidenGEPRecipe() override = default;
1790
1795
1796 VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
1797
1798 /// Generate the gep nodes.
1799 void execute(VPTransformState &State) override;
1800
1801 /// Return the cost of this VPWidenGEPRecipe.
1803 VPCostContext &Ctx) const override {
1804 // TODO: Compute accurate cost after retiring the legacy cost model.
1805 return 0;
1806 }
1807
1808#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1809 /// Print the recipe.
1810 void print(raw_ostream &O, const Twine &Indent,
1811 VPSlotTracker &SlotTracker) const override;
1812#endif
1813
1814 /// Returns true if the recipe only uses the first lane of operand \p Op.
1815 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1817 "Op must be an operand of the recipe");
1818 if (Op == getOperand(0))
1819 return isPointerLoopInvariant();
1820 else
1821 return !isPointerLoopInvariant() && Op->isDefinedOutsideLoopRegions();
1822 }
1823};
1824
1825/// A recipe to compute a pointer to the last element of each part of a widened
1826/// memory access for widened memory accesses of IndexedTy. Used for
1827/// VPWidenMemoryRecipes or VPInterleaveRecipes that are reversed.
1829 public VPUnrollPartAccessor<2> {
1830 Type *IndexedTy;
1831
1832 /// The constant stride of the pointer computed by this recipe, expressed in
1833 /// units of IndexedTy.
1834 int64_t Stride;
1835
1836public:
1838 int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
1839 : VPRecipeWithIRFlags(VPDef::VPVectorEndPointerSC,
1840 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
1841 IndexedTy(IndexedTy), Stride(Stride) {
1842 assert(Stride < 0 && "Stride must be negative");
1843 }
1844
1845 VP_CLASSOF_IMPL(VPDef::VPVectorEndPointerSC)
1846
1848 const VPValue *getVFValue() const { return getOperand(1); }
1849
1850 void execute(VPTransformState &State) override;
1851
1852 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1854 "Op must be an operand of the recipe");
1855 return true;
1856 }
1857
1858 /// Return the cost of this VPVectorPointerRecipe.
1860 VPCostContext &Ctx) const override {
1861 // TODO: Compute accurate cost after retiring the legacy cost model.
1862 return 0;
1863 }
1864
1865 /// Returns true if the recipe only uses the first part of operand \p Op.
1866 bool onlyFirstPartUsed(const VPValue *Op) const override {
1868 "Op must be an operand of the recipe");
1869 assert(getNumOperands() <= 2 && "must have at most two operands");
1870 return true;
1871 }
1872
1874 return new VPVectorEndPointerRecipe(getOperand(0), getVFValue(), IndexedTy,
1875 Stride, getGEPNoWrapFlags(),
1876 getDebugLoc());
1877 }
1878
1879#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1880 /// Print the recipe.
1881 void print(raw_ostream &O, const Twine &Indent,
1882 VPSlotTracker &SlotTracker) const override;
1883#endif
1884};
1885
1886/// A recipe to compute the pointers for widened memory accesses of IndexTy.
1888 public VPUnrollPartAccessor<1> {
1889 Type *IndexedTy;
1890
1891public:
1893 DebugLoc DL)
1894 : VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
1895 GEPFlags, DL),
1896 IndexedTy(IndexedTy) {}
1897
1898 VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
1899
1900 void execute(VPTransformState &State) override;
1901
1902 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1904 "Op must be an operand of the recipe");
1905 return true;
1906 }
1907
1908 /// Returns true if the recipe only uses the first part of operand \p Op.
1909 bool onlyFirstPartUsed(const VPValue *Op) const override {
1911 "Op must be an operand of the recipe");
1912 assert(getNumOperands() <= 2 && "must have at most two operands");
1913 return true;
1914 }
1915
1917 return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1919 }
1920
1921 /// Return true if this VPVectorPointerRecipe corresponds to part 0. Note that
1922 /// this is only accurate after the VPlan has been unrolled.
1923 bool isFirstPart() const { return getUnrollPart(*this) == 0; }
1924
1925 /// Return the cost of this VPHeaderPHIRecipe.
1927 VPCostContext &Ctx) const override {
1928 // TODO: Compute accurate cost after retiring the legacy cost model.
1929 return 0;
1930 }
1931
1932#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1933 /// Print the recipe.
1934 void print(raw_ostream &O, const Twine &Indent,
1935 VPSlotTracker &SlotTracker) const override;
1936#endif
1937};
1938
1939/// A pure virtual base class for all recipes modeling header phis, including
1940/// phis for first order recurrences, pointer inductions and reductions. The
1941/// start value is the first operand of the recipe and the incoming value from
1942/// the backedge is the second operand.
1943///
1944/// Inductions are modeled using the following sub-classes:
1945/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
1946/// starting at a specified value (zero for the main vector loop, the resume
1947/// value for the epilogue vector loop) and stepping by 1. The induction
1948/// controls exiting of the vector loop by comparing against the vector trip
1949/// count. Produces a single scalar PHI for the induction value per
1950/// iteration.
1951/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
1952/// floating point inductions with arbitrary start and step values. Produces
1953/// a vector PHI per-part.
1954/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
1955/// value of an IV with different start and step values. Produces a single
1956/// scalar value per iteration
1957/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
1958/// canonical or derived induction.
1959/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
1960/// pointer induction. Produces either a vector PHI per-part or scalar values
1961/// per-lane based on the canonical induction.
1963 public VPPhiAccessors {
1964protected:
1965 VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
1966 VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
1967 : VPSingleDefRecipe(VPDefID, ArrayRef<VPValue *>({Start}),
1968 UnderlyingInstr, DL) {}
1969
1970 const VPRecipeBase *getAsRecipe() const override { return this; }
1971
1972public:
1973 ~VPHeaderPHIRecipe() override = default;
1974
1975 /// Method to support type inquiry through isa, cast, and dyn_cast.
1976 static inline bool classof(const VPRecipeBase *B) {
1977 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
1978 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
1979 }
1980 static inline bool classof(const VPValue *V) {
1981 auto *B = V->getDefiningRecipe();
1982 return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
1983 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
1984 }
1985
1986 /// Generate the phi nodes.
1987 void execute(VPTransformState &State) override = 0;
1988
1989 /// Return the cost of this header phi recipe.
1991 VPCostContext &Ctx) const override;
1992
1993#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1994 /// Print the recipe.
1995 void print(raw_ostream &O, const Twine &Indent,
1996 VPSlotTracker &SlotTracker) const override = 0;
1997#endif
1998
1999 /// Returns the start value of the phi, if one is set.
2001 return getNumOperands() == 0 ? nullptr : getOperand(0);
2002 }
2004 return getNumOperands() == 0 ? nullptr : getOperand(0);
2005 }
2006
2007 /// Update the start value of the recipe.
2009
2010 /// Returns the incoming value from the loop backedge.
2012 return getOperand(1);
2013 }
2014
2015 /// Update the incoming value from the loop backedge.
2017
2018 /// Returns the backedge value as a recipe. The backedge value is guaranteed
2019 /// to be a recipe.
2021 return *getBackedgeValue()->getDefiningRecipe();
2022 }
2023};
2024
2025/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2026/// VPWidenPointerInductionRecipe), providing shared functionality, including
2027/// retrieving the step value, induction descriptor and original phi node.
2029 const InductionDescriptor &IndDesc;
2030
2031public:
2032 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
2033 VPValue *Step, const InductionDescriptor &IndDesc,
2034 DebugLoc DL)
2035 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2036 addOperand(Step);
2037 }
2038
2039 static inline bool classof(const VPRecipeBase *R) {
2040 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
2041 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
2042 }
2043
2044 static inline bool classof(const VPValue *V) {
2045 auto *R = V->getDefiningRecipe();
2046 return R && classof(R);
2047 }
2048
2049 static inline bool classof(const VPHeaderPHIRecipe *R) {
2050 return classof(static_cast<const VPRecipeBase *>(R));
2051 }
2052
2053 virtual void execute(VPTransformState &State) override = 0;
2054
2055 /// Returns the step value of the induction.
2057 const VPValue *getStepValue() const { return getOperand(1); }
2058
2059 /// Update the step value of the recipe.
2060 void setStepValue(VPValue *V) { setOperand(1, V); }
2061
2063 const VPValue *getVFValue() const { return getOperand(2); }
2064
2065 /// Returns the number of incoming values, also number of incoming blocks.
2066 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2067 /// incoming value, its start value.
2068 unsigned getNumIncoming() const override { return 1; }
2069
2071
2072 /// Returns the induction descriptor for the recipe.
2073 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
2074
2076 // TODO: All operands of base recipe must exist and be at same index in
2077 // derived recipe.
2079 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2080 }
2081
2083 // TODO: All operands of base recipe must exist and be at same index in
2084 // derived recipe.
2086 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2087 }
2088
2089 /// Returns true if the recipe only uses the first lane of operand \p Op.
2090 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2092 "Op must be an operand of the recipe");
2093 // The recipe creates its own wide start value, so it only requests the
2094 // first lane of the operand.
2095 // TODO: Remove once creating the start value is modeled separately.
2096 return Op == getStartValue() || Op == getStepValue();
2097 }
2098};
2099
2100/// A recipe for handling phi nodes of integer and floating-point inductions,
2101/// producing their vector values. This is an abstract recipe and must be
2102/// converted to concrete recipes before executing.
2104 TruncInst *Trunc;
2105
2106 // If this recipe is unrolled it will have 2 additional operands.
2107 bool isUnrolled() const { return getNumOperands() == 5; }
2108
2109public:
2111 VPValue *VF, const InductionDescriptor &IndDesc,
2112 DebugLoc DL)
2113 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2114 Step, IndDesc, DL),
2115 Trunc(nullptr) {
2116 addOperand(VF);
2117 }
2118
2120 VPValue *VF, const InductionDescriptor &IndDesc,
2121 TruncInst *Trunc, DebugLoc DL)
2122 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2123 Step, IndDesc, DL),
2124 Trunc(Trunc) {
2125 addOperand(VF);
2127 (void)Metadata;
2128 if (Trunc)
2130 assert(Metadata.empty() && "unexpected metadata on Trunc");
2131 }
2132
2134
2140
2141 VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
2142
2143 void execute(VPTransformState &State) override {
2144 llvm_unreachable("cannot execute this recipe, should be expanded via "
2145 "expandVPWidenIntOrFpInductionRecipe");
2146 }
2147
2148#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2149 /// Print the recipe.
2150 void print(raw_ostream &O, const Twine &Indent,
2151 VPSlotTracker &SlotTracker) const override;
2152#endif
2153
2155 // If the recipe has been unrolled return the VPValue for the induction
2156 // increment.
2157 return isUnrolled() ? getOperand(getNumOperands() - 2) : nullptr;
2158 }
2159
2160 /// Returns the number of incoming values, also number of incoming blocks.
2161 /// Note that at the moment, VPWidenIntOrFpInductionRecipes only have a single
2162 /// incoming value, its start value.
2163 unsigned getNumIncoming() const override { return 1; }
2164
2165 /// Returns the first defined value as TruncInst, if it is one or nullptr
2166 /// otherwise.
2167 TruncInst *getTruncInst() { return Trunc; }
2168 const TruncInst *getTruncInst() const { return Trunc; }
2169
2170 /// Returns true if the induction is canonical, i.e. starting at 0 and
2171 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
2172 /// same type as the canonical induction.
2173 bool isCanonical() const;
2174
2175 /// Returns the scalar type of the induction.
2177 return Trunc ? Trunc->getType()
2179 }
2180
2181 /// Returns the VPValue representing the value of this induction at
2182 /// the last unrolled part, if it exists. Returns itself if unrolling did not
2183 /// take place.
2185 return isUnrolled() ? getOperand(getNumOperands() - 1) : this;
2186 }
2187};
2188
2190 bool IsScalarAfterVectorization;
2191
2192public:
2193 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2194 /// Start and the number of elements unrolled \p NumUnrolledElems, typically
2195 /// VF*UF.
2197 VPValue *NumUnrolledElems,
2198 const InductionDescriptor &IndDesc,
2199 bool IsScalarAfterVectorization, DebugLoc DL)
2200 : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
2201 Step, IndDesc, DL),
2202 IsScalarAfterVectorization(IsScalarAfterVectorization) {
2203 addOperand(NumUnrolledElems);
2204 }
2205
2207
2211 getOperand(2), getInductionDescriptor(), IsScalarAfterVectorization,
2212 getDebugLoc());
2213 }
2214
2215 VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
2216
2217 /// Generate vector values for the pointer induction.
2218 void execute(VPTransformState &State) override {
2219 llvm_unreachable("cannot execute this recipe, should be expanded via "
2220 "expandVPWidenPointerInduction");
2221 };
2222
2223 /// Returns true if only scalar values will be generated.
2224 bool onlyScalarsGenerated(bool IsScalable);
2225
2226#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2227 /// Print the recipe.
2228 void print(raw_ostream &O, const Twine &Indent,
2229 VPSlotTracker &SlotTracker) const override;
2230#endif
2231};
2232
2233/// A recipe for widened phis. Incoming values are operands of the recipe and
2234/// their operand index corresponds to the incoming predecessor block. If the
2235/// recipe is placed in an entry block to a (non-replicate) region, it must have
2236/// exactly 2 incoming values, the first from the predecessor of the region and
2237/// the second from the exiting block of the region.
2239 public VPPhiAccessors {
2240 /// Name to use for the generated IR instruction for the widened phi.
2241 std::string Name;
2242
2243protected:
2244 const VPRecipeBase *getAsRecipe() const override { return this; }
2245
2246public:
2247 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
2248 /// debug location \p DL.
2249 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
2250 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
2251 : VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi, DL),
2252 Name(Name.str()) {
2253 if (Start)
2254 addOperand(Start);
2255 }
2256
2259 getOperand(0), getDebugLoc(), Name);
2261 C->addOperand(Op);
2262 return C;
2263 }
2264
2265 ~VPWidenPHIRecipe() override = default;
2266
2267 VP_CLASSOF_IMPL(VPDef::VPWidenPHISC)
2268
2269 /// Generate the phi/select nodes.
2270 void execute(VPTransformState &State) override;
2271
2272#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2273 /// Print the recipe.
2274 void print(raw_ostream &O, const Twine &Indent,
2275 VPSlotTracker &SlotTracker) const override;
2276#endif
2277};
2278
2279/// A recipe for handling first-order recurrence phis. The start value is the
2280/// first operand of the recipe and the incoming value from the backedge is the
2281/// second operand.
2284 : VPHeaderPHIRecipe(VPDef::VPFirstOrderRecurrencePHISC, Phi, &Start) {}
2285
2286 VP_CLASSOF_IMPL(VPDef::VPFirstOrderRecurrencePHISC)
2287
2292
2293 void execute(VPTransformState &State) override;
2294
2295 /// Return the cost of this first-order recurrence phi recipe.
2297 VPCostContext &Ctx) const override;
2298
2299#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2300 /// Print the recipe.
2301 void print(raw_ostream &O, const Twine &Indent,
2302 VPSlotTracker &SlotTracker) const override;
2303#endif
2304
2305 /// Returns true if the recipe only uses the first lane of operand \p Op.
2306 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2308 "Op must be an operand of the recipe");
2309 return Op == getStartValue();
2310 }
2311};
2312
2313/// A recipe for handling reduction phis. The start value is the first operand
2314/// of the recipe and the incoming value from the backedge is the second
2315/// operand.
2317 public VPUnrollPartAccessor<2> {
2318 /// The recurrence kind of the reduction.
2319 const RecurKind Kind;
2320
2321 /// The phi is part of an in-loop reduction.
2322 bool IsInLoop;
2323
2324 /// The phi is part of an ordered reduction. Requires IsInLoop to be true.
2325 bool IsOrdered;
2326
2327 /// When expanding the reduction PHI, the plan's VF element count is divided
2328 /// by this factor to form the reduction phi's VF.
2329 unsigned VFScaleFactor = 1;
2330
2331public:
2332 /// Create a new VPReductionPHIRecipe for the reduction \p Phi.
2334 bool IsInLoop = false, bool IsOrdered = false,
2335 unsigned VFScaleFactor = 1)
2336 : VPHeaderPHIRecipe(VPDef::VPReductionPHISC, Phi, &Start), Kind(Kind),
2337 IsInLoop(IsInLoop), IsOrdered(IsOrdered), VFScaleFactor(VFScaleFactor) {
2338 assert((!IsOrdered || IsInLoop) && "IsOrdered requires IsInLoop");
2339 }
2340
2341 ~VPReductionPHIRecipe() override = default;
2342
2344 auto *R = new VPReductionPHIRecipe(
2346 *getOperand(0), IsInLoop, IsOrdered, VFScaleFactor);
2347 R->addOperand(getBackedgeValue());
2348 return R;
2349 }
2350
2351 VP_CLASSOF_IMPL(VPDef::VPReductionPHISC)
2352
2353 /// Generate the phi/select nodes.
2354 void execute(VPTransformState &State) override;
2355
2356 /// Get the factor that the VF of this recipe's output should be scaled by.
2357 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2358
2359#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2360 /// Print the recipe.
2361 void print(raw_ostream &O, const Twine &Indent,
2362 VPSlotTracker &SlotTracker) const override;
2363#endif
2364
2365 /// Returns the number of incoming values, also number of incoming blocks.
2366 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2367 /// incoming value, its start value.
2368 unsigned getNumIncoming() const override { return 2; }
2369
2370 /// Returns the recurrence kind of the reduction.
2371 RecurKind getRecurrenceKind() const { return Kind; }
2372
2373 /// Returns true, if the phi is part of an ordered reduction.
2374 bool isOrdered() const { return IsOrdered; }
2375
2376 /// Returns true, if the phi is part of an in-loop reduction.
2377 bool isInLoop() const { return IsInLoop; }
2378
2379 /// Returns true if the recipe only uses the first lane of operand \p Op.
2380 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2382 "Op must be an operand of the recipe");
2383 return isOrdered() || isInLoop();
2384 }
2385};
2386
2387/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2388/// instructions.
2390public:
2391 /// The blend operation is a User of the incoming values and of their
2392 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2393 /// be omitted (implied by passing an odd number of operands) in which case
2394 /// all other incoming values are merged into it.
2396 : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, DL) {
2397 assert(Operands.size() > 0 && "Expected at least one operand!");
2398 }
2399
2404
2405 VP_CLASSOF_IMPL(VPDef::VPBlendSC)
2406
2407 /// A normalized blend is one that has an odd number of operands, whereby the
2408 /// first operand does not have an associated mask.
2409 bool isNormalized() const { return getNumOperands() % 2; }
2410
2411 /// Return the number of incoming values, taking into account when normalized
2412 /// the first incoming value will have no mask.
2413 unsigned getNumIncomingValues() const {
2414 return (getNumOperands() + isNormalized()) / 2;
2415 }
2416
2417 /// Return incoming value number \p Idx.
2418 VPValue *getIncomingValue(unsigned Idx) const {
2419 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2420 }
2421
2422 /// Return mask number \p Idx.
2423 VPValue *getMask(unsigned Idx) const {
2424 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2425 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2426 }
2427
2428 /// Set mask number \p Idx to \p V.
2429 void setMask(unsigned Idx, VPValue *V) {
2430 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2431 Idx == 0 ? setOperand(1, V) : setOperand(Idx * 2 + !isNormalized(), V);
2432 }
2433
2434 void execute(VPTransformState &State) override {
2435 llvm_unreachable("VPBlendRecipe should be expanded by simplifyBlends");
2436 }
2437
2438 /// Return the cost of this VPWidenMemoryRecipe.
2439 InstructionCost computeCost(ElementCount VF,
2440 VPCostContext &Ctx) const override;
2441
2442#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2443 /// Print the recipe.
2444 void print(raw_ostream &O, const Twine &Indent,
2445 VPSlotTracker &SlotTracker) const override;
2446#endif
2447
2448 /// Returns true if the recipe only uses the first lane of operand \p Op.
2449 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2451 "Op must be an operand of the recipe");
2452 // Recursing through Blend recipes only, must terminate at header phi's the
2453 // latest.
2454 return all_of(users(),
2455 [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
2456 }
2457};
2458
2459/// A common base class for interleaved memory operations.
2460/// An Interleaved memory operation is a memory access method that combines
2461/// multiple strided loads/stores into a single wide load/store with shuffles.
2462/// The first operand is the start address. The optional operands are, in order,
2463/// the stored values and the mask.
2465 public VPIRMetadata {
2467
2468 /// Indicates if the interleave group is in a conditional block and requires a
2469 /// mask.
2470 bool HasMask = false;
2471
2472 /// Indicates if gaps between members of the group need to be masked out or if
2473 /// unusued gaps can be loaded speculatively.
2474 bool NeedsMaskForGaps = false;
2475
2476protected:
2477 VPInterleaveBase(const unsigned char SC,
2479 ArrayRef<VPValue *> Operands,
2480 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2481 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2482 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(MD), IG(IG),
2483 NeedsMaskForGaps(NeedsMaskForGaps) {
2484 // TODO: extend the masked interleaved-group support to reversed access.
2485 assert((!Mask || !IG->isReverse()) &&
2486 "Reversed masked interleave-group not supported.");
2487 for (unsigned I = 0; I < IG->getFactor(); ++I)
2488 if (Instruction *Inst = IG->getMember(I)) {
2489 if (Inst->getType()->isVoidTy())
2490 continue;
2491 new VPValue(Inst, this);
2492 }
2493
2494 for (auto *SV : StoredValues)
2495 addOperand(SV);
2496 if (Mask) {
2497 HasMask = true;
2498 addOperand(Mask);
2499 }
2500 }
2501
2502public:
2503 VPInterleaveBase *clone() override = 0;
2504
2505 static inline bool classof(const VPRecipeBase *R) {
2506 return R->getVPDefID() == VPRecipeBase::VPInterleaveSC ||
2507 R->getVPDefID() == VPRecipeBase::VPInterleaveEVLSC;
2508 }
2509
2510 static inline bool classof(const VPUser *U) {
2511 auto *R = dyn_cast<VPRecipeBase>(U);
2512 return R && classof(R);
2513 }
2514
2515 /// Return the address accessed by this recipe.
2516 VPValue *getAddr() const {
2517 return getOperand(0); // Address is the 1st, mandatory operand.
2518 }
2519
2520 /// Return the mask used by this recipe. Note that a full mask is represented
2521 /// by a nullptr.
2522 VPValue *getMask() const {
2523 // Mask is optional and the last operand.
2524 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2525 }
2526
2527 /// Return true if the access needs a mask because of the gaps.
2528 bool needsMaskForGaps() const { return NeedsMaskForGaps; }
2529
2531
2532 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2533
2534 void execute(VPTransformState &State) override {
2535 llvm_unreachable("VPInterleaveBase should not be instantiated.");
2536 }
2537
2538 /// Return the cost of this recipe.
2539 InstructionCost computeCost(ElementCount VF,
2540 VPCostContext &Ctx) const override;
2541
2542 /// Returns true if the recipe only uses the first lane of operand \p Op.
2543 virtual bool onlyFirstLaneUsed(const VPValue *Op) const override = 0;
2544
2545 /// Returns the number of stored operands of this interleave group. Returns 0
2546 /// for load interleave groups.
2547 virtual unsigned getNumStoreOperands() const = 0;
2548
2549 /// Return the VPValues stored by this interleave group. If it is a load
2550 /// interleave group, return an empty ArrayRef.
2552 return ArrayRef<VPValue *>(op_end() -
2553 (getNumStoreOperands() + (HasMask ? 1 : 0)),
2555 }
2556};
2557
2558/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2559/// or stores into one wide load/store and shuffles. The first operand of a
2560/// VPInterleave recipe is the address, followed by the stored values, followed
2561/// by an optional mask.
2563public:
2565 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2566 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2567 : VPInterleaveBase(VPDef::VPInterleaveSC, IG, Addr, StoredValues, Mask,
2568 NeedsMaskForGaps, MD, DL) {}
2569
2570 ~VPInterleaveRecipe() override = default;
2571
2575 needsMaskForGaps(), *this, getDebugLoc());
2576 }
2577
2578 VP_CLASSOF_IMPL(VPDef::VPInterleaveSC)
2579
2580 /// Generate the wide load or store, and shuffles.
2581 void execute(VPTransformState &State) override;
2582
2583#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2584 /// Print the recipe.
2585 void print(raw_ostream &O, const Twine &Indent,
2586 VPSlotTracker &SlotTracker) const override;
2587#endif
2588
2589 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2591 "Op must be an operand of the recipe");
2592 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2593 }
2594
2595 unsigned getNumStoreOperands() const override {
2596 return getNumOperands() - (getMask() ? 2 : 1);
2597 }
2598};
2599
2600/// A recipe for interleaved memory operations with vector-predication
2601/// intrinsics. The first operand is the address, the second operand is the
2602/// explicit vector length. Stored values and mask are optional operands.
2604public:
2606 : VPInterleaveBase(VPDef::VPInterleaveEVLSC, R.getInterleaveGroup(),
2607 ArrayRef<VPValue *>({R.getAddr(), &EVL}),
2608 R.getStoredValues(), Mask, R.needsMaskForGaps(), R,
2609 R.getDebugLoc()) {
2610 assert(!getInterleaveGroup()->isReverse() &&
2611 "Reversed interleave-group with tail folding is not supported.");
2612 assert(!needsMaskForGaps() && "Interleaved access with gap mask is not "
2613 "supported for scalable vector.");
2614 }
2615
2616 ~VPInterleaveEVLRecipe() override = default;
2617
2619 llvm_unreachable("cloning not implemented yet");
2620 }
2621
2622 VP_CLASSOF_IMPL(VPDef::VPInterleaveEVLSC)
2623
2624 /// The VPValue of the explicit vector length.
2625 VPValue *getEVL() const { return getOperand(1); }
2626
2627 /// Generate the wide load or store, and shuffles.
2628 void execute(VPTransformState &State) override;
2629
2630#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2631 /// Print the recipe.
2632 void print(raw_ostream &O, const Twine &Indent,
2633 VPSlotTracker &SlotTracker) const override;
2634#endif
2635
2636 /// The recipe only uses the first lane of the address, and EVL operand.
2637 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2639 "Op must be an operand of the recipe");
2640 return (Op == getAddr() && !llvm::is_contained(getStoredValues(), Op)) ||
2641 Op == getEVL();
2642 }
2643
2644 unsigned getNumStoreOperands() const override {
2645 return getNumOperands() - (getMask() ? 3 : 2);
2646 }
2647};
2648
2649/// A recipe to represent inloop reduction operations, performing a reduction on
2650/// a vector operand into a scalar value, and adding the result to a chain.
2651/// The Operands are {ChainOp, VecOp, [Condition]}.
2653 /// The recurrence kind for the reduction in question.
2654 RecurKind RdxKind;
2655 bool IsOrdered;
2656 /// Whether the reduction is conditional.
2657 bool IsConditional = false;
2658
2659protected:
2660 VPReductionRecipe(const unsigned char SC, RecurKind RdxKind,
2663 bool IsOrdered, DebugLoc DL)
2664 : VPRecipeWithIRFlags(SC, Operands, FMFs, DL), RdxKind(RdxKind),
2665 IsOrdered(IsOrdered) {
2666 if (CondOp) {
2667 IsConditional = true;
2668 addOperand(CondOp);
2669 }
2671 }
2672
2673public:
2675 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2676 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2677 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, I,
2678 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2679 IsOrdered, DL) {}
2680
2682 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2683 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2684 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, nullptr,
2685 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2686 IsOrdered, DL) {}
2687
2688 ~VPReductionRecipe() override = default;
2689
2691 return new VPReductionRecipe(RdxKind, getFastMathFlags(),
2693 getCondOp(), IsOrdered, getDebugLoc());
2694 }
2695
2696 static inline bool classof(const VPRecipeBase *R) {
2697 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2698 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC;
2699 }
2700
2701 static inline bool classof(const VPUser *U) {
2702 auto *R = dyn_cast<VPRecipeBase>(U);
2703 return R && classof(R);
2704 }
2705
2706 /// Generate the reduction in the loop.
2707 void execute(VPTransformState &State) override;
2708
2709 /// Return the cost of VPReductionRecipe.
2710 InstructionCost computeCost(ElementCount VF,
2711 VPCostContext &Ctx) const override;
2712
2713#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2714 /// Print the recipe.
2715 void print(raw_ostream &O, const Twine &Indent,
2716 VPSlotTracker &SlotTracker) const override;
2717#endif
2718
2719 /// Return the recurrence kind for the in-loop reduction.
2720 RecurKind getRecurrenceKind() const { return RdxKind; }
2721 /// Return true if the in-loop reduction is ordered.
2722 bool isOrdered() const { return IsOrdered; };
2723 /// Return true if the in-loop reduction is conditional.
2724 bool isConditional() const { return IsConditional; };
2725 /// The VPValue of the scalar Chain being accumulated.
2726 VPValue *getChainOp() const { return getOperand(0); }
2727 /// The VPValue of the vector value to be reduced.
2728 VPValue *getVecOp() const { return getOperand(1); }
2729 /// The VPValue of the condition for the block.
2731 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2732 }
2733};
2734
2735/// A recipe for forming partial reductions. In the loop, an accumulator and
2736/// vector operand are added together and passed to the next iteration as the
2737/// next accumulator. After the loop body, the accumulator is reduced to a
2738/// scalar value.
2740 unsigned Opcode;
2741
2742 /// The divisor by which the VF of this recipe's output should be divided
2743 /// during execution.
2744 unsigned VFScaleFactor;
2745
2746public:
2748 VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
2749 : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1, Cond,
2750 VFScaleFactor, ReductionInst) {}
2751 VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
2752 VPValue *Cond, unsigned ScaleFactor,
2753 Instruction *ReductionInst = nullptr)
2754 : VPReductionRecipe(VPDef::VPPartialReductionSC, RecurKind::Add,
2755 FastMathFlags(), ReductionInst,
2756 ArrayRef<VPValue *>({Op0, Op1}), Cond, false, {}),
2757 Opcode(Opcode), VFScaleFactor(ScaleFactor) {
2758 [[maybe_unused]] auto *AccumulatorRecipe =
2760 assert((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2761 isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2762 "Unexpected operand order for partial reduction recipe");
2763 }
2764 ~VPPartialReductionRecipe() override = default;
2765
2767 return new VPPartialReductionRecipe(Opcode, getOperand(0), getOperand(1),
2768 getCondOp(), VFScaleFactor,
2770 }
2771
2772 VP_CLASSOF_IMPL(VPDef::VPPartialReductionSC)
2773
2774 /// Generate the reduction in the loop.
2775 void execute(VPTransformState &State) override;
2776
2777 /// Return the cost of this VPPartialReductionRecipe.
2779 VPCostContext &Ctx) const override;
2780
2781 /// Get the binary op's opcode.
2782 unsigned getOpcode() const { return Opcode; }
2783
2784 /// Get the factor that the VF of this recipe's output should be scaled by.
2785 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2786
2787#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2788 /// Print the recipe.
2789 void print(raw_ostream &O, const Twine &Indent,
2790 VPSlotTracker &SlotTracker) const override;
2791#endif
2792};
2793
2794/// A recipe to represent inloop reduction operations with vector-predication
2795/// intrinsics, performing a reduction on a vector operand with the explicit
2796/// vector length (EVL) into a scalar value, and adding the result to a chain.
2797/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2799public:
2803 VPDef::VPReductionEVLSC, R.getRecurrenceKind(),
2804 R.getFastMathFlags(),
2806 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2807 R.isOrdered(), DL) {}
2808
2809 ~VPReductionEVLRecipe() override = default;
2810
2812 llvm_unreachable("cloning not implemented yet");
2813 }
2814
2815 VP_CLASSOF_IMPL(VPDef::VPReductionEVLSC)
2816
2817 /// Generate the reduction in the loop
2818 void execute(VPTransformState &State) override;
2819
2820#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2821 /// Print the recipe.
2822 void print(raw_ostream &O, const Twine &Indent,
2823 VPSlotTracker &SlotTracker) const override;
2824#endif
2825
2826 /// The VPValue of the explicit vector length.
2827 VPValue *getEVL() const { return getOperand(2); }
2828
2829 /// Returns true if the recipe only uses the first lane of operand \p Op.
2830 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2832 "Op must be an operand of the recipe");
2833 return Op == getEVL();
2834 }
2835};
2836
2837/// VPReplicateRecipe replicates a given instruction producing multiple scalar
2838/// copies of the original scalar type, one per lane, instead of producing a
2839/// single copy of widened type for all lanes. If the instruction is known to be
2840/// a single scalar, only one copy, per lane zero, will be generated.
2842 public VPIRMetadata {
2843 /// Indicator if only a single replica per lane is needed.
2844 bool IsSingleScalar;
2845
2846 /// Indicator if the replicas are also predicated.
2847 bool IsPredicated;
2848
2849public:
2851 bool IsSingleScalar, VPValue *Mask = nullptr,
2852 VPIRMetadata Metadata = {})
2853 : VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
2854 VPIRMetadata(Metadata), IsSingleScalar(IsSingleScalar),
2855 IsPredicated(Mask) {
2856 if (Mask)
2857 addOperand(Mask);
2858 }
2859
2860 ~VPReplicateRecipe() override = default;
2861
2863 auto *Copy =
2864 new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsSingleScalar,
2865 isPredicated() ? getMask() : nullptr, *this);
2866 Copy->transferFlags(*this);
2867 return Copy;
2868 }
2869
2870 VP_CLASSOF_IMPL(VPDef::VPReplicateSC)
2871
2872 /// Generate replicas of the desired Ingredient. Replicas will be generated
2873 /// for all parts and lanes unless a specific part and lane are specified in
2874 /// the \p State.
2875 void execute(VPTransformState &State) override;
2876
2877 /// Return the cost of this VPReplicateRecipe.
2878 InstructionCost computeCost(ElementCount VF,
2879 VPCostContext &Ctx) const override;
2880
2881#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2882 /// Print the recipe.
2883 void print(raw_ostream &O, const Twine &Indent,
2884 VPSlotTracker &SlotTracker) const override;
2885#endif
2886
2887 bool isSingleScalar() const { return IsSingleScalar; }
2888
2889 bool isPredicated() const { return IsPredicated; }
2890
2891 /// Returns true if the recipe only uses the first lane of operand \p Op.
2892 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2894 "Op must be an operand of the recipe");
2895 return isSingleScalar();
2896 }
2897
2898 /// Returns true if the recipe uses scalars of operand \p Op.
2899 bool usesScalars(const VPValue *Op) const override {
2901 "Op must be an operand of the recipe");
2902 return true;
2903 }
2904
2905 /// Returns true if the recipe is used by a widened recipe via an intervening
2906 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
2907 /// in a vector.
2908 bool shouldPack() const;
2909
2910 /// Return the mask of a predicated VPReplicateRecipe.
2912 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
2913 return getOperand(getNumOperands() - 1);
2914 }
2915
2916 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
2917};
2918
2919/// A recipe for generating conditional branches on the bits of a mask.
2921public:
2923 : VPRecipeBase(VPDef::VPBranchOnMaskSC, {BlockInMask}, DL) {}
2924
2927 }
2928
2929 VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)
2930
2931 /// Generate the extraction of the appropriate bit from the block mask and the
2932 /// conditional branch.
2933 void execute(VPTransformState &State) override;
2934
2935 /// Return the cost of this VPBranchOnMaskRecipe.
2936 InstructionCost computeCost(ElementCount VF,
2937 VPCostContext &Ctx) const override;
2938
2939#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2940 /// Print the recipe.
2941 void print(raw_ostream &O, const Twine &Indent,
2942 VPSlotTracker &SlotTracker) const override {
2943 O << Indent << "BRANCH-ON-MASK ";
2945 }
2946#endif
2947
2948 /// Returns true if the recipe uses scalars of operand \p Op.
2949 bool usesScalars(const VPValue *Op) const override {
2951 "Op must be an operand of the recipe");
2952 return true;
2953 }
2954};
2955
2956/// A recipe to combine multiple recipes into a single 'expression' recipe,
2957/// which should be considered a single entity for cost-modeling and transforms.
2958/// The recipe needs to be 'decomposed', i.e. replaced by its individual
2959/// expression recipes, before execute. The individual expression recipes are
2960/// completely disconnected from the def-use graph of other recipes not part of
2961/// the expression. Def-use edges between pairs of expression recipes remain
2962/// intact, whereas every edge between an expression recipe and a recipe outside
2963/// the expression is elevated to connect the non-expression recipe with the
2964/// VPExpressionRecipe itself.
2965class VPExpressionRecipe : public VPSingleDefRecipe {
2966 /// Recipes included in this VPExpressionRecipe.
2967 SmallVector<VPSingleDefRecipe *> ExpressionRecipes;
2968
2969 /// Temporary VPValues used for external operands of the expression, i.e.
2970 /// operands not defined by recipes in the expression.
2971 SmallVector<VPValue *> LiveInPlaceholders;
2972
2973 enum class ExpressionTypes {
2974 /// Represents an inloop extended reduction operation, performing a
2975 /// reduction on an extended vector operand into a scalar value, and adding
2976 /// the result to a chain.
2977 ExtendedReduction,
2978 /// Represent an inloop multiply-accumulate reduction, multiplying the
2979 /// extended vector operands, performing a reduction.add on the result, and
2980 /// adding the scalar result to a chain.
2981 ExtMulAccReduction,
2982 /// Represent an inloop multiply-accumulate reduction, multiplying the
2983 /// vector operands, performing a reduction.add on the result, and adding
2984 /// the scalar result to a chain.
2985 MulAccReduction,
2986 };
2987
2988 /// Type of the expression.
2989 ExpressionTypes ExpressionType;
2990
2991 /// Construct a new VPExpressionRecipe by internalizing recipes in \p
2992 /// ExpressionRecipes. External operands (i.e. not defined by another recipe
2993 /// in the expression) are replaced by temporary VPValues and the original
2994 /// operands are transferred to the VPExpressionRecipe itself. Clone recipes
2995 /// as needed (excluding last) to ensure they are only used by other recipes
2996 /// in the expression.
2997 VPExpressionRecipe(ExpressionTypes ExpressionType,
2998 ArrayRef<VPSingleDefRecipe *> ExpressionRecipes);
2999
3000public:
3002 : VPExpressionRecipe(ExpressionTypes::ExtendedReduction, {Ext, Red}) {}
3004 : VPExpressionRecipe(ExpressionTypes::MulAccReduction, {Mul, Red}) {}
3007 : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction,
3008 {Ext0, Ext1, Mul, Red}) {}
3009
3011 for (auto *R : reverse(ExpressionRecipes))
3012 delete R;
3013 for (VPValue *T : LiveInPlaceholders)
3014 delete T;
3015 }
3016
3017 VP_CLASSOF_IMPL(VPDef::VPExpressionSC)
3018
3019 VPExpressionRecipe *clone() override {
3020 assert(!ExpressionRecipes.empty() && "empty expressions should be removed");
3021 SmallVector<VPSingleDefRecipe *> NewExpressiondRecipes;
3022 for (auto *R : ExpressionRecipes)
3023 NewExpressiondRecipes.push_back(R->clone());
3024 for (auto *New : NewExpressiondRecipes) {
3025 for (const auto &[Idx, Old] : enumerate(ExpressionRecipes))
3026 New->replaceUsesOfWith(Old, NewExpressiondRecipes[Idx]);
3027 // Update placeholder operands in the cloned recipe to use the external
3028 // operands, to be internalized when the cloned expression is constructed.
3029 for (const auto &[Placeholder, OutsideOp] :
3030 zip(LiveInPlaceholders, operands()))
3031 New->replaceUsesOfWith(Placeholder, OutsideOp);
3032 }
3033 return new VPExpressionRecipe(ExpressionType, NewExpressiondRecipes);
3034 }
3035
3036 /// Return the VPValue to use to infer the result type of the recipe.
3038 unsigned OpIdx =
3039 cast<VPReductionRecipe>(ExpressionRecipes.back())->isConditional() ? 2
3040 : 1;
3041 return getOperand(getNumOperands() - OpIdx);
3042 }
3043
3044 /// Insert the recipes of the expression back into the VPlan, directly before
3045 /// the current recipe. Leaves the expression recipe empty, which must be
3046 /// removed before codegen.
3047 void decompose();
3048
3049 /// Method for generating code, must not be called as this recipe is abstract.
3050 void execute(VPTransformState &State) override {
3051 llvm_unreachable("recipe must be removed before execute");
3052 }
3053
3055 VPCostContext &Ctx) const override;
3056
3057#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3058 /// Print the recipe.
3059 void print(raw_ostream &O, const Twine &Indent,
3060 VPSlotTracker &SlotTracker) const override;
3061#endif
3062
3063 /// Returns true if this expression contains recipes that may read from or
3064 /// write to memory.
3065 bool mayReadOrWriteMemory() const;
3066
3067 /// Returns true if this expression contains recipes that may have side
3068 /// effects.
3069 bool mayHaveSideEffects() const;
3070};
3071
3072/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
3073/// control converges back from a Branch-on-Mask. The phi nodes are needed in
3074/// order to merge values that are set under such a branch and feed their uses.
3075/// The phi nodes can be scalar or vector depending on the users of the value.
3076/// This recipe works in concert with VPBranchOnMaskRecipe.
3078public:
3079 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
3080 /// nodes after merging back from a Branch-on-Mask.
3082 : VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
3083 ~VPPredInstPHIRecipe() override = default;
3084
3086 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
3087 }
3088
3089 VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)
3090
3091 /// Generates phi nodes for live-outs (from a replicate region) as needed to
3092 /// retain SSA form.
3093 void execute(VPTransformState &State) override;
3094
3095 /// Return the cost of this VPPredInstPHIRecipe.
3097 VPCostContext &Ctx) const override {
3098 // TODO: Compute accurate cost after retiring the legacy cost model.
3099 return 0;
3100 }
3101
3102#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3103 /// Print the recipe.
3104 void print(raw_ostream &O, const Twine &Indent,
3105 VPSlotTracker &SlotTracker) const override;
3106#endif
3107
3108 /// Returns true if the recipe uses scalars of operand \p Op.
3109 bool usesScalars(const VPValue *Op) const override {
3111 "Op must be an operand of the recipe");
3112 return true;
3113 }
3114};
3115
3116/// A common base class for widening memory operations. An optional mask can be
3117/// provided as the last operand.
3119 public VPIRMetadata {
3120protected:
3122
3123 /// Whether the accessed addresses are consecutive.
3125
3126 /// Whether the consecutive accessed addresses are in reverse order.
3128
3129 /// Whether the memory access is masked.
3130 bool IsMasked = false;
3131
3132 void setMask(VPValue *Mask) {
3133 assert(!IsMasked && "cannot re-set mask");
3134 if (!Mask)
3135 return;
3136 addOperand(Mask);
3137 IsMasked = true;
3138 }
3139
3140 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
3141 std::initializer_list<VPValue *> Operands,
3142 bool Consecutive, bool Reverse,
3143 const VPIRMetadata &Metadata, DebugLoc DL)
3144 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
3146 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
3147 }
3148
3149public:
3151 llvm_unreachable("cloning not supported");
3152 }
3153
3154 static inline bool classof(const VPRecipeBase *R) {
3155 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
3156 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
3157 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
3158 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
3159 }
3160
3161 static inline bool classof(const VPUser *U) {
3162 auto *R = dyn_cast<VPRecipeBase>(U);
3163 return R && classof(R);
3164 }
3165
3166 /// Return whether the loaded-from / stored-to addresses are consecutive.
3167 bool isConsecutive() const { return Consecutive; }
3168
3169 /// Return whether the consecutive loaded/stored addresses are in reverse
3170 /// order.
3171 bool isReverse() const { return Reverse; }
3172
3173 /// Return the address accessed by this recipe.
3174 VPValue *getAddr() const { return getOperand(0); }
3175
3176 /// Returns true if the recipe is masked.
3177 bool isMasked() const { return IsMasked; }
3178
3179 /// Return the mask used by this recipe. Note that a full mask is represented
3180 /// by a nullptr.
3181 VPValue *getMask() const {
3182 // Mask is optional and therefore the last operand.
3183 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
3184 }
3185
3186 /// Generate the wide load/store.
3187 void execute(VPTransformState &State) override {
3188 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
3189 }
3190
3191 /// Return the cost of this VPWidenMemoryRecipe.
3192 InstructionCost computeCost(ElementCount VF,
3193 VPCostContext &Ctx) const override;
3194
3196};
3197
3198/// A recipe for widening load operations, using the address to load from and an
3199/// optional mask.
3201 public VPValue {
3203 bool Consecutive, bool Reverse,
3204 const VPIRMetadata &Metadata, DebugLoc DL)
3205 : VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
3206 Reverse, Metadata, DL),
3207 VPValue(this, &Load) {
3208 setMask(Mask);
3209 }
3210
3213 getMask(), Consecutive, Reverse, *this,
3214 getDebugLoc());
3215 }
3216
3217 VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC);
3218
3219 /// Generate a wide load or gather.
3220 void execute(VPTransformState &State) override;
3221
3222#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3223 /// Print the recipe.
3224 void print(raw_ostream &O, const Twine &Indent,
3225 VPSlotTracker &SlotTracker) const override;
3226#endif
3227
3228 /// Returns true if the recipe only uses the first lane of operand \p Op.
3229 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3231 "Op must be an operand of the recipe");
3232 // Widened, consecutive loads operations only demand the first lane of
3233 // their address.
3234 return Op == getAddr() && isConsecutive();
3235 }
3236};
3237
3238/// A recipe for widening load operations with vector-predication intrinsics,
3239/// using the address to load from, the explicit vector length and an optional
3240/// mask.
3241struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
3243 VPValue *Mask)
3244 : VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
3245 {Addr, &EVL}, L.isConsecutive(), L.isReverse(), L,
3246 L.getDebugLoc()),
3247 VPValue(this, &getIngredient()) {
3248 setMask(Mask);
3249 }
3250
3251 VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
3252
3253 /// Return the EVL operand.
3254 VPValue *getEVL() const { return getOperand(1); }
3255
3256 /// Generate the wide load or gather.
3257 void execute(VPTransformState &State) override;
3258
3259 /// Return the cost of this VPWidenLoadEVLRecipe.
3261 VPCostContext &Ctx) const override;
3262
3263#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3264 /// Print the recipe.
3265 void print(raw_ostream &O, const Twine &Indent,
3266 VPSlotTracker &SlotTracker) const override;
3267#endif
3268
3269 /// Returns true if the recipe only uses the first lane of operand \p Op.
3270 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3272 "Op must be an operand of the recipe");
3273 // Widened loads only demand the first lane of EVL and consecutive loads
3274 // only demand the first lane of their address.
3275 return Op == getEVL() || (Op == getAddr() && isConsecutive());
3276 }
3277};
3278
3279/// A recipe for widening store operations, using the stored value, the address
3280/// to store to and an optional mask.
3282 VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
3283 VPValue *Mask, bool Consecutive, bool Reverse,
3284 const VPIRMetadata &Metadata, DebugLoc DL)
3285 : VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
3286 Consecutive, Reverse, Metadata, DL) {
3287 setMask(Mask);
3288 }
3289
3295
3296 VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
3297
3298 /// Return the value stored by this recipe.
3299 VPValue *getStoredValue() const { return getOperand(1); }
3300
3301 /// Generate a wide store or scatter.
3302 void execute(VPTransformState &State) override;
3303
3304#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3305 /// Print the recipe.
3306 void print(raw_ostream &O, const Twine &Indent,
3307 VPSlotTracker &SlotTracker) const override;
3308#endif
3309
3310 /// Returns true if the recipe only uses the first lane of operand \p Op.
3311 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3313 "Op must be an operand of the recipe");
3314 // Widened, consecutive stores only demand the first lane of their address,
3315 // unless the same operand is also stored.
3316 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3317 }
3318};
3319
3320/// A recipe for widening store operations with vector-predication intrinsics,
3321/// using the value to store, the address to store to, the explicit vector
3322/// length and an optional mask.
3325 VPValue *Mask)
3326 : VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
3327 {Addr, S.getStoredValue(), &EVL}, S.isConsecutive(),
3328 S.isReverse(), S, S.getDebugLoc()) {
3329 setMask(Mask);
3330 }
3331
3332 VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
3333
3334 /// Return the address accessed by this recipe.
3335 VPValue *getStoredValue() const { return getOperand(1); }
3336
3337 /// Return the EVL operand.
3338 VPValue *getEVL() const { return getOperand(2); }
3339
3340 /// Generate the wide store or scatter.
3341 void execute(VPTransformState &State) override;
3342
3343 /// Return the cost of this VPWidenStoreEVLRecipe.
3345 VPCostContext &Ctx) const override;
3346
3347#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3348 /// Print the recipe.
3349 void print(raw_ostream &O, const Twine &Indent,
3350 VPSlotTracker &SlotTracker) const override;
3351#endif
3352
3353 /// Returns true if the recipe only uses the first lane of operand \p Op.
3354 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3356 "Op must be an operand of the recipe");
3357 if (Op == getEVL()) {
3358 assert(getStoredValue() != Op && "unexpected store of EVL");
3359 return true;
3360 }
3361 // Widened, consecutive memory operations only demand the first lane of
3362 // their address, unless the same operand is also stored. That latter can
3363 // happen with opaque pointers.
3364 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3365 }
3366};
3367
3368/// Recipe to expand a SCEV expression.
3370 const SCEV *Expr;
3371
3372public:
3374 : VPSingleDefRecipe(VPDef::VPExpandSCEVSC, {}), Expr(Expr) {}
3375
3376 ~VPExpandSCEVRecipe() override = default;
3377
3378 VPExpandSCEVRecipe *clone() override { return new VPExpandSCEVRecipe(Expr); }
3379
3380 VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)
3381
3382 void execute(VPTransformState &State) override {
3383 llvm_unreachable("SCEV expressions must be expanded before final execute");
3384 }
3385
3386 /// Return the cost of this VPExpandSCEVRecipe.
3388 VPCostContext &Ctx) const override {
3389 // TODO: Compute accurate cost after retiring the legacy cost model.
3390 return 0;
3391 }
3392
3393#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3394 /// Print the recipe.
3395 void print(raw_ostream &O, const Twine &Indent,
3396 VPSlotTracker &SlotTracker) const override;
3397#endif
3398
3399 const SCEV *getSCEV() const { return Expr; }
3400};
3401
3402/// Canonical scalar induction phi of the vector loop. Starting at the specified
3403/// start value (either 0 or the resume value when vectorizing the epilogue
3404/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
3405/// canonical induction variable.
3407public:
3409 : VPHeaderPHIRecipe(VPDef::VPCanonicalIVPHISC, nullptr, StartV, DL) {}
3410
3411 ~VPCanonicalIVPHIRecipe() override = default;
3412
3414 auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
3415 R->addOperand(getBackedgeValue());
3416 return R;
3417 }
3418
3419 VP_CLASSOF_IMPL(VPDef::VPCanonicalIVPHISC)
3420
3421 void execute(VPTransformState &State) override {
3422 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3423 "scalar phi recipe");
3424 }
3425
3426#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3427 /// Print the recipe.
3428 void print(raw_ostream &O, const Twine &Indent,
3429 VPSlotTracker &SlotTracker) const override;
3430#endif
3431
3432 /// Returns the scalar type of the induction.
3434 return getStartValue()->getLiveInIRValue()->getType();
3435 }
3436
3437 /// Returns true if the recipe only uses the first lane of operand \p Op.
3438 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3440 "Op must be an operand of the recipe");
3441 return true;
3442 }
3443
3444 /// Returns true if the recipe only uses the first part of operand \p Op.
3445 bool onlyFirstPartUsed(const VPValue *Op) const override {
3447 "Op must be an operand of the recipe");
3448 return true;
3449 }
3450
3451 /// Return the cost of this VPCanonicalIVPHIRecipe.
3453 VPCostContext &Ctx) const override {
3454 // For now, match the behavior of the legacy cost model.
3455 return 0;
3456 }
3457};
3458
3459/// A recipe for generating the active lane mask for the vector loop that is
3460/// used to predicate the vector operations.
3461/// TODO: It would be good to use the existing VPWidenPHIRecipe instead and
3462/// remove VPActiveLaneMaskPHIRecipe.
3464public:
3466 : VPHeaderPHIRecipe(VPDef::VPActiveLaneMaskPHISC, nullptr, StartMask,
3467 DL) {}
3468
3469 ~VPActiveLaneMaskPHIRecipe() override = default;
3470
3473 if (getNumOperands() == 2)
3474 R->addOperand(getOperand(1));
3475 return R;
3476 }
3477
3478 VP_CLASSOF_IMPL(VPDef::VPActiveLaneMaskPHISC)
3479
3480 /// Generate the active lane mask phi of the vector loop.
3481 void execute(VPTransformState &State) override;
3482
3483#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3484 /// Print the recipe.
3485 void print(raw_ostream &O, const Twine &Indent,
3486 VPSlotTracker &SlotTracker) const override;
3487#endif
3488};
3489
3490/// A recipe for generating the phi node for the current index of elements,
3491/// adjusted in accordance with EVL value. It starts at the start value of the
3492/// canonical induction and gets incremented by EVL in each iteration of the
3493/// vector loop.
3495public:
3497 : VPHeaderPHIRecipe(VPDef::VPEVLBasedIVPHISC, nullptr, StartIV, DL) {}
3498
3499 ~VPEVLBasedIVPHIRecipe() override = default;
3500
3502 llvm_unreachable("cloning not implemented yet");
3503 }
3504
3505 VP_CLASSOF_IMPL(VPDef::VPEVLBasedIVPHISC)
3506
3507 void execute(VPTransformState &State) override {
3508 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3509 "scalar phi recipe");
3510 }
3511
3512 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3514 VPCostContext &Ctx) const override {
3515 // For now, match the behavior of the legacy cost model.
3516 return 0;
3517 }
3518
3519 /// Returns true if the recipe only uses the first lane of operand \p Op.
3520 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3522 "Op must be an operand of the recipe");
3523 return true;
3524 }
3525
3526#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3527 /// Print the recipe.
3528 void print(raw_ostream &O, const Twine &Indent,
3529 VPSlotTracker &SlotTracker) const override;
3530#endif
3531};
3532
3533/// A Recipe for widening the canonical induction variable of the vector loop.
3535 public VPUnrollPartAccessor<1> {
3536public:
3538 : VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3539
3540 ~VPWidenCanonicalIVRecipe() override = default;
3541
3546
3547 VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC)
3548
3549 /// Generate a canonical vector induction variable of the vector loop, with
3550 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3551 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3552 void execute(VPTransformState &State) override;
3553
3554 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3556 VPCostContext &Ctx) const override {
3557 // TODO: Compute accurate cost after retiring the legacy cost model.
3558 return 0;
3559 }
3560
3561#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3562 /// Print the recipe.
3563 void print(raw_ostream &O, const Twine &Indent,
3564 VPSlotTracker &SlotTracker) const override;
3565#endif
3566};
3567
3568/// A recipe for converting the input value \p IV value to the corresponding
3569/// value of an IV with different start and step values, using Start + IV *
3570/// Step.
3572 /// Kind of the induction.
3574 /// If not nullptr, the floating point induction binary operator. Must be set
3575 /// for floating point inductions.
3576 const FPMathOperator *FPBinOp;
3577
3578 /// Name to use for the generated IR instruction for the derived IV.
3579 std::string Name;
3580
3581public:
3583 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3584 const Twine &Name = "")
3586 IndDesc.getKind(),
3587 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3588 Start, CanonicalIV, Step, Name) {}
3589
3591 const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3592 VPValue *Step, const Twine &Name = "")
3593 : VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3594 FPBinOp(FPBinOp), Name(Name.str()) {}
3595
3596 ~VPDerivedIVRecipe() override = default;
3597
3599 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3600 getStepValue());
3601 }
3602
3603 VP_CLASSOF_IMPL(VPDef::VPDerivedIVSC)
3604
3605 /// Generate the transformed value of the induction at offset StartValue (1.
3606 /// operand) + IV (2. operand) * StepValue (3, operand).
3607 void execute(VPTransformState &State) override;
3608
3609 /// Return the cost of this VPDerivedIVRecipe.
3611 VPCostContext &Ctx) const override {
3612 // TODO: Compute accurate cost after retiring the legacy cost model.
3613 return 0;
3614 }
3615
3616#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3617 /// Print the recipe.
3618 void print(raw_ostream &O, const Twine &Indent,
3619 VPSlotTracker &SlotTracker) const override;
3620#endif
3621
3623 return getStartValue()->getLiveInIRValue()->getType();
3624 }
3625
3626 VPValue *getStartValue() const { return getOperand(0); }
3627 VPValue *getStepValue() const { return getOperand(2); }
3628
3629 /// Returns true if the recipe only uses the first lane of operand \p Op.
3630 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3632 "Op must be an operand of the recipe");
3633 return true;
3634 }
3635};
3636
3637/// A recipe for handling phi nodes of integer and floating-point inductions,
3638/// producing their scalar values.
3640 public VPUnrollPartAccessor<3> {
3641 Instruction::BinaryOps InductionOpcode;
3642
3643public:
3646 DebugLoc DL)
3647 : VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
3648 ArrayRef<VPValue *>({IV, Step, VF}), FMFs, DL),
3649 InductionOpcode(Opcode) {}
3650
3652 VPValue *Step, VPValue *VF,
3655 IV, Step, VF, IndDesc.getInductionOpcode(),
3656 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3657 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3658 : FastMathFlags(),
3659 DL) {}
3660
3661 ~VPScalarIVStepsRecipe() override = default;
3662
3664 return new VPScalarIVStepsRecipe(
3665 getOperand(0), getOperand(1), getOperand(2), InductionOpcode,
3667 getDebugLoc());
3668 }
3669
3670 /// Return true if this VPScalarIVStepsRecipe corresponds to part 0. Note that
3671 /// this is only accurate after the VPlan has been unrolled.
3672 bool isPart0() const { return getUnrollPart(*this) == 0; }
3673
3674 VP_CLASSOF_IMPL(VPDef::VPScalarIVStepsSC)
3675
3676 /// Generate the scalarized versions of the phi node as needed by their users.
3677 void execute(VPTransformState &State) override;
3678
3679 /// Return the cost of this VPScalarIVStepsRecipe.
3681 VPCostContext &Ctx) const override {
3682 // TODO: Compute accurate cost after retiring the legacy cost model.
3683 return 0;
3684 }
3685
3686#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3687 /// Print the recipe.
3688 void print(raw_ostream &O, const Twine &Indent,
3689 VPSlotTracker &SlotTracker) const override;
3690#endif
3691
3692 VPValue *getStepValue() const { return getOperand(1); }
3693
3694 /// Returns true if the recipe only uses the first lane of operand \p Op.
3695 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3697 "Op must be an operand of the recipe");
3698 return true;
3699 }
3700};
3701
3702/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
3703/// types implementing VPPhiAccessors. Used by isa<> & co.
3705 static inline bool isPossible(const VPRecipeBase *f) {
3706 // TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
3708 }
3709};
3710/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
3711/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
3712template <typename SrcTy>
3713struct CastInfoVPPhiAccessors : public CastIsPossible<VPPhiAccessors, SrcTy> {
3714
3716
3717 /// doCast is used by cast<>.
3718 static inline VPPhiAccessors *doCast(SrcTy R) {
3719 return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
3720 switch (R->getVPDefID()) {
3721 case VPDef::VPInstructionSC:
3722 return cast<VPPhi>(R);
3723 case VPDef::VPIRInstructionSC:
3724 return cast<VPIRPhi>(R);
3725 case VPDef::VPWidenPHISC:
3726 return cast<VPWidenPHIRecipe>(R);
3727 default:
3728 return cast<VPHeaderPHIRecipe>(R);
3729 }
3730 }());
3731 }
3732
3733 /// doCastIfPossible is used by dyn_cast<>.
3734 static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
3735 if (!Self::isPossible(f))
3736 return nullptr;
3737 return doCast(f);
3738 }
3739};
3740template <>
3743template <>
3746
3747/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
3748/// holds a sequence of zero or more VPRecipe's each representing a sequence of
3749/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
3750class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
3751 friend class VPlan;
3752
3753 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3754 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3755 : VPBlockBase(VPBasicBlockSC, Name.str()) {
3756 if (Recipe)
3757 appendRecipe(Recipe);
3758 }
3759
3760public:
3762
3763protected:
3764 /// The VPRecipes held in the order of output instructions to generate.
3766
3767 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
3768 : VPBlockBase(BlockSC, Name.str()) {}
3769
3770public:
3771 ~VPBasicBlock() override {
3772 while (!Recipes.empty())
3773 Recipes.pop_back();
3774 }
3775
3776 /// Instruction iterators...
3781
3782 //===--------------------------------------------------------------------===//
3783 /// Recipe iterator methods
3784 ///
3785 inline iterator begin() { return Recipes.begin(); }
3786 inline const_iterator begin() const { return Recipes.begin(); }
3787 inline iterator end() { return Recipes.end(); }
3788 inline const_iterator end() const { return Recipes.end(); }
3789
3790 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
3791 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
3792 inline reverse_iterator rend() { return Recipes.rend(); }
3793 inline const_reverse_iterator rend() const { return Recipes.rend(); }
3794
3795 inline size_t size() const { return Recipes.size(); }
3796 inline bool empty() const { return Recipes.empty(); }
3797 inline const VPRecipeBase &front() const { return Recipes.front(); }
3798 inline VPRecipeBase &front() { return Recipes.front(); }
3799 inline const VPRecipeBase &back() const { return Recipes.back(); }
3800 inline VPRecipeBase &back() { return Recipes.back(); }
3801
3802 /// Returns a reference to the list of recipes.
3804
3805 /// Returns a pointer to a member of the recipe list.
3806 static RecipeListTy VPBasicBlock::*getSublistAccess(VPRecipeBase *) {
3807 return &VPBasicBlock::Recipes;
3808 }
3809
3810 /// Method to support type inquiry through isa, cast, and dyn_cast.
3811 static inline bool classof(const VPBlockBase *V) {
3812 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3813 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3814 }
3815
3816 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
3817 assert(Recipe && "No recipe to append.");
3818 assert(!Recipe->Parent && "Recipe already in VPlan");
3819 Recipe->Parent = this;
3820 Recipes.insert(InsertPt, Recipe);
3821 }
3822
3823 /// Augment the existing recipes of a VPBasicBlock with an additional
3824 /// \p Recipe as the last recipe.
3825 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
3826
3827 /// The method which generates the output IR instructions that correspond to
3828 /// this VPBasicBlock, thereby "executing" the VPlan.
3829 void execute(VPTransformState *State) override;
3830
3831 /// Return the cost of this VPBasicBlock.
3832 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
3833
3834 /// Return the position of the first non-phi node recipe in the block.
3835 iterator getFirstNonPhi();
3836
3837 /// Returns an iterator range over the PHI-like recipes in the block.
3841
3842 /// Split current block at \p SplitAt by inserting a new block between the
3843 /// current block and its successors and moving all recipes starting at
3844 /// SplitAt to the new block. Returns the new block.
3845 VPBasicBlock *splitAt(iterator SplitAt);
3846
3847 VPRegionBlock *getEnclosingLoopRegion();
3848 const VPRegionBlock *getEnclosingLoopRegion() const;
3849
3850#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3851 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
3852 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
3853 ///
3854 /// Note that the numbering is applied to the whole VPlan, so printing
3855 /// individual blocks is consistent with the whole VPlan printing.
3856 void print(raw_ostream &O, const Twine &Indent,
3857 VPSlotTracker &SlotTracker) const override;
3858 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3859#endif
3860
3861 /// If the block has multiple successors, return the branch recipe terminating
3862 /// the block. If there are no or only a single successor, return nullptr;
3863 VPRecipeBase *getTerminator();
3864 const VPRecipeBase *getTerminator() const;
3865
3866 /// Returns true if the block is exiting it's parent region.
3867 bool isExiting() const;
3868
3869 /// Clone the current block and it's recipes, without updating the operands of
3870 /// the cloned recipes.
3871 VPBasicBlock *clone() override;
3872
3873 /// Returns the predecessor block at index \p Idx with the predecessors as per
3874 /// the corresponding plain CFG. If the block is an entry block to a region,
3875 /// the first predecessor is the single predecessor of a region, and the
3876 /// second predecessor is the exiting block of the region.
3877 const VPBasicBlock *getCFGPredecessor(unsigned Idx) const;
3878
3879protected:
3880 /// Execute the recipes in the IR basic block \p BB.
3881 void executeRecipes(VPTransformState *State, BasicBlock *BB);
3882
3883 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
3884 /// generated for this VPBB.
3885 void connectToPredecessors(VPTransformState &State);
3886
3887private:
3888 /// Create an IR BasicBlock to hold the output instructions generated by this
3889 /// VPBasicBlock, and return it. Update the CFGState accordingly.
3890 BasicBlock *createEmptyBasicBlock(VPTransformState &State);
3891};
3892
3893inline const VPBasicBlock *
3895 return getAsRecipe()->getParent()->getCFGPredecessor(Idx);
3896}
3897
3898/// A special type of VPBasicBlock that wraps an existing IR basic block.
3899/// Recipes of the block get added before the first non-phi instruction in the
3900/// wrapped block.
3901/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
3902/// preheader block.
3903class VPIRBasicBlock : public VPBasicBlock {
3904 friend class VPlan;
3905
3906 BasicBlock *IRBB;
3907
3908 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
3909 VPIRBasicBlock(BasicBlock *IRBB)
3910 : VPBasicBlock(VPIRBasicBlockSC,
3911 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
3912 IRBB(IRBB) {}
3913
3914public:
3915 ~VPIRBasicBlock() override {}
3916
3917 static inline bool classof(const VPBlockBase *V) {
3918 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3919 }
3920
3921 /// The method which generates the output IR instructions that correspond to
3922 /// this VPBasicBlock, thereby "executing" the VPlan.
3923 void execute(VPTransformState *State) override;
3924
3925 VPIRBasicBlock *clone() override;
3926
3927 BasicBlock *getIRBasicBlock() const { return IRBB; }
3928};
3929
3930/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
3931/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
3932/// A VPRegionBlock may indicate that its contents are to be replicated several
3933/// times. This is designed to support predicated scalarization, in which a
3934/// scalar if-then code structure needs to be generated VF * UF times. Having
3935/// this replication indicator helps to keep a single model for multiple
3936/// candidate VF's. The actual replication takes place only once the desired VF
3937/// and UF have been determined.
3938class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
3939 friend class VPlan;
3940
3941 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
3942 VPBlockBase *Entry;
3943
3944 /// Hold the Single Exiting block of the SESE region modelled by the
3945 /// VPRegionBlock.
3946 VPBlockBase *Exiting;
3947
3948 /// An indicator whether this region is to generate multiple replicated
3949 /// instances of output IR corresponding to its VPBlockBases.
3950 bool IsReplicator;
3951
3952 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
3953 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
3954 const std::string &Name = "", bool IsReplicator = false)
3955 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
3956 IsReplicator(IsReplicator) {
3957 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
3958 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
3959 Entry->setParent(this);
3960 Exiting->setParent(this);
3961 }
3962 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
3963 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3964 IsReplicator(IsReplicator) {}
3965
3966public:
3967 ~VPRegionBlock() override {}
3968
3969 /// Method to support type inquiry through isa, cast, and dyn_cast.
3970 static inline bool classof(const VPBlockBase *V) {
3971 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
3972 }
3973
3974 const VPBlockBase *getEntry() const { return Entry; }
3975 VPBlockBase *getEntry() { return Entry; }
3976
3977 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
3978 /// EntryBlock must have no predecessors.
3979 void setEntry(VPBlockBase *EntryBlock) {
3980 assert(EntryBlock->getPredecessors().empty() &&
3981 "Entry block cannot have predecessors.");
3982 Entry = EntryBlock;
3983 EntryBlock->setParent(this);
3984 }
3985
3986 const VPBlockBase *getExiting() const { return Exiting; }
3987 VPBlockBase *getExiting() { return Exiting; }
3988
3989 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
3990 /// ExitingBlock must have no successors.
3991 void setExiting(VPBlockBase *ExitingBlock) {
3992 assert(ExitingBlock->getSuccessors().empty() &&
3993 "Exit block cannot have successors.");
3994 Exiting = ExitingBlock;
3995 ExitingBlock->setParent(this);
3996 }
3997
3998 /// Returns the pre-header VPBasicBlock of the loop region.
4000 assert(!isReplicator() && "should only get pre-header of loop regions");
4001 return getSinglePredecessor()->getExitingBasicBlock();
4002 }
4003
4004 /// An indicator whether this region is to generate multiple replicated
4005 /// instances of output IR corresponding to its VPBlockBases.
4006 bool isReplicator() const { return IsReplicator; }
4007
4008 /// The method which generates the output IR instructions that correspond to
4009 /// this VPRegionBlock, thereby "executing" the VPlan.
4010 void execute(VPTransformState *State) override;
4011
4012 // Return the cost of this region.
4013 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
4014
4015#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4016 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
4017 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
4018 /// consequtive numbers.
4019 ///
4020 /// Note that the numbering is applied to the whole VPlan, so printing
4021 /// individual regions is consistent with the whole VPlan printing.
4022 void print(raw_ostream &O, const Twine &Indent,
4023 VPSlotTracker &SlotTracker) const override;
4024 using VPBlockBase::print; // Get the print(raw_stream &O) version.
4025#endif
4026
4027 /// Clone all blocks in the single-entry single-exit region of the block and
4028 /// their recipes without updating the operands of the cloned recipes.
4029 VPRegionBlock *clone() override;
4030
4031 /// Remove the current region from its VPlan, connecting its predecessor to
4032 /// its entry, and its exiting block to its successor.
4033 void dissolveToCFGLoop();
4034};
4035
4036/// VPlan models a candidate for vectorization, encoding various decisions take
4037/// to produce efficient output IR, including which branches, basic-blocks and
4038/// output IR instructions to generate, and their cost. VPlan holds a
4039/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
4040/// VPBasicBlock.
4041class VPlan {
4042 friend class VPlanPrinter;
4043 friend class VPSlotTracker;
4044
4045 /// VPBasicBlock corresponding to the original preheader. Used to place
4046 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
4047 /// rest of VPlan execution.
4048 /// When this VPlan is used for the epilogue vector loop, the entry will be
4049 /// replaced by a new entry block created during skeleton creation.
4050 VPBasicBlock *Entry;
4051
4052 /// VPIRBasicBlock wrapping the header of the original scalar loop.
4053 VPIRBasicBlock *ScalarHeader;
4054
4055 /// Immutable list of VPIRBasicBlocks wrapping the exit blocks of the original
4056 /// scalar loop. Note that some exit blocks may be unreachable at the moment,
4057 /// e.g. if the scalar epilogue always executes.
4059
4060 /// Holds the VFs applicable to this VPlan.
4062
4063 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
4064 /// any UF.
4066
4067 /// Holds the name of the VPlan, for printing.
4068 std::string Name;
4069
4070 /// Represents the trip count of the original loop, for folding
4071 /// the tail.
4072 VPValue *TripCount = nullptr;
4073
4074 /// Represents the backedge taken count of the original loop, for folding
4075 /// the tail. It equals TripCount - 1.
4076 VPValue *BackedgeTakenCount = nullptr;
4077
4078 /// Represents the vector trip count.
4079 VPValue VectorTripCount;
4080
4081 /// Represents the vectorization factor of the loop.
4082 VPValue VF;
4083
4084 /// Represents the loop-invariant VF * UF of the vector loop region.
4085 VPValue VFxUF;
4086
4087 /// Holds a mapping between Values and their corresponding VPValue inside
4088 /// VPlan.
4089 Value2VPValueTy Value2VPValue;
4090
4091 /// Contains all the external definitions created for this VPlan. External
4092 /// definitions are VPValues that hold a pointer to their underlying IR.
4094
4095 /// Mapping from SCEVs to the VPValues representing their expansions.
4096 /// NOTE: This mapping is temporary and will be removed once all users have
4097 /// been modeled in VPlan directly.
4098 DenseMap<const SCEV *, VPValue *> SCEVToExpansion;
4099
4100 /// Blocks allocated and owned by the VPlan. They will be deleted once the
4101 /// VPlan is destroyed.
4102 SmallVector<VPBlockBase *> CreatedBlocks;
4103
4104 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
4105 /// wrapping the original header of the scalar loop.
4106 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
4107 : Entry(Entry), ScalarHeader(ScalarHeader) {
4108 Entry->setPlan(this);
4109 assert(ScalarHeader->getNumSuccessors() == 0 &&
4110 "scalar header must be a leaf node");
4111 }
4112
4113public:
4114 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
4115 /// original preheader and scalar header of \p L, to be used as entry and
4116 /// scalar header blocks of the new VPlan.
4117 VPlan(Loop *L);
4118
4119 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
4120 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
4121 VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
4122 setEntry(createVPBasicBlock("preheader"));
4123 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
4124 TripCount = TC;
4125 }
4126
4128
4130 Entry = VPBB;
4131 VPBB->setPlan(this);
4132 }
4133
4134 /// Generate the IR code for this VPlan.
4135 void execute(VPTransformState *State);
4136
4137 /// Return the cost of this plan.
4139
4140 VPBasicBlock *getEntry() { return Entry; }
4141 const VPBasicBlock *getEntry() const { return Entry; }
4142
4143 /// Returns the preheader of the vector loop region, if one exists, or null
4144 /// otherwise.
4146 VPRegionBlock *VectorRegion = getVectorLoopRegion();
4147 return VectorRegion
4148 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
4149 : nullptr;
4150 }
4151
4152 /// Returns the VPRegionBlock of the vector loop.
4155
4156 /// Returns the 'middle' block of the plan, that is the block that selects
4157 /// whether to execute the scalar tail loop or the exit block from the loop
4158 /// latch. If there is an early exit from the vector loop, the middle block
4159 /// conceptully has the early exit block as third successor, split accross 2
4160 /// VPBBs. In that case, the second VPBB selects whether to execute the scalar
4161 /// tail loop or the exit bock. If the scalar tail loop or exit block are
4162 /// known to always execute, the middle block may branch directly to that
4163 /// block. This function cannot be called once the vector loop region has been
4164 /// removed.
4166 VPRegionBlock *LoopRegion = getVectorLoopRegion();
4167 assert(
4168 LoopRegion &&
4169 "cannot call the function after vector loop region has been removed");
4170 auto *RegionSucc = cast<VPBasicBlock>(LoopRegion->getSingleSuccessor());
4171 if (RegionSucc->getSingleSuccessor() ||
4172 is_contained(RegionSucc->getSuccessors(), getScalarPreheader()))
4173 return RegionSucc;
4174 // There is an early exit. The successor of RegionSucc is the middle block.
4175 return cast<VPBasicBlock>(RegionSucc->getSuccessors()[1]);
4176 }
4177
4179 return const_cast<VPlan *>(this)->getMiddleBlock();
4180 }
4181
4182 /// Return the VPBasicBlock for the preheader of the scalar loop.
4184 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
4185 }
4186
4187 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
4188 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
4189
4190 /// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
4191 /// the original scalar loop.
4192 ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }
4193
4194 /// Return the VPIRBasicBlock corresponding to \p IRBB. \p IRBB must be an
4195 /// exit block.
4197
4198 /// Returns true if \p VPBB is an exit block.
4199 bool isExitBlock(VPBlockBase *VPBB);
4200
4201 /// The trip count of the original loop.
4203 assert(TripCount && "trip count needs to be set before accessing it");
4204 return TripCount;
4205 }
4206
4207 /// Set the trip count assuming it is currently null; if it is not - use
4208 /// resetTripCount().
4209 void setTripCount(VPValue *NewTripCount) {
4210 assert(!TripCount && NewTripCount && "TripCount should not be set yet.");
4211 TripCount = NewTripCount;
4212 }
4213
4214 /// Resets the trip count for the VPlan. The caller must make sure all uses of
4215 /// the original trip count have been replaced.
4216 void resetTripCount(VPValue *NewTripCount) {
4217 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
4218 "TripCount must be set when resetting");
4219 TripCount = NewTripCount;
4220 }
4221
4222 /// The backedge taken count of the original loop.
4224 if (!BackedgeTakenCount)
4225 BackedgeTakenCount = new VPValue();
4226 return BackedgeTakenCount;
4227 }
4228
4229 /// The vector trip count.
4230 VPValue &getVectorTripCount() { return VectorTripCount; }
4231
4232 /// Returns the VF of the vector loop region.
4233 VPValue &getVF() { return VF; };
4234
4235 /// Returns VF * UF of the vector loop region.
4236 VPValue &getVFxUF() { return VFxUF; }
4237
4240 }
4241
4242 void addVF(ElementCount VF) { VFs.insert(VF); }
4243
4245 assert(hasVF(VF) && "Cannot set VF not already in plan");
4246 VFs.clear();
4247 VFs.insert(VF);
4248 }
4249
4250 bool hasVF(ElementCount VF) const { return VFs.count(VF); }
4251 bool hasScalableVF() const {
4252 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
4253 }
4254
4255 /// Returns an iterator range over all VFs of the plan.
4258 return VFs;
4259 }
4260
4261 bool hasScalarVFOnly() const {
4262 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
4263 assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
4264 "Plan with scalar VF should only have a single VF");
4265 return HasScalarVFOnly;
4266 }
4267
4268 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
4269
4270 unsigned getUF() const {
4271 assert(UFs.size() == 1 && "Expected a single UF");
4272 return UFs[0];
4273 }
4274
4275 void setUF(unsigned UF) {
4276 assert(hasUF(UF) && "Cannot set the UF not already in plan");
4277 UFs.clear();
4278 UFs.insert(UF);
4279 }
4280
4281 /// Returns true if the VPlan already has been unrolled, i.e. it has a single
4282 /// concrete UF.
4283 bool isUnrolled() const { return UFs.size() == 1; }
4284
4285 /// Return a string with the name of the plan and the applicable VFs and UFs.
4286 std::string getName() const;
4287
4288 void setName(const Twine &newName) { Name = newName.str(); }
4289
4290 /// Gets the live-in VPValue for \p V or adds a new live-in (if none exists
4291 /// yet) for \p V.
4293 assert(V && "Trying to get or add the VPValue of a null Value");
4294 auto [It, Inserted] = Value2VPValue.try_emplace(V);
4295 if (Inserted) {
4296 VPValue *VPV = new VPValue(V);
4297 VPLiveIns.push_back(VPV);
4298 assert(VPV->isLiveIn() && "VPV must be a live-in.");
4299 It->second = VPV;
4300 }
4301
4302 assert(It->second->isLiveIn() && "Only live-ins should be in mapping");
4303 return It->second;
4304 }
4305
4306 /// Return a VPValue wrapping i1 true.
4308 LLVMContext &Ctx = getContext();
4310 }
4311
4312 /// Return a VPValue wrapping i1 false.
4314 LLVMContext &Ctx = getContext();
4316 }
4317
4318 /// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
4319 VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
4320
4321 /// Return the list of live-in VPValues available in the VPlan.
4323 assert(all_of(Value2VPValue,
4324 [this](const auto &P) {
4325 return is_contained(VPLiveIns, P.second);
4326 }) &&
4327 "all VPValues in Value2VPValue must also be in VPLiveIns");
4328 return VPLiveIns;
4329 }
4330
4331#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4332 /// Print the live-ins of this VPlan to \p O.
4333 void printLiveIns(raw_ostream &O) const;
4334
4335 /// Print this VPlan to \p O.
4336 void print(raw_ostream &O) const;
4337
4338 /// Print this VPlan in DOT format to \p O.
4339 void printDOT(raw_ostream &O) const;
4340
4341 /// Dump the plan to stderr (for debugging).
4342 LLVM_DUMP_METHOD void dump() const;
4343#endif
4344
4345 /// Returns the canonical induction recipe of the vector loop.
4348 if (EntryVPBB->empty()) {
4349 // VPlan native path.
4350 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
4351 }
4352 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
4353 }
4354
4355 VPValue *getSCEVExpansion(const SCEV *S) const {
4356 return SCEVToExpansion.lookup(S);
4357 }
4358
4359 void addSCEVExpansion(const SCEV *S, VPValue *V) {
4360 assert(!SCEVToExpansion.contains(S) && "SCEV already expanded");
4361 SCEVToExpansion[S] = V;
4362 }
4363
4364 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
4365 /// recipes to refer to the clones, and return it.
4366 VPlan *duplicate();
4367
4368 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
4369 /// present. The returned block is owned by the VPlan and deleted once the
4370 /// VPlan is destroyed.
4372 VPRecipeBase *Recipe = nullptr) {
4373 auto *VPB = new VPBasicBlock(Name, Recipe);
4374 CreatedBlocks.push_back(VPB);
4375 return VPB;
4376 }
4377
4378 /// Create a new VPRegionBlock with \p Entry, \p Exiting and \p Name. If \p
4379 /// IsReplicator is true, the region is a replicate region. The returned block
4380 /// is owned by the VPlan and deleted once the VPlan is destroyed.
4382 const std::string &Name = "",
4383 bool IsReplicator = false) {
4384 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, IsReplicator);
4385 CreatedBlocks.push_back(VPB);
4386 return VPB;
4387 }
4388
4389 /// Create a new loop VPRegionBlock with \p Name and entry and exiting blocks set
4390 /// to nullptr. The returned block is owned by the VPlan and deleted once the
4391 /// VPlan is destroyed.
4392 VPRegionBlock *createVPRegionBlock(const std::string &Name = "") {
4393 auto *VPB = new VPRegionBlock(Name);
4394 CreatedBlocks.push_back(VPB);
4395 return VPB;
4396 }
4397
4398 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
4399 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
4400 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
4402
4403 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
4404 /// instructions in \p IRBB, except its terminator which is managed by the
4405 /// successors of the block in VPlan. The returned block is owned by the VPlan
4406 /// and deleted once the VPlan is destroyed.
4408
4409 /// Returns true if the VPlan is based on a loop with an early exit. That is
4410 /// the case if the VPlan has either more than one exit block or a single exit
4411 /// block with multiple predecessors (one for the exit via the latch and one
4412 /// via the other early exit).
4413 bool hasEarlyExit() const {
4414 return count_if(ExitBlocks,
4415 [](VPIRBasicBlock *EB) { return EB->hasPredecessors(); }) >
4416 1 ||
4417 (ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
4418 }
4419
4420 /// Returns true if the scalar tail may execute after the vector loop. Note
4421 /// that this relies on unneeded branches to the scalar tail loop being
4422 /// removed.
4423 bool hasScalarTail() const {
4424 return !(!getScalarPreheader()->hasPredecessors() ||
4426 }
4427};
4428
4429#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4430inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
4431 Plan.print(OS);
4432 return OS;
4433}
4434#endif
4435
4436} // end namespace llvm
4437
4438#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:3471
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition VPlan.h:3465
~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:3750
RecipeListTy::const_iterator const_iterator
Definition VPlan.h:3778
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition VPlan.h:3825
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition VPlan.h:3780
RecipeListTy::iterator iterator
Instruction iterators...
Definition VPlan.h:3777
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition VPlan.h:3803
iplist< VPRecipeBase > RecipeListTy
Definition VPlan.h:3761
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition VPlan.h:3767
iterator end()
Definition VPlan.h:3787
iterator begin()
Recipe iterator methods.
Definition VPlan.h:3785
RecipeListTy::reverse_iterator reverse_iterator
Definition VPlan.h:3779
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:3838
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:823
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition VPlan.cpp:246
~VPBasicBlock() override
Definition VPlan.h:3771
const_reverse_iterator rbegin() const
Definition VPlan.h:3791
reverse_iterator rend()
Definition VPlan.h:3792
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition VPlan.h:3765
VPRecipeBase & back()
Definition VPlan.h:3800
const VPRecipeBase & front() const
Definition VPlan.h:3797
const_iterator begin() const
Definition VPlan.h:3786
VPRecipeBase & front()
Definition VPlan.h:3798
const VPRecipeBase & back() const
Definition VPlan.h:3799
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:3816
bool empty() const
Definition VPlan.h:3796
const_iterator end() const
Definition VPlan.h:3788
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3811
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition VPlan.h:3806
reverse_iterator rbegin()
Definition VPlan.h:3790
friend class VPlan
Definition VPlan.h:3751
size_t size() const
Definition VPlan.h:3795
const_reverse_iterator rend() const
Definition VPlan.h:3793
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2449
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition VPlan.h:2418
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition VPlan.h:2423
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition VPlan.h:2413
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2434
VPBlendRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2400
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:2395
void setMask(unsigned Idx, VPValue *V)
Set mask number Idx to V.
Definition VPlan.h:2429
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:2409
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:702
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:2941
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2925
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2949
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
Definition VPlan.h:2922
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3406
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:3445
~VPCanonicalIVPHIRecipe() override=default
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3413
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
Definition VPlan.h:3408
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3438
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:3433
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3421
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:3452
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:3610
VPValue * getStepValue() const
Definition VPlan.h:3627
Type * getScalarType() const
Definition VPlan.h:3622
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3598
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3590
~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:3630
VPValue * getStartValue() const
Definition VPlan.h:3626
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3582
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:3501
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3507
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition VPlan.h:3513
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition VPlan.h:3496
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3520
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:3382
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
Definition VPlan.h:3387
VPExpandSCEVRecipe(const SCEV *Expr)
Definition VPlan.h:3373
const SCEV * getSCEV() const
Definition VPlan.h:3399
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:3378
~VPExpandSCEVRecipe() override=default
void execute(VPTransformState &State) override
Method for generating code, must not be called as this recipe is abstract.
Definition VPlan.h:3050
VPValue * getOperandOfResultType() const
Return the VPValue to use to infer the result type of the recipe.
Definition VPlan.h:3037
VPExpressionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3019
void decompose()
Insert the recipes of the expression back into the VPlan, directly before the current recipe.
~VPExpressionRecipe() override
Definition VPlan.h:3010
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpressionRecipe(VPWidenCastRecipe *Ext, VPReductionRecipe *Red)
Definition VPlan.h:3001
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:3005
VPExpressionRecipe(VPWidenRecipe *Mul, VPReductionRecipe *Red)
Definition VPlan.h:3003
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:1970
static bool classof(const VPValue *V)
Definition VPlan.h:1980
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:2011
void setBackedgeValue(VPValue *V)
Update the incoming value from the loop backedge.
Definition VPlan.h:2016
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition VPlan.h:2000
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition VPlan.h:2008
VPValue * getStartValue() const
Definition VPlan.h:2003
static bool classof(const VPRecipeBase *B)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:1976
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition VPlan.h:2020
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, VPValue *Start, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1965
~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:1689
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:1706
unsigned getOpcode() const
Definition VPlan.h:1702
VPHistogramRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1683
~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:3903
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition VPlan.cpp:503
BasicBlock * getIRBasicBlock() const
Definition VPlan.h:3927
~VPIRBasicBlock() override
Definition VPlan.h:3915
static bool classof(const VPBlockBase *V)
Definition VPlan.h:3917
friend class VPlan
Definition VPlan.h:3904
VPIRBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition VPlan.cpp:528
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:815
LLVM_ABI_FOR_TEST FastMathFlags getFastMathFlags() const
TruncFlagsTy TruncFlags
Definition VPlan.h:659
CmpInst::Predicate getPredicate() const
Definition VPlan.h:797
bool hasNonNegFlag() const
Returns true if the recipe has non-negative flag.
Definition VPlan.h:820
void transferFlags(VPIRFlags &Other)
Definition VPlan.h:719
ExactFlagsTy ExactFlags
Definition VPlan.h:661
bool hasNoSignedWrap() const
Definition VPlan.h:839
bool isDisjoint() const
Definition VPlan.h:850
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:822
GEPNoWrapFlags getGEPNoWrapFlags() const
Definition VPlan.h:809
bool hasPredicate() const
Returns true if the recipe has a comparison predicate.
Definition VPlan.h:812
DisjointFlagsTy DisjointFlags
Definition VPlan.h:660
unsigned AllFlags
Definition VPlan.h:665
void setPredicate(CmpInst::Predicate Pred)
Definition VPlan.h:803
bool hasNoUnsignedWrap() const
Definition VPlan.h:828
NonNegFlagsTy NonNegFlags
Definition VPlan.h:663
void dropPoisonGeneratingFlags()
Drop all poison-generating flags.
Definition VPlan.h:725
void applyFlags(Instruction &I) const
Apply the IR flags to I.
Definition VPlan.h:760
VPIRFlags(GEPNoWrapFlags GEPFlags)
Definition VPlan.h:716
VPIRFlags(Instruction &I)
Definition VPlan.h:671
Instruction & getInstruction() const
Definition VPlan.h:1372
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first part of operand Op.
Definition VPlan.h:1386
~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:1392
VPIRInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1359
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:1380
VPIRInstruction(Instruction &I)
VPIRInstruction::create() should be used to create VPIRInstructions, as subclasses may need to be cre...
Definition VPlan.h:1347
Helper to manage IR metadata for recipes.
Definition VPlan.h:934
VPIRMetadata(Instruction &I)
Adds metatadata that can be preserved from the original instruction I.
Definition VPlan.h:942
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:951
VPIRMetadata(const VPIRMetadata &Other)
Copy constructor for cloning.
Definition VPlan.h:949
void addMetadata(unsigned Kind, MDNode *Node)
Add metadata with kind Kind and Node.
Definition VPlan.h:960
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:1228
static bool classof(const VPUser *R)
Definition VPlan.h:1212
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:1194
Type * getResultType() const
Definition VPlan.h:1234
VPInstructionWithType(unsigned Opcode, ArrayRef< VPValue * > Operands, Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL, const Twine &Name="")
Definition VPlan.h:1189
VPInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1216
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:975
VPInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
Definition VPlan.h:1097
VPInstruction * clone() override
Clone the current recipe.
Definition VPlan.h:1108
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
Definition VPlan.h:1052
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
Definition VPlan.h:1008
@ WideIVStep
Scale the first operand (vector step) by the second operand (scalar-step).
Definition VPlan.h:1042
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
Definition VPlan.h:1055
@ FirstOrderRecurrenceSplice
Definition VPlan.h:981
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
Definition VPlan.h:1046
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition VPlan.h:1005
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
Definition VPlan.h:1002
@ VScale
Returns the value for vscale.
Definition VPlan.h:1057
@ CanonicalIVIncrementForPart
Definition VPlan.h:995
@ CalculateTripCountMinusVF
Definition VPlan.h:993
bool hasResult() const
Definition VPlan.h:1136
StringRef getName() const
Returns the symbolic name assigned to the VPInstruction.
Definition VPlan.h:1176
unsigned getOpcode() const
Definition VPlan.h:1116
friend class VPlanSlp
Definition VPlan.h:976
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:2528
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2534
static bool classof(const VPUser *U)
Definition VPlan.h:2510
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:2477
Instruction * getInsertPos() const
Definition VPlan.h:2532
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2505
const InterleaveGroup< Instruction > * getInterleaveGroup() const
Definition VPlan.h:2530
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:2522
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition VPlan.h:2551
VPInterleaveBase * clone() override=0
Clone the current recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:2516
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2625
~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:2637
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2644
VPInterleaveEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2618
VPInterleaveEVLRecipe(VPInterleaveRecipe &R, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:2605
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition VPlan.h:2562
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2595
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2589
~VPInterleaveRecipe() override=default
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2572
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Definition VPlan.h:2564
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:2747
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned ScaleFactor, Instruction *ReductionInst=nullptr)
Definition VPlan.h:2751
~VPPartialReductionRecipe() override=default
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2785
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:2782
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2766
Helper type to provide functions to access incoming values and blocks for phi-like recipes.
Definition VPlan.h:1245
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:1267
virtual unsigned getNumIncoming() const
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:1262
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:3894
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:1287
VPValue * getIncomingValue(unsigned Idx) const
Returns the incoming VPValue with index Idx.
Definition VPlan.h:1254
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:1272
const_incoming_blocks_range incoming_blocks() const
Returns an iterator range over the incoming blocks.
Definition VPlan.h:1276
~VPPredInstPHIRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:3109
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3085
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
Definition VPlan.h:3096
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition VPlan.h:3081
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:2830
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2827
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2800
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2811
~VPReductionEVLRecipe() override=default
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition VPlan.h:2374
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2343
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2357
~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:2380
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:2333
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2368
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
Definition VPlan.h:2377
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:2371
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition VPlan.h:2652
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition VPlan.h:2724
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2696
VPReductionRecipe(const RecurKind RdxKind, FastMathFlags FMFs, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2681
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition VPlan.h:2728
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition VPlan.h:2730
RecurKind getRecurrenceKind() const
Return the recurrence kind for the in-loop reduction.
Definition VPlan.h:2720
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition VPlan.h:2722
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition VPlan.h:2726
VPReductionRecipe(RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2674
VPReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2690
VPReductionRecipe(const unsigned char SC, RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
Definition VPlan.h:2660
static bool classof(const VPUser *U)
Definition VPlan.h:2701
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:3938
const VPBlockBase * getEntry() const
Definition VPlan.h:3974
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4006
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition VPlan.h:3991
VPBlockBase * getExiting()
Definition VPlan.h:3987
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition VPlan.h:3979
const VPBlockBase * getExiting() const
Definition VPlan.h:3986
VPBlockBase * getEntry()
Definition VPlan.h:3975
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition VPlan.h:3999
~VPRegionBlock() override
Definition VPlan.h:3967
friend class VPlan
Definition VPlan.h:3939
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3970
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2842
VPReplicateRecipe(Instruction *I, ArrayRef< VPValue * > Operands, bool IsSingleScalar, VPValue *Mask=nullptr, VPIRMetadata Metadata={})
Definition VPlan.h:2850
bool isSingleScalar() const
Definition VPlan.h:2887
~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:2892
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2899
bool isPredicated() const
Definition VPlan.h:2889
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2862
unsigned getOpcode() const
Definition VPlan.h:2916
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition VPlan.h:2911
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3695
VPValue * getStepValue() const
Definition VPlan.h:3692
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition VPlan.h:3680
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step, VPValue *VF, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:3651
bool isPart0() const
Return true if this VPScalarIVStepsRecipe corresponds to part 0.
Definition VPlan.h:3672
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3663
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, VPValue *VF, Instruction::BinaryOps Opcode, FastMathFlags FMFs, DebugLoc DL)
Definition VPlan.h:3644
~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:922
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:1459
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:1866
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1852
VPVectorEndPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1873
const VPValue * getVFValue() const
Definition VPlan.h:1848
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:1859
VPVectorEndPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1837
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:1923
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1892
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:1909
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1902
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition VPlan.h:1926
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1916
const_operand_range args() const
Definition VPlan.h:1664
VPWidenCallRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1645
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1632
operand_range args()
Definition VPlan.h:1663
Function * getCalledScalarFunction() const
Definition VPlan.h:1659
~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:3555
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3542
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition VPlan.h:3537
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1479
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, CastInst &UI)
Definition VPlan.h:1487
Instruction::CastOps getOpcode() const
Definition VPlan.h:1529
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:1495
Type * getResultType() const
Returns the result type of the cast.
Definition VPlan.h:1532
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:1506
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1815
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1781
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition VPlan.h:1802
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1791
~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:2090
static bool classof(const VPValue *V)
Definition VPlan.h:2044
void setStepValue(VPValue *V)
Update the step value of the recipe.
Definition VPlan.h:2060
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition VPlan.h:2075
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2068
PHINode * getPHINode() const
Definition VPlan.h:2070
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2032
VPValue * getStepValue()
Returns the step value of the induction.
Definition VPlan.h:2056
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition VPlan.h:2073
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition VPlan.h:2082
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2039
static bool classof(const VPHeaderPHIRecipe *R)
Definition VPlan.h:2049
const VPValue * getVFValue() const
Definition VPlan.h:2063
const VPValue * getStepValue() const
Definition VPlan.h:2057
virtual void execute(VPTransformState &State) override=0
Generate the phi nodes.
const TruncInst * getTruncInst() const
Definition VPlan.h:2168
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:2143
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
Definition VPlan.h:2119
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2135
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition VPlan.h:2167
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2110
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition VPlan.h:2184
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2163
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:2176
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:1562
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
Definition VPlan.h:1597
bool mayReadFromMemory() const
Returns true if the intrinsic may read from memory.
Definition VPlan.h:1606
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:1553
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
Definition VPlan.h:1612
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1579
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
Definition VPlan.h:1609
~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:1600
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:3130
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition VPlan.h:3127
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition VPlan.h:3167
static bool classof(const VPUser *U)
Definition VPlan.h:3161
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition VPlan.h:3187
Instruction & Ingredient
Definition VPlan.h:3121
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3150
Instruction & getIngredient() const
Definition VPlan.h:3195
bool Consecutive
Whether the accessed addresses are consecutive.
Definition VPlan.h:3124
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:3154
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:3181
bool isMasked() const
Returns true if the recipe is masked.
Definition VPlan.h:3177
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3140
void setMask(VPValue *Mask)
Definition VPlan.h:3132
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:3174
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition VPlan.h:3171
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:2244
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:2249
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2257
~VPWidenPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2208
~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:2218
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:2196
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:1436
VPWidenRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1452
VPWidenRecipe(Instruction &I, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1446
VPWidenRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:1440
~VPWidenRecipe() override=default
unsigned getOpcode() const
Definition VPlan.h:1469
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:4041
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition VPlan.cpp:1145
friend class VPSlotTracker
Definition VPlan.h:4043
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition VPlan.cpp:1121
bool hasVF(ElementCount VF) const
Definition VPlan.h:4250
LLVMContext & getContext() const
Definition VPlan.h:4238
VPBasicBlock * getEntry()
Definition VPlan.h:4140
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:4381
VPValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4230
void setName(const Twine &newName)
Definition VPlan.h:4288
bool hasScalableVF() const
Definition VPlan.h:4251
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:4236
VPValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4233
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4202
VPValue * getTrue()
Return a VPValue wrapping i1 true.
Definition VPlan.h:4307
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition VPlan.h:4223
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition VPlan.h:4257
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
Definition VPlan.h:4121
VPIRBasicBlock * getExitBlock(BasicBlock *IRBB) const
Return the VPIRBasicBlock corresponding to IRBB.
Definition VPlan.cpp:953
LLVM_ABI_FOR_TEST ~VPlan()
Definition VPlan.cpp:930
bool isExitBlock(VPBlockBase *VPBB)
Returns true if VPBB is an exit block.
Definition VPlan.cpp:961
const VPBasicBlock * getEntry() const
Definition VPlan.h:4141
friend class VPlanPrinter
Definition VPlan.h:4042
unsigned getUF() const
Definition VPlan.h:4270
VPRegionBlock * createVPRegionBlock(const std::string &Name="")
Create a new loop VPRegionBlock with Name and entry and exiting blocks set to nullptr.
Definition VPlan.h:4392
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
Definition VPlan.cpp:1259
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition VPlan.h:4359
bool hasUF(unsigned UF) const
Definition VPlan.h:4268
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
Definition VPlan.h:4192
void setVF(ElementCount VF)
Definition VPlan.h:4244
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
Definition VPlan.h:4283
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1050
bool hasEarlyExit() const
Returns true if the VPlan is based on a loop with an early exit.
Definition VPlan.h:4413
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition VPlan.cpp:1032
const VPBasicBlock * getMiddleBlock() const
Definition VPlan.h:4178
void setTripCount(VPValue *NewTripCount)
Set the trip count assuming it is currently null; if it is not - use resetTripCount().
Definition VPlan.h:4209
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition VPlan.h:4216
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition VPlan.h:4165
void setEntry(VPBasicBlock *VPBB)
Definition VPlan.h:4129
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition VPlan.h:4371
LLVM_ABI_FOR_TEST VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
Definition VPlan.cpp:1265
VPValue * getFalse()
Return a VPValue wrapping i1 false.
Definition VPlan.h:4313
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:4292
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition VPlan.cpp:1151
bool hasScalarVFOnly() const
Definition VPlan.h:4261
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4183
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
Definition VPlan.cpp:968
ArrayRef< VPValue * > getLiveIns() const
Return the list of live-in VPValues available in the VPlan.
Definition VPlan.h:4322
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition VPlan.h:4346
void print(raw_ostream &O) const
Print this VPlan to O.
Definition VPlan.cpp:1104
void addVF(ElementCount VF)
Definition VPlan.h:4242
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition VPlan.h:4188
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
Definition VPlan.h:4319
VPValue * getSCEVExpansion(const SCEV *S) const
Definition VPlan.h:4355
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition VPlan.cpp:1066
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition VPlan.h:4145
void setUF(unsigned UF)
Definition VPlan.h:4275
bool hasScalarTail() const
Returns true if the scalar tail may execute after the vector loop.
Definition VPlan.h:4423
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition VPlan.cpp:1192
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:2427
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:330
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:843
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:1753
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:1727
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:853
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:2474
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:378
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:1734
auto reverse(ContainerTy &&C)
Definition STLExtras.h:420
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:337
@ 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:1956
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:1963
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:1899
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:3713
static VPPhiAccessors * doCastIfPossible(SrcTy f)
doCastIfPossible is used by dyn_cast<>.
Definition VPlan.h:3734
CastInfo< VPPhiAccessors, SrcTy > Self
Definition VPlan.h:3715
static VPPhiAccessors * doCast(SrcTy R)
doCast is used by cast<>.
Definition VPlan.h:3718
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:3705
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:2288
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
Definition VPlan.h:2283
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:2306
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:1417
VPIRPhi(PHINode &PN)
Definition VPlan.h:1410
static bool classof(const VPRecipeBase *U)
Definition VPlan.h:1412
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:1428
static bool classof(const VPUser *U)
Definition VPlan.h:1305
VPPhi * clone() override
Clone the current recipe.
Definition VPlan.h:1320
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:1335
VPPhi(ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
Definition VPlan.h:1302
static bool classof(const VPSingleDefRecipe *SDR)
Definition VPlan.h:1315
static bool classof(const VPValue *V)
Definition VPlan.h:1310
A pure-virtual common base class for recipes defining a single VPValue and using IR flags.
Definition VPlan.h:868
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:882
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, Instruction &I)
Definition VPlan.h:873
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:877
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:902
static bool classof(const VPSingleDefRecipe *U)
Definition VPlan.h:907
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:897
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:869
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:3254
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:3242
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3270
A recipe for widening load operations, using the address to load from and an optional mask.
Definition VPlan.h:3201
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:3229
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:3202
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3211
bool isInvariantCond() const
Definition VPlan.h:1752
VPWidenSelectRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1726
VPWidenSelectRecipe(SelectInst &I, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1720
VPValue * getCond() const
Definition VPlan.h:1748
unsigned getOpcode() const
Definition VPlan.h:1746
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1757
~VPWidenSelectRecipe() override=default
VPValue * getStoredValue() const
Return the address accessed by this recipe.
Definition VPlan.h:3335
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:3354
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue *Addr, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:3324
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition VPlan.h:3338
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition VPlan.h:3281
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3311
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition VPlan.h:3299
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3290
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3282