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