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