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