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 Type *SourceElementTy;
1767
1768 bool isPointerLoopInvariant() const {
1769 return getOperand(0)->isDefinedOutsideLoopRegions();
1770 }
1771
1772 bool isIndexLoopInvariant(unsigned I) const {
1773 return getOperand(I + 1)->isDefinedOutsideLoopRegions();
1774 }
1775
1776 bool areAllOperandsInvariant() const {
1777 return all_of(operands(), [](VPValue *Op) {
1778 return Op->isDefinedOutsideLoopRegions();
1779 });
1780 }
1781
1782public:
1784 : VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP),
1785 SourceElementTy(GEP->getSourceElementType()) {
1787 (void)Metadata;
1789 assert(Metadata.empty() && "unexpected metadata on GEP");
1790 }
1791
1792 ~VPWidenGEPRecipe() override = default;
1793
1798
1799 VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
1800
1801 /// This recipe generates a GEP instruction.
1802 unsigned getOpcode() const { return Instruction::GetElementPtr; }
1803
1804 /// Generate the gep nodes.
1805 void execute(VPTransformState &State) override;
1806
1807 Type *getSourceElementType() const { return SourceElementTy; }
1808
1809 /// Return the cost of this VPWidenGEPRecipe.
1811 VPCostContext &Ctx) const override {
1812 // TODO: Compute accurate cost after retiring the legacy cost model.
1813 return 0;
1814 }
1815
1816#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1817 /// Print the recipe.
1818 void print(raw_ostream &O, const Twine &Indent,
1819 VPSlotTracker &SlotTracker) const override;
1820#endif
1821
1822 /// Returns true if the recipe only uses the first lane of operand \p Op.
1823 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1825 "Op must be an operand of the recipe");
1826 if (Op == getOperand(0))
1827 return isPointerLoopInvariant();
1828 else
1829 return !isPointerLoopInvariant() && Op->isDefinedOutsideLoopRegions();
1830 }
1831};
1832
1833/// A recipe to compute a pointer to the last element of each part of a widened
1834/// memory access for widened memory accesses of IndexedTy. Used for
1835/// VPWidenMemoryRecipes or VPInterleaveRecipes that are reversed.
1837 public VPUnrollPartAccessor<2> {
1838 Type *IndexedTy;
1839
1840 /// The constant stride of the pointer computed by this recipe, expressed in
1841 /// units of IndexedTy.
1842 int64_t Stride;
1843
1844public:
1846 int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
1847 : VPRecipeWithIRFlags(VPDef::VPVectorEndPointerSC,
1848 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
1849 IndexedTy(IndexedTy), Stride(Stride) {
1850 assert(Stride < 0 && "Stride must be negative");
1851 }
1852
1853 VP_CLASSOF_IMPL(VPDef::VPVectorEndPointerSC)
1854
1856 const VPValue *getVFValue() const { return getOperand(1); }
1857
1858 void execute(VPTransformState &State) override;
1859
1860 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1862 "Op must be an operand of the recipe");
1863 return true;
1864 }
1865
1866 /// Return the cost of this VPVectorPointerRecipe.
1868 VPCostContext &Ctx) const override {
1869 // TODO: Compute accurate cost after retiring the legacy cost model.
1870 return 0;
1871 }
1872
1873 /// Returns true if the recipe only uses the first part of operand \p Op.
1874 bool onlyFirstPartUsed(const VPValue *Op) const override {
1876 "Op must be an operand of the recipe");
1877 assert(getNumOperands() <= 2 && "must have at most two operands");
1878 return true;
1879 }
1880
1882 return new VPVectorEndPointerRecipe(getOperand(0), getVFValue(), IndexedTy,
1883 Stride, getGEPNoWrapFlags(),
1884 getDebugLoc());
1885 }
1886
1887#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1888 /// Print the recipe.
1889 void print(raw_ostream &O, const Twine &Indent,
1890 VPSlotTracker &SlotTracker) const override;
1891#endif
1892};
1893
1894/// A recipe to compute the pointers for widened memory accesses of IndexTy.
1896 public VPUnrollPartAccessor<1> {
1897 Type *SourceElementTy;
1898
1899public:
1902 : VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
1903 GEPFlags, DL),
1904 SourceElementTy(SourceElementTy) {}
1905
1906 VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
1907
1908 void execute(VPTransformState &State) override;
1909
1910 Type *getSourceElementType() const { return SourceElementTy; }
1911
1912 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1914 "Op must be an operand of the recipe");
1915 return true;
1916 }
1917
1918 /// Returns true if the recipe only uses the first part of operand \p Op.
1919 bool onlyFirstPartUsed(const VPValue *Op) const override {
1921 "Op must be an operand of the recipe");
1922 assert(getNumOperands() <= 2 && "must have at most two operands");
1923 return true;
1924 }
1925
1927 return new VPVectorPointerRecipe(getOperand(0), SourceElementTy,
1929 }
1930
1931 /// Return true if this VPVectorPointerRecipe corresponds to part 0. Note that
1932 /// this is only accurate after the VPlan has been unrolled.
1933 bool isFirstPart() const { return getUnrollPart(*this) == 0; }
1934
1935 /// Return the cost of this VPHeaderPHIRecipe.
1937 VPCostContext &Ctx) const override {
1938 // TODO: Compute accurate cost after retiring the legacy cost model.
1939 return 0;
1940 }
1941
1942#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1943 /// Print the recipe.
1944 void print(raw_ostream &O, const Twine &Indent,
1945 VPSlotTracker &SlotTracker) const override;
1946#endif
1947};
1948
1949/// A pure virtual base class for all recipes modeling header phis, including
1950/// phis for first order recurrences, pointer inductions and reductions. The
1951/// start value is the first operand of the recipe and the incoming value from
1952/// the backedge is the second operand.
1953///
1954/// Inductions are modeled using the following sub-classes:
1955/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
1956/// starting at a specified value (zero for the main vector loop, the resume
1957/// value for the epilogue vector loop) and stepping by 1. The induction
1958/// controls exiting of the vector loop by comparing against the vector trip
1959/// count. Produces a single scalar PHI for the induction value per
1960/// iteration.
1961/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
1962/// floating point inductions with arbitrary start and step values. Produces
1963/// a vector PHI per-part.
1964/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
1965/// value of an IV with different start and step values. Produces a single
1966/// scalar value per iteration
1967/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
1968/// canonical or derived induction.
1969/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
1970/// pointer induction. Produces either a vector PHI per-part or scalar values
1971/// per-lane based on the canonical induction.
1973 public VPPhiAccessors {
1974protected:
1975 VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
1976 VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
1977 : VPSingleDefRecipe(VPDefID, ArrayRef<VPValue *>({Start}),
1978 UnderlyingInstr, DL) {}
1979
1980 const VPRecipeBase *getAsRecipe() const override { return this; }
1981
1982public:
1983 ~VPHeaderPHIRecipe() override = default;
1984
1985 /// Method to support type inquiry through isa, cast, and dyn_cast.
1986 static inline bool classof(const VPRecipeBase *B) {
1987 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
1988 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
1989 }
1990 static inline bool classof(const VPValue *V) {
1991 auto *B = V->getDefiningRecipe();
1992 return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
1993 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
1994 }
1995
1996 /// Generate the phi nodes.
1997 void execute(VPTransformState &State) override = 0;
1998
1999 /// Return the cost of this header phi recipe.
2001 VPCostContext &Ctx) const override;
2002
2003#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2004 /// Print the recipe.
2005 void print(raw_ostream &O, const Twine &Indent,
2006 VPSlotTracker &SlotTracker) const override = 0;
2007#endif
2008
2009 /// Returns the start value of the phi, if one is set.
2011 return getNumOperands() == 0 ? nullptr : getOperand(0);
2012 }
2014 return getNumOperands() == 0 ? nullptr : getOperand(0);
2015 }
2016
2017 /// Update the start value of the recipe.
2019
2020 /// Returns the incoming value from the loop backedge.
2022 return getOperand(1);
2023 }
2024
2025 /// Update the incoming value from the loop backedge.
2027
2028 /// Returns the backedge value as a recipe. The backedge value is guaranteed
2029 /// to be a recipe.
2031 return *getBackedgeValue()->getDefiningRecipe();
2032 }
2033};
2034
2035/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2036/// VPWidenPointerInductionRecipe), providing shared functionality, including
2037/// retrieving the step value, induction descriptor and original phi node.
2039 const InductionDescriptor &IndDesc;
2040
2041public:
2042 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
2043 VPValue *Step, const InductionDescriptor &IndDesc,
2044 DebugLoc DL)
2045 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2046 addOperand(Step);
2047 }
2048
2049 static inline bool classof(const VPRecipeBase *R) {
2050 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
2051 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
2052 }
2053
2054 static inline bool classof(const VPValue *V) {
2055 auto *R = V->getDefiningRecipe();
2056 return R && classof(R);
2057 }
2058
2059 static inline bool classof(const VPHeaderPHIRecipe *R) {
2060 return classof(static_cast<const VPRecipeBase *>(R));
2061 }
2062
2063 virtual void execute(VPTransformState &State) override = 0;
2064
2065 /// Returns the step value of the induction.
2067 const VPValue *getStepValue() const { return getOperand(1); }
2068
2069 /// Update the step value of the recipe.
2070 void setStepValue(VPValue *V) { setOperand(1, V); }
2071
2073 const VPValue *getVFValue() const { return getOperand(2); }
2074
2075 /// Returns the number of incoming values, also number of incoming blocks.
2076 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2077 /// incoming value, its start value.
2078 unsigned getNumIncoming() const override { return 1; }
2079
2081
2082 /// Returns the induction descriptor for the recipe.
2083 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
2084
2086 // TODO: All operands of base recipe must exist and be at same index in
2087 // derived recipe.
2089 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2090 }
2091
2093 // TODO: All operands of base recipe must exist and be at same index in
2094 // derived recipe.
2096 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2097 }
2098
2099 /// Returns true if the recipe only uses the first lane of operand \p Op.
2100 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2102 "Op must be an operand of the recipe");
2103 // The recipe creates its own wide start value, so it only requests the
2104 // first lane of the operand.
2105 // TODO: Remove once creating the start value is modeled separately.
2106 return Op == getStartValue() || Op == getStepValue();
2107 }
2108};
2109
2110/// A recipe for handling phi nodes of integer and floating-point inductions,
2111/// producing their vector values. This is an abstract recipe and must be
2112/// converted to concrete recipes before executing.
2114 TruncInst *Trunc;
2115
2116 // If this recipe is unrolled it will have 2 additional operands.
2117 bool isUnrolled() const { return getNumOperands() == 5; }
2118
2119public:
2121 VPValue *VF, const InductionDescriptor &IndDesc,
2122 DebugLoc DL)
2123 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2124 Step, IndDesc, DL),
2125 Trunc(nullptr) {
2126 addOperand(VF);
2127 }
2128
2130 VPValue *VF, const InductionDescriptor &IndDesc,
2131 TruncInst *Trunc, DebugLoc DL)
2132 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2133 Step, IndDesc, DL),
2134 Trunc(Trunc) {
2135 addOperand(VF);
2137 (void)Metadata;
2138 if (Trunc)
2140 assert(Metadata.empty() && "unexpected metadata on Trunc");
2141 }
2142
2144
2150
2151 VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
2152
2153 void execute(VPTransformState &State) override {
2154 llvm_unreachable("cannot execute this recipe, should be expanded via "
2155 "expandVPWidenIntOrFpInductionRecipe");
2156 }
2157
2158#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2159 /// Print the recipe.
2160 void print(raw_ostream &O, const Twine &Indent,
2161 VPSlotTracker &SlotTracker) const override;
2162#endif
2163
2165 // If the recipe has been unrolled return the VPValue for the induction
2166 // increment.
2167 return isUnrolled() ? getOperand(getNumOperands() - 2) : nullptr;
2168 }
2169
2170 /// Returns the number of incoming values, also number of incoming blocks.
2171 /// Note that at the moment, VPWidenIntOrFpInductionRecipes only have a single
2172 /// incoming value, its start value.
2173 unsigned getNumIncoming() const override { return 1; }
2174
2175 /// Returns the first defined value as TruncInst, if it is one or nullptr
2176 /// otherwise.
2177 TruncInst *getTruncInst() { return Trunc; }
2178 const TruncInst *getTruncInst() const { return Trunc; }
2179
2180 /// Returns true if the induction is canonical, i.e. starting at 0 and
2181 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
2182 /// same type as the canonical induction.
2183 bool isCanonical() const;
2184
2185 /// Returns the scalar type of the induction.
2187 return Trunc ? Trunc->getType()
2189 }
2190
2191 /// Returns the VPValue representing the value of this induction at
2192 /// the last unrolled part, if it exists. Returns itself if unrolling did not
2193 /// take place.
2195 return isUnrolled() ? getOperand(getNumOperands() - 1) : this;
2196 }
2197};
2198
2200 bool IsScalarAfterVectorization;
2201
2202public:
2203 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2204 /// Start and the number of elements unrolled \p NumUnrolledElems, typically
2205 /// VF*UF.
2207 VPValue *NumUnrolledElems,
2208 const InductionDescriptor &IndDesc,
2209 bool IsScalarAfterVectorization, DebugLoc DL)
2210 : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
2211 Step, IndDesc, DL),
2212 IsScalarAfterVectorization(IsScalarAfterVectorization) {
2213 addOperand(NumUnrolledElems);
2214 }
2215
2217
2221 getOperand(2), getInductionDescriptor(), IsScalarAfterVectorization,
2222 getDebugLoc());
2223 }
2224
2225 VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
2226
2227 /// Generate vector values for the pointer induction.
2228 void execute(VPTransformState &State) override {
2229 llvm_unreachable("cannot execute this recipe, should be expanded via "
2230 "expandVPWidenPointerInduction");
2231 };
2232
2233 /// Returns true if only scalar values will be generated.
2234 bool onlyScalarsGenerated(bool IsScalable);
2235
2236#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2237 /// Print the recipe.
2238 void print(raw_ostream &O, const Twine &Indent,
2239 VPSlotTracker &SlotTracker) const override;
2240#endif
2241};
2242
2243/// A recipe for widened phis. Incoming values are operands of the recipe and
2244/// their operand index corresponds to the incoming predecessor block. If the
2245/// recipe is placed in an entry block to a (non-replicate) region, it must have
2246/// exactly 2 incoming values, the first from the predecessor of the region and
2247/// the second from the exiting block of the region.
2249 public VPPhiAccessors {
2250 /// Name to use for the generated IR instruction for the widened phi.
2251 std::string Name;
2252
2253protected:
2254 const VPRecipeBase *getAsRecipe() const override { return this; }
2255
2256public:
2257 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
2258 /// debug location \p DL.
2259 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
2260 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
2261 : VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi, DL),
2262 Name(Name.str()) {
2263 if (Start)
2264 addOperand(Start);
2265 }
2266
2269 getOperand(0), getDebugLoc(), Name);
2271 C->addOperand(Op);
2272 return C;
2273 }
2274
2275 ~VPWidenPHIRecipe() override = default;
2276
2277 VP_CLASSOF_IMPL(VPDef::VPWidenPHISC)
2278
2279 /// Generate the phi/select nodes.
2280 void execute(VPTransformState &State) override;
2281
2282#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2283 /// Print the recipe.
2284 void print(raw_ostream &O, const Twine &Indent,
2285 VPSlotTracker &SlotTracker) const override;
2286#endif
2287};
2288
2289/// A recipe for handling first-order recurrence phis. The start value is the
2290/// first operand of the recipe and the incoming value from the backedge is the
2291/// second operand.
2294 : VPHeaderPHIRecipe(VPDef::VPFirstOrderRecurrencePHISC, Phi, &Start) {}
2295
2296 VP_CLASSOF_IMPL(VPDef::VPFirstOrderRecurrencePHISC)
2297
2302
2303 void execute(VPTransformState &State) override;
2304
2305 /// Return the cost of this first-order recurrence phi recipe.
2307 VPCostContext &Ctx) const override;
2308
2309#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2310 /// Print the recipe.
2311 void print(raw_ostream &O, const Twine &Indent,
2312 VPSlotTracker &SlotTracker) const override;
2313#endif
2314
2315 /// Returns true if the recipe only uses the first lane of operand \p Op.
2316 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2318 "Op must be an operand of the recipe");
2319 return Op == getStartValue();
2320 }
2321};
2322
2323/// A recipe for handling reduction phis. The start value is the first operand
2324/// of the recipe and the incoming value from the backedge is the second
2325/// operand.
2327 public VPUnrollPartAccessor<2> {
2328 /// The recurrence kind of the reduction.
2329 const RecurKind Kind;
2330
2331 /// The phi is part of an in-loop reduction.
2332 bool IsInLoop;
2333
2334 /// The phi is part of an ordered reduction. Requires IsInLoop to be true.
2335 bool IsOrdered;
2336
2337 /// When expanding the reduction PHI, the plan's VF element count is divided
2338 /// by this factor to form the reduction phi's VF.
2339 unsigned VFScaleFactor = 1;
2340
2341public:
2342 /// Create a new VPReductionPHIRecipe for the reduction \p Phi.
2344 bool IsInLoop = false, bool IsOrdered = false,
2345 unsigned VFScaleFactor = 1)
2346 : VPHeaderPHIRecipe(VPDef::VPReductionPHISC, Phi, &Start), Kind(Kind),
2347 IsInLoop(IsInLoop), IsOrdered(IsOrdered), VFScaleFactor(VFScaleFactor) {
2348 assert((!IsOrdered || IsInLoop) && "IsOrdered requires IsInLoop");
2349 }
2350
2351 ~VPReductionPHIRecipe() override = default;
2352
2354 auto *R = new VPReductionPHIRecipe(
2356 *getOperand(0), IsInLoop, IsOrdered, VFScaleFactor);
2357 R->addOperand(getBackedgeValue());
2358 return R;
2359 }
2360
2361 VP_CLASSOF_IMPL(VPDef::VPReductionPHISC)
2362
2363 /// Generate the phi/select nodes.
2364 void execute(VPTransformState &State) override;
2365
2366 /// Get the factor that the VF of this recipe's output should be scaled by.
2367 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2368
2369#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2370 /// Print the recipe.
2371 void print(raw_ostream &O, const Twine &Indent,
2372 VPSlotTracker &SlotTracker) const override;
2373#endif
2374
2375 /// Returns the number of incoming values, also number of incoming blocks.
2376 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2377 /// incoming value, its start value.
2378 unsigned getNumIncoming() const override { return 2; }
2379
2380 /// Returns the recurrence kind of the reduction.
2381 RecurKind getRecurrenceKind() const { return Kind; }
2382
2383 /// Returns true, if the phi is part of an ordered reduction.
2384 bool isOrdered() const { return IsOrdered; }
2385
2386 /// Returns true, if the phi is part of an in-loop reduction.
2387 bool isInLoop() const { return IsInLoop; }
2388
2389 /// Returns true if the recipe only uses the first lane of operand \p Op.
2390 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2392 "Op must be an operand of the recipe");
2393 return isOrdered() || isInLoop();
2394 }
2395};
2396
2397/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2398/// instructions.
2400public:
2401 /// The blend operation is a User of the incoming values and of their
2402 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2403 /// be omitted (implied by passing an odd number of operands) in which case
2404 /// all other incoming values are merged into it.
2406 : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, DL) {
2407 assert(Operands.size() > 0 && "Expected at least one operand!");
2408 }
2409
2414
2415 VP_CLASSOF_IMPL(VPDef::VPBlendSC)
2416
2417 /// A normalized blend is one that has an odd number of operands, whereby the
2418 /// first operand does not have an associated mask.
2419 bool isNormalized() const { return getNumOperands() % 2; }
2420
2421 /// Return the number of incoming values, taking into account when normalized
2422 /// the first incoming value will have no mask.
2423 unsigned getNumIncomingValues() const {
2424 return (getNumOperands() + isNormalized()) / 2;
2425 }
2426
2427 /// Return incoming value number \p Idx.
2428 VPValue *getIncomingValue(unsigned Idx) const {
2429 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2430 }
2431
2432 /// Return mask number \p Idx.
2433 VPValue *getMask(unsigned Idx) const {
2434 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2435 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2436 }
2437
2438 /// Set mask number \p Idx to \p V.
2439 void setMask(unsigned Idx, VPValue *V) {
2440 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2441 Idx == 0 ? setOperand(1, V) : setOperand(Idx * 2 + !isNormalized(), V);
2442 }
2443
2444 void execute(VPTransformState &State) override {
2445 llvm_unreachable("VPBlendRecipe should be expanded by simplifyBlends");
2446 }
2447
2448 /// Return the cost of this VPWidenMemoryRecipe.
2449 InstructionCost computeCost(ElementCount VF,
2450 VPCostContext &Ctx) const override;
2451
2452#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2453 /// Print the recipe.
2454 void print(raw_ostream &O, const Twine &Indent,
2455 VPSlotTracker &SlotTracker) const override;
2456#endif
2457
2458 /// Returns true if the recipe only uses the first lane of operand \p Op.
2459 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2461 "Op must be an operand of the recipe");
2462 // Recursing through Blend recipes only, must terminate at header phi's the
2463 // latest.
2464 return all_of(users(),
2465 [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
2466 }
2467};
2468
2469/// A common base class for interleaved memory operations.
2470/// An Interleaved memory operation is a memory access method that combines
2471/// multiple strided loads/stores into a single wide load/store with shuffles.
2472/// The first operand is the start address. The optional operands are, in order,
2473/// the stored values and the mask.
2475 public VPIRMetadata {
2477
2478 /// Indicates if the interleave group is in a conditional block and requires a
2479 /// mask.
2480 bool HasMask = false;
2481
2482 /// Indicates if gaps between members of the group need to be masked out or if
2483 /// unusued gaps can be loaded speculatively.
2484 bool NeedsMaskForGaps = false;
2485
2486protected:
2487 VPInterleaveBase(const unsigned char SC,
2489 ArrayRef<VPValue *> Operands,
2490 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2491 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2492 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(MD), IG(IG),
2493 NeedsMaskForGaps(NeedsMaskForGaps) {
2494 // TODO: extend the masked interleaved-group support to reversed access.
2495 assert((!Mask || !IG->isReverse()) &&
2496 "Reversed masked interleave-group not supported.");
2497 for (unsigned I = 0; I < IG->getFactor(); ++I)
2498 if (Instruction *Inst = IG->getMember(I)) {
2499 if (Inst->getType()->isVoidTy())
2500 continue;
2501 new VPValue(Inst, this);
2502 }
2503
2504 for (auto *SV : StoredValues)
2505 addOperand(SV);
2506 if (Mask) {
2507 HasMask = true;
2508 addOperand(Mask);
2509 }
2510 }
2511
2512public:
2513 VPInterleaveBase *clone() override = 0;
2514
2515 static inline bool classof(const VPRecipeBase *R) {
2516 return R->getVPDefID() == VPRecipeBase::VPInterleaveSC ||
2517 R->getVPDefID() == VPRecipeBase::VPInterleaveEVLSC;
2518 }
2519
2520 static inline bool classof(const VPUser *U) {
2521 auto *R = dyn_cast<VPRecipeBase>(U);
2522 return R && classof(R);
2523 }
2524
2525 /// Return the address accessed by this recipe.
2526 VPValue *getAddr() const {
2527 return getOperand(0); // Address is the 1st, mandatory operand.
2528 }
2529
2530 /// Return the mask used by this recipe. Note that a full mask is represented
2531 /// by a nullptr.
2532 VPValue *getMask() const {
2533 // Mask is optional and the last operand.
2534 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2535 }
2536
2537 /// Return true if the access needs a mask because of the gaps.
2538 bool needsMaskForGaps() const { return NeedsMaskForGaps; }
2539
2541
2542 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2543
2544 void execute(VPTransformState &State) override {
2545 llvm_unreachable("VPInterleaveBase should not be instantiated.");
2546 }
2547
2548 /// Return the cost of this recipe.
2549 InstructionCost computeCost(ElementCount VF,
2550 VPCostContext &Ctx) const override;
2551
2552 /// Returns true if the recipe only uses the first lane of operand \p Op.
2553 virtual bool onlyFirstLaneUsed(const VPValue *Op) const override = 0;
2554
2555 /// Returns the number of stored operands of this interleave group. Returns 0
2556 /// for load interleave groups.
2557 virtual unsigned getNumStoreOperands() const = 0;
2558
2559 /// Return the VPValues stored by this interleave group. If it is a load
2560 /// interleave group, return an empty ArrayRef.
2562 return ArrayRef<VPValue *>(op_end() -
2563 (getNumStoreOperands() + (HasMask ? 1 : 0)),
2565 }
2566};
2567
2568/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2569/// or stores into one wide load/store and shuffles. The first operand of a
2570/// VPInterleave recipe is the address, followed by the stored values, followed
2571/// by an optional mask.
2573public:
2575 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2576 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2577 : VPInterleaveBase(VPDef::VPInterleaveSC, IG, Addr, StoredValues, Mask,
2578 NeedsMaskForGaps, MD, DL) {}
2579
2580 ~VPInterleaveRecipe() override = default;
2581
2585 needsMaskForGaps(), *this, getDebugLoc());
2586 }
2587
2588 VP_CLASSOF_IMPL(VPDef::VPInterleaveSC)
2589
2590 /// Generate the wide load or store, and shuffles.
2591 void execute(VPTransformState &State) override;
2592
2593#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2594 /// Print the recipe.
2595 void print(raw_ostream &O, const Twine &Indent,
2596 VPSlotTracker &SlotTracker) const override;
2597#endif
2598
2599 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2601 "Op must be an operand of the recipe");
2602 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2603 }
2604
2605 unsigned getNumStoreOperands() const override {
2606 return getNumOperands() - (getMask() ? 2 : 1);
2607 }
2608};
2609
2610/// A recipe for interleaved memory operations with vector-predication
2611/// intrinsics. The first operand is the address, the second operand is the
2612/// explicit vector length. Stored values and mask are optional operands.
2614public:
2616 : VPInterleaveBase(VPDef::VPInterleaveEVLSC, R.getInterleaveGroup(),
2617 ArrayRef<VPValue *>({R.getAddr(), &EVL}),
2618 R.getStoredValues(), Mask, R.needsMaskForGaps(), R,
2619 R.getDebugLoc()) {
2620 assert(!getInterleaveGroup()->isReverse() &&
2621 "Reversed interleave-group with tail folding is not supported.");
2622 assert(!needsMaskForGaps() && "Interleaved access with gap mask is not "
2623 "supported for scalable vector.");
2624 }
2625
2626 ~VPInterleaveEVLRecipe() override = default;
2627
2629 llvm_unreachable("cloning not implemented yet");
2630 }
2631
2632 VP_CLASSOF_IMPL(VPDef::VPInterleaveEVLSC)
2633
2634 /// The VPValue of the explicit vector length.
2635 VPValue *getEVL() const { return getOperand(1); }
2636
2637 /// Generate the wide load or store, and shuffles.
2638 void execute(VPTransformState &State) override;
2639
2640#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2641 /// Print the recipe.
2642 void print(raw_ostream &O, const Twine &Indent,
2643 VPSlotTracker &SlotTracker) const override;
2644#endif
2645
2646 /// The recipe only uses the first lane of the address, and EVL operand.
2647 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2649 "Op must be an operand of the recipe");
2650 return (Op == getAddr() && !llvm::is_contained(getStoredValues(), Op)) ||
2651 Op == getEVL();
2652 }
2653
2654 unsigned getNumStoreOperands() const override {
2655 return getNumOperands() - (getMask() ? 3 : 2);
2656 }
2657};
2658
2659/// A recipe to represent inloop reduction operations, performing a reduction on
2660/// a vector operand into a scalar value, and adding the result to a chain.
2661/// The Operands are {ChainOp, VecOp, [Condition]}.
2663 /// The recurrence kind for the reduction in question.
2664 RecurKind RdxKind;
2665 bool IsOrdered;
2666 /// Whether the reduction is conditional.
2667 bool IsConditional = false;
2668
2669protected:
2670 VPReductionRecipe(const unsigned char SC, RecurKind RdxKind,
2673 bool IsOrdered, DebugLoc DL)
2674 : VPRecipeWithIRFlags(SC, Operands, FMFs, DL), RdxKind(RdxKind),
2675 IsOrdered(IsOrdered) {
2676 if (CondOp) {
2677 IsConditional = true;
2678 addOperand(CondOp);
2679 }
2681 }
2682
2683public:
2685 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2686 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2687 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, I,
2688 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2689 IsOrdered, DL) {}
2690
2692 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2693 bool IsOrdered, DebugLoc DL = DebugLoc::getUnknown())
2694 : VPReductionRecipe(VPDef::VPReductionSC, RdxKind, FMFs, nullptr,
2695 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2696 IsOrdered, DL) {}
2697
2698 ~VPReductionRecipe() override = default;
2699
2701 return new VPReductionRecipe(RdxKind, getFastMathFlags(),
2703 getCondOp(), IsOrdered, getDebugLoc());
2704 }
2705
2706 static inline bool classof(const VPRecipeBase *R) {
2707 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2708 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC;
2709 }
2710
2711 static inline bool classof(const VPUser *U) {
2712 auto *R = dyn_cast<VPRecipeBase>(U);
2713 return R && classof(R);
2714 }
2715
2716 /// Generate the reduction in the loop.
2717 void execute(VPTransformState &State) override;
2718
2719 /// Return the cost of VPReductionRecipe.
2720 InstructionCost computeCost(ElementCount VF,
2721 VPCostContext &Ctx) const override;
2722
2723#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2724 /// Print the recipe.
2725 void print(raw_ostream &O, const Twine &Indent,
2726 VPSlotTracker &SlotTracker) const override;
2727#endif
2728
2729 /// Return the recurrence kind for the in-loop reduction.
2730 RecurKind getRecurrenceKind() const { return RdxKind; }
2731 /// Return true if the in-loop reduction is ordered.
2732 bool isOrdered() const { return IsOrdered; };
2733 /// Return true if the in-loop reduction is conditional.
2734 bool isConditional() const { return IsConditional; };
2735 /// The VPValue of the scalar Chain being accumulated.
2736 VPValue *getChainOp() const { return getOperand(0); }
2737 /// The VPValue of the vector value to be reduced.
2738 VPValue *getVecOp() const { return getOperand(1); }
2739 /// The VPValue of the condition for the block.
2741 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2742 }
2743};
2744
2745/// A recipe for forming partial reductions. In the loop, an accumulator and
2746/// vector operand are added together and passed to the next iteration as the
2747/// next accumulator. After the loop body, the accumulator is reduced to a
2748/// scalar value.
2750 unsigned Opcode;
2751
2752 /// The divisor by which the VF of this recipe's output should be divided
2753 /// during execution.
2754 unsigned VFScaleFactor;
2755
2756public:
2758 VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
2759 : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1, Cond,
2760 VFScaleFactor, ReductionInst) {}
2761 VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
2762 VPValue *Cond, unsigned ScaleFactor,
2763 Instruction *ReductionInst = nullptr)
2764 : VPReductionRecipe(VPDef::VPPartialReductionSC, RecurKind::Add,
2765 FastMathFlags(), ReductionInst,
2766 ArrayRef<VPValue *>({Op0, Op1}), Cond, false, {}),
2767 Opcode(Opcode), VFScaleFactor(ScaleFactor) {
2768 [[maybe_unused]] auto *AccumulatorRecipe =
2770 assert((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2771 isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2772 "Unexpected operand order for partial reduction recipe");
2773 }
2774 ~VPPartialReductionRecipe() override = default;
2775
2777 return new VPPartialReductionRecipe(Opcode, getOperand(0), getOperand(1),
2778 getCondOp(), VFScaleFactor,
2780 }
2781
2782 VP_CLASSOF_IMPL(VPDef::VPPartialReductionSC)
2783
2784 /// Generate the reduction in the loop.
2785 void execute(VPTransformState &State) override;
2786
2787 /// Return the cost of this VPPartialReductionRecipe.
2789 VPCostContext &Ctx) const override;
2790
2791 /// Get the binary op's opcode.
2792 unsigned getOpcode() const { return Opcode; }
2793
2794 /// Get the factor that the VF of this recipe's output should be scaled by.
2795 unsigned getVFScaleFactor() const { return VFScaleFactor; }
2796
2797#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2798 /// Print the recipe.
2799 void print(raw_ostream &O, const Twine &Indent,
2800 VPSlotTracker &SlotTracker) const override;
2801#endif
2802};
2803
2804/// A recipe to represent inloop reduction operations with vector-predication
2805/// intrinsics, performing a reduction on a vector operand with the explicit
2806/// vector length (EVL) into a scalar value, and adding the result to a chain.
2807/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2809public:
2813 VPDef::VPReductionEVLSC, R.getRecurrenceKind(),
2814 R.getFastMathFlags(),
2816 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2817 R.isOrdered(), DL) {}
2818
2819 ~VPReductionEVLRecipe() override = default;
2820
2822 llvm_unreachable("cloning not implemented yet");
2823 }
2824
2825 VP_CLASSOF_IMPL(VPDef::VPReductionEVLSC)
2826
2827 /// Generate the reduction in the loop
2828 void execute(VPTransformState &State) override;
2829
2830#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2831 /// Print the recipe.
2832 void print(raw_ostream &O, const Twine &Indent,
2833 VPSlotTracker &SlotTracker) const override;
2834#endif
2835
2836 /// The VPValue of the explicit vector length.
2837 VPValue *getEVL() const { return getOperand(2); }
2838
2839 /// Returns true if the recipe only uses the first lane of operand \p Op.
2840 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2842 "Op must be an operand of the recipe");
2843 return Op == getEVL();
2844 }
2845};
2846
2847/// VPReplicateRecipe replicates a given instruction producing multiple scalar
2848/// copies of the original scalar type, one per lane, instead of producing a
2849/// single copy of widened type for all lanes. If the instruction is known to be
2850/// a single scalar, only one copy, per lane zero, will be generated.
2852 public VPIRMetadata {
2853 /// Indicator if only a single replica per lane is needed.
2854 bool IsSingleScalar;
2855
2856 /// Indicator if the replicas are also predicated.
2857 bool IsPredicated;
2858
2859public:
2861 bool IsSingleScalar, VPValue *Mask = nullptr,
2862 VPIRMetadata Metadata = {})
2863 : VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
2864 VPIRMetadata(Metadata), IsSingleScalar(IsSingleScalar),
2865 IsPredicated(Mask) {
2866 if (Mask)
2867 addOperand(Mask);
2868 }
2869
2870 ~VPReplicateRecipe() override = default;
2871
2873 auto *Copy =
2874 new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsSingleScalar,
2875 isPredicated() ? getMask() : nullptr, *this);
2876 Copy->transferFlags(*this);
2877 return Copy;
2878 }
2879
2880 VP_CLASSOF_IMPL(VPDef::VPReplicateSC)
2881
2882 /// Generate replicas of the desired Ingredient. Replicas will be generated
2883 /// for all parts and lanes unless a specific part and lane are specified in
2884 /// the \p State.
2885 void execute(VPTransformState &State) override;
2886
2887 /// Return the cost of this VPReplicateRecipe.
2888 InstructionCost computeCost(ElementCount VF,
2889 VPCostContext &Ctx) const override;
2890
2891#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2892 /// Print the recipe.
2893 void print(raw_ostream &O, const Twine &Indent,
2894 VPSlotTracker &SlotTracker) const override;
2895#endif
2896
2897 bool isSingleScalar() const { return IsSingleScalar; }
2898
2899 bool isPredicated() const { return IsPredicated; }
2900
2901 /// Returns true if the recipe only uses the first lane of operand \p Op.
2902 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2904 "Op must be an operand of the recipe");
2905 return isSingleScalar();
2906 }
2907
2908 /// Returns true if the recipe uses scalars of operand \p Op.
2909 bool usesScalars(const VPValue *Op) const override {
2911 "Op must be an operand of the recipe");
2912 return true;
2913 }
2914
2915 /// Returns true if the recipe is used by a widened recipe via an intervening
2916 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
2917 /// in a vector.
2918 bool shouldPack() const;
2919
2920 /// Return the mask of a predicated VPReplicateRecipe.
2922 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
2923 return getOperand(getNumOperands() - 1);
2924 }
2925
2926 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
2927};
2928
2929/// A recipe for generating conditional branches on the bits of a mask.
2931public:
2933 : VPRecipeBase(VPDef::VPBranchOnMaskSC, {BlockInMask}, DL) {}
2934
2937 }
2938
2939 VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)
2940
2941 /// Generate the extraction of the appropriate bit from the block mask and the
2942 /// conditional branch.
2943 void execute(VPTransformState &State) override;
2944
2945 /// Return the cost of this VPBranchOnMaskRecipe.
2946 InstructionCost computeCost(ElementCount VF,
2947 VPCostContext &Ctx) const override;
2948
2949#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2950 /// Print the recipe.
2951 void print(raw_ostream &O, const Twine &Indent,
2952 VPSlotTracker &SlotTracker) const override {
2953 O << Indent << "BRANCH-ON-MASK ";
2955 }
2956#endif
2957
2958 /// Returns true if the recipe uses scalars of operand \p Op.
2959 bool usesScalars(const VPValue *Op) const override {
2961 "Op must be an operand of the recipe");
2962 return true;
2963 }
2964};
2965
2966/// A recipe to combine multiple recipes into a single 'expression' recipe,
2967/// which should be considered a single entity for cost-modeling and transforms.
2968/// The recipe needs to be 'decomposed', i.e. replaced by its individual
2969/// expression recipes, before execute. The individual expression recipes are
2970/// completely disconnected from the def-use graph of other recipes not part of
2971/// the expression. Def-use edges between pairs of expression recipes remain
2972/// intact, whereas every edge between an expression recipe and a recipe outside
2973/// the expression is elevated to connect the non-expression recipe with the
2974/// VPExpressionRecipe itself.
2975class VPExpressionRecipe : public VPSingleDefRecipe {
2976 /// Recipes included in this VPExpressionRecipe.
2977 SmallVector<VPSingleDefRecipe *> ExpressionRecipes;
2978
2979 /// Temporary VPValues used for external operands of the expression, i.e.
2980 /// operands not defined by recipes in the expression.
2981 SmallVector<VPValue *> LiveInPlaceholders;
2982
2983 enum class ExpressionTypes {
2984 /// Represents an inloop extended reduction operation, performing a
2985 /// reduction on an extended vector operand into a scalar value, and adding
2986 /// the result to a chain.
2987 ExtendedReduction,
2988 /// Represent an inloop multiply-accumulate reduction, multiplying the
2989 /// extended vector operands, performing a reduction.add on the result, and
2990 /// adding the scalar result to a chain.
2991 ExtMulAccReduction,
2992 /// Represent an inloop multiply-accumulate reduction, multiplying the
2993 /// vector operands, performing a reduction.add on the result, and adding
2994 /// the scalar result to a chain.
2995 MulAccReduction,
2996 };
2997
2998 /// Type of the expression.
2999 ExpressionTypes ExpressionType;
3000
3001 /// Construct a new VPExpressionRecipe by internalizing recipes in \p
3002 /// ExpressionRecipes. External operands (i.e. not defined by another recipe
3003 /// in the expression) are replaced by temporary VPValues and the original
3004 /// operands are transferred to the VPExpressionRecipe itself. Clone recipes
3005 /// as needed (excluding last) to ensure they are only used by other recipes
3006 /// in the expression.
3007 VPExpressionRecipe(ExpressionTypes ExpressionType,
3008 ArrayRef<VPSingleDefRecipe *> ExpressionRecipes);
3009
3010public:
3012 : VPExpressionRecipe(ExpressionTypes::ExtendedReduction, {Ext, Red}) {}
3014 : VPExpressionRecipe(ExpressionTypes::MulAccReduction, {Mul, Red}) {}
3017 : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction,
3018 {Ext0, Ext1, Mul, Red}) {}
3019
3021 for (auto *R : reverse(ExpressionRecipes))
3022 delete R;
3023 for (VPValue *T : LiveInPlaceholders)
3024 delete T;
3025 }
3026
3027 VP_CLASSOF_IMPL(VPDef::VPExpressionSC)
3028
3029 VPExpressionRecipe *clone() override {
3030 assert(!ExpressionRecipes.empty() && "empty expressions should be removed");
3031 SmallVector<VPSingleDefRecipe *> NewExpressiondRecipes;
3032 for (auto *R : ExpressionRecipes)
3033 NewExpressiondRecipes.push_back(R->clone());
3034 for (auto *New : NewExpressiondRecipes) {
3035 for (const auto &[Idx, Old] : enumerate(ExpressionRecipes))
3036 New->replaceUsesOfWith(Old, NewExpressiondRecipes[Idx]);
3037 // Update placeholder operands in the cloned recipe to use the external
3038 // operands, to be internalized when the cloned expression is constructed.
3039 for (const auto &[Placeholder, OutsideOp] :
3040 zip(LiveInPlaceholders, operands()))
3041 New->replaceUsesOfWith(Placeholder, OutsideOp);
3042 }
3043 return new VPExpressionRecipe(ExpressionType, NewExpressiondRecipes);
3044 }
3045
3046 /// Return the VPValue to use to infer the result type of the recipe.
3048 unsigned OpIdx =
3049 cast<VPReductionRecipe>(ExpressionRecipes.back())->isConditional() ? 2
3050 : 1;
3051 return getOperand(getNumOperands() - OpIdx);
3052 }
3053
3054 /// Insert the recipes of the expression back into the VPlan, directly before
3055 /// the current recipe. Leaves the expression recipe empty, which must be
3056 /// removed before codegen.
3057 void decompose();
3058
3059 /// Method for generating code, must not be called as this recipe is abstract.
3060 void execute(VPTransformState &State) override {
3061 llvm_unreachable("recipe must be removed before execute");
3062 }
3063
3065 VPCostContext &Ctx) const override;
3066
3067#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3068 /// Print the recipe.
3069 void print(raw_ostream &O, const Twine &Indent,
3070 VPSlotTracker &SlotTracker) const override;
3071#endif
3072
3073 /// Returns true if this expression contains recipes that may read from or
3074 /// write to memory.
3075 bool mayReadOrWriteMemory() const;
3076
3077 /// Returns true if this expression contains recipes that may have side
3078 /// effects.
3079 bool mayHaveSideEffects() const;
3080};
3081
3082/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
3083/// control converges back from a Branch-on-Mask. The phi nodes are needed in
3084/// order to merge values that are set under such a branch and feed their uses.
3085/// The phi nodes can be scalar or vector depending on the users of the value.
3086/// This recipe works in concert with VPBranchOnMaskRecipe.
3088public:
3089 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
3090 /// nodes after merging back from a Branch-on-Mask.
3092 : VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
3093 ~VPPredInstPHIRecipe() override = default;
3094
3096 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
3097 }
3098
3099 VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)
3100
3101 /// Generates phi nodes for live-outs (from a replicate region) as needed to
3102 /// retain SSA form.
3103 void execute(VPTransformState &State) override;
3104
3105 /// Return the cost of this VPPredInstPHIRecipe.
3107 VPCostContext &Ctx) const override {
3108 // TODO: Compute accurate cost after retiring the legacy cost model.
3109 return 0;
3110 }
3111
3112#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3113 /// Print the recipe.
3114 void print(raw_ostream &O, const Twine &Indent,
3115 VPSlotTracker &SlotTracker) const override;
3116#endif
3117
3118 /// Returns true if the recipe uses scalars of operand \p Op.
3119 bool usesScalars(const VPValue *Op) const override {
3121 "Op must be an operand of the recipe");
3122 return true;
3123 }
3124};
3125
3126/// A common base class for widening memory operations. An optional mask can be
3127/// provided as the last operand.
3129 public VPIRMetadata {
3130protected:
3132
3133 /// Whether the accessed addresses are consecutive.
3135
3136 /// Whether the consecutive accessed addresses are in reverse order.
3138
3139 /// Whether the memory access is masked.
3140 bool IsMasked = false;
3141
3142 void setMask(VPValue *Mask) {
3143 assert(!IsMasked && "cannot re-set mask");
3144 if (!Mask)
3145 return;
3146 addOperand(Mask);
3147 IsMasked = true;
3148 }
3149
3150 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
3151 std::initializer_list<VPValue *> Operands,
3152 bool Consecutive, bool Reverse,
3153 const VPIRMetadata &Metadata, DebugLoc DL)
3154 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
3156 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
3157 }
3158
3159public:
3161 llvm_unreachable("cloning not supported");
3162 }
3163
3164 static inline bool classof(const VPRecipeBase *R) {
3165 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
3166 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
3167 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
3168 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
3169 }
3170
3171 static inline bool classof(const VPUser *U) {
3172 auto *R = dyn_cast<VPRecipeBase>(U);
3173 return R && classof(R);
3174 }
3175
3176 /// Return whether the loaded-from / stored-to addresses are consecutive.
3177 bool isConsecutive() const { return Consecutive; }
3178
3179 /// Return whether the consecutive loaded/stored addresses are in reverse
3180 /// order.
3181 bool isReverse() const { return Reverse; }
3182
3183 /// Return the address accessed by this recipe.
3184 VPValue *getAddr() const { return getOperand(0); }
3185
3186 /// Returns true if the recipe is masked.
3187 bool isMasked() const { return IsMasked; }
3188
3189 /// Return the mask used by this recipe. Note that a full mask is represented
3190 /// by a nullptr.
3191 VPValue *getMask() const {
3192 // Mask is optional and therefore the last operand.
3193 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
3194 }
3195
3196 /// Generate the wide load/store.
3197 void execute(VPTransformState &State) override {
3198 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
3199 }
3200
3201 /// Return the cost of this VPWidenMemoryRecipe.
3202 InstructionCost computeCost(ElementCount VF,
3203 VPCostContext &Ctx) const override;
3204
3206};
3207
3208/// A recipe for widening load operations, using the address to load from and an
3209/// optional mask.
3211 public VPValue {
3213 bool Consecutive, bool Reverse,
3214 const VPIRMetadata &Metadata, DebugLoc DL)
3215 : VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
3216 Reverse, Metadata, DL),
3217 VPValue(this, &Load) {
3218 setMask(Mask);
3219 }
3220
3223 getMask(), Consecutive, Reverse, *this,
3224 getDebugLoc());
3225 }
3226
3227 VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC);
3228
3229 /// Generate a wide load or gather.
3230 void execute(VPTransformState &State) override;
3231
3232#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3233 /// Print the recipe.
3234 void print(raw_ostream &O, const Twine &Indent,
3235 VPSlotTracker &SlotTracker) const override;
3236#endif
3237
3238 /// Returns true if the recipe only uses the first lane of operand \p Op.
3239 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3241 "Op must be an operand of the recipe");
3242 // Widened, consecutive loads operations only demand the first lane of
3243 // their address.
3244 return Op == getAddr() && isConsecutive();
3245 }
3246};
3247
3248/// A recipe for widening load operations with vector-predication intrinsics,
3249/// using the address to load from, the explicit vector length and an optional
3250/// mask.
3251struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
3253 VPValue *Mask)
3254 : VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
3255 {Addr, &EVL}, L.isConsecutive(), L.isReverse(), L,
3256 L.getDebugLoc()),
3257 VPValue(this, &getIngredient()) {
3258 setMask(Mask);
3259 }
3260
3261 VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
3262
3263 /// Return the EVL operand.
3264 VPValue *getEVL() const { return getOperand(1); }
3265
3266 /// Generate the wide load or gather.
3267 void execute(VPTransformState &State) override;
3268
3269 /// Return the cost of this VPWidenLoadEVLRecipe.
3271 VPCostContext &Ctx) const override;
3272
3273#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3274 /// Print the recipe.
3275 void print(raw_ostream &O, const Twine &Indent,
3276 VPSlotTracker &SlotTracker) const override;
3277#endif
3278
3279 /// Returns true if the recipe only uses the first lane of operand \p Op.
3280 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3282 "Op must be an operand of the recipe");
3283 // Widened loads only demand the first lane of EVL and consecutive loads
3284 // only demand the first lane of their address.
3285 return Op == getEVL() || (Op == getAddr() && isConsecutive());
3286 }
3287};
3288
3289/// A recipe for widening store operations, using the stored value, the address
3290/// to store to and an optional mask.
3292 VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
3293 VPValue *Mask, bool Consecutive, bool Reverse,
3294 const VPIRMetadata &Metadata, DebugLoc DL)
3295 : VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
3296 Consecutive, Reverse, Metadata, DL) {
3297 setMask(Mask);
3298 }
3299
3305
3306 VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
3307
3308 /// Return the value stored by this recipe.
3309 VPValue *getStoredValue() const { return getOperand(1); }
3310
3311 /// Generate a wide store or scatter.
3312 void execute(VPTransformState &State) override;
3313
3314#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3315 /// Print the recipe.
3316 void print(raw_ostream &O, const Twine &Indent,
3317 VPSlotTracker &SlotTracker) const override;
3318#endif
3319
3320 /// Returns true if the recipe only uses the first lane of operand \p Op.
3321 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3323 "Op must be an operand of the recipe");
3324 // Widened, consecutive stores only demand the first lane of their address,
3325 // unless the same operand is also stored.
3326 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3327 }
3328};
3329
3330/// A recipe for widening store operations with vector-predication intrinsics,
3331/// using the value to store, the address to store to, the explicit vector
3332/// length and an optional mask.
3335 VPValue *Mask)
3336 : VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
3337 {Addr, S.getStoredValue(), &EVL}, S.isConsecutive(),
3338 S.isReverse(), S, S.getDebugLoc()) {
3339 setMask(Mask);
3340 }
3341
3342 VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
3343
3344 /// Return the address accessed by this recipe.
3345 VPValue *getStoredValue() const { return getOperand(1); }
3346
3347 /// Return the EVL operand.
3348 VPValue *getEVL() const { return getOperand(2); }
3349
3350 /// Generate the wide store or scatter.
3351 void execute(VPTransformState &State) override;
3352
3353 /// Return the cost of this VPWidenStoreEVLRecipe.
3355 VPCostContext &Ctx) const override;
3356
3357#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3358 /// Print the recipe.
3359 void print(raw_ostream &O, const Twine &Indent,
3360 VPSlotTracker &SlotTracker) const override;
3361#endif
3362
3363 /// Returns true if the recipe only uses the first lane of operand \p Op.
3364 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3366 "Op must be an operand of the recipe");
3367 if (Op == getEVL()) {
3368 assert(getStoredValue() != Op && "unexpected store of EVL");
3369 return true;
3370 }
3371 // Widened, consecutive memory operations only demand the first lane of
3372 // their address, unless the same operand is also stored. That latter can
3373 // happen with opaque pointers.
3374 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3375 }
3376};
3377
3378/// Recipe to expand a SCEV expression.
3380 const SCEV *Expr;
3381
3382public:
3384 : VPSingleDefRecipe(VPDef::VPExpandSCEVSC, {}), Expr(Expr) {}
3385
3386 ~VPExpandSCEVRecipe() override = default;
3387
3388 VPExpandSCEVRecipe *clone() override { return new VPExpandSCEVRecipe(Expr); }
3389
3390 VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)
3391
3392 void execute(VPTransformState &State) override {
3393 llvm_unreachable("SCEV expressions must be expanded before final execute");
3394 }
3395
3396 /// Return the cost of this VPExpandSCEVRecipe.
3398 VPCostContext &Ctx) const override {
3399 // TODO: Compute accurate cost after retiring the legacy cost model.
3400 return 0;
3401 }
3402
3403#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3404 /// Print the recipe.
3405 void print(raw_ostream &O, const Twine &Indent,
3406 VPSlotTracker &SlotTracker) const override;
3407#endif
3408
3409 const SCEV *getSCEV() const { return Expr; }
3410};
3411
3412/// Canonical scalar induction phi of the vector loop. Starting at the specified
3413/// start value (either 0 or the resume value when vectorizing the epilogue
3414/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
3415/// canonical induction variable.
3417public:
3419 : VPHeaderPHIRecipe(VPDef::VPCanonicalIVPHISC, nullptr, StartV, DL) {}
3420
3421 ~VPCanonicalIVPHIRecipe() override = default;
3422
3424 auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
3425 R->addOperand(getBackedgeValue());
3426 return R;
3427 }
3428
3429 VP_CLASSOF_IMPL(VPDef::VPCanonicalIVPHISC)
3430
3431 void execute(VPTransformState &State) override {
3432 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3433 "scalar phi recipe");
3434 }
3435
3436#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3437 /// Print the recipe.
3438 void print(raw_ostream &O, const Twine &Indent,
3439 VPSlotTracker &SlotTracker) const override;
3440#endif
3441
3442 /// Returns the scalar type of the induction.
3444 return getStartValue()->getLiveInIRValue()->getType();
3445 }
3446
3447 /// Returns true if the recipe only uses the first lane of operand \p Op.
3448 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3450 "Op must be an operand of the recipe");
3451 return true;
3452 }
3453
3454 /// Returns true if the recipe only uses the first part of operand \p Op.
3455 bool onlyFirstPartUsed(const VPValue *Op) const override {
3457 "Op must be an operand of the recipe");
3458 return true;
3459 }
3460
3461 /// Return the cost of this VPCanonicalIVPHIRecipe.
3463 VPCostContext &Ctx) const override {
3464 // For now, match the behavior of the legacy cost model.
3465 return 0;
3466 }
3467};
3468
3469/// A recipe for generating the active lane mask for the vector loop that is
3470/// used to predicate the vector operations.
3471/// TODO: It would be good to use the existing VPWidenPHIRecipe instead and
3472/// remove VPActiveLaneMaskPHIRecipe.
3474public:
3476 : VPHeaderPHIRecipe(VPDef::VPActiveLaneMaskPHISC, nullptr, StartMask,
3477 DL) {}
3478
3479 ~VPActiveLaneMaskPHIRecipe() override = default;
3480
3483 if (getNumOperands() == 2)
3484 R->addOperand(getOperand(1));
3485 return R;
3486 }
3487
3488 VP_CLASSOF_IMPL(VPDef::VPActiveLaneMaskPHISC)
3489
3490 /// Generate the active lane mask phi of the vector loop.
3491 void execute(VPTransformState &State) override;
3492
3493#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3494 /// Print the recipe.
3495 void print(raw_ostream &O, const Twine &Indent,
3496 VPSlotTracker &SlotTracker) const override;
3497#endif
3498};
3499
3500/// A recipe for generating the phi node for the current index of elements,
3501/// adjusted in accordance with EVL value. It starts at the start value of the
3502/// canonical induction and gets incremented by EVL in each iteration of the
3503/// vector loop.
3505public:
3507 : VPHeaderPHIRecipe(VPDef::VPEVLBasedIVPHISC, nullptr, StartIV, DL) {}
3508
3509 ~VPEVLBasedIVPHIRecipe() override = default;
3510
3512 llvm_unreachable("cloning not implemented yet");
3513 }
3514
3515 VP_CLASSOF_IMPL(VPDef::VPEVLBasedIVPHISC)
3516
3517 void execute(VPTransformState &State) override {
3518 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3519 "scalar phi recipe");
3520 }
3521
3522 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3524 VPCostContext &Ctx) const override {
3525 // For now, match the behavior of the legacy cost model.
3526 return 0;
3527 }
3528
3529 /// Returns true if the recipe only uses the first lane of operand \p Op.
3530 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3532 "Op must be an operand of the recipe");
3533 return true;
3534 }
3535
3536#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3537 /// Print the recipe.
3538 void print(raw_ostream &O, const Twine &Indent,
3539 VPSlotTracker &SlotTracker) const override;
3540#endif
3541};
3542
3543/// A Recipe for widening the canonical induction variable of the vector loop.
3545 public VPUnrollPartAccessor<1> {
3546public:
3548 : VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3549
3550 ~VPWidenCanonicalIVRecipe() override = default;
3551
3556
3557 VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC)
3558
3559 /// Generate a canonical vector induction variable of the vector loop, with
3560 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3561 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3562 void execute(VPTransformState &State) override;
3563
3564 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3566 VPCostContext &Ctx) const override {
3567 // TODO: Compute accurate cost after retiring the legacy cost model.
3568 return 0;
3569 }
3570
3571#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3572 /// Print the recipe.
3573 void print(raw_ostream &O, const Twine &Indent,
3574 VPSlotTracker &SlotTracker) const override;
3575#endif
3576};
3577
3578/// A recipe for converting the input value \p IV value to the corresponding
3579/// value of an IV with different start and step values, using Start + IV *
3580/// Step.
3582 /// Kind of the induction.
3584 /// If not nullptr, the floating point induction binary operator. Must be set
3585 /// for floating point inductions.
3586 const FPMathOperator *FPBinOp;
3587
3588 /// Name to use for the generated IR instruction for the derived IV.
3589 std::string Name;
3590
3591public:
3593 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3594 const Twine &Name = "")
3596 IndDesc.getKind(),
3597 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3598 Start, CanonicalIV, Step, Name) {}
3599
3601 const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3602 VPValue *Step, const Twine &Name = "")
3603 : VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3604 FPBinOp(FPBinOp), Name(Name.str()) {}
3605
3606 ~VPDerivedIVRecipe() override = default;
3607
3609 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3610 getStepValue());
3611 }
3612
3613 VP_CLASSOF_IMPL(VPDef::VPDerivedIVSC)
3614
3615 /// Generate the transformed value of the induction at offset StartValue (1.
3616 /// operand) + IV (2. operand) * StepValue (3, operand).
3617 void execute(VPTransformState &State) override;
3618
3619 /// Return the cost of this VPDerivedIVRecipe.
3621 VPCostContext &Ctx) const override {
3622 // TODO: Compute accurate cost after retiring the legacy cost model.
3623 return 0;
3624 }
3625
3626#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3627 /// Print the recipe.
3628 void print(raw_ostream &O, const Twine &Indent,
3629 VPSlotTracker &SlotTracker) const override;
3630#endif
3631
3633 return getStartValue()->getLiveInIRValue()->getType();
3634 }
3635
3636 VPValue *getStartValue() const { return getOperand(0); }
3637 VPValue *getStepValue() const { return getOperand(2); }
3638
3639 /// Returns true if the recipe only uses the first lane of operand \p Op.
3640 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3642 "Op must be an operand of the recipe");
3643 return true;
3644 }
3645};
3646
3647/// A recipe for handling phi nodes of integer and floating-point inductions,
3648/// producing their scalar values.
3650 public VPUnrollPartAccessor<3> {
3651 Instruction::BinaryOps InductionOpcode;
3652
3653public:
3656 DebugLoc DL)
3657 : VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
3658 ArrayRef<VPValue *>({IV, Step, VF}), FMFs, DL),
3659 InductionOpcode(Opcode) {}
3660
3662 VPValue *Step, VPValue *VF,
3665 IV, Step, VF, IndDesc.getInductionOpcode(),
3666 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3667 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3668 : FastMathFlags(),
3669 DL) {}
3670
3671 ~VPScalarIVStepsRecipe() override = default;
3672
3674 return new VPScalarIVStepsRecipe(
3675 getOperand(0), getOperand(1), getOperand(2), InductionOpcode,
3677 getDebugLoc());
3678 }
3679
3680 /// Return true if this VPScalarIVStepsRecipe corresponds to part 0. Note that
3681 /// this is only accurate after the VPlan has been unrolled.
3682 bool isPart0() const { return getUnrollPart(*this) == 0; }
3683
3684 VP_CLASSOF_IMPL(VPDef::VPScalarIVStepsSC)
3685
3686 /// Generate the scalarized versions of the phi node as needed by their users.
3687 void execute(VPTransformState &State) override;
3688
3689 /// Return the cost of this VPScalarIVStepsRecipe.
3691 VPCostContext &Ctx) const override {
3692 // TODO: Compute accurate cost after retiring the legacy cost model.
3693 return 0;
3694 }
3695
3696#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3697 /// Print the recipe.
3698 void print(raw_ostream &O, const Twine &Indent,
3699 VPSlotTracker &SlotTracker) const override;
3700#endif
3701
3702 VPValue *getStepValue() const { return getOperand(1); }
3703
3704 /// Returns true if the recipe only uses the first lane of operand \p Op.
3705 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3707 "Op must be an operand of the recipe");
3708 return true;
3709 }
3710};
3711
3712/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
3713/// types implementing VPPhiAccessors. Used by isa<> & co.
3715 static inline bool isPossible(const VPRecipeBase *f) {
3716 // TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
3718 }
3719};
3720/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
3721/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
3722template <typename SrcTy>
3723struct CastInfoVPPhiAccessors : public CastIsPossible<VPPhiAccessors, SrcTy> {
3724
3726
3727 /// doCast is used by cast<>.
3728 static inline VPPhiAccessors *doCast(SrcTy R) {
3729 return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
3730 switch (R->getVPDefID()) {
3731 case VPDef::VPInstructionSC:
3732 return cast<VPPhi>(R);
3733 case VPDef::VPIRInstructionSC:
3734 return cast<VPIRPhi>(R);
3735 case VPDef::VPWidenPHISC:
3736 return cast<VPWidenPHIRecipe>(R);
3737 default:
3738 return cast<VPHeaderPHIRecipe>(R);
3739 }
3740 }());
3741 }
3742
3743 /// doCastIfPossible is used by dyn_cast<>.
3744 static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
3745 if (!Self::isPossible(f))
3746 return nullptr;
3747 return doCast(f);
3748 }
3749};
3750template <>
3753template <>
3756
3757/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
3758/// holds a sequence of zero or more VPRecipe's each representing a sequence of
3759/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
3760class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
3761 friend class VPlan;
3762
3763 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3764 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3765 : VPBlockBase(VPBasicBlockSC, Name.str()) {
3766 if (Recipe)
3767 appendRecipe(Recipe);
3768 }
3769
3770public:
3772
3773protected:
3774 /// The VPRecipes held in the order of output instructions to generate.
3776
3777 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
3778 : VPBlockBase(BlockSC, Name.str()) {}
3779
3780public:
3781 ~VPBasicBlock() override {
3782 while (!Recipes.empty())
3783 Recipes.pop_back();
3784 }
3785
3786 /// Instruction iterators...
3791
3792 //===--------------------------------------------------------------------===//
3793 /// Recipe iterator methods
3794 ///
3795 inline iterator begin() { return Recipes.begin(); }
3796 inline const_iterator begin() const { return Recipes.begin(); }
3797 inline iterator end() { return Recipes.end(); }
3798 inline const_iterator end() const { return Recipes.end(); }
3799
3800 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
3801 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
3802 inline reverse_iterator rend() { return Recipes.rend(); }
3803 inline const_reverse_iterator rend() const { return Recipes.rend(); }
3804
3805 inline size_t size() const { return Recipes.size(); }
3806 inline bool empty() const { return Recipes.empty(); }
3807 inline const VPRecipeBase &front() const { return Recipes.front(); }
3808 inline VPRecipeBase &front() { return Recipes.front(); }
3809 inline const VPRecipeBase &back() const { return Recipes.back(); }
3810 inline VPRecipeBase &back() { return Recipes.back(); }
3811
3812 /// Returns a reference to the list of recipes.
3814
3815 /// Returns a pointer to a member of the recipe list.
3816 static RecipeListTy VPBasicBlock::*getSublistAccess(VPRecipeBase *) {
3817 return &VPBasicBlock::Recipes;
3818 }
3819
3820 /// Method to support type inquiry through isa, cast, and dyn_cast.
3821 static inline bool classof(const VPBlockBase *V) {
3822 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3823 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3824 }
3825
3826 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
3827 assert(Recipe && "No recipe to append.");
3828 assert(!Recipe->Parent && "Recipe already in VPlan");
3829 Recipe->Parent = this;
3830 Recipes.insert(InsertPt, Recipe);
3831 }
3832
3833 /// Augment the existing recipes of a VPBasicBlock with an additional
3834 /// \p Recipe as the last recipe.
3835 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
3836
3837 /// The method which generates the output IR instructions that correspond to
3838 /// this VPBasicBlock, thereby "executing" the VPlan.
3839 void execute(VPTransformState *State) override;
3840
3841 /// Return the cost of this VPBasicBlock.
3842 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
3843
3844 /// Return the position of the first non-phi node recipe in the block.
3845 iterator getFirstNonPhi();
3846
3847 /// Returns an iterator range over the PHI-like recipes in the block.
3851
3852 /// Split current block at \p SplitAt by inserting a new block between the
3853 /// current block and its successors and moving all recipes starting at
3854 /// SplitAt to the new block. Returns the new block.
3855 VPBasicBlock *splitAt(iterator SplitAt);
3856
3857 VPRegionBlock *getEnclosingLoopRegion();
3858 const VPRegionBlock *getEnclosingLoopRegion() const;
3859
3860#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3861 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
3862 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
3863 ///
3864 /// Note that the numbering is applied to the whole VPlan, so printing
3865 /// individual blocks is consistent with the whole VPlan printing.
3866 void print(raw_ostream &O, const Twine &Indent,
3867 VPSlotTracker &SlotTracker) const override;
3868 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3869#endif
3870
3871 /// If the block has multiple successors, return the branch recipe terminating
3872 /// the block. If there are no or only a single successor, return nullptr;
3873 VPRecipeBase *getTerminator();
3874 const VPRecipeBase *getTerminator() const;
3875
3876 /// Returns true if the block is exiting it's parent region.
3877 bool isExiting() const;
3878
3879 /// Clone the current block and it's recipes, without updating the operands of
3880 /// the cloned recipes.
3881 VPBasicBlock *clone() override;
3882
3883 /// Returns the predecessor block at index \p Idx with the predecessors as per
3884 /// the corresponding plain CFG. If the block is an entry block to a region,
3885 /// the first predecessor is the single predecessor of a region, and the
3886 /// second predecessor is the exiting block of the region.
3887 const VPBasicBlock *getCFGPredecessor(unsigned Idx) const;
3888
3889protected:
3890 /// Execute the recipes in the IR basic block \p BB.
3891 void executeRecipes(VPTransformState *State, BasicBlock *BB);
3892
3893 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
3894 /// generated for this VPBB.
3895 void connectToPredecessors(VPTransformState &State);
3896
3897private:
3898 /// Create an IR BasicBlock to hold the output instructions generated by this
3899 /// VPBasicBlock, and return it. Update the CFGState accordingly.
3900 BasicBlock *createEmptyBasicBlock(VPTransformState &State);
3901};
3902
3903inline const VPBasicBlock *
3905 return getAsRecipe()->getParent()->getCFGPredecessor(Idx);
3906}
3907
3908/// A special type of VPBasicBlock that wraps an existing IR basic block.
3909/// Recipes of the block get added before the first non-phi instruction in the
3910/// wrapped block.
3911/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
3912/// preheader block.
3913class VPIRBasicBlock : public VPBasicBlock {
3914 friend class VPlan;
3915
3916 BasicBlock *IRBB;
3917
3918 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
3919 VPIRBasicBlock(BasicBlock *IRBB)
3920 : VPBasicBlock(VPIRBasicBlockSC,
3921 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
3922 IRBB(IRBB) {}
3923
3924public:
3925 ~VPIRBasicBlock() override {}
3926
3927 static inline bool classof(const VPBlockBase *V) {
3928 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3929 }
3930
3931 /// The method which generates the output IR instructions that correspond to
3932 /// this VPBasicBlock, thereby "executing" the VPlan.
3933 void execute(VPTransformState *State) override;
3934
3935 VPIRBasicBlock *clone() override;
3936
3937 BasicBlock *getIRBasicBlock() const { return IRBB; }
3938};
3939
3940/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
3941/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
3942/// A VPRegionBlock may indicate that its contents are to be replicated several
3943/// times. This is designed to support predicated scalarization, in which a
3944/// scalar if-then code structure needs to be generated VF * UF times. Having
3945/// this replication indicator helps to keep a single model for multiple
3946/// candidate VF's. The actual replication takes place only once the desired VF
3947/// and UF have been determined.
3948class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
3949 friend class VPlan;
3950
3951 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
3952 VPBlockBase *Entry;
3953
3954 /// Hold the Single Exiting block of the SESE region modelled by the
3955 /// VPRegionBlock.
3956 VPBlockBase *Exiting;
3957
3958 /// An indicator whether this region is to generate multiple replicated
3959 /// instances of output IR corresponding to its VPBlockBases.
3960 bool IsReplicator;
3961
3962 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
3963 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
3964 const std::string &Name = "", bool IsReplicator = false)
3965 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
3966 IsReplicator(IsReplicator) {
3967 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
3968 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
3969 Entry->setParent(this);
3970 Exiting->setParent(this);
3971 }
3972 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
3973 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3974 IsReplicator(IsReplicator) {}
3975
3976public:
3977 ~VPRegionBlock() override {}
3978
3979 /// Method to support type inquiry through isa, cast, and dyn_cast.
3980 static inline bool classof(const VPBlockBase *V) {
3981 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
3982 }
3983
3984 const VPBlockBase *getEntry() const { return Entry; }
3985 VPBlockBase *getEntry() { return Entry; }
3986
3987 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
3988 /// EntryBlock must have no predecessors.
3989 void setEntry(VPBlockBase *EntryBlock) {
3990 assert(EntryBlock->getPredecessors().empty() &&
3991 "Entry block cannot have predecessors.");
3992 Entry = EntryBlock;
3993 EntryBlock->setParent(this);
3994 }
3995
3996 const VPBlockBase *getExiting() const { return Exiting; }
3997 VPBlockBase *getExiting() { return Exiting; }
3998
3999 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
4000 /// ExitingBlock must have no successors.
4001 void setExiting(VPBlockBase *ExitingBlock) {
4002 assert(ExitingBlock->getSuccessors().empty() &&
4003 "Exit block cannot have successors.");
4004 Exiting = ExitingBlock;
4005 ExitingBlock->setParent(this);
4006 }
4007
4008 /// Returns the pre-header VPBasicBlock of the loop region.
4010 assert(!isReplicator() && "should only get pre-header of loop regions");
4011 return getSinglePredecessor()->getExitingBasicBlock();
4012 }
4013
4014 /// An indicator whether this region is to generate multiple replicated
4015 /// instances of output IR corresponding to its VPBlockBases.
4016 bool isReplicator() const { return IsReplicator; }
4017
4018 /// The method which generates the output IR instructions that correspond to
4019 /// this VPRegionBlock, thereby "executing" the VPlan.
4020 void execute(VPTransformState *State) override;
4021
4022 // Return the cost of this region.
4023 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
4024
4025#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4026 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
4027 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
4028 /// consequtive numbers.
4029 ///
4030 /// Note that the numbering is applied to the whole VPlan, so printing
4031 /// individual regions is consistent with the whole VPlan printing.
4032 void print(raw_ostream &O, const Twine &Indent,
4033 VPSlotTracker &SlotTracker) const override;
4034 using VPBlockBase::print; // Get the print(raw_stream &O) version.
4035#endif
4036
4037 /// Clone all blocks in the single-entry single-exit region of the block and
4038 /// their recipes without updating the operands of the cloned recipes.
4039 VPRegionBlock *clone() override;
4040
4041 /// Remove the current region from its VPlan, connecting its predecessor to
4042 /// its entry, and its exiting block to its successor.
4043 void dissolveToCFGLoop();
4044};
4045
4046/// VPlan models a candidate for vectorization, encoding various decisions take
4047/// to produce efficient output IR, including which branches, basic-blocks and
4048/// output IR instructions to generate, and their cost. VPlan holds a
4049/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
4050/// VPBasicBlock.
4051class VPlan {
4052 friend class VPlanPrinter;
4053 friend class VPSlotTracker;
4054
4055 /// VPBasicBlock corresponding to the original preheader. Used to place
4056 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
4057 /// rest of VPlan execution.
4058 /// When this VPlan is used for the epilogue vector loop, the entry will be
4059 /// replaced by a new entry block created during skeleton creation.
4060 VPBasicBlock *Entry;
4061
4062 /// VPIRBasicBlock wrapping the header of the original scalar loop.
4063 VPIRBasicBlock *ScalarHeader;
4064
4065 /// Immutable list of VPIRBasicBlocks wrapping the exit blocks of the original
4066 /// scalar loop. Note that some exit blocks may be unreachable at the moment,
4067 /// e.g. if the scalar epilogue always executes.
4069
4070 /// Holds the VFs applicable to this VPlan.
4072
4073 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
4074 /// any UF.
4076
4077 /// Holds the name of the VPlan, for printing.
4078 std::string Name;
4079
4080 /// Represents the trip count of the original loop, for folding
4081 /// the tail.
4082 VPValue *TripCount = nullptr;
4083
4084 /// Represents the backedge taken count of the original loop, for folding
4085 /// the tail. It equals TripCount - 1.
4086 VPValue *BackedgeTakenCount = nullptr;
4087
4088 /// Represents the vector trip count.
4089 VPValue VectorTripCount;
4090
4091 /// Represents the vectorization factor of the loop.
4092 VPValue VF;
4093
4094 /// Represents the loop-invariant VF * UF of the vector loop region.
4095 VPValue VFxUF;
4096
4097 /// Holds a mapping between Values and their corresponding VPValue inside
4098 /// VPlan.
4099 Value2VPValueTy Value2VPValue;
4100
4101 /// Contains all the external definitions created for this VPlan. External
4102 /// definitions are VPValues that hold a pointer to their underlying IR.
4104
4105 /// Mapping from SCEVs to the VPValues representing their expansions.
4106 /// NOTE: This mapping is temporary and will be removed once all users have
4107 /// been modeled in VPlan directly.
4108 DenseMap<const SCEV *, VPValue *> SCEVToExpansion;
4109
4110 /// Blocks allocated and owned by the VPlan. They will be deleted once the
4111 /// VPlan is destroyed.
4112 SmallVector<VPBlockBase *> CreatedBlocks;
4113
4114 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
4115 /// wrapping the original header of the scalar loop.
4116 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
4117 : Entry(Entry), ScalarHeader(ScalarHeader) {
4118 Entry->setPlan(this);
4119 assert(ScalarHeader->getNumSuccessors() == 0 &&
4120 "scalar header must be a leaf node");
4121 }
4122
4123public:
4124 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
4125 /// original preheader and scalar header of \p L, to be used as entry and
4126 /// scalar header blocks of the new VPlan.
4127 VPlan(Loop *L);
4128
4129 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
4130 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
4131 VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
4132 setEntry(createVPBasicBlock("preheader"));
4133 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
4134 TripCount = TC;
4135 }
4136
4138
4140 Entry = VPBB;
4141 VPBB->setPlan(this);
4142 }
4143
4144 /// Generate the IR code for this VPlan.
4145 void execute(VPTransformState *State);
4146
4147 /// Return the cost of this plan.
4149
4150 VPBasicBlock *getEntry() { return Entry; }
4151 const VPBasicBlock *getEntry() const { return Entry; }
4152
4153 /// Returns the preheader of the vector loop region, if one exists, or null
4154 /// otherwise.
4156 VPRegionBlock *VectorRegion = getVectorLoopRegion();
4157 return VectorRegion
4158 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
4159 : nullptr;
4160 }
4161
4162 /// Returns the VPRegionBlock of the vector loop.
4165
4166 /// Returns the 'middle' block of the plan, that is the block that selects
4167 /// whether to execute the scalar tail loop or the exit block from the loop
4168 /// latch. If there is an early exit from the vector loop, the middle block
4169 /// conceptully has the early exit block as third successor, split accross 2
4170 /// VPBBs. In that case, the second VPBB selects whether to execute the scalar
4171 /// tail loop or the exit bock. If the scalar tail loop or exit block are
4172 /// known to always execute, the middle block may branch directly to that
4173 /// block. This function cannot be called once the vector loop region has been
4174 /// removed.
4176 VPRegionBlock *LoopRegion = getVectorLoopRegion();
4177 assert(
4178 LoopRegion &&
4179 "cannot call the function after vector loop region has been removed");
4180 auto *RegionSucc = cast<VPBasicBlock>(LoopRegion->getSingleSuccessor());
4181 if (RegionSucc->getSingleSuccessor() ||
4182 is_contained(RegionSucc->getSuccessors(), getScalarPreheader()))
4183 return RegionSucc;
4184 // There is an early exit. The successor of RegionSucc is the middle block.
4185 return cast<VPBasicBlock>(RegionSucc->getSuccessors()[1]);
4186 }
4187
4189 return const_cast<VPlan *>(this)->getMiddleBlock();
4190 }
4191
4192 /// Return the VPBasicBlock for the preheader of the scalar loop.
4194 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
4195 }
4196
4197 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
4198 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
4199
4200 /// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
4201 /// the original scalar loop.
4202 ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }
4203
4204 /// Return the VPIRBasicBlock corresponding to \p IRBB. \p IRBB must be an
4205 /// exit block.
4207
4208 /// Returns true if \p VPBB is an exit block.
4209 bool isExitBlock(VPBlockBase *VPBB);
4210
4211 /// The trip count of the original loop.
4213 assert(TripCount && "trip count needs to be set before accessing it");
4214 return TripCount;
4215 }
4216
4217 /// Set the trip count assuming it is currently null; if it is not - use
4218 /// resetTripCount().
4219 void setTripCount(VPValue *NewTripCount) {
4220 assert(!TripCount && NewTripCount && "TripCount should not be set yet.");
4221 TripCount = NewTripCount;
4222 }
4223
4224 /// Resets the trip count for the VPlan. The caller must make sure all uses of
4225 /// the original trip count have been replaced.
4226 void resetTripCount(VPValue *NewTripCount) {
4227 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
4228 "TripCount must be set when resetting");
4229 TripCount = NewTripCount;
4230 }
4231
4232 /// The backedge taken count of the original loop.
4234 if (!BackedgeTakenCount)
4235 BackedgeTakenCount = new VPValue();
4236 return BackedgeTakenCount;
4237 }
4238
4239 /// The vector trip count.
4240 VPValue &getVectorTripCount() { return VectorTripCount; }
4241
4242 /// Returns the VF of the vector loop region.
4243 VPValue &getVF() { return VF; };
4244
4245 /// Returns VF * UF of the vector loop region.
4246 VPValue &getVFxUF() { return VFxUF; }
4247
4250 }
4251
4252 void addVF(ElementCount VF) { VFs.insert(VF); }
4253
4255 assert(hasVF(VF) && "Cannot set VF not already in plan");
4256 VFs.clear();
4257 VFs.insert(VF);
4258 }
4259
4260 bool hasVF(ElementCount VF) const { return VFs.count(VF); }
4261 bool hasScalableVF() const {
4262 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
4263 }
4264
4265 /// Returns an iterator range over all VFs of the plan.
4268 return VFs;
4269 }
4270
4271 bool hasScalarVFOnly() const {
4272 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
4273 assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
4274 "Plan with scalar VF should only have a single VF");
4275 return HasScalarVFOnly;
4276 }
4277
4278 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
4279
4280 unsigned getUF() const {
4281 assert(UFs.size() == 1 && "Expected a single UF");
4282 return UFs[0];
4283 }
4284
4285 void setUF(unsigned UF) {
4286 assert(hasUF(UF) && "Cannot set the UF not already in plan");
4287 UFs.clear();
4288 UFs.insert(UF);
4289 }
4290
4291 /// Returns true if the VPlan already has been unrolled, i.e. it has a single
4292 /// concrete UF.
4293 bool isUnrolled() const { return UFs.size() == 1; }
4294
4295 /// Return a string with the name of the plan and the applicable VFs and UFs.
4296 std::string getName() const;
4297
4298 void setName(const Twine &newName) { Name = newName.str(); }
4299
4300 /// Gets the live-in VPValue for \p V or adds a new live-in (if none exists
4301 /// yet) for \p V.
4303 assert(V && "Trying to get or add the VPValue of a null Value");
4304 auto [It, Inserted] = Value2VPValue.try_emplace(V);
4305 if (Inserted) {
4306 VPValue *VPV = new VPValue(V);
4307 VPLiveIns.push_back(VPV);
4308 assert(VPV->isLiveIn() && "VPV must be a live-in.");
4309 It->second = VPV;
4310 }
4311
4312 assert(It->second->isLiveIn() && "Only live-ins should be in mapping");
4313 return It->second;
4314 }
4315
4316 /// Return a VPValue wrapping i1 true.
4318 LLVMContext &Ctx = getContext();
4320 }
4321
4322 /// Return a VPValue wrapping i1 false.
4324 LLVMContext &Ctx = getContext();
4326 }
4327
4328 /// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
4329 VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
4330
4331 /// Return the list of live-in VPValues available in the VPlan.
4333 assert(all_of(Value2VPValue,
4334 [this](const auto &P) {
4335 return is_contained(VPLiveIns, P.second);
4336 }) &&
4337 "all VPValues in Value2VPValue must also be in VPLiveIns");
4338 return VPLiveIns;
4339 }
4340
4341#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4342 /// Print the live-ins of this VPlan to \p O.
4343 void printLiveIns(raw_ostream &O) const;
4344
4345 /// Print this VPlan to \p O.
4346 void print(raw_ostream &O) const;
4347
4348 /// Print this VPlan in DOT format to \p O.
4349 void printDOT(raw_ostream &O) const;
4350
4351 /// Dump the plan to stderr (for debugging).
4352 LLVM_DUMP_METHOD void dump() const;
4353#endif
4354
4355 /// Returns the canonical induction recipe of the vector loop.
4358 if (EntryVPBB->empty()) {
4359 // VPlan native path.
4360 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
4361 }
4362 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
4363 }
4364
4365 VPValue *getSCEVExpansion(const SCEV *S) const {
4366 return SCEVToExpansion.lookup(S);
4367 }
4368
4369 void addSCEVExpansion(const SCEV *S, VPValue *V) {
4370 assert(!SCEVToExpansion.contains(S) && "SCEV already expanded");
4371 SCEVToExpansion[S] = V;
4372 }
4373
4374 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
4375 /// recipes to refer to the clones, and return it.
4376 VPlan *duplicate();
4377
4378 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
4379 /// present. The returned block is owned by the VPlan and deleted once the
4380 /// VPlan is destroyed.
4382 VPRecipeBase *Recipe = nullptr) {
4383 auto *VPB = new VPBasicBlock(Name, Recipe);
4384 CreatedBlocks.push_back(VPB);
4385 return VPB;
4386 }
4387
4388 /// Create a new VPRegionBlock with \p Entry, \p Exiting and \p Name. If \p
4389 /// IsReplicator is true, the region is a replicate region. The returned block
4390 /// is owned by the VPlan and deleted once the VPlan is destroyed.
4392 const std::string &Name = "",
4393 bool IsReplicator = false) {
4394 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, IsReplicator);
4395 CreatedBlocks.push_back(VPB);
4396 return VPB;
4397 }
4398
4399 /// Create a new loop VPRegionBlock with \p Name and entry and exiting blocks set
4400 /// to nullptr. The returned block is owned by the VPlan and deleted once the
4401 /// VPlan is destroyed.
4402 VPRegionBlock *createVPRegionBlock(const std::string &Name = "") {
4403 auto *VPB = new VPRegionBlock(Name);
4404 CreatedBlocks.push_back(VPB);
4405 return VPB;
4406 }
4407
4408 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
4409 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
4410 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
4412
4413 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
4414 /// instructions in \p IRBB, except its terminator which is managed by the
4415 /// successors of the block in VPlan. The returned block is owned by the VPlan
4416 /// and deleted once the VPlan is destroyed.
4418
4419 /// Returns true if the VPlan is based on a loop with an early exit. That is
4420 /// the case if the VPlan has either more than one exit block or a single exit
4421 /// block with multiple predecessors (one for the exit via the latch and one
4422 /// via the other early exit).
4423 bool hasEarlyExit() const {
4424 return count_if(ExitBlocks,
4425 [](VPIRBasicBlock *EB) { return EB->hasPredecessors(); }) >
4426 1 ||
4427 (ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
4428 }
4429
4430 /// Returns true if the scalar tail may execute after the vector loop. Note
4431 /// that this relies on unneeded branches to the scalar tail loop being
4432 /// removed.
4433 bool hasScalarTail() const {
4434 return !(!getScalarPreheader()->hasPredecessors() ||
4436 }
4437};
4438
4439#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4440inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
4441 Plan.print(OS);
4442 return OS;
4443}
4444#endif
4445
4446} // end namespace llvm
4447
4448#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:3481
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition VPlan.h:3475
~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:3760
RecipeListTy::const_iterator const_iterator
Definition VPlan.h:3788
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition VPlan.h:3835
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition VPlan.h:3790
RecipeListTy::iterator iterator
Instruction iterators...
Definition VPlan.h:3787
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition VPlan.h:3813
iplist< VPRecipeBase > RecipeListTy
Definition VPlan.h:3771
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition VPlan.h:3777
iterator end()
Definition VPlan.h:3797
iterator begin()
Recipe iterator methods.
Definition VPlan.h:3795
RecipeListTy::reverse_iterator reverse_iterator
Definition VPlan.h:3789
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:3848
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:3781
const_reverse_iterator rbegin() const
Definition VPlan.h:3801
reverse_iterator rend()
Definition VPlan.h:3802
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition VPlan.h:3775
VPRecipeBase & back()
Definition VPlan.h:3810
const VPRecipeBase & front() const
Definition VPlan.h:3807
const_iterator begin() const
Definition VPlan.h:3796
VPRecipeBase & front()
Definition VPlan.h:3808
const VPRecipeBase & back() const
Definition VPlan.h:3809
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:3826
bool empty() const
Definition VPlan.h:3806
const_iterator end() const
Definition VPlan.h:3798
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3821
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition VPlan.h:3816
reverse_iterator rbegin()
Definition VPlan.h:3800
friend class VPlan
Definition VPlan.h:3761
size_t size() const
Definition VPlan.h:3805
const_reverse_iterator rend() const
Definition VPlan.h:3803
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2459
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition VPlan.h:2428
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition VPlan.h:2433
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition VPlan.h:2423
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2444
VPBlendRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2410
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:2405
void setMask(unsigned Idx, VPValue *V)
Set mask number Idx to V.
Definition VPlan.h:2439
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:2419
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:2951
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2935
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2959
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
Definition VPlan.h:2932
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3416
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:3455
~VPCanonicalIVPHIRecipe() override=default
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3423
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
Definition VPlan.h:3418
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3448
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:3443
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3431
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:3462
This class augments a recipe with a set of VPValues defined by the recipe.
Definition VPlanValue.h:302
friend class VPValue
Definition VPlanValue.h:303
VPDef(const unsigned char SC)
Definition VPlanValue.h:382
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:3620
VPValue * getStepValue() const
Definition VPlan.h:3637
Type * getScalarType() const
Definition VPlan.h:3632
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3608
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3600
~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:3640
VPValue * getStartValue() const
Definition VPlan.h:3636
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3592
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:3511
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3517
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition VPlan.h:3523
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition VPlan.h:3506
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3530
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:3392
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
Definition VPlan.h:3397
VPExpandSCEVRecipe(const SCEV *Expr)
Definition VPlan.h:3383
const SCEV * getSCEV() const
Definition VPlan.h:3409
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:3388
~VPExpandSCEVRecipe() override=default
void execute(VPTransformState &State) override
Method for generating code, must not be called as this recipe is abstract.
Definition VPlan.h:3060
VPValue * getOperandOfResultType() const
Return the VPValue to use to infer the result type of the recipe.
Definition VPlan.h:3047
VPExpressionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3029
void decompose()
Insert the recipes of the expression back into the VPlan, directly before the current recipe.
~VPExpressionRecipe() override
Definition VPlan.h:3020
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpressionRecipe(VPWidenCastRecipe *Ext, VPReductionRecipe *Red)
Definition VPlan.h:3011
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:3015
VPExpressionRecipe(VPWidenRecipe *Mul, VPReductionRecipe *Red)
Definition VPlan.h:3013
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:1980
static bool classof(const VPValue *V)
Definition VPlan.h:1990
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:2021
void setBackedgeValue(VPValue *V)
Update the incoming value from the loop backedge.
Definition VPlan.h:2026
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition VPlan.h:2010
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition VPlan.h:2018
VPValue * getStartValue() const
Definition VPlan.h:2013
static bool classof(const VPRecipeBase *B)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:1986
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition VPlan.h:2030
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, VPValue *Start, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1975
~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:3913
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:3937
~VPIRBasicBlock() override
Definition VPlan.h:3925
static bool classof(const VPBlockBase *V)
Definition VPlan.h:3927
friend class VPlan
Definition VPlan.h:3914
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:2538
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2544
static bool classof(const VPUser *U)
Definition VPlan.h:2520
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:2487
Instruction * getInsertPos() const
Definition VPlan.h:2542
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2515
const InterleaveGroup< Instruction > * getInterleaveGroup() const
Definition VPlan.h:2540
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:2532
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition VPlan.h:2561
VPInterleaveBase * clone() override=0
Clone the current recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:2526
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2635
~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:2647
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2654
VPInterleaveEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2628
VPInterleaveEVLRecipe(VPInterleaveRecipe &R, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:2615
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition VPlan.h:2572
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2605
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2599
~VPInterleaveRecipe() override=default
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2582
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Definition VPlan.h:2574
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:2757
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned ScaleFactor, Instruction *ReductionInst=nullptr)
Definition VPlan.h:2761
~VPPartialReductionRecipe() override=default
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2795
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:2792
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2776
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:3904
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:3119
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3095
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
Definition VPlan.h:3106
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition VPlan.h:3091
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:2840
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2837
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2810
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2821
~VPReductionEVLRecipe() override=default
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition VPlan.h:2384
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2353
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
Definition VPlan.h:2367
~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:2390
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:2343
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2378
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
Definition VPlan.h:2387
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:2381
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition VPlan.h:2662
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition VPlan.h:2734
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2706
VPReductionRecipe(const RecurKind RdxKind, FastMathFlags FMFs, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2691
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition VPlan.h:2738
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition VPlan.h:2740
RecurKind getRecurrenceKind() const
Return the recurrence kind for the in-loop reduction.
Definition VPlan.h:2730
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition VPlan.h:2732
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition VPlan.h:2736
VPReductionRecipe(RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2684
VPReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2700
VPReductionRecipe(const unsigned char SC, RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
Definition VPlan.h:2670
static bool classof(const VPUser *U)
Definition VPlan.h:2711
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:3948
const VPBlockBase * getEntry() const
Definition VPlan.h:3984
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4016
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition VPlan.h:4001
VPBlockBase * getExiting()
Definition VPlan.h:3997
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition VPlan.h:3989
const VPBlockBase * getExiting() const
Definition VPlan.h:3996
VPBlockBase * getEntry()
Definition VPlan.h:3985
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition VPlan.h:4009
~VPRegionBlock() override
Definition VPlan.h:3977
friend class VPlan
Definition VPlan.h:3949
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:3980
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2852
VPReplicateRecipe(Instruction *I, ArrayRef< VPValue * > Operands, bool IsSingleScalar, VPValue *Mask=nullptr, VPIRMetadata Metadata={})
Definition VPlan.h:2860
bool isSingleScalar() const
Definition VPlan.h:2897
~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:2902
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:2909
bool isPredicated() const
Definition VPlan.h:2899
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2872
unsigned getOpcode() const
Definition VPlan.h:2926
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition VPlan.h:2921
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3705
VPValue * getStepValue() const
Definition VPlan.h:3702
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition VPlan.h:3690
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step, VPValue *VF, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:3661
bool isPart0() const
Return true if this VPScalarIVStepsRecipe corresponds to part 0.
Definition VPlan.h:3682
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3673
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, VPValue *VF, Instruction::BinaryOps Opcode, FastMathFlags FMFs, DebugLoc DL)
Definition VPlan.h:3654
~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:199
void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the operands to O.
Definition VPlan.cpp:1455
operand_range operands()
Definition VPlanValue.h:267
void setOperand(unsigned I, VPValue *New)
Definition VPlanValue.h:243
unsigned getNumOperands() const
Definition VPlanValue.h:237
operand_iterator op_end()
Definition VPlanValue.h:265
VPValue * getOperand(unsigned N) const
Definition VPlanValue.h:238
VPUser(ArrayRef< VPValue * > Operands)
Definition VPlanValue.h:218
iterator_range< const_operand_iterator > const_operand_range
Definition VPlanValue.h:261
iterator_range< operand_iterator > operand_range
Definition VPlanValue.h:260
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:176
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:186
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:171
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:1874
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1860
VPVectorEndPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1881
const VPValue * getVFValue() const
Definition VPlan.h:1856
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:1867
VPVectorEndPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1845
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:1933
Type * getSourceElementType() const
Definition VPlan.h:1910
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:1919
VPVectorPointerRecipe(VPValue *Ptr, Type *SourceElementTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1900
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:1912
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition VPlan.h:1936
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1926
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:3565
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3552
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition VPlan.h:3547
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:1802
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1823
Type * getSourceElementType() const
Definition VPlan.h:1807
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef< VPValue * > Operands)
Definition VPlan.h:1783
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition VPlan.h:1810
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1794
~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:2100
static bool classof(const VPValue *V)
Definition VPlan.h:2054
void setStepValue(VPValue *V)
Update the step value of the recipe.
Definition VPlan.h:2070
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition VPlan.h:2085
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2078
PHINode * getPHINode() const
Definition VPlan.h:2080
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2042
VPValue * getStepValue()
Returns the step value of the induction.
Definition VPlan.h:2066
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition VPlan.h:2083
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition VPlan.h:2092
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2049
static bool classof(const VPHeaderPHIRecipe *R)
Definition VPlan.h:2059
const VPValue * getVFValue() const
Definition VPlan.h:2073
const VPValue * getStepValue() const
Definition VPlan.h:2067
virtual void execute(VPTransformState &State) override=0
Generate the phi nodes.
const TruncInst * getTruncInst() const
Definition VPlan.h:2178
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:2153
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
Definition VPlan.h:2129
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2145
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition VPlan.h:2177
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2120
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition VPlan.h:2194
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2173
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:2186
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:3140
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition VPlan.h:3137
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition VPlan.h:3177
static bool classof(const VPUser *U)
Definition VPlan.h:3171
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition VPlan.h:3197
Instruction & Ingredient
Definition VPlan.h:3131
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3160
Instruction & getIngredient() const
Definition VPlan.h:3205
bool Consecutive
Whether the accessed addresses are consecutive.
Definition VPlan.h:3134
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:3164
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:3191
bool isMasked() const
Returns true if the recipe is masked.
Definition VPlan.h:3187
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3150
void setMask(VPValue *Mask)
Definition VPlan.h:3142
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:3184
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition VPlan.h:3181
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:2254
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:2259
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2267
~VPWidenPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2218
~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:2228
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:2206
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:4051
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition VPlan.cpp:1141
friend class VPSlotTracker
Definition VPlan.h:4053
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition VPlan.cpp:1117
bool hasVF(ElementCount VF) const
Definition VPlan.h:4260
LLVMContext & getContext() const
Definition VPlan.h:4248
VPBasicBlock * getEntry()
Definition VPlan.h:4150
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:4391
VPValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4240
void setName(const Twine &newName)
Definition VPlan.h:4298
bool hasScalableVF() const
Definition VPlan.h:4261
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:4246
VPValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4243
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4212
VPValue * getTrue()
Return a VPValue wrapping i1 true.
Definition VPlan.h:4317
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition VPlan.h:4233
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition VPlan.h:4267
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
Definition VPlan.h:4131
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:4151
friend class VPlanPrinter
Definition VPlan.h:4052
unsigned getUF() const
Definition VPlan.h:4280
VPRegionBlock * createVPRegionBlock(const std::string &Name="")
Create a new loop VPRegionBlock with Name and entry and exiting blocks set to nullptr.
Definition VPlan.h:4402
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
Definition VPlan.cpp:1255
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition VPlan.h:4369
bool hasUF(unsigned UF) const
Definition VPlan.h:4278
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
Definition VPlan.h:4202
void setVF(ElementCount VF)
Definition VPlan.h:4254
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
Definition VPlan.h:4293
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition VPlan.cpp:1046
bool hasEarlyExit() const
Returns true if the VPlan is based on a loop with an early exit.
Definition VPlan.h:4423
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition VPlan.cpp:1028
const VPBasicBlock * getMiddleBlock() const
Definition VPlan.h:4188
void setTripCount(VPValue *NewTripCount)
Set the trip count assuming it is currently null; if it is not - use resetTripCount().
Definition VPlan.h:4219
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition VPlan.h:4226
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition VPlan.h:4175
void setEntry(VPBasicBlock *VPBB)
Definition VPlan.h:4139
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition VPlan.h:4381
LLVM_ABI_FOR_TEST VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
Definition VPlan.cpp:1261
VPValue * getFalse()
Return a VPValue wrapping i1 false.
Definition VPlan.h:4323
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:4302
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition VPlan.cpp:1147
bool hasScalarVFOnly() const
Definition VPlan.h:4271
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4193
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:4332
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition VPlan.h:4356
void print(raw_ostream &O) const
Print this VPlan to O.
Definition VPlan.cpp:1100
void addVF(ElementCount VF)
Definition VPlan.h:4252
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition VPlan.h:4198
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
Definition VPlan.h:4329
VPValue * getSCEVExpansion(const SCEV *S) const
Definition VPlan.h:4365
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition VPlan.cpp:1062
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition VPlan.h:4155
void setUF(unsigned UF)
Definition VPlan.h:4285
bool hasScalarTail() const
Returns true if the scalar tail may execute after the vector loop.
Definition VPlan.h:4433
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition VPlan.cpp:1188
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:2405
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:318
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:831
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:1731
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:1705
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:841
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:2452
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:366
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:1712
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
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:325
@ 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:1934
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:1941
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:1877
DenseMap< Value *, VPValue * > Value2VPValueTy
Definition VPlanValue.h:192
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:3723
static VPPhiAccessors * doCastIfPossible(SrcTy f)
doCastIfPossible is used by dyn_cast<>.
Definition VPlan.h:3744
CastInfo< VPPhiAccessors, SrcTy > Self
Definition VPlan.h:3725
static VPPhiAccessors * doCast(SrcTy R)
doCast is used by cast<>.
Definition VPlan.h:3728
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:3715
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:2298
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
Definition VPlan.h:2293
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:2316
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:3264
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:3252
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3280
A recipe for widening load operations, using the address to load from and an optional mask.
Definition VPlan.h:3211
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:3239
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:3212
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3221
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:3345
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:3364
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue *Addr, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:3334
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition VPlan.h:3348
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition VPlan.h:3291
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3321
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition VPlan.h:3309
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3300
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3292