LLVM 21.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"
42#include <algorithm>
43#include <cassert>
44#include <cstddef>
45#include <string>
46
47namespace llvm {
48
49class BasicBlock;
50class DominatorTree;
51class InnerLoopVectorizer;
52class IRBuilderBase;
53struct VPTransformState;
54class raw_ostream;
55class RecurrenceDescriptor;
56class SCEV;
57class Type;
58class VPBasicBlock;
59class VPBuilder;
60class VPRegionBlock;
61class VPlan;
62class VPLane;
63class VPReplicateRecipe;
64class VPlanSlp;
65class Value;
66class LoopVectorizationCostModel;
67
68struct VPCostContext;
69
70namespace Intrinsic {
71typedef unsigned ID;
72}
73
74using VPlanPtr = std::unique_ptr<VPlan>;
75
76/// VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
77/// A VPBlockBase can be either a VPBasicBlock or a VPRegionBlock.
79 friend class VPBlockUtils;
80
81 const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
82
83 /// An optional name for the block.
84 std::string Name;
85
86 /// The immediate VPRegionBlock which this VPBlockBase belongs to, or null if
87 /// it is a topmost VPBlockBase.
88 VPRegionBlock *Parent = nullptr;
89
90 /// List of predecessor blocks.
92
93 /// List of successor blocks.
95
96 /// VPlan containing the block. Can only be set on the entry block of the
97 /// plan.
98 VPlan *Plan = nullptr;
99
100 /// Add \p Successor as the last successor to this block.
101 void appendSuccessor(VPBlockBase *Successor) {
102 assert(Successor && "Cannot add nullptr successor!");
103 Successors.push_back(Successor);
104 }
105
106 /// Add \p Predecessor as the last predecessor to this block.
107 void appendPredecessor(VPBlockBase *Predecessor) {
108 assert(Predecessor && "Cannot add nullptr predecessor!");
109 Predecessors.push_back(Predecessor);
110 }
111
112 /// Remove \p Predecessor from the predecessors of this block.
113 void removePredecessor(VPBlockBase *Predecessor) {
114 auto Pos = find(Predecessors, Predecessor);
115 assert(Pos && "Predecessor does not exist");
116 Predecessors.erase(Pos);
117 }
118
119 /// Remove \p Successor from the successors of this block.
120 void removeSuccessor(VPBlockBase *Successor) {
121 auto Pos = find(Successors, Successor);
122 assert(Pos && "Successor does not exist");
123 Successors.erase(Pos);
124 }
125
126 /// This function replaces one predecessor with another, useful when
127 /// trying to replace an old block in the CFG with a new one.
128 void replacePredecessor(VPBlockBase *Old, VPBlockBase *New) {
129 auto I = find(Predecessors, Old);
130 assert(I != Predecessors.end());
131 assert(Old->getParent() == New->getParent() &&
132 "replaced predecessor must have the same parent");
133 *I = New;
134 }
135
136 /// This function replaces one successor with another, useful when
137 /// trying to replace an old block in the CFG with a new one.
138 void replaceSuccessor(VPBlockBase *Old, VPBlockBase *New) {
139 auto I = find(Successors, Old);
140 assert(I != Successors.end());
141 assert(Old->getParent() == New->getParent() &&
142 "replaced successor must have the same parent");
143 *I = New;
144 }
145
146protected:
147 VPBlockBase(const unsigned char SC, const std::string &N)
148 : SubclassID(SC), Name(N) {}
149
150public:
151 /// An enumeration for keeping track of the concrete subclass of VPBlockBase
152 /// that are actually instantiated. Values of this enumeration are kept in the
153 /// SubclassID field of the VPBlockBase objects. They are used for concrete
154 /// type identification.
155 using VPBlockTy = enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC };
156
158
159 virtual ~VPBlockBase() = default;
160
161 const std::string &getName() const { return Name; }
162
163 void setName(const Twine &newName) { Name = newName.str(); }
164
165 /// \return an ID for the concrete type of this object.
166 /// This is used to implement the classof checks. This should not be used
167 /// for any other purpose, as the values may change as LLVM evolves.
168 unsigned getVPBlockID() const { return SubclassID; }
169
170 VPRegionBlock *getParent() { return Parent; }
171 const VPRegionBlock *getParent() const { return Parent; }
172
173 /// \return A pointer to the plan containing the current block.
174 VPlan *getPlan();
175 const VPlan *getPlan() const;
176
177 /// Sets the pointer of the plan containing the block. The block must be the
178 /// entry block into the VPlan.
179 void setPlan(VPlan *ParentPlan);
180
181 void setParent(VPRegionBlock *P) { Parent = P; }
182
183 /// \return the VPBasicBlock that is the entry of this VPBlockBase,
184 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
185 /// VPBlockBase is a VPBasicBlock, it is returned.
186 const VPBasicBlock *getEntryBasicBlock() const;
188
189 /// \return the VPBasicBlock that is the exiting this VPBlockBase,
190 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
191 /// VPBlockBase is a VPBasicBlock, it is returned.
192 const VPBasicBlock *getExitingBasicBlock() const;
194
195 const VPBlocksTy &getSuccessors() const { return Successors; }
196 VPBlocksTy &getSuccessors() { return Successors; }
197
200
201 const VPBlocksTy &getPredecessors() const { return Predecessors; }
202 VPBlocksTy &getPredecessors() { return Predecessors; }
203
204 /// \return the successor of this VPBlockBase if it has a single successor.
205 /// Otherwise return a null pointer.
207 return (Successors.size() == 1 ? *Successors.begin() : nullptr);
208 }
209
210 /// \return the predecessor of this VPBlockBase if it has a single
211 /// predecessor. Otherwise return a null pointer.
213 return (Predecessors.size() == 1 ? *Predecessors.begin() : nullptr);
214 }
215
216 size_t getNumSuccessors() const { return Successors.size(); }
217 size_t getNumPredecessors() const { return Predecessors.size(); }
218
219 /// An Enclosing Block of a block B is any block containing B, including B
220 /// itself. \return the closest enclosing block starting from "this", which
221 /// has successors. \return the root enclosing block if all enclosing blocks
222 /// have no successors.
224
225 /// \return the closest enclosing block starting from "this", which has
226 /// predecessors. \return the root enclosing block if all enclosing blocks
227 /// have no predecessors.
229
230 /// \return the successors either attached directly to this VPBlockBase or, if
231 /// this VPBlockBase is the exit block of a VPRegionBlock and has no
232 /// successors of its own, search recursively for the first enclosing
233 /// VPRegionBlock that has successors and return them. If no such
234 /// VPRegionBlock exists, return the (empty) successors of the topmost
235 /// VPBlockBase reached.
238 }
239
240 /// \return the hierarchical successor of this VPBlockBase if it has a single
241 /// hierarchical successor. Otherwise return a null pointer.
244 }
245
246 /// \return the predecessors either attached directly to this VPBlockBase or,
247 /// if this VPBlockBase is the entry block of a VPRegionBlock and has no
248 /// predecessors of its own, search recursively for the first enclosing
249 /// VPRegionBlock that has predecessors and return them. If no such
250 /// VPRegionBlock exists, return the (empty) predecessors of the topmost
251 /// VPBlockBase reached.
254 }
255
256 /// \return the hierarchical predecessor of this VPBlockBase if it has a
257 /// single hierarchical predecessor. Otherwise return a null pointer.
260 }
261
262 /// Set a given VPBlockBase \p Successor as the single successor of this
263 /// VPBlockBase. This VPBlockBase is not added as predecessor of \p Successor.
264 /// This VPBlockBase must have no successors.
266 assert(Successors.empty() && "Setting one successor when others exist.");
267 assert(Successor->getParent() == getParent() &&
268 "connected blocks must have the same parent");
269 appendSuccessor(Successor);
270 }
271
272 /// Set two given VPBlockBases \p IfTrue and \p IfFalse to be the two
273 /// successors of this VPBlockBase. This VPBlockBase is not added as
274 /// predecessor of \p IfTrue or \p IfFalse. This VPBlockBase must have no
275 /// successors.
276 void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse) {
277 assert(Successors.empty() && "Setting two successors when others exist.");
278 appendSuccessor(IfTrue);
279 appendSuccessor(IfFalse);
280 }
281
282 /// Set each VPBasicBlock in \p NewPreds as predecessor of this VPBlockBase.
283 /// This VPBlockBase must have no predecessors. This VPBlockBase is not added
284 /// as successor of any VPBasicBlock in \p NewPreds.
286 assert(Predecessors.empty() && "Block predecessors already set.");
287 for (auto *Pred : NewPreds)
288 appendPredecessor(Pred);
289 }
290
291 /// Set each VPBasicBlock in \p NewSuccss as successor of this VPBlockBase.
292 /// This VPBlockBase must have no successors. This VPBlockBase is not added
293 /// as predecessor of any VPBasicBlock in \p NewSuccs.
295 assert(Successors.empty() && "Block successors already set.");
296 for (auto *Succ : NewSuccs)
297 appendSuccessor(Succ);
298 }
299
300 /// Remove all the predecessor of this block.
301 void clearPredecessors() { Predecessors.clear(); }
302
303 /// Remove all the successors of this block.
304 void clearSuccessors() { Successors.clear(); }
305
306 /// Swap successors of the block. The block must have exactly 2 successors.
307 // TODO: This should be part of introducing conditional branch recipes rather
308 // than being independent.
310 assert(Successors.size() == 2 && "must have 2 successors to swap");
311 std::swap(Successors[0], Successors[1]);
312 }
313
314 /// The method which generates the output IR that correspond to this
315 /// VPBlockBase, thereby "executing" the VPlan.
316 virtual void execute(VPTransformState *State) = 0;
317
318 /// Return the cost of the block.
320
321 /// Return true if it is legal to hoist instructions into this block.
323 // There are currently no constraints that prevent an instruction to be
324 // hoisted into a VPBlockBase.
325 return true;
326 }
327
328#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
329 void printAsOperand(raw_ostream &OS, bool PrintType = false) const {
330 OS << getName();
331 }
332
333 /// Print plain-text dump of this VPBlockBase to \p O, prefixing all lines
334 /// with \p Indent. \p SlotTracker is used to print unnamed VPValue's using
335 /// consequtive numbers.
336 ///
337 /// Note that the numbering is applied to the whole VPlan, so printing
338 /// individual blocks is consistent with the whole VPlan printing.
339 virtual void print(raw_ostream &O, const Twine &Indent,
340 VPSlotTracker &SlotTracker) const = 0;
341
342 /// Print plain-text dump of this VPlan to \p O.
343 void print(raw_ostream &O) const;
344
345 /// Print the successors of this block to \p O, prefixing all lines with \p
346 /// Indent.
347 void printSuccessors(raw_ostream &O, const Twine &Indent) const;
348
349 /// Dump this VPBlockBase to dbgs().
350 LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
351#endif
352
353 /// Clone the current block and it's recipes without updating the operands of
354 /// the cloned recipes, including all blocks in the single-entry single-exit
355 /// region for VPRegionBlocks.
356 virtual VPBlockBase *clone() = 0;
357};
358
359/// VPRecipeBase is a base class modeling a sequence of one or more output IR
360/// instructions. VPRecipeBase owns the VPValues it defines through VPDef
361/// and is responsible for deleting its defined values. Single-value
362/// recipes must inherit from VPSingleDef instead of inheriting from both
363/// VPRecipeBase and VPValue separately.
364class VPRecipeBase : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock>,
365 public VPDef,
366 public VPUser {
367 friend VPBasicBlock;
368 friend class VPBlockUtils;
369
370 /// Each VPRecipe belongs to a single VPBasicBlock.
371 VPBasicBlock *Parent = nullptr;
372
373 /// The debug location for the recipe.
374 DebugLoc DL;
375
376public:
378 DebugLoc DL = {})
379 : VPDef(SC), VPUser(Operands), DL(DL) {}
380
381 template <typename IterT>
383 DebugLoc DL = {})
384 : VPDef(SC), VPUser(Operands), DL(DL) {}
385 virtual ~VPRecipeBase() = default;
386
387 /// Clone the current recipe.
388 virtual VPRecipeBase *clone() = 0;
389
390 /// \return the VPBasicBlock which this VPRecipe belongs to.
391 VPBasicBlock *getParent() { return Parent; }
392 const VPBasicBlock *getParent() const { return Parent; }
393
394 /// The method which generates the output IR instructions that correspond to
395 /// this VPRecipe, thereby "executing" the VPlan.
396 virtual void execute(VPTransformState &State) = 0;
397
398 /// Return the cost of this recipe, taking into account if the cost
399 /// computation should be skipped and the ForceTargetInstructionCost flag.
400 /// Also takes care of printing the cost for debugging.
402
403 /// Insert an unlinked recipe into a basic block immediately before
404 /// the specified recipe.
405 void insertBefore(VPRecipeBase *InsertPos);
406 /// Insert an unlinked recipe into \p BB immediately before the insertion
407 /// point \p IP;
409
410 /// Insert an unlinked Recipe into a basic block immediately after
411 /// the specified Recipe.
412 void insertAfter(VPRecipeBase *InsertPos);
413
414 /// Unlink this recipe from its current VPBasicBlock and insert it into
415 /// the VPBasicBlock that MovePos lives in, right after MovePos.
416 void moveAfter(VPRecipeBase *MovePos);
417
418 /// Unlink this recipe and insert into BB before I.
419 ///
420 /// \pre I is a valid iterator into BB.
422
423 /// This method unlinks 'this' from the containing basic block, but does not
424 /// delete it.
425 void removeFromParent();
426
427 /// This method unlinks 'this' from the containing basic block and deletes it.
428 ///
429 /// \returns an iterator pointing to the element after the erased one
431
432 /// Method to support type inquiry through isa, cast, and dyn_cast.
433 static inline bool classof(const VPDef *D) {
434 // All VPDefs are also VPRecipeBases.
435 return true;
436 }
437
438 static inline bool classof(const VPUser *U) { return true; }
439
440 /// Returns true if the recipe may have side-effects.
441 bool mayHaveSideEffects() const;
442
443 /// Returns true for PHI-like recipes.
444 bool isPhi() const {
445 return getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC;
446 }
447
448 /// Returns true if the recipe may read from memory.
449 bool mayReadFromMemory() const;
450
451 /// Returns true if the recipe may write to memory.
452 bool mayWriteToMemory() const;
453
454 /// Returns true if the recipe may read from or write to memory.
455 bool mayReadOrWriteMemory() const {
457 }
458
459 /// Returns the debug location of the recipe.
460 DebugLoc getDebugLoc() const { return DL; }
461
462protected:
463 /// Compute the cost of this recipe either using a recipe's specialized
464 /// implementation or using the legacy cost model and the underlying
465 /// instructions.
467 VPCostContext &Ctx) const;
468};
469
470// Helper macro to define common classof implementations for recipes.
471#define VP_CLASSOF_IMPL(VPDefID) \
472 static inline bool classof(const VPDef *D) { \
473 return D->getVPDefID() == VPDefID; \
474 } \
475 static inline bool classof(const VPValue *V) { \
476 auto *R = V->getDefiningRecipe(); \
477 return R && R->getVPDefID() == VPDefID; \
478 } \
479 static inline bool classof(const VPUser *U) { \
480 auto *R = dyn_cast<VPRecipeBase>(U); \
481 return R && R->getVPDefID() == VPDefID; \
482 } \
483 static inline bool classof(const VPRecipeBase *R) { \
484 return R->getVPDefID() == VPDefID; \
485 } \
486 static inline bool classof(const VPSingleDefRecipe *R) { \
487 return R->getVPDefID() == VPDefID; \
488 }
489
490/// VPSingleDef is a base class for recipes for modeling a sequence of one or
491/// more output IR that define a single result VPValue.
492/// Note that VPRecipeBase must be inherited from before VPValue.
493class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
494public:
495 template <typename IterT>
496 VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL = {})
497 : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
498
499 VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
500 DebugLoc DL = {})
501 : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
502
503 template <typename IterT>
504 VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV,
505 DebugLoc DL = {})
506 : VPRecipeBase(SC, Operands, DL), VPValue(this, UV) {}
507
508 static inline bool classof(const VPRecipeBase *R) {
509 switch (R->getVPDefID()) {
510 case VPRecipeBase::VPDerivedIVSC:
511 case VPRecipeBase::VPEVLBasedIVPHISC:
512 case VPRecipeBase::VPExpandSCEVSC:
513 case VPRecipeBase::VPInstructionSC:
514 case VPRecipeBase::VPReductionEVLSC:
515 case VPRecipeBase::VPReductionSC:
516 case VPRecipeBase::VPReplicateSC:
517 case VPRecipeBase::VPScalarIVStepsSC:
518 case VPRecipeBase::VPVectorPointerSC:
519 case VPRecipeBase::VPReverseVectorPointerSC:
520 case VPRecipeBase::VPWidenCallSC:
521 case VPRecipeBase::VPWidenCanonicalIVSC:
522 case VPRecipeBase::VPWidenCastSC:
523 case VPRecipeBase::VPWidenGEPSC:
524 case VPRecipeBase::VPWidenIntrinsicSC:
525 case VPRecipeBase::VPWidenSC:
526 case VPRecipeBase::VPWidenEVLSC:
527 case VPRecipeBase::VPWidenSelectSC:
528 case VPRecipeBase::VPBlendSC:
529 case VPRecipeBase::VPPredInstPHISC:
530 case VPRecipeBase::VPCanonicalIVPHISC:
531 case VPRecipeBase::VPActiveLaneMaskPHISC:
532 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
533 case VPRecipeBase::VPWidenPHISC:
534 case VPRecipeBase::VPWidenIntOrFpInductionSC:
535 case VPRecipeBase::VPWidenPointerInductionSC:
536 case VPRecipeBase::VPReductionPHISC:
537 case VPRecipeBase::VPScalarCastSC:
538 case VPRecipeBase::VPPartialReductionSC:
539 return true;
540 case VPRecipeBase::VPBranchOnMaskSC:
541 case VPRecipeBase::VPInterleaveSC:
542 case VPRecipeBase::VPIRInstructionSC:
543 case VPRecipeBase::VPWidenLoadEVLSC:
544 case VPRecipeBase::VPWidenLoadSC:
545 case VPRecipeBase::VPWidenStoreEVLSC:
546 case VPRecipeBase::VPWidenStoreSC:
547 case VPRecipeBase::VPHistogramSC:
548 // TODO: Widened stores don't define a value, but widened loads do. Split
549 // the recipes to be able to make widened loads VPSingleDefRecipes.
550 return false;
551 }
552 llvm_unreachable("Unhandled VPDefID");
553 }
554
555 static inline bool classof(const VPUser *U) {
556 auto *R = dyn_cast<VPRecipeBase>(U);
557 return R && classof(R);
558 }
559
560 virtual VPSingleDefRecipe *clone() override = 0;
561
562 /// Returns the underlying instruction.
564 return cast<Instruction>(getUnderlyingValue());
565 }
567 return cast<Instruction>(getUnderlyingValue());
568 }
569
570#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
571 /// Print this VPSingleDefRecipe to dbgs() (for debugging).
572 LLVM_DUMP_METHOD void dump() const;
573#endif
574};
575
576/// Class to record LLVM IR flag for a recipe along with it.
578 enum class OperationType : unsigned char {
579 Cmp,
580 OverflowingBinOp,
581 DisjointOp,
582 PossiblyExactOp,
583 GEPOp,
584 FPMathOp,
585 NonNegOp,
586 Other
587 };
588
589public:
590 struct WrapFlagsTy {
591 char HasNUW : 1;
592 char HasNSW : 1;
593
595 };
596
598 char IsDisjoint : 1;
600 };
601
602private:
603 struct ExactFlagsTy {
604 char IsExact : 1;
605 };
606 struct NonNegFlagsTy {
607 char NonNeg : 1;
608 };
609 struct FastMathFlagsTy {
610 char AllowReassoc : 1;
611 char NoNaNs : 1;
612 char NoInfs : 1;
613 char NoSignedZeros : 1;
614 char AllowReciprocal : 1;
615 char AllowContract : 1;
616 char ApproxFunc : 1;
617
618 FastMathFlagsTy(const FastMathFlags &FMF);
619 };
620
621 OperationType OpType;
622
623 union {
627 ExactFlagsTy ExactFlags;
629 NonNegFlagsTy NonNegFlags;
630 FastMathFlagsTy FMFs;
631 unsigned AllFlags;
632 };
633
634protected:
636 OpType = Other.OpType;
637 AllFlags = Other.AllFlags;
638 }
639
640public:
641 template <typename IterT>
642 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DebugLoc DL = {})
643 : VPSingleDefRecipe(SC, Operands, DL) {
644 OpType = OperationType::Other;
645 AllFlags = 0;
646 }
647
648 template <typename IterT>
649 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, Instruction &I)
651 if (auto *Op = dyn_cast<CmpInst>(&I)) {
652 OpType = OperationType::Cmp;
653 CmpPredicate = Op->getPredicate();
654 } else if (auto *Op = dyn_cast<PossiblyDisjointInst>(&I)) {
655 OpType = OperationType::DisjointOp;
656 DisjointFlags.IsDisjoint = Op->isDisjoint();
657 } else if (auto *Op = dyn_cast<OverflowingBinaryOperator>(&I)) {
658 OpType = OperationType::OverflowingBinOp;
659 WrapFlags = {Op->hasNoUnsignedWrap(), Op->hasNoSignedWrap()};
660 } else if (auto *Op = dyn_cast<PossiblyExactOperator>(&I)) {
661 OpType = OperationType::PossiblyExactOp;
662 ExactFlags.IsExact = Op->isExact();
663 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
664 OpType = OperationType::GEPOp;
665 GEPFlags = GEP->getNoWrapFlags();
666 } else if (auto *PNNI = dyn_cast<PossiblyNonNegInst>(&I)) {
667 OpType = OperationType::NonNegOp;
668 NonNegFlags.NonNeg = PNNI->hasNonNeg();
669 } else if (auto *Op = dyn_cast<FPMathOperator>(&I)) {
670 OpType = OperationType::FPMathOp;
671 FMFs = Op->getFastMathFlags();
672 } else {
673 OpType = OperationType::Other;
674 AllFlags = 0;
675 }
676 }
677
678 template <typename IterT>
679 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
680 CmpInst::Predicate Pred, DebugLoc DL = {})
681 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::Cmp),
682 CmpPredicate(Pred) {}
683
684 template <typename IterT>
685 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
687 : VPSingleDefRecipe(SC, Operands, DL),
688 OpType(OperationType::OverflowingBinOp), WrapFlags(WrapFlags) {}
689
690 template <typename IterT>
691 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
692 FastMathFlags FMFs, DebugLoc DL = {})
693 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::FPMathOp),
694 FMFs(FMFs) {}
695
696 template <typename IterT>
697 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
699 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::DisjointOp),
701
702protected:
703 template <typename IterT>
704 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
706 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::GEPOp),
708
709public:
710 static inline bool classof(const VPRecipeBase *R) {
711 return R->getVPDefID() == VPRecipeBase::VPInstructionSC ||
712 R->getVPDefID() == VPRecipeBase::VPWidenSC ||
713 R->getVPDefID() == VPRecipeBase::VPWidenEVLSC ||
714 R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
715 R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
716 R->getVPDefID() == VPRecipeBase::VPWidenIntrinsicSC ||
717 R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
718 R->getVPDefID() == VPRecipeBase::VPReverseVectorPointerSC ||
719 R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
720 }
721
722 static inline bool classof(const VPUser *U) {
723 auto *R = dyn_cast<VPRecipeBase>(U);
724 return R && classof(R);
725 }
726
727 /// Drop all poison-generating flags.
729 // NOTE: This needs to be kept in-sync with
730 // Instruction::dropPoisonGeneratingFlags.
731 switch (OpType) {
732 case OperationType::OverflowingBinOp:
733 WrapFlags.HasNUW = false;
734 WrapFlags.HasNSW = false;
735 break;
736 case OperationType::DisjointOp:
738 break;
739 case OperationType::PossiblyExactOp:
740 ExactFlags.IsExact = false;
741 break;
742 case OperationType::GEPOp:
744 break;
745 case OperationType::FPMathOp:
746 FMFs.NoNaNs = false;
747 FMFs.NoInfs = false;
748 break;
749 case OperationType::NonNegOp:
750 NonNegFlags.NonNeg = false;
751 break;
752 case OperationType::Cmp:
753 case OperationType::Other:
754 break;
755 }
756 }
757
758 /// Set the IR flags for \p I.
759 void setFlags(Instruction *I) const {
760 switch (OpType) {
761 case OperationType::OverflowingBinOp:
762 I->setHasNoUnsignedWrap(WrapFlags.HasNUW);
763 I->setHasNoSignedWrap(WrapFlags.HasNSW);
764 break;
765 case OperationType::DisjointOp:
766 cast<PossiblyDisjointInst>(I)->setIsDisjoint(DisjointFlags.IsDisjoint);
767 break;
768 case OperationType::PossiblyExactOp:
769 I->setIsExact(ExactFlags.IsExact);
770 break;
771 case OperationType::GEPOp:
772 cast<GetElementPtrInst>(I)->setNoWrapFlags(GEPFlags);
773 break;
774 case OperationType::FPMathOp:
775 I->setHasAllowReassoc(FMFs.AllowReassoc);
776 I->setHasNoNaNs(FMFs.NoNaNs);
777 I->setHasNoInfs(FMFs.NoInfs);
778 I->setHasNoSignedZeros(FMFs.NoSignedZeros);
779 I->setHasAllowReciprocal(FMFs.AllowReciprocal);
780 I->setHasAllowContract(FMFs.AllowContract);
781 I->setHasApproxFunc(FMFs.ApproxFunc);
782 break;
783 case OperationType::NonNegOp:
784 I->setNonNeg(NonNegFlags.NonNeg);
785 break;
786 case OperationType::Cmp:
787 case OperationType::Other:
788 break;
789 }
790 }
791
793 assert(OpType == OperationType::Cmp &&
794 "recipe doesn't have a compare predicate");
795 return CmpPredicate;
796 }
797
799
800 /// Returns true if the recipe has fast-math flags.
801 bool hasFastMathFlags() const { return OpType == OperationType::FPMathOp; }
802
804
805 bool hasNoUnsignedWrap() const {
806 assert(OpType == OperationType::OverflowingBinOp &&
807 "recipe doesn't have a NUW flag");
808 return WrapFlags.HasNUW;
809 }
810
811 bool hasNoSignedWrap() const {
812 assert(OpType == OperationType::OverflowingBinOp &&
813 "recipe doesn't have a NSW flag");
814 return WrapFlags.HasNSW;
815 }
816
817 bool isDisjoint() const {
818 assert(OpType == OperationType::DisjointOp &&
819 "recipe cannot have a disjoing flag");
821 }
822
823#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
824 void printFlags(raw_ostream &O) const;
825#endif
826};
827
828/// Helper to access the operand that contains the unroll part for this recipe
829/// after unrolling.
830template <unsigned PartOpIdx> class VPUnrollPartAccessor {
831protected:
832 /// Return the VPValue operand containing the unroll part or null if there is
833 /// no such operand.
835
836 /// Return the unroll part.
837 unsigned getUnrollPart(VPUser &U) const;
838};
839
840/// This is a concrete Recipe that models a single VPlan-level instruction.
841/// While as any Recipe it may generate a sequence of IR instructions when
842/// executed, these instructions would always form a single-def expression as
843/// the VPInstruction is also a single def-use vertex.
845 public VPUnrollPartAccessor<1> {
846 friend class VPlanSlp;
847
848public:
849 /// VPlan opcodes, extending LLVM IR with idiomatics instructions.
850 enum {
852 Instruction::OtherOpsEnd + 1, // Combines the incoming and previous
853 // values of a first-order recurrence.
859 /// Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
860 /// The first operand is the incoming value from the predecessor in VPlan,
861 /// the second operand is the incoming value for all other predecessors
862 /// (which are currently not modeled in VPlan).
865 // Increment the canonical IV separately for each unrolled part.
870 // Takes the VPValue to extract from as first operand and the lane or part
871 // to extract as second operand, counting from the end starting with 1 for
872 // last. The second operand must be a positive constant and <= VF.
874 LogicalAnd, // Non-poison propagating logical And.
875 // Add an offset in bytes (second operand) to a base pointer (first
876 // operand). Only generates scalar values (either for the first lane only or
877 // for all lanes, depending on its uses).
879 // Returns a scalar boolean value, which is true if any lane of its (only
880 // boolean) vector operand is true.
882 // Extracts the first active lane of a vector, where the first operand is
883 // the predicate, and the second operand is the vector to extract.
885 };
886
887private:
888 typedef unsigned char OpcodeTy;
889 OpcodeTy Opcode;
890
891 /// An optional name that can be used for the generated IR instruction.
892 const std::string Name;
893
894 /// Returns true if this VPInstruction generates scalar values for all lanes.
895 /// Most VPInstructions generate a single value per part, either vector or
896 /// scalar. VPReplicateRecipe takes care of generating multiple (scalar)
897 /// values per all lanes, stemming from an original ingredient. This method
898 /// identifies the (rare) cases of VPInstructions that do so as well, w/o an
899 /// underlying ingredient.
900 bool doesGeneratePerAllLanes() const;
901
902 /// Returns true if we can generate a scalar for the first lane only if
903 /// needed.
904 bool canGenerateScalarForFirstLane() const;
905
906 /// Utility methods serving execute(): generates a single vector instance of
907 /// the modeled instruction. \returns the generated value. . In some cases an
908 /// existing value is returned rather than a generated one.
909 Value *generate(VPTransformState &State);
910
911 /// Utility methods serving execute(): generates a scalar single instance of
912 /// the modeled instruction for a given lane. \returns the scalar generated
913 /// value for lane \p Lane.
914 Value *generatePerLane(VPTransformState &State, const VPLane &Lane);
915
916#if !defined(NDEBUG)
917 /// Return true if the VPInstruction is a floating point math operation, i.e.
918 /// has fast-math flags.
919 bool isFPMathOp() const;
920#endif
921
922public:
924 const Twine &Name = "")
925 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DL),
926 Opcode(Opcode), Name(Name.str()) {}
927
928 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
929 DebugLoc DL = {}, const Twine &Name = "")
931
932 VPInstruction(unsigned Opcode, CmpInst::Predicate Pred, VPValue *A,
933 VPValue *B, DebugLoc DL = {}, const Twine &Name = "");
934
935 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
936 WrapFlagsTy WrapFlags, DebugLoc DL = {}, const Twine &Name = "")
937 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, WrapFlags, DL),
938 Opcode(Opcode), Name(Name.str()) {}
939
940 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
941 DisjointFlagsTy DisjointFlag, DebugLoc DL = {},
942 const Twine &Name = "")
943 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DisjointFlag, DL),
944 Opcode(Opcode), Name(Name.str()) {
945 assert(Opcode == Instruction::Or && "only OR opcodes can be disjoint");
946 }
947
949 DebugLoc DL = {}, const Twine &Name = "")
950 : VPRecipeWithIRFlags(VPDef::VPInstructionSC,
951 ArrayRef<VPValue *>({Ptr, Offset}), Flags, DL),
952 Opcode(VPInstruction::PtrAdd), Name(Name.str()) {}
953
954 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
955 FastMathFlags FMFs, DebugLoc DL = {}, const Twine &Name = "");
956
957 VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
958
959 VPInstruction *clone() override {
961 auto *New = new VPInstruction(Opcode, Operands, getDebugLoc(), Name);
962 New->transferFlags(*this);
963 return New;
964 }
965
966 unsigned getOpcode() const { return Opcode; }
967
968 /// Generate the instruction.
969 /// TODO: We currently execute only per-part unless a specific instance is
970 /// provided.
971 void execute(VPTransformState &State) override;
972
973 /// Return the cost of this VPInstruction.
975 VPCostContext &Ctx) const override;
976
977#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
978 /// Print the VPInstruction to \p O.
979 void print(raw_ostream &O, const Twine &Indent,
980 VPSlotTracker &SlotTracker) const override;
981
982 /// Print the VPInstruction to dbgs() (for debugging).
983 LLVM_DUMP_METHOD void dump() const;
984#endif
985
986 bool hasResult() const {
987 // CallInst may or may not have a result, depending on the called function.
988 // Conservatively return calls have results for now.
989 switch (getOpcode()) {
990 case Instruction::Ret:
991 case Instruction::Br:
992 case Instruction::Store:
993 case Instruction::Switch:
994 case Instruction::IndirectBr:
995 case Instruction::Resume:
996 case Instruction::CatchRet:
997 case Instruction::Unreachable:
998 case Instruction::Fence:
999 case Instruction::AtomicRMW:
1002 return false;
1003 default:
1004 return true;
1005 }
1006 }
1007
1008 /// Returns true if the underlying opcode may read from or write to memory.
1009 bool opcodeMayReadOrWriteFromMemory() const;
1010
1011 /// Returns true if the recipe only uses the first lane of operand \p Op.
1012 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1013
1014 /// Returns true if the recipe only uses the first part of operand \p Op.
1015 bool onlyFirstPartUsed(const VPValue *Op) const override;
1016
1017 /// Returns true if this VPInstruction produces a scalar value from a vector,
1018 /// e.g. by performing a reduction or extracting a lane.
1019 bool isVectorToScalar() const;
1020
1021 /// Returns true if this VPInstruction's operands are single scalars and the
1022 /// result is also a single scalar.
1023 bool isSingleScalar() const;
1024
1025 /// Returns the symbolic name assigned to the VPInstruction.
1026 StringRef getName() const { return Name; }
1027};
1028
1029/// A recipe to wrap on original IR instruction not to be modified during
1030/// execution, execept for PHIs. For PHIs, a single VPValue operand is allowed,
1031/// and it is used to add a new incoming value for the single predecessor VPBB.
1032/// Expect PHIs, VPIRInstructions cannot have any operands.
1034 Instruction &I;
1035
1036public:
1038 : VPRecipeBase(VPDef::VPIRInstructionSC, ArrayRef<VPValue *>()), I(I) {}
1039
1040 ~VPIRInstruction() override = default;
1041
1042 VP_CLASSOF_IMPL(VPDef::VPIRInstructionSC)
1043
1045 auto *R = new VPIRInstruction(I);
1046 for (auto *Op : operands())
1047 R->addOperand(Op);
1048 return R;
1049 }
1050
1051 void execute(VPTransformState &State) override;
1052
1053 /// Return the cost of this VPIRInstruction.
1055 VPCostContext &Ctx) const override;
1056
1057 Instruction &getInstruction() const { return I; }
1058
1059#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1060 /// Print the recipe.
1061 void print(raw_ostream &O, const Twine &Indent,
1062 VPSlotTracker &SlotTracker) const override;
1063#endif
1064
1065 bool usesScalars(const VPValue *Op) const override {
1067 "Op must be an operand of the recipe");
1068 return true;
1069 }
1070
1071 bool onlyFirstPartUsed(const VPValue *Op) const override {
1073 "Op must be an operand of the recipe");
1074 return true;
1075 }
1076
1077 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1079 "Op must be an operand of the recipe");
1080 return true;
1081 }
1082
1083 /// Update the recipes single operand to the last lane of the operand using \p
1084 /// Builder. Must only be used for single operand VPIRInstructions wrapping a
1085 /// PHINode.
1086 void extractLastLaneOfOperand(VPBuilder &Builder);
1087};
1088
1089/// VPWidenRecipe is a recipe for producing a widened instruction using the
1090/// opcode and operands of the recipe. This recipe covers most of the
1091/// traditional vectorization cases where each recipe transforms into a
1092/// vectorized version of itself.
1094 unsigned Opcode;
1095
1096protected:
1097 template <typename IterT>
1098 VPWidenRecipe(unsigned VPDefOpcode, Instruction &I,
1100 : VPRecipeWithIRFlags(VPDefOpcode, Operands, I), Opcode(I.getOpcode()) {}
1101
1102public:
1103 template <typename IterT>
1105 : VPWidenRecipe(VPDef::VPWidenSC, I, Operands) {}
1106
1107 ~VPWidenRecipe() override = default;
1108
1109 VPWidenRecipe *clone() override {
1110 auto *R = new VPWidenRecipe(*getUnderlyingInstr(), operands());
1111 R->transferFlags(*this);
1112 return R;
1113 }
1114
1115 static inline bool classof(const VPRecipeBase *R) {
1116 return R->getVPDefID() == VPRecipeBase::VPWidenSC ||
1117 R->getVPDefID() == VPRecipeBase::VPWidenEVLSC;
1118 }
1119
1120 static inline bool classof(const VPUser *U) {
1121 auto *R = dyn_cast<VPRecipeBase>(U);
1122 return R && classof(R);
1123 }
1124
1125 /// Produce a widened instruction using the opcode and operands of the recipe,
1126 /// processing State.VF elements.
1127 void execute(VPTransformState &State) override;
1128
1129 /// Return the cost of this VPWidenRecipe.
1131 VPCostContext &Ctx) const override;
1132
1133 unsigned getOpcode() const { return Opcode; }
1134
1135#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1136 /// Print the recipe.
1137 void print(raw_ostream &O, const Twine &Indent,
1138 VPSlotTracker &SlotTracker) const override;
1139#endif
1140};
1141
1142/// A recipe for widening operations with vector-predication intrinsics with
1143/// explicit vector length (EVL).
1146
1147public:
1148 template <typename IterT>
1150 : VPWidenRecipe(VPDef::VPWidenEVLSC, I, Operands) {
1151 addOperand(&EVL);
1152 }
1154 : VPWidenEVLRecipe(*W.getUnderlyingInstr(), W.operands(), EVL) {
1155 transferFlags(W);
1156 }
1157
1158 ~VPWidenEVLRecipe() override = default;
1159
1160 VPWidenRecipe *clone() override final {
1161 llvm_unreachable("VPWidenEVLRecipe cannot be cloned");
1162 return nullptr;
1163 }
1164
1165 VP_CLASSOF_IMPL(VPDef::VPWidenEVLSC);
1166
1168 const VPValue *getEVL() const { return getOperand(getNumOperands() - 1); }
1169
1170 /// Produce a vp-intrinsic using the opcode and operands of the recipe,
1171 /// processing EVL elements.
1172 void execute(VPTransformState &State) override final;
1173
1174 /// Returns true if the recipe only uses the first lane of operand \p Op.
1175 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1177 "Op must be an operand of the recipe");
1178 // EVL in that recipe is always the last operand, thus any use before means
1179 // the VPValue should be vectorized.
1180 return getEVL() == Op;
1181 }
1182
1183#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1184 /// Print the recipe.
1185 void print(raw_ostream &O, const Twine &Indent,
1186 VPSlotTracker &SlotTracker) const override final;
1187#endif
1188};
1189
1190/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1192 /// Cast instruction opcode.
1193 Instruction::CastOps Opcode;
1194
1195 /// Result type for the cast.
1196 Type *ResultTy;
1197
1198public:
1200 CastInst &UI)
1201 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), Opcode(Opcode),
1202 ResultTy(ResultTy) {
1203 assert(UI.getOpcode() == Opcode &&
1204 "opcode of underlying cast doesn't match");
1205 }
1206
1208 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), Opcode(Opcode),
1209 ResultTy(ResultTy) {}
1210
1211 ~VPWidenCastRecipe() override = default;
1212
1214 if (auto *UV = getUnderlyingValue())
1215 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1216 *cast<CastInst>(UV));
1217
1218 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
1219 }
1220
1221 VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
1222
1223 /// Produce widened copies of the cast.
1224 void execute(VPTransformState &State) override;
1225
1226 /// Return the cost of this VPWidenCastRecipe.
1228 VPCostContext &Ctx) const override;
1229
1230#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1231 /// Print the recipe.
1232 void print(raw_ostream &O, const Twine &Indent,
1233 VPSlotTracker &SlotTracker) const override;
1234#endif
1235
1236 Instruction::CastOps getOpcode() const { return Opcode; }
1237
1238 /// Returns the result type of the cast.
1239 Type *getResultType() const { return ResultTy; }
1240};
1241
1242/// VPScalarCastRecipe is a recipe to create scalar cast instructions.
1244 Instruction::CastOps Opcode;
1245
1246 Type *ResultTy;
1247
1248 Value *generate(VPTransformState &State);
1249
1250public:
1252 DebugLoc DL)
1253 : VPSingleDefRecipe(VPDef::VPScalarCastSC, {Op}, DL), Opcode(Opcode),
1254 ResultTy(ResultTy) {}
1255
1256 ~VPScalarCastRecipe() override = default;
1257
1259 return new VPScalarCastRecipe(Opcode, getOperand(0), ResultTy,
1260 getDebugLoc());
1261 }
1262
1263 VP_CLASSOF_IMPL(VPDef::VPScalarCastSC)
1264
1265 void execute(VPTransformState &State) override;
1266
1267 /// Return the cost of this VPScalarCastRecipe.
1269 VPCostContext &Ctx) const override {
1270 // TODO: Compute accurate cost after retiring the legacy cost model.
1271 return 0;
1272 }
1273
1274#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1275 void print(raw_ostream &O, const Twine &Indent,
1276 VPSlotTracker &SlotTracker) const override;
1277#endif
1278
1279 /// Returns the result type of the cast.
1280 Type *getResultType() const { return ResultTy; }
1281
1282 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1283 // At the moment, only uniform codegen is implemented.
1285 "Op must be an operand of the recipe");
1286 return true;
1287 }
1288};
1289
1290/// A recipe for widening vector intrinsics.
1292 /// ID of the vector intrinsic to widen.
1293 Intrinsic::ID VectorIntrinsicID;
1294
1295 /// Scalar return type of the intrinsic.
1296 Type *ResultTy;
1297
1298 /// True if the intrinsic may read from memory.
1299 bool MayReadFromMemory;
1300
1301 /// True if the intrinsic may read write to memory.
1302 bool MayWriteToMemory;
1303
1304 /// True if the intrinsic may have side-effects.
1305 bool MayHaveSideEffects;
1306
1307public:
1309 ArrayRef<VPValue *> CallArguments, Type *Ty,
1310 DebugLoc DL = {})
1311 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1312 VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1313 MayReadFromMemory(CI.mayReadFromMemory()),
1314 MayWriteToMemory(CI.mayWriteToMemory()),
1315 MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1316
1318 ArrayRef<VPValue *> CallArguments, Type *Ty,
1319 DebugLoc DL = {})
1320 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1321 VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1322 LLVMContext &Ctx = Ty->getContext();
1323 AttributeList Attrs = Intrinsic::getAttributes(Ctx, VectorIntrinsicID);
1324 MemoryEffects ME = Attrs.getMemoryEffects();
1325 MayReadFromMemory = ME.onlyWritesMemory();
1326 MayWriteToMemory = ME.onlyReadsMemory();
1327 MayHaveSideEffects = MayWriteToMemory ||
1328 !Attrs.hasFnAttr(Attribute::NoUnwind) ||
1329 !Attrs.hasFnAttr(Attribute::WillReturn);
1330 }
1331
1333 std::initializer_list<VPValue *> CallArguments,
1334 Type *Ty, DebugLoc DL = {})
1335 : VPWidenIntrinsicRecipe(VectorIntrinsicID,
1336 ArrayRef<VPValue *>(CallArguments), Ty, DL) {}
1337
1338 ~VPWidenIntrinsicRecipe() override = default;
1339
1341 return new VPWidenIntrinsicRecipe(*cast<CallInst>(getUnderlyingValue()),
1342 VectorIntrinsicID, {op_begin(), op_end()},
1343 ResultTy, getDebugLoc());
1344 }
1345
1346 VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
1347
1348 /// Produce a widened version of the vector intrinsic.
1349 void execute(VPTransformState &State) override;
1350
1351 /// Return the cost of this vector intrinsic.
1353 VPCostContext &Ctx) const override;
1354
1355 /// Return the ID of the intrinsic.
1356 Intrinsic::ID getVectorIntrinsicID() const { return VectorIntrinsicID; }
1357
1358 /// Return the scalar return type of the intrinsic.
1359 Type *getResultType() const { return ResultTy; }
1360
1361 /// Return to name of the intrinsic as string.
1363
1364 /// Returns true if the intrinsic may read from memory.
1365 bool mayReadFromMemory() const { return MayReadFromMemory; }
1366
1367 /// Returns true if the intrinsic may write to memory.
1368 bool mayWriteToMemory() const { return MayWriteToMemory; }
1369
1370 /// Returns true if the intrinsic may have side-effects.
1371 bool mayHaveSideEffects() const { return MayHaveSideEffects; }
1372
1373#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1374 /// Print the recipe.
1375 void print(raw_ostream &O, const Twine &Indent,
1376 VPSlotTracker &SlotTracker) const override;
1377#endif
1378
1379 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1380};
1381
1382/// A recipe for widening Call instructions using library calls.
1384 /// Variant stores a pointer to the chosen function. There is a 1:1 mapping
1385 /// between a given VF and the chosen vectorized variant, so there will be a
1386 /// different VPlan for each VF with a valid variant.
1387 Function *Variant;
1388
1389public:
1391 ArrayRef<VPValue *> CallArguments, DebugLoc DL = {})
1392 : VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
1393 *cast<Instruction>(UV)),
1394 Variant(Variant) {
1395 assert(
1396 isa<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue()) &&
1397 "last operand must be the called function");
1398 }
1399
1400 ~VPWidenCallRecipe() override = default;
1401
1403 return new VPWidenCallRecipe(getUnderlyingValue(), Variant,
1404 {op_begin(), op_end()}, getDebugLoc());
1405 }
1406
1407 VP_CLASSOF_IMPL(VPDef::VPWidenCallSC)
1408
1409 /// Produce a widened version of the call instruction.
1410 void execute(VPTransformState &State) override;
1411
1412 /// Return the cost of this VPWidenCallRecipe.
1414 VPCostContext &Ctx) const override;
1415
1417 return cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
1418 }
1419
1421 return make_range(op_begin(), op_begin() + getNumOperands() - 1);
1422 }
1424 return make_range(op_begin(), op_begin() + getNumOperands() - 1);
1425 }
1426
1427#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1428 /// Print the recipe.
1429 void print(raw_ostream &O, const Twine &Indent,
1430 VPSlotTracker &SlotTracker) const override;
1431#endif
1432};
1433
1434/// A recipe representing a sequence of load -> update -> store as part of
1435/// a histogram operation. This means there may be aliasing between vector
1436/// lanes, which is handled by the llvm.experimental.vector.histogram family
1437/// of intrinsics. The only update operations currently supported are
1438/// 'add' and 'sub' where the other term is loop-invariant.
1440 /// Opcode of the update operation, currently either add or sub.
1441 unsigned Opcode;
1442
1443public:
1444 template <typename IterT>
1445 VPHistogramRecipe(unsigned Opcode, iterator_range<IterT> Operands,
1446 DebugLoc DL = {})
1447 : VPRecipeBase(VPDef::VPHistogramSC, Operands, DL), Opcode(Opcode) {}
1448
1449 ~VPHistogramRecipe() override = default;
1450
1452 return new VPHistogramRecipe(Opcode, operands(), getDebugLoc());
1453 }
1454
1455 VP_CLASSOF_IMPL(VPDef::VPHistogramSC);
1456
1457 /// Produce a vectorized histogram operation.
1458 void execute(VPTransformState &State) override;
1459
1460 /// Return the cost of this VPHistogramRecipe.
1462 VPCostContext &Ctx) const override;
1463
1464 unsigned getOpcode() const { return Opcode; }
1465
1466 /// Return the mask operand if one was provided, or a null pointer if all
1467 /// lanes should be executed unconditionally.
1468 VPValue *getMask() const {
1469 return getNumOperands() == 3 ? getOperand(2) : nullptr;
1470 }
1471
1472#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1473 /// Print the recipe
1474 void print(raw_ostream &O, const Twine &Indent,
1475 VPSlotTracker &SlotTracker) const override;
1476#endif
1477};
1478
1479/// A recipe for widening select instructions.
1481 template <typename IterT>
1483 : VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I) {}
1484
1485 ~VPWidenSelectRecipe() override = default;
1486
1488 return new VPWidenSelectRecipe(*cast<SelectInst>(getUnderlyingInstr()),
1489 operands());
1490 }
1491
1492 VP_CLASSOF_IMPL(VPDef::VPWidenSelectSC)
1493
1494 /// Produce a widened version of the select instruction.
1495 void execute(VPTransformState &State) override;
1496
1497 /// Return the cost of this VPWidenSelectRecipe.
1499 VPCostContext &Ctx) const override;
1500
1501#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1502 /// Print the recipe.
1503 void print(raw_ostream &O, const Twine &Indent,
1504 VPSlotTracker &SlotTracker) const override;
1505#endif
1506
1507 VPValue *getCond() const {
1508 return getOperand(0);
1509 }
1510
1511 bool isInvariantCond() const {
1513 }
1514};
1515
1516/// A recipe for handling GEP instructions.
1518 bool isPointerLoopInvariant() const {
1520 }
1521
1522 bool isIndexLoopInvariant(unsigned I) const {
1524 }
1525
1526 bool areAllOperandsInvariant() const {
1527 return all_of(operands(), [](VPValue *Op) {
1528 return Op->isDefinedOutsideLoopRegions();
1529 });
1530 }
1531
1532public:
1533 template <typename IterT>
1535 : VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {}
1536
1537 ~VPWidenGEPRecipe() override = default;
1538
1540 return new VPWidenGEPRecipe(cast<GetElementPtrInst>(getUnderlyingInstr()),
1541 operands());
1542 }
1543
1544 VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
1545
1546 /// Generate the gep nodes.
1547 void execute(VPTransformState &State) override;
1548
1549 /// Return the cost of this VPWidenGEPRecipe.
1551 VPCostContext &Ctx) const override {
1552 // TODO: Compute accurate cost after retiring the legacy cost model.
1553 return 0;
1554 }
1555
1556#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1557 /// Print the recipe.
1558 void print(raw_ostream &O, const Twine &Indent,
1559 VPSlotTracker &SlotTracker) const override;
1560#endif
1561};
1562
1563/// A recipe to compute the pointers for widened memory accesses of IndexTy
1564/// in reverse order.
1566 public VPUnrollPartAccessor<2> {
1567 Type *IndexedTy;
1568
1569public:
1572 : VPRecipeWithIRFlags(VPDef::VPReverseVectorPointerSC,
1573 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
1574 IndexedTy(IndexedTy) {}
1575
1576 VP_CLASSOF_IMPL(VPDef::VPReverseVectorPointerSC)
1577
1579 const VPValue *getVFValue() const { return getOperand(1); }
1580
1581 void execute(VPTransformState &State) override;
1582
1583 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1585 "Op must be an operand of the recipe");
1586 return true;
1587 }
1588
1589 /// Return the cost of this VPVectorPointerRecipe.
1591 VPCostContext &Ctx) const override {
1592 // TODO: Compute accurate cost after retiring the legacy cost model.
1593 return 0;
1594 }
1595
1596 /// Returns true if the recipe only uses the first part of operand \p Op.
1597 bool onlyFirstPartUsed(const VPValue *Op) const override {
1599 "Op must be an operand of the recipe");
1600 assert(getNumOperands() <= 2 && "must have at most two operands");
1601 return true;
1602 }
1603
1606 IndexedTy, getGEPNoWrapFlags(),
1607 getDebugLoc());
1608 }
1609
1610#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1611 /// Print the recipe.
1612 void print(raw_ostream &O, const Twine &Indent,
1613 VPSlotTracker &SlotTracker) const override;
1614#endif
1615};
1616
1617/// A recipe to compute the pointers for widened memory accesses of IndexTy.
1619 public VPUnrollPartAccessor<1> {
1620 Type *IndexedTy;
1621
1622public:
1624 DebugLoc DL)
1625 : VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
1626 GEPFlags, DL),
1627 IndexedTy(IndexedTy) {}
1628
1629 VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
1630
1631 void execute(VPTransformState &State) override;
1632
1633 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1635 "Op must be an operand of the recipe");
1636 return true;
1637 }
1638
1639 /// Returns true if the recipe only uses the first part of operand \p Op.
1640 bool onlyFirstPartUsed(const VPValue *Op) const override {
1642 "Op must be an operand of the recipe");
1643 assert(getNumOperands() <= 2 && "must have at most two operands");
1644 return true;
1645 }
1646
1648 return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1650 }
1651
1652 /// Return the cost of this VPHeaderPHIRecipe.
1654 VPCostContext &Ctx) const override {
1655 // TODO: Compute accurate cost after retiring the legacy cost model.
1656 return 0;
1657 }
1658
1659#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1660 /// Print the recipe.
1661 void print(raw_ostream &O, const Twine &Indent,
1662 VPSlotTracker &SlotTracker) const override;
1663#endif
1664};
1665
1666/// A pure virtual base class for all recipes modeling header phis, including
1667/// phis for first order recurrences, pointer inductions and reductions. The
1668/// start value is the first operand of the recipe and the incoming value from
1669/// the backedge is the second operand.
1670///
1671/// Inductions are modeled using the following sub-classes:
1672/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
1673/// starting at a specified value (zero for the main vector loop, the resume
1674/// value for the epilogue vector loop) and stepping by 1. The induction
1675/// controls exiting of the vector loop by comparing against the vector trip
1676/// count. Produces a single scalar PHI for the induction value per
1677/// iteration.
1678/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
1679/// floating point inductions with arbitrary start and step values. Produces
1680/// a vector PHI per-part.
1681/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
1682/// value of an IV with different start and step values. Produces a single
1683/// scalar value per iteration
1684/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
1685/// canonical or derived induction.
1686/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
1687/// pointer induction. Produces either a vector PHI per-part or scalar values
1688/// per-lane based on the canonical induction.
1690protected:
1691 VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
1692 VPValue *Start = nullptr, DebugLoc DL = {})
1693 : VPSingleDefRecipe(VPDefID, ArrayRef<VPValue *>(), UnderlyingInstr, DL) {
1694 if (Start)
1695 addOperand(Start);
1696 }
1697
1698public:
1699 ~VPHeaderPHIRecipe() override = default;
1700
1701 /// Method to support type inquiry through isa, cast, and dyn_cast.
1702 static inline bool classof(const VPRecipeBase *B) {
1703 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
1704 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
1705 }
1706 static inline bool classof(const VPValue *V) {
1707 auto *B = V->getDefiningRecipe();
1708 return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
1709 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
1710 }
1711
1712 /// Generate the phi nodes.
1713 void execute(VPTransformState &State) override = 0;
1714
1715 /// Return the cost of this header phi recipe.
1717 VPCostContext &Ctx) const override;
1718
1719#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1720 /// Print the recipe.
1721 void print(raw_ostream &O, const Twine &Indent,
1722 VPSlotTracker &SlotTracker) const override = 0;
1723#endif
1724
1725 /// Returns the start value of the phi, if one is set.
1727 return getNumOperands() == 0 ? nullptr : getOperand(0);
1728 }
1730 return getNumOperands() == 0 ? nullptr : getOperand(0);
1731 }
1732
1733 /// Update the start value of the recipe.
1735
1736 /// Returns the incoming value from the loop backedge.
1738 return getOperand(1);
1739 }
1740
1741 /// Returns the backedge value as a recipe. The backedge value is guaranteed
1742 /// to be a recipe.
1745 }
1746};
1747
1748/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
1749/// VPWidenPointerInductionRecipe), providing shared functionality, including
1750/// retrieving the step value, induction descriptor and original phi node.
1752 const InductionDescriptor &IndDesc;
1753
1754public:
1755 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
1756 VPValue *Step, const InductionDescriptor &IndDesc,
1757 DebugLoc DL)
1758 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
1759 addOperand(Step);
1760 }
1761
1762 static inline bool classof(const VPRecipeBase *R) {
1763 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
1764 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
1765 }
1766
1767 static inline bool classof(const VPValue *V) {
1768 auto *R = V->getDefiningRecipe();
1769 return R && classof(R);
1770 }
1771
1772 static inline bool classof(const VPHeaderPHIRecipe *R) {
1773 return classof(static_cast<const VPRecipeBase *>(R));
1774 }
1775
1776 virtual void execute(VPTransformState &State) override = 0;
1777
1778 /// Returns the step value of the induction.
1780 const VPValue *getStepValue() const { return getOperand(1); }
1781
1782 PHINode *getPHINode() const { return cast<PHINode>(getUnderlyingValue()); }
1783
1784 /// Returns the induction descriptor for the recipe.
1785 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
1786
1788 // TODO: All operands of base recipe must exist and be at same index in
1789 // derived recipe.
1791 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
1792 }
1793
1795 // TODO: All operands of base recipe must exist and be at same index in
1796 // derived recipe.
1798 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
1799 }
1800};
1801
1802/// A recipe for handling phi nodes of integer and floating-point inductions,
1803/// producing their vector values.
1805 TruncInst *Trunc;
1806
1807public:
1809 VPValue *VF, const InductionDescriptor &IndDesc,
1810 DebugLoc DL)
1811 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
1812 Step, IndDesc, DL),
1813 Trunc(nullptr) {
1814 addOperand(VF);
1815 }
1816
1818 VPValue *VF, const InductionDescriptor &IndDesc,
1819 TruncInst *Trunc, DebugLoc DL)
1820 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
1821 Step, IndDesc, DL),
1822 Trunc(Trunc) {
1823 addOperand(VF);
1824 }
1825
1827
1832 }
1833
1834 VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
1835
1836 /// Generate the vectorized and scalarized versions of the phi node as
1837 /// needed by their users.
1838 void execute(VPTransformState &State) override;
1839
1840#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1841 /// Print the recipe.
1842 void print(raw_ostream &O, const Twine &Indent,
1843 VPSlotTracker &SlotTracker) const override;
1844#endif
1845
1847 const VPValue *getVFValue() const { return getOperand(2); }
1848
1850 // If the recipe has been unrolled (4 operands), return the VPValue for the
1851 // induction increment.
1852 return getNumOperands() == 5 ? getOperand(3) : nullptr;
1853 }
1854
1855 /// Returns the first defined value as TruncInst, if it is one or nullptr
1856 /// otherwise.
1857 TruncInst *getTruncInst() { return Trunc; }
1858 const TruncInst *getTruncInst() const { return Trunc; }
1859
1860 /// Returns true if the induction is canonical, i.e. starting at 0 and
1861 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
1862 /// same type as the canonical induction.
1863 bool isCanonical() const;
1864
1865 /// Returns the scalar type of the induction.
1867 return Trunc ? Trunc->getType() : getPHINode()->getType();
1868 }
1869
1870 /// Returns the VPValue representing the value of this induction at
1871 /// the last unrolled part, if it exists. Returns itself if unrolling did not
1872 /// take place.
1874 return getNumOperands() == 5 ? getOperand(4) : this;
1875 }
1876};
1877
1879 public VPUnrollPartAccessor<3> {
1880 bool IsScalarAfterVectorization;
1881
1882public:
1883 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
1884 /// Start.
1886 const InductionDescriptor &IndDesc,
1887 bool IsScalarAfterVectorization, DebugLoc DL)
1888 : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
1889 Step, IndDesc, DL),
1890 IsScalarAfterVectorization(IsScalarAfterVectorization) {}
1891
1893
1896 cast<PHINode>(getUnderlyingInstr()), getOperand(0), getOperand(1),
1897 getInductionDescriptor(), IsScalarAfterVectorization, getDebugLoc());
1898 }
1899
1900 VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
1901
1902 /// Generate vector values for the pointer induction.
1903 void execute(VPTransformState &State) override;
1904
1905 /// Returns true if only scalar values will be generated.
1906 bool onlyScalarsGenerated(bool IsScalable);
1907
1908 /// Returns the VPValue representing the value of this induction at
1909 /// the first unrolled part, if it exists. Returns itself if unrolling did not
1910 /// take place.
1912 return getUnrollPart(*this) == 0 ? this : getOperand(2);
1913 }
1914
1915#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1916 /// Print the recipe.
1917 void print(raw_ostream &O, const Twine &Indent,
1918 VPSlotTracker &SlotTracker) const override;
1919#endif
1920};
1921
1922/// Recipe to generate a scalar PHI. Used to generate code for recipes that
1923/// produce scalar header phis, including VPCanonicalIVPHIRecipe and
1924/// VPEVLBasedIVPHIRecipe.
1926 std::string Name;
1927
1928public:
1929 VPScalarPHIRecipe(VPValue *Start, VPValue *BackedgeValue, DebugLoc DL,
1930 StringRef Name)
1931 : VPHeaderPHIRecipe(VPDef::VPScalarPHISC, nullptr, Start, DL),
1932 Name(Name.str()) {
1933 addOperand(BackedgeValue);
1934 }
1935
1936 ~VPScalarPHIRecipe() override = default;
1937
1939 llvm_unreachable("cloning not implemented yet");
1940 }
1941
1942 VP_CLASSOF_IMPL(VPDef::VPScalarPHISC)
1943
1944 /// Generate the phi/select nodes.
1945 void execute(VPTransformState &State) override;
1946
1947 /// Returns true if the recipe only uses the first lane of operand \p Op.
1948 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1950 "Op must be an operand of the recipe");
1951 return true;
1952 }
1953
1954#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1955 /// Print the recipe.
1956 void print(raw_ostream &O, const Twine &Indent,
1957 VPSlotTracker &SlotTracker) const override;
1958#endif
1959};
1960
1961/// A recipe for handling phis that are widened in the vector loop.
1962/// In the VPlan native path, all incoming VPValues & VPBasicBlock pairs are
1963/// managed in the recipe directly.
1965 /// List of incoming blocks. Only used in the VPlan native path.
1966 SmallVector<VPBasicBlock *, 2> IncomingBlocks;
1967
1968public:
1969 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
1970 /// debug location \p DL.
1971 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr, DebugLoc DL = {})
1972 : VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi, DL) {
1973 if (Start)
1974 addOperand(Start);
1975 }
1976
1978 llvm_unreachable("cloning not implemented yet");
1979 }
1980
1981 ~VPWidenPHIRecipe() override = default;
1982
1983 VP_CLASSOF_IMPL(VPDef::VPWidenPHISC)
1984
1985 /// Generate the phi/select nodes.
1986 void execute(VPTransformState &State) override;
1987
1988#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1989 /// Print the recipe.
1990 void print(raw_ostream &O, const Twine &Indent,
1991 VPSlotTracker &SlotTracker) const override;
1992#endif
1993
1994 /// Adds a pair (\p IncomingV, \p IncomingBlock) to the phi.
1995 void addIncoming(VPValue *IncomingV, VPBasicBlock *IncomingBlock) {
1996 addOperand(IncomingV);
1997 IncomingBlocks.push_back(IncomingBlock);
1998 }
1999
2000 /// Returns the \p I th incoming VPBasicBlock.
2001 VPBasicBlock *getIncomingBlock(unsigned I) { return IncomingBlocks[I]; }
2002
2003 /// Set the \p I th incoming VPBasicBlock to \p IncomingBlock.
2004 void setIncomingBlock(unsigned I, VPBasicBlock *IncomingBlock) {
2005 IncomingBlocks[I] = IncomingBlock;
2006 }
2007
2008 /// Returns the \p I th incoming VPValue.
2009 VPValue *getIncomingValue(unsigned I) { return getOperand(I); }
2010};
2011
2012/// A recipe for handling first-order recurrence phis. The start value is the
2013/// first operand of the recipe and the incoming value from the backedge is the
2014/// second operand.
2017 : VPHeaderPHIRecipe(VPDef::VPFirstOrderRecurrencePHISC, Phi, &Start) {}
2018
2019 VP_CLASSOF_IMPL(VPDef::VPFirstOrderRecurrencePHISC)
2020
2022 return R->getVPDefID() == VPDef::VPFirstOrderRecurrencePHISC;
2023 }
2024
2027 cast<PHINode>(getUnderlyingInstr()), *getOperand(0));
2028 }
2029
2030 void execute(VPTransformState &State) override;
2031
2032 /// Return the cost of this first-order recurrence phi recipe.
2034 VPCostContext &Ctx) const override;
2035
2036#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2037 /// Print the recipe.
2038 void print(raw_ostream &O, const Twine &Indent,
2039 VPSlotTracker &SlotTracker) const override;
2040#endif
2041};
2042
2043/// A recipe for handling reduction phis. The start value is the first operand
2044/// of the recipe and the incoming value from the backedge is the second
2045/// operand.
2047 public VPUnrollPartAccessor<2> {
2048 /// Descriptor for the reduction.
2049 const RecurrenceDescriptor &RdxDesc;
2050
2051 /// The phi is part of an in-loop reduction.
2052 bool IsInLoop;
2053
2054 /// The phi is part of an ordered reduction. Requires IsInLoop to be true.
2055 bool IsOrdered;
2056
2057 /// When expanding the reduction PHI, the plan's VF element count is divided
2058 /// by this factor to form the reduction phi's VF.
2059 unsigned VFScaleFactor = 1;
2060
2061public:
2062 /// Create a new VPReductionPHIRecipe for the reduction \p Phi described by \p
2063 /// RdxDesc.
2065 VPValue &Start, bool IsInLoop = false,
2066 bool IsOrdered = false, unsigned VFScaleFactor = 1)
2067 : VPHeaderPHIRecipe(VPDef::VPReductionPHISC, Phi, &Start),
2068 RdxDesc(RdxDesc), IsInLoop(IsInLoop), IsOrdered(IsOrdered),
2069 VFScaleFactor(VFScaleFactor) {
2070 assert((!IsOrdered || IsInLoop) && "IsOrdered requires IsInLoop");
2071 }
2072
2073 ~VPReductionPHIRecipe() override = default;
2074
2076 auto *R = new VPReductionPHIRecipe(cast<PHINode>(getUnderlyingInstr()),
2077 RdxDesc, *getOperand(0), IsInLoop,
2078 IsOrdered, VFScaleFactor);
2079 R->addOperand(getBackedgeValue());
2080 return R;
2081 }
2082
2083 VP_CLASSOF_IMPL(VPDef::VPReductionPHISC)
2084
2086 return R->getVPDefID() == VPDef::VPReductionPHISC;
2087 }
2088
2089 /// Generate the phi/select nodes.
2090 void execute(VPTransformState &State) override;
2091
2092#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2093 /// Print the recipe.
2094 void print(raw_ostream &O, const Twine &Indent,
2095 VPSlotTracker &SlotTracker) const override;
2096#endif
2097
2099 return RdxDesc;
2100 }
2101
2102 /// Returns true, if the phi is part of an ordered reduction.
2103 bool isOrdered() const { return IsOrdered; }
2104
2105 /// Returns true, if the phi is part of an in-loop reduction.
2106 bool isInLoop() const { return IsInLoop; }
2107};
2108
2109/// A recipe for forming partial reductions. In the loop, an accumulator and
2110/// vector operand are added together and passed to the next iteration as the
2111/// next accumulator. After the loop body, the accumulator is reduced to a
2112/// scalar value.
2114 unsigned Opcode;
2115
2116public:
2118 VPValue *Op1)
2119 : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1,
2120 ReductionInst) {}
2121 VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
2122 Instruction *ReductionInst = nullptr)
2123 : VPSingleDefRecipe(VPDef::VPPartialReductionSC,
2124 ArrayRef<VPValue *>({Op0, Op1}), ReductionInst),
2125 Opcode(Opcode) {
2126 [[maybe_unused]] auto *AccumulatorRecipe =
2128 assert((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2129 isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2130 "Unexpected operand order for partial reduction recipe");
2131 }
2132 ~VPPartialReductionRecipe() override = default;
2133
2135 return new VPPartialReductionRecipe(Opcode, getOperand(0), getOperand(1),
2137 }
2138
2139 VP_CLASSOF_IMPL(VPDef::VPPartialReductionSC)
2140
2141 /// Generate the reduction in the loop.
2142 void execute(VPTransformState &State) override;
2143
2144 /// Return the cost of this VPPartialReductionRecipe.
2146 VPCostContext &Ctx) const override;
2147
2148 /// Get the binary op's opcode.
2149 unsigned getOpcode() const { return Opcode; }
2150
2151#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2152 /// Print the recipe.
2153 void print(raw_ostream &O, const Twine &Indent,
2154 VPSlotTracker &SlotTracker) const override;
2155#endif
2156};
2157
2158/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2159/// instructions.
2161public:
2162 /// The blend operation is a User of the incoming values and of their
2163 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2164 /// be omitted (implied by passing an odd number of operands) in which case
2165 /// all other incoming values are merged into it.
2167 : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, Phi->getDebugLoc()) {
2168 assert(Operands.size() > 0 && "Expected at least one operand!");
2169 }
2170
2171 VPBlendRecipe *clone() override {
2173 return new VPBlendRecipe(cast<PHINode>(getUnderlyingValue()), Ops);
2174 }
2175
2176 VP_CLASSOF_IMPL(VPDef::VPBlendSC)
2177
2178 /// A normalized blend is one that has an odd number of operands, whereby the
2179 /// first operand does not have an associated mask.
2180 bool isNormalized() const { return getNumOperands() % 2; }
2181
2182 /// Return the number of incoming values, taking into account when normalized
2183 /// the first incoming value will have no mask.
2184 unsigned getNumIncomingValues() const {
2185 return (getNumOperands() + isNormalized()) / 2;
2186 }
2187
2188 /// Return incoming value number \p Idx.
2189 VPValue *getIncomingValue(unsigned Idx) const {
2190 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2191 }
2192
2193 /// Return mask number \p Idx.
2194 VPValue *getMask(unsigned Idx) const {
2195 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2196 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2197 }
2198
2199 /// Generate the phi/select nodes.
2200 void execute(VPTransformState &State) override;
2201
2202 /// Return the cost of this VPWidenMemoryRecipe.
2204 VPCostContext &Ctx) const override;
2205
2206#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2207 /// Print the recipe.
2208 void print(raw_ostream &O, const Twine &Indent,
2209 VPSlotTracker &SlotTracker) const override;
2210#endif
2211
2212 /// Returns true if the recipe only uses the first lane of operand \p Op.
2213 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2215 "Op must be an operand of the recipe");
2216 // Recursing through Blend recipes only, must terminate at header phi's the
2217 // latest.
2218 return all_of(users(),
2219 [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
2220 }
2221};
2222
2223/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2224/// or stores into one wide load/store and shuffles. The first operand of a
2225/// VPInterleave recipe is the address, followed by the stored values, followed
2226/// by an optional mask.
2229
2230 /// Indicates if the interleave group is in a conditional block and requires a
2231 /// mask.
2232 bool HasMask = false;
2233
2234 /// Indicates if gaps between members of the group need to be masked out or if
2235 /// unusued gaps can be loaded speculatively.
2236 bool NeedsMaskForGaps = false;
2237
2238public:
2240 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2241 bool NeedsMaskForGaps)
2242 : VPRecipeBase(VPDef::VPInterleaveSC, {Addr}), IG(IG),
2243 NeedsMaskForGaps(NeedsMaskForGaps) {
2244 for (unsigned i = 0; i < IG->getFactor(); ++i)
2245 if (Instruction *I = IG->getMember(i)) {
2246 if (I->getType()->isVoidTy())
2247 continue;
2248 new VPValue(I, this);
2249 }
2250
2251 for (auto *SV : StoredValues)
2252 addOperand(SV);
2253 if (Mask) {
2254 HasMask = true;
2255 addOperand(Mask);
2256 }
2257 }
2258 ~VPInterleaveRecipe() override = default;
2259
2261 return new VPInterleaveRecipe(IG, getAddr(), getStoredValues(), getMask(),
2262 NeedsMaskForGaps);
2263 }
2264
2265 VP_CLASSOF_IMPL(VPDef::VPInterleaveSC)
2266
2267 /// Return the address accessed by this recipe.
2268 VPValue *getAddr() const {
2269 return getOperand(0); // Address is the 1st, mandatory operand.
2270 }
2271
2272 /// Return the mask used by this recipe. Note that a full mask is represented
2273 /// by a nullptr.
2274 VPValue *getMask() const {
2275 // Mask is optional and therefore the last, currently 2nd operand.
2276 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2277 }
2278
2279 /// Return the VPValues stored by this interleave group. If it is a load
2280 /// interleave group, return an empty ArrayRef.
2282 // The first operand is the address, followed by the stored values, followed
2283 // by an optional mask.
2286 }
2287
2288 /// Generate the wide load or store, and shuffles.
2289 void execute(VPTransformState &State) override;
2290
2291 /// Return the cost of this VPInterleaveRecipe.
2293 VPCostContext &Ctx) const override;
2294
2295#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2296 /// Print the recipe.
2297 void print(raw_ostream &O, const Twine &Indent,
2298 VPSlotTracker &SlotTracker) const override;
2299#endif
2300
2302
2303 /// Returns the number of stored operands of this interleave group. Returns 0
2304 /// for load interleave groups.
2305 unsigned getNumStoreOperands() const {
2306 return getNumOperands() - (HasMask ? 2 : 1);
2307 }
2308
2309 /// The recipe only uses the first lane of the address.
2310 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2312 "Op must be an operand of the recipe");
2313 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2314 }
2315
2316 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2317};
2318
2319/// A recipe to represent inloop reduction operations, performing a reduction on
2320/// a vector operand into a scalar value, and adding the result to a chain.
2321/// The Operands are {ChainOp, VecOp, [Condition]}.
2323 /// The recurrence decriptor for the reduction in question.
2324 const RecurrenceDescriptor &RdxDesc;
2325 bool IsOrdered;
2326 /// Whether the reduction is conditional.
2327 bool IsConditional = false;
2328
2329protected:
2330 VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
2332 VPValue *CondOp, bool IsOrdered, DebugLoc DL)
2333 : VPSingleDefRecipe(SC, Operands, I, DL), RdxDesc(R),
2334 IsOrdered(IsOrdered) {
2335 if (CondOp) {
2336 IsConditional = true;
2337 addOperand(CondOp);
2338 }
2339 }
2340
2341public:
2343 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2344 bool IsOrdered, DebugLoc DL = {})
2345 : VPReductionRecipe(VPDef::VPReductionSC, R, I,
2346 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2347 IsOrdered, DL) {}
2348
2349 ~VPReductionRecipe() override = default;
2350
2352 return new VPReductionRecipe(RdxDesc, getUnderlyingInstr(), getChainOp(),
2353 getVecOp(), getCondOp(), IsOrdered,
2354 getDebugLoc());
2355 }
2356
2357 static inline bool classof(const VPRecipeBase *R) {
2358 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2359 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC;
2360 }
2361
2362 static inline bool classof(const VPUser *U) {
2363 auto *R = dyn_cast<VPRecipeBase>(U);
2364 return R && classof(R);
2365 }
2366
2367 /// Generate the reduction in the loop.
2368 void execute(VPTransformState &State) override;
2369
2370 /// Return the cost of VPReductionRecipe.
2372 VPCostContext &Ctx) const override;
2373
2374#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2375 /// Print the recipe.
2376 void print(raw_ostream &O, const Twine &Indent,
2377 VPSlotTracker &SlotTracker) const override;
2378#endif
2379
2380 /// Return the recurrence decriptor for the in-loop reduction.
2382 return RdxDesc;
2383 }
2384 /// Return true if the in-loop reduction is ordered.
2385 bool isOrdered() const { return IsOrdered; };
2386 /// Return true if the in-loop reduction is conditional.
2387 bool isConditional() const { return IsConditional; };
2388 /// The VPValue of the scalar Chain being accumulated.
2389 VPValue *getChainOp() const { return getOperand(0); }
2390 /// The VPValue of the vector value to be reduced.
2391 VPValue *getVecOp() const { return getOperand(1); }
2392 /// The VPValue of the condition for the block.
2394 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2395 }
2396};
2397
2398/// A recipe to represent inloop reduction operations with vector-predication
2399/// intrinsics, performing a reduction on a vector operand with the explicit
2400/// vector length (EVL) into a scalar value, and adding the result to a chain.
2401/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2403public:
2406 VPDef::VPReductionEVLSC, R.getRecurrenceDescriptor(),
2408 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2409 R.isOrdered(), R.getDebugLoc()) {}
2410
2411 ~VPReductionEVLRecipe() override = default;
2412
2414 llvm_unreachable("cloning not implemented yet");
2415 }
2416
2417 VP_CLASSOF_IMPL(VPDef::VPReductionEVLSC)
2418
2419 /// Generate the reduction in the loop
2420 void execute(VPTransformState &State) override;
2421
2422#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2423 /// Print the recipe.
2424 void print(raw_ostream &O, const Twine &Indent,
2425 VPSlotTracker &SlotTracker) const override;
2426#endif
2427
2428 /// The VPValue of the explicit vector length.
2429 VPValue *getEVL() const { return getOperand(2); }
2430
2431 /// Returns true if the recipe only uses the first lane of operand \p Op.
2432 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2434 "Op must be an operand of the recipe");
2435 return Op == getEVL();
2436 }
2437};
2438
2439/// VPReplicateRecipe replicates a given instruction producing multiple scalar
2440/// copies of the original scalar type, one per lane, instead of producing a
2441/// single copy of widened type for all lanes. If the instruction is known to be
2442/// uniform only one copy, per lane zero, will be generated.
2444 /// Indicator if only a single replica per lane is needed.
2445 bool IsUniform;
2446
2447 /// Indicator if the replicas are also predicated.
2448 bool IsPredicated;
2449
2450public:
2451 template <typename IterT>
2453 bool IsUniform, VPValue *Mask = nullptr)
2454 : VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
2455 IsUniform(IsUniform), IsPredicated(Mask) {
2456 if (Mask)
2457 addOperand(Mask);
2458 }
2459
2460 ~VPReplicateRecipe() override = default;
2461
2463 auto *Copy =
2464 new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsUniform,
2465 isPredicated() ? getMask() : nullptr);
2466 Copy->transferFlags(*this);
2467 return Copy;
2468 }
2469
2470 VP_CLASSOF_IMPL(VPDef::VPReplicateSC)
2471
2472 /// Generate replicas of the desired Ingredient. Replicas will be generated
2473 /// for all parts and lanes unless a specific part and lane are specified in
2474 /// the \p State.
2475 void execute(VPTransformState &State) override;
2476
2477 /// Return the cost of this VPReplicateRecipe.
2479 VPCostContext &Ctx) const override;
2480
2481#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2482 /// Print the recipe.
2483 void print(raw_ostream &O, const Twine &Indent,
2484 VPSlotTracker &SlotTracker) const override;
2485#endif
2486
2487 bool isUniform() const { return IsUniform; }
2488
2489 bool isPredicated() const { return IsPredicated; }
2490
2491 /// Returns true if the recipe only uses the first lane of operand \p Op.
2492 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2494 "Op must be an operand of the recipe");
2495 return isUniform();
2496 }
2497
2498 /// Returns true if the recipe uses scalars of operand \p Op.
2499 bool usesScalars(const VPValue *Op) const override {
2501 "Op must be an operand of the recipe");
2502 return true;
2503 }
2504
2505 /// Returns true if the recipe is used by a widened recipe via an intervening
2506 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
2507 /// in a vector.
2508 bool shouldPack() const;
2509
2510 /// Return the mask of a predicated VPReplicateRecipe.
2512 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
2513 return getOperand(getNumOperands() - 1);
2514 }
2515
2516 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
2517};
2518
2519/// A recipe for generating conditional branches on the bits of a mask.
2521public:
2523 : VPRecipeBase(VPDef::VPBranchOnMaskSC, {}) {
2524 if (BlockInMask) // nullptr means all-one mask.
2525 addOperand(BlockInMask);
2526 }
2527
2529 return new VPBranchOnMaskRecipe(getOperand(0));
2530 }
2531
2532 VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)
2533
2534 /// Generate the extraction of the appropriate bit from the block mask and the
2535 /// conditional branch.
2536 void execute(VPTransformState &State) override;
2537
2538 /// Return the cost of this VPBranchOnMaskRecipe.
2540 VPCostContext &Ctx) const override;
2541
2542#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2543 /// Print the recipe.
2544 void print(raw_ostream &O, const Twine &Indent,
2545 VPSlotTracker &SlotTracker) const override {
2546 O << Indent << "BRANCH-ON-MASK ";
2547 if (VPValue *Mask = getMask())
2548 Mask->printAsOperand(O, SlotTracker);
2549 else
2550 O << " All-One";
2551 }
2552#endif
2553
2554 /// Return the mask used by this recipe. Note that a full mask is represented
2555 /// by a nullptr.
2556 VPValue *getMask() const {
2557 assert(getNumOperands() <= 1 && "should have either 0 or 1 operands");
2558 // Mask is optional.
2559 return getNumOperands() == 1 ? getOperand(0) : nullptr;
2560 }
2561
2562 /// Returns true if the recipe uses scalars of operand \p Op.
2563 bool usesScalars(const VPValue *Op) const override {
2565 "Op must be an operand of the recipe");
2566 return true;
2567 }
2568};
2569
2570/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
2571/// control converges back from a Branch-on-Mask. The phi nodes are needed in
2572/// order to merge values that are set under such a branch and feed their uses.
2573/// The phi nodes can be scalar or vector depending on the users of the value.
2574/// This recipe works in concert with VPBranchOnMaskRecipe.
2576public:
2577 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
2578 /// nodes after merging back from a Branch-on-Mask.
2580 : VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
2581 ~VPPredInstPHIRecipe() override = default;
2582
2584 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
2585 }
2586
2587 VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)
2588
2589 /// Generates phi nodes for live-outs (from a replicate region) as needed to
2590 /// retain SSA form.
2591 void execute(VPTransformState &State) override;
2592
2593 /// Return the cost of this VPPredInstPHIRecipe.
2595 VPCostContext &Ctx) const override {
2596 // TODO: Compute accurate cost after retiring the legacy cost model.
2597 return 0;
2598 }
2599
2600#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2601 /// Print the recipe.
2602 void print(raw_ostream &O, const Twine &Indent,
2603 VPSlotTracker &SlotTracker) const override;
2604#endif
2605
2606 /// Returns true if the recipe uses scalars of operand \p Op.
2607 bool usesScalars(const VPValue *Op) const override {
2609 "Op must be an operand of the recipe");
2610 return true;
2611 }
2612};
2613
2614/// A common base class for widening memory operations. An optional mask can be
2615/// provided as the last operand.
2617protected:
2619
2620 /// Whether the accessed addresses are consecutive.
2622
2623 /// Whether the consecutive accessed addresses are in reverse order.
2625
2626 /// Whether the memory access is masked.
2627 bool IsMasked = false;
2628
2629 void setMask(VPValue *Mask) {
2630 assert(!IsMasked && "cannot re-set mask");
2631 if (!Mask)
2632 return;
2633 addOperand(Mask);
2634 IsMasked = true;
2635 }
2636
2637 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
2638 std::initializer_list<VPValue *> Operands,
2639 bool Consecutive, bool Reverse, DebugLoc DL)
2641 Reverse(Reverse) {
2642 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
2643 }
2644
2645public:
2647 llvm_unreachable("cloning not supported");
2648 }
2649
2650 static inline bool classof(const VPRecipeBase *R) {
2651 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
2652 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
2653 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
2654 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
2655 }
2656
2657 static inline bool classof(const VPUser *U) {
2658 auto *R = dyn_cast<VPRecipeBase>(U);
2659 return R && classof(R);
2660 }
2661
2662 /// Return whether the loaded-from / stored-to addresses are consecutive.
2663 bool isConsecutive() const { return Consecutive; }
2664
2665 /// Return whether the consecutive loaded/stored addresses are in reverse
2666 /// order.
2667 bool isReverse() const { return Reverse; }
2668
2669 /// Return the address accessed by this recipe.
2670 VPValue *getAddr() const { return getOperand(0); }
2671
2672 /// Returns true if the recipe is masked.
2673 bool isMasked() const { return IsMasked; }
2674
2675 /// Return the mask used by this recipe. Note that a full mask is represented
2676 /// by a nullptr.
2677 VPValue *getMask() const {
2678 // Mask is optional and therefore the last operand.
2679 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
2680 }
2681
2682 /// Generate the wide load/store.
2683 void execute(VPTransformState &State) override {
2684 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
2685 }
2686
2687 /// Return the cost of this VPWidenMemoryRecipe.
2689 VPCostContext &Ctx) const override;
2690
2692};
2693
2694/// A recipe for widening load operations, using the address to load from and an
2695/// optional mask.
2696struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
2698 bool Consecutive, bool Reverse, DebugLoc DL)
2699 : VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
2700 Reverse, DL),
2701 VPValue(this, &Load) {
2702 setMask(Mask);
2703 }
2704
2706 return new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(),
2708 getDebugLoc());
2709 }
2710
2711 VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC);
2712
2713 /// Generate a wide load or gather.
2714 void execute(VPTransformState &State) override;
2715
2716#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2717 /// Print the recipe.
2718 void print(raw_ostream &O, const Twine &Indent,
2719 VPSlotTracker &SlotTracker) const override;
2720#endif
2721
2722 /// Returns true if the recipe only uses the first lane of operand \p Op.
2723 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2725 "Op must be an operand of the recipe");
2726 // Widened, consecutive loads operations only demand the first lane of
2727 // their address.
2728 return Op == getAddr() && isConsecutive();
2729 }
2730};
2731
2732/// A recipe for widening load operations with vector-predication intrinsics,
2733/// using the address to load from, the explicit vector length and an optional
2734/// mask.
2735struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
2737 : VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
2738 {L.getAddr(), &EVL}, L.isConsecutive(),
2739 L.isReverse(), L.getDebugLoc()),
2740 VPValue(this, &getIngredient()) {
2741 setMask(Mask);
2742 }
2743
2744 VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
2745
2746 /// Return the EVL operand.
2747 VPValue *getEVL() const { return getOperand(1); }
2748
2749 /// Generate the wide load or gather.
2750 void execute(VPTransformState &State) override;
2751
2752 /// Return the cost of this VPWidenLoadEVLRecipe.
2754 VPCostContext &Ctx) const override;
2755
2756#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2757 /// Print the recipe.
2758 void print(raw_ostream &O, const Twine &Indent,
2759 VPSlotTracker &SlotTracker) const override;
2760#endif
2761
2762 /// Returns true if the recipe only uses the first lane of operand \p Op.
2763 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2765 "Op must be an operand of the recipe");
2766 // Widened loads only demand the first lane of EVL and consecutive loads
2767 // only demand the first lane of their address.
2768 return Op == getEVL() || (Op == getAddr() && isConsecutive());
2769 }
2770};
2771
2772/// A recipe for widening store operations, using the stored value, the address
2773/// to store to and an optional mask.
2776 VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
2777 : VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
2779 setMask(Mask);
2780 }
2781
2783 return new VPWidenStoreRecipe(cast<StoreInst>(Ingredient), getAddr(),
2785 Reverse, getDebugLoc());
2786 }
2787
2788 VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
2789
2790 /// Return the value stored by this recipe.
2791 VPValue *getStoredValue() const { return getOperand(1); }
2792
2793 /// Generate a wide store or scatter.
2794 void execute(VPTransformState &State) override;
2795
2796#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2797 /// Print the recipe.
2798 void print(raw_ostream &O, const Twine &Indent,
2799 VPSlotTracker &SlotTracker) const override;
2800#endif
2801
2802 /// Returns true if the recipe only uses the first lane of operand \p Op.
2803 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2805 "Op must be an operand of the recipe");
2806 // Widened, consecutive stores only demand the first lane of their address,
2807 // unless the same operand is also stored.
2808 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
2809 }
2810};
2811
2812/// A recipe for widening store operations with vector-predication intrinsics,
2813/// using the value to store, the address to store to, the explicit vector
2814/// length and an optional mask.
2817 : VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
2818 {S.getAddr(), S.getStoredValue(), &EVL},
2819 S.isConsecutive(), S.isReverse(), S.getDebugLoc()) {
2820 setMask(Mask);
2821 }
2822
2823 VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
2824
2825 /// Return the address accessed by this recipe.
2826 VPValue *getStoredValue() const { return getOperand(1); }
2827
2828 /// Return the EVL operand.
2829 VPValue *getEVL() const { return getOperand(2); }
2830
2831 /// Generate the wide store or scatter.
2832 void execute(VPTransformState &State) override;
2833
2834 /// Return the cost of this VPWidenStoreEVLRecipe.
2836 VPCostContext &Ctx) const override;
2837
2838#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2839 /// Print the recipe.
2840 void print(raw_ostream &O, const Twine &Indent,
2841 VPSlotTracker &SlotTracker) const override;
2842#endif
2843
2844 /// Returns true if the recipe only uses the first lane of operand \p Op.
2845 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2847 "Op must be an operand of the recipe");
2848 if (Op == getEVL()) {
2849 assert(getStoredValue() != Op && "unexpected store of EVL");
2850 return true;
2851 }
2852 // Widened, consecutive memory operations only demand the first lane of
2853 // their address, unless the same operand is also stored. That latter can
2854 // happen with opaque pointers.
2855 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
2856 }
2857};
2858
2859/// Recipe to expand a SCEV expression.
2861 const SCEV *Expr;
2862 ScalarEvolution &SE;
2863
2864public:
2866 : VPSingleDefRecipe(VPDef::VPExpandSCEVSC, {}), Expr(Expr), SE(SE) {}
2867
2868 ~VPExpandSCEVRecipe() override = default;
2869
2871 return new VPExpandSCEVRecipe(Expr, SE);
2872 }
2873
2874 VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)
2875
2876 /// Generate a canonical vector induction variable of the vector loop, with
2877 void execute(VPTransformState &State) override;
2878
2879 /// Return the cost of this VPExpandSCEVRecipe.
2881 VPCostContext &Ctx) const override {
2882 // TODO: Compute accurate cost after retiring the legacy cost model.
2883 return 0;
2884 }
2885
2886#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2887 /// Print the recipe.
2888 void print(raw_ostream &O, const Twine &Indent,
2889 VPSlotTracker &SlotTracker) const override;
2890#endif
2891
2892 const SCEV *getSCEV() const { return Expr; }
2893};
2894
2895/// Canonical scalar induction phi of the vector loop. Starting at the specified
2896/// start value (either 0 or the resume value when vectorizing the epilogue
2897/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
2898/// canonical induction variable.
2900public:
2902 : VPHeaderPHIRecipe(VPDef::VPCanonicalIVPHISC, nullptr, StartV, DL) {}
2903
2904 ~VPCanonicalIVPHIRecipe() override = default;
2905
2907 auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
2908 R->addOperand(getBackedgeValue());
2909 return R;
2910 }
2911
2912 VP_CLASSOF_IMPL(VPDef::VPCanonicalIVPHISC)
2913
2915 return D->getVPDefID() == VPDef::VPCanonicalIVPHISC;
2916 }
2917
2918 void execute(VPTransformState &State) override {
2920 "cannot execute this recipe, should be replaced by VPScalarPHIRecipe");
2921 }
2922
2923#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2924 /// Print the recipe.
2925 void print(raw_ostream &O, const Twine &Indent,
2926 VPSlotTracker &SlotTracker) const override;
2927#endif
2928
2929 /// Returns the scalar type of the induction.
2931 return getStartValue()->getLiveInIRValue()->getType();
2932 }
2933
2934 /// Returns true if the recipe only uses the first lane of operand \p Op.
2935 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2937 "Op must be an operand of the recipe");
2938 return true;
2939 }
2940
2941 /// Returns true if the recipe only uses the first part of operand \p Op.
2942 bool onlyFirstPartUsed(const VPValue *Op) const override {
2944 "Op must be an operand of the recipe");
2945 return true;
2946 }
2947
2948 /// Return the cost of this VPCanonicalIVPHIRecipe.
2950 VPCostContext &Ctx) const override {
2951 // For now, match the behavior of the legacy cost model.
2952 return 0;
2953 }
2954};
2955
2956/// A recipe for generating the active lane mask for the vector loop that is
2957/// used to predicate the vector operations.
2958/// TODO: It would be good to use the existing VPWidenPHIRecipe instead and
2959/// remove VPActiveLaneMaskPHIRecipe.
2961public:
2963 : VPHeaderPHIRecipe(VPDef::VPActiveLaneMaskPHISC, nullptr, StartMask,
2964 DL) {}
2965
2966 ~VPActiveLaneMaskPHIRecipe() override = default;
2967
2970 if (getNumOperands() == 2)
2971 R->addOperand(getOperand(1));
2972 return R;
2973 }
2974
2975 VP_CLASSOF_IMPL(VPDef::VPActiveLaneMaskPHISC)
2976
2978 return D->getVPDefID() == VPDef::VPActiveLaneMaskPHISC;
2979 }
2980
2981 /// Generate the active lane mask phi of the vector loop.
2982 void execute(VPTransformState &State) override;
2983
2984#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2985 /// Print the recipe.
2986 void print(raw_ostream &O, const Twine &Indent,
2987 VPSlotTracker &SlotTracker) const override;
2988#endif
2989};
2990
2991/// A recipe for generating the phi node for the current index of elements,
2992/// adjusted in accordance with EVL value. It starts at the start value of the
2993/// canonical induction and gets incremented by EVL in each iteration of the
2994/// vector loop.
2996public:
2998 : VPHeaderPHIRecipe(VPDef::VPEVLBasedIVPHISC, nullptr, StartIV, DL) {}
2999
3000 ~VPEVLBasedIVPHIRecipe() override = default;
3001
3003 llvm_unreachable("cloning not implemented yet");
3004 }
3005
3006 VP_CLASSOF_IMPL(VPDef::VPEVLBasedIVPHISC)
3007
3009 return D->getVPDefID() == VPDef::VPEVLBasedIVPHISC;
3010 }
3011
3012 void execute(VPTransformState &State) override {
3014 "cannot execute this recipe, should be replaced by VPScalarPHIRecipe");
3015 }
3016
3017 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3019 VPCostContext &Ctx) const override {
3020 // For now, match the behavior of the legacy cost model.
3021 return 0;
3022 }
3023
3024 /// Returns true if the recipe only uses the first lane of operand \p Op.
3025 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3027 "Op must be an operand of the recipe");
3028 return true;
3029 }
3030
3031#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3032 /// Print the recipe.
3033 void print(raw_ostream &O, const Twine &Indent,
3034 VPSlotTracker &SlotTracker) const override;
3035#endif
3036};
3037
3038/// A Recipe for widening the canonical induction variable of the vector loop.
3040 public VPUnrollPartAccessor<1> {
3041public:
3043 : VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3044
3045 ~VPWidenCanonicalIVRecipe() override = default;
3046
3048 return new VPWidenCanonicalIVRecipe(
3049 cast<VPCanonicalIVPHIRecipe>(getOperand(0)));
3050 }
3051
3052 VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC)
3053
3054 /// Generate a canonical vector induction variable of the vector loop, with
3055 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3056 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3057 void execute(VPTransformState &State) override;
3058
3059 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3061 VPCostContext &Ctx) const override {
3062 // TODO: Compute accurate cost after retiring the legacy cost model.
3063 return 0;
3064 }
3065
3066#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3067 /// Print the recipe.
3068 void print(raw_ostream &O, const Twine &Indent,
3069 VPSlotTracker &SlotTracker) const override;
3070#endif
3071};
3072
3073/// A recipe for converting the input value \p IV value to the corresponding
3074/// value of an IV with different start and step values, using Start + IV *
3075/// Step.
3077 /// Kind of the induction.
3079 /// If not nullptr, the floating point induction binary operator. Must be set
3080 /// for floating point inductions.
3081 const FPMathOperator *FPBinOp;
3082
3083 /// Name to use for the generated IR instruction for the derived IV.
3084 std::string Name;
3085
3086public:
3088 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3089 const Twine &Name = "")
3091 IndDesc.getKind(),
3092 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3093 Start, CanonicalIV, Step, Name) {}
3094
3096 const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3097 VPValue *Step, const Twine &Name = "")
3098 : VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3099 FPBinOp(FPBinOp), Name(Name.str()) {}
3100
3101 ~VPDerivedIVRecipe() override = default;
3102
3104 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3105 getStepValue());
3106 }
3107
3108 VP_CLASSOF_IMPL(VPDef::VPDerivedIVSC)
3109
3110 /// Generate the transformed value of the induction at offset StartValue (1.
3111 /// operand) + IV (2. operand) * StepValue (3, operand).
3112 void execute(VPTransformState &State) override;
3113
3114 /// Return the cost of this VPDerivedIVRecipe.
3116 VPCostContext &Ctx) const override {
3117 // TODO: Compute accurate cost after retiring the legacy cost model.
3118 return 0;
3119 }
3120
3121#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3122 /// Print the recipe.
3123 void print(raw_ostream &O, const Twine &Indent,
3124 VPSlotTracker &SlotTracker) const override;
3125#endif
3126
3128 return getStartValue()->getLiveInIRValue()->getType();
3129 }
3130
3131 VPValue *getStartValue() const { return getOperand(0); }
3132 VPValue *getStepValue() const { return getOperand(2); }
3133
3134 /// Returns true if the recipe only uses the first lane of operand \p Op.
3135 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3137 "Op must be an operand of the recipe");
3138 return true;
3139 }
3140};
3141
3142/// A recipe for handling phi nodes of integer and floating-point inductions,
3143/// producing their scalar values.
3145 public VPUnrollPartAccessor<2> {
3146 Instruction::BinaryOps InductionOpcode;
3147
3148public:
3151 : VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
3152 ArrayRef<VPValue *>({IV, Step}), FMFs),
3153 InductionOpcode(Opcode) {}
3154
3156 VPValue *Step)
3158 IV, Step, IndDesc.getInductionOpcode(),
3159 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3160 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3161 : FastMathFlags()) {}
3162
3163 ~VPScalarIVStepsRecipe() override = default;
3164
3166 return new VPScalarIVStepsRecipe(
3167 getOperand(0), getOperand(1), InductionOpcode,
3169 }
3170
3171 VP_CLASSOF_IMPL(VPDef::VPScalarIVStepsSC)
3172
3173 /// Generate the scalarized versions of the phi node as needed by their users.
3174 void execute(VPTransformState &State) override;
3175
3176 /// Return the cost of this VPScalarIVStepsRecipe.
3178 VPCostContext &Ctx) const override {
3179 // TODO: Compute accurate cost after retiring the legacy cost model.
3180 return 0;
3181 }
3182
3183#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3184 /// Print the recipe.
3185 void print(raw_ostream &O, const Twine &Indent,
3186 VPSlotTracker &SlotTracker) const override;
3187#endif
3188
3189 VPValue *getStepValue() const { return getOperand(1); }
3190
3191 /// Returns true if the recipe only uses the first lane of operand \p Op.
3192 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3194 "Op must be an operand of the recipe");
3195 return true;
3196 }
3197};
3198
3199/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
3200/// holds a sequence of zero or more VPRecipe's each representing a sequence of
3201/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
3203 friend class VPlan;
3204
3205 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3206 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3207 : VPBlockBase(VPBasicBlockSC, Name.str()) {
3208 if (Recipe)
3209 appendRecipe(Recipe);
3210 }
3211
3212public:
3214
3215protected:
3216 /// The VPRecipes held in the order of output instructions to generate.
3218
3219 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
3220 : VPBlockBase(BlockSC, Name.str()) {}
3221
3222public:
3223 ~VPBasicBlock() override {
3224 while (!Recipes.empty())
3225 Recipes.pop_back();
3226 }
3227
3228 /// Instruction iterators...
3233
3234 //===--------------------------------------------------------------------===//
3235 /// Recipe iterator methods
3236 ///
3237 inline iterator begin() { return Recipes.begin(); }
3238 inline const_iterator begin() const { return Recipes.begin(); }
3239 inline iterator end() { return Recipes.end(); }
3240 inline const_iterator end() const { return Recipes.end(); }
3241
3242 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
3243 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
3244 inline reverse_iterator rend() { return Recipes.rend(); }
3245 inline const_reverse_iterator rend() const { return Recipes.rend(); }
3246
3247 inline size_t size() const { return Recipes.size(); }
3248 inline bool empty() const { return Recipes.empty(); }
3249 inline const VPRecipeBase &front() const { return Recipes.front(); }
3250 inline VPRecipeBase &front() { return Recipes.front(); }
3251 inline const VPRecipeBase &back() const { return Recipes.back(); }
3252 inline VPRecipeBase &back() { return Recipes.back(); }
3253
3254 /// Returns a reference to the list of recipes.
3256
3257 /// Returns a pointer to a member of the recipe list.
3259 return &VPBasicBlock::Recipes;
3260 }
3261
3262 /// Method to support type inquiry through isa, cast, and dyn_cast.
3263 static inline bool classof(const VPBlockBase *V) {
3264 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3265 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3266 }
3267
3268 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
3269 assert(Recipe && "No recipe to append.");
3270 assert(!Recipe->Parent && "Recipe already in VPlan");
3271 Recipe->Parent = this;
3272 Recipes.insert(InsertPt, Recipe);
3273 }
3274
3275 /// Augment the existing recipes of a VPBasicBlock with an additional
3276 /// \p Recipe as the last recipe.
3277 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
3278
3279 /// The method which generates the output IR instructions that correspond to
3280 /// this VPBasicBlock, thereby "executing" the VPlan.
3281 void execute(VPTransformState *State) override;
3282
3283 /// Return the cost of this VPBasicBlock.
3285
3286 /// Return the position of the first non-phi node recipe in the block.
3288
3289 /// Returns an iterator range over the PHI-like recipes in the block.
3291 return make_range(begin(), getFirstNonPhi());
3292 }
3293
3294 /// Split current block at \p SplitAt by inserting a new block between the
3295 /// current block and its successors and moving all recipes starting at
3296 /// SplitAt to the new block. Returns the new block.
3297 VPBasicBlock *splitAt(iterator SplitAt);
3298
3301
3302#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3303 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
3304 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
3305 ///
3306 /// Note that the numbering is applied to the whole VPlan, so printing
3307 /// individual blocks is consistent with the whole VPlan printing.
3308 void print(raw_ostream &O, const Twine &Indent,
3309 VPSlotTracker &SlotTracker) const override;
3310 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3311#endif
3312
3313 /// If the block has multiple successors, return the branch recipe terminating
3314 /// the block. If there are no or only a single successor, return nullptr;
3316 const VPRecipeBase *getTerminator() const;
3317
3318 /// Returns true if the block is exiting it's parent region.
3319 bool isExiting() const;
3320
3321 /// Clone the current block and it's recipes, without updating the operands of
3322 /// the cloned recipes.
3323 VPBasicBlock *clone() override;
3324
3325protected:
3326 /// Execute the recipes in the IR basic block \p BB.
3327 void executeRecipes(VPTransformState *State, BasicBlock *BB);
3328
3329 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
3330 /// generated for this VPBB.
3332
3333private:
3334 /// Create an IR BasicBlock to hold the output instructions generated by this
3335 /// VPBasicBlock, and return it. Update the CFGState accordingly.
3336 BasicBlock *createEmptyBasicBlock(VPTransformState &State);
3337};
3338
3339/// A special type of VPBasicBlock that wraps an existing IR basic block.
3340/// Recipes of the block get added before the first non-phi instruction in the
3341/// wrapped block.
3342/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
3343/// preheader block.
3345 friend class VPlan;
3346
3347 BasicBlock *IRBB;
3348
3349 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
3351 : VPBasicBlock(VPIRBasicBlockSC,
3352 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
3353 IRBB(IRBB) {}
3354
3355public:
3356 ~VPIRBasicBlock() override {}
3357
3358 static inline bool classof(const VPBlockBase *V) {
3359 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3360 }
3361
3362 /// The method which generates the output IR instructions that correspond to
3363 /// this VPBasicBlock, thereby "executing" the VPlan.
3364 void execute(VPTransformState *State) override;
3365
3366 VPIRBasicBlock *clone() override;
3367
3368 BasicBlock *getIRBasicBlock() const { return IRBB; }
3369};
3370
3371/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
3372/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
3373/// A VPRegionBlock may indicate that its contents are to be replicated several
3374/// times. This is designed to support predicated scalarization, in which a
3375/// scalar if-then code structure needs to be generated VF * UF times. Having
3376/// this replication indicator helps to keep a single model for multiple
3377/// candidate VF's. The actual replication takes place only once the desired VF
3378/// and UF have been determined.
3380 friend class VPlan;
3381
3382 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
3383 VPBlockBase *Entry;
3384
3385 /// Hold the Single Exiting block of the SESE region modelled by the
3386 /// VPRegionBlock.
3387 VPBlockBase *Exiting;
3388
3389 /// An indicator whether this region is to generate multiple replicated
3390 /// instances of output IR corresponding to its VPBlockBases.
3391 bool IsReplicator;
3392
3393 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
3394 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
3395 const std::string &Name = "", bool IsReplicator = false)
3396 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
3397 IsReplicator(IsReplicator) {
3398 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
3399 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
3400 Entry->setParent(this);
3401 Exiting->setParent(this);
3402 }
3403 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
3404 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3405 IsReplicator(IsReplicator) {}
3406
3407public:
3408 ~VPRegionBlock() override {}
3409
3410 /// Method to support type inquiry through isa, cast, and dyn_cast.
3411 static inline bool classof(const VPBlockBase *V) {
3412 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
3413 }
3414
3415 const VPBlockBase *getEntry() const { return Entry; }
3416 VPBlockBase *getEntry() { return Entry; }
3417
3418 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
3419 /// EntryBlock must have no predecessors.
3420 void setEntry(VPBlockBase *EntryBlock) {
3421 assert(EntryBlock->getPredecessors().empty() &&
3422 "Entry block cannot have predecessors.");
3423 Entry = EntryBlock;
3424 EntryBlock->setParent(this);
3425 }
3426
3427 const VPBlockBase *getExiting() const { return Exiting; }
3428 VPBlockBase *getExiting() { return Exiting; }
3429
3430 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
3431 /// ExitingBlock must have no successors.
3432 void setExiting(VPBlockBase *ExitingBlock) {
3433 assert(ExitingBlock->getSuccessors().empty() &&
3434 "Exit block cannot have successors.");
3435 Exiting = ExitingBlock;
3436 ExitingBlock->setParent(this);
3437 }
3438
3439 /// Returns the pre-header VPBasicBlock of the loop region.
3441 assert(!isReplicator() && "should only get pre-header of loop regions");
3443 }
3444
3445 /// An indicator whether this region is to generate multiple replicated
3446 /// instances of output IR corresponding to its VPBlockBases.
3447 bool isReplicator() const { return IsReplicator; }
3448
3449 /// The method which generates the output IR instructions that correspond to
3450 /// this VPRegionBlock, thereby "executing" the VPlan.
3451 void execute(VPTransformState *State) override;
3452
3453 // Return the cost of this region.
3455
3456#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3457 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
3458 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
3459 /// consequtive numbers.
3460 ///
3461 /// Note that the numbering is applied to the whole VPlan, so printing
3462 /// individual regions is consistent with the whole VPlan printing.
3463 void print(raw_ostream &O, const Twine &Indent,
3464 VPSlotTracker &SlotTracker) const override;
3465 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3466#endif
3467
3468 /// Clone all blocks in the single-entry single-exit region of the block and
3469 /// their recipes without updating the operands of the cloned recipes.
3470 VPRegionBlock *clone() override;
3471};
3472
3473/// VPlan models a candidate for vectorization, encoding various decisions take
3474/// to produce efficient output IR, including which branches, basic-blocks and
3475/// output IR instructions to generate, and their cost. VPlan holds a
3476/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
3477/// VPBasicBlock.
3478class VPlan {
3479 friend class VPlanPrinter;
3480 friend class VPSlotTracker;
3481
3482 /// VPBasicBlock corresponding to the original preheader. Used to place
3483 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
3484 /// rest of VPlan execution.
3485 /// When this VPlan is used for the epilogue vector loop, the entry will be
3486 /// replaced by a new entry block created during skeleton creation.
3487 VPBasicBlock *Entry;
3488
3489 /// VPIRBasicBlock wrapping the header of the original scalar loop.
3490 VPIRBasicBlock *ScalarHeader;
3491
3492 /// Holds the VFs applicable to this VPlan.
3494
3495 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
3496 /// any UF.
3498
3499 /// Holds the name of the VPlan, for printing.
3500 std::string Name;
3501
3502 /// Represents the trip count of the original loop, for folding
3503 /// the tail.
3504 VPValue *TripCount = nullptr;
3505
3506 /// Represents the backedge taken count of the original loop, for folding
3507 /// the tail. It equals TripCount - 1.
3508 VPValue *BackedgeTakenCount = nullptr;
3509
3510 /// Represents the vector trip count.
3511 VPValue VectorTripCount;
3512
3513 /// Represents the vectorization factor of the loop.
3514 VPValue VF;
3515
3516 /// Represents the loop-invariant VF * UF of the vector loop region.
3517 VPValue VFxUF;
3518
3519 /// Holds a mapping between Values and their corresponding VPValue inside
3520 /// VPlan.
3521 Value2VPValueTy Value2VPValue;
3522
3523 /// Contains all the external definitions created for this VPlan. External
3524 /// definitions are VPValues that hold a pointer to their underlying IR.
3525 SmallVector<VPValue *, 16> VPLiveInsToFree;
3526
3527 /// Mapping from SCEVs to the VPValues representing their expansions.
3528 /// NOTE: This mapping is temporary and will be removed once all users have
3529 /// been modeled in VPlan directly.
3530 DenseMap<const SCEV *, VPValue *> SCEVToExpansion;
3531
3532 /// Blocks allocated and owned by the VPlan. They will be deleted once the
3533 /// VPlan is destroyed.
3534 SmallVector<VPBlockBase *> CreatedBlocks;
3535
3536 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
3537 /// wrapping the original header of the scalar loop.
3538 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
3539 : Entry(Entry), ScalarHeader(ScalarHeader) {
3540 Entry->setPlan(this);
3541 assert(ScalarHeader->getNumSuccessors() == 0 &&
3542 "scalar header must be a leaf node");
3543 }
3544
3545public:
3546 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
3547 /// original preheader and scalar header of \p L, to be used as entry and
3548 /// scalar header blocks of the new VPlan.
3549 VPlan(Loop *L);
3550
3551 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
3552 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
3553 VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
3554 setEntry(createVPBasicBlock("preheader"));
3555 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
3556 TripCount = TC;
3557 }
3558
3559 ~VPlan();
3560
3562 Entry = VPBB;
3563 VPBB->setPlan(this);
3564 }
3565
3566 /// Create initial VPlan, having an "entry" VPBasicBlock (wrapping
3567 /// original scalar pre-header) which contains SCEV expansions that need
3568 /// to happen before the CFG is modified (when executing a VPlan for the
3569 /// epilogue vector loop, the original entry needs to be replaced by a new
3570 /// one); a VPBasicBlock for the vector pre-header, followed by a region for
3571 /// the vector loop, followed by the middle VPBasicBlock. If a check is needed
3572 /// to guard executing the scalar epilogue loop, it will be added to the
3573 /// middle block, together with VPBasicBlocks for the scalar preheader and
3574 /// exit blocks. \p InductionTy is the type of the canonical induction and
3575 /// used for related values, like the trip count expression.
3576 static VPlanPtr createInitialVPlan(Type *InductionTy,
3578 bool RequiresScalarEpilogueCheck,
3579 bool TailFolded, Loop *TheLoop);
3580
3581 /// Prepare the plan for execution, setting up the required live-in values.
3582 void prepareToExecute(Value *TripCount, Value *VectorTripCount,
3583 VPTransformState &State);
3584
3585 /// Generate the IR code for this VPlan.
3586 void execute(VPTransformState *State);
3587
3588 /// Return the cost of this plan.
3590
3591 VPBasicBlock *getEntry() { return Entry; }
3592 const VPBasicBlock *getEntry() const { return Entry; }
3593
3594 /// Returns the preheader of the vector loop region, if one exists, or null
3595 /// otherwise.
3597 VPRegionBlock *VectorRegion = getVectorLoopRegion();
3598 return VectorRegion
3599 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
3600 : nullptr;
3601 }
3602
3603 /// Returns the VPRegionBlock of the vector loop.
3605 const VPRegionBlock *getVectorLoopRegion() const;
3606
3607 /// Returns the 'middle' block of the plan, that is the block that selects
3608 /// whether to execute the scalar tail loop or the exit block from the loop
3609 /// latch.
3611 return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
3612 }
3614 return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
3615 }
3616
3617 /// Return the VPBasicBlock for the preheader of the scalar loop.
3619 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
3620 }
3621
3622 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
3623 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
3624
3625 /// Return an iterator range over the VPIRBasicBlock wrapping the exit blocks
3626 /// of the VPlan, that is leaf nodes except the scalar header. Defined in
3627 /// VPlanHCFG, as the definition of the type needs access to the definitions
3628 /// of VPBlockShallowTraversalWrapper.
3629 auto getExitBlocks();
3630
3631 /// Returns true if \p VPBB is an exit block.
3632 bool isExitBlock(VPBlockBase *VPBB);
3633
3634 /// The trip count of the original loop.
3636 assert(TripCount && "trip count needs to be set before accessing it");
3637 return TripCount;
3638 }
3639
3640 /// Resets the trip count for the VPlan. The caller must make sure all uses of
3641 /// the original trip count have been replaced.
3642 void resetTripCount(VPValue *NewTripCount) {
3643 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
3644 "TripCount always must be set");
3645 TripCount = NewTripCount;
3646 }
3647
3648 /// The backedge taken count of the original loop.
3650 if (!BackedgeTakenCount)
3651 BackedgeTakenCount = new VPValue();
3652 return BackedgeTakenCount;
3653 }
3654
3655 /// The vector trip count.
3656 VPValue &getVectorTripCount() { return VectorTripCount; }
3657
3658 /// Returns the VF of the vector loop region.
3659 VPValue &getVF() { return VF; };
3660
3661 /// Returns VF * UF of the vector loop region.
3662 VPValue &getVFxUF() { return VFxUF; }
3663
3664 void addVF(ElementCount VF) { VFs.insert(VF); }
3665
3667 assert(hasVF(VF) && "Cannot set VF not already in plan");
3668 VFs.clear();
3669 VFs.insert(VF);
3670 }
3671
3672 bool hasVF(ElementCount VF) const { return VFs.count(VF); }
3673 bool hasScalableVF() const {
3674 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
3675 }
3676
3677 /// Returns an iterator range over all VFs of the plan.
3680 return {VFs.begin(), VFs.end()};
3681 }
3682
3683 bool hasScalarVFOnly() const {
3684 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
3685 assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
3686 "Plan with scalar VF should only have a single VF");
3687 return HasScalarVFOnly;
3688 }
3689
3690 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
3691
3692 unsigned getUF() const {
3693 assert(UFs.size() == 1 && "Expected a single UF");
3694 return UFs[0];
3695 }
3696
3697 void setUF(unsigned UF) {
3698 assert(hasUF(UF) && "Cannot set the UF not already in plan");
3699 UFs.clear();
3700 UFs.insert(UF);
3701 }
3702
3703 /// Return a string with the name of the plan and the applicable VFs and UFs.
3704 std::string getName() const;
3705
3706 void setName(const Twine &newName) { Name = newName.str(); }
3707
3708 /// Gets the live-in VPValue for \p V or adds a new live-in (if none exists
3709 /// yet) for \p V.
3711 assert(V && "Trying to get or add the VPValue of a null Value");
3712 auto [It, Inserted] = Value2VPValue.try_emplace(V);
3713 if (Inserted) {
3714 VPValue *VPV = new VPValue(V);
3715 VPLiveInsToFree.push_back(VPV);
3716 assert(VPV->isLiveIn() && "VPV must be a live-in.");
3717 It->second = VPV;
3718 }
3719
3720 assert(It->second->isLiveIn() && "Only live-ins should be in mapping");
3721 return It->second;
3722 }
3723
3724 /// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
3725 VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
3726
3727#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3728 /// Print the live-ins of this VPlan to \p O.
3729 void printLiveIns(raw_ostream &O) const;
3730
3731 /// Print this VPlan to \p O.
3732 void print(raw_ostream &O) const;
3733
3734 /// Print this VPlan in DOT format to \p O.
3735 void printDOT(raw_ostream &O) const;
3736
3737 /// Dump the plan to stderr (for debugging).
3738 LLVM_DUMP_METHOD void dump() const;
3739#endif
3740
3741 /// Returns the canonical induction recipe of the vector loop.
3744 if (EntryVPBB->empty()) {
3745 // VPlan native path.
3746 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
3747 }
3748 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
3749 }
3750
3751 VPValue *getSCEVExpansion(const SCEV *S) const {
3752 return SCEVToExpansion.lookup(S);
3753 }
3754
3755 void addSCEVExpansion(const SCEV *S, VPValue *V) {
3756 assert(!SCEVToExpansion.contains(S) && "SCEV already expanded");
3757 SCEVToExpansion[S] = V;
3758 }
3759
3760 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
3761 /// recipes to refer to the clones, and return it.
3762 VPlan *duplicate();
3763
3764 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
3765 /// present. The returned block is owned by the VPlan and deleted once the
3766 /// VPlan is destroyed.
3768 VPRecipeBase *Recipe = nullptr) {
3769 auto *VPB = new VPBasicBlock(Name, Recipe);
3770 CreatedBlocks.push_back(VPB);
3771 return VPB;
3772 }
3773
3774 /// Create a new VPRegionBlock with \p Entry, \p Exiting and \p Name. If \p
3775 /// IsReplicator is true, the region is a replicate region. The returned block
3776 /// is owned by the VPlan and deleted once the VPlan is destroyed.
3778 const std::string &Name = "",
3779 bool IsReplicator = false) {
3780 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, IsReplicator);
3781 CreatedBlocks.push_back(VPB);
3782 return VPB;
3783 }
3784
3785 /// Create a new VPRegionBlock with \p Name and entry and exiting blocks set
3786 /// to nullptr. If \p IsReplicator is true, the region is a replicate region.
3787 /// The returned block is owned by the VPlan and deleted once the VPlan is
3788 /// destroyed.
3789 VPRegionBlock *createVPRegionBlock(const std::string &Name = "",
3790 bool IsReplicator = false) {
3791 auto *VPB = new VPRegionBlock(Name, IsReplicator);
3792 CreatedBlocks.push_back(VPB);
3793 return VPB;
3794 }
3795
3796 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
3797 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
3798 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
3800
3801 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
3802 /// instructions in \p IRBB, except its terminator which is managed by the
3803 /// successors of the block in VPlan. The returned block is owned by the VPlan
3804 /// and deleted once the VPlan is destroyed.
3806};
3807
3808#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3810 const Value *V;
3811
3812 VPlanIngredient(const Value *V) : V(V) {}
3813
3814 void print(raw_ostream &O) const;
3815};
3816
3818 I.print(OS);
3819 return OS;
3820}
3821
3823 Plan.print(OS);
3824 return OS;
3825}
3826#endif
3827
3828} // end namespace llvm
3829
3830#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
aarch64 promote const
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
always inline
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
uint64_t Addr
std::string Name
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1315
Hexagon Common GEP
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file contains the declarations of the entities induced by Vectorization Plans,...
#define VP_CLASSOF_IMPL(VPDefID)
Definition: VPlan.h:471
static const uint32_t IV[8]
Definition: blake3_impl.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:198
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
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:444
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:608
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:22
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:33
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition: DenseMap.h:226
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition: DenseMap.h:147
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition: TypeSize.h:311
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:205
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:933
A struct for saving information about induction variables.
InductionKind
This enum represents the kinds of inductions that we support.
bool mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:310
The group of interleaved loads/stores sharing the same stride and close to each other.
Definition: VectorUtils.h:488
uint32_t getFactor() const
Definition: VectorUtils.h:504
InstTy * getMember(uint32_t Index) const
Get the member with the given index Index.
Definition: VectorUtils.h:558
InstTy * getInsertPos() const
Definition: VectorUtils.h:574
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:176
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
Definition: ModRef.h:198
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:195
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:77
This class represents an analyzed expression in the program.
The main scalar evolution driver.
This class represents the LLVM 'select' instruction.
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:98
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:113
void clear()
Completely clear the SetVector.
Definition: SetVector.h:273
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:264
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:93
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:103
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:162
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
Definition: SetVector.h:254
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:698
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:370
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
iterator erase(const_iterator CI)
Definition: SmallVector.h:737
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
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
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
A recipe for generating the active lane mask for the vector loop that is used to predicate the vector...
Definition: VPlan.h:2960
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:2968
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:2977
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition: VPlan.h:2962
~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:3202
RecipeListTy::const_iterator const_iterator
Definition: VPlan.h:3230
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition: VPlan.h:3277
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition: VPlan.h:3232
RecipeListTy::iterator iterator
Instruction iterators...
Definition: VPlan.h:3229
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:482
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition: VPlan.h:3255
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition: VPlan.h:3219
iterator end()
Definition: VPlan.h:3239
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:3237
RecipeListTy::reverse_iterator reverse_iterator
Definition: VPlan.h:3231
VPBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition: VPlan.cpp:526
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition: VPlan.h:3290
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of this VPBasicBlock.
Definition: VPlan.cpp:772
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition: VPlan.cpp:210
void connectToPredecessors(VPTransformState &State)
Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block generated for this VPBB.
Definition: VPlan.cpp:416
~VPBasicBlock() override
Definition: VPlan.h:3223
VPRegionBlock * getEnclosingLoopRegion()
Definition: VPlan.cpp:575
const_reverse_iterator rbegin() const
Definition: VPlan.h:3243
reverse_iterator rend()
Definition: VPlan.h:3244
VPBasicBlock * splitAt(iterator SplitAt)
Split current block at SplitAt by inserting a new block between the current block and its successors ...
Definition: VPlan.cpp:545
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition: VPlan.h:3217
void executeRecipes(VPTransformState *State, BasicBlock *BB)
Execute the recipes in the IR basic block BB.
Definition: VPlan.cpp:533
VPRecipeBase & back()
Definition: VPlan.h:3252
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPBsicBlock to O, prefixing all lines with Indent.
Definition: VPlan.cpp:645
const VPRecipeBase & front() const
Definition: VPlan.h:3249
const_iterator begin() const
Definition: VPlan.h:3238
VPRecipeBase & front()
Definition: VPlan.h:3250
bool isExiting() const
Returns true if the block is exiting it's parent region.
Definition: VPlan.cpp:623
VPRecipeBase * getTerminator()
If the block has multiple successors, return the branch recipe terminating the block.
Definition: VPlan.cpp:611
const VPRecipeBase & back() const
Definition: VPlan.h:3251
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition: VPlan.h:3268
bool empty() const
Definition: VPlan.h:3248
const_iterator end() const
Definition: VPlan.h:3240
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:3263
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition: VPlan.h:3258
reverse_iterator rbegin()
Definition: VPlan.h:3242
size_t size() const
Definition: VPlan.h:3247
const_reverse_iterator rend() const
Definition: VPlan.h:3245
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition: VPlan.h:2160
VPBlendRecipe(PHINode *Phi, ArrayRef< VPValue * > Operands)
The blend operation is a User of the incoming values and of their respective masks,...
Definition: VPlan.h:2166
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 VPWidenMemoryRecipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2213
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition: VPlan.h:2189
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition: VPlan.h:2194
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition: VPlan.h:2184
VPBlendRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2171
void execute(VPTransformState &State) override
Generate the phi/select nodes.
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:2180
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:78
void setSuccessors(ArrayRef< VPBlockBase * > NewSuccs)
Set each VPBasicBlock in NewSuccss as successor of this VPBlockBase.
Definition: VPlan.h:294
VPRegionBlock * getParent()
Definition: VPlan.h:170
VPBlocksTy & getPredecessors()
Definition: VPlan.h:202
iterator_range< VPBlockBase ** > predecessors()
Definition: VPlan.h:199
const VPBasicBlock * getExitingBasicBlock() const
Definition: VPlan.cpp:180
LLVM_DUMP_METHOD void dump() const
Dump this VPBlockBase to dbgs().
Definition: VPlan.h:350
void setName(const Twine &newName)
Definition: VPlan.h:163
size_t getNumSuccessors() const
Definition: VPlan.h:216
iterator_range< VPBlockBase ** > successors()
Definition: VPlan.h:198
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.
void swapSuccessors()
Swap successors of the block. The block must have exactly 2 successors.
Definition: VPlan.h:309
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:633
bool isLegalToHoistInto()
Return true if it is legal to hoist instructions into this block.
Definition: VPlan.h:322
virtual ~VPBlockBase()=default
const VPBlocksTy & getHierarchicalPredecessors()
Definition: VPlan.h:252
size_t getNumPredecessors() const
Definition: VPlan.h:217
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition: VPlan.h:285
VPBlockBase * getEnclosingBlockWithPredecessors()
Definition: VPlan.cpp:202
const VPBlocksTy & getPredecessors() const
Definition: VPlan.h:201
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:155
virtual InstructionCost cost(ElementCount VF, VPCostContext &Ctx)=0
Return the cost of the block.
VPlan * getPlan()
Definition: VPlan.cpp:155
void setPlan(VPlan *ParentPlan)
Sets the pointer of the plan containing the block.
Definition: VPlan.cpp:174
const VPRegionBlock * getParent() const
Definition: VPlan.h:171
const std::string & getName() const
Definition: VPlan.h:161
void clearSuccessors()
Remove all the successors of this block.
Definition: VPlan.h:304
VPBlockBase * getSingleHierarchicalSuccessor()
Definition: VPlan.h:242
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
Definition: VPlan.h:276
VPBlockBase * getSinglePredecessor() const
Definition: VPlan.h:212
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:236
void clearPredecessors()
Remove all the predecessor of this block.
Definition: VPlan.h:301
unsigned getVPBlockID() const
Definition: VPlan.h:168
void printAsOperand(raw_ostream &OS, bool PrintType=false) const
Definition: VPlan.h:329
VPBlockBase(const unsigned char SC, const std::string &N)
Definition: VPlan.h:147
VPBlocksTy & getSuccessors()
Definition: VPlan.h:196
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
Definition: VPlan.cpp:194
const VPBasicBlock * getEntryBasicBlock() const
Definition: VPlan.cpp:160
void setOneSuccessor(VPBlockBase *Successor)
Set a given VPBlockBase Successor as the single successor of this VPBlockBase.
Definition: VPlan.h:265
void setParent(VPRegionBlock *P)
Definition: VPlan.h:181
VPBlockBase * getSingleHierarchicalPredecessor()
Definition: VPlan.h:258
VPBlockBase * getSingleSuccessor() const
Definition: VPlan.h:206
const VPBlocksTy & getSuccessors() const
Definition: VPlan.h:195
Class that provides utilities for VPBlockBases in VPlan.
Definition: VPlanUtils.h:79
A recipe for generating conditional branches on the bits of a mask.
Definition: VPlan.h:2520
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:2556
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPBranchOnMaskRecipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Definition: VPlan.h:2544
VPBranchOnMaskRecipe(VPValue *BlockInMask)
Definition: VPlan.h:2522
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2528
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2563
void execute(VPTransformState &State) override
Generate the extraction of the appropriate bit from the block mask and the conditional branch.
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition: VPlan.h:2899
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition: VPlan.h:2942
~VPCanonicalIVPHIRecipe() override=default
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:2914
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2906
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
Definition: VPlan.h:2901
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2935
Type * getScalarType() const
Returns the scalar type of the induction.
Definition: VPlan.h:2930
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition: VPlan.h:2918
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:2949
This class augments a recipe with a set of VPValues defined by the recipe.
Definition: VPlanValue.h:298
unsigned getVPDefID() const
Definition: VPlanValue.h:426
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition: VPlan.h:3076
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:3115
VPValue * getStepValue() const
Definition: VPlan.h:3132
Type * getScalarType() const
Definition: VPlan.h:3127
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3103
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition: VPlan.h:3095
~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:3135
VPValue * getStartValue() const
Definition: VPlan.h:3131
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition: VPlan.h:3087
A recipe for generating the phi node for the current index of elements, adjusted in accordance with E...
Definition: VPlan.h:2995
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:3008
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:3002
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition: VPlan.h:3012
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition: VPlan.h:3018
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition: VPlan.h:2997
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3025
Recipe to expand a SCEV expression.
Definition: VPlan.h:2860
VPExpandSCEVRecipe(const SCEV *Expr, ScalarEvolution &SE)
Definition: VPlan.h:2865
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
Definition: VPlan.h:2880
const SCEV * getSCEV() const
Definition: VPlan.h:2892
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with.
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:2870
~VPExpandSCEVRecipe() override=default
A pure virtual base class for all recipes modeling header phis, including phis for first order recurr...
Definition: VPlan.h:1689
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this header phi recipe.
static bool classof(const VPValue *V)
Definition: VPlan.h:1706
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, VPValue *Start=nullptr, DebugLoc DL={})
Definition: VPlan.h:1691
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:1737
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition: VPlan.h:1726
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition: VPlan.h:1734
VPValue * getStartValue() const
Definition: VPlan.h:1729
static bool classof(const VPRecipeBase *B)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:1702
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition: VPlan.h:1743
~VPHeaderPHIRecipe() override=default
A recipe representing a sequence of load -> update -> store as part of a histogram operation.
Definition: VPlan.h:1439
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:1451
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHistogramRecipe.
VPHistogramRecipe(unsigned Opcode, iterator_range< IterT > Operands, DebugLoc DL={})
Definition: VPlan.h:1445
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:1468
unsigned getOpcode() const
Definition: VPlan.h:1464
~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:3344
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:453
BasicBlock * getIRBasicBlock() const
Definition: VPlan.h:3368
~VPIRBasicBlock() override
Definition: VPlan.h:3356
static bool classof(const VPBlockBase *V)
Definition: VPlan.h:3358
VPIRBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition: VPlan.cpp:475
A recipe to wrap on original IR instruction not to be modified during execution, execept for PHIs.
Definition: VPlan.h:1033
Instruction & getInstruction() const
Definition: VPlan.h:1057
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first part of operand Op.
Definition: VPlan.h:1071
~VPIRInstruction() override=default
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1077
VPIRInstruction * clone() override
Clone the current recipe.
Definition: VPlan.h:1044
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPIRInstruction.
void extractLastLaneOfOperand(VPBuilder &Builder)
Update the recipes single operand to the last lane of the operand using Builder.
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:1065
VPIRInstruction(Instruction &I)
Definition: VPlan.h:1037
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:845
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInstruction.
VPInstruction(VPValue *Ptr, VPValue *Offset, GEPNoWrapFlags Flags, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:948
VPInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
Definition: VPlan.h:923
VPInstruction * clone() override
Clone the current recipe.
Definition: VPlan.h:959
@ ResumePhi
Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
Definition: VPlan.h:863
@ FirstOrderRecurrenceSplice
Definition: VPlan.h:851
@ CanonicalIVIncrementForPart
Definition: VPlan.h:866
@ ComputeReductionResult
Definition: VPlan.h:869
@ CalculateTripCountMinusVF
Definition: VPlan.h:864
bool hasResult() const
Definition: VPlan.h:986
bool opcodeMayReadOrWriteFromMemory() const
Returns true if the underlying opcode may read from or write to memory.
LLVM_DUMP_METHOD void dump() const
Print the VPInstruction to dbgs() (for debugging).
StringRef getName() const
Returns the symbolic name assigned to the VPInstruction.
Definition: VPlan.h:1026
unsigned getOpcode() const
Definition: VPlan.h:966
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, WrapFlagsTy WrapFlags, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:935
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:928
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, DisjointFlagsTy DisjointFlag, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:940
bool isVectorToScalar() const
Returns true if this VPInstruction produces a scalar value from a vector, e.g.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the VPInstruction to O.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
bool isSingleScalar() const
Returns true if this VPInstruction's operands are single scalars and the result is also a single scal...
void execute(VPTransformState &State) override
Generate the instruction.
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition: VPlan.h:2227
bool onlyFirstLaneUsed(const VPValue *Op) const override
The recipe only uses the first lane of the address.
Definition: VPlan.h:2310
~VPInterleaveRecipe() override=default
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition: VPlan.h:2268
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps)
Definition: VPlan.h:2239
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:2274
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2260
void execute(VPTransformState &State) override
Generate the wide load or store, and shuffles.
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition: VPlan.h:2281
Instruction * getInsertPos() const
Definition: VPlan.h:2316
const InterleaveGroup< Instruction > * getInterleaveGroup()
Definition: VPlan.h:2301
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInterleaveRecipe.
unsigned getNumStoreOperands() const
Returns the number of stored operands of this interleave group.
Definition: VPlan.h:2305
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
Definition: VPlanHelpers.h:116
A recipe for forming partial reductions.
Definition: VPlan.h:2113
~VPPartialReductionRecipe() override=default
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:2149
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, Instruction *ReductionInst=nullptr)
Definition: VPlan.h:2121
VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0, VPValue *Op1)
Definition: VPlan.h:2117
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2134
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition: VPlan.h:2575
~VPPredInstPHIRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2607
void execute(VPTransformState &State) override
Generates phi nodes for live-outs (from a replicate region) as needed to retain SSA form.
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2583
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 VPPredInstPHIRecipe.
Definition: VPlan.h:2594
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition: VPlan.h:2579
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:366
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:455
bool mayHaveSideEffects() const
Returns true if the recipe may have side-effects.
bool mayWriteToMemory() const
Returns true if the recipe may write to memory.
virtual InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const
Compute the cost of this recipe either using a recipe's specialized implementation or using the legac...
virtual ~VPRecipeBase()=default
VPBasicBlock * getParent()
Definition: VPlan.h:391
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
Definition: VPlan.h:460
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:433
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
VPRecipeBase(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL={})
Definition: VPlan.h:377
virtual VPRecipeBase * clone()=0
Clone the current recipe.
const VPBasicBlock * getParent() const
Definition: VPlan.h:392
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:438
VPRecipeBase(const unsigned char SC, iterator_range< IterT > Operands, DebugLoc DL={})
Definition: VPlan.h:382
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool isPhi() const
Returns true for PHI-like recipes.
Definition: VPlan.h:444
void moveAfter(VPRecipeBase *MovePos)
Unlink this recipe from its current VPBasicBlock and insert it into the VPBasicBlock that MovePos liv...
Class to record LLVM IR flag for a recipe along with it.
Definition: VPlan.h:577
ExactFlagsTy ExactFlags
Definition: VPlan.h:627
FastMathFlagsTy FMFs
Definition: VPlan.h:630
NonNegFlagsTy NonNegFlags
Definition: VPlan.h:629
CmpInst::Predicate CmpPredicate
Definition: VPlan.h:624
GEPNoWrapFlags getGEPNoWrapFlags() const
Definition: VPlan.h:798
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, CmpInst::Predicate Pred, DebugLoc DL={})
Definition: VPlan.h:679
void setFlags(Instruction *I) const
Set the IR flags for I.
Definition: VPlan.h:759
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, GEPNoWrapFlags GEPFlags, DebugLoc DL={})
Definition: VPlan.h:704
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:710
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, FastMathFlags FMFs, DebugLoc DL={})
Definition: VPlan.h:691
void dropPoisonGeneratingFlags()
Drop all poison-generating flags.
Definition: VPlan.h:728
bool hasFastMathFlags() const
Returns true if the recipe has fast-math flags.
Definition: VPlan.h:801
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, Instruction &I)
Definition: VPlan.h:649
DisjointFlagsTy DisjointFlags
Definition: VPlan.h:626
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, WrapFlagsTy WrapFlags, DebugLoc DL={})
Definition: VPlan.h:685
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DisjointFlagsTy DisjointFlags, DebugLoc DL={})
Definition: VPlan.h:697
GEPNoWrapFlags GEPFlags
Definition: VPlan.h:628
void transferFlags(VPRecipeWithIRFlags &Other)
Definition: VPlan.h:635
WrapFlagsTy WrapFlags
Definition: VPlan.h:625
bool hasNoUnsignedWrap() const
Definition: VPlan.h:805
bool isDisjoint() const
Definition: VPlan.h:817
void printFlags(raw_ostream &O) const
CmpInst::Predicate getPredicate() const
Definition: VPlan.h:792
bool hasNoSignedWrap() const
Definition: VPlan.h:811
static bool classof(const VPUser *U)
Definition: VPlan.h:722
FastMathFlags getFastMathFlags() const
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DebugLoc DL={})
Definition: VPlan.h:642
A recipe to represent inloop reduction operations with vector-predication intrinsics,...
Definition: VPlan.h:2402
void execute(VPTransformState &State) override
Generate the reduction in the loop.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2432
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition: VPlan.h:2429
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp)
Definition: VPlan.h:2404
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2413
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPReductionEVLRecipe() override=default
A recipe for handling reduction phis.
Definition: VPlan.h:2047
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition: VPlan.h:2103
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2075
~VPReductionPHIRecipe() override=default
VPReductionPHIRecipe(PHINode *Phi, const RecurrenceDescriptor &RdxDesc, VPValue &Start, bool IsInLoop=false, bool IsOrdered=false, unsigned VFScaleFactor=1)
Create a new VPReductionPHIRecipe for the reduction Phi described by RdxDesc.
Definition: VPlan.h:2064
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
Definition: VPlan.h:2106
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.
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:2085
const RecurrenceDescriptor & getRecurrenceDescriptor() const
Definition: VPlan.h:2098
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition: VPlan.h:2322
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition: VPlan.h:2387
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:2357
VPReductionRecipe(const RecurrenceDescriptor &R, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL={})
Definition: VPlan.h:2342
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
Definition: VPlan.h:2330
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of VPReductionRecipe.
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition: VPlan.h:2391
const RecurrenceDescriptor & getRecurrenceDescriptor() const
Return the recurrence decriptor for the in-loop reduction.
Definition: VPlan.h:2381
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition: VPlan.h:2393
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition: VPlan.h:2385
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition: VPlan.h:2389
VPReductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2351
void execute(VPTransformState &State) override
Generate the reduction in the loop.
static bool classof(const VPUser *U)
Definition: VPlan.h:2362
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:3379
VPRegionBlock * clone() override
Clone all blocks in the single-entry single-exit region of the block and their recipes without updati...
Definition: VPlan.cpp:716
const VPBlockBase * getEntry() const
Definition: VPlan.h:3415
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition: VPlan.h:3447
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition: VPlan.h:3432
VPBlockBase * getExiting()
Definition: VPlan.h:3428
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition: VPlan.h:3420
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of the block.
Definition: VPlan.cpp:779
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPRegionBlock to O (recursively), prefixing all lines with Indent.
Definition: VPlan.cpp:817
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPRegionBlock,...
Definition: VPlan.cpp:725
const VPBlockBase * getExiting() const
Definition: VPlan.h:3427
VPBlockBase * getEntry()
Definition: VPlan.h:3416
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition: VPlan.h:3440
~VPRegionBlock() override
Definition: VPlan.h:3408
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:3411
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition: VPlan.h:2443
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate replicas of the desired Ingredient.
~VPReplicateRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPReplicateRecipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2492
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2499
bool isUniform() const
Definition: VPlan.h:2487
bool isPredicated() const
Definition: VPlan.h:2489
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2462
VPReplicateRecipe(Instruction *I, iterator_range< IterT > Operands, bool IsUniform, VPValue *Mask=nullptr)
Definition: VPlan.h:2452
unsigned getOpcode() const
Definition: VPlan.h:2516
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition: VPlan.h:2511
bool shouldPack() const
Returns true if the recipe is used by a widened recipe via an intervening VPPredInstPHIRecipe.
A recipe to compute the pointers for widened memory accesses of IndexTy in reverse order.
Definition: VPlan.h:1566
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPVectorPointerRecipe.
Definition: VPlan.h:1590
VPReverseVectorPointerRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1604
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition: VPlan.h:1597
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1583
VPReverseVectorPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition: VPlan.h:1570
const VPValue * getVFValue() const
Definition: VPlan.h:1579
VPScalarCastRecipe is a recipe to create scalar cast instructions.
Definition: VPlan.h:1243
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarCastRecipe.
Definition: VPlan.h:1268
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Each concrete VPDef prints itself.
~VPScalarCastRecipe() override=default
VPScalarCastRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1258
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1282
VPScalarCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, DebugLoc DL)
Definition: VPlan.h:1251
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Type * getResultType() const
Returns the result type of the cast.
Definition: VPlan.h:1280
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition: VPlan.h:3145
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:3192
VPValue * getStepValue() const
Definition: VPlan.h:3189
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition: VPlan.h:3177
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step)
Definition: VPlan.h:3155
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3165
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, Instruction::BinaryOps Opcode, FastMathFlags FMFs)
Definition: VPlan.h:3149
~VPScalarIVStepsRecipe() override=default
void execute(VPTransformState &State) override
Generate the scalarized versions of the phi node as needed by their users.
Recipe to generate a scalar PHI.
Definition: VPlan.h:1925
VPScalarPHIRecipe(VPValue *Start, VPValue *BackedgeValue, DebugLoc DL, StringRef Name)
Definition: VPlan.h:1929
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:1948
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPScalarPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPScalarPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1938
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition: VPlan.h:493
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL={})
Definition: VPlan.h:499
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
Definition: VPlan.h:563
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:508
const Instruction * getUnderlyingInstr() const
Definition: VPlan.h:566
VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL={})
Definition: VPlan.h:496
static bool classof(const VPUser *U)
Definition: VPlan.h:555
LLVM_DUMP_METHOD void dump() const
Print this VPSingleDefRecipe to dbgs() (for debugging).
VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV, DebugLoc DL={})
Definition: VPlan.h:504
virtual VPSingleDefRecipe * clone() override=0
Clone the current recipe.
This class can be used to assign names to VPValues.
Definition: VPlanHelpers.h:389
Helper to access the operand that contains the unroll part for this recipe after unrolling.
Definition: VPlan.h:830
VPValue * getUnrollPartOperand(VPUser &U) const
Return the VPValue operand containing the unroll part or null if there is no such operand.
unsigned getUnrollPart(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:206
operand_range operands()
Definition: VPlanValue.h:263
void setOperand(unsigned I, VPValue *New)
Definition: VPlanValue.h:248
unsigned getNumOperands() const
Definition: VPlanValue.h:242
operand_iterator op_end()
Definition: VPlanValue.h:261
operand_iterator op_begin()
Definition: VPlanValue.h:259
VPValue * getOperand(unsigned N) const
Definition: VPlanValue.h:243
VPUser()=delete
void addOperand(VPValue *Operand)
Definition: VPlanValue.h:237
bool isDefinedOutsideLoopRegions() const
Returns true if the VPValue is defined outside any loop region.
Definition: VPlan.cpp:1435
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition: VPlan.cpp:125
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:89
unsigned getNumUsers() const
Definition: VPlanValue.h:117
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition: VPlanValue.h:178
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition: VPlanValue.h:173
friend class VPRecipeBase
Definition: VPlanValue.h:56
user_range users()
Definition: VPlanValue.h:138
A recipe to compute the pointers for widened memory accesses of IndexTy.
Definition: VPlan.h:1619
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition: VPlan.h:1623
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:1640
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1633
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition: VPlan.h:1653
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1647
A recipe for widening Call instructions using library calls.
Definition: VPlan.h:1383
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
const_operand_range arg_operands() const
Definition: VPlan.h:1423
VPWidenCallRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1402
Function * getCalledScalarFunction() const
Definition: VPlan.h:1416
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCallRecipe.
void execute(VPTransformState &State) override
Produce a widened version of the call instruction.
operand_range arg_operands()
Definition: VPlan.h:1420
~VPWidenCallRecipe() override=default
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, DebugLoc DL={})
Definition: VPlan.h:1390
A Recipe for widening the canonical induction variable of the vector loop.
Definition: VPlan.h:3040
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:3060
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3047
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition: VPlan.h:3042
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition: VPlan.h:1191
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, CastInst &UI)
Definition: VPlan.h:1199
Instruction::CastOps getOpcode() const
Definition: VPlan.h:1236
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Returns the result type of the cast.
Definition: VPlan.h:1239
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
Definition: VPlan.h:1207
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:1213
A recipe for widening operations with vector-predication intrinsics with explicit vector length (EVL)...
Definition: VPlan.h:1144
const VPValue * getEVL() const
Definition: VPlan.h:1168
~VPWidenEVLRecipe() override=default
VPWidenEVLRecipe(Instruction &I, iterator_range< IterT > Operands, VPValue &EVL)
Definition: VPlan.h:1149
VPWidenRecipe * clone() override final
Clone the current recipe.
Definition: VPlan.h:1160
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override final
Print the recipe.
VP_CLASSOF_IMPL(VPDef::VPWidenEVLSC)
VPWidenEVLRecipe(VPWidenRecipe &W, VPValue &EVL)
Definition: VPlan.h:1153
void execute(VPTransformState &State) override final
Produce a vp-intrinsic using the opcode and operands of the recipe, processing EVL elements.
VPValue * getEVL()
Definition: VPlan.h:1167
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:1175
A recipe for handling GEP instructions.
Definition: VPlan.h:1517
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the gep nodes.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition: VPlan.h:1550
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1539
~VPWidenGEPRecipe() override=default
VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range< IterT > Operands)
Definition: VPlan.h:1534
Base class for widened induction (VPWidenIntOrFpInductionRecipe and VPWidenPointerInductionRecipe),...
Definition: VPlan.h:1751
static bool classof(const VPValue *V)
Definition: VPlan.h:1767
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition: VPlan.h:1787
PHINode * getPHINode() const
Definition: VPlan.h:1782
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition: VPlan.h:1755
VPValue * getStepValue()
Returns the step value of the induction.
Definition: VPlan.h:1779
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition: VPlan.h:1785
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition: VPlan.h:1794
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:1762
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:1772
const VPValue * getStepValue() const
Definition: VPlan.h:1780
virtual void execute(VPTransformState &State) override=0
Generate the phi nodes.
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition: VPlan.h:1804
const TruncInst * getTruncInst() const
Definition: VPlan.h:1858
const VPValue * getVFValue() const
Definition: VPlan.h:1847
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
Definition: VPlan.h:1817
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1828
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition: VPlan.h:1857
void execute(VPTransformState &State) override
Generate the vectorized and scalarized versions of the phi node as needed by their users.
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition: VPlan.h:1808
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition: VPlan.h:1873
Type * getScalarType() const
Returns the scalar type of the induction.
Definition: VPlan.h:1866
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.
A recipe for widening vector intrinsics.
Definition: VPlan.h:1291
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, std::initializer_list< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1332
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
Definition: VPlan.h:1356
bool mayReadFromMemory() const
Returns true if the intrinsic may read from memory.
Definition: VPlan.h:1365
StringRef getIntrinsicName() const
Return to name of the intrinsic as string.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1317
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
Definition: VPlan.h:1371
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1340
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
Definition: VPlan.h:1368
~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:1359
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.
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1308
A common base class for widening memory operations.
Definition: VPlan.h:2616
bool IsMasked
Whether the memory access is masked.
Definition: VPlan.h:2627
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition: VPlan.h:2624
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition: VPlan.h:2663
static bool classof(const VPUser *U)
Definition: VPlan.h:2657
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition: VPlan.h:2683
Instruction & Ingredient
Definition: VPlan.h:2618
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2646
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenMemoryRecipe.
Instruction & getIngredient() const
Definition: VPlan.h:2691
bool Consecutive
Whether the accessed addresses are consecutive.
Definition: VPlan.h:2621
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:2650
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:2637
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:2677
bool isMasked() const
Returns true if the recipe is masked.
Definition: VPlan.h:2673
void setMask(VPValue *Mask)
Definition: VPlan.h:2629
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition: VPlan.h:2670
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition: VPlan.h:2667
A recipe for handling phis that are widened in the vector loop.
Definition: VPlan.h:1964
void addIncoming(VPValue *IncomingV, VPBasicBlock *IncomingBlock)
Adds a pair (IncomingV, IncomingBlock) to the phi.
Definition: VPlan.h:1995
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start=nullptr, DebugLoc DL={})
Create a new VPWidenPHIRecipe for Phi with start value Start and debug location DL.
Definition: VPlan.h:1971
VPValue * getIncomingValue(unsigned I)
Returns the I th incoming VPValue.
Definition: VPlan.h:2009
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void setIncomingBlock(unsigned I, VPBasicBlock *IncomingBlock)
Set the I th incoming VPBasicBlock to IncomingBlock.
Definition: VPlan.h:2004
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1977
~VPWidenPHIRecipe() override=default
VPBasicBlock * getIncomingBlock(unsigned I)
Returns the I th incoming VPBasicBlock.
Definition: VPlan.h:2001
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1894
~VPWidenPointerInductionRecipe() override=default
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, bool IsScalarAfterVectorization, DebugLoc DL)
Create a new VPWidenPointerInductionRecipe for Phi with start value Start.
Definition: VPlan.h:1885
bool onlyScalarsGenerated(bool IsScalable)
Returns true if only scalar values will be generated.
VPValue * getFirstUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the first unrolled part,...
Definition: VPlan.h:1911
void execute(VPTransformState &State) override
Generate vector values for the pointer induction.
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:1093
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenRecipe.
void execute(VPTransformState &State) override
Produce a widened instruction using the opcode and operands of the recipe, processing State....
VPWidenRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1109
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPWidenRecipe() override=default
VPWidenRecipe(Instruction &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1104
unsigned getOpcode() const
Definition: VPlan.h:1133
VPWidenRecipe(unsigned VPDefOpcode, Instruction &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1098
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:1115
static bool classof(const VPUser *U)
Definition: VPlan.h:1120
VPlanPrinter prints a given VPlan to a given output stream.
Definition: VPlanHelpers.h:418
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
Definition: VPlanSLP.h:72
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3478
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition: VPlan.cpp:1163
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition: VPlan.cpp:1139
bool hasVF(ElementCount VF) const
Definition: VPlan.h:3672
void prepareToExecute(Value *TripCount, Value *VectorTripCount, VPTransformState &State)
Prepare the plan for execution, setting up the required live-in values.
Definition: VPlan.cpp:938
VPBasicBlock * getEntry()
Definition: VPlan.h:3591
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:3777
VPValue & getVectorTripCount()
The vector trip count.
Definition: VPlan.h:3656
void setName(const Twine &newName)
Definition: VPlan.h:3706
bool hasScalableVF() const
Definition: VPlan.h:3673
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition: VPlan.h:3662
VPValue & getVF()
Returns the VF of the vector loop region.
Definition: VPlan.h:3659
VPValue * getTripCount() const
The trip count of the original loop.
Definition: VPlan.h:3635
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition: VPlan.h:3649
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition: VPlan.h:3679
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
Definition: VPlan.h:3553
bool isExitBlock(VPBlockBase *VPBB)
Returns true if VPBB is an exit block.
Definition: VPlan.cpp:967
const VPBasicBlock * getEntry() const
Definition: VPlan.h:3592
unsigned getUF() const
Definition: VPlan.h:3692
static VPlanPtr createInitialVPlan(Type *InductionTy, PredicatedScalarEvolution &PSE, bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop)
Create initial VPlan, having an "entry" VPBasicBlock (wrapping original scalar pre-header) which cont...
Definition: VPlan.cpp:859
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
Definition: VPlan.cpp:1264
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition: VPlan.h:3755
bool hasUF(unsigned UF) const
Definition: VPlan.h:3690
void setVF(ElementCount VF)
Definition: VPlan.h:3666
VPRegionBlock * createVPRegionBlock(const std::string &Name="", bool IsReplicator=false)
Create a new VPRegionBlock with Name and entry and exiting blocks set to nullptr.
Definition: VPlan.h:3789
auto getExitBlocks()
Return an iterator range over the VPIRBasicBlock wrapping the exit blocks of the VPlan,...
Definition: VPlanCFG.h:310
VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition: VPlan.cpp:1070
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition: VPlan.cpp:1064
const VPBasicBlock * getMiddleBlock() const
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition: VPlan.h:3610
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition: VPlan.h:3642
VPBasicBlock * getMiddleBlock()
Definition: VPlan.h:3613
void setEntry(VPBasicBlock *VPBB)
Definition: VPlan.h:3561
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition: VPlan.h:3767
VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
Definition: VPlan.cpp:1270
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:3710
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition: VPlan.cpp:1169
bool hasScalarVFOnly() const
Definition: VPlan.h:3683
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition: VPlan.h:3618
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
Definition: VPlan.cpp:974
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition: VPlan.h:3742
void print(raw_ostream &O) const
Print this VPlan to O.
Definition: VPlan.cpp:1122
void addVF(ElementCount VF)
Definition: VPlan.h:3664
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition: VPlan.h:3623
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
Definition: VPlan.h:3725
VPValue * getSCEVExpansion(const SCEV *S) const
Definition: VPlan.h:3751
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition: VPlan.cpp:1086
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition: VPlan.h:3596
void setUF(unsigned UF)
Definition: VPlan.h:3697
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition: VPlan.cpp:1210
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
An ilist node that can access its parent list.
Definition: ilist_node.h:321
base_list_type::const_reverse_iterator const_reverse_iterator
Definition: ilist.h:125
void pop_back()
Definition: ilist.h:255
base_list_type::reverse_iterator reverse_iterator
Definition: ilist.h:123
base_list_type::const_iterator const_iterator
Definition: ilist.h:122
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
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:52
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.
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
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:1759
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:1739
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
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:1746
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:74
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
#define N
Struct to hold various analysis needed for cost computations.
Definition: VPlanHelpers.h:356
A recipe for handling first-order recurrence phis.
Definition: VPlan.h:2015
void execute(VPTransformState &State) override
Generate the phi nodes.
VPFirstOrderRecurrencePHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2025
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
Definition: VPlan.h:2016
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this first-order recurrence phi recipe.
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:2021
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
WrapFlagsTy(bool HasNUW, bool HasNSW)
Definition: VPlan.h:594
VPTransformState holds information passed down when "executing" a VPlan, needed for generating the ou...
Definition: VPlanHelpers.h:196
A recipe for widening load operations with vector-predication intrinsics, using the address to load f...
Definition: VPlan.h:2735
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:2747
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:2763
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue &EVL, VPValue *Mask)
Definition: VPlan.h:2736
A recipe for widening load operations, using the address to load from and an optional mask.
Definition: VPlan.h:2696
VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC)
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:2697
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2723
void execute(VPTransformState &State) override
Generate a wide load or gather.
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2705
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
A recipe for widening select instructions.
Definition: VPlan.h:1480
bool isInvariantCond() const
Definition: VPlan.h:1511
VPWidenSelectRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1487
VPWidenSelectRecipe(SelectInst &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1482
VPValue * getCond() const
Definition: VPlan.h:1507
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 VPWidenSelectRecipe.
void execute(VPTransformState &State) override
Produce a widened version of the select instruction.
~VPWidenSelectRecipe() override=default
A recipe for widening store operations with vector-predication intrinsics, using the value to store,...
Definition: VPlan.h:2815
VPValue * getStoredValue() const
Return the address accessed by this recipe.
Definition: VPlan.h:2826
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:2845
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue &EVL, VPValue *Mask)
Definition: VPlan.h:2816
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition: VPlan.h:2829
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition: VPlan.h:2774
void execute(VPTransformState &State) override
Generate a wide store or scatter.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2803
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:2775
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition: VPlan.h:2791
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2782
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPlanIngredient(const Value *V)
Definition: VPlan.h:3812
const Value * V
Definition: VPlan.h:3810
void print(raw_ostream &O) const
Definition: VPlan.cpp:1408