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