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