LLVM 20.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/// 6. The VPlanPrinter class providing a way to print a plan in dot format;
21/// These are documented in docs/VectorizationPlan.rst.
22//
23//===----------------------------------------------------------------------===//
24
25#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
26#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
27
28#include "VPlanAnalysis.h"
29#include "VPlanValue.h"
30#include "llvm/ADT/DenseMap.h"
34#include "llvm/ADT/Twine.h"
35#include "llvm/ADT/ilist.h"
36#include "llvm/ADT/ilist_node.h"
42#include "llvm/IR/DebugLoc.h"
43#include "llvm/IR/FMF.h"
44#include "llvm/IR/Operator.h"
46#include <algorithm>
47#include <cassert>
48#include <cstddef>
49#include <string>
50
51namespace llvm {
52
53class BasicBlock;
54class DominatorTree;
55class InnerLoopVectorizer;
56class IRBuilderBase;
57class LoopInfo;
58class raw_ostream;
59class RecurrenceDescriptor;
60class SCEV;
61class Type;
62class VPBasicBlock;
63class VPRegionBlock;
64class VPlan;
65class VPReplicateRecipe;
66class VPlanSlp;
67class Value;
68class LoopVectorizationCostModel;
69class LoopVersioning;
70
71struct VPCostContext;
72
73namespace Intrinsic {
74typedef unsigned ID;
75}
76
77/// Returns a calculation for the total number of elements for a given \p VF.
78/// For fixed width vectors this value is a constant, whereas for scalable
79/// vectors it is an expression determined at runtime.
80Value *getRuntimeVF(IRBuilderBase &B, Type *Ty, ElementCount VF);
81
82/// Return a value for Step multiplied by VF.
83Value *createStepForVF(IRBuilderBase &B, Type *Ty, ElementCount VF,
84 int64_t Step);
85
86/// A helper function that returns the reciprocal of the block probability of
87/// predicated blocks. If we return X, we are assuming the predicated block
88/// will execute once for every X iterations of the loop header.
89///
90/// TODO: We should use actual block probability here, if available. Currently,
91/// we always assume predicated blocks have a 50% chance of executing.
92inline unsigned getReciprocalPredBlockProb() { return 2; }
93
94/// A range of powers-of-2 vectorization factors with fixed start and
95/// adjustable end. The range includes start and excludes end, e.g.,:
96/// [1, 16) = {1, 2, 4, 8}
97struct VFRange {
98 // A power of 2.
100
101 // A power of 2. If End <= Start range is empty.
103
104 bool isEmpty() const {
106 }
107
109 : Start(Start), End(End) {
111 "Both Start and End should have the same scalable flag");
113 "Expected Start to be a power of 2");
115 "Expected End to be a power of 2");
116 }
117
118 /// Iterator to iterate over vectorization factors in a VFRange.
120 : public iterator_facade_base<iterator, std::forward_iterator_tag,
121 ElementCount> {
122 ElementCount VF;
123
124 public:
125 iterator(ElementCount VF) : VF(VF) {}
126
127 bool operator==(const iterator &Other) const { return VF == Other.VF; }
128
129 ElementCount operator*() const { return VF; }
130
132 VF *= 2;
133 return *this;
134 }
135 };
136
140 return iterator(End);
141 }
142};
143
144using VPlanPtr = std::unique_ptr<VPlan>;
145
146/// In what follows, the term "input IR" refers to code that is fed into the
147/// vectorizer whereas the term "output IR" refers to code that is generated by
148/// the vectorizer.
149
150/// VPLane provides a way to access lanes in both fixed width and scalable
151/// vectors, where for the latter the lane index sometimes needs calculating
152/// as a runtime expression.
153class VPLane {
154public:
155 /// Kind describes how to interpret Lane.
156 enum class Kind : uint8_t {
157 /// For First, Lane is the index into the first N elements of a
158 /// fixed-vector <N x <ElTy>> or a scalable vector <vscale x N x <ElTy>>.
159 First,
160 /// For ScalableLast, Lane is the offset from the start of the last
161 /// N-element subvector in a scalable vector <vscale x N x <ElTy>>. For
162 /// example, a Lane of 0 corresponds to lane `(vscale - 1) * N`, a Lane of
163 /// 1 corresponds to `((vscale - 1) * N) + 1`, etc.
165 };
166
167private:
168 /// in [0..VF)
169 unsigned Lane;
170
171 /// Indicates how the Lane should be interpreted, as described above.
172 Kind LaneKind;
173
174public:
175 VPLane(unsigned Lane) : Lane(Lane), LaneKind(VPLane::Kind::First) {}
176 VPLane(unsigned Lane, Kind LaneKind) : Lane(Lane), LaneKind(LaneKind) {}
177
179
180 static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset) {
181 assert(Offset > 0 && Offset <= VF.getKnownMinValue() &&
182 "trying to extract with invalid offset");
183 unsigned LaneOffset = VF.getKnownMinValue() - Offset;
184 Kind LaneKind;
185 if (VF.isScalable())
186 // In this case 'LaneOffset' refers to the offset from the start of the
187 // last subvector with VF.getKnownMinValue() elements.
189 else
190 LaneKind = VPLane::Kind::First;
191 return VPLane(LaneOffset, LaneKind);
192 }
193
195 return getLaneFromEnd(VF, 1);
196 }
197
198 /// Returns a compile-time known value for the lane index and asserts if the
199 /// lane can only be calculated at runtime.
200 unsigned getKnownLane() const {
201 assert(LaneKind == Kind::First);
202 return Lane;
203 }
204
205 /// Returns an expression describing the lane index that can be used at
206 /// runtime.
207 Value *getAsRuntimeExpr(IRBuilderBase &Builder, const ElementCount &VF) const;
208
209 /// Returns the Kind of lane offset.
210 Kind getKind() const { return LaneKind; }
211
212 /// Returns true if this is the first lane of the whole vector.
213 bool isFirstLane() const { return Lane == 0 && LaneKind == Kind::First; }
214
215 /// Maps the lane to a cache index based on \p VF.
216 unsigned mapToCacheIndex(const ElementCount &VF) const {
217 switch (LaneKind) {
219 assert(VF.isScalable() && Lane < VF.getKnownMinValue());
220 return VF.getKnownMinValue() + Lane;
221 default:
222 assert(Lane < VF.getKnownMinValue());
223 return Lane;
224 }
225 }
226
227 /// Returns the maxmimum number of lanes that we are able to consider
228 /// caching for \p VF.
229 static unsigned getNumCachedLanes(const ElementCount &VF) {
230 return VF.getKnownMinValue() * (VF.isScalable() ? 2 : 1);
231 }
232};
233
234/// VPTransformState holds information passed down when "executing" a VPlan,
235/// needed for generating the output IR.
240 Loop *CurrentParentLoop, Type *CanonicalIVTy);
241 /// Target Transform Info.
243
244 /// The chosen Vectorization Factor of the loop being vectorized.
246
247 /// Hold the index to generate specific scalar instructions. Null indicates
248 /// that all instances are to be generated, using either scalar or vector
249 /// instructions.
250 std::optional<VPLane> Lane;
251
252 struct DataState {
253 // Each value from the original loop, when vectorized, is represented by a
254 // vector value in the map.
256
259
260 /// Get the generated vector Value for a given VPValue \p Def if \p IsScalar
261 /// is false, otherwise return the generated scalar. \See set.
262 Value *get(VPValue *Def, bool IsScalar = false);
263
264 /// Get the generated Value for a given VPValue and given Part and Lane.
265 Value *get(VPValue *Def, const VPLane &Lane);
266
267 bool hasVectorValue(VPValue *Def) { return Data.VPV2Vector.contains(Def); }
268
270 auto I = Data.VPV2Scalars.find(Def);
271 if (I == Data.VPV2Scalars.end())
272 return false;
273 unsigned CacheIdx = Lane.mapToCacheIndex(VF);
274 return CacheIdx < I->second.size() && I->second[CacheIdx];
275 }
276
277 /// Set the generated vector Value for a given VPValue, if \p
278 /// IsScalar is false. If \p IsScalar is true, set the scalar in lane 0.
279 void set(VPValue *Def, Value *V, bool IsScalar = false) {
280 if (IsScalar) {
281 set(Def, V, VPLane(0));
282 return;
283 }
284 assert((VF.isScalar() || V->getType()->isVectorTy()) &&
285 "scalar values must be stored as (0, 0)");
286 Data.VPV2Vector[Def] = V;
287 }
288
289 /// Reset an existing vector value for \p Def and a given \p Part.
290 void reset(VPValue *Def, Value *V) {
291 assert(Data.VPV2Vector.contains(Def) && "need to overwrite existing value");
292 Data.VPV2Vector[Def] = V;
293 }
294
295 /// Set the generated scalar \p V for \p Def and the given \p Lane.
296 void set(VPValue *Def, Value *V, const VPLane &Lane) {
297 auto &Scalars = Data.VPV2Scalars[Def];
298 unsigned CacheIdx = Lane.mapToCacheIndex(VF);
299 if (Scalars.size() <= CacheIdx)
300 Scalars.resize(CacheIdx + 1);
301 assert(!Scalars[CacheIdx] && "should overwrite existing value");
302 Scalars[CacheIdx] = V;
303 }
304
305 /// Reset an existing scalar value for \p Def and a given \p Lane.
306 void reset(VPValue *Def, Value *V, const VPLane &Lane) {
307 auto Iter = Data.VPV2Scalars.find(Def);
308 assert(Iter != Data.VPV2Scalars.end() &&
309 "need to overwrite existing value");
310 unsigned CacheIdx = Lane.mapToCacheIndex(VF);
311 assert(CacheIdx < Iter->second.size() &&
312 "need to overwrite existing value");
313 Iter->second[CacheIdx] = V;
314 }
315
316 /// Add additional metadata to \p To that was not present on \p Orig.
317 ///
318 /// Currently this is used to add the noalias annotations based on the
319 /// inserted memchecks. Use this for instructions that are *cloned* into the
320 /// vector loop.
321 void addNewMetadata(Instruction *To, const Instruction *Orig);
322
323 /// Add metadata from one instruction to another.
324 ///
325 /// This includes both the original MDs from \p From and additional ones (\see
326 /// addNewMetadata). Use this for *newly created* instructions in the vector
327 /// loop.
328 void addMetadata(Value *To, Instruction *From);
329
330 /// Set the debug location in the builder using the debug location \p DL.
332
333 /// Construct the vector value of a scalarized value \p V one lane at a time.
334 void packScalarIntoVectorValue(VPValue *Def, const VPLane &Lane);
335
336 /// Hold state information used when constructing the CFG of the output IR,
337 /// traversing the VPBasicBlocks and generating corresponding IR BasicBlocks.
338 struct CFGState {
339 /// The previous VPBasicBlock visited. Initially set to null.
341
342 /// The previous IR BasicBlock created or used. Initially set to the new
343 /// header BasicBlock.
344 BasicBlock *PrevBB = nullptr;
345
346 /// The last IR BasicBlock in the output IR. Set to the exit block of the
347 /// vector loop.
348 BasicBlock *ExitBB = nullptr;
349
350 /// A mapping of each VPBasicBlock to the corresponding BasicBlock. In case
351 /// of replication, maps the BasicBlock of the last replica created.
353
354 /// Updater for the DominatorTree.
356
358 : DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy) {}
359
360 /// Returns the BasicBlock* mapped to the pre-header of the loop region
361 /// containing \p R.
364
365 /// Hold a pointer to LoopInfo to register new basic blocks in the loop.
367
368 /// Hold a reference to the IRBuilder used to generate output IR code.
370
371 /// Hold a pointer to InnerLoopVectorizer to reuse its IR generation methods.
373
374 /// Pointer to the VPlan code is generated for.
376
377 /// The parent loop object for the current scope, or nullptr.
379
380 /// LoopVersioning. It's only set up (non-null) if memchecks were
381 /// used.
382 ///
383 /// This is currently only used to add no-alias metadata based on the
384 /// memchecks. The actually versioning is performed manually.
386
387 /// Map SCEVs to their expanded values. Populated when executing
388 /// VPExpandSCEVRecipes.
390
391 /// VPlan-based type analysis.
393};
394
395/// VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
396/// A VPBlockBase can be either a VPBasicBlock or a VPRegionBlock.
398 friend class VPBlockUtils;
399
400 const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
401
402 /// An optional name for the block.
403 std::string Name;
404
405 /// The immediate VPRegionBlock which this VPBlockBase belongs to, or null if
406 /// it is a topmost VPBlockBase.
407 VPRegionBlock *Parent = nullptr;
408
409 /// List of predecessor blocks.
411
412 /// List of successor blocks.
414
415 /// VPlan containing the block. Can only be set on the entry block of the
416 /// plan.
417 VPlan *Plan = nullptr;
418
419 /// Add \p Successor as the last successor to this block.
420 void appendSuccessor(VPBlockBase *Successor) {
421 assert(Successor && "Cannot add nullptr successor!");
422 Successors.push_back(Successor);
423 }
424
425 /// Add \p Predecessor as the last predecessor to this block.
426 void appendPredecessor(VPBlockBase *Predecessor) {
427 assert(Predecessor && "Cannot add nullptr predecessor!");
428 Predecessors.push_back(Predecessor);
429 }
430
431 /// Remove \p Predecessor from the predecessors of this block.
432 void removePredecessor(VPBlockBase *Predecessor) {
433 auto Pos = find(Predecessors, Predecessor);
434 assert(Pos && "Predecessor does not exist");
435 Predecessors.erase(Pos);
436 }
437
438 /// Remove \p Successor from the successors of this block.
439 void removeSuccessor(VPBlockBase *Successor) {
440 auto Pos = find(Successors, Successor);
441 assert(Pos && "Successor does not exist");
442 Successors.erase(Pos);
443 }
444
445 /// This function replaces one predecessor with another, useful when
446 /// trying to replace an old block in the CFG with a new one.
447 void replacePredecessor(VPBlockBase *Old, VPBlockBase *New) {
448 auto I = find(Predecessors, Old);
449 assert(I != Predecessors.end());
450 assert(Old->getParent() == New->getParent() &&
451 "replaced predecessor must have the same parent");
452 *I = New;
453 }
454
455 /// This function replaces one successor with another, useful when
456 /// trying to replace an old block in the CFG with a new one.
457 void replaceSuccessor(VPBlockBase *Old, VPBlockBase *New) {
458 auto I = find(Successors, Old);
459 assert(I != Successors.end());
460 assert(Old->getParent() == New->getParent() &&
461 "replaced successor must have the same parent");
462 *I = New;
463 }
464
465protected:
466 VPBlockBase(const unsigned char SC, const std::string &N)
467 : SubclassID(SC), Name(N) {}
468
469public:
470 /// An enumeration for keeping track of the concrete subclass of VPBlockBase
471 /// that are actually instantiated. Values of this enumeration are kept in the
472 /// SubclassID field of the VPBlockBase objects. They are used for concrete
473 /// type identification.
474 using VPBlockTy = enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC };
475
477
478 virtual ~VPBlockBase() = default;
479
480 const std::string &getName() const { return Name; }
481
482 void setName(const Twine &newName) { Name = newName.str(); }
483
484 /// \return an ID for the concrete type of this object.
485 /// This is used to implement the classof checks. This should not be used
486 /// for any other purpose, as the values may change as LLVM evolves.
487 unsigned getVPBlockID() const { return SubclassID; }
488
489 VPRegionBlock *getParent() { return Parent; }
490 const VPRegionBlock *getParent() const { return Parent; }
491
492 /// \return A pointer to the plan containing the current block.
493 VPlan *getPlan();
494 const VPlan *getPlan() const;
495
496 /// Sets the pointer of the plan containing the block. The block must be the
497 /// entry block into the VPlan.
498 void setPlan(VPlan *ParentPlan);
499
500 void setParent(VPRegionBlock *P) { Parent = P; }
501
502 /// \return the VPBasicBlock that is the entry of this VPBlockBase,
503 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
504 /// VPBlockBase is a VPBasicBlock, it is returned.
505 const VPBasicBlock *getEntryBasicBlock() const;
507
508 /// \return the VPBasicBlock that is the exiting this VPBlockBase,
509 /// recursively, if the latter is a VPRegionBlock. Otherwise, if this
510 /// VPBlockBase is a VPBasicBlock, it is returned.
511 const VPBasicBlock *getExitingBasicBlock() const;
513
514 const VPBlocksTy &getSuccessors() const { return Successors; }
515 VPBlocksTy &getSuccessors() { return Successors; }
516
519
520 const VPBlocksTy &getPredecessors() const { return Predecessors; }
521 VPBlocksTy &getPredecessors() { return Predecessors; }
522
523 /// \return the successor of this VPBlockBase if it has a single successor.
524 /// Otherwise return a null pointer.
526 return (Successors.size() == 1 ? *Successors.begin() : nullptr);
527 }
528
529 /// \return the predecessor of this VPBlockBase if it has a single
530 /// predecessor. Otherwise return a null pointer.
532 return (Predecessors.size() == 1 ? *Predecessors.begin() : nullptr);
533 }
534
535 size_t getNumSuccessors() const { return Successors.size(); }
536 size_t getNumPredecessors() const { return Predecessors.size(); }
537
538 /// An Enclosing Block of a block B is any block containing B, including B
539 /// itself. \return the closest enclosing block starting from "this", which
540 /// has successors. \return the root enclosing block if all enclosing blocks
541 /// have no successors.
543
544 /// \return the closest enclosing block starting from "this", which has
545 /// predecessors. \return the root enclosing block if all enclosing blocks
546 /// have no predecessors.
548
549 /// \return the successors either attached directly to this VPBlockBase or, if
550 /// this VPBlockBase is the exit block of a VPRegionBlock and has no
551 /// successors of its own, search recursively for the first enclosing
552 /// VPRegionBlock that has successors and return them. If no such
553 /// VPRegionBlock exists, return the (empty) successors of the topmost
554 /// VPBlockBase reached.
557 }
558
559 /// \return the hierarchical successor of this VPBlockBase if it has a single
560 /// hierarchical successor. Otherwise return a null pointer.
563 }
564
565 /// \return the predecessors either attached directly to this VPBlockBase or,
566 /// if this VPBlockBase is the entry block of a VPRegionBlock and has no
567 /// predecessors of its own, search recursively for the first enclosing
568 /// VPRegionBlock that has predecessors and return them. If no such
569 /// VPRegionBlock exists, return the (empty) predecessors of the topmost
570 /// VPBlockBase reached.
573 }
574
575 /// \return the hierarchical predecessor of this VPBlockBase if it has a
576 /// single hierarchical predecessor. Otherwise return a null pointer.
579 }
580
581 /// Set a given VPBlockBase \p Successor as the single successor of this
582 /// VPBlockBase. This VPBlockBase is not added as predecessor of \p Successor.
583 /// This VPBlockBase must have no successors.
585 assert(Successors.empty() && "Setting one successor when others exist.");
586 assert(Successor->getParent() == getParent() &&
587 "connected blocks must have the same parent");
588 appendSuccessor(Successor);
589 }
590
591 /// Set two given VPBlockBases \p IfTrue and \p IfFalse to be the two
592 /// successors of this VPBlockBase. This VPBlockBase is not added as
593 /// predecessor of \p IfTrue or \p IfFalse. This VPBlockBase must have no
594 /// successors.
595 void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse) {
596 assert(Successors.empty() && "Setting two successors when others exist.");
597 appendSuccessor(IfTrue);
598 appendSuccessor(IfFalse);
599 }
600
601 /// Set each VPBasicBlock in \p NewPreds as predecessor of this VPBlockBase.
602 /// This VPBlockBase must have no predecessors. This VPBlockBase is not added
603 /// as successor of any VPBasicBlock in \p NewPreds.
605 assert(Predecessors.empty() && "Block predecessors already set.");
606 for (auto *Pred : NewPreds)
607 appendPredecessor(Pred);
608 }
609
610 /// Set each VPBasicBlock in \p NewSuccss as successor of this VPBlockBase.
611 /// This VPBlockBase must have no successors. This VPBlockBase is not added
612 /// as predecessor of any VPBasicBlock in \p NewSuccs.
614 assert(Successors.empty() && "Block successors already set.");
615 for (auto *Succ : NewSuccs)
616 appendSuccessor(Succ);
617 }
618
619 /// Remove all the predecessor of this block.
620 void clearPredecessors() { Predecessors.clear(); }
621
622 /// Remove all the successors of this block.
623 void clearSuccessors() { Successors.clear(); }
624
625 /// Swap successors of the block. The block must have exactly 2 successors.
626 // TODO: This should be part of introducing conditional branch recipes rather
627 // than being independent.
629 assert(Successors.size() == 2 && "must have 2 successors to swap");
630 std::swap(Successors[0], Successors[1]);
631 }
632
633 /// The method which generates the output IR that correspond to this
634 /// VPBlockBase, thereby "executing" the VPlan.
635 virtual void execute(VPTransformState *State) = 0;
636
637 /// Return the cost of the block.
639
640 /// Return true if it is legal to hoist instructions into this block.
642 // There are currently no constraints that prevent an instruction to be
643 // hoisted into a VPBlockBase.
644 return true;
645 }
646
647#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
648 void printAsOperand(raw_ostream &OS, bool PrintType = false) const {
649 OS << getName();
650 }
651
652 /// Print plain-text dump of this VPBlockBase to \p O, prefixing all lines
653 /// with \p Indent. \p SlotTracker is used to print unnamed VPValue's using
654 /// consequtive numbers.
655 ///
656 /// Note that the numbering is applied to the whole VPlan, so printing
657 /// individual blocks is consistent with the whole VPlan printing.
658 virtual void print(raw_ostream &O, const Twine &Indent,
659 VPSlotTracker &SlotTracker) const = 0;
660
661 /// Print plain-text dump of this VPlan to \p O.
662 void print(raw_ostream &O) const {
664 print(O, "", SlotTracker);
665 }
666
667 /// Print the successors of this block to \p O, prefixing all lines with \p
668 /// Indent.
669 void printSuccessors(raw_ostream &O, const Twine &Indent) const;
670
671 /// Dump this VPBlockBase to dbgs().
672 LLVM_DUMP_METHOD void dump() const { print(dbgs()); }
673#endif
674
675 /// Clone the current block and it's recipes without updating the operands of
676 /// the cloned recipes, including all blocks in the single-entry single-exit
677 /// region for VPRegionBlocks.
678 virtual VPBlockBase *clone() = 0;
679};
680
681/// Struct to hold various analysis needed for cost computations.
690
694 : TTI(TTI), TLI(TLI), Types(CanIVTy), LLVMCtx(CanIVTy->getContext()),
695 CM(CM), CostKind(CostKind) {}
696
697 /// Return the cost for \p UI with \p VF using the legacy cost model as
698 /// fallback until computing the cost of all recipes migrates to VPlan.
700
701 /// Return true if the cost for \p UI shouldn't be computed, e.g. because it
702 /// has already been pre-computed.
703 bool skipCostComputation(Instruction *UI, bool IsVector) const;
704
705 /// Returns the OperandInfo for \p V, if it is a live-in.
707};
708
709/// VPRecipeBase is a base class modeling a sequence of one or more output IR
710/// instructions. VPRecipeBase owns the VPValues it defines through VPDef
711/// and is responsible for deleting its defined values. Single-value
712/// recipes must inherit from VPSingleDef instead of inheriting from both
713/// VPRecipeBase and VPValue separately.
714class VPRecipeBase : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock>,
715 public VPDef,
716 public VPUser {
717 friend VPBasicBlock;
718 friend class VPBlockUtils;
719
720 /// Each VPRecipe belongs to a single VPBasicBlock.
721 VPBasicBlock *Parent = nullptr;
722
723 /// The debug location for the recipe.
724 DebugLoc DL;
725
726public:
728 DebugLoc DL = {})
729 : VPDef(SC), VPUser(Operands), DL(DL) {}
730
731 template <typename IterT>
733 DebugLoc DL = {})
734 : VPDef(SC), VPUser(Operands), DL(DL) {}
735 virtual ~VPRecipeBase() = default;
736
737 /// Clone the current recipe.
738 virtual VPRecipeBase *clone() = 0;
739
740 /// \return the VPBasicBlock which this VPRecipe belongs to.
741 VPBasicBlock *getParent() { return Parent; }
742 const VPBasicBlock *getParent() const { return Parent; }
743
744 /// The method which generates the output IR instructions that correspond to
745 /// this VPRecipe, thereby "executing" the VPlan.
746 virtual void execute(VPTransformState &State) = 0;
747
748 /// Return the cost of this recipe, taking into account if the cost
749 /// computation should be skipped and the ForceTargetInstructionCost flag.
750 /// Also takes care of printing the cost for debugging.
752
753 /// Insert an unlinked recipe into a basic block immediately before
754 /// the specified recipe.
755 void insertBefore(VPRecipeBase *InsertPos);
756 /// Insert an unlinked recipe into \p BB immediately before the insertion
757 /// point \p IP;
759
760 /// Insert an unlinked Recipe into a basic block immediately after
761 /// the specified Recipe.
762 void insertAfter(VPRecipeBase *InsertPos);
763
764 /// Unlink this recipe from its current VPBasicBlock and insert it into
765 /// the VPBasicBlock that MovePos lives in, right after MovePos.
766 void moveAfter(VPRecipeBase *MovePos);
767
768 /// Unlink this recipe and insert into BB before I.
769 ///
770 /// \pre I is a valid iterator into BB.
772
773 /// This method unlinks 'this' from the containing basic block, but does not
774 /// delete it.
775 void removeFromParent();
776
777 /// This method unlinks 'this' from the containing basic block and deletes it.
778 ///
779 /// \returns an iterator pointing to the element after the erased one
781
782 /// Method to support type inquiry through isa, cast, and dyn_cast.
783 static inline bool classof(const VPDef *D) {
784 // All VPDefs are also VPRecipeBases.
785 return true;
786 }
787
788 static inline bool classof(const VPUser *U) { return true; }
789
790 /// Returns true if the recipe may have side-effects.
791 bool mayHaveSideEffects() const;
792
793 /// Returns true for PHI-like recipes.
794 bool isPhi() const {
795 return getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC;
796 }
797
798 /// Returns true if the recipe may read from memory.
799 bool mayReadFromMemory() const;
800
801 /// Returns true if the recipe may write to memory.
802 bool mayWriteToMemory() const;
803
804 /// Returns true if the recipe may read from or write to memory.
805 bool mayReadOrWriteMemory() const {
807 }
808
809 /// Returns the debug location of the recipe.
810 DebugLoc getDebugLoc() const { return DL; }
811
812protected:
813 /// Compute the cost of this recipe either using a recipe's specialized
814 /// implementation or using the legacy cost model and the underlying
815 /// instructions.
817 VPCostContext &Ctx) const;
818};
819
820// Helper macro to define common classof implementations for recipes.
821#define VP_CLASSOF_IMPL(VPDefID) \
822 static inline bool classof(const VPDef *D) { \
823 return D->getVPDefID() == VPDefID; \
824 } \
825 static inline bool classof(const VPValue *V) { \
826 auto *R = V->getDefiningRecipe(); \
827 return R && R->getVPDefID() == VPDefID; \
828 } \
829 static inline bool classof(const VPUser *U) { \
830 auto *R = dyn_cast<VPRecipeBase>(U); \
831 return R && R->getVPDefID() == VPDefID; \
832 } \
833 static inline bool classof(const VPRecipeBase *R) { \
834 return R->getVPDefID() == VPDefID; \
835 } \
836 static inline bool classof(const VPSingleDefRecipe *R) { \
837 return R->getVPDefID() == VPDefID; \
838 }
839
840/// VPSingleDef is a base class for recipes for modeling a sequence of one or
841/// more output IR that define a single result VPValue.
842/// Note that VPRecipeBase must be inherited from before VPValue.
843class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
844public:
845 template <typename IterT>
846 VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL = {})
847 : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
848
849 VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
850 DebugLoc DL = {})
851 : VPRecipeBase(SC, Operands, DL), VPValue(this) {}
852
853 template <typename IterT>
854 VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV,
855 DebugLoc DL = {})
856 : VPRecipeBase(SC, Operands, DL), VPValue(this, UV) {}
857
858 static inline bool classof(const VPRecipeBase *R) {
859 switch (R->getVPDefID()) {
860 case VPRecipeBase::VPDerivedIVSC:
861 case VPRecipeBase::VPEVLBasedIVPHISC:
862 case VPRecipeBase::VPExpandSCEVSC:
863 case VPRecipeBase::VPInstructionSC:
864 case VPRecipeBase::VPReductionEVLSC:
865 case VPRecipeBase::VPReductionSC:
866 case VPRecipeBase::VPReplicateSC:
867 case VPRecipeBase::VPScalarIVStepsSC:
868 case VPRecipeBase::VPVectorPointerSC:
869 case VPRecipeBase::VPReverseVectorPointerSC:
870 case VPRecipeBase::VPWidenCallSC:
871 case VPRecipeBase::VPWidenCanonicalIVSC:
872 case VPRecipeBase::VPWidenCastSC:
873 case VPRecipeBase::VPWidenGEPSC:
874 case VPRecipeBase::VPWidenIntrinsicSC:
875 case VPRecipeBase::VPWidenSC:
876 case VPRecipeBase::VPWidenEVLSC:
877 case VPRecipeBase::VPWidenSelectSC:
878 case VPRecipeBase::VPBlendSC:
879 case VPRecipeBase::VPPredInstPHISC:
880 case VPRecipeBase::VPCanonicalIVPHISC:
881 case VPRecipeBase::VPActiveLaneMaskPHISC:
882 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
883 case VPRecipeBase::VPWidenPHISC:
884 case VPRecipeBase::VPWidenIntOrFpInductionSC:
885 case VPRecipeBase::VPWidenPointerInductionSC:
886 case VPRecipeBase::VPReductionPHISC:
887 case VPRecipeBase::VPScalarCastSC:
888 case VPRecipeBase::VPPartialReductionSC:
889 return true;
890 case VPRecipeBase::VPBranchOnMaskSC:
891 case VPRecipeBase::VPInterleaveSC:
892 case VPRecipeBase::VPIRInstructionSC:
893 case VPRecipeBase::VPWidenLoadEVLSC:
894 case VPRecipeBase::VPWidenLoadSC:
895 case VPRecipeBase::VPWidenStoreEVLSC:
896 case VPRecipeBase::VPWidenStoreSC:
897 case VPRecipeBase::VPHistogramSC:
898 // TODO: Widened stores don't define a value, but widened loads do. Split
899 // the recipes to be able to make widened loads VPSingleDefRecipes.
900 return false;
901 }
902 llvm_unreachable("Unhandled VPDefID");
903 }
904
905 static inline bool classof(const VPUser *U) {
906 auto *R = dyn_cast<VPRecipeBase>(U);
907 return R && classof(R);
908 }
909
910 virtual VPSingleDefRecipe *clone() override = 0;
911
912 /// Returns the underlying instruction.
914 return cast<Instruction>(getUnderlyingValue());
915 }
917 return cast<Instruction>(getUnderlyingValue());
918 }
919
920#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
921 /// Print this VPSingleDefRecipe to dbgs() (for debugging).
922 LLVM_DUMP_METHOD void dump() const;
923#endif
924};
925
926/// Class to record LLVM IR flag for a recipe along with it.
928 enum class OperationType : unsigned char {
929 Cmp,
930 OverflowingBinOp,
931 DisjointOp,
932 PossiblyExactOp,
933 GEPOp,
934 FPMathOp,
935 NonNegOp,
936 Other
937 };
938
939public:
940 struct WrapFlagsTy {
941 char HasNUW : 1;
942 char HasNSW : 1;
943
945 };
946
948 char IsDisjoint : 1;
950 };
951
952private:
953 struct ExactFlagsTy {
954 char IsExact : 1;
955 };
956 struct NonNegFlagsTy {
957 char NonNeg : 1;
958 };
959 struct FastMathFlagsTy {
960 char AllowReassoc : 1;
961 char NoNaNs : 1;
962 char NoInfs : 1;
963 char NoSignedZeros : 1;
964 char AllowReciprocal : 1;
965 char AllowContract : 1;
966 char ApproxFunc : 1;
967
968 FastMathFlagsTy(const FastMathFlags &FMF);
969 };
970
971 OperationType OpType;
972
973 union {
977 ExactFlagsTy ExactFlags;
979 NonNegFlagsTy NonNegFlags;
980 FastMathFlagsTy FMFs;
981 unsigned AllFlags;
982 };
983
984protected:
986 OpType = Other.OpType;
987 AllFlags = Other.AllFlags;
988 }
989
990public:
991 template <typename IterT>
992 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DebugLoc DL = {})
993 : VPSingleDefRecipe(SC, Operands, DL) {
994 OpType = OperationType::Other;
995 AllFlags = 0;
996 }
997
998 template <typename IterT>
999 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, Instruction &I)
1001 if (auto *Op = dyn_cast<CmpInst>(&I)) {
1002 OpType = OperationType::Cmp;
1003 CmpPredicate = Op->getPredicate();
1004 } else if (auto *Op = dyn_cast<PossiblyDisjointInst>(&I)) {
1005 OpType = OperationType::DisjointOp;
1006 DisjointFlags.IsDisjoint = Op->isDisjoint();
1007 } else if (auto *Op = dyn_cast<OverflowingBinaryOperator>(&I)) {
1008 OpType = OperationType::OverflowingBinOp;
1009 WrapFlags = {Op->hasNoUnsignedWrap(), Op->hasNoSignedWrap()};
1010 } else if (auto *Op = dyn_cast<PossiblyExactOperator>(&I)) {
1011 OpType = OperationType::PossiblyExactOp;
1012 ExactFlags.IsExact = Op->isExact();
1013 } else if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
1014 OpType = OperationType::GEPOp;
1015 GEPFlags = GEP->getNoWrapFlags();
1016 } else if (auto *PNNI = dyn_cast<PossiblyNonNegInst>(&I)) {
1017 OpType = OperationType::NonNegOp;
1018 NonNegFlags.NonNeg = PNNI->hasNonNeg();
1019 } else if (auto *Op = dyn_cast<FPMathOperator>(&I)) {
1020 OpType = OperationType::FPMathOp;
1021 FMFs = Op->getFastMathFlags();
1022 } else {
1023 OpType = OperationType::Other;
1024 AllFlags = 0;
1025 }
1026 }
1027
1028 template <typename IterT>
1029 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
1030 CmpInst::Predicate Pred, DebugLoc DL = {})
1031 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::Cmp),
1032 CmpPredicate(Pred) {}
1033
1034 template <typename IterT>
1035 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
1037 : VPSingleDefRecipe(SC, Operands, DL),
1038 OpType(OperationType::OverflowingBinOp), WrapFlags(WrapFlags) {}
1039
1040 template <typename IterT>
1041 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
1042 FastMathFlags FMFs, DebugLoc DL = {})
1043 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::FPMathOp),
1044 FMFs(FMFs) {}
1045
1046 template <typename IterT>
1047 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
1049 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::DisjointOp),
1051
1052protected:
1053 template <typename IterT>
1054 VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
1056 : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::GEPOp),
1057 GEPFlags(GEPFlags) {}
1058
1059public:
1060 static inline bool classof(const VPRecipeBase *R) {
1061 return R->getVPDefID() == VPRecipeBase::VPInstructionSC ||
1062 R->getVPDefID() == VPRecipeBase::VPWidenSC ||
1063 R->getVPDefID() == VPRecipeBase::VPWidenEVLSC ||
1064 R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
1065 R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
1066 R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
1067 R->getVPDefID() == VPRecipeBase::VPReverseVectorPointerSC ||
1068 R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
1069 }
1070
1071 static inline bool classof(const VPUser *U) {
1072 auto *R = dyn_cast<VPRecipeBase>(U);
1073 return R && classof(R);
1074 }
1075
1076 /// Drop all poison-generating flags.
1078 // NOTE: This needs to be kept in-sync with
1079 // Instruction::dropPoisonGeneratingFlags.
1080 switch (OpType) {
1081 case OperationType::OverflowingBinOp:
1082 WrapFlags.HasNUW = false;
1083 WrapFlags.HasNSW = false;
1084 break;
1085 case OperationType::DisjointOp:
1086 DisjointFlags.IsDisjoint = false;
1087 break;
1088 case OperationType::PossiblyExactOp:
1089 ExactFlags.IsExact = false;
1090 break;
1091 case OperationType::GEPOp:
1093 break;
1094 case OperationType::FPMathOp:
1095 FMFs.NoNaNs = false;
1096 FMFs.NoInfs = false;
1097 break;
1098 case OperationType::NonNegOp:
1099 NonNegFlags.NonNeg = false;
1100 break;
1101 case OperationType::Cmp:
1102 case OperationType::Other:
1103 break;
1104 }
1105 }
1106
1107 /// Set the IR flags for \p I.
1108 void setFlags(Instruction *I) const {
1109 switch (OpType) {
1110 case OperationType::OverflowingBinOp:
1111 I->setHasNoUnsignedWrap(WrapFlags.HasNUW);
1112 I->setHasNoSignedWrap(WrapFlags.HasNSW);
1113 break;
1114 case OperationType::DisjointOp:
1115 cast<PossiblyDisjointInst>(I)->setIsDisjoint(DisjointFlags.IsDisjoint);
1116 break;
1117 case OperationType::PossiblyExactOp:
1118 I->setIsExact(ExactFlags.IsExact);
1119 break;
1120 case OperationType::GEPOp:
1121 cast<GetElementPtrInst>(I)->setNoWrapFlags(GEPFlags);
1122 break;
1123 case OperationType::FPMathOp:
1124 I->setHasAllowReassoc(FMFs.AllowReassoc);
1125 I->setHasNoNaNs(FMFs.NoNaNs);
1126 I->setHasNoInfs(FMFs.NoInfs);
1127 I->setHasNoSignedZeros(FMFs.NoSignedZeros);
1128 I->setHasAllowReciprocal(FMFs.AllowReciprocal);
1129 I->setHasAllowContract(FMFs.AllowContract);
1130 I->setHasApproxFunc(FMFs.ApproxFunc);
1131 break;
1132 case OperationType::NonNegOp:
1133 I->setNonNeg(NonNegFlags.NonNeg);
1134 break;
1135 case OperationType::Cmp:
1136 case OperationType::Other:
1137 break;
1138 }
1139 }
1140
1142 assert(OpType == OperationType::Cmp &&
1143 "recipe doesn't have a compare predicate");
1144 return CmpPredicate;
1145 }
1146
1148
1149 /// Returns true if the recipe has fast-math flags.
1150 bool hasFastMathFlags() const { return OpType == OperationType::FPMathOp; }
1151
1153
1154 bool hasNoUnsignedWrap() const {
1155 assert(OpType == OperationType::OverflowingBinOp &&
1156 "recipe doesn't have a NUW flag");
1157 return WrapFlags.HasNUW;
1158 }
1159
1160 bool hasNoSignedWrap() const {
1161 assert(OpType == OperationType::OverflowingBinOp &&
1162 "recipe doesn't have a NSW flag");
1163 return WrapFlags.HasNSW;
1164 }
1165
1166 bool isDisjoint() const {
1167 assert(OpType == OperationType::DisjointOp &&
1168 "recipe cannot have a disjoing flag");
1170 }
1171
1172#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1173 void printFlags(raw_ostream &O) const;
1174#endif
1175};
1176
1177/// Helper to access the operand that contains the unroll part for this recipe
1178/// after unrolling.
1179template <unsigned PartOpIdx> class VPUnrollPartAccessor {
1180protected:
1181 /// Return the VPValue operand containing the unroll part or null if there is
1182 /// no such operand.
1184
1185 /// Return the unroll part.
1186 unsigned getUnrollPart(VPUser &U) const;
1187};
1188
1189/// This is a concrete Recipe that models a single VPlan-level instruction.
1190/// While as any Recipe it may generate a sequence of IR instructions when
1191/// executed, these instructions would always form a single-def expression as
1192/// the VPInstruction is also a single def-use vertex.
1194 public VPUnrollPartAccessor<1> {
1195 friend class VPlanSlp;
1196
1197public:
1198 /// VPlan opcodes, extending LLVM IR with idiomatics instructions.
1199 enum {
1201 Instruction::OtherOpsEnd + 1, // Combines the incoming and previous
1202 // values of a first-order recurrence.
1208 /// Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
1209 /// The first operand is the incoming value from the predecessor in VPlan,
1210 /// the second operand is the incoming value for all other predecessors
1211 /// (which are currently not modeled in VPlan).
1214 // Increment the canonical IV separately for each unrolled part.
1219 // Takes the VPValue to extract from as first operand and the lane or part
1220 // to extract as second operand, counting from the end starting with 1 for
1221 // last. The second operand must be a positive constant and <= VF.
1223 LogicalAnd, // Non-poison propagating logical And.
1224 // Add an offset in bytes (second operand) to a base pointer (first
1225 // operand). Only generates scalar values (either for the first lane only or
1226 // for all lanes, depending on its uses).
1228 // Returns a scalar boolean value, which is true if any lane of its (only
1229 // boolean) vector operand is true.
1231 };
1232
1233private:
1234 typedef unsigned char OpcodeTy;
1235 OpcodeTy Opcode;
1236
1237 /// An optional name that can be used for the generated IR instruction.
1238 const std::string Name;
1239
1240 /// Returns true if this VPInstruction generates scalar values for all lanes.
1241 /// Most VPInstructions generate a single value per part, either vector or
1242 /// scalar. VPReplicateRecipe takes care of generating multiple (scalar)
1243 /// values per all lanes, stemming from an original ingredient. This method
1244 /// identifies the (rare) cases of VPInstructions that do so as well, w/o an
1245 /// underlying ingredient.
1246 bool doesGeneratePerAllLanes() const;
1247
1248 /// Returns true if we can generate a scalar for the first lane only if
1249 /// needed.
1250 bool canGenerateScalarForFirstLane() const;
1251
1252 /// Utility methods serving execute(): generates a single vector instance of
1253 /// the modeled instruction. \returns the generated value. . In some cases an
1254 /// existing value is returned rather than a generated one.
1255 Value *generate(VPTransformState &State);
1256
1257 /// Utility methods serving execute(): generates a scalar single instance of
1258 /// the modeled instruction for a given lane. \returns the scalar generated
1259 /// value for lane \p Lane.
1260 Value *generatePerLane(VPTransformState &State, const VPLane &Lane);
1261
1262#if !defined(NDEBUG)
1263 /// Return true if the VPInstruction is a floating point math operation, i.e.
1264 /// has fast-math flags.
1265 bool isFPMathOp() const;
1266#endif
1267
1268public:
1270 const Twine &Name = "")
1271 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DL),
1272 Opcode(Opcode), Name(Name.str()) {}
1273
1274 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
1275 DebugLoc DL = {}, const Twine &Name = "")
1277
1278 VPInstruction(unsigned Opcode, CmpInst::Predicate Pred, VPValue *A,
1279 VPValue *B, DebugLoc DL = {}, const Twine &Name = "");
1280
1281 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
1282 WrapFlagsTy WrapFlags, DebugLoc DL = {}, const Twine &Name = "")
1283 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, WrapFlags, DL),
1284 Opcode(Opcode), Name(Name.str()) {}
1285
1286 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
1287 DisjointFlagsTy DisjointFlag, DebugLoc DL = {},
1288 const Twine &Name = "")
1289 : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DisjointFlag, DL),
1290 Opcode(Opcode), Name(Name.str()) {
1291 assert(Opcode == Instruction::Or && "only OR opcodes can be disjoint");
1292 }
1293
1295 DebugLoc DL = {}, const Twine &Name = "")
1296 : VPRecipeWithIRFlags(VPDef::VPInstructionSC,
1297 ArrayRef<VPValue *>({Ptr, Offset}), Flags, DL),
1298 Opcode(VPInstruction::PtrAdd), Name(Name.str()) {}
1299
1300 VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
1301 FastMathFlags FMFs, DebugLoc DL = {}, const Twine &Name = "");
1302
1303 VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
1304
1305 VPInstruction *clone() override {
1307 auto *New = new VPInstruction(Opcode, Operands, getDebugLoc(), Name);
1308 New->transferFlags(*this);
1309 return New;
1310 }
1311
1312 unsigned getOpcode() const { return Opcode; }
1313
1314 /// Generate the instruction.
1315 /// TODO: We currently execute only per-part unless a specific instance is
1316 /// provided.
1317 void execute(VPTransformState &State) override;
1318
1319 /// Return the cost of this VPInstruction.
1321 VPCostContext &Ctx) const override {
1322 // TODO: Compute accurate cost after retiring the legacy cost model.
1323 return 0;
1324 }
1325
1326#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1327 /// Print the VPInstruction to \p O.
1328 void print(raw_ostream &O, const Twine &Indent,
1329 VPSlotTracker &SlotTracker) const override;
1330
1331 /// Print the VPInstruction to dbgs() (for debugging).
1332 LLVM_DUMP_METHOD void dump() const;
1333#endif
1334
1335 bool hasResult() const {
1336 // CallInst may or may not have a result, depending on the called function.
1337 // Conservatively return calls have results for now.
1338 switch (getOpcode()) {
1339 case Instruction::Ret:
1340 case Instruction::Br:
1341 case Instruction::Store:
1342 case Instruction::Switch:
1343 case Instruction::IndirectBr:
1344 case Instruction::Resume:
1345 case Instruction::CatchRet:
1346 case Instruction::Unreachable:
1347 case Instruction::Fence:
1348 case Instruction::AtomicRMW:
1351 return false;
1352 default:
1353 return true;
1354 }
1355 }
1356
1357 /// Returns true if the underlying opcode may read from or write to memory.
1358 bool opcodeMayReadOrWriteFromMemory() const;
1359
1360 /// Returns true if the recipe only uses the first lane of operand \p Op.
1361 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1362
1363 /// Returns true if the recipe only uses the first part of operand \p Op.
1364 bool onlyFirstPartUsed(const VPValue *Op) const override;
1365
1366 /// Returns true if this VPInstruction produces a scalar value from a vector,
1367 /// e.g. by performing a reduction or extracting a lane.
1368 bool isVectorToScalar() const;
1369
1370 /// Returns true if this VPInstruction's operands are single scalars and the
1371 /// result is also a single scalar.
1372 bool isSingleScalar() const;
1373
1374 /// Returns the symbolic name assigned to the VPInstruction.
1375 StringRef getName() const { return Name; }
1376};
1377
1378/// A recipe to wrap on original IR instruction not to be modified during
1379/// execution, execept for PHIs. For PHIs, a single VPValue operand is allowed,
1380/// and it is used to add a new incoming value for the single predecessor VPBB.
1381/// Expect PHIs, VPIRInstructions cannot have any operands.
1383 Instruction &I;
1384
1385public:
1387 : VPRecipeBase(VPDef::VPIRInstructionSC, ArrayRef<VPValue *>()), I(I) {}
1388
1389 ~VPIRInstruction() override = default;
1390
1391 VP_CLASSOF_IMPL(VPDef::VPIRInstructionSC)
1392
1394 auto *R = new VPIRInstruction(I);
1395 for (auto *Op : operands())
1396 R->addOperand(Op);
1397 return R;
1398 }
1399
1400 void execute(VPTransformState &State) override;
1401
1402 /// Return the cost of this VPIRInstruction.
1404 VPCostContext &Ctx) const override;
1405
1406 Instruction &getInstruction() const { return I; }
1407
1408#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1409 /// Print the recipe.
1410 void print(raw_ostream &O, const Twine &Indent,
1411 VPSlotTracker &SlotTracker) const override;
1412#endif
1413
1414 bool usesScalars(const VPValue *Op) const override {
1416 "Op must be an operand of the recipe");
1417 return true;
1418 }
1419
1420 bool onlyFirstPartUsed(const VPValue *Op) const override {
1422 "Op must be an operand of the recipe");
1423 return true;
1424 }
1425
1426 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1428 "Op must be an operand of the recipe");
1429 return true;
1430 }
1431};
1432
1433/// VPWidenRecipe is a recipe for producing a widened instruction using the
1434/// opcode and operands of the recipe. This recipe covers most of the
1435/// traditional vectorization cases where each recipe transforms into a
1436/// vectorized version of itself.
1438 unsigned Opcode;
1439
1440protected:
1441 template <typename IterT>
1442 VPWidenRecipe(unsigned VPDefOpcode, Instruction &I,
1444 : VPRecipeWithIRFlags(VPDefOpcode, Operands, I), Opcode(I.getOpcode()) {}
1445
1446public:
1447 template <typename IterT>
1449 : VPWidenRecipe(VPDef::VPWidenSC, I, Operands) {}
1450
1451 ~VPWidenRecipe() override = default;
1452
1453 VPWidenRecipe *clone() override {
1454 auto *R = new VPWidenRecipe(*getUnderlyingInstr(), operands());
1455 R->transferFlags(*this);
1456 return R;
1457 }
1458
1459 static inline bool classof(const VPRecipeBase *R) {
1460 return R->getVPDefID() == VPRecipeBase::VPWidenSC ||
1461 R->getVPDefID() == VPRecipeBase::VPWidenEVLSC;
1462 }
1463
1464 static inline bool classof(const VPUser *U) {
1465 auto *R = dyn_cast<VPRecipeBase>(U);
1466 return R && classof(R);
1467 }
1468
1469 /// Produce a widened instruction using the opcode and operands of the recipe,
1470 /// processing State.VF elements.
1471 void execute(VPTransformState &State) override;
1472
1473 /// Return the cost of this VPWidenRecipe.
1475 VPCostContext &Ctx) const override;
1476
1477 unsigned getOpcode() const { return Opcode; }
1478
1479#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1480 /// Print the recipe.
1481 void print(raw_ostream &O, const Twine &Indent,
1482 VPSlotTracker &SlotTracker) const override;
1483#endif
1484};
1485
1486/// A recipe for widening operations with vector-predication intrinsics with
1487/// explicit vector length (EVL).
1490
1491public:
1492 template <typename IterT>
1494 : VPWidenRecipe(VPDef::VPWidenEVLSC, I, Operands) {
1495 addOperand(&EVL);
1496 }
1498 : VPWidenEVLRecipe(*W.getUnderlyingInstr(), W.operands(), EVL) {
1499 transferFlags(W);
1500 }
1501
1502 ~VPWidenEVLRecipe() override = default;
1503
1504 VPWidenRecipe *clone() override final {
1505 llvm_unreachable("VPWidenEVLRecipe cannot be cloned");
1506 return nullptr;
1507 }
1508
1509 VP_CLASSOF_IMPL(VPDef::VPWidenEVLSC);
1510
1512 const VPValue *getEVL() const { return getOperand(getNumOperands() - 1); }
1513
1514 /// Produce a vp-intrinsic using the opcode and operands of the recipe,
1515 /// processing EVL elements.
1516 void execute(VPTransformState &State) override final;
1517
1518 /// Returns true if the recipe only uses the first lane of operand \p Op.
1519 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1521 "Op must be an operand of the recipe");
1522 // EVL in that recipe is always the last operand, thus any use before means
1523 // the VPValue should be vectorized.
1524 return getEVL() == Op;
1525 }
1526
1527#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1528 /// Print the recipe.
1529 void print(raw_ostream &O, const Twine &Indent,
1530 VPSlotTracker &SlotTracker) const override final;
1531#endif
1532};
1533
1534/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1536 /// Cast instruction opcode.
1537 Instruction::CastOps Opcode;
1538
1539 /// Result type for the cast.
1540 Type *ResultTy;
1541
1542public:
1544 CastInst &UI)
1545 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), Opcode(Opcode),
1546 ResultTy(ResultTy) {
1547 assert(UI.getOpcode() == Opcode &&
1548 "opcode of underlying cast doesn't match");
1549 }
1550
1552 : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), Opcode(Opcode),
1553 ResultTy(ResultTy) {}
1554
1555 ~VPWidenCastRecipe() override = default;
1556
1558 if (auto *UV = getUnderlyingValue())
1559 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1560 *cast<CastInst>(UV));
1561
1562 return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy);
1563 }
1564
1565 VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
1566
1567 /// Produce widened copies of the cast.
1568 void execute(VPTransformState &State) override;
1569
1570 /// Return the cost of this VPWidenCastRecipe.
1572 VPCostContext &Ctx) const override;
1573
1574#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1575 /// Print the recipe.
1576 void print(raw_ostream &O, const Twine &Indent,
1577 VPSlotTracker &SlotTracker) const override;
1578#endif
1579
1580 Instruction::CastOps getOpcode() const { return Opcode; }
1581
1582 /// Returns the result type of the cast.
1583 Type *getResultType() const { return ResultTy; }
1584};
1585
1586/// VPScalarCastRecipe is a recipe to create scalar cast instructions.
1588 Instruction::CastOps Opcode;
1589
1590 Type *ResultTy;
1591
1592 Value *generate(VPTransformState &State);
1593
1594public:
1596 DebugLoc DL)
1597 : VPSingleDefRecipe(VPDef::VPScalarCastSC, {Op}, DL), Opcode(Opcode),
1598 ResultTy(ResultTy) {}
1599
1600 ~VPScalarCastRecipe() override = default;
1601
1603 return new VPScalarCastRecipe(Opcode, getOperand(0), ResultTy,
1604 getDebugLoc());
1605 }
1606
1607 VP_CLASSOF_IMPL(VPDef::VPScalarCastSC)
1608
1609 void execute(VPTransformState &State) override;
1610
1611 /// Return the cost of this VPScalarCastRecipe.
1613 VPCostContext &Ctx) const override {
1614 // TODO: Compute accurate cost after retiring the legacy cost model.
1615 return 0;
1616 }
1617
1618#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1619 void print(raw_ostream &O, const Twine &Indent,
1620 VPSlotTracker &SlotTracker) const override;
1621#endif
1622
1623 /// Returns the result type of the cast.
1624 Type *getResultType() const { return ResultTy; }
1625
1626 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1627 // At the moment, only uniform codegen is implemented.
1629 "Op must be an operand of the recipe");
1630 return true;
1631 }
1632};
1633
1634/// A recipe for widening vector intrinsics.
1636 /// ID of the vector intrinsic to widen.
1637 Intrinsic::ID VectorIntrinsicID;
1638
1639 /// Scalar return type of the intrinsic.
1640 Type *ResultTy;
1641
1642 /// True if the intrinsic may read from memory.
1643 bool MayReadFromMemory;
1644
1645 /// True if the intrinsic may read write to memory.
1646 bool MayWriteToMemory;
1647
1648 /// True if the intrinsic may have side-effects.
1649 bool MayHaveSideEffects;
1650
1651public:
1653 ArrayRef<VPValue *> CallArguments, Type *Ty,
1654 DebugLoc DL = {})
1655 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1656 VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1657 MayReadFromMemory(CI.mayReadFromMemory()),
1658 MayWriteToMemory(CI.mayWriteToMemory()),
1659 MayHaveSideEffects(CI.mayHaveSideEffects()) {}
1660
1662 ArrayRef<VPValue *> CallArguments, Type *Ty,
1663 DebugLoc DL = {})
1664 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1665 VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1666 LLVMContext &Ctx = Ty->getContext();
1667 AttributeList Attrs = Intrinsic::getAttributes(Ctx, VectorIntrinsicID);
1668 MemoryEffects ME = Attrs.getMemoryEffects();
1669 MayReadFromMemory = ME.onlyWritesMemory();
1670 MayWriteToMemory = ME.onlyReadsMemory();
1671 MayHaveSideEffects = MayWriteToMemory ||
1672 !Attrs.hasFnAttr(Attribute::NoUnwind) ||
1673 !Attrs.hasFnAttr(Attribute::WillReturn);
1674 }
1675
1677 std::initializer_list<VPValue *> CallArguments,
1678 Type *Ty, DebugLoc DL = {})
1679 : VPWidenIntrinsicRecipe(VectorIntrinsicID,
1680 ArrayRef<VPValue *>(CallArguments), Ty, DL) {}
1681
1682 ~VPWidenIntrinsicRecipe() override = default;
1683
1685 return new VPWidenIntrinsicRecipe(*cast<CallInst>(getUnderlyingValue()),
1686 VectorIntrinsicID, {op_begin(), op_end()},
1687 ResultTy, getDebugLoc());
1688 }
1689
1690 VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
1691
1692 /// Produce a widened version of the vector intrinsic.
1693 void execute(VPTransformState &State) override;
1694
1695 /// Return the cost of this vector intrinsic.
1697 VPCostContext &Ctx) const override;
1698
1699 /// Return the ID of the intrinsic.
1700 Intrinsic::ID getVectorIntrinsicID() const { return VectorIntrinsicID; }
1701
1702 /// Return the scalar return type of the intrinsic.
1703 Type *getResultType() const { return ResultTy; }
1704
1705 /// Return to name of the intrinsic as string.
1707
1708 /// Returns true if the intrinsic may read from memory.
1709 bool mayReadFromMemory() const { return MayReadFromMemory; }
1710
1711 /// Returns true if the intrinsic may write to memory.
1712 bool mayWriteToMemory() const { return MayWriteToMemory; }
1713
1714 /// Returns true if the intrinsic may have side-effects.
1715 bool mayHaveSideEffects() const { return MayHaveSideEffects; }
1716
1717#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1718 /// Print the recipe.
1719 void print(raw_ostream &O, const Twine &Indent,
1720 VPSlotTracker &SlotTracker) const override;
1721#endif
1722
1723 bool onlyFirstLaneUsed(const VPValue *Op) const override;
1724};
1725
1726/// A recipe for widening Call instructions using library calls.
1728 /// Variant stores a pointer to the chosen function. There is a 1:1 mapping
1729 /// between a given VF and the chosen vectorized variant, so there will be a
1730 /// different VPlan for each VF with a valid variant.
1731 Function *Variant;
1732
1733public:
1735 ArrayRef<VPValue *> CallArguments, DebugLoc DL = {})
1736 : VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
1737 *cast<Instruction>(UV)),
1738 Variant(Variant) {
1739 assert(
1740 isa<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue()) &&
1741 "last operand must be the called function");
1742 }
1743
1744 ~VPWidenCallRecipe() override = default;
1745
1747 return new VPWidenCallRecipe(getUnderlyingValue(), Variant,
1748 {op_begin(), op_end()}, getDebugLoc());
1749 }
1750
1751 VP_CLASSOF_IMPL(VPDef::VPWidenCallSC)
1752
1753 /// Produce a widened version of the call instruction.
1754 void execute(VPTransformState &State) override;
1755
1756 /// Return the cost of this VPWidenCallRecipe.
1758 VPCostContext &Ctx) const override;
1759
1761 return cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
1762 }
1763
1765 return make_range(op_begin(), op_begin() + getNumOperands() - 1);
1766 }
1768 return make_range(op_begin(), op_begin() + getNumOperands() - 1);
1769 }
1770
1771#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1772 /// Print the recipe.
1773 void print(raw_ostream &O, const Twine &Indent,
1774 VPSlotTracker &SlotTracker) const override;
1775#endif
1776};
1777
1778/// A recipe representing a sequence of load -> update -> store as part of
1779/// a histogram operation. This means there may be aliasing between vector
1780/// lanes, which is handled by the llvm.experimental.vector.histogram family
1781/// of intrinsics. The only update operations currently supported are
1782/// 'add' and 'sub' where the other term is loop-invariant.
1784 /// Opcode of the update operation, currently either add or sub.
1785 unsigned Opcode;
1786
1787public:
1788 template <typename IterT>
1789 VPHistogramRecipe(unsigned Opcode, iterator_range<IterT> Operands,
1790 DebugLoc DL = {})
1791 : VPRecipeBase(VPDef::VPHistogramSC, Operands, DL), Opcode(Opcode) {}
1792
1793 ~VPHistogramRecipe() override = default;
1794
1796 return new VPHistogramRecipe(Opcode, operands(), getDebugLoc());
1797 }
1798
1799 VP_CLASSOF_IMPL(VPDef::VPHistogramSC);
1800
1801 /// Produce a vectorized histogram operation.
1802 void execute(VPTransformState &State) override;
1803
1804 /// Return the cost of this VPHistogramRecipe.
1806 VPCostContext &Ctx) const override;
1807
1808 unsigned getOpcode() const { return Opcode; }
1809
1810 /// Return the mask operand if one was provided, or a null pointer if all
1811 /// lanes should be executed unconditionally.
1812 VPValue *getMask() const {
1813 return getNumOperands() == 3 ? getOperand(2) : nullptr;
1814 }
1815
1816#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1817 /// Print the recipe
1818 void print(raw_ostream &O, const Twine &Indent,
1819 VPSlotTracker &SlotTracker) const override;
1820#endif
1821};
1822
1823/// A recipe for widening select instructions.
1825 template <typename IterT>
1827 : VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I) {}
1828
1829 ~VPWidenSelectRecipe() override = default;
1830
1832 return new VPWidenSelectRecipe(*cast<SelectInst>(getUnderlyingInstr()),
1833 operands());
1834 }
1835
1836 VP_CLASSOF_IMPL(VPDef::VPWidenSelectSC)
1837
1838 /// Produce a widened version of the select instruction.
1839 void execute(VPTransformState &State) override;
1840
1841 /// Return the cost of this VPWidenSelectRecipe.
1843 VPCostContext &Ctx) const override;
1844
1845#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1846 /// Print the recipe.
1847 void print(raw_ostream &O, const Twine &Indent,
1848 VPSlotTracker &SlotTracker) const override;
1849#endif
1850
1851 VPValue *getCond() const {
1852 return getOperand(0);
1853 }
1854
1855 bool isInvariantCond() const {
1857 }
1858};
1859
1860/// A recipe for handling GEP instructions.
1862 bool isPointerLoopInvariant() const {
1864 }
1865
1866 bool isIndexLoopInvariant(unsigned I) const {
1868 }
1869
1870 bool areAllOperandsInvariant() const {
1871 return all_of(operands(), [](VPValue *Op) {
1872 return Op->isDefinedOutsideLoopRegions();
1873 });
1874 }
1875
1876public:
1877 template <typename IterT>
1879 : VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {}
1880
1881 ~VPWidenGEPRecipe() override = default;
1882
1884 return new VPWidenGEPRecipe(cast<GetElementPtrInst>(getUnderlyingInstr()),
1885 operands());
1886 }
1887
1888 VP_CLASSOF_IMPL(VPDef::VPWidenGEPSC)
1889
1890 /// Generate the gep nodes.
1891 void execute(VPTransformState &State) override;
1892
1893 /// Return the cost of this VPWidenGEPRecipe.
1895 VPCostContext &Ctx) const override {
1896 // TODO: Compute accurate cost after retiring the legacy cost model.
1897 return 0;
1898 }
1899
1900#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1901 /// Print the recipe.
1902 void print(raw_ostream &O, const Twine &Indent,
1903 VPSlotTracker &SlotTracker) const override;
1904#endif
1905};
1906
1907/// A recipe to compute the pointers for widened memory accesses of IndexTy
1908/// in reverse order.
1910 public VPUnrollPartAccessor<2> {
1911 Type *IndexedTy;
1912
1913public:
1916 : VPRecipeWithIRFlags(VPDef::VPReverseVectorPointerSC,
1917 ArrayRef<VPValue *>({Ptr, VF}), GEPFlags, DL),
1918 IndexedTy(IndexedTy) {}
1919
1920 VP_CLASSOF_IMPL(VPDef::VPReverseVectorPointerSC)
1921
1923 const VPValue *getVFValue() const { return getOperand(1); }
1924
1925 void execute(VPTransformState &State) override;
1926
1927 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1929 "Op must be an operand of the recipe");
1930 return true;
1931 }
1932
1933 /// Return the cost of this VPVectorPointerRecipe.
1935 VPCostContext &Ctx) const override {
1936 // TODO: Compute accurate cost after retiring the legacy cost model.
1937 return 0;
1938 }
1939
1940 /// Returns true if the recipe only uses the first part of operand \p Op.
1941 bool onlyFirstPartUsed(const VPValue *Op) const override {
1943 "Op must be an operand of the recipe");
1944 assert(getNumOperands() <= 2 && "must have at most two operands");
1945 return true;
1946 }
1947
1950 IndexedTy, getGEPNoWrapFlags(),
1951 getDebugLoc());
1952 }
1953
1954#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1955 /// Print the recipe.
1956 void print(raw_ostream &O, const Twine &Indent,
1957 VPSlotTracker &SlotTracker) const override;
1958#endif
1959};
1960
1961/// A recipe to compute the pointers for widened memory accesses of IndexTy.
1963 public VPUnrollPartAccessor<1> {
1964 Type *IndexedTy;
1965
1966public:
1968 DebugLoc DL)
1969 : VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
1970 GEPFlags, DL),
1971 IndexedTy(IndexedTy) {}
1972
1973 VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
1974
1975 void execute(VPTransformState &State) override;
1976
1977 bool onlyFirstLaneUsed(const VPValue *Op) const override {
1979 "Op must be an operand of the recipe");
1980 return true;
1981 }
1982
1983 /// Returns true if the recipe only uses the first part of operand \p Op.
1984 bool onlyFirstPartUsed(const VPValue *Op) const override {
1986 "Op must be an operand of the recipe");
1987 assert(getNumOperands() <= 2 && "must have at most two operands");
1988 return true;
1989 }
1990
1992 return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1994 }
1995
1996 /// Return the cost of this VPHeaderPHIRecipe.
1998 VPCostContext &Ctx) const override {
1999 // TODO: Compute accurate cost after retiring the legacy cost model.
2000 return 0;
2001 }
2002
2003#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2004 /// Print the recipe.
2005 void print(raw_ostream &O, const Twine &Indent,
2006 VPSlotTracker &SlotTracker) const override;
2007#endif
2008};
2009
2010/// A pure virtual base class for all recipes modeling header phis, including
2011/// phis for first order recurrences, pointer inductions and reductions. The
2012/// start value is the first operand of the recipe and the incoming value from
2013/// the backedge is the second operand.
2014///
2015/// Inductions are modeled using the following sub-classes:
2016/// * VPCanonicalIVPHIRecipe: Canonical scalar induction of the vector loop,
2017/// starting at a specified value (zero for the main vector loop, the resume
2018/// value for the epilogue vector loop) and stepping by 1. The induction
2019/// controls exiting of the vector loop by comparing against the vector trip
2020/// count. Produces a single scalar PHI for the induction value per
2021/// iteration.
2022/// * VPWidenIntOrFpInductionRecipe: Generates vector values for integer and
2023/// floating point inductions with arbitrary start and step values. Produces
2024/// a vector PHI per-part.
2025/// * VPDerivedIVRecipe: Converts the canonical IV value to the corresponding
2026/// value of an IV with different start and step values. Produces a single
2027/// scalar value per iteration
2028/// * VPScalarIVStepsRecipe: Generates scalar values per-lane based on a
2029/// canonical or derived induction.
2030/// * VPWidenPointerInductionRecipe: Generate vector and scalar values for a
2031/// pointer induction. Produces either a vector PHI per-part or scalar values
2032/// per-lane based on the canonical induction.
2034protected:
2035 VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr,
2036 VPValue *Start = nullptr, DebugLoc DL = {})
2037 : VPSingleDefRecipe(VPDefID, ArrayRef<VPValue *>(), UnderlyingInstr, DL) {
2038 if (Start)
2039 addOperand(Start);
2040 }
2041
2042public:
2043 ~VPHeaderPHIRecipe() override = default;
2044
2045 /// Method to support type inquiry through isa, cast, and dyn_cast.
2046 static inline bool classof(const VPRecipeBase *B) {
2047 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
2048 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
2049 }
2050 static inline bool classof(const VPValue *V) {
2051 auto *B = V->getDefiningRecipe();
2052 return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
2053 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
2054 }
2055
2056 /// Generate the phi nodes.
2057 void execute(VPTransformState &State) override = 0;
2058
2059 /// Return the cost of this header phi recipe.
2061 VPCostContext &Ctx) const override;
2062
2063#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2064 /// Print the recipe.
2065 void print(raw_ostream &O, const Twine &Indent,
2066 VPSlotTracker &SlotTracker) const override = 0;
2067#endif
2068
2069 /// Returns the start value of the phi, if one is set.
2071 return getNumOperands() == 0 ? nullptr : getOperand(0);
2072 }
2074 return getNumOperands() == 0 ? nullptr : getOperand(0);
2075 }
2076
2077 /// Update the start value of the recipe.
2079
2080 /// Returns the incoming value from the loop backedge.
2082 return getOperand(1);
2083 }
2084
2085 /// Returns the backedge value as a recipe. The backedge value is guaranteed
2086 /// to be a recipe.
2089 }
2090};
2091
2092/// Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2093/// VPWidenPointerInductionRecipe), providing shared functionality, including
2094/// retrieving the step value, induction descriptor and original phi node.
2096 const InductionDescriptor &IndDesc;
2097
2098public:
2099 VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
2100 VPValue *Step, const InductionDescriptor &IndDesc,
2101 DebugLoc DL)
2102 : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2103 addOperand(Step);
2104 }
2105
2106 static inline bool classof(const VPRecipeBase *R) {
2107 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
2108 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
2109 }
2110
2111 static inline bool classof(const VPValue *V) {
2112 auto *R = V->getDefiningRecipe();
2113 return R && classof(R);
2114 }
2115
2116 static inline bool classof(const VPHeaderPHIRecipe *R) {
2117 return classof(static_cast<const VPRecipeBase *>(R));
2118 }
2119
2120 virtual void execute(VPTransformState &State) override = 0;
2121
2122 /// Returns the step value of the induction.
2124 const VPValue *getStepValue() const { return getOperand(1); }
2125
2126 PHINode *getPHINode() const { return cast<PHINode>(getUnderlyingValue()); }
2127
2128 /// Returns the induction descriptor for the recipe.
2129 const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
2130
2132 // TODO: All operands of base recipe must exist and be at same index in
2133 // derived recipe.
2135 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2136 }
2137
2139 // TODO: All operands of base recipe must exist and be at same index in
2140 // derived recipe.
2142 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2143 }
2144};
2145
2146/// A recipe for handling phi nodes of integer and floating-point inductions,
2147/// producing their vector values.
2149 TruncInst *Trunc;
2150
2151public:
2153 VPValue *VF, const InductionDescriptor &IndDesc,
2154 DebugLoc DL)
2155 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2156 Step, IndDesc, DL),
2157 Trunc(nullptr) {
2158 addOperand(VF);
2159 }
2160
2162 VPValue *VF, const InductionDescriptor &IndDesc,
2163 TruncInst *Trunc, DebugLoc DL)
2164 : VPWidenInductionRecipe(VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2165 Step, IndDesc, DL),
2166 Trunc(Trunc) {
2167 addOperand(VF);
2168 }
2169
2171
2176 }
2177
2178 VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
2179
2180 /// Generate the vectorized and scalarized versions of the phi node as
2181 /// needed by their users.
2182 void execute(VPTransformState &State) override;
2183
2184#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2185 /// Print the recipe.
2186 void print(raw_ostream &O, const Twine &Indent,
2187 VPSlotTracker &SlotTracker) const override;
2188#endif
2189
2191 const VPValue *getVFValue() const { return getOperand(2); }
2192
2194 // If the recipe has been unrolled (4 operands), return the VPValue for the
2195 // induction increment.
2196 return getNumOperands() == 5 ? getOperand(3) : nullptr;
2197 }
2198
2199 /// Returns the first defined value as TruncInst, if it is one or nullptr
2200 /// otherwise.
2201 TruncInst *getTruncInst() { return Trunc; }
2202 const TruncInst *getTruncInst() const { return Trunc; }
2203
2204 /// Returns true if the induction is canonical, i.e. starting at 0 and
2205 /// incremented by UF * VF (= the original IV is incremented by 1) and has the
2206 /// same type as the canonical induction.
2207 bool isCanonical() const;
2208
2209 /// Returns the scalar type of the induction.
2211 return Trunc ? Trunc->getType() : getPHINode()->getType();
2212 }
2213
2214 /// Returns the VPValue representing the value of this induction at
2215 /// the last unrolled part, if it exists. Returns itself if unrolling did not
2216 /// take place.
2218 return getNumOperands() == 5 ? getOperand(4) : this;
2219 }
2220};
2221
2223 public VPUnrollPartAccessor<3> {
2224 bool IsScalarAfterVectorization;
2225
2226public:
2227 /// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2228 /// Start.
2230 const InductionDescriptor &IndDesc,
2231 bool IsScalarAfterVectorization, DebugLoc DL)
2232 : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
2233 Step, IndDesc, DL),
2234 IsScalarAfterVectorization(IsScalarAfterVectorization) {}
2235
2237
2240 cast<PHINode>(getUnderlyingInstr()), getOperand(0), getOperand(1),
2241 getInductionDescriptor(), IsScalarAfterVectorization, getDebugLoc());
2242 }
2243
2244 VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
2245
2246 /// Generate vector values for the pointer induction.
2247 void execute(VPTransformState &State) override;
2248
2249 /// Returns true if only scalar values will be generated.
2250 bool onlyScalarsGenerated(bool IsScalable);
2251
2252 /// Returns the VPValue representing the value of this induction at
2253 /// the first unrolled part, if it exists. Returns itself if unrolling did not
2254 /// take place.
2256 return getUnrollPart(*this) == 0 ? this : getOperand(2);
2257 }
2258
2259#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2260 /// Print the recipe.
2261 void print(raw_ostream &O, const Twine &Indent,
2262 VPSlotTracker &SlotTracker) const override;
2263#endif
2264};
2265
2266/// Recipe to generate a scalar PHI. Used to generate code for recipes that
2267/// produce scalar header phis, including VPCanonicalIVPHIRecipe and
2268/// VPEVLBasedIVPHIRecipe.
2270 std::string Name;
2271
2272public:
2273 VPScalarPHIRecipe(VPValue *Start, VPValue *BackedgeValue, DebugLoc DL,
2274 StringRef Name)
2275 : VPHeaderPHIRecipe(VPDef::VPScalarPHISC, nullptr, Start, DL),
2276 Name(Name.str()) {
2277 addOperand(BackedgeValue);
2278 }
2279
2280 ~VPScalarPHIRecipe() override = default;
2281
2283 llvm_unreachable("cloning not implemented yet");
2284 }
2285
2286 VP_CLASSOF_IMPL(VPDef::VPScalarPHISC)
2287
2288 /// Generate the phi/select nodes.
2289 void execute(VPTransformState &State) override;
2290
2291 /// Returns true if the recipe only uses the first lane of operand \p Op.
2292 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2294 "Op must be an operand of the recipe");
2295 return true;
2296 }
2297
2298#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2299 /// Print the recipe.
2300 void print(raw_ostream &O, const Twine &Indent,
2301 VPSlotTracker &SlotTracker) const override;
2302#endif
2303};
2304
2305/// A recipe for handling phis that are widened in the vector loop.
2306/// In the VPlan native path, all incoming VPValues & VPBasicBlock pairs are
2307/// managed in the recipe directly.
2309 /// List of incoming blocks. Only used in the VPlan native path.
2310 SmallVector<VPBasicBlock *, 2> IncomingBlocks;
2311
2312public:
2313 /// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start.
2314 VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr)
2315 : VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi) {
2316 if (Start)
2317 addOperand(Start);
2318 }
2319
2321 llvm_unreachable("cloning not implemented yet");
2322 }
2323
2324 ~VPWidenPHIRecipe() override = default;
2325
2326 VP_CLASSOF_IMPL(VPDef::VPWidenPHISC)
2327
2328 /// Generate the phi/select nodes.
2329 void execute(VPTransformState &State) override;
2330
2331#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2332 /// Print the recipe.
2333 void print(raw_ostream &O, const Twine &Indent,
2334 VPSlotTracker &SlotTracker) const override;
2335#endif
2336
2337 /// Adds a pair (\p IncomingV, \p IncomingBlock) to the phi.
2338 void addIncoming(VPValue *IncomingV, VPBasicBlock *IncomingBlock) {
2339 addOperand(IncomingV);
2340 IncomingBlocks.push_back(IncomingBlock);
2341 }
2342
2343 /// Returns the \p I th incoming VPBasicBlock.
2344 VPBasicBlock *getIncomingBlock(unsigned I) { return IncomingBlocks[I]; }
2345
2346 /// Returns the \p I th incoming VPValue.
2347 VPValue *getIncomingValue(unsigned I) { return getOperand(I); }
2348};
2349
2350/// A recipe for handling first-order recurrence phis. The start value is the
2351/// first operand of the recipe and the incoming value from the backedge is the
2352/// second operand.
2355 : VPHeaderPHIRecipe(VPDef::VPFirstOrderRecurrencePHISC, Phi, &Start) {}
2356
2357 VP_CLASSOF_IMPL(VPDef::VPFirstOrderRecurrencePHISC)
2358
2360 return R->getVPDefID() == VPDef::VPFirstOrderRecurrencePHISC;
2361 }
2362
2365 cast<PHINode>(getUnderlyingInstr()), *getOperand(0));
2366 }
2367
2368 void execute(VPTransformState &State) override;
2369
2370 /// Return the cost of this first-order recurrence phi recipe.
2372 VPCostContext &Ctx) const override;
2373
2374#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2375 /// Print the recipe.
2376 void print(raw_ostream &O, const Twine &Indent,
2377 VPSlotTracker &SlotTracker) const override;
2378#endif
2379};
2380
2381/// A recipe for handling reduction phis. The start value is the first operand
2382/// of the recipe and the incoming value from the backedge is the second
2383/// operand.
2385 public VPUnrollPartAccessor<2> {
2386 /// Descriptor for the reduction.
2387 const RecurrenceDescriptor &RdxDesc;
2388
2389 /// The phi is part of an in-loop reduction.
2390 bool IsInLoop;
2391
2392 /// The phi is part of an ordered reduction. Requires IsInLoop to be true.
2393 bool IsOrdered;
2394
2395 /// When expanding the reduction PHI, the plan's VF element count is divided
2396 /// by this factor to form the reduction phi's VF.
2397 unsigned VFScaleFactor = 1;
2398
2399public:
2400 /// Create a new VPReductionPHIRecipe for the reduction \p Phi described by \p
2401 /// RdxDesc.
2403 VPValue &Start, bool IsInLoop = false,
2404 bool IsOrdered = false, unsigned VFScaleFactor = 1)
2405 : VPHeaderPHIRecipe(VPDef::VPReductionPHISC, Phi, &Start),
2406 RdxDesc(RdxDesc), IsInLoop(IsInLoop), IsOrdered(IsOrdered),
2407 VFScaleFactor(VFScaleFactor) {
2408 assert((!IsOrdered || IsInLoop) && "IsOrdered requires IsInLoop");
2409 }
2410
2411 ~VPReductionPHIRecipe() override = default;
2412
2414 auto *R = new VPReductionPHIRecipe(cast<PHINode>(getUnderlyingInstr()),
2415 RdxDesc, *getOperand(0), IsInLoop,
2416 IsOrdered, VFScaleFactor);
2417 R->addOperand(getBackedgeValue());
2418 return R;
2419 }
2420
2421 VP_CLASSOF_IMPL(VPDef::VPReductionPHISC)
2422
2424 return R->getVPDefID() == VPDef::VPReductionPHISC;
2425 }
2426
2427 /// Generate the phi/select nodes.
2428 void execute(VPTransformState &State) override;
2429
2430#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2431 /// Print the recipe.
2432 void print(raw_ostream &O, const Twine &Indent,
2433 VPSlotTracker &SlotTracker) const override;
2434#endif
2435
2437 return RdxDesc;
2438 }
2439
2440 /// Returns true, if the phi is part of an ordered reduction.
2441 bool isOrdered() const { return IsOrdered; }
2442
2443 /// Returns true, if the phi is part of an in-loop reduction.
2444 bool isInLoop() const { return IsInLoop; }
2445};
2446
2447/// A recipe for forming partial reductions. In the loop, an accumulator and
2448/// vector operand are added together and passed to the next iteration as the
2449/// next accumulator. After the loop body, the accumulator is reduced to a
2450/// scalar value.
2452 unsigned Opcode;
2453
2454public:
2456 VPValue *Op1)
2457 : VPPartialReductionRecipe(ReductionInst->getOpcode(), Op0, Op1,
2458 ReductionInst) {}
2459 VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1,
2460 Instruction *ReductionInst = nullptr)
2461 : VPSingleDefRecipe(VPDef::VPPartialReductionSC,
2462 ArrayRef<VPValue *>({Op0, Op1}), ReductionInst),
2463 Opcode(Opcode) {
2464 auto *AccumulatorRecipe = getOperand(1)->getDefiningRecipe();
2465 assert((isa<VPReductionPHIRecipe>(AccumulatorRecipe) ||
2466 isa<VPPartialReductionRecipe>(AccumulatorRecipe)) &&
2467 "Unexpected operand order for partial reduction recipe");
2468 }
2469 ~VPPartialReductionRecipe() override = default;
2470
2472 return new VPPartialReductionRecipe(Opcode, getOperand(0), getOperand(1),
2474 }
2475
2476 VP_CLASSOF_IMPL(VPDef::VPPartialReductionSC)
2477
2478 /// Generate the reduction in the loop.
2479 void execute(VPTransformState &State) override;
2480
2481 /// Return the cost of this VPPartialReductionRecipe.
2483 VPCostContext &Ctx) const override;
2484
2485 /// Get the binary op's opcode.
2486 unsigned getOpcode() const { return Opcode; }
2487
2488#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2489 /// Print the recipe.
2490 void print(raw_ostream &O, const Twine &Indent,
2491 VPSlotTracker &SlotTracker) const override;
2492#endif
2493};
2494
2495/// A recipe for vectorizing a phi-node as a sequence of mask-based select
2496/// instructions.
2498public:
2499 /// The blend operation is a User of the incoming values and of their
2500 /// respective masks, ordered [I0, M0, I1, M1, I2, M2, ...]. Note that M0 can
2501 /// be omitted (implied by passing an odd number of operands) in which case
2502 /// all other incoming values are merged into it.
2504 : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, Phi->getDebugLoc()) {
2505 assert(Operands.size() > 0 && "Expected at least one operand!");
2506 }
2507
2508 VPBlendRecipe *clone() override {
2510 return new VPBlendRecipe(cast<PHINode>(getUnderlyingValue()), Ops);
2511 }
2512
2513 VP_CLASSOF_IMPL(VPDef::VPBlendSC)
2514
2515 /// A normalized blend is one that has an odd number of operands, whereby the
2516 /// first operand does not have an associated mask.
2517 bool isNormalized() const { return getNumOperands() % 2; }
2518
2519 /// Return the number of incoming values, taking into account when normalized
2520 /// the first incoming value will have no mask.
2521 unsigned getNumIncomingValues() const {
2522 return (getNumOperands() + isNormalized()) / 2;
2523 }
2524
2525 /// Return incoming value number \p Idx.
2526 VPValue *getIncomingValue(unsigned Idx) const {
2527 return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - isNormalized());
2528 }
2529
2530 /// Return mask number \p Idx.
2531 VPValue *getMask(unsigned Idx) const {
2532 assert((Idx > 0 || !isNormalized()) && "First index has no mask!");
2533 return Idx == 0 ? getOperand(1) : getOperand(Idx * 2 + !isNormalized());
2534 }
2535
2536 /// Generate the phi/select nodes.
2537 void execute(VPTransformState &State) override;
2538
2539 /// Return the cost of this VPWidenMemoryRecipe.
2541 VPCostContext &Ctx) const override;
2542
2543#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2544 /// Print the recipe.
2545 void print(raw_ostream &O, const Twine &Indent,
2546 VPSlotTracker &SlotTracker) const override;
2547#endif
2548
2549 /// Returns true if the recipe only uses the first lane of operand \p Op.
2550 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2552 "Op must be an operand of the recipe");
2553 // Recursing through Blend recipes only, must terminate at header phi's the
2554 // latest.
2555 return all_of(users(),
2556 [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
2557 }
2558};
2559
2560/// VPInterleaveRecipe is a recipe for transforming an interleave group of load
2561/// or stores into one wide load/store and shuffles. The first operand of a
2562/// VPInterleave recipe is the address, followed by the stored values, followed
2563/// by an optional mask.
2566
2567 /// Indicates if the interleave group is in a conditional block and requires a
2568 /// mask.
2569 bool HasMask = false;
2570
2571 /// Indicates if gaps between members of the group need to be masked out or if
2572 /// unusued gaps can be loaded speculatively.
2573 bool NeedsMaskForGaps = false;
2574
2575public:
2577 ArrayRef<VPValue *> StoredValues, VPValue *Mask,
2578 bool NeedsMaskForGaps)
2579 : VPRecipeBase(VPDef::VPInterleaveSC, {Addr}), IG(IG),
2580 NeedsMaskForGaps(NeedsMaskForGaps) {
2581 for (unsigned i = 0; i < IG->getFactor(); ++i)
2582 if (Instruction *I = IG->getMember(i)) {
2583 if (I->getType()->isVoidTy())
2584 continue;
2585 new VPValue(I, this);
2586 }
2587
2588 for (auto *SV : StoredValues)
2589 addOperand(SV);
2590 if (Mask) {
2591 HasMask = true;
2592 addOperand(Mask);
2593 }
2594 }
2595 ~VPInterleaveRecipe() override = default;
2596
2598 return new VPInterleaveRecipe(IG, getAddr(), getStoredValues(), getMask(),
2599 NeedsMaskForGaps);
2600 }
2601
2602 VP_CLASSOF_IMPL(VPDef::VPInterleaveSC)
2603
2604 /// Return the address accessed by this recipe.
2605 VPValue *getAddr() const {
2606 return getOperand(0); // Address is the 1st, mandatory operand.
2607 }
2608
2609 /// Return the mask used by this recipe. Note that a full mask is represented
2610 /// by a nullptr.
2611 VPValue *getMask() const {
2612 // Mask is optional and therefore the last, currently 2nd operand.
2613 return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
2614 }
2615
2616 /// Return the VPValues stored by this interleave group. If it is a load
2617 /// interleave group, return an empty ArrayRef.
2619 // The first operand is the address, followed by the stored values, followed
2620 // by an optional mask.
2623 }
2624
2625 /// Generate the wide load or store, and shuffles.
2626 void execute(VPTransformState &State) override;
2627
2628 /// Return the cost of this VPInterleaveRecipe.
2630 VPCostContext &Ctx) const override;
2631
2632#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2633 /// Print the recipe.
2634 void print(raw_ostream &O, const Twine &Indent,
2635 VPSlotTracker &SlotTracker) const override;
2636#endif
2637
2639
2640 /// Returns the number of stored operands of this interleave group. Returns 0
2641 /// for load interleave groups.
2642 unsigned getNumStoreOperands() const {
2643 return getNumOperands() - (HasMask ? 2 : 1);
2644 }
2645
2646 /// The recipe only uses the first lane of the address.
2647 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2649 "Op must be an operand of the recipe");
2650 return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
2651 }
2652
2653 Instruction *getInsertPos() const { return IG->getInsertPos(); }
2654};
2655
2656/// A recipe to represent inloop reduction operations, performing a reduction on
2657/// a vector operand into a scalar value, and adding the result to a chain.
2658/// The Operands are {ChainOp, VecOp, [Condition]}.
2660 /// The recurrence decriptor for the reduction in question.
2661 const RecurrenceDescriptor &RdxDesc;
2662 bool IsOrdered;
2663 /// Whether the reduction is conditional.
2664 bool IsConditional = false;
2665
2666protected:
2667 VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
2669 VPValue *CondOp, bool IsOrdered, DebugLoc DL)
2670 : VPSingleDefRecipe(SC, Operands, I, DL), RdxDesc(R),
2671 IsOrdered(IsOrdered) {
2672 if (CondOp) {
2673 IsConditional = true;
2674 addOperand(CondOp);
2675 }
2676 }
2677
2678public:
2680 VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2681 bool IsOrdered, DebugLoc DL = {})
2682 : VPReductionRecipe(VPDef::VPReductionSC, R, I,
2683 ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2684 IsOrdered, DL) {}
2685
2686 ~VPReductionRecipe() override = default;
2687
2689 return new VPReductionRecipe(RdxDesc, getUnderlyingInstr(), getChainOp(),
2690 getVecOp(), getCondOp(), IsOrdered,
2691 getDebugLoc());
2692 }
2693
2694 static inline bool classof(const VPRecipeBase *R) {
2695 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2696 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC;
2697 }
2698
2699 static inline bool classof(const VPUser *U) {
2700 auto *R = dyn_cast<VPRecipeBase>(U);
2701 return R && classof(R);
2702 }
2703
2704 /// Generate the reduction in the loop.
2705 void execute(VPTransformState &State) override;
2706
2707 /// Return the cost of VPReductionRecipe.
2709 VPCostContext &Ctx) const override;
2710
2711#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2712 /// Print the recipe.
2713 void print(raw_ostream &O, const Twine &Indent,
2714 VPSlotTracker &SlotTracker) const override;
2715#endif
2716
2717 /// Return the recurrence decriptor for the in-loop reduction.
2719 return RdxDesc;
2720 }
2721 /// Return true if the in-loop reduction is ordered.
2722 bool isOrdered() const { return IsOrdered; };
2723 /// Return true if the in-loop reduction is conditional.
2724 bool isConditional() const { return IsConditional; };
2725 /// The VPValue of the scalar Chain being accumulated.
2726 VPValue *getChainOp() const { return getOperand(0); }
2727 /// The VPValue of the vector value to be reduced.
2728 VPValue *getVecOp() const { return getOperand(1); }
2729 /// The VPValue of the condition for the block.
2731 return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
2732 }
2733};
2734
2735/// A recipe to represent inloop reduction operations with vector-predication
2736/// intrinsics, performing a reduction on a vector operand with the explicit
2737/// vector length (EVL) into a scalar value, and adding the result to a chain.
2738/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
2740public:
2743 VPDef::VPReductionEVLSC, R.getRecurrenceDescriptor(),
2745 ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2746 R.isOrdered(), R.getDebugLoc()) {}
2747
2748 ~VPReductionEVLRecipe() override = default;
2749
2751 llvm_unreachable("cloning not implemented yet");
2752 }
2753
2754 VP_CLASSOF_IMPL(VPDef::VPReductionEVLSC)
2755
2756 /// Generate the reduction in the loop
2757 void execute(VPTransformState &State) override;
2758
2759#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2760 /// Print the recipe.
2761 void print(raw_ostream &O, const Twine &Indent,
2762 VPSlotTracker &SlotTracker) const override;
2763#endif
2764
2765 /// The VPValue of the explicit vector length.
2766 VPValue *getEVL() const { return getOperand(2); }
2767
2768 /// Returns true if the recipe only uses the first lane of operand \p Op.
2769 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2771 "Op must be an operand of the recipe");
2772 return Op == getEVL();
2773 }
2774};
2775
2776/// VPReplicateRecipe replicates a given instruction producing multiple scalar
2777/// copies of the original scalar type, one per lane, instead of producing a
2778/// single copy of widened type for all lanes. If the instruction is known to be
2779/// uniform only one copy, per lane zero, will be generated.
2781 /// Indicator if only a single replica per lane is needed.
2782 bool IsUniform;
2783
2784 /// Indicator if the replicas are also predicated.
2785 bool IsPredicated;
2786
2787public:
2788 template <typename IterT>
2790 bool IsUniform, VPValue *Mask = nullptr)
2791 : VPRecipeWithIRFlags(VPDef::VPReplicateSC, Operands, *I),
2792 IsUniform(IsUniform), IsPredicated(Mask) {
2793 if (Mask)
2794 addOperand(Mask);
2795 }
2796
2797 ~VPReplicateRecipe() override = default;
2798
2800 auto *Copy =
2801 new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsUniform,
2802 isPredicated() ? getMask() : nullptr);
2803 Copy->transferFlags(*this);
2804 return Copy;
2805 }
2806
2807 VP_CLASSOF_IMPL(VPDef::VPReplicateSC)
2808
2809 /// Generate replicas of the desired Ingredient. Replicas will be generated
2810 /// for all parts and lanes unless a specific part and lane are specified in
2811 /// the \p State.
2812 void execute(VPTransformState &State) override;
2813
2814 /// Return the cost of this VPReplicateRecipe.
2816 VPCostContext &Ctx) const override;
2817
2818#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2819 /// Print the recipe.
2820 void print(raw_ostream &O, const Twine &Indent,
2821 VPSlotTracker &SlotTracker) const override;
2822#endif
2823
2824 bool isUniform() const { return IsUniform; }
2825
2826 bool isPredicated() const { return IsPredicated; }
2827
2828 /// Returns true if the recipe only uses the first lane of operand \p Op.
2829 bool onlyFirstLaneUsed(const VPValue *Op) const override {
2831 "Op must be an operand of the recipe");
2832 return isUniform();
2833 }
2834
2835 /// Returns true if the recipe uses scalars of operand \p Op.
2836 bool usesScalars(const VPValue *Op) const override {
2838 "Op must be an operand of the recipe");
2839 return true;
2840 }
2841
2842 /// Returns true if the recipe is used by a widened recipe via an intervening
2843 /// VPPredInstPHIRecipe. In this case, the scalar values should also be packed
2844 /// in a vector.
2845 bool shouldPack() const;
2846
2847 /// Return the mask of a predicated VPReplicateRecipe.
2849 assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
2850 return getOperand(getNumOperands() - 1);
2851 }
2852
2853 unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
2854};
2855
2856/// A recipe for generating conditional branches on the bits of a mask.
2858public:
2860 : VPRecipeBase(VPDef::VPBranchOnMaskSC, {}) {
2861 if (BlockInMask) // nullptr means all-one mask.
2862 addOperand(BlockInMask);
2863 }
2864
2866 return new VPBranchOnMaskRecipe(getOperand(0));
2867 }
2868
2869 VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)
2870
2871 /// Generate the extraction of the appropriate bit from the block mask and the
2872 /// conditional branch.
2873 void execute(VPTransformState &State) override;
2874
2875 /// Return the cost of this VPBranchOnMaskRecipe.
2877 VPCostContext &Ctx) const override;
2878
2879#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2880 /// Print the recipe.
2881 void print(raw_ostream &O, const Twine &Indent,
2882 VPSlotTracker &SlotTracker) const override {
2883 O << Indent << "BRANCH-ON-MASK ";
2884 if (VPValue *Mask = getMask())
2885 Mask->printAsOperand(O, SlotTracker);
2886 else
2887 O << " All-One";
2888 }
2889#endif
2890
2891 /// Return the mask used by this recipe. Note that a full mask is represented
2892 /// by a nullptr.
2893 VPValue *getMask() const {
2894 assert(getNumOperands() <= 1 && "should have either 0 or 1 operands");
2895 // Mask is optional.
2896 return getNumOperands() == 1 ? getOperand(0) : nullptr;
2897 }
2898
2899 /// Returns true if the recipe uses scalars of operand \p Op.
2900 bool usesScalars(const VPValue *Op) const override {
2902 "Op must be an operand of the recipe");
2903 return true;
2904 }
2905};
2906
2907/// VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when
2908/// control converges back from a Branch-on-Mask. The phi nodes are needed in
2909/// order to merge values that are set under such a branch and feed their uses.
2910/// The phi nodes can be scalar or vector depending on the users of the value.
2911/// This recipe works in concert with VPBranchOnMaskRecipe.
2913public:
2914 /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
2915 /// nodes after merging back from a Branch-on-Mask.
2917 : VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
2918 ~VPPredInstPHIRecipe() override = default;
2919
2921 return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
2922 }
2923
2924 VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)
2925
2926 /// Generates phi nodes for live-outs (from a replicate region) as needed to
2927 /// retain SSA form.
2928 void execute(VPTransformState &State) override;
2929
2930 /// Return the cost of this VPPredInstPHIRecipe.
2932 VPCostContext &Ctx) const override {
2933 // TODO: Compute accurate cost after retiring the legacy cost model.
2934 return 0;
2935 }
2936
2937#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2938 /// Print the recipe.
2939 void print(raw_ostream &O, const Twine &Indent,
2940 VPSlotTracker &SlotTracker) const override;
2941#endif
2942
2943 /// Returns true if the recipe uses scalars of operand \p Op.
2944 bool usesScalars(const VPValue *Op) const override {
2946 "Op must be an operand of the recipe");
2947 return true;
2948 }
2949};
2950
2951/// A common base class for widening memory operations. An optional mask can be
2952/// provided as the last operand.
2954protected:
2956
2957 /// Whether the accessed addresses are consecutive.
2959
2960 /// Whether the consecutive accessed addresses are in reverse order.
2962
2963 /// Whether the memory access is masked.
2964 bool IsMasked = false;
2965
2966 void setMask(VPValue *Mask) {
2967 assert(!IsMasked && "cannot re-set mask");
2968 if (!Mask)
2969 return;
2970 addOperand(Mask);
2971 IsMasked = true;
2972 }
2973
2974 VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
2975 std::initializer_list<VPValue *> Operands,
2976 bool Consecutive, bool Reverse, DebugLoc DL)
2978 Reverse(Reverse) {
2979 assert((Consecutive || !Reverse) && "Reverse implies consecutive");
2980 }
2981
2982public:
2984 llvm_unreachable("cloning not supported");
2985 }
2986
2987 static inline bool classof(const VPRecipeBase *R) {
2988 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
2989 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
2990 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
2991 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
2992 }
2993
2994 static inline bool classof(const VPUser *U) {
2995 auto *R = dyn_cast<VPRecipeBase>(U);
2996 return R && classof(R);
2997 }
2998
2999 /// Return whether the loaded-from / stored-to addresses are consecutive.
3000 bool isConsecutive() const { return Consecutive; }
3001
3002 /// Return whether the consecutive loaded/stored addresses are in reverse
3003 /// order.
3004 bool isReverse() const { return Reverse; }
3005
3006 /// Return the address accessed by this recipe.
3007 VPValue *getAddr() const { return getOperand(0); }
3008
3009 /// Returns true if the recipe is masked.
3010 bool isMasked() const { return IsMasked; }
3011
3012 /// Return the mask used by this recipe. Note that a full mask is represented
3013 /// by a nullptr.
3014 VPValue *getMask() const {
3015 // Mask is optional and therefore the last operand.
3016 return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
3017 }
3018
3019 /// Generate the wide load/store.
3020 void execute(VPTransformState &State) override {
3021 llvm_unreachable("VPWidenMemoryRecipe should not be instantiated.");
3022 }
3023
3024 /// Return the cost of this VPWidenMemoryRecipe.
3026 VPCostContext &Ctx) const override;
3027
3029};
3030
3031/// A recipe for widening load operations, using the address to load from and an
3032/// optional mask.
3033struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
3035 bool Consecutive, bool Reverse, DebugLoc DL)
3036 : VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
3037 Reverse, DL),
3038 VPValue(this, &Load) {
3039 setMask(Mask);
3040 }
3041
3043 return new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(),
3045 getDebugLoc());
3046 }
3047
3048 VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC);
3049
3050 /// Generate a wide load or gather.
3051 void execute(VPTransformState &State) override;
3052
3053#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3054 /// Print the recipe.
3055 void print(raw_ostream &O, const Twine &Indent,
3056 VPSlotTracker &SlotTracker) const override;
3057#endif
3058
3059 /// Returns true if the recipe only uses the first lane of operand \p Op.
3060 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3062 "Op must be an operand of the recipe");
3063 // Widened, consecutive loads operations only demand the first lane of
3064 // their address.
3065 return Op == getAddr() && isConsecutive();
3066 }
3067};
3068
3069/// A recipe for widening load operations with vector-predication intrinsics,
3070/// using the address to load from, the explicit vector length and an optional
3071/// mask.
3072struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
3074 : VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
3075 {L.getAddr(), &EVL}, L.isConsecutive(),
3076 L.isReverse(), L.getDebugLoc()),
3077 VPValue(this, &getIngredient()) {
3078 setMask(Mask);
3079 }
3080
3081 VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
3082
3083 /// Return the EVL operand.
3084 VPValue *getEVL() const { return getOperand(1); }
3085
3086 /// Generate the wide load or gather.
3087 void execute(VPTransformState &State) override;
3088
3089 /// Return the cost of this VPWidenLoadEVLRecipe.
3091 VPCostContext &Ctx) const override;
3092
3093#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3094 /// Print the recipe.
3095 void print(raw_ostream &O, const Twine &Indent,
3096 VPSlotTracker &SlotTracker) const override;
3097#endif
3098
3099 /// Returns true if the recipe only uses the first lane of operand \p Op.
3100 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3102 "Op must be an operand of the recipe");
3103 // Widened loads only demand the first lane of EVL and consecutive loads
3104 // only demand the first lane of their address.
3105 return Op == getEVL() || (Op == getAddr() && isConsecutive());
3106 }
3107};
3108
3109/// A recipe for widening store operations, using the stored value, the address
3110/// to store to and an optional mask.
3113 VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
3114 : VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
3116 setMask(Mask);
3117 }
3118
3120 return new VPWidenStoreRecipe(cast<StoreInst>(Ingredient), getAddr(),
3122 Reverse, getDebugLoc());
3123 }
3124
3125 VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC);
3126
3127 /// Return the value stored by this recipe.
3128 VPValue *getStoredValue() const { return getOperand(1); }
3129
3130 /// Generate a wide store or scatter.
3131 void execute(VPTransformState &State) override;
3132
3133#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3134 /// Print the recipe.
3135 void print(raw_ostream &O, const Twine &Indent,
3136 VPSlotTracker &SlotTracker) const override;
3137#endif
3138
3139 /// Returns true if the recipe only uses the first lane of operand \p Op.
3140 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3142 "Op must be an operand of the recipe");
3143 // Widened, consecutive stores only demand the first lane of their address,
3144 // unless the same operand is also stored.
3145 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3146 }
3147};
3148
3149/// A recipe for widening store operations with vector-predication intrinsics,
3150/// using the value to store, the address to store to, the explicit vector
3151/// length and an optional mask.
3154 : VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
3155 {S.getAddr(), S.getStoredValue(), &EVL},
3156 S.isConsecutive(), S.isReverse(), S.getDebugLoc()) {
3157 setMask(Mask);
3158 }
3159
3160 VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)
3161
3162 /// Return the address accessed by this recipe.
3163 VPValue *getStoredValue() const { return getOperand(1); }
3164
3165 /// Return the EVL operand.
3166 VPValue *getEVL() const { return getOperand(2); }
3167
3168 /// Generate the wide store or scatter.
3169 void execute(VPTransformState &State) override;
3170
3171 /// Return the cost of this VPWidenStoreEVLRecipe.
3173 VPCostContext &Ctx) const override;
3174
3175#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3176 /// Print the recipe.
3177 void print(raw_ostream &O, const Twine &Indent,
3178 VPSlotTracker &SlotTracker) const override;
3179#endif
3180
3181 /// Returns true if the recipe only uses the first lane of operand \p Op.
3182 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3184 "Op must be an operand of the recipe");
3185 if (Op == getEVL()) {
3186 assert(getStoredValue() != Op && "unexpected store of EVL");
3187 return true;
3188 }
3189 // Widened, consecutive memory operations only demand the first lane of
3190 // their address, unless the same operand is also stored. That latter can
3191 // happen with opaque pointers.
3192 return Op == getAddr() && isConsecutive() && Op != getStoredValue();
3193 }
3194};
3195
3196/// Recipe to expand a SCEV expression.
3198 const SCEV *Expr;
3199 ScalarEvolution &SE;
3200
3201public:
3203 : VPSingleDefRecipe(VPDef::VPExpandSCEVSC, {}), Expr(Expr), SE(SE) {}
3204
3205 ~VPExpandSCEVRecipe() override = default;
3206
3208 return new VPExpandSCEVRecipe(Expr, SE);
3209 }
3210
3211 VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)
3212
3213 /// Generate a canonical vector induction variable of the vector loop, with
3214 void execute(VPTransformState &State) override;
3215
3216 /// Return the cost of this VPExpandSCEVRecipe.
3218 VPCostContext &Ctx) const override {
3219 // TODO: Compute accurate cost after retiring the legacy cost model.
3220 return 0;
3221 }
3222
3223#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3224 /// Print the recipe.
3225 void print(raw_ostream &O, const Twine &Indent,
3226 VPSlotTracker &SlotTracker) const override;
3227#endif
3228
3229 const SCEV *getSCEV() const { return Expr; }
3230};
3231
3232/// Canonical scalar induction phi of the vector loop. Starting at the specified
3233/// start value (either 0 or the resume value when vectorizing the epilogue
3234/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
3235/// canonical induction variable.
3237public:
3239 : VPHeaderPHIRecipe(VPDef::VPCanonicalIVPHISC, nullptr, StartV, DL) {}
3240
3241 ~VPCanonicalIVPHIRecipe() override = default;
3242
3244 auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
3245 R->addOperand(getBackedgeValue());
3246 return R;
3247 }
3248
3249 VP_CLASSOF_IMPL(VPDef::VPCanonicalIVPHISC)
3250
3252 return D->getVPDefID() == VPDef::VPCanonicalIVPHISC;
3253 }
3254
3255 void execute(VPTransformState &State) override {
3257 "cannot execute this recipe, should be replaced by VPScalarPHIRecipe");
3258 }
3259
3260#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3261 /// Print the recipe.
3262 void print(raw_ostream &O, const Twine &Indent,
3263 VPSlotTracker &SlotTracker) const override;
3264#endif
3265
3266 /// Returns the scalar type of the induction.
3268 return getStartValue()->getLiveInIRValue()->getType();
3269 }
3270
3271 /// Returns true if the recipe only uses the first lane of operand \p Op.
3272 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3274 "Op must be an operand of the recipe");
3275 return true;
3276 }
3277
3278 /// Returns true if the recipe only uses the first part of operand \p Op.
3279 bool onlyFirstPartUsed(const VPValue *Op) const override {
3281 "Op must be an operand of the recipe");
3282 return true;
3283 }
3284
3285 /// Return the cost of this VPCanonicalIVPHIRecipe.
3287 VPCostContext &Ctx) const override {
3288 // For now, match the behavior of the legacy cost model.
3289 return 0;
3290 }
3291};
3292
3293/// A recipe for generating the active lane mask for the vector loop that is
3294/// used to predicate the vector operations.
3295/// TODO: It would be good to use the existing VPWidenPHIRecipe instead and
3296/// remove VPActiveLaneMaskPHIRecipe.
3298public:
3300 : VPHeaderPHIRecipe(VPDef::VPActiveLaneMaskPHISC, nullptr, StartMask,
3301 DL) {}
3302
3303 ~VPActiveLaneMaskPHIRecipe() override = default;
3304
3307 if (getNumOperands() == 2)
3308 R->addOperand(getOperand(1));
3309 return R;
3310 }
3311
3312 VP_CLASSOF_IMPL(VPDef::VPActiveLaneMaskPHISC)
3313
3315 return D->getVPDefID() == VPDef::VPActiveLaneMaskPHISC;
3316 }
3317
3318 /// Generate the active lane mask phi of the vector loop.
3319 void execute(VPTransformState &State) override;
3320
3321#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3322 /// Print the recipe.
3323 void print(raw_ostream &O, const Twine &Indent,
3324 VPSlotTracker &SlotTracker) const override;
3325#endif
3326};
3327
3328/// A recipe for generating the phi node for the current index of elements,
3329/// adjusted in accordance with EVL value. It starts at the start value of the
3330/// canonical induction and gets incremented by EVL in each iteration of the
3331/// vector loop.
3333public:
3335 : VPHeaderPHIRecipe(VPDef::VPEVLBasedIVPHISC, nullptr, StartIV, DL) {}
3336
3337 ~VPEVLBasedIVPHIRecipe() override = default;
3338
3340 llvm_unreachable("cloning not implemented yet");
3341 }
3342
3343 VP_CLASSOF_IMPL(VPDef::VPEVLBasedIVPHISC)
3344
3346 return D->getVPDefID() == VPDef::VPEVLBasedIVPHISC;
3347 }
3348
3349 void execute(VPTransformState &State) override {
3351 "cannot execute this recipe, should be replaced by VPScalarPHIRecipe");
3352 }
3353
3354 /// Return the cost of this VPEVLBasedIVPHIRecipe.
3356 VPCostContext &Ctx) const override {
3357 // For now, match the behavior of the legacy cost model.
3358 return 0;
3359 }
3360
3361 /// Returns true if the recipe only uses the first lane of operand \p Op.
3362 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3364 "Op must be an operand of the recipe");
3365 return true;
3366 }
3367
3368#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3369 /// Print the recipe.
3370 void print(raw_ostream &O, const Twine &Indent,
3371 VPSlotTracker &SlotTracker) const override;
3372#endif
3373};
3374
3375/// A Recipe for widening the canonical induction variable of the vector loop.
3377 public VPUnrollPartAccessor<1> {
3378public:
3380 : VPSingleDefRecipe(VPDef::VPWidenCanonicalIVSC, {CanonicalIV}) {}
3381
3382 ~VPWidenCanonicalIVRecipe() override = default;
3383
3385 return new VPWidenCanonicalIVRecipe(
3386 cast<VPCanonicalIVPHIRecipe>(getOperand(0)));
3387 }
3388
3389 VP_CLASSOF_IMPL(VPDef::VPWidenCanonicalIVSC)
3390
3391 /// Generate a canonical vector induction variable of the vector loop, with
3392 /// start = {<Part*VF, Part*VF+1, ..., Part*VF+VF-1> for 0 <= Part < UF}, and
3393 /// step = <VF*UF, VF*UF, ..., VF*UF>.
3394 void execute(VPTransformState &State) override;
3395
3396 /// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3398 VPCostContext &Ctx) const override {
3399 // TODO: Compute accurate cost after retiring the legacy cost model.
3400 return 0;
3401 }
3402
3403#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3404 /// Print the recipe.
3405 void print(raw_ostream &O, const Twine &Indent,
3406 VPSlotTracker &SlotTracker) const override;
3407#endif
3408};
3409
3410/// A recipe for converting the input value \p IV value to the corresponding
3411/// value of an IV with different start and step values, using Start + IV *
3412/// Step.
3414 /// Kind of the induction.
3416 /// If not nullptr, the floating point induction binary operator. Must be set
3417 /// for floating point inductions.
3418 const FPMathOperator *FPBinOp;
3419
3420 /// Name to use for the generated IR instruction for the derived IV.
3421 std::string Name;
3422
3423public:
3425 VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3426 const Twine &Name = "")
3428 IndDesc.getKind(),
3429 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3430 Start, CanonicalIV, Step, Name) {}
3431
3433 const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3434 VPValue *Step, const Twine &Name = "")
3435 : VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3436 FPBinOp(FPBinOp), Name(Name.str()) {}
3437
3438 ~VPDerivedIVRecipe() override = default;
3439
3441 return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
3442 getStepValue());
3443 }
3444
3445 VP_CLASSOF_IMPL(VPDef::VPDerivedIVSC)
3446
3447 /// Generate the transformed value of the induction at offset StartValue (1.
3448 /// operand) + IV (2. operand) * StepValue (3, operand).
3449 void execute(VPTransformState &State) override;
3450
3451 /// Return the cost of this VPDerivedIVRecipe.
3453 VPCostContext &Ctx) const override {
3454 // TODO: Compute accurate cost after retiring the legacy cost model.
3455 return 0;
3456 }
3457
3458#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3459 /// Print the recipe.
3460 void print(raw_ostream &O, const Twine &Indent,
3461 VPSlotTracker &SlotTracker) const override;
3462#endif
3463
3465 return getStartValue()->getLiveInIRValue()->getType();
3466 }
3467
3468 VPValue *getStartValue() const { return getOperand(0); }
3469 VPValue *getStepValue() const { return getOperand(2); }
3470
3471 /// Returns true if the recipe only uses the first lane of operand \p Op.
3472 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3474 "Op must be an operand of the recipe");
3475 return true;
3476 }
3477};
3478
3479/// A recipe for handling phi nodes of integer and floating-point inductions,
3480/// producing their scalar values.
3482 public VPUnrollPartAccessor<2> {
3483 Instruction::BinaryOps InductionOpcode;
3484
3485public:
3488 : VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
3489 ArrayRef<VPValue *>({IV, Step}), FMFs),
3490 InductionOpcode(Opcode) {}
3491
3493 VPValue *Step)
3495 IV, Step, IndDesc.getInductionOpcode(),
3496 dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
3497 ? IndDesc.getInductionBinOp()->getFastMathFlags()
3498 : FastMathFlags()) {}
3499
3500 ~VPScalarIVStepsRecipe() override = default;
3501
3503 return new VPScalarIVStepsRecipe(
3504 getOperand(0), getOperand(1), InductionOpcode,
3506 }
3507
3508 VP_CLASSOF_IMPL(VPDef::VPScalarIVStepsSC)
3509
3510 /// Generate the scalarized versions of the phi node as needed by their users.
3511 void execute(VPTransformState &State) override;
3512
3513 /// Return the cost of this VPScalarIVStepsRecipe.
3515 VPCostContext &Ctx) const override {
3516 // TODO: Compute accurate cost after retiring the legacy cost model.
3517 return 0;
3518 }
3519
3520#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3521 /// Print the recipe.
3522 void print(raw_ostream &O, const Twine &Indent,
3523 VPSlotTracker &SlotTracker) const override;
3524#endif
3525
3526 VPValue *getStepValue() const { return getOperand(1); }
3527
3528 /// Returns true if the recipe only uses the first lane of operand \p Op.
3529 bool onlyFirstLaneUsed(const VPValue *Op) const override {
3531 "Op must be an operand of the recipe");
3532 return true;
3533 }
3534};
3535
3536/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
3537/// holds a sequence of zero or more VPRecipe's each representing a sequence of
3538/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
3540 friend class VPlan;
3541
3542 /// Use VPlan::createVPBasicBlock to create VPBasicBlocks.
3543 VPBasicBlock(const Twine &Name = "", VPRecipeBase *Recipe = nullptr)
3544 : VPBlockBase(VPBasicBlockSC, Name.str()) {
3545 if (Recipe)
3546 appendRecipe(Recipe);
3547 }
3548
3549public:
3551
3552protected:
3553 /// The VPRecipes held in the order of output instructions to generate.
3555
3556 VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
3557 : VPBlockBase(BlockSC, Name.str()) {}
3558
3559public:
3560 ~VPBasicBlock() override {
3561 while (!Recipes.empty())
3562 Recipes.pop_back();
3563 }
3564
3565 /// Instruction iterators...
3570
3571 //===--------------------------------------------------------------------===//
3572 /// Recipe iterator methods
3573 ///
3574 inline iterator begin() { return Recipes.begin(); }
3575 inline const_iterator begin() const { return Recipes.begin(); }
3576 inline iterator end() { return Recipes.end(); }
3577 inline const_iterator end() const { return Recipes.end(); }
3578
3579 inline reverse_iterator rbegin() { return Recipes.rbegin(); }
3580 inline const_reverse_iterator rbegin() const { return Recipes.rbegin(); }
3581 inline reverse_iterator rend() { return Recipes.rend(); }
3582 inline const_reverse_iterator rend() const { return Recipes.rend(); }
3583
3584 inline size_t size() const { return Recipes.size(); }
3585 inline bool empty() const { return Recipes.empty(); }
3586 inline const VPRecipeBase &front() const { return Recipes.front(); }
3587 inline VPRecipeBase &front() { return Recipes.front(); }
3588 inline const VPRecipeBase &back() const { return Recipes.back(); }
3589 inline VPRecipeBase &back() { return Recipes.back(); }
3590
3591 /// Returns a reference to the list of recipes.
3593
3594 /// Returns a pointer to a member of the recipe list.
3596 return &VPBasicBlock::Recipes;
3597 }
3598
3599 /// Method to support type inquiry through isa, cast, and dyn_cast.
3600 static inline bool classof(const VPBlockBase *V) {
3601 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3602 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3603 }
3604
3605 void insert(VPRecipeBase *Recipe, iterator InsertPt) {
3606 assert(Recipe && "No recipe to append.");
3607 assert(!Recipe->Parent && "Recipe already in VPlan");
3608 Recipe->Parent = this;
3609 Recipes.insert(InsertPt, Recipe);
3610 }
3611
3612 /// Augment the existing recipes of a VPBasicBlock with an additional
3613 /// \p Recipe as the last recipe.
3614 void appendRecipe(VPRecipeBase *Recipe) { insert(Recipe, end()); }
3615
3616 /// The method which generates the output IR instructions that correspond to
3617 /// this VPBasicBlock, thereby "executing" the VPlan.
3618 void execute(VPTransformState *State) override;
3619
3620 /// Return the cost of this VPBasicBlock.
3622
3623 /// Return the position of the first non-phi node recipe in the block.
3625
3626 /// Returns an iterator range over the PHI-like recipes in the block.
3628 return make_range(begin(), getFirstNonPhi());
3629 }
3630
3631 /// Split current block at \p SplitAt by inserting a new block between the
3632 /// current block and its successors and moving all recipes starting at
3633 /// SplitAt to the new block. Returns the new block.
3634 VPBasicBlock *splitAt(iterator SplitAt);
3635
3638
3639#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3640 /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p
3641 /// SlotTracker is used to print unnamed VPValue's using consequtive numbers.
3642 ///
3643 /// Note that the numbering is applied to the whole VPlan, so printing
3644 /// individual blocks is consistent with the whole VPlan printing.
3645 void print(raw_ostream &O, const Twine &Indent,
3646 VPSlotTracker &SlotTracker) const override;
3647 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3648#endif
3649
3650 /// If the block has multiple successors, return the branch recipe terminating
3651 /// the block. If there are no or only a single successor, return nullptr;
3653 const VPRecipeBase *getTerminator() const;
3654
3655 /// Returns true if the block is exiting it's parent region.
3656 bool isExiting() const;
3657
3658 /// Clone the current block and it's recipes, without updating the operands of
3659 /// the cloned recipes.
3660 VPBasicBlock *clone() override;
3661
3662protected:
3663 /// Execute the recipes in the IR basic block \p BB.
3664 void executeRecipes(VPTransformState *State, BasicBlock *BB);
3665
3666 /// Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block
3667 /// generated for this VPBB.
3669
3670private:
3671 /// Create an IR BasicBlock to hold the output instructions generated by this
3672 /// VPBasicBlock, and return it. Update the CFGState accordingly.
3673 BasicBlock *createEmptyBasicBlock(VPTransformState::CFGState &CFG);
3674};
3675
3676/// A special type of VPBasicBlock that wraps an existing IR basic block.
3677/// Recipes of the block get added before the first non-phi instruction in the
3678/// wrapped block.
3679/// Note: At the moment, VPIRBasicBlock can only be used to wrap VPlan's
3680/// preheader block.
3682 friend class VPlan;
3683
3684 BasicBlock *IRBB;
3685
3686 /// Use VPlan::createVPIRBasicBlock to create VPIRBasicBlocks.
3688 : VPBasicBlock(VPIRBasicBlockSC,
3689 (Twine("ir-bb<") + IRBB->getName() + Twine(">")).str()),
3690 IRBB(IRBB) {}
3691
3692public:
3693 ~VPIRBasicBlock() override {}
3694
3695 static inline bool classof(const VPBlockBase *V) {
3696 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3697 }
3698
3699 /// The method which generates the output IR instructions that correspond to
3700 /// this VPBasicBlock, thereby "executing" the VPlan.
3701 void execute(VPTransformState *State) override;
3702
3703 VPIRBasicBlock *clone() override;
3704
3705 BasicBlock *getIRBasicBlock() const { return IRBB; }
3706};
3707
3708/// VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks
3709/// which form a Single-Entry-Single-Exiting subgraph of the output IR CFG.
3710/// A VPRegionBlock may indicate that its contents are to be replicated several
3711/// times. This is designed to support predicated scalarization, in which a
3712/// scalar if-then code structure needs to be generated VF * UF times. Having
3713/// this replication indicator helps to keep a single model for multiple
3714/// candidate VF's. The actual replication takes place only once the desired VF
3715/// and UF have been determined.
3717 friend class VPlan;
3718
3719 /// Hold the Single Entry of the SESE region modelled by the VPRegionBlock.
3720 VPBlockBase *Entry;
3721
3722 /// Hold the Single Exiting block of the SESE region modelled by the
3723 /// VPRegionBlock.
3724 VPBlockBase *Exiting;
3725
3726 /// An indicator whether this region is to generate multiple replicated
3727 /// instances of output IR corresponding to its VPBlockBases.
3728 bool IsReplicator;
3729
3730 /// Use VPlan::createVPRegionBlock to create VPRegionBlocks.
3731 VPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting,
3732 const std::string &Name = "", bool IsReplicator = false)
3733 : VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
3734 IsReplicator(IsReplicator) {
3735 assert(Entry->getPredecessors().empty() && "Entry block has predecessors.");
3736 assert(Exiting->getSuccessors().empty() && "Exit block has successors.");
3737 Entry->setParent(this);
3738 Exiting->setParent(this);
3739 }
3740 VPRegionBlock(const std::string &Name = "", bool IsReplicator = false)
3741 : VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
3742 IsReplicator(IsReplicator) {}
3743
3744public:
3745 ~VPRegionBlock() override {}
3746
3747 /// Method to support type inquiry through isa, cast, and dyn_cast.
3748 static inline bool classof(const VPBlockBase *V) {
3749 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
3750 }
3751
3752 const VPBlockBase *getEntry() const { return Entry; }
3753 VPBlockBase *getEntry() { return Entry; }
3754
3755 /// Set \p EntryBlock as the entry VPBlockBase of this VPRegionBlock. \p
3756 /// EntryBlock must have no predecessors.
3757 void setEntry(VPBlockBase *EntryBlock) {
3758 assert(EntryBlock->getPredecessors().empty() &&
3759 "Entry block cannot have predecessors.");
3760 Entry = EntryBlock;
3761 EntryBlock->setParent(this);
3762 }
3763
3764 const VPBlockBase *getExiting() const { return Exiting; }
3765 VPBlockBase *getExiting() { return Exiting; }
3766
3767 /// Set \p ExitingBlock as the exiting VPBlockBase of this VPRegionBlock. \p
3768 /// ExitingBlock must have no successors.
3769 void setExiting(VPBlockBase *ExitingBlock) {
3770 assert(ExitingBlock->getSuccessors().empty() &&
3771 "Exit block cannot have successors.");
3772 Exiting = ExitingBlock;
3773 ExitingBlock->setParent(this);
3774 }
3775
3776 /// Returns the pre-header VPBasicBlock of the loop region.
3778 assert(!isReplicator() && "should only get pre-header of loop regions");
3780 }
3781
3782 /// An indicator whether this region is to generate multiple replicated
3783 /// instances of output IR corresponding to its VPBlockBases.
3784 bool isReplicator() const { return IsReplicator; }
3785
3786 /// The method which generates the output IR instructions that correspond to
3787 /// this VPRegionBlock, thereby "executing" the VPlan.
3788 void execute(VPTransformState *State) override;
3789
3790 // Return the cost of this region.
3792
3793#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3794 /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with
3795 /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using
3796 /// consequtive numbers.
3797 ///
3798 /// Note that the numbering is applied to the whole VPlan, so printing
3799 /// individual regions is consistent with the whole VPlan printing.
3800 void print(raw_ostream &O, const Twine &Indent,
3801 VPSlotTracker &SlotTracker) const override;
3802 using VPBlockBase::print; // Get the print(raw_stream &O) version.
3803#endif
3804
3805 /// Clone all blocks in the single-entry single-exit region of the block and
3806 /// their recipes without updating the operands of the cloned recipes.
3807 VPRegionBlock *clone() override;
3808};
3809
3810/// VPlan models a candidate for vectorization, encoding various decisions take
3811/// to produce efficient output IR, including which branches, basic-blocks and
3812/// output IR instructions to generate, and their cost. VPlan holds a
3813/// Hierarchical-CFG of VPBasicBlocks and VPRegionBlocks rooted at an Entry
3814/// VPBasicBlock.
3815class VPlan {
3816 friend class VPlanPrinter;
3817 friend class VPSlotTracker;
3818
3819 /// VPBasicBlock corresponding to the original preheader. Used to place
3820 /// VPExpandSCEV recipes for expressions used during skeleton creation and the
3821 /// rest of VPlan execution.
3822 /// When this VPlan is used for the epilogue vector loop, the entry will be
3823 /// replaced by a new entry block created during skeleton creation.
3824 VPBasicBlock *Entry;
3825
3826 /// VPIRBasicBlock wrapping the header of the original scalar loop.
3827 VPIRBasicBlock *ScalarHeader;
3828
3829 /// Holds the VFs applicable to this VPlan.
3831
3832 /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
3833 /// any UF.
3835
3836 /// Holds the name of the VPlan, for printing.
3837 std::string Name;
3838
3839 /// Represents the trip count of the original loop, for folding
3840 /// the tail.
3841 VPValue *TripCount = nullptr;
3842
3843 /// Represents the backedge taken count of the original loop, for folding
3844 /// the tail. It equals TripCount - 1.
3845 VPValue *BackedgeTakenCount = nullptr;
3846
3847 /// Represents the vector trip count.
3848 VPValue VectorTripCount;
3849
3850 /// Represents the vectorization factor of the loop.
3851 VPValue VF;
3852
3853 /// Represents the loop-invariant VF * UF of the vector loop region.
3854 VPValue VFxUF;
3855
3856 /// Holds a mapping between Values and their corresponding VPValue inside
3857 /// VPlan.
3858 Value2VPValueTy Value2VPValue;
3859
3860 /// Contains all the external definitions created for this VPlan. External
3861 /// definitions are VPValues that hold a pointer to their underlying IR.
3862 SmallVector<VPValue *, 16> VPLiveInsToFree;
3863
3864 /// Mapping from SCEVs to the VPValues representing their expansions.
3865 /// NOTE: This mapping is temporary and will be removed once all users have
3866 /// been modeled in VPlan directly.
3867 DenseMap<const SCEV *, VPValue *> SCEVToExpansion;
3868
3869 /// Blocks allocated and owned by the VPlan. They will be deleted once the
3870 /// VPlan is destroyed.
3871 SmallVector<VPBlockBase *> CreatedBlocks;
3872
3873 /// Construct a VPlan with \p Entry to the plan and with \p ScalarHeader
3874 /// wrapping the original header of the scalar loop.
3875 VPlan(VPBasicBlock *Entry, VPIRBasicBlock *ScalarHeader)
3876 : Entry(Entry), ScalarHeader(ScalarHeader) {
3877 Entry->setPlan(this);
3878 assert(ScalarHeader->getNumSuccessors() == 0 &&
3879 "scalar header must be a leaf node");
3880 }
3881
3882public:
3883 /// Construct a VPlan for \p L. This will create VPIRBasicBlocks wrapping the
3884 /// original preheader and scalar header of \p L, to be used as entry and
3885 /// scalar header blocks of the new VPlan.
3886 VPlan(Loop *L);
3887
3888 /// Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock
3889 /// wrapping \p ScalarHeaderBB and a trip count of \p TC.
3890 VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC) {
3891 setEntry(createVPBasicBlock("preheader"));
3892 ScalarHeader = createVPIRBasicBlock(ScalarHeaderBB);
3893 TripCount = TC;
3894 }
3895
3896 ~VPlan();
3897
3899 Entry = VPBB;
3900 VPBB->setPlan(this);
3901 }
3902
3903 /// Create initial VPlan, having an "entry" VPBasicBlock (wrapping
3904 /// original scalar pre-header) which contains SCEV expansions that need
3905 /// to happen before the CFG is modified (when executing a VPlan for the
3906 /// epilogue vector loop, the original entry needs to be replaced by a new
3907 /// one); a VPBasicBlock for the vector pre-header, followed by a region for
3908 /// the vector loop, followed by the middle VPBasicBlock. If a check is needed
3909 /// to guard executing the scalar epilogue loop, it will be added to the
3910 /// middle block, together with VPBasicBlocks for the scalar preheader and
3911 /// exit blocks. \p InductionTy is the type of the canonical induction and
3912 /// used for related values, like the trip count expression.
3913 static VPlanPtr createInitialVPlan(Type *InductionTy,
3915 bool RequiresScalarEpilogueCheck,
3916 bool TailFolded, Loop *TheLoop);
3917
3918 /// Prepare the plan for execution, setting up the required live-in values.
3919 void prepareToExecute(Value *TripCount, Value *VectorTripCount,
3920 VPTransformState &State);
3921
3922 /// Generate the IR code for this VPlan.
3923 void execute(VPTransformState *State);
3924
3925 /// Return the cost of this plan.
3927
3928 VPBasicBlock *getEntry() { return Entry; }
3929 const VPBasicBlock *getEntry() const { return Entry; }
3930
3931 /// Returns the preheader of the vector loop region, if one exists, or null
3932 /// otherwise.
3934 VPRegionBlock *VectorRegion = getVectorLoopRegion();
3935 return VectorRegion
3936 ? cast<VPBasicBlock>(VectorRegion->getSinglePredecessor())
3937 : nullptr;
3938 }
3939
3940 /// Returns the VPRegionBlock of the vector loop.
3942 const VPRegionBlock *getVectorLoopRegion() const;
3943
3944 /// Returns the 'middle' block of the plan, that is the block that selects
3945 /// whether to execute the scalar tail loop or the exit block from the loop
3946 /// latch.
3948 return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
3949 }
3951 return cast<VPBasicBlock>(getScalarPreheader()->getPredecessors().front());
3952 }
3953
3954 /// Return the VPBasicBlock for the preheader of the scalar loop.
3956 return cast<VPBasicBlock>(getScalarHeader()->getSinglePredecessor());
3957 }
3958
3959 /// Return the VPIRBasicBlock wrapping the header of the scalar loop.
3960 VPIRBasicBlock *getScalarHeader() const { return ScalarHeader; }
3961
3962 /// Return an iterator range over the VPIRBasicBlock wrapping the exit blocks
3963 /// of the VPlan, that is leaf nodes except the scalar header. Defined in
3964 /// VPlanHCFG, as the definition of the type needs access to the definitions
3965 /// of VPBlockShallowTraversalWrapper.
3966 auto getExitBlocks();
3967
3968 /// The trip count of the original loop.
3970 assert(TripCount && "trip count needs to be set before accessing it");
3971 return TripCount;
3972 }
3973
3974 /// Resets the trip count for the VPlan. The caller must make sure all uses of
3975 /// the original trip count have been replaced.
3976 void resetTripCount(VPValue *NewTripCount) {
3977 assert(TripCount && NewTripCount && TripCount->getNumUsers() == 0 &&
3978 "TripCount always must be set");
3979 TripCount = NewTripCount;
3980 }
3981
3982 /// The backedge taken count of the original loop.
3984 if (!BackedgeTakenCount)
3985 BackedgeTakenCount = new VPValue();
3986 return BackedgeTakenCount;
3987 }
3988
3989 /// The vector trip count.
3990 VPValue &getVectorTripCount() { return VectorTripCount; }
3991
3992 /// Returns the VF of the vector loop region.
3993 VPValue &getVF() { return VF; };
3994
3995 /// Returns VF * UF of the vector loop region.
3996 VPValue &getVFxUF() { return VFxUF; }
3997
3998 void addVF(ElementCount VF) { VFs.insert(VF); }
3999
4001 assert(hasVF(VF) && "Cannot set VF not already in plan");
4002 VFs.clear();
4003 VFs.insert(VF);
4004 }
4005
4006 bool hasVF(ElementCount VF) { return VFs.count(VF); }
4008 return any_of(VFs, [](ElementCount VF) { return VF.isScalable(); });
4009 }
4010
4011 /// Returns an iterator range over all VFs of the plan.
4014 return {VFs.begin(), VFs.end()};
4015 }
4016
4017 bool hasScalarVFOnly() const { return VFs.size() == 1 && VFs[0].isScalar(); }
4018
4019 bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
4020
4021 unsigned getUF() const {
4022 assert(UFs.size() == 1 && "Expected a single UF");
4023 return UFs[0];
4024 }
4025
4026 void setUF(unsigned UF) {
4027 assert(hasUF(UF) && "Cannot set the UF not already in plan");
4028 UFs.clear();
4029 UFs.insert(UF);
4030 }
4031
4032 /// Return a string with the name of the plan and the applicable VFs and UFs.
4033 std::string getName() const;
4034
4035 void setName(const Twine &newName) { Name = newName.str(); }
4036
4037 /// Gets the live-in VPValue for \p V or adds a new live-in (if none exists
4038 /// yet) for \p V.
4040 assert(V && "Trying to get or add the VPValue of a null Value");
4041 if (!Value2VPValue.count(V)) {
4042 VPValue *VPV = new VPValue(V);
4043 VPLiveInsToFree.push_back(VPV);
4044 assert(VPV->isLiveIn() && "VPV must be a live-in.");
4045 assert(!Value2VPValue.count(V) && "Value already exists in VPlan");
4046 Value2VPValue[V] = VPV;
4047 }
4048
4049 assert(Value2VPValue.count(V) && "Value does not exist in VPlan");
4050 assert(Value2VPValue[V]->isLiveIn() &&
4051 "Only live-ins should be in mapping");
4052 return Value2VPValue[V];
4053 }
4054
4055 /// Return the live-in VPValue for \p V, if there is one or nullptr otherwise.
4056 VPValue *getLiveIn(Value *V) const { return Value2VPValue.lookup(V); }
4057
4058#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4059 /// Print the live-ins of this VPlan to \p O.
4060 void printLiveIns(raw_ostream &O) const;
4061
4062 /// Print this VPlan to \p O.
4063 void print(raw_ostream &O) const;
4064
4065 /// Print this VPlan in DOT format to \p O.
4066 void printDOT(raw_ostream &O) const;
4067
4068 /// Dump the plan to stderr (for debugging).
4069 LLVM_DUMP_METHOD void dump() const;
4070#endif
4071
4072 /// Returns the canonical induction recipe of the vector loop.
4075 if (EntryVPBB->empty()) {
4076 // VPlan native path.
4077 EntryVPBB = cast<VPBasicBlock>(EntryVPBB->getSingleSuccessor());
4078 }
4079 return cast<VPCanonicalIVPHIRecipe>(&*EntryVPBB->begin());
4080 }
4081
4082 VPValue *getSCEVExpansion(const SCEV *S) const {
4083 return SCEVToExpansion.lookup(S);
4084 }
4085
4086 void addSCEVExpansion(const SCEV *S, VPValue *V) {
4087 assert(!SCEVToExpansion.contains(S) && "SCEV already expanded");
4088 SCEVToExpansion[S] = V;
4089 }
4090
4091 /// Clone the current VPlan, update all VPValues of the new VPlan and cloned
4092 /// recipes to refer to the clones, and return it.
4093 VPlan *duplicate();
4094
4095 /// Create a new VPBasicBlock with \p Name and containing \p Recipe if
4096 /// present. The returned block is owned by the VPlan and deleted once the
4097 /// VPlan is destroyed.
4099 VPRecipeBase *Recipe = nullptr) {
4100 auto *VPB = new VPBasicBlock(Name, Recipe);
4101 CreatedBlocks.push_back(VPB);
4102 return VPB;
4103 }
4104
4105 /// Create a new VPRegionBlock with \p Entry, \p Exiting and \p Name. If \p
4106 /// IsReplicator is true, the region is a replicate region. The returned block
4107 /// is owned by the VPlan and deleted once the VPlan is destroyed.
4109 const std::string &Name = "",
4110 bool IsReplicator = false) {
4111 auto *VPB = new VPRegionBlock(Entry, Exiting, Name, IsReplicator);
4112 CreatedBlocks.push_back(VPB);
4113 return VPB;
4114 }
4115
4116 /// Create a new VPRegionBlock with \p Name and entry and exiting blocks set
4117 /// to nullptr. If \p IsReplicator is true, the region is a replicate region.
4118 /// The returned block is owned by the VPlan and deleted once the VPlan is
4119 /// destroyed.
4120 VPRegionBlock *createVPRegionBlock(const std::string &Name = "",
4121 bool IsReplicator = false) {
4122 auto *VPB = new VPRegionBlock(Name, IsReplicator);
4123 CreatedBlocks.push_back(VPB);
4124 return VPB;
4125 }
4126
4127 /// Create a VPIRBasicBlock wrapping \p IRBB, but do not create
4128 /// VPIRInstructions wrapping the instructions in t\p IRBB. The returned
4129 /// block is owned by the VPlan and deleted once the VPlan is destroyed.
4131
4132 /// Create a VPIRBasicBlock from \p IRBB containing VPIRInstructions for all
4133 /// instructions in \p IRBB, except its terminator which is managed by the
4134 /// successors of the block in VPlan. The returned block is owned by the VPlan
4135 /// and deleted once the VPlan is destroyed.
4137};
4138
4139#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4140/// VPlanPrinter prints a given VPlan to a given output stream. The printing is
4141/// indented and follows the dot format.
4143 raw_ostream &OS;
4144 const VPlan &Plan;
4145 unsigned Depth = 0;
4146 unsigned TabWidth = 2;
4147 std::string Indent;
4148 unsigned BID = 0;
4150
4152
4153 /// Handle indentation.
4154 void bumpIndent(int b) { Indent = std::string((Depth += b) * TabWidth, ' '); }
4155
4156 /// Print a given \p Block of the Plan.
4157 void dumpBlock(const VPBlockBase *Block);
4158
4159 /// Print the information related to the CFG edges going out of a given
4160 /// \p Block, followed by printing the successor blocks themselves.
4161 void dumpEdges(const VPBlockBase *Block);
4162
4163 /// Print a given \p BasicBlock, including its VPRecipes, followed by printing
4164 /// its successor blocks.
4165 void dumpBasicBlock(const VPBasicBlock *BasicBlock);
4166
4167 /// Print a given \p Region of the Plan.
4168 void dumpRegion(const VPRegionBlock *Region);
4169
4170 unsigned getOrCreateBID(const VPBlockBase *Block) {
4171 return BlockID.count(Block) ? BlockID[Block] : BlockID[Block] = BID++;
4172 }
4173
4174 Twine getOrCreateName(const VPBlockBase *Block);
4175
4176 Twine getUID(const VPBlockBase *Block);
4177
4178 /// Print the information related to a CFG edge between two VPBlockBases.
4179 void drawEdge(const VPBlockBase *From, const VPBlockBase *To, bool Hidden,
4180 const Twine &Label);
4181
4182public:
4184 : OS(O), Plan(P), SlotTracker(&P) {}
4185
4186 LLVM_DUMP_METHOD void dump();
4187};
4188
4190 const Value *V;
4191
4192 VPlanIngredient(const Value *V) : V(V) {}
4193
4194 void print(raw_ostream &O) const;
4195};
4196
4198 I.print(OS);
4199 return OS;
4200}
4201
4203 Plan.print(OS);
4204 return OS;
4205}
4206#endif
4207
4210 InterleaveGroupMap;
4211
4212 /// Type for mapping of instruction based interleave groups to VPInstruction
4213 /// interleave groups
4216
4217 /// Recursively \p Region and populate VPlan based interleave groups based on
4218 /// \p IAI.
4219 void visitRegion(VPRegionBlock *Region, Old2NewTy &Old2New,
4221 /// Recursively traverse \p Block and populate VPlan based interleave groups
4222 /// based on \p IAI.
4223 void visitBlock(VPBlockBase *Block, Old2NewTy &Old2New,
4225
4226public:
4228
4231 // Avoid releasing a pointer twice.
4232 for (auto &I : InterleaveGroupMap)
4233 DelSet.insert(I.second);
4234 for (auto *Ptr : DelSet)
4235 delete Ptr;
4236 }
4237
4238 /// Get the interleave group that \p Instr belongs to.
4239 ///
4240 /// \returns nullptr if doesn't have such group.
4243 return InterleaveGroupMap.lookup(Instr);
4244 }
4245};
4246
4247/// Class that maps (parts of) an existing VPlan to trees of combined
4248/// VPInstructions.
4250 enum class OpMode { Failed, Load, Opcode };
4251
4252 /// A DenseMapInfo implementation for using SmallVector<VPValue *, 4> as
4253 /// DenseMap keys.
4254 struct BundleDenseMapInfo {
4255 static SmallVector<VPValue *, 4> getEmptyKey() {
4256 return {reinterpret_cast<VPValue *>(-1)};
4257 }
4258
4259 static SmallVector<VPValue *, 4> getTombstoneKey() {
4260 return {reinterpret_cast<VPValue *>(-2)};
4261 }
4262
4263 static unsigned getHashValue(const SmallVector<VPValue *, 4> &V) {
4264 return static_cast<unsigned>(hash_combine_range(V.begin(), V.end()));
4265 }
4266
4267 static bool isEqual(const SmallVector<VPValue *, 4> &LHS,
4269 return LHS == RHS;
4270 }
4271 };
4272
4273 /// Mapping of values in the original VPlan to a combined VPInstruction.
4275 BundleToCombined;
4276
4278
4279 /// Basic block to operate on. For now, only instructions in a single BB are
4280 /// considered.
4281 const VPBasicBlock &BB;
4282
4283 /// Indicates whether we managed to combine all visited instructions or not.
4284 bool CompletelySLP = true;
4285
4286 /// Width of the widest combined bundle in bits.
4287 unsigned WidestBundleBits = 0;
4288
4289 using MultiNodeOpTy =
4290 typename std::pair<VPInstruction *, SmallVector<VPValue *, 4>>;
4291
4292 // Input operand bundles for the current multi node. Each multi node operand
4293 // bundle contains values not matching the multi node's opcode. They will
4294 // be reordered in reorderMultiNodeOps, once we completed building a
4295 // multi node.
4296 SmallVector<MultiNodeOpTy, 4> MultiNodeOps;
4297
4298 /// Indicates whether we are building a multi node currently.
4299 bool MultiNodeActive = false;
4300
4301 /// Check if we can vectorize Operands together.
4302 bool areVectorizable(ArrayRef<VPValue *> Operands) const;
4303
4304 /// Add combined instruction \p New for the bundle \p Operands.
4305 void addCombined(ArrayRef<VPValue *> Operands, VPInstruction *New);
4306
4307 /// Indicate we hit a bundle we failed to combine. Returns nullptr for now.
4308 VPInstruction *markFailed();
4309
4310 /// Reorder operands in the multi node to maximize sequential memory access
4311 /// and commutative operations.
4312 SmallVector<MultiNodeOpTy, 4> reorderMultiNodeOps();
4313
4314 /// Choose the best candidate to use for the lane after \p Last. The set of
4315 /// candidates to choose from are values with an opcode matching \p Last's
4316 /// or loads consecutive to \p Last.
4317 std::pair<OpMode, VPValue *> getBest(OpMode Mode, VPValue *Last,
4318 SmallPtrSetImpl<VPValue *> &Candidates,
4320
4321#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4322 /// Print bundle \p Values to dbgs().
4323 void dumpBundle(ArrayRef<VPValue *> Values);
4324#endif
4325
4326public:
4327 VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB) : IAI(IAI), BB(BB) {}
4328
4329 ~VPlanSlp() = default;
4330
4331 /// Tries to build an SLP tree rooted at \p Operands and returns a
4332 /// VPInstruction combining \p Operands, if they can be combined.
4334
4335 /// Return the width of the widest combined bundle in bits.
4336 unsigned getWidestBundleBits() const { return WidestBundleBits; }
4337
4338 /// Return true if all visited instruction can be combined.
4339 bool isCompletelySLP() const { return CompletelySLP; }
4340};
4341} // end namespace llvm
4342
4343#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
aarch64 promote const
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
always inline
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the DenseMap class.
uint64_t Addr
std::string Name
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1315
Flatten the CFG
Hexagon Common GEP
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
#define P(N)
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file implements the SmallBitVector class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This pass exposes codegen information to IR-level passes.
This file contains the declarations of the entities induced by Vectorization Plans,...
#define VP_CLASSOF_IMPL(VPDefID)
Definition: VPlan.h:821
Value * RHS
Value * LHS
static const uint32_t IV[8]
Definition: blake3_impl.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:198
LLVM Basic Block Representation.
Definition: BasicBlock.h:61
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:444
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Definition: InstrTypes.h:608
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:22
This class represents an Operation in the Expression.
A debug info location.
Definition: DebugLoc.h:33
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:152
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition: DenseMap.h:147
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
constexpr bool isScalar() const
Exactly one element.
Definition: TypeSize.h:322
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition: Operator.h:205
Convenience struct for specifying and reasoning about fast-math flags.
Definition: FMF.h:20
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Definition: Instructions.h:933
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:113
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 mayWriteToMemory() const LLVM_READONLY
Return true if this instruction may modify memory.
bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
bool mayReadFromMemory() const LLVM_READONLY
Return true if this instruction may read memory.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:274
The group of interleaved loads/stores sharing the same stride and close to each other.
Definition: VectorUtils.h:488
uint32_t getFactor() const
Definition: VectorUtils.h:504
InstTy * getMember(uint32_t Index) const
Get the member with the given index Index.
Definition: VectorUtils.h:558
InstTy * getInsertPos() const
Definition: VectorUtils.h:574
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:630
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
An instruction for reading from memory.
Definition: Instructions.h:176
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
Definition: ModRef.h:198
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:195
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: IVDescriptors.h:77
This class represents an analyzed expression in the program.
The main scalar evolution driver.
This class represents the LLVM 'select' instruction.
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:98
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:113
void clear()
Completely clear the SetVector.
Definition: SetVector.h:273
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:264
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:93
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:103
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:162
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
Definition: SetVector.h:254
This class provides computation of slot numbers for LLVM Assembly writing.
Definition: AsmWriter.cpp:698
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:363
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:370
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
iterator erase(const_iterator CI)
Definition: SmallVector.h:737
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
An instruction for storing to memory.
Definition: Instructions.h:292
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
Iterator to iterate over vectorization factors in a VFRange.
Definition: VPlan.h:121
ElementCount operator*() const
Definition: VPlan.h:129
iterator & operator++()
Definition: VPlan.h:131
iterator(ElementCount VF)
Definition: VPlan.h:125
bool operator==(const iterator &Other) const
Definition: VPlan.h:127
A recipe for generating the active lane mask for the vector loop that is used to predicate the vector...
Definition: VPlan.h:3297
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:3305
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:3314
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
Definition: VPlan.h:3299
~VPActiveLaneMaskPHIRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:3539
RecipeListTy::const_iterator const_iterator
Definition: VPlan.h:3567
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
Definition: VPlan.h:3614
RecipeListTy::const_reverse_iterator const_reverse_iterator
Definition: VPlan.h:3569
RecipeListTy::iterator iterator
Instruction iterators...
Definition: VPlan.h:3566
void connectToPredecessors(VPTransformState::CFGState &CFG)
Connect the VPBBs predecessors' in the VPlan CFG to the IR basic block generated for this VPBB.
Definition: VPlan.cpp:415
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:480
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
Definition: VPlan.h:3592
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
Definition: VPlan.h:3556
iterator end()
Definition: VPlan.h:3576
iterator begin()
Recipe iterator methods.
Definition: VPlan.h:3574
RecipeListTy::reverse_iterator reverse_iterator
Definition: VPlan.h:3568
VPBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition: VPlan.cpp:517
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
Definition: VPlan.h:3627
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of this VPBasicBlock.
Definition: VPlan.cpp:758
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
Definition: VPlan.cpp:208
~VPBasicBlock() override
Definition: VPlan.h:3560
VPRegionBlock * getEnclosingLoopRegion()
Definition: VPlan.cpp:566
const_reverse_iterator rbegin() const
Definition: VPlan.h:3580
reverse_iterator rend()
Definition: VPlan.h:3581
VPBasicBlock * splitAt(iterator SplitAt)
Split current block at SplitAt by inserting a new block between the current block and its successors ...
Definition: VPlan.cpp:536
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
Definition: VPlan.h:3554
void executeRecipes(VPTransformState *State, BasicBlock *BB)
Execute the recipes in the IR basic block BB.
Definition: VPlan.cpp:524
VPRecipeBase & back()
Definition: VPlan.h:3589
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPBsicBlock to O, prefixing all lines with Indent.
Definition: VPlan.cpp:631
const VPRecipeBase & front() const
Definition: VPlan.h:3586
const_iterator begin() const
Definition: VPlan.h:3575
VPRecipeBase & front()
Definition: VPlan.h:3587
bool isExiting() const
Returns true if the block is exiting it's parent region.
Definition: VPlan.cpp:614
VPRecipeBase * getTerminator()
If the block has multiple successors, return the branch recipe terminating the block.
Definition: VPlan.cpp:602
const VPRecipeBase & back() const
Definition: VPlan.h:3588
void insert(VPRecipeBase *Recipe, iterator InsertPt)
Definition: VPlan.h:3605
bool empty() const
Definition: VPlan.h:3585
const_iterator end() const
Definition: VPlan.h:3577
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:3600
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
Definition: VPlan.h:3595
reverse_iterator rbegin()
Definition: VPlan.h:3579
size_t size() const
Definition: VPlan.h:3584
const_reverse_iterator rend() const
Definition: VPlan.h:3582
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition: VPlan.h:2497
VPBlendRecipe(PHINode *Phi, ArrayRef< VPValue * > Operands)
The blend operation is a User of the incoming values and of their respective masks,...
Definition: VPlan.h:2503
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenMemoryRecipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2550
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
Definition: VPlan.h:2526
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
Definition: VPlan.h:2531
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
Definition: VPlan.h:2521
VPBlendRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2508
void execute(VPTransformState &State) override
Generate the phi/select nodes.
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:2517
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:397
void setSuccessors(ArrayRef< VPBlockBase * > NewSuccs)
Set each VPBasicBlock in NewSuccss as successor of this VPBlockBase.
Definition: VPlan.h:613
VPRegionBlock * getParent()
Definition: VPlan.h:489
VPBlocksTy & getPredecessors()
Definition: VPlan.h:521
iterator_range< VPBlockBase ** > predecessors()
Definition: VPlan.h:518
const VPBasicBlock * getExitingBasicBlock() const
Definition: VPlan.cpp:178
LLVM_DUMP_METHOD void dump() const
Dump this VPBlockBase to dbgs().
Definition: VPlan.h:672
void setName(const Twine &newName)
Definition: VPlan.h:482
size_t getNumSuccessors() const
Definition: VPlan.h:535
iterator_range< VPBlockBase ** > successors()
Definition: VPlan.h:517
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.
void swapSuccessors()
Swap successors of the block. The block must have exactly 2 successors.
Definition: VPlan.h:628
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:619
bool isLegalToHoistInto()
Return true if it is legal to hoist instructions into this block.
Definition: VPlan.h:641
virtual ~VPBlockBase()=default
void print(raw_ostream &O) const
Print plain-text dump of this VPlan to O.
Definition: VPlan.h:662
const VPBlocksTy & getHierarchicalPredecessors()
Definition: VPlan.h:571
size_t getNumPredecessors() const
Definition: VPlan.h:536
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition: VPlan.h:604
VPBlockBase * getEnclosingBlockWithPredecessors()
Definition: VPlan.cpp:200
const VPBlocksTy & getPredecessors() const
Definition: VPlan.h:520
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:474
virtual InstructionCost cost(ElementCount VF, VPCostContext &Ctx)=0
Return the cost of the block.
VPlan * getPlan()
Definition: VPlan.cpp:153
void setPlan(VPlan *ParentPlan)
Sets the pointer of the plan containing the block.
Definition: VPlan.cpp:172
const VPRegionBlock * getParent() const
Definition: VPlan.h:490
const std::string & getName() const
Definition: VPlan.h:480
void clearSuccessors()
Remove all the successors of this block.
Definition: VPlan.h:623
VPBlockBase * getSingleHierarchicalSuccessor()
Definition: VPlan.h:561
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
Definition: VPlan.h:595
VPBlockBase * getSinglePredecessor() const
Definition: VPlan.h:531
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:555
void clearPredecessors()
Remove all the predecessor of this block.
Definition: VPlan.h:620
unsigned getVPBlockID() const
Definition: VPlan.h:487
void printAsOperand(raw_ostream &OS, bool PrintType=false) const
Definition: VPlan.h:648
VPBlockBase(const unsigned char SC, const std::string &N)
Definition: VPlan.h:466
VPBlocksTy & getSuccessors()
Definition: VPlan.h:515
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
Definition: VPlan.cpp:192
const VPBasicBlock * getEntryBasicBlock() const
Definition: VPlan.cpp:158
void setOneSuccessor(VPBlockBase *Successor)
Set a given VPBlockBase Successor as the single successor of this VPBlockBase.
Definition: VPlan.h:584
void setParent(VPRegionBlock *P)
Definition: VPlan.h:500
VPBlockBase * getSingleHierarchicalPredecessor()
Definition: VPlan.h:577
VPBlockBase * getSingleSuccessor() const
Definition: VPlan.h:525
const VPBlocksTy & getSuccessors() const
Definition: VPlan.h:514
Class that provides utilities for VPBlockBases in VPlan.
Definition: VPlanUtils.h:79
A recipe for generating conditional branches on the bits of a mask.
Definition: VPlan.h:2857
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:2893
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPBranchOnMaskRecipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Definition: VPlan.h:2881
VPBranchOnMaskRecipe(VPValue *BlockInMask)
Definition: VPlan.h:2859
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2865
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2900
void execute(VPTransformState &State) override
Generate the extraction of the appropriate bit from the block mask and the conditional branch.
Canonical scalar induction phi of the vector loop.
Definition: VPlan.h:3236
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition: VPlan.h:3279
~VPCanonicalIVPHIRecipe() override=default
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:3251
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3243
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
Definition: VPlan.h:3238
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3272
Type * getScalarType() const
Returns the scalar type of the induction.
Definition: VPlan.h:3267
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition: VPlan.h:3255
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPCanonicalIVPHIRecipe.
Definition: VPlan.h:3286
This class augments a recipe with a set of VPValues defined by the recipe.
Definition: VPlanValue.h:298
unsigned getVPDefID() const
Definition: VPlanValue.h:426
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition: VPlan.h:3413
void execute(VPTransformState &State) override
Generate the transformed value of the induction at offset StartValue (1.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPDerivedIVRecipe.
Definition: VPlan.h:3452
VPValue * getStepValue() const
Definition: VPlan.h:3469
Type * getScalarType() const
Definition: VPlan.h:3464
VPDerivedIVRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3440
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
Definition: VPlan.h:3432
~VPDerivedIVRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3472
VPValue * getStartValue() const
Definition: VPlan.h:3468
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Definition: VPlan.h:3424
A recipe for generating the phi node for the current index of elements, adjusted in accordance with E...
Definition: VPlan.h:3332
static bool classof(const VPHeaderPHIRecipe *D)
Definition: VPlan.h:3345
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPEVLBasedIVPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3339
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
Definition: VPlan.h:3349
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
Definition: VPlan.h:3355
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
Definition: VPlan.h:3334
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3362
Recipe to expand a SCEV expression.
Definition: VPlan.h:3197
VPExpandSCEVRecipe(const SCEV *Expr, ScalarEvolution &SE)
Definition: VPlan.h:3202
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
Definition: VPlan.h:3217
const SCEV * getSCEV() const
Definition: VPlan.h:3229
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpandSCEVRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3207
~VPExpandSCEVRecipe() override=default
A pure virtual base class for all recipes modeling header phis, including phis for first order recurr...
Definition: VPlan.h:2033
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this header phi recipe.
static bool classof(const VPValue *V)
Definition: VPlan.h:2050
VPHeaderPHIRecipe(unsigned char VPDefID, Instruction *UnderlyingInstr, VPValue *Start=nullptr, DebugLoc DL={})
Definition: VPlan.h:2035
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override=0
Print the recipe.
virtual VPValue * getBackedgeValue()
Returns the incoming value from the loop backedge.
Definition: VPlan.h:2081
VPValue * getStartValue()
Returns the start value of the phi, if one is set.
Definition: VPlan.h:2070
void setStartValue(VPValue *V)
Update the start value of the recipe.
Definition: VPlan.h:2078
VPValue * getStartValue() const
Definition: VPlan.h:2073
static bool classof(const VPRecipeBase *B)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:2046
void execute(VPTransformState &State) override=0
Generate the phi nodes.
virtual VPRecipeBase & getBackedgeRecipe()
Returns the backedge value as a recipe.
Definition: VPlan.h:2087
~VPHeaderPHIRecipe() override=default
A recipe representing a sequence of load -> update -> store as part of a histogram operation.
Definition: VPlan.h:1783
void execute(VPTransformState &State) override
Produce a vectorized histogram operation.
VP_CLASSOF_IMPL(VPDef::VPHistogramSC)
VPHistogramRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1795
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHistogramRecipe.
VPHistogramRecipe(unsigned Opcode, iterator_range< IterT > Operands, DebugLoc DL={})
Definition: VPlan.h:1789
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:1812
unsigned getOpcode() const
Definition: VPlan.h:1808
~VPHistogramRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
A special type of VPBasicBlock that wraps an existing IR basic block.
Definition: VPlan.h:3681
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
Definition: VPlan.cpp:451
BasicBlock * getIRBasicBlock() const
Definition: VPlan.h:3705
~VPIRBasicBlock() override
Definition: VPlan.h:3693
static bool classof(const VPBlockBase *V)
Definition: VPlan.h:3695
VPIRBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Definition: VPlan.cpp:473
A recipe to wrap on original IR instruction not to be modified during execution, execept for PHIs.
Definition: VPlan.h:1382
Instruction & getInstruction() const
Definition: VPlan.h:1406
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first part of operand Op.
Definition: VPlan.h:1420
~VPIRInstruction() override=default
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1426
VPIRInstruction * clone() override
Clone the current recipe.
Definition: VPlan.h:1393
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPIRInstruction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool usesScalars(const VPValue *Op) const override
Returns true if the VPUser uses scalars of operand Op.
Definition: VPlan.h:1414
VPIRInstruction(Instruction &I)
Definition: VPlan.h:1386
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:1194
VPInstruction(VPValue *Ptr, VPValue *Offset, GEPNoWrapFlags Flags, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:1294
VPInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
Definition: VPlan.h:1269
VPInstruction * clone() override
Clone the current recipe.
Definition: VPlan.h:1305
bool hasResult() const
Definition: VPlan.h:1335
bool opcodeMayReadOrWriteFromMemory() const
Returns true if the underlying opcode may read from or write to memory.
LLVM_DUMP_METHOD void dump() const
Print the VPInstruction to dbgs() (for debugging).
StringRef getName() const
Returns the symbolic name assigned to the VPInstruction.
Definition: VPlan.h:1375
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInstruction.
Definition: VPlan.h:1320
unsigned getOpcode() const
Definition: VPlan.h:1312
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, WrapFlagsTy WrapFlags, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:1281
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:1274
@ ResumePhi
Creates a scalar phi in a leaf VPBB with a single predecessor in VPlan.
Definition: VPlan.h:1212
@ FirstOrderRecurrenceSplice
Definition: VPlan.h:1200
@ CanonicalIVIncrementForPart
Definition: VPlan.h:1215
@ CalculateTripCountMinusVF
Definition: VPlan.h:1213
VPInstruction(unsigned Opcode, std::initializer_list< VPValue * > Operands, DisjointFlagsTy DisjointFlag, DebugLoc DL={}, const Twine &Name="")
Definition: VPlan.h:1286
bool isVectorToScalar() const
Returns true if this VPInstruction produces a scalar value from a vector, e.g.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the VPInstruction to O.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
bool isSingleScalar() const
Returns true if this VPInstruction's operands are single scalars and the result is also a single scal...
void execute(VPTransformState &State) override
Generate the instruction.
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition: VPlan.h:2564
bool onlyFirstLaneUsed(const VPValue *Op) const override
The recipe only uses the first lane of the address.
Definition: VPlan.h:2647
~VPInterleaveRecipe() override=default
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition: VPlan.h:2605
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps)
Definition: VPlan.h:2576
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:2611
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPInterleaveRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2597
void execute(VPTransformState &State) override
Generate the wide load or store, and shuffles.
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
Definition: VPlan.h:2618
Instruction * getInsertPos() const
Definition: VPlan.h:2653
const InterleaveGroup< Instruction > * getInterleaveGroup()
Definition: VPlan.h:2638
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInterleaveRecipe.
unsigned getNumStoreOperands() const
Returns the number of stored operands of this interleave group.
Definition: VPlan.h:2642
InterleaveGroup< VPInstruction > * getInterleaveGroup(VPInstruction *Instr) const
Get the interleave group that Instr belongs to.
Definition: VPlan.h:4242
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
Definition: VPlan.h:153
static VPLane getLastLaneForVF(const ElementCount &VF)
Definition: VPlan.h:194
static unsigned getNumCachedLanes(const ElementCount &VF)
Returns the maxmimum number of lanes that we are able to consider caching for VF.
Definition: VPlan.h:229
Value * getAsRuntimeExpr(IRBuilderBase &Builder, const ElementCount &VF) const
Returns an expression describing the lane index that can be used at runtime.
Definition: VPlan.cpp:73
VPLane(unsigned Lane, Kind LaneKind)
Definition: VPlan.h:176
Kind getKind() const
Returns the Kind of lane offset.
Definition: VPlan.h:210
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset)
Definition: VPlan.h:180
bool isFirstLane() const
Returns true if this is the first lane of the whole vector.
Definition: VPlan.h:213
VPLane(unsigned Lane)
Definition: VPlan.h:175
unsigned getKnownLane() const
Returns a compile-time known value for the lane index and asserts if the lane can only be calculated ...
Definition: VPlan.h:200
static VPLane getFirstLane()
Definition: VPlan.h:178
Kind
Kind describes how to interpret Lane.
Definition: VPlan.h:156
@ ScalableLast
For ScalableLast, Lane is the offset from the start of the last N-element subvector in a scalable vec...
@ First
For First, Lane is the index into the first N elements of a fixed-vector <N x <ElTy>> or a scalable v...
unsigned mapToCacheIndex(const ElementCount &VF) const
Maps the lane to a cache index based on VF.
Definition: VPlan.h:216
A recipe for forming partial reductions.
Definition: VPlan.h:2451
~VPPartialReductionRecipe() override=default
void execute(VPTransformState &State) override
Generate the reduction in the loop.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPartialReductionRecipe.
unsigned getOpcode() const
Get the binary op's opcode.
Definition: VPlan.h:2486
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, Instruction *ReductionInst=nullptr)
Definition: VPlan.h:2459
VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0, VPValue *Op1)
Definition: VPlan.h:2455
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2471
VPPredInstPHIRecipe is a recipe for generating the phi nodes needed when control converges back from ...
Definition: VPlan.h:2912
~VPPredInstPHIRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2944
void execute(VPTransformState &State) override
Generates phi nodes for live-outs (from a replicate region) as needed to retain SSA form.
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2920
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
Definition: VPlan.h:2931
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
Definition: VPlan.h:2916
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:716
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:805
bool mayHaveSideEffects() const
Returns true if the recipe may have side-effects.
bool mayWriteToMemory() const
Returns true if the recipe may write to memory.
virtual InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const
Compute the cost of this recipe either using a recipe's specialized implementation or using the legac...
virtual ~VPRecipeBase()=default
VPBasicBlock * getParent()
Definition: VPlan.h:741
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
Definition: VPlan.h:810
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:783
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
VPRecipeBase(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL={})
Definition: VPlan.h:727
virtual VPRecipeBase * clone()=0
Clone the current recipe.
const VPBasicBlock * getParent() const
Definition: VPlan.h:742
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:788
VPRecipeBase(const unsigned char SC, iterator_range< IterT > Operands, DebugLoc DL={})
Definition: VPlan.h:732
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool isPhi() const
Returns true for PHI-like recipes.
Definition: VPlan.h:794
void moveAfter(VPRecipeBase *MovePos)
Unlink this recipe from its current VPBasicBlock and insert it into the VPBasicBlock that MovePos liv...
Class to record LLVM IR flag for a recipe along with it.
Definition: VPlan.h:927
ExactFlagsTy ExactFlags
Definition: VPlan.h:977
FastMathFlagsTy FMFs
Definition: VPlan.h:980
NonNegFlagsTy NonNegFlags
Definition: VPlan.h:979
CmpInst::Predicate CmpPredicate
Definition: VPlan.h:974
GEPNoWrapFlags getGEPNoWrapFlags() const
Definition: VPlan.h:1147
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, CmpInst::Predicate Pred, DebugLoc DL={})
Definition: VPlan.h:1029
void setFlags(Instruction *I) const
Set the IR flags for I.
Definition: VPlan.h:1108
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, GEPNoWrapFlags GEPFlags, DebugLoc DL={})
Definition: VPlan.h:1054
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:1060
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, FastMathFlags FMFs, DebugLoc DL={})
Definition: VPlan.h:1041
void dropPoisonGeneratingFlags()
Drop all poison-generating flags.
Definition: VPlan.h:1077
bool hasFastMathFlags() const
Returns true if the recipe has fast-math flags.
Definition: VPlan.h:1150
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, Instruction &I)
Definition: VPlan.h:999
DisjointFlagsTy DisjointFlags
Definition: VPlan.h:976
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, WrapFlagsTy WrapFlags, DebugLoc DL={})
Definition: VPlan.h:1035
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DisjointFlagsTy DisjointFlags, DebugLoc DL={})
Definition: VPlan.h:1047
GEPNoWrapFlags GEPFlags
Definition: VPlan.h:978
void transferFlags(VPRecipeWithIRFlags &Other)
Definition: VPlan.h:985
WrapFlagsTy WrapFlags
Definition: VPlan.h:975
bool hasNoUnsignedWrap() const
Definition: VPlan.h:1154
bool isDisjoint() const
Definition: VPlan.h:1166
void printFlags(raw_ostream &O) const
CmpInst::Predicate getPredicate() const
Definition: VPlan.h:1141
bool hasNoSignedWrap() const
Definition: VPlan.h:1160
static bool classof(const VPUser *U)
Definition: VPlan.h:1071
FastMathFlags getFastMathFlags() const
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands, DebugLoc DL={})
Definition: VPlan.h:992
A recipe to represent inloop reduction operations with vector-predication intrinsics,...
Definition: VPlan.h:2739
void execute(VPTransformState &State) override
Generate the reduction in the loop.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2769
VPValue * getEVL() const
The VPValue of the explicit vector length.
Definition: VPlan.h:2766
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp)
Definition: VPlan.h:2741
VPReductionEVLRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2750
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPReductionEVLRecipe() override=default
A recipe for handling reduction phis.
Definition: VPlan.h:2385
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
Definition: VPlan.h:2441
VPReductionPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2413
~VPReductionPHIRecipe() override=default
VPReductionPHIRecipe(PHINode *Phi, const RecurrenceDescriptor &RdxDesc, VPValue &Start, bool IsInLoop=false, bool IsOrdered=false, unsigned VFScaleFactor=1)
Create a new VPReductionPHIRecipe for the reduction Phi described by RdxDesc.
Definition: VPlan.h:2402
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
Definition: VPlan.h:2444
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:2423
const RecurrenceDescriptor & getRecurrenceDescriptor() const
Definition: VPlan.h:2436
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
Definition: VPlan.h:2659
bool isConditional() const
Return true if the in-loop reduction is conditional.
Definition: VPlan.h:2724
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:2694
VPReductionRecipe(const RecurrenceDescriptor &R, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL={})
Definition: VPlan.h:2679
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
Definition: VPlan.h:2667
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of VPReductionRecipe.
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
Definition: VPlan.h:2728
const RecurrenceDescriptor & getRecurrenceDescriptor() const
Return the recurrence decriptor for the in-loop reduction.
Definition: VPlan.h:2718
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPValue * getCondOp() const
The VPValue of the condition for the block.
Definition: VPlan.h:2730
bool isOrdered() const
Return true if the in-loop reduction is ordered.
Definition: VPlan.h:2722
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
Definition: VPlan.h:2726
VPReductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2688
void execute(VPTransformState &State) override
Generate the reduction in the loop.
static bool classof(const VPUser *U)
Definition: VPlan.h:2699
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:3716
VPRegionBlock * clone() override
Clone all blocks in the single-entry single-exit region of the block and their recipes without updati...
Definition: VPlan.cpp:702
const VPBlockBase * getEntry() const
Definition: VPlan.h:3752
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
Definition: VPlan.h:3784
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
Definition: VPlan.h:3769
VPBlockBase * getExiting()
Definition: VPlan.h:3765
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
Definition: VPlan.h:3757
InstructionCost cost(ElementCount VF, VPCostContext &Ctx) override
Return the cost of the block.
Definition: VPlan.cpp:765
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print this VPRegionBlock to O (recursively), prefixing all lines with Indent.
Definition: VPlan.cpp:803
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPRegionBlock,...
Definition: VPlan.cpp:711
const VPBlockBase * getExiting() const
Definition: VPlan.h:3764
VPBlockBase * getEntry()
Definition: VPlan.h:3753
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
Definition: VPlan.h:3777
~VPRegionBlock() override
Definition: VPlan.h:3745
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
Definition: VPlan.h:3748
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition: VPlan.h:2780
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate replicas of the desired Ingredient.
~VPReplicateRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPReplicateRecipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2829
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
Definition: VPlan.h:2836
bool isUniform() const
Definition: VPlan.h:2824
bool isPredicated() const
Definition: VPlan.h:2826
VPReplicateRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2799
VPReplicateRecipe(Instruction *I, iterator_range< IterT > Operands, bool IsUniform, VPValue *Mask=nullptr)
Definition: VPlan.h:2789
unsigned getOpcode() const
Definition: VPlan.h:2853
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
Definition: VPlan.h:2848
bool shouldPack() const
Returns true if the recipe is used by a widened recipe via an intervening VPPredInstPHIRecipe.
A recipe to compute the pointers for widened memory accesses of IndexTy in reverse order.
Definition: VPlan.h:1910
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPVectorPointerRecipe.
Definition: VPlan.h:1934
VPReverseVectorPointerRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1948
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition: VPlan.h:1941
void print(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 onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1927
VPReverseVectorPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition: VPlan.h:1914
const VPValue * getVFValue() const
Definition: VPlan.h:1923
VPScalarCastRecipe is a recipe to create scalar cast instructions.
Definition: VPlan.h:1587
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarCastRecipe.
Definition: VPlan.h:1612
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Each concrete VPDef prints itself.
~VPScalarCastRecipe() override=default
VPScalarCastRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1602
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1626
VPScalarCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, DebugLoc DL)
Definition: VPlan.h:1595
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
Type * getResultType() const
Returns the result type of the cast.
Definition: VPlan.h:1624
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition: VPlan.h:3482
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3529
VPValue * getStepValue() const
Definition: VPlan.h:3526
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
Definition: VPlan.h:3514
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step)
Definition: VPlan.h:3492
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3502
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, Instruction::BinaryOps Opcode, FastMathFlags FMFs)
Definition: VPlan.h:3486
~VPScalarIVStepsRecipe() override=default
void execute(VPTransformState &State) override
Generate the scalarized versions of the phi node as needed by their users.
Recipe to generate a scalar PHI.
Definition: VPlan.h:2269
VPScalarPHIRecipe(VPValue *Start, VPValue *BackedgeValue, DebugLoc DL, StringRef Name)
Definition: VPlan.h:2273
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:2292
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPScalarPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPScalarPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2282
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition: VPlan.h:843
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL={})
Definition: VPlan.h:849
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
Definition: VPlan.h:913
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:858
const Instruction * getUnderlyingInstr() const
Definition: VPlan.h:916
VPSingleDefRecipe(const unsigned char SC, IterT Operands, DebugLoc DL={})
Definition: VPlan.h:846
static bool classof(const VPUser *U)
Definition: VPlan.h:905
LLVM_DUMP_METHOD void dump() const
Print this VPSingleDefRecipe to dbgs() (for debugging).
VPSingleDefRecipe(const unsigned char SC, IterT Operands, Value *UV, DebugLoc DL={})
Definition: VPlan.h:854
virtual VPSingleDefRecipe * clone() override=0
Clone the current recipe.
This class can be used to assign names to VPValues.
Definition: VPlanValue.h:447
An analysis for type-inference for VPValues.
Definition: VPlanAnalysis.h:40
Helper to access the operand that contains the unroll part for this recipe after unrolling.
Definition: VPlan.h:1179
VPValue * getUnrollPartOperand(VPUser &U) const
Return the VPValue operand containing the unroll part or null if there is no such operand.
unsigned getUnrollPart(VPUser &U) const
Return the unroll part.
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition: VPlanValue.h:206
operand_range operands()
Definition: VPlanValue.h:263
void setOperand(unsigned I, VPValue *New)
Definition: VPlanValue.h:248
unsigned getNumOperands() const
Definition: VPlanValue.h:242
operand_iterator op_end()
Definition: VPlanValue.h:261
operand_iterator op_begin()
Definition: VPlanValue.h:259
VPValue * getOperand(unsigned N) const
Definition: VPlanValue.h:243
VPUser()=delete
void addOperand(VPValue *Operand)
Definition: VPlanValue.h:237
bool isDefinedOutsideLoopRegions() const
Returns true if the VPValue is defined outside any loop region.
Definition: VPlan.cpp:1417
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition: VPlan.cpp:123
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
Definition: VPlanValue.h:89
unsigned getNumUsers() const
Definition: VPlanValue.h:117
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition: VPlanValue.h:178
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition: VPlanValue.h:173
friend class VPRecipeBase
Definition: VPlanValue.h:56
user_range users()
Definition: VPlanValue.h:138
A recipe to compute the pointers for widened memory accesses of IndexTy.
Definition: VPlan.h:1963
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
Definition: VPlan.h:1967
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
Definition: VPlan.h:1984
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
Definition: VPlan.h:1977
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
Definition: VPlan.h:1997
VPVectorPointerRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1991
A recipe for widening Call instructions using library calls.
Definition: VPlan.h:1727
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
const_operand_range arg_operands() const
Definition: VPlan.h:1767
VPWidenCallRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1746
Function * getCalledScalarFunction() const
Definition: VPlan.h:1760
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCallRecipe.
void execute(VPTransformState &State) override
Produce a widened version of the call instruction.
operand_range arg_operands()
Definition: VPlan.h:1764
~VPWidenCallRecipe() override=default
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, DebugLoc DL={})
Definition: VPlan.h:1734
A Recipe for widening the canonical induction variable of the vector loop.
Definition: VPlan.h:3377
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with start = {<Part*VF,...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPWidenCanonicalIVRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCanonicalIVPHIRecipe.
Definition: VPlan.h:3397
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3384
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
Definition: VPlan.h:3379
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition: VPlan.h:1535
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, CastInst &UI)
Definition: VPlan.h:1543
Instruction::CastOps getOpcode() const
Definition: VPlan.h:1580
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Returns the result type of the cast.
Definition: VPlan.h:1583
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
Definition: VPlan.h:1551
void execute(VPTransformState &State) override
Produce widened copies of the cast.
~VPWidenCastRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCastRecipe.
VPWidenCastRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1557
A recipe for widening operations with vector-predication intrinsics with explicit vector length (EVL)...
Definition: VPlan.h:1488
const VPValue * getEVL() const
Definition: VPlan.h:1512
~VPWidenEVLRecipe() override=default
VPWidenEVLRecipe(Instruction &I, iterator_range< IterT > Operands, VPValue &EVL)
Definition: VPlan.h:1493
VPWidenRecipe * clone() override final
Clone the current recipe.
Definition: VPlan.h:1504
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override final
Print the recipe.
VP_CLASSOF_IMPL(VPDef::VPWidenEVLSC)
VPWidenEVLRecipe(VPWidenRecipe &W, VPValue &EVL)
Definition: VPlan.h:1497
void execute(VPTransformState &State) override final
Produce a vp-intrinsic using the opcode and operands of the recipe, processing EVL elements.
VPValue * getEVL()
Definition: VPlan.h:1511
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:1519
A recipe for handling GEP instructions.
Definition: VPlan.h:1861
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the gep nodes.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
Definition: VPlan.h:1894
VPWidenGEPRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1883
~VPWidenGEPRecipe() override=default
VPWidenGEPRecipe(GetElementPtrInst *GEP, iterator_range< IterT > Operands)
Definition: VPlan.h:1878
Base class for widened induction (VPWidenIntOrFpInductionRecipe and VPWidenPointerInductionRecipe),...
Definition: VPlan.h:2095
static bool classof(const VPValue *V)
Definition: VPlan.h:2111
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
Definition: VPlan.h:2131
PHINode * getPHINode() const
Definition: VPlan.h:2126
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition: VPlan.h:2099
VPValue * getStepValue()
Returns the step value of the induction.
Definition: VPlan.h:2123
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
Definition: VPlan.h:2129
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
Definition: VPlan.h:2138
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:2106
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:2116
const VPValue * getStepValue() const
Definition: VPlan.h:2124
virtual void execute(VPTransformState &State) override=0
Generate the phi nodes.
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition: VPlan.h:2148
const TruncInst * getTruncInst() const
Definition: VPlan.h:2202
const VPValue * getVFValue() const
Definition: VPlan.h:2191
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
Definition: VPlan.h:2161
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2172
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
Definition: VPlan.h:2201
void execute(VPTransformState &State) override
Generate the vectorized and scalarized versions of the phi node as needed by their users.
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
Definition: VPlan.h:2152
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
Definition: VPlan.h:2217
Type * getScalarType() const
Returns the scalar type of the induction.
Definition: VPlan.h:2210
bool isCanonical() const
Returns true if the induction is canonical, i.e.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
A recipe for widening vector intrinsics.
Definition: VPlan.h:1635
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, std::initializer_list< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1676
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
Definition: VPlan.h:1700
bool mayReadFromMemory() const
Returns true if the intrinsic may read from memory.
Definition: VPlan.h:1709
StringRef getIntrinsicName() const
Return to name of the intrinsic as string.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1661
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
Definition: VPlan.h:1715
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1684
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
Definition: VPlan.h:1712
~VPWidenIntrinsicRecipe() override=default
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
Type * getResultType() const
Return the scalar return type of the intrinsic.
Definition: VPlan.h:1703
void execute(VPTransformState &State) override
Produce a widened version of the vector intrinsic.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this vector intrinsic.
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL={})
Definition: VPlan.h:1652
A common base class for widening memory operations.
Definition: VPlan.h:2953
bool IsMasked
Whether the memory access is masked.
Definition: VPlan.h:2964
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
Definition: VPlan.h:2961
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
Definition: VPlan.h:3000
static bool classof(const VPUser *U)
Definition: VPlan.h:2994
void execute(VPTransformState &State) override
Generate the wide load/store.
Definition: VPlan.h:3020
Instruction & Ingredient
Definition: VPlan.h:2955
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2983
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenMemoryRecipe.
Instruction & getIngredient() const
Definition: VPlan.h:3028
bool Consecutive
Whether the accessed addresses are consecutive.
Definition: VPlan.h:2958
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:2987
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:2974
VPValue * getMask() const
Return the mask used by this recipe.
Definition: VPlan.h:3014
bool isMasked() const
Returns true if the recipe is masked.
Definition: VPlan.h:3010
void setMask(VPValue *Mask)
Definition: VPlan.h:2966
VPValue * getAddr() const
Return the address accessed by this recipe.
Definition: VPlan.h:3007
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
Definition: VPlan.h:3004
A recipe for handling phis that are widened in the vector loop.
Definition: VPlan.h:2308
void addIncoming(VPValue *IncomingV, VPBasicBlock *IncomingBlock)
Adds a pair (IncomingV, IncomingBlock) to the phi.
Definition: VPlan.h:2338
VPValue * getIncomingValue(unsigned I)
Returns the I th incoming VPValue.
Definition: VPlan.h:2347
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start=nullptr)
Create a new VPWidenPHIRecipe for Phi with start value Start.
Definition: VPlan.h:2314
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenPHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2320
~VPWidenPHIRecipe() override=default
VPBasicBlock * getIncomingBlock(unsigned I)
Returns the I th incoming VPBasicBlock.
Definition: VPlan.h:2344
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2238
~VPWidenPointerInductionRecipe() override=default
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, bool IsScalarAfterVectorization, DebugLoc DL)
Create a new VPWidenPointerInductionRecipe for Phi with start value Start.
Definition: VPlan.h:2229
bool onlyScalarsGenerated(bool IsScalable)
Returns true if only scalar values will be generated.
VPValue * getFirstUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the first unrolled part,...
Definition: VPlan.h:2255
void execute(VPTransformState &State) override
Generate vector values for the pointer induction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition: VPlan.h:1437
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenRecipe.
void execute(VPTransformState &State) override
Produce a widened instruction using the opcode and operands of the recipe, processing State....
VPWidenRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1453
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPWidenRecipe() override=default
VPWidenRecipe(Instruction &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1448
unsigned getOpcode() const
Definition: VPlan.h:1477
VPWidenRecipe(unsigned VPDefOpcode, Instruction &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1442
static bool classof(const VPRecipeBase *R)
Definition: VPlan.h:1459
static bool classof(const VPUser *U)
Definition: VPlan.h:1464
VPlanPrinter prints a given VPlan to a given output stream.
Definition: VPlan.h:4142
VPlanPrinter(raw_ostream &O, const VPlan &P)
Definition: VPlan.h:4183
LLVM_DUMP_METHOD void dump()
Definition: VPlan.cpp:1274
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
Definition: VPlan.h:4249
VPInstruction * buildGraph(ArrayRef< VPValue * > Operands)
Tries to build an SLP tree rooted at Operands and returns a VPInstruction combining Operands,...
Definition: VPlanSLP.cpp:359
bool isCompletelySLP() const
Return true if all visited instruction can be combined.
Definition: VPlan.h:4339
~VPlanSlp()=default
VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB)
Definition: VPlan.h:4327
unsigned getWidestBundleBits() const
Return the width of the widest combined bundle in bits.
Definition: VPlan.h:4336
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3815
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
Definition: VPlan.cpp:1145
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
Definition: VPlan.cpp:1121
void prepareToExecute(Value *TripCount, Value *VectorTripCount, VPTransformState &State)
Prepare the plan for execution, setting up the required live-in values.
Definition: VPlan.cpp:924
bool hasScalableVF()
Definition: VPlan.h:4007
VPBasicBlock * getEntry()
Definition: VPlan.h:3928
VPRegionBlock * createVPRegionBlock(VPBlockBase *Entry, VPBlockBase *Exiting, const std::string &Name="", bool IsReplicator=false)
Create a new VPRegionBlock with Entry, Exiting and Name.
Definition: VPlan.h:4108
VPValue & getVectorTripCount()
The vector trip count.
Definition: VPlan.h:3990
void setName(const Twine &newName)
Definition: VPlan.h:4035
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
Definition: VPlan.h:3996
VPValue & getVF()
Returns the VF of the vector loop region.
Definition: VPlan.h:3993
VPValue * getTripCount() const
The trip count of the original loop.
Definition: VPlan.h:3969
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
Definition: VPlan.h:3983
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
Definition: VPlan.h:4013
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
Definition: VPlan.h:3890
const VPBasicBlock * getEntry() const
Definition: VPlan.h:3929
unsigned getUF() const
Definition: VPlan.h:4021
static VPlanPtr createInitialVPlan(Type *InductionTy, PredicatedScalarEvolution &PSE, bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop)
Create initial VPlan, having an "entry" VPBasicBlock (wrapping original scalar pre-header) which cont...
Definition: VPlan.cpp:845
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
Definition: VPlan.cpp:1246
bool hasVF(ElementCount VF)
Definition: VPlan.h:4006
void addSCEVExpansion(const SCEV *S, VPValue *V)
Definition: VPlan.h:4086
bool hasUF(unsigned UF) const
Definition: VPlan.h:4019
void setVF(ElementCount VF)
Definition: VPlan.h:4000
VPRegionBlock * createVPRegionBlock(const std::string &Name="", bool IsReplicator=false)
Create a new VPRegionBlock with Name and entry and exiting blocks set to nullptr.
Definition: VPlan.h:4120
auto getExitBlocks()
Return an iterator range over the VPIRBasicBlock wrapping the exit blocks of the VPlan,...
Definition: VPlanCFG.h:310
VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
Definition: VPlan.cpp:1052
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
Definition: VPlan.cpp:1046
const VPBasicBlock * getMiddleBlock() const
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
Definition: VPlan.h:3947
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
Definition: VPlan.h:3976
VPBasicBlock * getMiddleBlock()
Definition: VPlan.h:3950
void setEntry(VPBasicBlock *VPBB)
Definition: VPlan.h:3898
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
Definition: VPlan.h:4098
VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
Definition: VPlan.cpp:1252
VPValue * getOrAddLiveIn(Value *V)
Gets the live-in VPValue for V or adds a new live-in (if none exists yet) for V.
Definition: VPlan.h:4039
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
Definition: VPlan.cpp:1151
bool hasScalarVFOnly() const
Definition: VPlan.h:4017
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
Definition: VPlan.h:3955
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
Definition: VPlan.cpp:956
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the vector loop.
Definition: VPlan.h:4073
void print(raw_ostream &O) const
Print this VPlan to O.
Definition: VPlan.cpp:1104
void addVF(ElementCount VF)
Definition: VPlan.h:3998
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
Definition: VPlan.h:3960
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
Definition: VPlan.h:4056
VPValue * getSCEVExpansion(const SCEV *S) const
Definition: VPlan.h:4082
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
Definition: VPlan.cpp:1068
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
Definition: VPlan.h:3933
void setUF(unsigned UF)
Definition: VPlan.h:4026
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
Definition: VPlan.cpp:1192
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
An ilist node that can access its parent list.
Definition: ilist_node.h:321
base_list_type::const_reverse_iterator const_reverse_iterator
Definition: ilist.h:125
void pop_back()
Definition: ilist.h:255
base_list_type::reverse_iterator reverse_iterator
Definition: ilist.h:123
base_list_type::const_iterator const_iterator
Definition: ilist.h:122
iterator insert(iterator where, pointer New)
Definition: ilist.h:165
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
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:52
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.
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
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:1759
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:1739
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition: Error.h:198
Value * getRuntimeVF(IRBuilderBase &B, Type *Ty, ElementCount VF)
Return the runtime value for VF.
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:720
auto dyn_cast_or_null(const Y &Val)
Definition: Casting.h:759
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:1746
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition: MathExtras.h:293
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:144
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
@ Other
Any other memory.
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303
Value * createStepForVF(IRBuilderBase &B, Type *Ty, ElementCount VF, int64_t Step)
Return a value for Step multiplied by VF.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1903
unsigned getReciprocalPredBlockProb()
A helper function that returns the reciprocal of the block probability of predicated blocks.
Definition: VPlan.h:92
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:468
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
#define N
A range of powers-of-2 vectorization factors with fixed start and adjustable end.
Definition: VPlan.h:97
iterator end()
Definition: VPlan.h:138
const ElementCount Start
Definition: VPlan.h:99
ElementCount End
Definition: VPlan.h:102
iterator begin()
Definition: VPlan.h:137
bool isEmpty() const
Definition: VPlan.h:104
VFRange(const ElementCount &Start, const ElementCount &End)
Definition: VPlan.h:108
Struct to hold various analysis needed for cost computations.
Definition: VPlan.h:682
LLVMContext & LLVMCtx
Definition: VPlan.h:686
LoopVectorizationCostModel & CM
Definition: VPlan.h:687
VPCostContext(const TargetTransformInfo &TTI, const TargetLibraryInfo &TLI, Type *CanIVTy, LoopVectorizationCostModel &CM, TargetTransformInfo::TargetCostKind CostKind)
Definition: VPlan.h:691
TargetTransformInfo::OperandValueInfo getOperandInfo(VPValue *V) const
Returns the OperandInfo for V, if it is a live-in.
Definition: VPlan.cpp:1665
bool skipCostComputation(Instruction *UI, bool IsVector) const
Return true if the cost for UI shouldn't be computed, e.g.
InstructionCost getLegacyCost(Instruction *UI, ElementCount VF) const
Return the cost for UI with VF using the legacy cost model as fallback until computing the cost of al...
TargetTransformInfo::TargetCostKind CostKind
Definition: VPlan.h:689
VPTypeAnalysis Types
Definition: VPlan.h:685
const TargetLibraryInfo & TLI
Definition: VPlan.h:684
const TargetTransformInfo & TTI
Definition: VPlan.h:683
SmallPtrSet< Instruction *, 8 > SkipCostComputation
Definition: VPlan.h:688
A recipe for handling first-order recurrence phis.
Definition: VPlan.h:2353
void execute(VPTransformState &State) override
Generate the phi nodes.
VPFirstOrderRecurrencePHIRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:2363
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
Definition: VPlan.h:2354
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this first-order recurrence phi recipe.
static bool classof(const VPHeaderPHIRecipe *R)
Definition: VPlan.h:2359
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
WrapFlagsTy(bool HasNUW, bool HasNSW)
Definition: VPlan.h:944
Hold state information used when constructing the CFG of the output IR, traversing the VPBasicBlocks ...
Definition: VPlan.h:338
BasicBlock * PrevBB
The previous IR BasicBlock created or used.
Definition: VPlan.h:344
SmallDenseMap< VPBasicBlock *, BasicBlock * > VPBB2IRBB
A mapping of each VPBasicBlock to the corresponding BasicBlock.
Definition: VPlan.h:352
VPBasicBlock * PrevVPBB
The previous VPBasicBlock visited. Initially set to null.
Definition: VPlan.h:340
BasicBlock * ExitBB
The last IR BasicBlock in the output IR.
Definition: VPlan.h:348
CFGState(DominatorTree *DT)
Definition: VPlan.h:357
BasicBlock * getPreheaderBBFor(VPRecipeBase *R)
Returns the BasicBlock* mapped to the pre-header of the loop region containing R.
Definition: VPlan.cpp:348
DomTreeUpdater DTU
Updater for the DominatorTree.
Definition: VPlan.h:355
DenseMap< VPValue *, Value * > VPV2Vector
Definition: VPlan.h:255
DenseMap< VPValue *, SmallVector< Value *, 4 > > VPV2Scalars
Definition: VPlan.h:257
VPTransformState holds information passed down when "executing" a VPlan, needed for generating the ou...
Definition: VPlan.h:236
bool hasScalarValue(VPValue *Def, VPLane Lane)
Definition: VPlan.h:269
bool hasVectorValue(VPValue *Def)
Definition: VPlan.h:267
LoopInfo * LI
Hold a pointer to LoopInfo to register new basic blocks in the loop.
Definition: VPlan.h:366
DenseMap< const SCEV *, Value * > ExpandedSCEVs
Map SCEVs to their expanded values.
Definition: VPlan.h:389
VPTypeAnalysis TypeAnalysis
VPlan-based type analysis.
Definition: VPlan.h:392
struct llvm::VPTransformState::DataState Data
void addMetadata(Value *To, Instruction *From)
Add metadata from one instruction to another.
Definition: VPlan.cpp:361
void packScalarIntoVectorValue(VPValue *Def, const VPLane &Lane)
Construct the vector value of a scalarized value V one lane at a time.
Definition: VPlan.cpp:394
Value * get(VPValue *Def, bool IsScalar=false)
Get the generated vector Value for a given VPValue Def if IsScalar is false, otherwise return the gen...
Definition: VPlan.cpp:249
struct llvm::VPTransformState::CFGState CFG
LoopVersioning * LVer
LoopVersioning.
Definition: VPlan.h:385
void addNewMetadata(Instruction *To, const Instruction *Orig)
Add additional metadata to To that was not present on Orig.
Definition: VPlan.cpp:353
void reset(VPValue *Def, Value *V, const VPLane &Lane)
Reset an existing scalar value for Def and a given Lane.
Definition: VPlan.h:306
std::optional< VPLane > Lane
Hold the index to generate specific scalar instructions.
Definition: VPlan.h:250
void set(VPValue *Def, Value *V, const VPLane &Lane)
Set the generated scalar V for Def and the given Lane.
Definition: VPlan.h:296
IRBuilderBase & Builder
Hold a reference to the IRBuilder used to generate output IR code.
Definition: VPlan.h:369
const TargetTransformInfo * TTI
Target Transform Info.
Definition: VPlan.h:242
VPlan * Plan
Pointer to the VPlan code is generated for.
Definition: VPlan.h:375
InnerLoopVectorizer * ILV
Hold a pointer to InnerLoopVectorizer to reuse its IR generation methods.
Definition: VPlan.h:372
void reset(VPValue *Def, Value *V)
Reset an existing vector value for Def and a given Part.
Definition: VPlan.h:290
ElementCount VF
The chosen Vectorization Factor of the loop being vectorized.
Definition: VPlan.h:245
void setDebugLocFrom(DebugLoc DL)
Set the debug location in the builder using the debug location DL.
Definition: VPlan.cpp:372
Loop * CurrentParentLoop
The parent loop object for the current scope, or nullptr.
Definition: VPlan.h:378
void set(VPValue *Def, Value *V, bool IsScalar=false)
Set the generated vector Value for a given VPValue, if IsScalar is false.
Definition: VPlan.h:279
A recipe for widening load operations with vector-predication intrinsics, using the address to load f...
Definition: VPlan.h:3072
void execute(VPTransformState &State) override
Generate the wide load or gather.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenLoadEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition: VPlan.h:3084
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3100
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue &EVL, VPValue *Mask)
Definition: VPlan.h:3073
A recipe for widening load operations, using the address to load from and an optional mask.
Definition: VPlan.h:3033
VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC)
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:3034
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3060
void execute(VPTransformState &State) override
Generate a wide load or gather.
VPWidenLoadRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3042
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
A recipe for widening select instructions.
Definition: VPlan.h:1824
bool isInvariantCond() const
Definition: VPlan.h:1855
VPWidenSelectRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:1831
VPWidenSelectRecipe(SelectInst &I, iterator_range< IterT > Operands)
Definition: VPlan.h:1826
VPValue * getCond() const
Definition: VPlan.h:1851
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenSelectRecipe.
void execute(VPTransformState &State) override
Produce a widened version of the select instruction.
~VPWidenSelectRecipe() override=default
A recipe for widening store operations with vector-predication intrinsics, using the value to store,...
Definition: VPlan.h:3152
VPValue * getStoredValue() const
Return the address accessed by this recipe.
Definition: VPlan.h:3163
void execute(VPTransformState &State) override
Generate the wide store or scatter.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3182
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue &EVL, VPValue *Mask)
Definition: VPlan.h:3153
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
Definition: VPlan.h:3166
A recipe for widening store operations, using the stored value, the address to store to and an option...
Definition: VPlan.h:3111
void execute(VPTransformState &State) override
Generate a wide store or scatter.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Definition: VPlan.h:3140
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
Definition: VPlan.h:3112
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
Definition: VPlan.h:3128
VPWidenStoreRecipe * clone() override
Clone the current recipe.
Definition: VPlan.h:3119
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPlanIngredient(const Value *V)
Definition: VPlan.h:4192
const Value * V
Definition: VPlan.h:4190
void print(raw_ostream &O) const
Definition: VPlan.cpp:1390