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