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