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