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() override = default;
1645
1646 VPWidenRecipe *clone() override {
1647 return new VPWidenRecipe(*getUnderlyingInstr(), operands(), *this, *this,
1648 getDebugLoc());
1649 }
1650
1651 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenSC)
1652
1653 /// Produce a widened instruction using the opcode and operands of the recipe,
1654 /// processing State.VF elements.
1655 void execute(VPTransformState &State) override;
1656
1657 /// Return the cost of this VPWidenRecipe.
1658 InstructionCost computeCost(ElementCount VF,
1659 VPCostContext &Ctx) const override;
1660
1661 unsigned getOpcode() const { return Opcode; }
1662
1663protected:
1664#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1665 /// Print the recipe.
1666 void printRecipe(raw_ostream &O, const Twine &Indent,
1667 VPSlotTracker &SlotTracker) const override;
1668#endif
1669
1670 /// Returns true if the recipe only uses the first lane of operand \p Op.
1671 bool usesFirstLaneOnly(const VPValue *Op) const override {
1673 "Op must be an operand of the recipe");
1674 return Opcode == Instruction::Select && Op == getOperand(0) &&
1675 Op->isDefinedOutsideLoopRegions();
1676 }
1677};
1678
1679/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1681 /// Cast instruction opcode.
1682 Instruction::CastOps Opcode;
1683
1684 /// Result type for the cast.
1685 Type *ResultTy;
1686
1687public:
1689 CastInst *CI = nullptr, const VPIRFlags &Flags = {},
1690 const VPIRMetadata &Metadata = {},
1692 : VPRecipeWithIRFlags(VPRecipeBase::VPWidenCastSC, Op, Flags, DL),
1693 VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
1694 assert(flagsValidForOpcode(Opcode) &&
1695 "Set flags not supported for the provided opcode");
1697 }
1698
1699 ~VPWidenCastRecipe() override = default;
1700
1702 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1704 *this, *this, getDebugLoc());
1705 }
1706
1707 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenCastSC)
1708
1709 /// Produce widened copies of the cast.
1710 LLVM_ABI_FOR_TEST void execute(VPTransformState &State) override;
1711
1712 /// Return the cost of this VPWidenCastRecipe.
1714 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
1715
1716 Instruction::CastOps getOpcode() const { return Opcode; }
1717
1718 /// Returns the result type of the cast.
1719 Type *getResultType() const { return ResultTy; }
1720
1721protected:
1722#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1723 /// Print the recipe.
1724 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
1725 VPSlotTracker &SlotTracker) const override;
1726#endif
1727};
1728
1729/// A recipe for widening vector intrinsics.
1731 /// ID of the vector intrinsic to widen.
1732 Intrinsic::ID VectorIntrinsicID;
1733
1734 /// Scalar return type of the intrinsic.
1735 Type *ResultTy;
1736
1737 /// True if the intrinsic may read from memory.
1738 bool MayReadFromMemory;
1739
1740 /// True if the intrinsic may read write to memory.
1741 bool MayWriteToMemory;
1742
1743 /// True if the intrinsic may have side-effects.
1744 bool MayHaveSideEffects;
1745
1746public:
1748 ArrayRef<VPValue *> CallArguments, Type *Ty,
1749 const VPIRFlags &Flags = {},
1750 const VPIRMetadata &MD = {},
1752 : VPRecipeWithIRFlags(VPRecipeBase::VPWidenIntrinsicSC, CallArguments,
1753 Flags, DL),
1754 VPIRMetadata(MD), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1755 MayReadFromMemory(CI.mayReadFromMemory()),
1756 MayWriteToMemory(CI.mayWriteToMemory()),
1757 MayHaveSideEffects(CI.mayHaveSideEffects()) {
1758 setUnderlyingValue(&CI);
1759 }
1760
1762 ArrayRef<VPValue *> CallArguments, Type *Ty,
1763 const VPIRFlags &Flags = {},
1764 const VPIRMetadata &Metadata = {},
1766 : VPRecipeWithIRFlags(VPRecipeBase::VPWidenIntrinsicSC, CallArguments,
1767 Flags, DL),
1768 VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1769 ResultTy(Ty) {
1770 LLVMContext &Ctx = Ty->getContext();
1771 AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
1772 MemoryEffects ME = Attrs.getMemoryEffects();
1773 MayReadFromMemory = !ME.onlyWritesMemory();
1774 MayWriteToMemory = !ME.onlyReadsMemory();
1775 MayHaveSideEffects = MayWriteToMemory ||
1776 !Attrs.hasAttribute(Attribute::NoUnwind) ||
1777 !Attrs.hasAttribute(Attribute::WillReturn);
1778 }
1779
1780 ~VPWidenIntrinsicRecipe() override = default;
1781
1783 if (Value *CI = getUnderlyingValue())
1784 return new VPWidenIntrinsicRecipe(*cast<CallInst>(CI), VectorIntrinsicID,
1785 operands(), ResultTy, *this, *this,
1786 getDebugLoc());
1787 return new VPWidenIntrinsicRecipe(VectorIntrinsicID, operands(), ResultTy,
1788 *this, *this, getDebugLoc());
1789 }
1790
1791 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenIntrinsicSC)
1792
1793 /// Produce a widened version of the vector intrinsic.
1794 LLVM_ABI_FOR_TEST void execute(VPTransformState &State) override;
1795
1796 /// Return the cost of this vector intrinsic.
1798 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
1799
1800 /// Return the ID of the intrinsic.
1801 Intrinsic::ID getVectorIntrinsicID() const { return VectorIntrinsicID; }
1802
1803 /// Return the scalar return type of the intrinsic.
1804 Type *getResultType() const { return ResultTy; }
1805
1806 /// Return to name of the intrinsic as string.
1808
1809 /// Returns true if the intrinsic may read from memory.
1810 bool mayReadFromMemory() const { return MayReadFromMemory; }
1811
1812 /// Returns true if the intrinsic may write to memory.
1813 bool mayWriteToMemory() const { return MayWriteToMemory; }
1814
1815 /// Returns true if the intrinsic may have side-effects.
1816 bool mayHaveSideEffects() const { return MayHaveSideEffects; }
1817
1818 LLVM_ABI_FOR_TEST bool usesFirstLaneOnly(const VPValue *Op) const override;
1819
1820protected:
1821#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1822 /// Print the recipe.
1823 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
1824 VPSlotTracker &SlotTracker) const override;
1825#endif
1826};
1827
1828/// A recipe for widening Call instructions using library calls.
1830 public VPIRMetadata {
1831 /// Variant stores a pointer to the chosen function. There is a 1:1 mapping
1832 /// between a given VF and the chosen vectorized variant, so there will be a
1833 /// different VPlan for each VF with a valid variant.
1834 Function *Variant;
1835
1836public:
1838 ArrayRef<VPValue *> CallArguments,
1839 const VPIRFlags &Flags = {},
1840 const VPIRMetadata &Metadata = {}, DebugLoc DL = {})
1841 : VPRecipeWithIRFlags(VPRecipeBase::VPWidenCallSC, CallArguments, Flags,
1842 DL),
1843 VPIRMetadata(Metadata), Variant(Variant) {
1844 setUnderlyingValue(UV);
1845 assert(
1846 isa<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue()) &&
1847 "last operand must be the called function");
1848 }
1849
1850 ~VPWidenCallRecipe() override = default;
1851
1853 return new VPWidenCallRecipe(getUnderlyingValue(), Variant, operands(),
1854 *this, *this, getDebugLoc());
1855 }
1856
1857 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenCallSC)
1858
1859 /// Produce a widened version of the call instruction.
1860 void execute(VPTransformState &State) override;
1861
1862 /// Return the cost of this VPWidenCallRecipe.
1863 InstructionCost computeCost(ElementCount VF,
1864 VPCostContext &Ctx) const override;
1865
1869
1872
1873protected:
1874#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1875 /// Print the recipe.
1876 void printRecipe(raw_ostream &O, const Twine &Indent,
1877 VPSlotTracker &SlotTracker) const override;
1878#endif
1879};
1880
1881/// A recipe representing a sequence of load -> update -> store as part of
1882/// a histogram operation. This means there may be aliasing between vector
1883/// lanes, which is handled by the llvm.experimental.vector.histogram family
1884/// of intrinsics. The only update operations currently supported are
1885/// 'add' and 'sub' where the other term is loop-invariant.
1887 /// Opcode of the update operation, currently either add or sub.
1888 unsigned Opcode;
1889
1890public:
1891 VPHistogramRecipe(unsigned Opcode, ArrayRef<VPValue *> Operands,
1893 : VPRecipeBase(VPRecipeBase::VPHistogramSC, Operands, DL),
1894 Opcode(Opcode) {}
1895
1896 ~VPHistogramRecipe() override = default;
1897
1899 return new VPHistogramRecipe(Opcode, operands(), getDebugLoc());
1900 }
1901
1902 VP_CLASSOF_IMPL(VPRecipeBase::VPHistogramSC);
1903
1904 /// Produce a vectorized histogram operation.
1905 void execute(VPTransformState &State) override;
1906
1907 /// Return the cost of this VPHistogramRecipe.
1909 VPCostContext &Ctx) const override;
1910
1911 unsigned getOpcode() const { return Opcode; }
1912
1913 /// Return the mask operand if one was provided, or a null pointer if all
1914 /// lanes should be executed unconditionally.
1915 VPValue *getMask() const {
1916 return getNumOperands() == 3 ? getOperand(2) : nullptr;
1917 }
1918
1919protected:
1920#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1921 /// Print the recipe
1922 void printRecipe(raw_ostream &O, const Twine &Indent,
1923 VPSlotTracker &SlotTracker) const override;
1924#endif
1925};
1926
1927/// A recipe for handling GEP instructions.
1929 Type *SourceElementTy;
1930
1931 bool isPointerLoopInvariant() const {
1932 return getOperand(0)->isDefinedOutsideLoopRegions();
1933 }
1934
1935 bool isIndexLoopInvariant(unsigned I) const {
1936 return getOperand(I + 1)->isDefinedOutsideLoopRegions();
1937 }
1938
1939public:
1941 const VPIRFlags &Flags = {},
1943 : VPRecipeWithIRFlags(VPRecipeBase::VPWidenGEPSC, Operands, Flags, DL),
1944 SourceElementTy(GEP->getSourceElementType()) {
1945 setUnderlyingValue(GEP);
1947 (void)Metadata;
1949 assert(Metadata.empty() && "unexpected metadata on GEP");
1950 }
1951
1952 ~VPWidenGEPRecipe() override = default;
1953
1956 operands(), *this, getDebugLoc());
1957 }
1958
1959 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenGEPSC)
1960
1961 /// This recipe generates a GEP instruction.
1962 unsigned getOpcode() const { return Instruction::GetElementPtr; }
1963
1964 /// Generate the gep nodes.
1965 void execute(VPTransformState &State) override;
1966
1967 Type *getSourceElementType() const { return SourceElementTy; }
1968
1969 /// Return the cost of this VPWidenGEPRecipe.
1971 VPCostContext &Ctx) const override {
1972 // TODO: Compute accurate cost after retiring the legacy cost model.
1973 return 0;
1974 }
1975
1976 /// Returns true if the recipe only uses the first lane of operand \p Op.
1977 bool usesFirstLaneOnly(const VPValue *Op) const override;
1978
1979protected:
1980#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1981 /// Print the recipe.
1982 void printRecipe(raw_ostream &O, const Twine &Indent,
1983 VPSlotTracker &SlotTracker) const override;
1984#endif
1985};
1986
1987/// A recipe to compute a pointer to the last element of each part of a widened
1988/// memory access for widened memory accesses of IndexedTy. Used for
1989/// VPWidenMemoryRecipes or VPInterleaveRecipes that are reversed.
1991 public VPUnrollPartAccessor<2> {
1992 Type *IndexedTy;
1993
1994 /// The constant stride of the pointer computed by this recipe, expressed in
1995 /// units of IndexedTy.
1996 int64_t Stride;
1997
1998public:
2000 int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
2001 : VPRecipeWithIRFlags(VPRecipeBase::VPVectorEndPointerSC,
2002 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
2003 IndexedTy(IndexedTy), Stride(Stride) {
2004 assert(Stride < 0 && "Stride must be negative");
2005 }
2006
2007 VP_CLASSOF_IMPL(VPRecipeBase::VPVectorEndPointerSC)
2008
2010 const VPValue *getVFValue() const { return getOperand(1); }
2011
2012 void execute(VPTransformState &State) override;
2013
2014 bool usesFirstLaneOnly(const VPValue *Op) const override {
2016 "Op must be an operand of the recipe");
2017 return true;
2018 }
2019
2020 /// Return the cost of this VPVectorPointerRecipe.
2022 VPCostContext &Ctx) const override {
2023 // TODO: Compute accurate cost after retiring the legacy cost model.
2024 return 0;
2025 }
2026
2027 /// Returns true if the recipe only uses the first part of operand \p Op.
2028 bool usesFirstPartOnly(const VPValue *Op) const override {
2030 "Op must be an operand of the recipe");
2031 assert(getNumOperands() <= 2 && "must have at most two operands");
2032 return true;
2033 }
2034
2036 return new VPVectorEndPointerRecipe(getOperand(0), getVFValue(), IndexedTy,
2037 Stride, getGEPNoWrapFlags(),
2038 getDebugLoc());
2039 }
2040
2041protected:
2042#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2043 /// Print the recipe.
2044 void printRecipe(raw_ostream &O, const Twine &Indent,
2045 VPSlotTracker &SlotTracker) const override;
2046#endif
2047};
2048
2049/// A recipe to compute the pointers for widened memory accesses of \p
2050/// SourceElementTy. Unrolling adds an extra offset operand for unrolled parts >
2051/// 0 and it produces `GEP Ptr, Offset`. The offset for unrolled part 0 is 0.
2053 Type *SourceElementTy;
2054
2055public:
2056 VPVectorPointerRecipe(VPValue *Ptr, Type *SourceElementTy,
2058 : VPRecipeWithIRFlags(VPRecipeBase::VPVectorPointerSC, Ptr, GEPFlags, DL),
2059 SourceElementTy(SourceElementTy) {}
2060
2061 VP_CLASSOF_IMPL(VPRecipeBase::VPVectorPointerSC)
2062
2064 return getNumOperands() == 2 ? getOperand(1) : nullptr;
2065 }
2066
2067 void execute(VPTransformState &State) override;
2068
2069 Type *getSourceElementType() const { return SourceElementTy; }
2070
2071 bool usesFirstLaneOnly(const VPValue *Op) const override {
2073 "Op must be an operand of the recipe");
2074 return true;
2075 }
2076
2077 /// Returns true if the recipe only uses the first part of operand \p Op.
2078 bool usesFirstPartOnly(const VPValue *Op) const override {
2080 "Op must be an operand of the recipe");
2081 assert(getNumOperands() <= 2 && "must have at most two operands");
2082 return true;
2083 }
2084
2086 auto *Clone = new VPVectorPointerRecipe(getOperand(0), SourceElementTy,
2088 if (auto *Off = getOffset())
2089 Clone->addOperand(Off);
2090 return Clone;
2091 }
2092
2093 /// Return the cost of this VPHeaderPHIRecipe.
2095 VPCostContext &Ctx) const override {
2096 // TODO: Compute accurate cost after retiring the legacy cost model.
2097 return 0;
2098 }
2099
2100protected:
2101#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2102 /// Print the recipe.
2103 void printRecipe(raw_ostream &O, const Twine &Indent,
2104 VPSlotTracker &SlotTracker) const override;
2105#endif
2106};
2107
2108/// A pure virtual base class for all recipes modeling header phis, including
2109/// phis for first order recurrences, pointer inductions and reductions. The
2110/// start value is the first operand of the recipe and the incoming value from
2111/// the backedge is the second operand.
2112///
2113/// Inductions are modeled using the following sub-classes:
2114/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
2115/// starting at a specified value (zero for the main vector loop, the resume
2116/// value for the epilogue vector loop) and stepping by 1. The induction
2117/// controls exiting of the vector loop by comparing against the vector trip
2118/// count. Produces a single scalar PHI for the induction value per
2119/// iteration.
2120/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
2121/// floating point inductions with arbitrary start and step values. Produces
2122/// a vector PHI per-part.
2123/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
2124/// value of an IV with different start and step values. Produces a single
2125/// scalar value per iteration
2126/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
2127/// canonical or derived induction.
2128/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
2129/// pointer induction. Produces either a vector PHI per-part or scalar values
2130/// per-lane based on the canonical induction.
2132 public VPPhiAccessors {
2133protected:
2134 VPHeaderPHIRecipe(unsigned char VPRecipeID, Instruction *UnderlyingInstr,
2135 VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
2136 : VPSingleDefRecipe(VPRecipeID, ArrayRef<VPValue *>({Start}),
2137 UnderlyingInstr, DL) {}
2138
2139 const VPRecipeBase *getAsRecipe() const override { return this; }
2140
2141public:
2142 ~VPHeaderPHIRecipe() override = default;
2143
2144 /// Method to support type inquiry through isa, cast, and dyn_cast.
2145 static inline bool classof(const VPRecipeBase *R) {
2146 return R->getVPRecipeID() >= VPRecipeBase::VPFirstHeaderPHISC &&
2147 R->getVPRecipeID() <= VPRecipeBase::VPLastHeaderPHISC;
2148 }
2149 static inline bool classof(const VPValue *V) {
2150 return isa<VPHeaderPHIRecipe>(V->getDefiningRecipe());
2151 }
2152 static inline bool classof(const VPSingleDefRecipe *R) {
2153 return isa<VPHeaderPHIRecipe>(static_cast<const VPRecipeBase *>(R));
2154 }
2155
2156 /// Generate the phi nodes.
2157 void execute(VPTransformState &State) override = 0;
2158
2159 /// Return the cost of this header phi recipe.
2161 VPCostContext &Ctx) const override;
2162
2163 /// Returns the start value of the phi, if one is set.
2165 return getNumOperands() == 0 ? nullptr : getOperand(0);
2166 }
2168 return getNumOperands() == 0 ? nullptr : getOperand(0);
2169 }
2170
2171 /// Update the start value of the recipe.
2173
2174 /// Returns the incoming value from the loop backedge.
2176 return getOperand(1);
2177 }
2178
2179 /// Update the incoming value from the loop backedge.
2181
2182 /// Returns the backedge value as a recipe. The backedge value is guaranteed
2183 /// to be a recipe.
2185 return *getBackedgeValue()->getDefiningRecipe();
2186 }
2187
2188protected:
2189#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2190 /// Print the recipe.
2191 void printRecipe(raw_ostream &O, const Twine &Indent,
2192 VPSlotTracker &SlotTracker) const override = 0;
2193#endif
2194};
2195
2196/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2197/// VPWidenPointerInductionRecipe), providing shared functionality, including
2198/// retrieving the step value, induction descriptor and original phi node.
2200 const InductionDescriptor &IndDesc;
2201
2202public:
2203 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
2204 VPValue *Step, const InductionDescriptor &IndDesc,
2205 DebugLoc DL)
2206 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2207 addOperand(Step);
2208 }
2209
2210 static inline bool classof(const VPRecipeBase *R) {
2211 return R->getVPRecipeID() == VPRecipeBase::VPWidenIntOrFpInductionSC ||
2212 R->getVPRecipeID() == VPRecipeBase::VPWidenPointerInductionSC;
2213 }
2214
2215 static inline bool classof(const VPValue *V) {
2216 auto *R = V->getDefiningRecipe();
2217 return R && classof(R);
2218 }
2219
2220 static inline bool classof(const VPSingleDefRecipe *R) {
2221 return classof(static_cast<const VPRecipeBase *>(R));
2222 }
2223
2224 void execute(VPTransformState &State) override = 0;
2225
2226 /// Returns the start value of the induction.
2228
2229 /// Returns the step value of the induction.
2231 const VPValue *getStepValue() const { return getOperand(1); }
2232
2233 /// Update the step value of the recipe.
2234 void setStepValue(VPValue *V) { setOperand(1, V); }
2235
2237 const VPValue *getVFValue() const { return getOperand(2); }
2238
2239 /// Returns the number of incoming values, also number of incoming blocks.
2240 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2241 /// incoming value, its start value.
2242 unsigned getNumIncoming() const override { return 1; }
2243
2245
2246 /// Returns the induction descriptor for the recipe.
2247 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
2248
2250 // TODO: All operands of base recipe must exist and be at same index in
2251 // derived recipe.
2253 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2254 }
2255
2257 // TODO: All operands of base recipe must exist and be at same index in
2258 // derived recipe.
2260 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2261 }
2262
2263 /// Returns true if the recipe only uses the first lane of operand \p Op.
2264 bool usesFirstLaneOnly(const VPValue *Op) const override {
2266 "Op must be an operand of the recipe");
2267 // The recipe creates its own wide start value, so it only requests the
2268 // first lane of the operand.
2269 // TODO: Remove once creating the start value is modeled separately.
2270 return Op == getStartValue() || Op == getStepValue();
2271 }
2272};
2273
2274/// A recipe for handling phi nodes of integer and floating-point inductions,
2275/// producing their vector values. This is an abstract recipe and must be
2276/// converted to concrete recipes before executing.
2278 public VPIRFlags {
2279 TruncInst *Trunc;
2280
2281 // If this recipe is unrolled it will have 2 additional operands.
2282 bool isUnrolled() const { return getNumOperands() == 5; }
2283
2284public:
2286 VPValue *VF, const InductionDescriptor &IndDesc,
2287 const VPIRFlags &Flags, DebugLoc DL)
2288 : VPWidenInductionRecipe(VPRecipeBase::VPWidenIntOrFpInductionSC, IV,
2289 Start, Step, IndDesc, DL),
2290 VPIRFlags(Flags), Trunc(nullptr) {
2291 addOperand(VF);
2292 }
2293
2295 VPValue *VF, const InductionDescriptor &IndDesc,
2296 TruncInst *Trunc, const VPIRFlags &Flags,
2297 DebugLoc DL)
2298 : VPWidenInductionRecipe(VPRecipeBase::VPWidenIntOrFpInductionSC, IV,
2299 Start, Step, IndDesc, DL),
2300 VPIRFlags(Flags), Trunc(Trunc) {
2301 addOperand(VF);
2303 (void)Metadata;
2304 if (Trunc)
2306 assert(Metadata.empty() && "unexpected metadata on Trunc");
2307 }
2308
2310
2316
2317 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenIntOrFpInductionSC)
2318
2319 void execute(VPTransformState &State) override {
2320 llvm_unreachable("cannot execute this recipe, should be expanded via "
2321 "expandVPWidenIntOrFpInductionRecipe");
2322 }
2323
2324 /// Returns the start value of the induction.
2326
2327 /// If the recipe has been unrolled, return the VPValue for the induction
2328 /// increment, otherwise return null.
2330 return isUnrolled() ? getOperand(getNumOperands() - 2) : nullptr;
2331 }
2332
2333 /// Returns the number of incoming values, also number of incoming blocks.
2334 /// Note that at the moment, VPWidenIntOrFpInductionRecipes only have a single
2335 /// incoming value, its start value.
2336 unsigned getNumIncoming() const override { return 1; }
2337
2338 /// Returns the first defined value as TruncInst, if it is one or nullptr
2339 /// otherwise.
2340 TruncInst *getTruncInst() { return Trunc; }
2341 const TruncInst *getTruncInst() const { return Trunc; }
2342
2343 /// Returns true if the induction is canonical, i.e. starting at 0 and
2344 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
2345 /// same type as the canonical induction.
2346 bool isCanonical() const;
2347
2348 /// Returns the scalar type of the induction.
2350 return Trunc ? Trunc->getType() : getStartValue()->getType();
2351 }
2352
2353 /// Returns the VPValue representing the value of this induction at
2354 /// the last unrolled part, if it exists. Returns itself if unrolling did not
2355 /// take place.
2357 return isUnrolled() ? getOperand(getNumOperands() - 1) : this;
2358 }
2359
2360protected:
2361#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2362 /// Print the recipe.
2363 void printRecipe(raw_ostream &O, const Twine &Indent,
2364 VPSlotTracker &SlotTracker) const override;
2365#endif
2366};
2367
2369public:
2370 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2371 /// Start and the number of elements unrolled \p NumUnrolledElems, typically
2372 /// VF*UF.
2374 VPValue *NumUnrolledElems,
2375 const InductionDescriptor &IndDesc, DebugLoc DL)
2376 : VPWidenInductionRecipe(VPRecipeBase::VPWidenPointerInductionSC, Phi,
2377 Start, Step, IndDesc, DL) {
2378 addOperand(NumUnrolledElems);
2379 }
2380
2382
2388
2389 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenPointerInductionSC)
2390
2391 /// Generate vector values for the pointer induction.
2392 void execute(VPTransformState &State) override {
2393 llvm_unreachable("cannot execute this recipe, should be expanded via "
2394 "expandVPWidenPointerInduction");
2395 };
2396
2397 /// Returns true if only scalar values will be generated.
2398 bool onlyScalarsGenerated(bool IsScalable);
2399
2400protected:
2401#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2402 /// Print the recipe.
2403 void printRecipe(raw_ostream &O, const Twine &Indent,
2404 VPSlotTracker &SlotTracker) const override;
2405#endif
2406};
2407
2408/// A recipe for widened phis. Incoming values are operands of the recipe and
2409/// their operand index corresponds to the incoming predecessor block. If the
2410/// recipe is placed in an entry block to a (non-replicate) region, it must have
2411/// exactly 2 incoming values, the first from the predecessor of the region and
2412/// the second from the exiting block of the region.
2414 public VPPhiAccessors {
2415 /// Name to use for the generated IR instruction for the widened phi.
2416 std::string Name;
2417
2418public:
2419 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
2420 /// debug location \p DL.
2421 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
2422 DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "")
2423 : VPSingleDefRecipe(VPRecipeBase::VPWidenPHISC, {}, Phi, DL),
2424 Name(Name.str()) {
2425 if (Start)
2426 addOperand(Start);
2427 }
2428
2431 getOperand(0), getDebugLoc(), Name);
2433 C->addOperand(Op);
2434 return C;
2435 }
2436
2437 ~VPWidenPHIRecipe() override = default;
2438
2439 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenPHISC)
2440
2441 /// Generate the phi/select nodes.
2442 void execute(VPTransformState &State) override;
2443
2444 /// Return the cost of this VPWidenPHIRecipe.
2446 VPCostContext &Ctx) const override;
2447
2448protected:
2449#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2450 /// Print the recipe.
2451 void printRecipe(raw_ostream &O, const Twine &Indent,
2452 VPSlotTracker &SlotTracker) const override;
2453#endif
2454
2455 const VPRecipeBase *getAsRecipe() const override { return this; }
2456};
2457
2458/// A recipe for handling first-order recurrence phis. The start value is the
2459/// first operand of the recipe and the incoming value from the backedge is the
2460/// second operand.
2463 VPValue &BackedgeValue)
2464 : VPHeaderPHIRecipe(VPRecipeBase::VPFirstOrderRecurrencePHISC, Phi,
2465 &Start) {
2466 addOperand(&BackedgeValue);
2467 }
2468
2469 VP_CLASSOF_IMPL(VPRecipeBase::VPFirstOrderRecurrencePHISC)
2470
2475
2476 void execute(VPTransformState &State) override;
2477
2478 /// Return the cost of this first-order recurrence phi recipe.
2480 VPCostContext &Ctx) const override;
2481
2482 /// Returns true if the recipe only uses the first lane of operand \p Op.
2483 bool usesFirstLaneOnly(const VPValue *Op) const override {
2485 "Op must be an operand of the recipe");
2486 return Op == getStartValue();
2487 }
2488
2489protected:
2490#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2491 /// Print the recipe.
2492 void printRecipe(raw_ostream &O, const Twine &Indent,
2493 VPSlotTracker &SlotTracker) const override;
2494#endif
2495};
2496
2497/// Possible variants of a reduction.
2498
2499/// This reduction is ordered and in-loop.
2500struct RdxOrdered {};
2501/// This reduction is in-loop.
2502struct RdxInLoop {};
2503/// This reduction is unordered with the partial result scaled down by some
2504/// factor.
2507};
2508using ReductionStyle = std::variant<RdxOrdered, RdxInLoop, RdxUnordered>;
2509
2510inline ReductionStyle getReductionStyle(bool InLoop, bool Ordered,
2511 unsigned ScaleFactor) {
2512 assert((!Ordered || InLoop) && "Ordered implies in-loop");
2513 if (Ordered)
2514 return RdxOrdered{};
2515 if (InLoop)
2516 return RdxInLoop{};
2517 return RdxUnordered{/*VFScaleFactor=*/ScaleFactor};
2518}
2519
2520/// A recipe for handling reduction phis. The start value is the first operand
2521/// of the recipe and the incoming value from the backedge is the second
2522/// operand.
2524 public VPUnrollPartAccessor<2> {
2525 /// The recurrence kind of the reduction.
2526 const RecurKind Kind;
2527
2528 ReductionStyle Style;
2529
2530 /// The phi is part of a multi-use reduction (e.g., used in FindLastIV
2531 /// patterns for argmin/argmax).
2532 /// TODO: Also support cases where the phi itself has a single use, but its
2533 /// compare has multiple uses.
2534 bool HasUsesOutsideReductionChain;
2535
2536public:
2537 /// Create a new VPReductionPHIRecipe for the reduction \p Phi.
2539 VPValue &BackedgeValue, ReductionStyle Style,
2540 bool HasUsesOutsideReductionChain = false)
2541 : VPHeaderPHIRecipe(VPRecipeBase::VPReductionPHISC, Phi, &Start),
2542 Kind(Kind), Style(Style),
2543 HasUsesOutsideReductionChain(HasUsesOutsideReductionChain) {
2544 addOperand(&BackedgeValue);
2545 }
2546
2547 ~VPReductionPHIRecipe() override = default;
2548
2550 return new VPReductionPHIRecipe(
2552 *getOperand(0), *getBackedgeValue(), Style,
2553 HasUsesOutsideReductionChain);
2554 }
2555
2556 VP_CLASSOF_IMPL(VPRecipeBase::VPReductionPHISC)
2557
2558 /// Generate the phi/select nodes.
2559 void execute(VPTransformState &State) override;
2560
2561 /// Get the factor that the VF of this recipe's output should be scaled by, or
2562 /// 1 if it isn't scaled.
2563 unsigned getVFScaleFactor() const {
2564 auto *Partial = std::get_if<RdxUnordered>(&Style);
2565 return Partial ? Partial->VFScaleFactor : 1;
2566 }
2567
2568 /// Set the VFScaleFactor for this reduction phi. Can only be set to a factor
2569 /// > 1.
2570 void setVFScaleFactor(unsigned ScaleFactor) {
2571 assert(ScaleFactor > 1 && "must set to scale factor > 1");
2572 Style = RdxUnordered{ScaleFactor};
2573 }
2574
2575 /// Returns the number of incoming values, also number of incoming blocks.
2576 /// Note that at the moment, VPWidenPointerInductionRecipe only has a single
2577 /// incoming value, its start value.
2578 unsigned getNumIncoming() const override { return 2; }
2579
2580 /// Returns the recurrence kind of the reduction.
2581 RecurKind getRecurrenceKind() const { return Kind; }
2582
2583 /// Returns true, if the phi is part of an ordered reduction.
2584 bool isOrdered() const { return std::holds_alternative<RdxOrdered>(Style); }
2585
2586 /// Returns true if the phi is part of an in-loop reduction.
2587 bool isInLoop() const {
2588 return std::holds_alternative<RdxInLoop>(Style) ||
2589 std::holds_alternative<RdxOrdered>(Style);
2590 }
2591
2592 /// Returns true if the reduction outputs a vector with a scaled down VF.
2593 bool isPartialReduction() const { return getVFScaleFactor() > 1; }
2594
2595 /// Returns true, if the phi is part of a multi-use reduction.
2597 return HasUsesOutsideReductionChain;
2598 }
2599
2600 /// Returns true if the recipe only uses the first lane of operand \p Op.
2601 bool usesFirstLaneOnly(const VPValue *Op) const override {
2603 "Op must be an operand of the recipe");
2604 return isOrdered() || isInLoop();
2605 }
2606
2607protected:
2608#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2609 /// Print the recipe.
2610 void printRecipe(raw_ostream &O, const Twine &Indent,
2611 VPSlotTracker &SlotTracker) const override;
2612#endif
2613};
2614
2615/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2616/// instructions.
2618public:
2619 /// The blend operation is a User of the incoming values and of their
2620 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2621 /// be omitted (implied by passing an odd number of operands) in which case
2622 /// all other incoming values are merged into it.
2624 : VPSingleDefRecipe(VPRecipeBase::VPBlendSC, Operands, Phi, DL) {
2625 assert(Operands.size() >= 2 && "Expected at least two operands!");
2626 }
2627
2632
2633 VP_CLASSOF_IMPL(VPRecipeBase::VPBlendSC)
2634
2635 /// A normalized blend is one that has an odd number of operands, whereby the
2636 /// first operand does not have an associated mask.
2637 bool isNormalized() const { return getNumOperands() % 2; }
2638
2639 /// Return the number of incoming values, taking into account when normalized
2640 /// the first incoming value will have no mask.
2641 unsigned getNumIncomingValues() const {
2642 return (getNumOperands() + isNormalized()) / 2;
2643 }
2644
2645 /// Return incoming value number \p Idx.
2646 VPValue *getIncomingValue(unsigned Idx) const {
2647 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2648 }
2649
2650 /// Return mask number \p Idx.
2651 VPValue *getMask(unsigned Idx) const {
2652 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2653 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2654 }
2655
2656 /// Set mask number \p Idx to \p V.
2657 void setMask(unsigned Idx, VPValue *V) {
2658 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2659 Idx == 0 ? setOperand(1, V) : setOperand(Idx * 2 + !isNormalized(), V);
2660 }
2661
2662 void execute(VPTransformState &State) override {
2663 llvm_unreachable("VPBlendRecipe should be expanded by simplifyBlends");
2664 }
2665
2666 /// Return the cost of this VPWidenMemoryRecipe.
2667 InstructionCost computeCost(ElementCount VF,
2668 VPCostContext &Ctx) const override;
2669
2670 /// Returns true if the recipe only uses the first lane of operand \p Op.
2671 bool usesFirstLaneOnly(const VPValue *Op) const override {
2673 "Op must be an operand of the recipe");
2674 // Recursing through Blend recipes only, must terminate at header phi's the
2675 // latest.
2676 return all_of(users(),
2677 [this](VPUser *U) { return U->usesFirstLaneOnly(this); });
2678 }
2679
2680protected:
2681#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2682 /// Print the recipe.
2683 void printRecipe(raw_ostream &O, const Twine &Indent,
2684 VPSlotTracker &SlotTracker) const override;
2685#endif
2686};
2687
2688/// A common base class for interleaved memory operations.
2689/// An Interleaved memory operation is a memory access method that combines
2690/// multiple strided loads/stores into a single wide load/store with shuffles.
2691/// The first operand is the start address. The optional operands are, in order,
2692/// the stored values and the mask.
2694 public VPIRMetadata {
2696
2697 /// Indicates if the interleave group is in a conditional block and requires a
2698 /// mask.
2699 bool HasMask = false;
2700
2701 /// Indicates if gaps between members of the group need to be masked out or if
2702 /// unusued gaps can be loaded speculatively.
2703 bool NeedsMaskForGaps = false;
2704
2705protected:
2706 VPInterleaveBase(const unsigned char SC,
2708 ArrayRef<VPValue *> Operands,
2709 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2710 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2711 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(MD), IG(IG),
2712 NeedsMaskForGaps(NeedsMaskForGaps) {
2713 // TODO: extend the masked interleaved-group support to reversed access.
2714 assert((!Mask || !IG->isReverse()) &&
2715 "Reversed masked interleave-group not supported.");
2716 if (StoredValues.empty()) {
2717 for (unsigned I = 0; I < IG->getFactor(); ++I)
2718 if (Instruction *Inst = IG->getMember(I)) {
2719 assert(!Inst->getType()->isVoidTy() && "must have result");
2720 new VPRecipeValue(this, Inst);
2721 }
2722 } else {
2723 for (auto *SV : StoredValues)
2724 addOperand(SV);
2725 }
2726 if (Mask) {
2727 HasMask = true;
2728 addOperand(Mask);
2729 }
2730 }
2731
2732public:
2733 VPInterleaveBase *clone() override = 0;
2734
2735 static inline bool classof(const VPRecipeBase *R) {
2736 return R->getVPRecipeID() == VPRecipeBase::VPInterleaveSC ||
2737 R->getVPRecipeID() == VPRecipeBase::VPInterleaveEVLSC;
2738 }
2739
2740 static inline bool classof(const VPUser *U) {
2741 auto *R = dyn_cast<VPRecipeBase>(U);
2742 return R && classof(R);
2743 }
2744
2745 /// Return the address accessed by this recipe.
2746 VPValue *getAddr() const {
2747 return getOperand(0); // Address is the 1st, mandatory operand.
2748 }
2749
2750 /// Return the mask used by this recipe. Note that a full mask is represented
2751 /// by a nullptr.
2752 VPValue *getMask() const {
2753 // Mask is optional and the last operand.
2754 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2755 }
2756
2757 /// Return true if the access needs a mask because of the gaps.
2758 bool needsMaskForGaps() const { return NeedsMaskForGaps; }
2759
2761
2762 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2763
2764 void execute(VPTransformState &State) override {
2765 llvm_unreachable("VPInterleaveBase should not be instantiated.");
2766 }
2767
2768 /// Return the cost of this recipe.
2769 InstructionCost computeCost(ElementCount VF,
2770 VPCostContext &Ctx) const override;
2771
2772 /// Returns true if the recipe only uses the first lane of operand \p Op.
2773 bool usesFirstLaneOnly(const VPValue *Op) const override = 0;
2774
2775 /// Returns the number of stored operands of this interleave group. Returns 0
2776 /// for load interleave groups.
2777 virtual unsigned getNumStoreOperands() const = 0;
2778
2779 /// Return the VPValues stored by this interleave group. If it is a load
2780 /// interleave group, return an empty ArrayRef.
2782 return ArrayRef<VPValue *>(op_end() -
2783 (getNumStoreOperands() + (HasMask ? 1 : 0)),
2785 }
2786};
2787
2788/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2789/// or stores into one wide load/store and shuffles. The first operand of a
2790/// VPInterleave recipe is the address, followed by the stored values, followed
2791/// by an optional mask.
2793public:
2795 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2796 bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
2797 : VPInterleaveBase(VPRecipeBase::VPInterleaveSC, IG, Addr, StoredValues,
2798 Mask, NeedsMaskForGaps, MD, DL) {}
2799
2800 ~VPInterleaveRecipe() override = default;
2801
2805 needsMaskForGaps(), *this, getDebugLoc());
2806 }
2807
2808 VP_CLASSOF_IMPL(VPRecipeBase::VPInterleaveSC)
2809
2810 /// Generate the wide load or store, and shuffles.
2811 void execute(VPTransformState &State) override;
2812
2813 bool usesFirstLaneOnly(const VPValue *Op) const override {
2815 "Op must be an operand of the recipe");
2816 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2817 }
2818
2819 unsigned getNumStoreOperands() const override {
2820 return getNumOperands() - (getMask() ? 2 : 1);
2821 }
2822
2823protected:
2824#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2825 /// Print the recipe.
2826 void printRecipe(raw_ostream &O, const Twine &Indent,
2827 VPSlotTracker &SlotTracker) const override;
2828#endif
2829};
2830
2831/// A recipe for interleaved memory operations with vector-predication
2832/// intrinsics. The first operand is the address, the second operand is the
2833/// explicit vector length. Stored values and mask are optional operands.
2835public:
2838 VPRecipeBase::VPInterleaveEVLSC, R.getInterleaveGroup(),
2839 ArrayRef<VPValue *>({R.getAddr(), &EVL}), R.getStoredValues(), Mask,
2840 R.needsMaskForGaps(), R, R.getDebugLoc()) {
2841 assert(!getInterleaveGroup()->isReverse() &&
2842 "Reversed interleave-group with tail folding is not supported.");
2843 assert(!needsMaskForGaps() && "Interleaved access with gap mask is not "
2844 "supported for scalable vector.");
2845 }
2846
2847 ~VPInterleaveEVLRecipe() override = default;
2848
2850 llvm_unreachable("cloning not implemented yet");
2851 }
2852
2853 VP_CLASSOF_IMPL(VPRecipeBase::VPInterleaveEVLSC)
2854
2855 /// The VPValue of the explicit vector length.
2856 VPValue *getEVL() const { return getOperand(1); }
2857
2858 /// Generate the wide load or store, and shuffles.
2859 void execute(VPTransformState &State) override;
2860
2861 /// The recipe only uses the first lane of the address, and EVL operand.
2862 bool usesFirstLaneOnly(const VPValue *Op) const override {
2864 "Op must be an operand of the recipe");
2865 return (Op == getAddr() && !llvm::is_contained(getStoredValues(), Op)) ||
2866 Op == getEVL();
2867 }
2868
2869 unsigned getNumStoreOperands() const override {
2870 return getNumOperands() - (getMask() ? 3 : 2);
2871 }
2872
2873protected:
2874#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2875 /// Print the recipe.
2876 void printRecipe(raw_ostream &O, const Twine &Indent,
2877 VPSlotTracker &SlotTracker) const override;
2878#endif
2879};
2880
2881/// A recipe to represent inloop, ordered or partial reduction operations. It
2882/// performs a reduction on a vector operand into a scalar (vector in the case
2883/// of a partial reduction) value, and adds the result to a chain. The Operands
2884/// are {ChainOp, VecOp, [Condition]}.
2886
2887 /// The recurrence kind for the reduction in question.
2888 RecurKind RdxKind;
2889 /// Whether the reduction is conditional.
2890 bool IsConditional = false;
2891 ReductionStyle Style;
2892
2893protected:
2894 VPReductionRecipe(const unsigned char SC, RecurKind RdxKind,
2896 ArrayRef<VPValue *> Operands, VPValue *CondOp,
2897 ReductionStyle Style, DebugLoc DL)
2898 : VPRecipeWithIRFlags(SC, Operands, FMFs, DL), RdxKind(RdxKind),
2899 Style(Style) {
2900 if (CondOp) {
2901 IsConditional = true;
2902 addOperand(CondOp);
2903 }
2905 }
2906
2907public:
2909 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2911 : VPReductionRecipe(VPRecipeBase::VPReductionSC, RdxKind, FMFs, I,
2912 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp, Style,
2913 DL) {}
2914
2916 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2918 : VPReductionRecipe(VPRecipeBase::VPReductionSC, RdxKind, FMFs, nullptr,
2919 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp, Style,
2920 DL) {}
2921
2922 ~VPReductionRecipe() override = default;
2923
2925 return new VPReductionRecipe(RdxKind, getFastMathFlags(),
2927 getCondOp(), Style, getDebugLoc());
2928 }
2929
2930 static inline bool classof(const VPRecipeBase *R) {
2931 return R->getVPRecipeID() == VPRecipeBase::VPReductionSC ||
2932 R->getVPRecipeID() == VPRecipeBase::VPReductionEVLSC;
2933 }
2934
2935 static inline bool classof(const VPUser *U) {
2936 auto *R = dyn_cast<VPRecipeBase>(U);
2937 return R && classof(R);
2938 }
2939
2940 static inline bool classof(const VPValue *VPV) {
2941 const VPRecipeBase *R = VPV->getDefiningRecipe();
2942 return R && classof(R);
2943 }
2944
2945 static inline bool classof(const VPSingleDefRecipe *R) {
2946 return classof(static_cast<const VPRecipeBase *>(R));
2947 }
2948
2949 /// Generate the reduction in the loop.
2950 void execute(VPTransformState &State) override;
2951
2952 /// Return the cost of VPReductionRecipe.
2953 InstructionCost computeCost(ElementCount VF,
2954 VPCostContext &Ctx) const override;
2955
2956 /// Return the recurrence kind for the in-loop reduction.
2957 RecurKind getRecurrenceKind() const { return RdxKind; }
2958 /// Return true if the in-loop reduction is ordered.
2959 bool isOrdered() const { return std::holds_alternative<RdxOrdered>(Style); };
2960 /// Return true if the in-loop reduction is conditional.
2961 bool isConditional() const { return IsConditional; };
2962 /// Returns true if the reduction outputs a vector with a scaled down VF.
2963 bool isPartialReduction() const { return getVFScaleFactor() > 1; }
2964 /// Returns true if the reduction is in-loop.
2965 bool isInLoop() const {
2966 return std::holds_alternative<RdxInLoop>(Style) ||
2967 std::holds_alternative<RdxOrdered>(Style);
2968 }
2969 /// The VPValue of the scalar Chain being accumulated.
2970 VPValue *getChainOp() const { return getOperand(0); }
2971 /// The VPValue of the vector value to be reduced.
2972 VPValue *getVecOp() const { return getOperand(1); }
2973 /// The VPValue of the condition for the block.
2975 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2976 }
2977 /// Get the factor that the VF of this recipe's output should be scaled by, or
2978 /// 1 if it isn't scaled.
2979 unsigned getVFScaleFactor() const {
2980 auto *Partial = std::get_if<RdxUnordered>(&Style);
2981 return Partial ? Partial->VFScaleFactor : 1;
2982 }
2983
2984protected:
2985#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2986 /// Print the recipe.
2987 void printRecipe(raw_ostream &O, const Twine &Indent,
2988 VPSlotTracker &SlotTracker) const override;
2989#endif
2990};
2991
2992/// A recipe to represent inloop reduction operations with vector-predication
2993/// intrinsics, performing a reduction on a vector operand with the explicit
2994/// vector length (EVL) into a scalar value, and adding the result to a chain.
2995/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2997public:
3001 VPRecipeBase::VPReductionEVLSC, R.getRecurrenceKind(),
3002 R.getFastMathFlags(),
3004 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
3005 getReductionStyle(/*InLoop=*/true, R.isOrdered(), 1), DL) {}
3006
3007 ~VPReductionEVLRecipe() override = default;
3008
3010 llvm_unreachable("cloning not implemented yet");
3011 }
3012
3013 VP_CLASSOF_IMPL(VPRecipeBase::VPReductionEVLSC)
3014
3015 /// Generate the reduction in the loop
3016 void execute(VPTransformState &State) override;
3017
3018 /// The VPValue of the explicit vector length.
3019 VPValue *getEVL() const { return getOperand(2); }
3020
3021 /// Returns true if the recipe only uses the first lane of operand \p Op.
3022 bool usesFirstLaneOnly(const VPValue *Op) const override {
3024 "Op must be an operand of the recipe");
3025 return Op == getEVL();
3026 }
3027
3028protected:
3029#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3030 /// Print the recipe.
3031 void printRecipe(raw_ostream &O, const Twine &Indent,
3032 VPSlotTracker &SlotTracker) const override;
3033#endif
3034};
3035
3036/// VPReplicateRecipe replicates a given instruction producing multiple scalar
3037/// copies of the original scalar type, one per lane, instead of producing a
3038/// single copy of widened type for all lanes. If the instruction is known to be
3039/// a single scalar, only one copy, per lane zero, will be generated.
3041 public VPIRMetadata {
3042 /// Indicator if only a single replica per lane is needed.
3043 bool IsSingleScalar;
3044
3045 /// Indicator if the replicas are also predicated.
3046 bool IsPredicated;
3047
3048public:
3050 bool IsSingleScalar, VPValue *Mask = nullptr,
3051 const VPIRFlags &Flags = {}, VPIRMetadata Metadata = {},
3052 DebugLoc DL = DebugLoc::getUnknown())
3053 : VPRecipeWithIRFlags(VPRecipeBase::VPReplicateSC, Operands, Flags, DL),
3054 VPIRMetadata(Metadata), IsSingleScalar(IsSingleScalar),
3055 IsPredicated(Mask) {
3056 setUnderlyingValue(I);
3057 if (Mask)
3058 addOperand(Mask);
3059 }
3060
3061 ~VPReplicateRecipe() override = default;
3062
3064 auto *Copy = new VPReplicateRecipe(
3065 getUnderlyingInstr(), operands(), IsSingleScalar,
3066 isPredicated() ? getMask() : nullptr, *this, *this, getDebugLoc());
3067 Copy->transferFlags(*this);
3068 return Copy;
3069 }
3070
3071 VP_CLASSOF_IMPL(VPRecipeBase::VPReplicateSC)
3072
3073 /// Generate replicas of the desired Ingredient. Replicas will be generated
3074 /// for all parts and lanes unless a specific part and lane are specified in
3075 /// the \p State.
3076 void execute(VPTransformState &State) override;
3077
3078 /// Return the cost of this VPReplicateRecipe.
3079 InstructionCost computeCost(ElementCount VF,
3080 VPCostContext &Ctx) const override;
3081
3082 bool isSingleScalar() const { return IsSingleScalar; }
3083
3084 bool isPredicated() const { return IsPredicated; }
3085
3086 /// Returns true if the recipe only uses the first lane of operand \p Op.
3087 bool usesFirstLaneOnly(const VPValue *Op) const override {
3089 "Op must be an operand of the recipe");
3090 return isSingleScalar();
3091 }
3092
3093 /// Returns true if the recipe uses scalars of operand \p Op.
3094 bool usesScalars(const VPValue *Op) const override {
3096 "Op must be an operand of the recipe");
3097 return true;
3098 }
3099
3100 /// Returns true if the recipe is used by a widened recipe via an intervening
3101 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
3102 /// in a vector.
3103 bool shouldPack() const;
3104
3105 /// Return the mask of a predicated VPReplicateRecipe.
3107 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
3108 return getOperand(getNumOperands() - 1);
3109 }
3110
3111 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
3112
3113protected:
3114#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3115 /// Print the recipe.
3116 void printRecipe(raw_ostream &O, const Twine &Indent,
3117 VPSlotTracker &SlotTracker) const override;
3118#endif
3119};
3120
3121/// A recipe for generating conditional branches on the bits of a mask.
3123public:
3125 : VPRecipeBase(VPRecipeBase::VPBranchOnMaskSC, {BlockInMask}, DL) {}
3126
3129 }
3130
3131 VP_CLASSOF_IMPL(VPRecipeBase::VPBranchOnMaskSC)
3132
3133 /// Generate the extraction of the appropriate bit from the block mask and the
3134 /// conditional branch.
3135 void execute(VPTransformState &State) override;
3136
3137 /// Return the cost of this VPBranchOnMaskRecipe.
3138 InstructionCost computeCost(ElementCount VF,
3139 VPCostContext &Ctx) const override;
3140
3141#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3142 /// Print the recipe.
3143 void printRecipe(raw_ostream &O, const Twine &Indent,
3144 VPSlotTracker &SlotTracker) const override {
3145 O << Indent << "BRANCH-ON-MASK ";
3147 }
3148#endif
3149
3150 /// Returns true if the recipe uses scalars of operand \p Op.
3151 bool usesScalars(const VPValue *Op) const override {
3153 "Op must be an operand of the recipe");
3154 return true;
3155 }
3156};
3157
3158/// A recipe to combine multiple recipes into a single 'expression' recipe,
3159/// which should be considered a single entity for cost-modeling and transforms.
3160/// The recipe needs to be 'decomposed', i.e. replaced by its individual
3161/// expression recipes, before execute. The individual expression recipes are
3162/// completely disconnected from the def-use graph of other recipes not part of
3163/// the expression. Def-use edges between pairs of expression recipes remain
3164/// intact, whereas every edge between an expression recipe and a recipe outside
3165/// the expression is elevated to connect the non-expression recipe with the
3166/// VPExpressionRecipe itself.
3167class VPExpressionRecipe : public VPSingleDefRecipe {
3168 /// Recipes included in this VPExpressionRecipe. This could contain
3169 /// duplicates.
3170 SmallVector<VPSingleDefRecipe *> ExpressionRecipes;
3171
3172 /// Temporary VPValues used for external operands of the expression, i.e.
3173 /// operands not defined by recipes in the expression.
3174 SmallVector<VPValue *> LiveInPlaceholders;
3175
3176 enum class ExpressionTypes {
3177 /// Represents an inloop extended reduction operation, performing a
3178 /// reduction on an extended vector operand into a scalar value, and adding
3179 /// the result to a chain.
3180 ExtendedReduction,
3181 /// Represent an inloop multiply-accumulate reduction, multiplying the
3182 /// extended vector operands, performing a reduction.add on the result, and
3183 /// adding the scalar result to a chain.
3184 ExtMulAccReduction,
3185 /// Represent an inloop multiply-accumulate reduction, multiplying the
3186 /// vector operands, performing a reduction.add on the result, and adding
3187 /// the scalar result to a chain.
3188 MulAccReduction,
3189 /// Represent an inloop multiply-accumulate reduction, multiplying the
3190 /// extended vector operands, negating the multiplication, performing a
3191 /// reduction.add on the result, and adding the scalar result to a chain.
3192 ExtNegatedMulAccReduction,
3193 };
3194
3195 /// Type of the expression.
3196 ExpressionTypes ExpressionType;
3197
3198 /// Construct a new VPExpressionRecipe by internalizing recipes in \p
3199 /// ExpressionRecipes. External operands (i.e. not defined by another recipe
3200 /// in the expression) are replaced by temporary VPValues and the original
3201 /// operands are transferred to the VPExpressionRecipe itself. Clone recipes
3202 /// as needed (excluding last) to ensure they are only used by other recipes
3203 /// in the expression.
3204 VPExpressionRecipe(ExpressionTypes ExpressionType,
3205 ArrayRef<VPSingleDefRecipe *> ExpressionRecipes);
3206
3207public:
3209 : VPExpressionRecipe(ExpressionTypes::ExtendedReduction, {Ext, Red}) {}
3211 : VPExpressionRecipe(ExpressionTypes::MulAccReduction, {Mul, Red}) {}
3214 : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction,
3215 {Ext0, Ext1, Mul, Red}) {}
3218 VPReductionRecipe *Red)
3219 : VPExpressionRecipe(ExpressionTypes::ExtNegatedMulAccReduction,
3220 {Ext0, Ext1, Mul, Sub, Red}) {
3221 assert(Mul->getOpcode() == Instruction::Mul && "Expected a mul");
3222 assert(Red->getRecurrenceKind() == RecurKind::Add &&
3223 "Expected an add reduction");
3224 assert(getNumOperands() >= 3 && "Expected at least three operands");
3225 [[maybe_unused]] auto *SubConst = dyn_cast<VPConstantInt>(getOperand(2));
3226 assert(SubConst && SubConst->isZero() &&
3227 Sub->getOpcode() == Instruction::Sub && "Expected a negating sub");
3228 }
3229
3231 SmallPtrSet<VPSingleDefRecipe *, 4> ExpressionRecipesSeen;
3232 for (auto *R : reverse(ExpressionRecipes)) {
3233 if (ExpressionRecipesSeen.insert(R).second)
3234 delete R;
3235 }
3236 for (VPValue *T : LiveInPlaceholders)
3237 delete T;
3238 }
3239
3240 VP_CLASSOF_IMPL(VPRecipeBase::VPExpressionSC)
3241
3242 VPExpressionRecipe *clone() override {
3243 assert(!ExpressionRecipes.empty() && "empty expressions should be removed");
3244 SmallVector<VPSingleDefRecipe *> NewExpressiondRecipes;
3245 for (auto *R : ExpressionRecipes)
3246 NewExpressiondRecipes.push_back(R->clone());
3247 for (auto *New : NewExpressiondRecipes) {
3248 for (const auto &[Idx, Old] : enumerate(ExpressionRecipes))
3249 New->replaceUsesOfWith(Old, NewExpressiondRecipes[Idx]);
3250 // Update placeholder operands in the cloned recipe to use the external
3251 // operands, to be internalized when the cloned expression is constructed.
3252 for (const auto &[Placeholder, OutsideOp] :
3253 zip(LiveInPlaceholders, operands()))
3254 New->replaceUsesOfWith(Placeholder, OutsideOp);
3255 }
3256 return new VPExpressionRecipe(ExpressionType, NewExpressiondRecipes);
3257 }
3258
3259 /// Return the VPValue to use to infer the result type of the recipe.
3261 unsigned OpIdx =
3262 cast<VPReductionRecipe>(ExpressionRecipes.back())->isConditional() ? 2
3263 : 1;
3264 return getOperand(getNumOperands() - OpIdx);
3265 }
3266
3267 /// Insert the recipes of the expression back into the VPlan, directly before
3268 /// the current recipe. Leaves the expression recipe empty, which must be
3269 /// removed before codegen.
3270 void decompose();
3271
3272 unsigned getVFScaleFactor() const {
3273 auto *PR = dyn_cast<VPReductionRecipe>(ExpressionRecipes.back());
3274 return PR ? PR->getVFScaleFactor() : 1;
3275 }
3276
3277 /// Method for generating code, must not be called as this recipe is abstract.
3278 void execute(VPTransformState &State) override {
3279 llvm_unreachable("recipe must be removed before execute");
3280 }
3281
3283 VPCostContext &Ctx) const override;
3284
3285 /// Returns true if this expression contains recipes that may read from or
3286 /// write to memory.
3287 bool mayReadOrWriteMemory() const;
3288
3289 /// Returns true if this expression contains recipes that may have side
3290 /// effects.
3291 bool mayHaveSideEffects() const;
3292
3293 /// Returns true if the result of this VPExpressionRecipe is a single-scalar.
3294 bool isSingleScalar() const;
3295
3296protected:
3297#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3298 /// Print the recipe.
3299 void printRecipe(raw_ostream &O, const Twine &Indent,
3300 VPSlotTracker &SlotTracker) const override;
3301#endif
3302};
3303
3304/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
3305/// control converges back from a Branch-on-Mask. The phi nodes are needed in
3306/// order to merge values that are set under such a branch and feed their uses.
3307/// The phi nodes can be scalar or vector depending on the users of the value.
3308/// This recipe works in concert with VPBranchOnMaskRecipe.
3310public:
3311 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
3312 /// nodes after merging back from a Branch-on-Mask.
3314 : VPSingleDefRecipe(VPRecipeBase::VPPredInstPHISC, PredV, DL) {}
3315 ~VPPredInstPHIRecipe() override = default;
3316
3318 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
3319 }
3320
3321 VP_CLASSOF_IMPL(VPRecipeBase::VPPredInstPHISC)
3322
3323 /// Generates phi nodes for live-outs (from a replicate region) as needed to
3324 /// retain SSA form.
3325 void execute(VPTransformState &State) override;
3326
3327 /// Return the cost of this VPPredInstPHIRecipe.
3329 VPCostContext &Ctx) const override {
3330 // TODO: Compute accurate cost after retiring the legacy cost model.
3331 return 0;
3332 }
3333
3334 /// Returns true if the recipe uses scalars of operand \p Op.
3335 bool usesScalars(const VPValue *Op) const override {
3337 "Op must be an operand of the recipe");
3338 return true;
3339 }
3340
3341protected:
3342#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3343 /// Print the recipe.
3344 void printRecipe(raw_ostream &O, const Twine &Indent,
3345 VPSlotTracker &SlotTracker) const override;
3346#endif
3347};
3348
3349/// A common base class for widening memory operations. An optional mask can be
3350/// provided as the last operand.
3352 public VPIRMetadata {
3353protected:
3355
3356 /// Alignment information for this memory access.
3358
3359 /// Whether the accessed addresses are consecutive.
3361
3362 /// Whether the consecutive accessed addresses are in reverse order.
3364
3365 /// Whether the memory access is masked.
3366 bool IsMasked = false;
3367
3368 void setMask(VPValue *Mask) {
3369 assert(!IsMasked && "cannot re-set mask");
3370 if (!Mask)
3371 return;
3372 addOperand(Mask);
3373 IsMasked = true;
3374 }
3375
3376 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
3377 std::initializer_list<VPValue *> Operands,
3378 bool Consecutive, bool Reverse,
3379 const VPIRMetadata &Metadata, DebugLoc DL)
3380 : VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
3382 Reverse(Reverse) {
3383 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
3385 "Reversed acccess without VPVectorEndPointerRecipe address?");
3386 }
3387
3388public:
3390 llvm_unreachable("cloning not supported");
3391 }
3392
3393 static inline bool classof(const VPRecipeBase *R) {
3394 return R->getVPRecipeID() == VPRecipeBase::VPWidenLoadSC ||
3395 R->getVPRecipeID() == VPRecipeBase::VPWidenStoreSC ||
3396 R->getVPRecipeID() == VPRecipeBase::VPWidenLoadEVLSC ||
3397 R->getVPRecipeID() == VPRecipeBase::VPWidenStoreEVLSC;
3398 }
3399
3400 static inline bool classof(const VPUser *U) {
3401 auto *R = dyn_cast<VPRecipeBase>(U);
3402 return R && classof(R);
3403 }
3404
3405 /// Return whether the loaded-from / stored-to addresses are consecutive.
3406 bool isConsecutive() const { return Consecutive; }
3407
3408 /// Return whether the consecutive loaded/stored addresses are in reverse
3409 /// order.
3410 bool isReverse() const { return Reverse; }
3411
3412 /// Return the address accessed by this recipe.
3413 VPValue *getAddr() const { return getOperand(0); }
3414
3415 /// Returns true if the recipe is masked.
3416 bool isMasked() const { return IsMasked; }
3417
3418 /// Return the mask used by this recipe. Note that a full mask is represented
3419 /// by a nullptr.
3420 VPValue *getMask() const {
3421 // Mask is optional and therefore the last operand.
3422 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
3423 }
3424
3425 /// Returns the alignment of the memory access.
3426 Align getAlign() const { return Alignment; }
3427
3428 /// Generate the wide load/store.
3429 void execute(VPTransformState &State) override {
3430 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
3431 }
3432
3433 /// Return the cost of this VPWidenMemoryRecipe.
3434 InstructionCost computeCost(ElementCount VF,
3435 VPCostContext &Ctx) const override;
3436
3438};
3439
3440/// A recipe for widening load operations, using the address to load from and an
3441/// optional mask.
3443 public VPRecipeValue {
3445 bool Consecutive, bool Reverse,
3446 const VPIRMetadata &Metadata, DebugLoc DL)
3447 : VPWidenMemoryRecipe(VPRecipeBase::VPWidenLoadSC, Load, {Addr},
3448 Consecutive, Reverse, Metadata, DL),
3449 VPRecipeValue(this, &Load) {
3450 setMask(Mask);
3451 }
3452
3455 getMask(), Consecutive, Reverse, *this,
3456 getDebugLoc());
3457 }
3458
3459 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenLoadSC);
3460
3461 /// Generate a wide load or gather.
3462 void execute(VPTransformState &State) override;
3463
3464 /// Returns true if the recipe only uses the first lane of operand \p Op.
3465 bool usesFirstLaneOnly(const VPValue *Op) const override {
3467 "Op must be an operand of the recipe");
3468 // Widened, consecutive loads operations only demand the first lane of
3469 // their address.
3470 return Op == getAddr() && isConsecutive();
3471 }
3472
3473protected:
3474#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3475 /// Print the recipe.
3476 void printRecipe(raw_ostream &O, const Twine &Indent,
3477 VPSlotTracker &SlotTracker) const override;
3478#endif
3479};
3480
3481/// A recipe for widening load operations with vector-predication intrinsics,
3482/// using the address to load from, the explicit vector length and an optional
3483/// mask.
3485 public VPRecipeValue {
3487 VPValue *Mask)
3488 : VPWidenMemoryRecipe(VPRecipeBase::VPWidenLoadEVLSC, L.getIngredient(),
3489 {Addr, &EVL}, L.isConsecutive(), L.isReverse(), L,
3490 L.getDebugLoc()),
3491 VPRecipeValue(this, &getIngredient()) {
3492 setMask(Mask);
3493 }
3494
3495 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenLoadEVLSC)
3496
3497 /// Return the EVL operand.
3498 VPValue *getEVL() const { return getOperand(1); }
3499
3500 /// Generate the wide load or gather.
3501 LLVM_ABI_FOR_TEST void execute(VPTransformState &State) override;
3502
3503 /// Return the cost of this VPWidenLoadEVLRecipe.
3505 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
3506
3507 /// Returns true if the recipe only uses the first lane of operand \p Op.
3508 bool usesFirstLaneOnly(const VPValue *Op) const override {
3510 "Op must be an operand of the recipe");
3511 // Widened loads only demand the first lane of EVL and consecutive loads
3512 // only demand the first lane of their address.
3513 return Op == getEVL() || (Op == getAddr() && isConsecutive());
3514 }
3515
3516protected:
3517#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3518 /// Print the recipe.
3519 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
3520 VPSlotTracker &SlotTracker) const override;
3521#endif
3522};
3523
3524/// A recipe for widening store operations, using the stored value, the address
3525/// to store to and an optional mask.
3527 VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
3528 VPValue *Mask, bool Consecutive, bool Reverse,
3529 const VPIRMetadata &Metadata, DebugLoc DL)
3530 : VPWidenMemoryRecipe(VPRecipeBase::VPWidenStoreSC, Store,
3531 {Addr, StoredVal}, Consecutive, Reverse, Metadata,
3532 DL) {
3533 setMask(Mask);
3534 }
3535
3541
3542 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenStoreSC);
3543
3544 /// Return the value stored by this recipe.
3545 VPValue *getStoredValue() const { return getOperand(1); }
3546
3547 /// Generate a wide store or scatter.
3548 void execute(VPTransformState &State) override;
3549
3550 /// Returns true if the recipe only uses the first lane of operand \p Op.
3551 bool usesFirstLaneOnly(const VPValue *Op) const override {
3553 "Op must be an operand of the recipe");
3554 // Widened, consecutive stores only demand the first lane of their address,
3555 // unless the same operand is also stored.
3556 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3557 }
3558
3559protected:
3560#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3561 /// Print the recipe.
3562 void printRecipe(raw_ostream &O, const Twine &Indent,
3563 VPSlotTracker &SlotTracker) const override;
3564#endif
3565};
3566
3567/// A recipe for widening store operations with vector-predication intrinsics,
3568/// using the value to store, the address to store to, the explicit vector
3569/// length and an optional mask.
3572 VPValue *StoredVal, VPValue &EVL, VPValue *Mask)
3573 : VPWidenMemoryRecipe(VPRecipeBase::VPWidenStoreEVLSC, S.getIngredient(),
3574 {Addr, StoredVal, &EVL}, S.isConsecutive(),
3575 S.isReverse(), S, S.getDebugLoc()) {
3576 setMask(Mask);
3577 }
3578
3579 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenStoreEVLSC)
3580
3581 /// Return the address accessed by this recipe.
3582 VPValue *getStoredValue() const { return getOperand(1); }
3583
3584 /// Return the EVL operand.
3585 VPValue *getEVL() const { return getOperand(2); }
3586
3587 /// Generate the wide store or scatter.
3588 LLVM_ABI_FOR_TEST void execute(VPTransformState &State) override;
3589
3590 /// Return the cost of this VPWidenStoreEVLRecipe.
3592 computeCost(ElementCount VF, VPCostContext &Ctx) const override;
3593
3594 /// Returns true if the recipe only uses the first lane of operand \p Op.
3595 bool usesFirstLaneOnly(const VPValue *Op) const override {
3597 "Op must be an operand of the recipe");
3598 if (Op == getEVL()) {
3599 assert(getStoredValue() != Op && "unexpected store of EVL");
3600 return true;
3601 }
3602 // Widened, consecutive memory operations only demand the first lane of
3603 // their address, unless the same operand is also stored. That latter can
3604 // happen with opaque pointers.
3605 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3606 }
3607
3608protected:
3609#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3610 /// Print the recipe.
3611 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
3612 VPSlotTracker &SlotTracker) const override;
3613#endif
3614};
3615
3616/// Recipe to expand a SCEV expression.
3618 const SCEV *Expr;
3619
3620public:
3622 : VPSingleDefRecipe(VPRecipeBase::VPExpandSCEVSC, {}), Expr(Expr) {}
3623
3624 ~VPExpandSCEVRecipe() override = default;
3625
3626 VPExpandSCEVRecipe *clone() override { return new VPExpandSCEVRecipe(Expr); }
3627
3628 VP_CLASSOF_IMPL(VPRecipeBase::VPExpandSCEVSC)
3629
3630 void execute(VPTransformState &State) override {
3631 llvm_unreachable("SCEV expressions must be expanded before final execute");
3632 }
3633
3634 /// Return the cost of this VPExpandSCEVRecipe.
3636 VPCostContext &Ctx) const override {
3637 // TODO: Compute accurate cost after retiring the legacy cost model.
3638 return 0;
3639 }
3640
3641 const SCEV *getSCEV() const { return Expr; }
3642
3643protected:
3644#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3645 /// Print the recipe.
3646 void printRecipe(raw_ostream &O, const Twine &Indent,
3647 VPSlotTracker &SlotTracker) const override;
3648#endif
3649};
3650
3651/// Canonical scalar induction phi of the vector loop. Starting at the specified
3652/// start value (either 0 or the resume value when vectorizing the epilogue
3653/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
3654/// canonical induction variable.
3656public:
3658 : VPHeaderPHIRecipe(VPRecipeBase::VPCanonicalIVPHISC, nullptr, StartV,
3659 DL) {}
3660
3661 ~VPCanonicalIVPHIRecipe() override = default;
3662
3665 R->addOperand(getBackedgeValue());
3666 return R;
3667 }
3668
3669 VP_CLASSOF_IMPL(VPRecipeBase::VPCanonicalIVPHISC)
3670
3671 void execute(VPTransformState &State) override {
3672 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3673 "scalar phi recipe");
3674 }
3675
3676 /// Returns the start value of the canonical induction.
3678
3679 /// Returns the scalar type of the induction.
3680 Type *getScalarType() const { return getStartValue()->getType(); }
3681
3682 /// Returns true if the recipe only uses the first lane of operand \p Op.
3683 bool usesFirstLaneOnly(const VPValue *Op) const override {
3685 "Op must be an operand of the recipe");
3686 return true;
3687 }
3688
3689 /// Returns true if the recipe only uses the first part of operand \p Op.
3690 bool usesFirstPartOnly(const VPValue *Op) const override {
3692 "Op must be an operand of the recipe");
3693 return true;
3694 }
3695
3696 /// Return the cost of this VPCanonicalIVPHIRecipe.
3698 VPCostContext &Ctx) const override {
3699 // For now, match the behavior of the legacy cost model.
3700 return 0;
3701 }
3702
3703protected:
3704#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3705 /// Print the recipe.
3706 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
3707 VPSlotTracker &SlotTracker) const override;
3708#endif
3709};
3710
3711/// A recipe for generating the active lane mask for the vector loop that is
3712/// used to predicate the vector operations.
3714public:
3716 : VPHeaderPHIRecipe(VPRecipeBase::VPActiveLaneMaskPHISC, nullptr,
3717 StartMask, DL) {}
3718
3719 ~VPActiveLaneMaskPHIRecipe() override = default;
3720
3723 if (getNumOperands() == 2)
3724 R->addOperand(getOperand(1));
3725 return R;
3726 }
3727
3728 VP_CLASSOF_IMPL(VPRecipeBase::VPActiveLaneMaskPHISC)
3729
3730 /// Generate the active lane mask phi of the vector loop.
3731 void execute(VPTransformState &State) override;
3732
3733protected:
3734#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3735 /// Print the recipe.
3736 void printRecipe(raw_ostream &O, const Twine &Indent,
3737 VPSlotTracker &SlotTracker) const override;
3738#endif
3739};
3740
3741/// A recipe for generating the phi node for the current index of elements,
3742/// adjusted in accordance with EVL value. It starts at the start value of the
3743/// canonical induction and gets incremented by EVL in each iteration of the
3744/// vector loop.
3746public:
3748 : VPHeaderPHIRecipe(VPRecipeBase::VPEVLBasedIVPHISC, nullptr, StartIV,
3749 DL) {}
3750
3751 ~VPEVLBasedIVPHIRecipe() override = default;
3752
3754 llvm_unreachable("cloning not implemented yet");
3755 }
3756
3757 VP_CLASSOF_IMPL(VPRecipeBase::VPEVLBasedIVPHISC)
3758
3759 void execute(VPTransformState &State) override {
3760 llvm_unreachable("cannot execute this recipe, should be replaced by a "
3761 "scalar phi recipe");
3762 }
3763
3764 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3766 VPCostContext &Ctx) const override {
3767 // For now, match the behavior of the legacy cost model.
3768 return 0;
3769 }
3770
3771 /// Returns true if the recipe only uses the first lane of operand \p Op.
3772 bool usesFirstLaneOnly(const VPValue *Op) const override {
3774 "Op must be an operand of the recipe");
3775 return true;
3776 }
3777
3778protected:
3779#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3780 /// Print the recipe.
3781 LLVM_ABI_FOR_TEST void printRecipe(raw_ostream &O, const Twine &Indent,
3782 VPSlotTracker &SlotTracker) const override;
3783#endif
3784};
3785
3786/// A Recipe for widening the canonical induction variable of the vector loop.
3788 public VPUnrollPartAccessor<1> {
3789public:
3791 : VPSingleDefRecipe(VPRecipeBase::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3792
3793 ~VPWidenCanonicalIVRecipe() override = default;
3794
3799
3800 VP_CLASSOF_IMPL(VPRecipeBase::VPWidenCanonicalIVSC)
3801
3802 /// Generate a canonical vector induction variable of the vector loop, with
3803 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3804 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3805 void execute(VPTransformState &State) override;
3806
3807 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3809 VPCostContext &Ctx) const override {
3810 // TODO: Compute accurate cost after retiring the legacy cost model.
3811 return 0;
3812 }
3813
3814protected:
3815#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3816 /// Print the recipe.
3817 void printRecipe(raw_ostream &O, const Twine &Indent,
3818 VPSlotTracker &SlotTracker) const override;
3819#endif
3820};
3821
3822/// A recipe for converting the input value \p IV value to the corresponding
3823/// value of an IV with different start and step values, using Start + IV *
3824/// Step.
3826 /// Kind of the induction.
3828 /// If not nullptr, the floating point induction binary operator. Must be set
3829 /// for floating point inductions.
3830 const FPMathOperator *FPBinOp;
3831
3832 /// Name to use for the generated IR instruction for the derived IV.
3833 std::string Name;
3834
3835public:
3837 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3838 const Twine &Name = "")
3840 IndDesc.getKind(),
3841 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3842 Start, CanonicalIV, Step, Name) {}
3843
3845 const FPMathOperator *FPBinOp, VPIRValue *Start,
3846 VPValue *IV, VPValue *Step, const Twine &Name = "")
3847 : VPSingleDefRecipe(VPRecipeBase::VPDerivedIVSC, {Start, IV, Step}),
3848 Kind(Kind), FPBinOp(FPBinOp), Name(Name.str()) {}
3849
3850 ~VPDerivedIVRecipe() override = default;
3851
3853 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3854 getStepValue());
3855 }
3856
3857 VP_CLASSOF_IMPL(VPRecipeBase::VPDerivedIVSC)
3858
3859 /// Generate the transformed value of the induction at offset StartValue (1.
3860 /// operand) + IV (2. operand) * StepValue (3, operand).
3861 void execute(VPTransformState &State) override;
3862
3863 /// Return the cost of this VPDerivedIVRecipe.
3865 VPCostContext &Ctx) const override {
3866 // TODO: Compute accurate cost after retiring the legacy cost model.
3867 return 0;
3868 }
3869
3870 Type *getScalarType() const { return getStartValue()->getType(); }
3871
3873 VPValue *getStepValue() const { return getOperand(2); }
3874
3875 /// Returns true if the recipe only uses the first lane of operand \p Op.
3876 bool usesFirstLaneOnly(const VPValue *Op) const override {
3878 "Op must be an operand of the recipe");
3879 return true;
3880 }
3881
3882protected:
3883#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3884 /// Print the recipe.
3885 void printRecipe(raw_ostream &O, const Twine &Indent,
3886 VPSlotTracker &SlotTracker) const override;
3887#endif
3888};
3889
3890/// A recipe for handling phi nodes of integer and floating-point inductions,
3891/// producing their scalar values. Before unrolling by UF the recipe represents
3892/// the VF*UF scalar values to be produced, or UF scalar values if only first
3893/// lane is used, and has 3 operands: IV, step and VF. Unrolling adds one extra
3894/// operand StartIndex to all unroll parts except part 0, as the recipe
3895/// represents the VF scalar values (this number of values is taken from
3896/// State.VF rather than from the VF operand) starting at IV + StartIndex.
3898 Instruction::BinaryOps InductionOpcode;
3899
3900public:
3903 DebugLoc DL)
3904 : VPRecipeWithIRFlags(VPRecipeBase::VPScalarIVStepsSC,
3905 ArrayRef<VPValue *>({IV, Step, VF}), FMFs, DL),
3906 InductionOpcode(Opcode) {}
3907
3909 VPValue *Step, VPValue *VF,
3912 IV, Step, VF, IndDesc.getInductionOpcode(),
3913 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3914 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3915 : FastMathFlags(),
3916 DL) {}
3917
3918 ~VPScalarIVStepsRecipe() override = default;
3919
3921 return new VPScalarIVStepsRecipe(
3922 getOperand(0), getOperand(1), getOperand(2), InductionOpcode,
3924 getDebugLoc());
3925 }
3926
3927 VP_CLASSOF_IMPL(VPRecipeBase::VPScalarIVStepsSC)
3928
3929 /// Generate the scalarized versions of the phi node as needed by their users.
3930 void execute(VPTransformState &State) override;
3931
3932 /// Return the cost of this VPScalarIVStepsRecipe.
3934 VPCostContext &Ctx) const override {
3935 // TODO: Compute accurate cost after retiring the legacy cost model.
3936 return 0;
3937 }
3938
3939 VPValue *getStepValue() const { return getOperand(1); }
3940
3941 /// Return the number of scalars to produce per unroll part, used to compute
3942 /// StartIndex during unrolling.
3943 VPValue *getVFValue() const { return getOperand(2); }
3944
3945 /// Return the StartIndex, or null if known to be zero, valid only after
3946 /// unrolling.
3948 return getNumOperands() == 4 ? getOperand(3) : nullptr;
3949 }
3950
3951 /// Returns true if the recipe only uses the first lane of operand \p Op.
3952 bool usesFirstLaneOnly(const VPValue *Op) const override {
3954 "Op must be an operand of the recipe");
3955 return true;
3956 }
3957
3958protected:
3959#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3960 /// Print the recipe.
3961 void printRecipe(raw_ostream &O, const Twine &Indent,
3962 VPSlotTracker &SlotTracker) const override;
3963#endif
3964};
3965
3966/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
3967/// types implementing VPPhiAccessors. Used by isa<> & co.
3969 static inline bool isPossible(const VPRecipeBase *f) {
3970 // TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
3972 }
3973};
3974/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
3975/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
3976template <typename SrcTy>
3977struct CastInfoVPPhiAccessors : public CastIsPossible<VPPhiAccessors, SrcTy> {
3978
3980
3981 /// doCast is used by cast<>.
3982 static inline VPPhiAccessors *doCast(SrcTy R) {
3983 return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
3984 switch (R->getVPRecipeID()) {
3985 case VPRecipeBase::VPInstructionSC:
3986 return cast<VPPhi>(R);
3987 case VPRecipeBase::VPIRInstructionSC:
3988 return cast<VPIRPhi>(R);
3989 case VPRecipeBase::VPWidenPHISC:
3990 return cast<VPWidenPHIRecipe>(R);
3991 default:
3992 return cast<VPHeaderPHIRecipe>(R);
3993 }
3994 }());
3995 }
3996
3997 /// doCastIfPossible is used by dyn_cast<>.
3998 static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
3999 if (!Self::isPossible(f))
4000 return nullptr;
4001 return doCast(f);
4002 }
4003};
4004template <>
4007template <>
4010
4011/// Casting from (const) VPRecipeBase -> (const) VPIRMetadata is supported for
4012/// all recipe types implementing VPIRMetadata. Used by isa<> & co.
4013namespace detail {
4014template <typename DstTy, typename RecipeBasePtrTy>
4015static inline auto castToVPIRMetadata(RecipeBasePtrTy R) -> DstTy {
4016 switch (R->getVPRecipeID()) {
4017 case VPRecipeBase::VPInstructionSC:
4018 return cast<VPInstruction>(R);
4019 case VPRecipeBase::VPWidenSC:
4020 return cast<VPWidenRecipe>(R);
4021 case VPRecipeBase::VPWidenCastSC:
4022 return cast<VPWidenCastRecipe>(R);
4023 case VPRecipeBase::VPWidenIntrinsicSC:
4025 case VPRecipeBase::VPWidenCallSC:
4026 return cast<VPWidenCallRecipe>(R);
4027 case VPRecipeBase::VPReplicateSC:
4028 return cast<VPReplicateRecipe>(R);
4029 case VPRecipeBase::VPInterleaveSC:
4030 case VPRecipeBase::VPInterleaveEVLSC:
4031 return cast<VPInterleaveBase>(R);
4032 case VPRecipeBase::VPWidenLoadSC:
4033 case VPRecipeBase::VPWidenLoadEVLSC:
4034 case VPRecipeBase::VPWidenStoreSC:
4035 case VPRecipeBase::VPWidenStoreEVLSC:
4036 return cast<VPWidenMemoryRecipe>(R);
4037 default:
4038 llvm_unreachable("invalid recipe for VPIRMetadata cast");
4039 }
4040}
4041} // namespace detail
4042
4043/// Support casting from VPRecipeBase -> VPIRMetadata, by down-casting to the
4044/// recipe types implementing VPIRMetadata. Used by cast<>, dyn_cast<> & co.
4045template <typename DstTy, typename SrcTy>
4046struct CastInfoVPIRMetadata : public CastIsPossible<DstTy, SrcTy> {
4047 static inline bool isPossible(SrcTy R) {
4048 // NOTE: Each recipe inheriting from VPIRMetadata must be listed here and
4049 // also handled in castToVPIRMetadata.
4054 R);
4055 }
4056
4057 using RetTy = DstTy *;
4058
4059 /// doCast is used by cast<>.
4060 static inline RetTy doCast(SrcTy R) {
4062 }
4063
4064 /// doCastIfPossible is used by dyn_cast<>.
4065 static inline RetTy doCastIfPossible(SrcTy R) {
4066 if (!isPossible(R))
4067 return nullptr;
4068 return doCast(R);
4069 }
4070};
4071template <>
4074template <>
4077
4078/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
4079/// holds a sequence of zero or more VPRecipe's each representing a sequence of
4080/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
4081class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
4082 friend class VPlan;
4083
4084 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
4085 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
4086 : VPBlockBase(VPBasicBlockSC, Name.str()) {
4087 if (Recipe)
4088 appendRecipe(Recipe);
4089 }
4090
4091public:
4093
4094protected:
4095 /// The VPRecipes held in the order of output instructions to generate.
4097
4098 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
4099 : VPBlockBase(BlockSC, Name.str()) {}
4100
4101public:
4102 ~VPBasicBlock() override {
4103 while (!Recipes.empty())
4104 Recipes.pop_back();
4105 }
4106
4107 /// Instruction iterators...
4112
4113 //===--------------------------------------------------------------------===//
4114 /// Recipe iterator methods
4115 ///
4116 inline iterator begin() { return Recipes.begin(); }
4117 inline const_iterator begin() const { return Recipes.begin(); }
4118 inline iterator end() { return Recipes.end(); }
4119 inline const_iterator end() const { return Recipes.end(); }
4120
4121 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
4122 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
4123 inline reverse_iterator rend() { return Recipes.rend(); }
4124 inline const_reverse_iterator rend() const { return Recipes.rend(); }
4125
4126 inline size_t size() const { return Recipes.size(); }
4127 inline bool empty() const { return Recipes.empty(); }
4128 inline const VPRecipeBase &front() const { return Recipes.front(); }
4129 inline VPRecipeBase &front() { return Recipes.front(); }
4130 inline const VPRecipeBase &back() const { return Recipes.back(); }
4131 inline VPRecipeBase &back() { return Recipes.back(); }
4132
4133 /// Returns a reference to the list of recipes.
4135
4136 /// Returns a pointer to a member of the recipe list.
4137 static RecipeListTy VPBasicBlock::*getSublistAccess(VPRecipeBase *) {
4138 return &VPBasicBlock::Recipes;
4139 }
4140
4141 /// Method to support type inquiry through isa, cast, and dyn_cast.
4142 static inline bool classof(const VPBlockBase *V) {
4143 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
4144 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
4145 }
4146
4147 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
4148 assert(Recipe && "No recipe to append.");
4149 assert(!Recipe->Parent && "Recipe already in VPlan");
4150 Recipe->Parent = this;
4151 Recipes.insert(InsertPt, Recipe);
4152 }
4153
4154 /// Augment the existing recipes of a VPBasicBlock with an additional
4155 /// \p Recipe as the last recipe.
4156 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
4157
4158 /// The method which generates the output IR instructions that correspond to
4159 /// this VPBasicBlock, thereby "executing" the VPlan.
4160 void execute(VPTransformState *State) override;
4161
4162 /// Return the cost of this VPBasicBlock.
4163 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
4164
4165 /// Return the position of the first non-phi node recipe in the block.
4166 iterator getFirstNonPhi();
4167
4168 /// Returns an iterator range over the PHI-like recipes in the block.
4172
4173 /// Split current block at \p SplitAt by inserting a new block between the
4174 /// current block and its successors and moving all recipes starting at
4175 /// SplitAt to the new block. Returns the new block.
4176 VPBasicBlock *splitAt(iterator SplitAt);
4177
4178 VPRegionBlock *getEnclosingLoopRegion();
4179 const VPRegionBlock *getEnclosingLoopRegion() const;
4180
4181#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4182 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
4183 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
4184 ///
4185 /// Note that the numbering is applied to the whole VPlan, so printing
4186 /// individual blocks is consistent with the whole VPlan printing.
4187 void print(raw_ostream &O, const Twine &Indent,
4188 VPSlotTracker &SlotTracker) const override;
4189 using VPBlockBase::print; // Get the print(raw_stream &O) version.
4190#endif
4191
4192 /// If the block has multiple successors, return the branch recipe terminating
4193 /// the block. If there are no or only a single successor, return nullptr;
4194 VPRecipeBase *getTerminator();
4195 const VPRecipeBase *getTerminator() const;
4196
4197 /// Returns true if the block is exiting it's parent region.
4198 bool isExiting() const;
4199
4200 /// Clone the current block and it's recipes, without updating the operands of
4201 /// the cloned recipes.
4202 VPBasicBlock *clone() override;
4203
4204 /// Returns the predecessor block at index \p Idx with the predecessors as per
4205 /// the corresponding plain CFG. If the block is an entry block to a region,
4206 /// the first predecessor is the single predecessor of a region, and the
4207 /// second predecessor is the exiting block of the region.
4208 const VPBasicBlock *getCFGPredecessor(unsigned Idx) const;
4209
4210protected:
4211 /// Execute the recipes in the IR basic block \p BB.
4212 void executeRecipes(VPTransformState *State, BasicBlock *BB);
4213
4214 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
4215 /// generated for this VPBB.
4216 void connectToPredecessors(VPTransformState &State);
4217
4218private:
4219 /// Create an IR BasicBlock to hold the output instructions generated by this
4220 /// VPBasicBlock, and return it. Update the CFGState accordingly.
4221 BasicBlock *createEmptyBasicBlock(VPTransformState &State);
4222};
4223
4224inline const VPBasicBlock *
4226 return getAsRecipe()->getParent()->getCFGPredecessor(Idx);
4227}
4228
4229/// A special type of VPBasicBlock that wraps an existing IR basic block.
4230/// Recipes of the block get added before the first non-phi instruction in the
4231/// wrapped block.
4232/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
4233/// preheader block.
4234class VPIRBasicBlock : public VPBasicBlock {
4235 friend class VPlan;
4236
4237 BasicBlock *IRBB;
4238
4239 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
4240 VPIRBasicBlock(BasicBlock *IRBB)
4241 : VPBasicBlock(VPIRBasicBlockSC,
4242 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
4243 IRBB(IRBB) {}
4244
4245public:
4246 ~VPIRBasicBlock() override = default;
4247
4248 static inline bool classof(const VPBlockBase *V) {
4249 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
4250 }
4251
4252 /// The method which generates the output IR instructions that correspond to
4253 /// this VPBasicBlock, thereby "executing" the VPlan.
4254 void execute(VPTransformState *State) override;
4255
4256 VPIRBasicBlock *clone() override;
4257
4258 BasicBlock *getIRBasicBlock() const { return IRBB; }
4259};
4260
4261/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
4262/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
4263/// A VPRegionBlock may indicate that its contents are to be replicated several
4264/// times. This is designed to support predicated scalarization, in which a
4265/// scalar if-then code structure needs to be generated VF * UF times. Having
4266/// this replication indicator helps to keep a single model for multiple
4267/// candidate VF's. The actual replication takes place only once the desired VF
4268/// and UF have been determined.
4269class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
4270 friend class VPlan;
4271
4272 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
4273 VPBlockBase *Entry;
4274
4275 /// Hold the Single Exiting block of the SESE region modelled by the
4276 /// VPRegionBlock.
4277 VPBlockBase *Exiting;
4278
4279 /// An indicator whether this region is to generate multiple replicated
4280 /// instances of output IR corresponding to its VPBlockBases.
4281 bool IsReplicator;
4282
4283 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
4284 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
4285 const std::string &Name = "", bool IsReplicator = false)
4286 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
4287 IsReplicator(IsReplicator) {
4288 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
4289 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
4290 Entry->setParent(this);
4291 Exiting->setParent(this);
4292 }
4293 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
4294 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
4295 IsReplicator(IsReplicator) {}
4296
4297public:
4298 ~VPRegionBlock() override = default;
4299
4300 /// Method to support type inquiry through isa, cast, and dyn_cast.
4301 static inline bool classof(const VPBlockBase *V) {
4302 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
4303 }
4304
4305 const VPBlockBase *getEntry() const { return Entry; }
4306 VPBlockBase *getEntry() { return Entry; }
4307
4308 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
4309 /// EntryBlock must have no predecessors.
4310 void setEntry(VPBlockBase *EntryBlock) {
4311 assert(EntryBlock->getPredecessors().empty() &&
4312 "Entry block cannot have predecessors.");
4313 Entry = EntryBlock;
4314 EntryBlock->setParent(this);
4315 }
4316
4317 const VPBlockBase *getExiting() const { return Exiting; }
4318 VPBlockBase *getExiting() { return Exiting; }
4319
4320 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
4321 /// ExitingBlock must have no successors.
4322 void setExiting(VPBlockBase *ExitingBlock) {
4323 assert(ExitingBlock->getSuccessors().empty() &&
4324 "Exit block cannot have successors.");
4325 Exiting = ExitingBlock;
4326 ExitingBlock->setParent(this);
4327 }
4328
4329 /// Returns the pre-header VPBasicBlock of the loop region.
4331 assert(!isReplicator() && "should only get pre-header of loop regions");
4332 return getSinglePredecessor()->getExitingBasicBlock();
4333 }
4334
4335 /// An indicator whether this region is to generate multiple replicated
4336 /// instances of output IR corresponding to its VPBlockBases.
4337 bool isReplicator() const { return IsReplicator; }
4338
4339 /// The method which generates the output IR instructions that correspond to
4340 /// this VPRegionBlock, thereby "executing" the VPlan.
4341 void execute(VPTransformState *State) override;
4342
4343 // Return the cost of this region.
4344 InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override;
4345
4346#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4347 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
4348 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
4349 /// consequtive numbers.
4350 ///
4351 /// Note that the numbering is applied to the whole VPlan, so printing
4352 /// individual regions is consistent with the whole VPlan printing.
4353 void print(raw_ostream &O, const Twine &Indent,
4354 VPSlotTracker &SlotTracker) const override;
4355 using VPBlockBase::print; // Get the print(raw_stream &O) version.
4356#endif
4357
4358 /// Clone all blocks in the single-entry single-exit region of the block and
4359 /// their recipes without updating the operands of the cloned recipes.
4360 VPRegionBlock *clone() override;
4361
4362 /// Remove the current region from its VPlan, connecting its predecessor to
4363 /// its entry, and its exiting block to its successor.
4364 void dissolveToCFGLoop();
4365
4366 /// Returns the canonical induction recipe of the region.
4368 VPBasicBlock *EntryVPBB = getEntryBasicBlock();
4369 if (EntryVPBB->empty()) {
4370 // VPlan native path. TODO: Unify both code paths.
4371 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
4372 }
4373 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
4374 }
4376 return const_cast<VPRegionBlock *>(this)->getCanonicalIV();
4377 }
4378
4379 /// Return the type of the canonical IV for loop regions.
4380 Type *getCanonicalIVType() { return getCanonicalIV()->getScalarType(); }
4381 const Type *getCanonicalIVType() const {
4382 return getCanonicalIV()->getScalarType();
4383 }
4384};
4385
4387 return getParent()->getParent();
4388}
4389
4391 return getParent()->getParent();
4392}
4393
4394/// VPlan models a candidate for vectorization, encoding various decisions take
4395/// to produce efficient output IR, including which branches, basic-blocks and
4396/// output IR instructions to generate, and their cost. VPlan holds a
4397/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
4398/// VPBasicBlock.
4399class VPlan {
4400 friend class VPlanPrinter;
4401 friend class VPSlotTracker;
4402
4403 /// VPBasicBlock corresponding to the original preheader. Used to place
4404 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
4405 /// rest of VPlan execution.
4406 /// When this VPlan is used for the epilogue vector loop, the entry will be
4407 /// replaced by a new entry block created during skeleton creation.
4408 VPBasicBlock *Entry;
4409
4410 /// VPIRBasicBlock wrapping the header of the original scalar loop.
4411 VPIRBasicBlock *ScalarHeader;
4412
4413 /// Immutable list of VPIRBasicBlocks wrapping the exit blocks of the original
4414 /// scalar loop. Note that some exit blocks may be unreachable at the moment,
4415 /// e.g. if the scalar epilogue always executes.
4417
4418 /// Holds the VFs applicable to this VPlan.
4420
4421 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
4422 /// any UF.
4424
4425 /// Holds the name of the VPlan, for printing.
4426 std::string Name;
4427
4428 /// Represents the trip count of the original loop, for folding
4429 /// the tail.
4430 VPValue *TripCount = nullptr;
4431
4432 /// Represents the backedge taken count of the original loop, for folding
4433 /// the tail. It equals TripCount - 1.
4434 VPSymbolicValue *BackedgeTakenCount = nullptr;
4435
4436 /// Represents the vector trip count.
4437 VPSymbolicValue VectorTripCount;
4438
4439 /// Represents the vectorization factor of the loop.
4440 VPSymbolicValue VF;
4441
4442 /// Represents the loop-invariant VF * UF of the vector loop region.
4443 VPSymbolicValue VFxUF;
4444
4445 /// Contains all the external definitions created for this VPlan, as a mapping
4446 /// from IR Values to VPIRValues.
4448
4449 /// Blocks allocated and owned by the VPlan. They will be deleted once the
4450 /// VPlan is destroyed.
4451 SmallVector<VPBlockBase *> CreatedBlocks;
4452
4453 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
4454 /// wrapping the original header of the scalar loop.
4455 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
4456 : Entry(Entry), ScalarHeader(ScalarHeader) {
4457 Entry->setPlan(this);
4458 assert(ScalarHeader->getNumSuccessors() == 0 &&
4459 "scalar header must be a leaf node");
4460 }
4461
4462public:
4463 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
4464 /// original preheader and scalar header of \p L, to be used as entry and
4465 /// scalar header blocks of the new VPlan.
4466 VPlan(Loop *L);
4467
4468 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
4469 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
4470 VPlan(BasicBlock *ScalarHeaderBB) {
4471 setEntry(createVPBasicBlock("preheader"));
4472 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
4473 }
4474
4476
4478 Entry = VPBB;
4479 VPBB->setPlan(this);
4480 }
4481
4482 /// Generate the IR code for this VPlan.
4483 void execute(VPTransformState *State);
4484
4485 /// Return the cost of this plan.
4487
4488 VPBasicBlock *getEntry() { return Entry; }
4489 const VPBasicBlock *getEntry() const { return Entry; }
4490
4491 /// Returns the preheader of the vector loop region, if one exists, or null
4492 /// otherwise.
4494 VPRegionBlock *VectorRegion = getVectorLoopRegion();
4495 return VectorRegion
4496 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
4497 : nullptr;
4498 }
4499
4500 /// Returns the VPRegionBlock of the vector loop.
4503
4504 /// Returns the 'middle' block of the plan, that is the block that selects
4505 /// whether to execute the scalar tail loop or the exit block from the loop
4506 /// latch. If there is an early exit from the vector loop, the middle block
4507 /// conceptully has the early exit block as third successor, split accross 2
4508 /// VPBBs. In that case, the second VPBB selects whether to execute the scalar
4509 /// tail loop or the exit block. If the scalar tail loop or exit block are
4510 /// known to always execute, the middle block may branch directly to that
4511 /// block. This function cannot be called once the vector loop region has been
4512 /// removed.
4514 VPRegionBlock *LoopRegion = getVectorLoopRegion();
4515 assert(
4516 LoopRegion &&
4517 "cannot call the function after vector loop region has been removed");
4518 // The middle block is always the last successor of the region.
4519 return cast<VPBasicBlock>(LoopRegion->getSuccessors().back());
4520 }
4521
4523 return const_cast<VPlan *>(this)->getMiddleBlock();
4524 }
4525
4526 /// Return the VPBasicBlock for the preheader of the scalar loop.
4528 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
4529 }
4530
4531 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
4532 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
4533
4534 /// Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of
4535 /// the original scalar loop.
4536 ArrayRef<VPIRBasicBlock *> getExitBlocks() const { return ExitBlocks; }
4537
4538 /// Return the VPIRBasicBlock corresponding to \p IRBB. \p IRBB must be an
4539 /// exit block.
4541
4542 /// Returns true if \p VPBB is an exit block.
4543 bool isExitBlock(VPBlockBase *VPBB);
4544
4545 /// The trip count of the original loop.
4547 assert(TripCount && "trip count needs to be set before accessing it");
4548 return TripCount;
4549 }
4550
4551 /// Set the trip count assuming it is currently null; if it is not - use
4552 /// resetTripCount().
4553 void setTripCount(VPValue *NewTripCount) {
4554 assert(!TripCount && NewTripCount && "TripCount should not be set yet.");
4555 TripCount = NewTripCount;
4556 }
4557
4558 /// Resets the trip count for the VPlan. The caller must make sure all uses of
4559 /// the original trip count have been replaced.
4560 void resetTripCount(VPValue *NewTripCount) {
4561 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
4562 "TripCount must be set when resetting");
4563 TripCount = NewTripCount;
4564 }
4565
4566 /// The backedge taken count of the original loop.
4568 if (!BackedgeTakenCount)
4569 BackedgeTakenCount = new VPSymbolicValue();
4570 return BackedgeTakenCount;
4571 }
4572 VPValue *getBackedgeTakenCount() const { return BackedgeTakenCount; }
4573
4574 /// The vector trip count.
4575 VPSymbolicValue &getVectorTripCount() { return VectorTripCount; }
4576
4577 /// Returns the VF of the vector loop region.
4578 VPValue &getVF() { return VF; };
4579 const VPValue &getVF() const { return VF; };
4580
4581 /// Returns VF * UF of the vector loop region.
4582 VPValue &getVFxUF() { return VFxUF; }
4583
4586 }
4587
4588 void addVF(ElementCount VF) { VFs.insert(VF); }
4589
4591 assert(hasVF(VF) && "Cannot set VF not already in plan");
4592 VFs.clear();
4593 VFs.insert(VF);
4594 }
4595
4596 bool hasVF(ElementCount VF) const { return VFs.count(VF); }
4597 bool hasScalableVF() const {
4598 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
4599 }
4600
4601 /// Returns an iterator range over all VFs of the plan.
4604 return VFs;
4605 }
4606
4607 bool hasScalarVFOnly() const {
4608 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
4609 assert(HasScalarVFOnly == hasVF(ElementCount::getFixed(1)) &&
4610 "Plan with scalar VF should only have a single VF");
4611 return HasScalarVFOnly;
4612 }
4613
4614 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
4615
4616 unsigned getUF() const {
4617 assert(UFs.size() == 1 && "Expected a single UF");
4618 return UFs[0];
4619 }
4620
4621 void setUF(unsigned UF) {
4622 assert(hasUF(UF) && "Cannot set the UF not already in plan");
4623 UFs.clear();
4624 UFs.insert(UF);
4625 }
4626
4627 /// Returns true if the VPlan already has been unrolled, i.e. it has a single
4628 /// concrete UF.
4629 bool isUnrolled() const { return UFs.size() == 1; }
4630
4631 /// Return a string with the name of the plan and the applicable VFs and UFs.
4632 std::string getName() const;
4633
4634 void setName(const Twine &newName) { Name = newName.str(); }
4635
4636 /// Gets the live-in VPIRValue for \p V or adds a new live-in (if none exists
4637 /// yet) for \p V.
4639 assert(V && "Trying to get or add the VPIRValue of a null Value");
4640 auto [It, Inserted] = LiveIns.try_emplace(V);
4641 if (Inserted) {
4642 if (auto *CI = dyn_cast<ConstantInt>(V))
4643 It->second = new VPConstantInt(CI);
4644 else
4645 It->second = new VPIRValue(V);
4646 }
4647
4648 assert(isa<VPIRValue>(It->second) &&
4649 "Only VPIRValues should be in mapping");
4650 return It->second;
4651 }
4653 assert(V && "Trying to get or add the VPIRValue of a null VPIRValue");
4654 return getOrAddLiveIn(V->getValue());
4655 }
4656
4657 /// Return a VPIRValue wrapping i1 true.
4658 VPIRValue *getTrue() { return getConstantInt(1, 1); }
4659
4660 /// Return a VPIRValue wrapping i1 false.
4661 VPIRValue *getFalse() { return getConstantInt(1, 0); }
4662
4663 /// Return a VPIRValue wrapping a ConstantInt with the given type and value.
4664 VPIRValue *getConstantInt(Type *Ty, uint64_t Val, bool IsSigned = false) {
4665 return getOrAddLiveIn(ConstantInt::get(Ty, Val, IsSigned));
4666 }
4667
4668 /// Return a VPIRValue wrapping a ConstantInt with the given bitwidth and
4669 /// value.
4671 bool IsSigned = false) {
4672 return getConstantInt(APInt(BitWidth, Val, IsSigned));
4673 }
4674
4675 /// Return a VPIRValue wrapping a ConstantInt with the given APInt value.
4677 return getOrAddLiveIn(ConstantInt::get(getContext(), Val));
4678 }
4679
4680 /// Return the live-in VPIRValue for \p V, if there is one or nullptr
4681 /// otherwise.
4682 VPIRValue *getLiveIn(Value *V) const { return LiveIns.lookup(V); }
4683
4684 /// Return the list of live-in VPValues available in the VPlan.
4685 auto getLiveIns() const { return LiveIns.values(); }
4686
4687#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4688 /// Print the live-ins of this VPlan to \p O.
4689 void printLiveIns(raw_ostream &O) const;
4690
4691 /// Print this VPlan to \p O.
4692 LLVM_ABI_FOR_TEST void print(raw_ostream &O) const;
4693
4694 /// Print this VPlan in DOT format to \p O.
4695 LLVM_ABI_FOR_TEST void printDOT(raw_ostream &O) const;
4696
4697 /// Dump the plan to stderr (for debugging).
4698 LLVM_DUMP_METHOD void dump() const;
4699#endif
4700
4701 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
4702 /// recipes to refer to the clones, and return it.
4704
4705 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
4706 /// present. The returned block is owned by the VPlan and deleted once the
4707 /// VPlan is destroyed.
4709 VPRecipeBase *Recipe = nullptr) {
4710 auto *VPB = new VPBasicBlock(Name, Recipe);
4711 CreatedBlocks.push_back(VPB);
4712 return VPB;
4713 }
4714
4715 /// Create a new loop region with \p Name and entry and exiting blocks set
4716 /// to \p Entry and \p Exiting respectively, if set. The returned block is
4717 /// owned by the VPlan and deleted once the VPlan is destroyed.
4718 VPRegionBlock *createLoopRegion(const std::string &Name = "",
4719 VPBlockBase *Entry = nullptr,
4720 VPBlockBase *Exiting = nullptr) {
4721 auto *VPB = Entry ? new VPRegionBlock(Entry, Exiting, Name)
4722 : new VPRegionBlock(Name);
4723 CreatedBlocks.push_back(VPB);
4724 return VPB;
4725 }
4726
4727 /// Create a new replicate region with \p Entry, \p Exiting and \p Name. The
4728 /// returned block is owned by the VPlan and deleted once the VPlan is
4729 /// destroyed.
4731 const std::string &Name = "") {
4732 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, true);
4733 CreatedBlocks.push_back(VPB);
4734 return VPB;
4735 }
4736
4737 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
4738 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
4739 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
4741
4742 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
4743 /// instructions in \p IRBB, except its terminator which is managed by the
4744 /// successors of the block in VPlan. The returned block is owned by the VPlan
4745 /// and deleted once the VPlan is destroyed.
4747
4748 /// Returns true if the VPlan is based on a loop with an early exit. That is
4749 /// the case if the VPlan has either more than one exit block or a single exit
4750 /// block with multiple predecessors (one for the exit via the latch and one
4751 /// via the other early exit).
4752 bool hasEarlyExit() const {
4753 return count_if(ExitBlocks,
4754 [](VPIRBasicBlock *EB) { return EB->hasPredecessors(); }) >
4755 1 ||
4756 (ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
4757 }
4758
4759 /// Returns true if the scalar tail may execute after the vector loop. Note
4760 /// that this relies on unneeded branches to the scalar tail loop being
4761 /// removed.
4762 bool hasScalarTail() const {
4763 return !(!getScalarPreheader()->hasPredecessors() ||
4765 }
4766};
4767
4768#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4769inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
4770 Plan.print(OS);
4771 return OS;
4772}
4773#endif
4774
4775} // end namespace llvm
4776
4777#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:3721
void printRecipe(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition VPlan.h:3715
~VPActiveLaneMaskPHIRecipe() override=default
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4081
RecipeListTy::const_iterator const_iterator
Definition VPlan.h:4109
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition VPlan.h:4156
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition VPlan.h:4111
RecipeListTy::iterator iterator
Instruction iterators...
Definition VPlan.h:4108
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition VPlan.h:4134
iplist< VPRecipeBase > RecipeListTy
Definition VPlan.h:4092
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition VPlan.h:4098
iterator end()
Definition VPlan.h:4118
iterator begin()
Recipe iterator methods.
Definition VPlan.h:4116
RecipeListTy::reverse_iterator reverse_iterator
Definition VPlan.h:4110
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition VPlan.h:4169
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:4102
const_reverse_iterator rbegin() const
Definition VPlan.h:4122
reverse_iterator rend()
Definition VPlan.h:4123
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition VPlan.h:4096
VPRecipeBase & back()
Definition VPlan.h:4131
const VPRecipeBase & front() const
Definition VPlan.h:4128
const_iterator begin() const
Definition VPlan.h:4117
VPRecipeBase & front()
Definition VPlan.h:4129
const VPRecipeBase & back() const
Definition VPlan.h:4130
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition VPlan.h:4147
bool empty() const
Definition VPlan.h:4127
const_iterator end() const
Definition VPlan.h:4119
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:4142
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition VPlan.h:4137
reverse_iterator rbegin()
Definition VPlan.h:4121
friend class VPlan
Definition VPlan.h:4082
size_t size() const
Definition VPlan.h:4126
const_reverse_iterator rend() const
Definition VPlan.h:4124
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition VPlan.h:2646
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition VPlan.h:2651
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition VPlan.h:2641
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2662
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2671
VPBlendRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2628
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:2623
void setMask(unsigned Idx, VPValue *V)
Set mask number Idx to V.
Definition VPlan.h:2657
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:2637
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:3143
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3127
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:3151
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
Definition VPlan.h:3124
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
Definition VPlan.h:3655
~VPCanonicalIVPHIRecipe() override=default
VPCanonicalIVPHIRecipe(VPIRValue *StartV, DebugLoc DL)
Definition VPlan.h:3657
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3683
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3663
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:3690
VPIRValue * getStartValue() const
Returns the start value of the canonical induction.
Definition VPlan.h:3677
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:3680
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3671
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPCanonicalIVPHIRecipe.
Definition VPlan.h:3697
void execute(VPTransformState &State) override
Generate the transformed value of the induction at offset StartValue (1.
VPIRValue * getStartValue() const
Definition VPlan.h:3872
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPDerivedIVRecipe.
Definition VPlan.h:3864
VPValue * getStepValue() const
Definition VPlan.h:3873
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPIRValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3836
Type * getScalarType() const
Definition VPlan.h:3870
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3852
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:3876
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPIRValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition VPlan.h:3844
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:3772
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:3753
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:3759
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition VPlan.h:3765
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition VPlan.h:3747
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:3630
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:3635
VPExpandSCEVRecipe(const SCEV *Expr)
Definition VPlan.h:3621
const SCEV * getSCEV() const
Definition VPlan.h:3641
VPExpandSCEVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3626
~VPExpandSCEVRecipe() override=default
void execute(VPTransformState &State) override
Method for generating code, must not be called as this recipe is abstract.
Definition VPlan.h:3278
VPValue * getOperandOfResultType() const
Return the VPValue to use to infer the result type of the recipe.
Definition VPlan.h:3260
VPExpressionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3242
void decompose()
Insert the recipes of the expression back into the VPlan, directly before the current recipe.
~VPExpressionRecipe() override
Definition VPlan.h:3230
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:3216
VPExpressionRecipe(VPWidenCastRecipe *Ext, VPReductionRecipe *Red)
Definition VPlan.h:3208
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:3212
void printRecipe(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
unsigned getVFScaleFactor() const
Definition VPlan.h:3272
VPExpressionRecipe(VPWidenRecipe *Mul, VPReductionRecipe *Red)
Definition VPlan.h:3210
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:2134
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:2139
static bool classof(const VPSingleDefRecipe *R)
Definition VPlan.h:2152
static bool classof(const VPValue *V)
Definition VPlan.h:2149
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:2175
void setBackedgeValue(VPValue *V)
Update the incoming value from the loop backedge.
Definition VPlan.h:2180
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition VPlan.h:2164
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition VPlan.h:2172
static bool classof(const VPRecipeBase *R)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:2145
VPValue * getStartValue() const
Definition VPlan.h:2167
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition VPlan.h:2184
~VPHeaderPHIRecipe() override=default
void execute(VPTransformState &State) override
Produce a vectorized histogram operation.
VPHistogramRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1898
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:1915
unsigned getOpcode() const
Definition VPlan.h:1911
VPHistogramRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1891
VP_CLASSOF_IMPL(VPRecipeBase::VPHistogramSC)
~VPHistogramRecipe() override=default
A special type of VPBasicBlock that wraps an existing IR basic block.
Definition VPlan.h:4234
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:4258
static bool classof(const VPBlockBase *V)
Definition VPlan.h:4248
~VPIRBasicBlock() override=default
friend class VPlan
Definition VPlan.h:4235
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:2758
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Definition VPlan.h:2764
static bool classof(const VPUser *U)
Definition VPlan.h:2740
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:2706
Instruction * getInsertPos() const
Definition VPlan.h:2762
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2735
const InterleaveGroup< Instruction > * getInterleaveGroup() const
Definition VPlan.h:2760
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:2752
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition VPlan.h:2781
VPInterleaveBase * clone() override=0
Clone the current recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:2746
A recipe for interleaved memory operations with vector-predication intrinsics.
Definition VPlan.h:2834
bool usesFirstLaneOnly(const VPValue *Op) const override
The recipe only uses the first lane of the address, and EVL operand.
Definition VPlan.h:2862
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition VPlan.h:2856
~VPInterleaveEVLRecipe() override=default
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2869
VPInterleaveEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2849
VPInterleaveEVLRecipe(VPInterleaveRecipe &R, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:2836
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition VPlan.h:2792
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
Definition VPlan.h:2819
~VPInterleaveRecipe() override=default
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2802
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2813
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Definition VPlan.h:2794
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:4225
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:3335
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3317
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
Definition VPlan.h:3328
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition VPlan.h:3313
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:4386
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:3019
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2998
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3022
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3009
~VPReductionEVLRecipe() override=default
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition VPlan.h:2584
void setVFScaleFactor(unsigned ScaleFactor)
Set the VFScaleFactor for this reduction phi.
Definition VPlan.h:2570
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2549
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:2563
~VPReductionPHIRecipe() override=default
bool hasUsesOutsideReductionChain() const
Returns true, if the phi is part of a multi-use reduction.
Definition VPlan.h:2596
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2578
bool isInLoop() const
Returns true if the phi is part of an in-loop reduction.
Definition VPlan.h:2587
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:2601
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:2538
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:2593
RecurKind getRecurrenceKind() const
Returns the recurrence kind of the reduction.
Definition VPlan.h:2581
A recipe to represent inloop, ordered or partial reduction operations.
Definition VPlan.h:2885
VPReductionRecipe(const unsigned char SC, RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, ReductionStyle Style, DebugLoc DL)
Definition VPlan.h:2894
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition VPlan.h:2961
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2930
static bool classof(const VPSingleDefRecipe *R)
Definition VPlan.h:2945
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition VPlan.h:2972
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition VPlan.h:2974
RecurKind getRecurrenceKind() const
Return the recurrence kind for the in-loop reduction.
Definition VPlan.h:2957
VPReductionRecipe(RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, ReductionStyle Style, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2908
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition VPlan.h:2959
VPReductionRecipe(const RecurKind RdxKind, FastMathFlags FMFs, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, ReductionStyle Style, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:2915
bool isPartialReduction() const
Returns true if the reduction outputs a vector with a scaled down VF.
Definition VPlan.h:2963
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition VPlan.h:2970
bool isInLoop() const
Returns true if the reduction is in-loop.
Definition VPlan.h:2965
VPReductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2924
static bool classof(const VPUser *U)
Definition VPlan.h:2935
static bool classof(const VPValue *VPV)
Definition VPlan.h:2940
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:2979
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition VPlan.h:4269
const VPBlockBase * getEntry() const
Definition VPlan.h:4305
Type * getCanonicalIVType()
Return the type of the canonical IV for loop regions.
Definition VPlan.h:4380
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition VPlan.h:4337
~VPRegionBlock() override=default
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition VPlan.h:4322
VPBlockBase * getExiting()
Definition VPlan.h:4318
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the region.
Definition VPlan.h:4367
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition VPlan.h:4310
const Type * getCanonicalIVType() const
Definition VPlan.h:4381
const VPBlockBase * getExiting() const
Definition VPlan.h:4317
VPBlockBase * getEntry()
Definition VPlan.h:4306
const VPCanonicalIVPHIRecipe * getCanonicalIV() const
Definition VPlan.h:4375
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition VPlan.h:4330
friend class VPlan
Definition VPlan.h:4270
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition VPlan.h:4301
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3041
bool isSingleScalar() const
Definition VPlan.h:3082
VPReplicateRecipe(Instruction *I, ArrayRef< VPValue * > Operands, bool IsSingleScalar, VPValue *Mask=nullptr, const VPIRFlags &Flags={}, VPIRMetadata Metadata={}, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:3049
~VPReplicateRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition VPlan.h:3094
bool isPredicated() const
Definition VPlan.h:3084
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3063
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3087
unsigned getOpcode() const
Definition VPlan.h:3111
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition VPlan.h:3106
VPValue * getStepValue() const
Definition VPlan.h:3939
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition VPlan.h:3933
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step, VPValue *VF, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:3908
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3920
VPValue * getStartIndex() const
Return the StartIndex, or null if known to be zero, valid only after unrolling.
Definition VPlan.h:3947
VPValue * getVFValue() const
Return the number of scalars to produce per unroll part, used to compute StartIndex during unrolling.
Definition VPlan.h:3943
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, VPValue *VF, Instruction::BinaryOps Opcode, FastMathFlags FMFs, DebugLoc DL)
Definition VPlan.h:3901
~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:3952
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:2014
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.
VPVectorEndPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2035
const VPValue * getVFValue() const
Definition VPlan.h:2010
bool usesFirstPartOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition VPlan.h:2028
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPVectorPointerRecipe.
Definition VPlan.h:2021
VPVectorEndPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:1999
Type * getSourceElementType() const
Definition VPlan.h:2069
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition VPlan.h:2071
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:2078
VPVectorPointerRecipe(VPValue *Ptr, Type *SourceElementTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition VPlan.h:2056
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition VPlan.h:2094
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2085
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1830
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, const VPIRFlags &Flags={}, const VPIRMetadata &Metadata={}, DebugLoc DL={})
Definition VPlan.h:1837
const_operand_range args() const
Definition VPlan.h:1871
VPWidenCallRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1852
operand_range args()
Definition VPlan.h:1870
Function * getCalledScalarFunction() const
Definition VPlan.h:1866
~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:3808
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3795
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition VPlan.h:3790
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1680
Instruction::CastOps getOpcode() const
Definition VPlan.h:1716
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:1719
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:1688
VPWidenCastRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1701
unsigned getOpcode() const
This recipe generates a GEP instruction.
Definition VPlan.h:1962
Type * getSourceElementType() const
Definition VPlan.h:1967
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition VPlan.h:1970
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1954
~VPWidenGEPRecipe() override=default
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags={}, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1940
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:2264
static bool classof(const VPValue *V)
Definition VPlan.h:2215
void setStepValue(VPValue *V)
Update the step value of the recipe.
Definition VPlan.h:2234
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition VPlan.h:2249
VPIRValue * getStartValue() const
Returns the start value of the induction.
Definition VPlan.h:2227
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2242
PHINode * getPHINode() const
Definition VPlan.h:2244
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition VPlan.h:2203
VPValue * getStepValue()
Returns the step value of the induction.
Definition VPlan.h:2230
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition VPlan.h:2247
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition VPlan.h:2256
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:2210
const VPValue * getVFValue() const
Definition VPlan.h:2237
static bool classof(const VPSingleDefRecipe *R)
Definition VPlan.h:2220
const VPValue * getStepValue() const
Definition VPlan.h:2231
VPIRValue * getStartValue() const
Returns the start value of the induction.
Definition VPlan.h:2325
const TruncInst * getTruncInst() const
Definition VPlan.h:2341
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition VPlan.h:2319
~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:2329
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2311
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPIRValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, const VPIRFlags &Flags, DebugLoc DL)
Definition VPlan.h:2285
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition VPlan.h:2340
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPIRValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, const VPIRFlags &Flags, DebugLoc DL)
Definition VPlan.h:2294
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition VPlan.h:2356
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Definition VPlan.h:2336
Type * getScalarType() const
Returns the scalar type of the induction.
Definition VPlan.h:2349
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:1730
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, const VPIRFlags &Flags={}, const VPIRMetadata &Metadata={}, DebugLoc DL=DebugLoc::getUnknown())
Definition VPlan.h:1761
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
Definition VPlan.h:1801
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:1810
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:1747
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
Definition VPlan.h:1816
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:1782
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
Definition VPlan.h:1813
~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:1804
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:3366
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition VPlan.h:3363
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition VPlan.h:3406
static bool classof(const VPUser *U)
Definition VPlan.h:3400
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition VPlan.h:3429
Instruction & Ingredient
Definition VPlan.h:3354
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3389
Instruction & getIngredient() const
Definition VPlan.h:3437
bool Consecutive
Whether the accessed addresses are consecutive.
Definition VPlan.h:3360
static bool classof(const VPRecipeBase *R)
Definition VPlan.h:3393
VPValue * getMask() const
Return the mask used by this recipe.
Definition VPlan.h:3420
Align Alignment
Alignment information for this memory access.
Definition VPlan.h:3357
bool isMasked() const
Returns true if the recipe is masked.
Definition VPlan.h:3416
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3376
void setMask(VPValue *Mask)
Definition VPlan.h:3368
Align getAlign() const
Returns the alignment of the memory access.
Definition VPlan.h:3426
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition VPlan.h:3413
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition VPlan.h:3410
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
Definition VPlan.h:2455
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:2421
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenPHIRecipe.
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:2429
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:2383
~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:2392
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:2373
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:1646
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:1671
VPWidenRecipe(Instruction &I, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags={}, const VPIRMetadata &Metadata={}, DebugLoc DL={})
Definition VPlan.h:1636
~VPWidenRecipe() override=default
unsigned getOpcode() const
Definition VPlan.h:1661
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:4399
VPIRValue * getLiveIn(Value *V) const
Return the live-in VPIRValue for V, if there is one or nullptr otherwise.
Definition VPlan.h:4682
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:4401
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:4596
LLVMContext & getContext() const
Definition VPlan.h:4584
VPBasicBlock * getEntry()
Definition VPlan.h:4488
void setName(const Twine &newName)
Definition VPlan.h:4634
bool hasScalableVF() const
Definition VPlan.h:4597
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition VPlan.h:4582
VPValue & getVF()
Returns the VF of the vector loop region.
Definition VPlan.h:4578
VPValue * getTripCount() const
The trip count of the original loop.
Definition VPlan.h:4546
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition VPlan.h:4567
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition VPlan.h:4603
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:4652
const VPValue & getVF() const
Definition VPlan.h:4579
bool isExitBlock(VPBlockBase *VPBB)
Returns true if VPBB is an exit block.
Definition VPlan.cpp:911
const VPBasicBlock * getEntry() const
Definition VPlan.h:4489
friend class VPlanPrinter
Definition VPlan.h:4400
VPIRValue * getFalse()
Return a VPIRValue wrapping i1 false.
Definition VPlan.h:4661
VPIRValue * getConstantInt(const APInt &Val)
Return a VPIRValue wrapping a ConstantInt with the given APInt value.
Definition VPlan.h:4676
unsigned getUF() const
Definition VPlan.h:4616
VPRegionBlock * createReplicateRegion(VPBlockBase *Entry, VPBlockBase *Exiting, const std::string &Name="")
Create a new replicate region with Entry, Exiting and Name.
Definition VPlan.h:4730
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:4685
bool hasUF(unsigned UF) const
Definition VPlan.h:4614
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
Definition VPlan.h:4536
VPSymbolicValue & getVectorTripCount()
The vector trip count.
Definition VPlan.h:4575
VPValue * getBackedgeTakenCount() const
Definition VPlan.h:4572
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:4638
void setVF(ElementCount VF)
Definition VPlan.h:4590
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
Definition VPlan.h:4629
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:4752
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:4670
const VPBasicBlock * getMiddleBlock() const
Definition VPlan.h:4522
void setTripCount(VPValue *NewTripCount)
Set the trip count assuming it is currently null; if it is not - use resetTripCount().
Definition VPlan.h:4553
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition VPlan.h:4560
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition VPlan.h:4513
void setEntry(VPBasicBlock *VPBB)
Definition VPlan.h:4477
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition VPlan.h:4708
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:4658
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:4718
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition VPlan.cpp:1132
bool hasScalarVFOnly() const
Definition VPlan.h:4607
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition VPlan.h:4527
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:4588
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition VPlan.h:4532
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:4493
void setUF(unsigned UF)
Definition VPlan.h:4621
bool hasScalarTail() const
Returns true if the scalar tail may execute after the vector loop.
Definition VPlan.h:4762
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:4470
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:4664
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:4015
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:2510
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:2508
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:4046
static RetTy doCast(SrcTy R)
doCast is used by cast<>.
Definition VPlan.h:4060
static RetTy doCastIfPossible(SrcTy R)
doCastIfPossible is used by dyn_cast<>.
Definition VPlan.h:4065
static bool isPossible(SrcTy R)
Definition VPlan.h:4047
Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the recipe types implementing...
Definition VPlan.h:3977
static VPPhiAccessors * doCastIfPossible(SrcTy f)
doCastIfPossible is used by dyn_cast<>.
Definition VPlan.h:3998
CastInfo< VPPhiAccessors, SrcTy > Self
Definition VPlan.h:3979
static VPPhiAccessors * doCast(SrcTy R)
doCast is used by cast<>.
Definition VPlan.h:3982
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:3969
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:2502
Possible variants of a reduction.
Definition VPlan.h:2500
This reduction is unordered with the partial result scaled down by some factor.
Definition VPlan.h:2505
unsigned VFScaleFactor
Definition VPlan.h:2506
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:2471
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:2483
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:2462
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:3485
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:3498
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue *Addr, VPValue &EVL, VPValue *Mask)
Definition VPlan.h:3486
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3508
A recipe for widening load operations, using the address to load from and an optional mask.
Definition VPlan.h:3443
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3465
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:3444
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3453
VP_CLASSOF_IMPL(VPRecipeBase::VPWidenLoadSC)
A recipe for widening store operations with vector-predication intrinsics, using the value to store,...
Definition VPlan.h:3570
VPValue * getStoredValue() const
Return the address accessed by this recipe.
Definition VPlan.h:3582
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:3571
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3595
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:3585
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition VPlan.h:3526
VP_CLASSOF_IMPL(VPRecipeBase::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition VPlan.h:3545
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition VPlan.h:3536
bool usesFirstLaneOnly(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition VPlan.h:3551
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, const VPIRMetadata &Metadata, DebugLoc DL)
Definition VPlan.h:3527