24#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
25#define LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
83 const unsigned char SubclassID;
100 VPlan *Plan =
nullptr;
110 assert(Predecessor &&
"Cannot add nullptr predecessor!");
115 void removePredecessor(VPBlockBase *Predecessor) {
116 auto Pos =
find(Predecessors, Predecessor);
117 assert(Pos &&
"Predecessor does not exist");
118 Predecessors.
erase(Pos);
122 void removeSuccessor(VPBlockBase *Successor) {
123 auto Pos =
find(Successors, Successor);
124 assert(Pos &&
"Successor does not exist");
125 Successors.
erase(Pos);
130 void replacePredecessor(VPBlockBase *Old, VPBlockBase *New) {
131 auto I =
find(Predecessors, Old);
133 assert(Old->getParent() ==
New->getParent() &&
134 "replaced predecessor must have the same parent");
140 void replaceSuccessor(VPBlockBase *Old, VPBlockBase *New) {
141 auto I =
find(Successors, Old);
143 assert(Old->getParent() ==
New->getParent() &&
144 "replaced successor must have the same parent");
150 : SubclassID(SC), Name(
N) {}
157 using VPBlockTy =
enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC };
163 const std::string &
getName()
const {
return Name; }
177 const VPlan *getPlan()
const;
181 void setPlan(
VPlan *ParentPlan);
209 return (Successors.size() == 1 ? *Successors.begin() :
nullptr);
215 return (Predecessors.size() == 1 ? *Predecessors.begin() :
nullptr);
271 assert(Successors.empty() &&
"Setting one successor when others exist.");
273 "connected blocks must have the same parent");
282 assert(Successors.empty() &&
"Setting two successors when others exist.");
283 appendSuccessor(IfTrue);
284 appendSuccessor(IfFalse);
291 assert(Predecessors.empty() &&
"Block predecessors already set.");
292 for (
auto *Pred : NewPreds)
293 appendPredecessor(Pred);
300 assert(Successors.empty() &&
"Block successors already set.");
301 for (
auto *Succ : NewSuccs)
302 appendSuccessor(Succ);
314 assert(Predecessors.size() == 2 &&
"must have 2 predecessors to swap");
315 std::swap(Predecessors[0], Predecessors[1]);
322 assert(Successors.size() == 2 &&
"must have 2 successors to swap");
329 "must have Pred exactly once in Predecessors");
330 return std::distance(Predecessors.begin(),
find(Predecessors, Pred));
336 "must have Succ exactly once in Successors");
337 return std::distance(Successors.begin(),
find(Successors, Succ));
347#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
391 VPBasicBlock *Parent =
nullptr;
408 const VPBasicBlock *
getParent()
const {
return Parent; }
467 bool mayReadFromMemory()
const;
470 bool mayWriteToMemory()
const;
481 bool isScalarCast()
const;
495#define VP_CLASSOF_IMPL(VPDefID) \
496 static inline bool classof(const VPDef *D) { \
497 return D->getVPDefID() == VPDefID; \
499 static inline bool classof(const VPValue *V) { \
500 auto *R = V->getDefiningRecipe(); \
501 return R && R->getVPDefID() == VPDefID; \
503 static inline bool classof(const VPUser *U) { \
504 auto *R = dyn_cast<VPRecipeBase>(U); \
505 return R && R->getVPDefID() == VPDefID; \
507 static inline bool classof(const VPRecipeBase *R) { \
508 return R->getVPDefID() == VPDefID; \
510 static inline bool classof(const VPSingleDefRecipe *R) { \
511 return R->getVPDefID() == VPDefID; \
528 switch (R->getVPDefID()) {
529 case VPRecipeBase::VPDerivedIVSC:
530 case VPRecipeBase::VPEVLBasedIVPHISC:
531 case VPRecipeBase::VPExpandSCEVSC:
532 case VPRecipeBase::VPExpressionSC:
533 case VPRecipeBase::VPInstructionSC:
534 case VPRecipeBase::VPReductionEVLSC:
535 case VPRecipeBase::VPReductionSC:
536 case VPRecipeBase::VPReplicateSC:
537 case VPRecipeBase::VPScalarIVStepsSC:
538 case VPRecipeBase::VPVectorPointerSC:
539 case VPRecipeBase::VPVectorEndPointerSC:
540 case VPRecipeBase::VPWidenCallSC:
541 case VPRecipeBase::VPWidenCanonicalIVSC:
542 case VPRecipeBase::VPWidenCastSC:
543 case VPRecipeBase::VPWidenGEPSC:
544 case VPRecipeBase::VPWidenIntrinsicSC:
545 case VPRecipeBase::VPWidenSC:
546 case VPRecipeBase::VPWidenSelectSC:
547 case VPRecipeBase::VPBlendSC:
548 case VPRecipeBase::VPPredInstPHISC:
549 case VPRecipeBase::VPCanonicalIVPHISC:
550 case VPRecipeBase::VPActiveLaneMaskPHISC:
551 case VPRecipeBase::VPFirstOrderRecurrencePHISC:
552 case VPRecipeBase::VPWidenPHISC:
553 case VPRecipeBase::VPWidenIntOrFpInductionSC:
554 case VPRecipeBase::VPWidenPointerInductionSC:
555 case VPRecipeBase::VPReductionPHISC:
556 case VPRecipeBase::VPPartialReductionSC:
558 case VPRecipeBase::VPBranchOnMaskSC:
559 case VPRecipeBase::VPInterleaveEVLSC:
560 case VPRecipeBase::VPInterleaveSC:
561 case VPRecipeBase::VPIRInstructionSC:
562 case VPRecipeBase::VPWidenLoadEVLSC:
563 case VPRecipeBase::VPWidenLoadSC:
564 case VPRecipeBase::VPWidenStoreEVLSC:
565 case VPRecipeBase::VPWidenStoreSC:
566 case VPRecipeBase::VPHistogramSC:
589#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
597 enum class OperationType :
unsigned char {
635 struct ExactFlagsTy {
638 struct FastMathFlagsTy {
639 char AllowReassoc : 1;
642 char NoSignedZeros : 1;
643 char AllowReciprocal : 1;
644 char AllowContract : 1;
650 OperationType OpType;
669 OpType = OperationType::Cmp;
672 OpType = OperationType::DisjointOp;
675 OpType = OperationType::OverflowingBinOp;
676 WrapFlags = {
Op->hasNoUnsignedWrap(),
Op->hasNoSignedWrap()};
678 OpType = OperationType::Trunc;
681 OpType = OperationType::PossiblyExactOp;
684 OpType = OperationType::GEPOp;
687 OpType = OperationType::NonNegOp;
690 OpType = OperationType::FPMathOp;
691 FMFs =
Op->getFastMathFlags();
693 OpType = OperationType::Other;
719 OpType = Other.OpType;
732 case OperationType::OverflowingBinOp:
736 case OperationType::Trunc:
740 case OperationType::DisjointOp:
743 case OperationType::PossiblyExactOp:
746 case OperationType::GEPOp:
749 case OperationType::FPMathOp:
753 case OperationType::NonNegOp:
756 case OperationType::Cmp:
757 case OperationType::Other:
765 case OperationType::OverflowingBinOp:
769 case OperationType::Trunc:
773 case OperationType::DisjointOp:
776 case OperationType::PossiblyExactOp:
779 case OperationType::GEPOp:
782 case OperationType::FPMathOp:
783 I.setHasAllowReassoc(
FMFs.AllowReassoc);
784 I.setHasNoNaNs(
FMFs.NoNaNs);
785 I.setHasNoInfs(
FMFs.NoInfs);
786 I.setHasNoSignedZeros(
FMFs.NoSignedZeros);
787 I.setHasAllowReciprocal(
FMFs.AllowReciprocal);
788 I.setHasAllowContract(
FMFs.AllowContract);
789 I.setHasApproxFunc(
FMFs.ApproxFunc);
791 case OperationType::NonNegOp:
794 case OperationType::Cmp:
795 case OperationType::Other:
801 assert(OpType == OperationType::Cmp &&
802 "recipe doesn't have a compare predicate");
807 assert(OpType == OperationType::Cmp &&
808 "recipe doesn't have a compare predicate");
826 assert(OpType == OperationType::NonNegOp &&
827 "recipe doesn't have a NNEG flag");
833 case OperationType::OverflowingBinOp:
835 case OperationType::Trunc:
844 case OperationType::OverflowingBinOp:
846 case OperationType::Trunc:
854 assert(OpType == OperationType::DisjointOp &&
855 "recipe cannot have a disjoing flag");
864#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
886 return R->getVPDefID() == VPRecipeBase::VPInstructionSC ||
887 R->getVPDefID() == VPRecipeBase::VPWidenSC ||
888 R->getVPDefID() == VPRecipeBase::VPWidenGEPSC ||
889 R->getVPDefID() == VPRecipeBase::VPWidenCallSC ||
890 R->getVPDefID() == VPRecipeBase::VPWidenCastSC ||
891 R->getVPDefID() == VPRecipeBase::VPWidenIntrinsicSC ||
892 R->getVPDefID() == VPRecipeBase::VPWidenSelectSC ||
893 R->getVPDefID() == VPRecipeBase::VPReductionSC ||
894 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC ||
895 R->getVPDefID() == VPRecipeBase::VPReplicateSC ||
896 R->getVPDefID() == VPRecipeBase::VPVectorEndPointerSC ||
897 R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
956 Metadata =
Other.Metadata;
965 Metadata.emplace_back(Kind,
Node);
986 Instruction::OtherOpsEnd + 1,
1078 bool doesGeneratePerAllLanes()
const;
1081 typedef unsigned char OpcodeTy;
1085 const std::string Name;
1089 bool canGenerateScalarForFirstLane()
const;
1100 static unsigned getNumOperandsForOpcode(
unsigned Opcode);
1111 DebugLoc
DL = DebugLoc::getUnknown(),
const Twine &Name =
"");
1135#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1148 case Instruction::Ret:
1149 case Instruction::Br:
1150 case Instruction::Store:
1151 case Instruction::Switch:
1152 case Instruction::IndirectBr:
1153 case Instruction::Resume:
1154 case Instruction::CatchRet:
1155 case Instruction::Unreachable:
1156 case Instruction::Fence:
1157 case Instruction::AtomicRMW:
1167 bool opcodeMayReadOrWriteFromMemory()
const;
1170 bool onlyFirstLaneUsed(
const VPValue *
Op)
const override;
1173 bool onlyFirstPartUsed(
const VPValue *
Op)
const override;
1177 bool isVectorToScalar()
const;
1181 bool isSingleScalar()
const;
1199 const Twine &Name =
"")
1201 ResultTy(ResultTy) {}
1207 ResultTy(ResultTy) {}
1212 if (R->isScalarCast())
1217 switch (VPI->getOpcode()) {
1251#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1292 std::function<
const VPBasicBlock *(size_t)> GetBlock = [
this](
size_t Idx) {
1310#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1322 return VPI && VPI->getOpcode() == Instruction::PHI;
1327 return VPI && VPI->getOpcode() == Instruction::PHI;
1332 return VPI && VPI->getOpcode() == Instruction::PHI;
1343#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1389#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1397 "Op must be an operand of the recipe");
1403 "Op must be an operand of the recipe");
1409 "Op must be an operand of the recipe");
1436#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1486#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1505 Opcode(Opcode), ResultTy(ResultTy) {
1507 "opcode of underlying cast doesn't match");
1517 "Set flags not supported for the provided opcode");
1526 New->setUnderlyingValue(UV);
1539#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1560 bool MayReadFromMemory;
1563 bool MayWriteToMemory;
1566 bool MayHaveSideEffects;
1573 VPIRMetadata(CI), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
1582 VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1588 MayHaveSideEffects = MayWriteToMemory ||
1589 !Attrs.hasAttribute(Attribute::NoUnwind) ||
1590 !Attrs.hasAttribute(Attribute::WillReturn);
1630#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1656 "last operand must be the called function");
1682#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1726#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1756#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1769 return getCond()->isDefinedOutsideLoopRegions();
1775 "Op must be an operand of the recipe");
1782 Type *SourceElementTy;
1784 bool isPointerLoopInvariant()
const {
1785 return getOperand(0)->isDefinedOutsideLoopRegions();
1788 bool isIndexLoopInvariant(
unsigned I)
const {
1789 return getOperand(
I + 1)->isDefinedOutsideLoopRegions();
1792 bool areAllOperandsInvariant()
const {
1794 return Op->isDefinedOutsideLoopRegions();
1832#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1841 "Op must be an operand of the recipe");
1843 return isPointerLoopInvariant();
1845 return !isPointerLoopInvariant() &&
Op->isDefinedOutsideLoopRegions();
1865 IndexedTy(IndexedTy), Stride(Stride) {
1866 assert(Stride < 0 &&
"Stride must be negative");
1878 "Op must be an operand of the recipe");
1892 "Op must be an operand of the recipe");
1903#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1913 Type *SourceElementTy;
1920 SourceElementTy(SourceElementTy) {}
1930 "Op must be an operand of the recipe");
1937 "Op must be an operand of the recipe");
1958#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1994 UnderlyingInstr,
DL) {}
2003 return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
2004 B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
2007 auto *
B = V->getDefiningRecipe();
2008 return B &&
B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
2009 B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
2019#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2066 return R->getVPDefID() == VPDef::VPWidenIntOrFpInductionSC ||
2067 R->getVPDefID() == VPDef::VPWidenPointerInductionSC;
2071 auto *R = V->getDefiningRecipe();
2105 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2112 "VPWidenIntOrFpInductionRecipe generates its own backedge value");
2118 "Op must be an operand of the recipe");
2171 "expandVPWidenIntOrFpInductionRecipe");
2174#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2203 return Trunc ? Trunc->getType()
2216 bool IsScalarAfterVectorization;
2225 bool IsScalarAfterVectorization,
DebugLoc DL)
2228 IsScalarAfterVectorization(IsScalarAfterVectorization) {
2246 "expandVPWidenPointerInduction");
2252#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2297#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2324#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2333 "Op must be an operand of the recipe");
2354 unsigned VFScaleFactor = 1;
2359 bool IsInLoop =
false,
bool IsOrdered =
false,
2360 unsigned VFScaleFactor = 1)
2362 IsInLoop(IsInLoop), IsOrdered(IsOrdered), VFScaleFactor(VFScaleFactor) {
2363 assert((!IsOrdered || IsInLoop) &&
"IsOrdered requires IsInLoop");
2371 *
getOperand(0), IsInLoop, IsOrdered, VFScaleFactor);
2384#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2407 "Op must be an operand of the recipe");
2422 assert(Operands.size() > 0 &&
"Expected at least one operand!");
2467#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2476 "Op must be an operand of the recipe");
2480 [
this](
VPUser *U) {
return U->onlyFirstLaneUsed(
this); });
2495 bool HasMask =
false;
2499 bool NeedsMaskForGaps =
false;
2508 NeedsMaskForGaps(NeedsMaskForGaps) {
2510 assert((!Mask || !IG->isReverse()) &&
2511 "Reversed masked interleave-group not supported.");
2512 for (
unsigned I = 0;
I < IG->getFactor(); ++
I)
2514 if (Inst->getType()->isVoidTy())
2519 for (
auto *SV : StoredValues)
2531 return R->getVPDefID() == VPRecipeBase::VPInterleaveSC ||
2532 R->getVPDefID() == VPRecipeBase::VPInterleaveEVLSC;
2593 NeedsMaskForGaps, MD, DL) {}
2608#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2616 "Op must be an operand of the recipe");
2633 R.getStoredValues(), Mask, R.needsMaskForGaps(), R,
2635 assert(!getInterleaveGroup()->isReverse() &&
2636 "Reversed interleave-group with tail folding is not supported.");
2637 assert(!needsMaskForGaps() &&
"Interleaved access with gap mask is not "
2638 "supported for scalable vector.");
2655#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2664 "Op must be an operand of the recipe");
2682 bool IsConditional =
false;
2690 IsOrdered(IsOrdered) {
2692 IsConditional =
true;
2722 return R->getVPDefID() == VPRecipeBase::VPReductionSC ||
2723 R->getVPDefID() == VPRecipeBase::VPReductionEVLSC ||
2724 R->getVPDefID() == VPRecipeBase::VPPartialReductionSC;
2748#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2779 unsigned VFScaleFactor;
2785 VFScaleFactor, ReductionInst) {}
2792 Opcode(Opcode), VFScaleFactor(ScaleFactor) {
2793 [[maybe_unused]]
auto *AccumulatorRecipe =
2797 assert((!AccumulatorRecipe ||
2800 "Unexpected operand order for partial reduction recipe");
2825#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2845 R.isOrdered(),
DL) {}
2858#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2870 "Op must be an operand of the recipe");
2882 bool IsSingleScalar;
2889 bool IsSingleScalar,
VPValue *Mask =
nullptr,
2893 IsPredicated(Mask) {
2904 Copy->transferFlags(*
this);
2919#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2932 "Op must be an operand of the recipe");
2939 "Op must be an operand of the recipe");
2946 bool shouldPack()
const;
2977#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2981 O << Indent <<
"BRANCH-ON-MASK ";
2989 "Op must be an operand of the recipe");
3012 enum class ExpressionTypes {
3028 ExtNegatedMulAccReduction,
3032 ExpressionTypes ExpressionType;
3045 : VPExpressionRecipe(ExpressionTypes::ExtendedReduction, {Ext, Red}) {}
3047 : VPExpressionRecipe(ExpressionTypes::MulAccReduction, {
Mul, Red}) {}
3050 : VPExpressionRecipe(ExpressionTypes::ExtMulAccReduction,
3051 {Ext0, Ext1,
Mul, Red}) {}
3055 : VPExpressionRecipe(ExpressionTypes::ExtNegatedMulAccReduction,
3056 {Ext0, Ext1,
Mul,
Sub, Red}) {
3057 assert(
Mul->getOpcode() == Instruction::Mul &&
"Expected a mul");
3059 "Expected an add reduction");
3062 assert(SubConst && SubConst->getValue() == 0 &&
3063 Sub->getOpcode() == Instruction::Sub &&
"Expected a negating sub");
3068 for (
auto *R :
reverse(ExpressionRecipes)) {
3069 if (ExpressionRecipesSeen.
insert(R).second)
3072 for (
VPValue *
T : LiveInPlaceholders)
3079 assert(!ExpressionRecipes.empty() &&
"empty expressions should be removed");
3081 for (
auto *R : ExpressionRecipes)
3082 NewExpressiondRecipes.
push_back(R->clone());
3083 for (
auto *New : NewExpressiondRecipes) {
3084 for (
const auto &[Idx, Old] :
enumerate(ExpressionRecipes))
3085 New->replaceUsesOfWith(Old, NewExpressiondRecipes[Idx]);
3088 for (
const auto &[Placeholder, OutsideOp] :
3090 New->replaceUsesOfWith(Placeholder, OutsideOp);
3110 return PR ? PR->getVFScaleFactor() : 1;
3121#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3169#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3178 "Op must be an operand of the recipe");
3211 std::initializer_list<VPValue *> Operands,
3225 return R->getVPDefID() == VPRecipeBase::VPWidenLoadSC ||
3226 R->getVPDefID() == VPRecipeBase::VPWidenStoreSC ||
3227 R->getVPDefID() == VPRecipeBase::VPWidenLoadEVLSC ||
3228 R->getVPDefID() == VPRecipeBase::VPWidenStoreEVLSC;
3295#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3304 "Op must be an operand of the recipe");
3318 {Addr, &EVL}, L.isConsecutive(), L.isReverse(),
3319 L.getAlign(), L, L.getDebugLoc()),
3336#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3345 "Op must be an operand of the recipe");
3377#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3386 "Op must be an operand of the recipe");
3401 S.isReverse(), S.getAlign(), S, S.getDebugLoc()) {
3420#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3429 "Op must be an operand of the recipe");
3456 llvm_unreachable(
"SCEV expressions must be expanded before final execute");
3466#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3496 "scalar phi recipe");
3499#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3513 "Op must be an operand of the recipe");
3520 "Op must be an operand of the recipe");
3556#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3582 "scalar phi recipe");
3595 "Op must be an operand of the recipe");
3599#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3634#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3657 const Twine &Name =
"")
3661 Start, CanonicalIV, Step, Name) {}
3667 FPBinOp(FPBinOp), Name(Name.str()) {}
3689#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3705 "Op must be an operand of the recipe");
3722 InductionOpcode(Opcode) {}
3728 IV, Step, VF, IndDesc.getInductionOpcode(),
3759#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3770 "Op must be an operand of the recipe");
3785template <
typename SrcTy>
3793 switch (R->getVPDefID()) {
3794 case VPDef::VPInstructionSC:
3796 case VPDef::VPIRInstructionSC:
3798 case VPDef::VPWidenPHISC:
3885 return V->getVPBlockID() == VPBlockBase::VPBasicBlockSC ||
3886 V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
3890 assert(Recipe &&
"No recipe to append.");
3891 assert(!Recipe->Parent &&
"Recipe already in VPlan");
3892 Recipe->Parent =
this;
3893 Recipes.insert(InsertPt, Recipe);
3923#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
3940 bool isExiting()
const;
3950 const VPBasicBlock *getCFGPredecessor(
unsigned Idx)
const;
3966inline const VPBasicBlock *
3976class VPIRBasicBlock :
public VPBasicBlock {
3983 : VPBasicBlock(VPIRBasicBlockSC,
3991 return V->getVPBlockID() == VPBlockBase::VPIRBasicBlockSC;
4027 const std::string &Name =
"",
bool IsReplicator =
false)
4028 :
VPBlockBase(VPRegionBlockSC, Name), Entry(Entry), Exiting(Exiting),
4029 IsReplicator(IsReplicator) {
4030 assert(Entry->getPredecessors().empty() &&
"Entry block has predecessors.");
4031 assert(Exiting->getSuccessors().empty() &&
"Exit block has successors.");
4032 Entry->setParent(
this);
4033 Exiting->setParent(
this);
4035 VPRegionBlock(
const std::string &Name =
"",
bool IsReplicator =
false)
4036 :
VPBlockBase(VPRegionBlockSC, Name), Entry(nullptr), Exiting(nullptr),
4037 IsReplicator(IsReplicator) {}
4044 return V->getVPBlockID() == VPBlockBase::VPRegionBlockSC;
4054 "Entry block cannot have predecessors.");
4066 "Exit block cannot have successors.");
4067 Exiting = ExitingBlock;
4088#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4106 void dissolveToCFGLoop();
4111 if (EntryVPBB->
empty()) {
4176 VPValue *BackedgeTakenCount =
nullptr;
4202 : Entry(Entry), ScalarHeader(ScalarHeader) {
4203 Entry->setPlan(
this);
4204 assert(ScalarHeader->getNumSuccessors() == 0 &&
4205 "scalar header must be a leaf node");
4264 "cannot call the function after vector loop region has been removed");
4266 if (RegionSucc->getSingleSuccessor() ||
4298 assert(TripCount &&
"trip count needs to be set before accessing it");
4305 assert(!TripCount && NewTripCount &&
"TripCount should not be set yet.");
4306 TripCount = NewTripCount;
4313 "TripCount must be set when resetting");
4314 TripCount = NewTripCount;
4319 if (!BackedgeTakenCount)
4320 BackedgeTakenCount =
new VPValue();
4321 return BackedgeTakenCount;
4342 assert(
hasVF(VF) &&
"Cannot set VF not already in plan");
4359 bool HasScalarVFOnly = VFs.size() == 1 && VFs[0].isScalar();
4361 "Plan with scalar VF should only have a single VF");
4362 return HasScalarVFOnly;
4365 bool hasUF(
unsigned UF)
const {
return UFs.empty() || UFs.contains(UF); }
4368 assert(UFs.size() == 1 &&
"Expected a single UF");
4373 assert(
hasUF(UF) &&
"Cannot set the UF not already in plan");
4390 assert(V &&
"Trying to get or add the VPValue of a null Value");
4391 auto [It, Inserted] = Value2VPValue.try_emplace(V);
4394 VPLiveIns.push_back(VPV);
4399 assert(It->second->isLiveIn() &&
"Only live-ins should be in mapping");
4416 bool IsSigned =
false) {
4431 [
this](
const auto &
P) {
4434 "all VPValues in Value2VPValue must also be in VPLiveIns");
4438#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
4462 CreatedBlocks.push_back(VPB);
4474 CreatedBlocks.push_back(VPB);
4482 const std::string &Name =
"") {
4484 CreatedBlocks.push_back(VPB);
4507 (ExitBlocks.size() == 1 && ExitBlocks[0]->getNumPredecessors() > 1);
4519#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define LLVM_ABI_FOR_TEST
This file defines the DenseMap class.
static MaybeAlign getAlign(Value *Ptr)
This file defines an InstructionCost class that is used when calculating the cost of an instruction,...
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
MachineInstr unsigned OpIdx
static StringRef getName(Value *V)
const SmallVectorImpl< MachineOperand > & Cond
static bool mayHaveSideEffects(MachineInstr &MI)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static const BasicSubtargetSubTypeKV * find(StringRef S, ArrayRef< BasicSubtargetSubTypeKV > A)
Find KV in array using binary search.
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
This file contains the declarations of the entities induced by Vectorization Plans,...
#define VP_CLASSOF_IMPL(VPDefID)
static const uint32_t IV[8]
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM Basic Block Representation.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static DebugLoc getUnknown()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
static constexpr ElementCount getFixed(ScalarTy MinVal)
Utility class for floating point operations which can have information about relaxed accuracy require...
Convenience struct for specifying and reasoning about fast-math flags.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Common base class shared among various IRBuilders.
A struct for saving information about induction variables.
InductionKind
This enum represents the kinds of inductions that we support.
InnerLoopVectorizer vectorizes loops which contain only one basic block to a specified vectorization ...
The group of interleaved loads/stores sharing the same stride and close to each other.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
This class emits a version of the loop where run-time checks ensure that may-alias pointers can't ove...
Represents a single loop in the control flow graph.
bool onlyWritesMemory() const
Whether this function only (at most) writes memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
This class represents an analyzed expression in the program.
This class represents the LLVM 'select' instruction.
This class provides computation of slot numbers for LLVM Assembly writing.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
This class represents a truncation of integer types.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
void execute(VPTransformState &State) override
Generate the active lane mask phi of the vector loop.
VPActiveLaneMaskPHIRecipe * clone() override
Clone the current recipe.
VPActiveLaneMaskPHIRecipe(VPValue *StartMask, DebugLoc DL)
~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.
RecipeListTy::const_iterator const_iterator
void appendRecipe(VPRecipeBase *Recipe)
Augment the existing recipes of a VPBasicBlock with an additional Recipe as the last recipe.
RecipeListTy::const_reverse_iterator const_reverse_iterator
RecipeListTy::iterator iterator
Instruction iterators...
RecipeListTy & getRecipeList()
Returns a reference to the list of recipes.
iplist< VPRecipeBase > RecipeListTy
VPBasicBlock(const unsigned char BlockSC, const Twine &Name="")
iterator begin()
Recipe iterator methods.
RecipeListTy::reverse_iterator reverse_iterator
iterator_range< iterator > phis()
Returns an iterator range over the PHI-like recipes in the block.
const VPBasicBlock * getCFGPredecessor(unsigned Idx) const
Returns the predecessor block at index Idx with the predecessors as per the corresponding plain CFG.
iterator getFirstNonPhi()
Return the position of the first non-phi node recipe in the block.
const_reverse_iterator rbegin() const
RecipeListTy Recipes
The VPRecipes held in the order of output instructions to generate.
const VPRecipeBase & front() const
const_iterator begin() const
const VPRecipeBase & back() const
void insert(VPRecipeBase *Recipe, iterator InsertPt)
const_iterator end() const
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
static RecipeListTy VPBasicBlock::* getSublistAccess(VPRecipeBase *)
Returns a pointer to a member of the recipe list.
reverse_iterator rbegin()
const_reverse_iterator rend() const
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VPValue * getIncomingValue(unsigned Idx) const
Return incoming value number Idx.
VPValue * getMask(unsigned Idx) const
Return mask number Idx.
unsigned getNumIncomingValues() const
Return the number of incoming values, taking into account when normalized the first incoming value wi...
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
VPBlendRecipe * clone() override
Clone the current recipe.
VPBlendRecipe(PHINode *Phi, ArrayRef< VPValue * > Operands, DebugLoc DL)
The blend operation is a User of the incoming values and of their respective masks,...
void setMask(unsigned Idx, VPValue *V)
Set mask number Idx to V.
bool isNormalized() const
A normalized blend is one that has an odd number of operands, whereby the first operand does not have...
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
void setSuccessors(ArrayRef< VPBlockBase * > NewSuccs)
Set each VPBasicBlock in NewSuccss as successor of this VPBlockBase.
VPRegionBlock * getParent()
VPBlocksTy & getPredecessors()
iterator_range< VPBlockBase ** > predecessors()
LLVM_DUMP_METHOD void dump() const
Dump this VPBlockBase to dbgs().
void setName(const Twine &newName)
size_t getNumSuccessors() const
iterator_range< VPBlockBase ** > successors()
virtual void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const =0
Print plain-text dump of this VPBlockBase to O, prefixing all lines with Indent.
bool hasPredecessors() const
Returns true if this block has any predecessors.
void swapSuccessors()
Swap successors of the block. The block must have exactly 2 successors.
void printSuccessors(raw_ostream &O, const Twine &Indent) const
Print the successors of this block to O, prefixing all lines with Indent.
SmallVectorImpl< VPBlockBase * > VPBlocksTy
virtual ~VPBlockBase()=default
const VPBlocksTy & getHierarchicalPredecessors()
unsigned getIndexForSuccessor(const VPBlockBase *Succ) const
Returns the index for Succ in the blocks successor list.
size_t getNumPredecessors() const
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
VPBlockBase * getEnclosingBlockWithPredecessors()
unsigned getIndexForPredecessor(const VPBlockBase *Pred) const
Returns the index for Pred in the blocks predecessors list.
const VPBlocksTy & getPredecessors() const
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...
virtual InstructionCost cost(ElementCount VF, VPCostContext &Ctx)=0
Return the cost of the block.
void setPlan(VPlan *ParentPlan)
Sets the pointer of the plan containing the block.
const VPRegionBlock * getParent() const
const std::string & getName() const
void clearSuccessors()
Remove all the successors of this block.
VPBlockBase * getSingleHierarchicalSuccessor()
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
VPBlockBase * getSinglePredecessor() const
virtual void execute(VPTransformState *State)=0
The method which generates the output IR that correspond to this VPBlockBase, thereby "executing" the...
const VPBlocksTy & getHierarchicalSuccessors()
void clearPredecessors()
Remove all the predecessor of this block.
friend class VPBlockUtils
unsigned getVPBlockID() const
void printAsOperand(raw_ostream &OS, bool PrintType=false) const
void swapPredecessors()
Swap predecessors of the block.
VPBlockBase(const unsigned char SC, const std::string &N)
VPBlocksTy & getSuccessors()
VPBlockBase * getEnclosingBlockWithSuccessors()
An Enclosing Block of a block B is any block containing B, including B itself.
const VPBasicBlock * getEntryBasicBlock() const
void setOneSuccessor(VPBlockBase *Successor)
Set a given VPBlockBase Successor as the single successor of this VPBlockBase.
void setParent(VPRegionBlock *P)
VPBlockBase * getSingleHierarchicalPredecessor()
VPBlockBase * getSingleSuccessor() const
const VPBlocksTy & getSuccessors() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPBranchOnMaskRecipe * clone() override
Clone the current recipe.
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
VPlan-based builder utility analogous to IRBuilder.
Canonical scalar induction phi of the vector loop.
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first part of operand Op.
~VPCanonicalIVPHIRecipe() override=default
VPCanonicalIVPHIRecipe * clone() override
Clone the current recipe.
VPCanonicalIVPHIRecipe(VPValue *StartV, DebugLoc DL)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Type * getScalarType() const
Returns the scalar type of the induction.
void execute(VPTransformState &State) override
Generate the phi nodes.
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.
This class augments a recipe with a set of VPValues defined by the recipe.
VPDef(const unsigned char SC)
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.
VPValue * getStepValue() const
Type * getScalarType() const
VPDerivedIVRecipe * clone() override
Clone the current recipe.
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind, const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV, VPValue *Step, const Twine &Name="")
~VPDerivedIVRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VPValue * getStartValue() const
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start, VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step, const Twine &Name="")
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPEVLBasedIVPHIRecipe * clone() override
Clone the current recipe.
~VPEVLBasedIVPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi nodes.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPEVLBasedIVPHIRecipe.
VPEVLBasedIVPHIRecipe(VPValue *StartIV, DebugLoc DL)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPExpandSCEVRecipe.
VPExpandSCEVRecipe(const SCEV *Expr)
const SCEV * getSCEV() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPExpandSCEVRecipe * clone() override
Clone the current recipe.
~VPExpandSCEVRecipe() override=default
void execute(VPTransformState &State) override
Method for generating code, must not be called as this recipe is abstract.
VPValue * getOperandOfResultType() const
Return the VPValue to use to infer the result type of the recipe.
VPExpressionRecipe * clone() override
Clone the current recipe.
void decompose()
Insert the recipes of the expression back into the VPlan, directly before the current recipe.
~VPExpressionRecipe() override
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool isSingleScalar() const
Returns true if the result of this VPExpressionRecipe is a single-scalar.
VPExpressionRecipe(VPWidenCastRecipe *Ext0, VPWidenCastRecipe *Ext1, VPWidenRecipe *Mul, VPWidenRecipe *Sub, VPReductionRecipe *Red)
VPExpressionRecipe(VPWidenCastRecipe *Ext, VPReductionRecipe *Red)
bool mayHaveSideEffects() const
Returns true if this expression contains recipes that may have side effects.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Compute the cost of this recipe either using a recipe's specialized implementation or using the legac...
bool mayReadOrWriteMemory() const
Returns true if this expression contains recipes that may read from or write to memory.
VPExpressionRecipe(VPWidenCastRecipe *Ext0, VPWidenCastRecipe *Ext1, VPWidenRecipe *Mul, VPReductionRecipe *Red)
unsigned getVFScaleFactor() const
VPExpressionRecipe(VPWidenRecipe *Mul, VPReductionRecipe *Red)
void execute(VPTransformState &State) override
Produce a vectorized histogram operation.
VP_CLASSOF_IMPL(VPDef::VPHistogramSC)
VPHistogramRecipe * clone() override
Clone the current recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHistogramRecipe.
VPValue * getMask() const
Return the mask operand if one was provided, or a null pointer if all lanes should be executed uncond...
unsigned getOpcode() const
VPHistogramRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
~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.
void execute(VPTransformState *State) override
The method which generates the output IR instructions that correspond to this VPBasicBlock,...
BasicBlock * getIRBasicBlock() const
~VPIRBasicBlock() override
static bool classof(const VPBlockBase *V)
VPIRBasicBlock * clone() override
Clone the current block and it's recipes, without updating the operands of the cloned recipes.
Class to record and manage LLVM IR flags.
bool flagsValidForOpcode(unsigned Opcode) const
Returns true if the set flags are valid for Opcode.
VPIRFlags(DisjointFlagsTy DisjointFlags)
VPIRFlags(WrapFlagsTy WrapFlags)
CmpInst::Predicate CmpPredicate
void printFlags(raw_ostream &O) const
bool hasFastMathFlags() const
Returns true if the recipe has fast-math flags.
LLVM_ABI_FOR_TEST FastMathFlags getFastMathFlags() const
CmpInst::Predicate getPredicate() const
bool hasNonNegFlag() const
Returns true if the recipe has non-negative flag.
void transferFlags(VPIRFlags &Other)
bool hasNoSignedWrap() const
void intersectFlags(const VPIRFlags &Other)
Only keep flags also present in Other.
VPIRFlags(TruncFlagsTy TruncFlags)
VPIRFlags(FastMathFlags FMFs)
VPIRFlags(NonNegFlagsTy NonNegFlags)
VPIRFlags(CmpInst::Predicate Pred)
GEPNoWrapFlags getGEPNoWrapFlags() const
bool hasPredicate() const
Returns true if the recipe has a comparison predicate.
DisjointFlagsTy DisjointFlags
void setPredicate(CmpInst::Predicate Pred)
bool hasNoUnsignedWrap() const
NonNegFlagsTy NonNegFlags
void dropPoisonGeneratingFlags()
Drop all poison-generating flags.
void applyFlags(Instruction &I) const
Apply the IR flags to I.
VPIRFlags(GEPNoWrapFlags GEPFlags)
VPIRFlags(Instruction &I)
Instruction & getInstruction() const
bool onlyFirstPartUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first part of operand Op.
~VPIRInstruction() override=default
void execute(VPTransformState &State) override
The method which generates the output IR instructions that correspond to this VPRecipe,...
void extractLastLaneOfFirstOperand(VPBuilder &Builder)
Update the recipes first operand to the last lane of the operand using Builder.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPIRInstruction * clone() override
Clone the current recipe.
static LLVM_ABI_FOR_TEST VPIRInstruction * create(Instruction &I)
Create a new VPIRPhi for \I , if it is a PHINode, otherwise create a VPIRInstruction.
LLVM_ABI_FOR_TEST InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPIRInstruction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool usesScalars(const VPValue *Op) const override
Returns true if the VPUser uses scalars of operand Op.
VPIRInstruction(Instruction &I)
VPIRInstruction::create() should be used to create VPIRInstructions, as subclasses may need to be cre...
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPInstruction.
static bool classof(const VPUser *R)
static bool classof(const VPRecipeBase *R)
VPInstructionWithType(unsigned Opcode, ArrayRef< VPValue * > Operands, Type *ResultTy, DebugLoc DL, const VPIRFlags &Flags, const VPIRMetadata &Metadata, const Twine &Name="")
Type * getResultType() const
VPInstructionWithType(unsigned Opcode, ArrayRef< VPValue * > Operands, Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL, const Twine &Name="")
VPInstruction * clone() override
Clone the current recipe.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the instruction.
This is a concrete Recipe that models a single VPlan-level instruction.
VPInstruction(unsigned Opcode, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
VPInstruction * clone() override
Clone the current recipe.
@ ExtractLane
Extracts a single lane (first operand) from a set of vector operands.
@ ComputeAnyOfResult
Compute the final result of a AnyOf reduction with select(cmp(),x,y), where one of (x,...
@ WideIVStep
Scale the first operand (vector step) by the second operand (scalar-step).
@ ExtractPenultimateElement
@ ResumeForEpilogue
Explicit user for the resume phi of the canonical induction in the main VPlan, used by the epilogue v...
@ Unpack
Extracts all lanes from its (non-scalable) vector operand.
@ FirstOrderRecurrenceSplice
@ ReductionStartVector
Start vector for reductions with 3 operands: the original start value, the identity value for the red...
@ BuildVector
Creates a fixed-width vector containing all operands.
@ BuildStructVector
Given operands of (the same) struct type, creates a struct of fixed- width vectors each containing a ...
@ VScale
Returns the value for vscale.
@ CanonicalIVIncrementForPart
@ CalculateTripCountMinusVF
StringRef getName() const
Returns the symbolic name assigned to the VPInstruction.
unsigned getOpcode() const
virtual unsigned getNumStoreOperands() const =0
Returns the number of stored operands of this interleave group.
bool needsMaskForGaps() const
Return true if the access needs a mask because of the gaps.
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=0
Returns true if the recipe only uses the first lane of operand Op.
static bool classof(const VPUser *U)
VPInterleaveBase(const unsigned char SC, const InterleaveGroup< Instruction > *IG, ArrayRef< VPValue * > Operands, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
Instruction * getInsertPos() const
static bool classof(const VPRecipeBase *R)
const InterleaveGroup< Instruction > * getInterleaveGroup() const
VPValue * getMask() const
Return the mask used by this recipe.
ArrayRef< VPValue * > getStoredValues() const
Return the VPValues stored by this interleave group.
VPInterleaveBase * clone() override=0
Clone the current recipe.
VPValue * getAddr() const
Return the address accessed by this recipe.
VPValue * getEVL() const
The VPValue of the explicit vector length.
~VPInterleaveEVLRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
The recipe only uses the first lane of the address, and EVL operand.
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
VPInterleaveEVLRecipe * clone() override
Clone the current recipe.
VPInterleaveEVLRecipe(VPInterleaveRecipe &R, VPValue &EVL, VPValue *Mask)
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
unsigned getNumStoreOperands() const override
Returns the number of stored operands of this interleave group.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
~VPInterleaveRecipe() override=default
VPInterleaveRecipe * clone() override
Clone the current recipe.
VPInterleaveRecipe(const InterleaveGroup< Instruction > *IG, VPValue *Addr, ArrayRef< VPValue * > StoredValues, VPValue *Mask, bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
In what follows, the term "input IR" refers to code that is fed into the vectorizer whereas the term ...
VPPartialReductionRecipe(Instruction *ReductionInst, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned VFScaleFactor)
VPPartialReductionRecipe(unsigned Opcode, VPValue *Op0, VPValue *Op1, VPValue *Cond, unsigned ScaleFactor, Instruction *ReductionInst=nullptr)
~VPPartialReductionRecipe() override=default
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
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.
VPPartialReductionRecipe * clone() override
Clone the current recipe.
Helper type to provide functions to access incoming values and blocks for phi-like recipes.
virtual const VPRecipeBase * getAsRecipe() const =0
Return a VPRecipeBase* to the current object.
VPUser::const_operand_range incoming_values() const
Returns an interator range over the incoming values.
virtual unsigned getNumIncoming() const
Returns the number of incoming values, also number of incoming blocks.
void removeIncomingValueFor(VPBlockBase *IncomingBlock) const
Removes the incoming value for IncomingBlock, which must be a predecessor.
const VPBasicBlock * getIncomingBlock(unsigned Idx) const
Returns the incoming block with index Idx.
detail::zippy< llvm::detail::zip_first, VPUser::const_operand_range, const_incoming_blocks_range > incoming_values_and_blocks() const
Returns an iterator range over pairs of incoming values and corresponding incoming blocks.
VPValue * getIncomingValue(unsigned Idx) const
Returns the incoming VPValue with index Idx.
virtual ~VPPhiAccessors()=default
void printPhiOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the recipe.
iterator_range< mapped_iterator< detail::index_iterator, std::function< const VPBasicBlock *(size_t)> > > const_incoming_blocks_range
const_incoming_blocks_range incoming_blocks() const
Returns an iterator range over the incoming blocks.
~VPPredInstPHIRecipe() override=default
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
VPPredInstPHIRecipe * clone() override
Clone the current recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPPredInstPHIRecipe.
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
Construct a VPPredInstPHIRecipe given PredInst whose value needs a phi nodes after merging back from ...
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
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.
VPRegionBlock * getRegion()
void setDebugLoc(DebugLoc NewDL)
Set the recipe's debug location to NewDL.
bool mayWriteToMemory() const
Returns true if the recipe may write to memory.
~VPRecipeBase() override=default
VPBasicBlock * getParent()
DebugLoc getDebugLoc() const
Returns the debug location of the recipe.
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.
iplist< VPRecipeBase >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
virtual VPRecipeBase * clone()=0
Clone the current recipe.
friend class VPBlockUtils
const VPBasicBlock * getParent() const
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)
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
void moveAfter(VPRecipeBase *MovePos)
Unlink this recipe from its current VPBasicBlock and insert it into the VPBasicBlock that MovePos liv...
VPRecipeBase(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VPValue * getEVL() const
The VPValue of the explicit vector length.
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp, DebugLoc DL=DebugLoc::getUnknown())
VPReductionEVLRecipe * clone() override
Clone the current recipe.
~VPReductionEVLRecipe() override=default
bool isOrdered() const
Returns true, if the phi is part of an ordered reduction.
VPReductionPHIRecipe * clone() override
Clone the current recipe.
unsigned getVFScaleFactor() const
Get the factor that the VF of this recipe's output should be scaled by.
~VPReductionPHIRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VPReductionPHIRecipe(PHINode *Phi, RecurKind Kind, VPValue &Start, bool IsInLoop=false, bool IsOrdered=false, unsigned VFScaleFactor=1)
Create a new VPReductionPHIRecipe for the reduction Phi.
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
bool isInLoop() const
Returns true, if the phi is part of an in-loop reduction.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
void execute(VPTransformState &State) override
Generate the phi/select nodes.
RecurKind getRecurrenceKind() const
Returns the recurrence kind of the reduction.
A recipe to represent inloop reduction operations, performing a reduction on a vector operand into a ...
bool isConditional() const
Return true if the in-loop reduction is conditional.
static bool classof(const VPRecipeBase *R)
VPReductionRecipe(const RecurKind RdxKind, FastMathFlags FMFs, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
static bool classof(const VPSingleDefRecipe *R)
VPValue * getVecOp() const
The VPValue of the vector value to be reduced.
VPValue * getCondOp() const
The VPValue of the condition for the block.
RecurKind getRecurrenceKind() const
Return the recurrence kind for the in-loop reduction.
bool isOrdered() const
Return true if the in-loop reduction is ordered.
~VPReductionRecipe() override=default
VPValue * getChainOp() const
The VPValue of the scalar Chain being accumulated.
VPReductionRecipe(RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp, bool IsOrdered, DebugLoc DL=DebugLoc::getUnknown())
VPReductionRecipe * clone() override
Clone the current recipe.
VPReductionRecipe(const unsigned char SC, RecurKind RdxKind, FastMathFlags FMFs, Instruction *I, ArrayRef< VPValue * > Operands, VPValue *CondOp, bool IsOrdered, DebugLoc DL)
static bool classof(const VPUser *U)
static bool classof(const VPValue *VPV)
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
const VPBlockBase * getEntry() const
Type * getCanonicalIVType()
Return the type of the canonical IV for loop regions.
bool isReplicator() const
An indicator whether this region is to generate multiple replicated instances of output IR correspond...
void setExiting(VPBlockBase *ExitingBlock)
Set ExitingBlock as the exiting VPBlockBase of this VPRegionBlock.
VPBlockBase * getExiting()
VPCanonicalIVPHIRecipe * getCanonicalIV()
Returns the canonical induction recipe of the region.
void setEntry(VPBlockBase *EntryBlock)
Set EntryBlock as the entry VPBlockBase of this VPRegionBlock.
const Type * getCanonicalIVType() const
const VPBlockBase * getExiting() const
const VPCanonicalIVPHIRecipe * getCanonicalIV() const
VPBasicBlock * getPreheaderVPBB()
Returns the pre-header VPBasicBlock of the loop region.
~VPRegionBlock() override
static bool classof(const VPBlockBase *V)
Method to support type inquiry through isa, cast, and dyn_cast.
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
VPReplicateRecipe(Instruction *I, ArrayRef< VPValue * > Operands, bool IsSingleScalar, VPValue *Mask=nullptr, VPIRMetadata Metadata={})
bool isSingleScalar() const
~VPReplicateRecipe() override=default
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
bool usesScalars(const VPValue *Op) const override
Returns true if the recipe uses scalars of operand Op.
bool isPredicated() const
VPReplicateRecipe * clone() override
Clone the current recipe.
unsigned getOpcode() const
VPValue * getMask()
Return the mask of a predicated VPReplicateRecipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VPValue * getStepValue() const
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPScalarIVStepsRecipe.
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV, VPValue *Step, VPValue *VF, DebugLoc DL=DebugLoc::getUnknown())
bool isPart0() const
Return true if this VPScalarIVStepsRecipe corresponds to part 0.
VPScalarIVStepsRecipe * clone() override
Clone the current recipe.
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step, VPValue *VF, Instruction::BinaryOps Opcode, FastMathFlags FMFs, DebugLoc DL)
~VPScalarIVStepsRecipe() override=default
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, Value *UV, DebugLoc DL=DebugLoc::getUnknown())
Instruction * getUnderlyingInstr()
Returns the underlying instruction.
static bool classof(const VPRecipeBase *R)
const Instruction * getUnderlyingInstr() const
static bool classof(const VPUser *U)
LLVM_DUMP_METHOD void dump() const
Print this VPSingleDefRecipe to dbgs() (for debugging).
VPSingleDefRecipe * clone() override=0
Clone the current recipe.
VPSingleDefRecipe(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
This class can be used to assign names to VPValues.
Helper to access the operand that contains the unroll part for this recipe after unrolling.
VPValue * getUnrollPartOperand(const VPUser &U) const
Return the VPValue operand containing the unroll part or null if there is no such operand.
unsigned getUnrollPart(const VPUser &U) const
Return the unroll part.
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const
Print the operands to O.
void setOperand(unsigned I, VPValue *New)
unsigned getNumOperands() const
operand_iterator op_end()
VPValue * getOperand(unsigned N) const
VPUser(ArrayRef< VPValue * > Operands)
iterator_range< const_operand_iterator > const_operand_range
iterator_range< operand_iterator > operand_range
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
friend class VPExpressionRecipe
Value * getLiveInIRValue() const
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Value * getUnderlyingValue() const
Return the underlying Value attached to this VPValue.
VPValue(const unsigned char SC, Value *UV=nullptr, VPDef *Def=nullptr)
void setUnderlyingValue(Value *Val)
unsigned getNumUsers() const
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
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.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPVectorEndPointerRecipe * clone() override
Clone the current recipe.
const VPValue * getVFValue() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPVectorPointerRecipe.
VPVectorEndPointerRecipe(VPValue *Ptr, VPValue *VF, Type *IndexedTy, int64_t Stride, GEPNoWrapFlags GEPFlags, DebugLoc DL)
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
bool isFirstPart() const
Return true if this VPVectorPointerRecipe corresponds to part 0.
Type * getSourceElementType() const
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.
VPVectorPointerRecipe(VPValue *Ptr, Type *SourceElementTy, GEPNoWrapFlags GEPFlags, DebugLoc DL)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPHeaderPHIRecipe.
VPVectorPointerRecipe * clone() override
Clone the current recipe.
const_operand_range args() const
VPWidenCallRecipe * clone() override
Clone the current recipe.
VPWidenCallRecipe(Value *UV, Function *Variant, ArrayRef< VPValue * > CallArguments, DebugLoc DL=DebugLoc::getUnknown())
Function * getCalledScalarFunction() const
~VPWidenCallRecipe() override=default
void execute(VPTransformState &State) override
Generate a canonical vector induction variable of the vector loop, with start = {<Part*VF,...
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
~VPWidenCanonicalIVRecipe() override=default
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenCanonicalIVPHIRecipe.
VPWidenCanonicalIVRecipe * clone() override
Clone the current recipe.
VPWidenCanonicalIVRecipe(VPCanonicalIVPHIRecipe *CanonicalIV)
VPWidenCastRecipe is a recipe to create vector cast instructions.
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, CastInst &UI)
Instruction::CastOps getOpcode() const
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy, const VPIRFlags &Flags={}, const VPIRMetadata &Metadata={}, DebugLoc DL=DebugLoc::getUnknown())
Type * getResultType() const
Returns the result type of the cast.
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.
unsigned getOpcode() const
This recipe generates a GEP instruction.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
Type * getSourceElementType() const
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef< VPValue * > Operands)
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenGEPRecipe.
VPWidenGEPRecipe * clone() override
Clone the current recipe.
~VPWidenGEPRecipe() override=default
void execute(VPTransformState &State) override=0
Generate the phi nodes.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
static bool classof(const VPValue *V)
void setStepValue(VPValue *V)
Update the step value of the recipe.
VPValue * getBackedgeValue() override
Returns the incoming value from the loop backedge.
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
PHINode * getPHINode() const
VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start, VPValue *Step, const InductionDescriptor &IndDesc, DebugLoc DL)
VPValue * getStepValue()
Returns the step value of the induction.
const InductionDescriptor & getInductionDescriptor() const
Returns the induction descriptor for the recipe.
VPRecipeBase & getBackedgeRecipe() override
Returns the backedge value as a recipe.
static bool classof(const VPRecipeBase *R)
static bool classof(const VPHeaderPHIRecipe *R)
const VPValue * getVFValue() const
const VPValue * getStepValue() const
const TruncInst * getTruncInst() const
void execute(VPTransformState &State) override
Generate the phi nodes.
~VPWidenIntOrFpInductionRecipe() override=default
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, TruncInst *Trunc, DebugLoc DL)
VPWidenIntOrFpInductionRecipe * clone() override
Clone the current recipe.
TruncInst * getTruncInst()
Returns the first defined value as TruncInst, if it is one or nullptr otherwise.
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, DebugLoc DL)
VPValue * getLastUnrolledPartOperand()
Returns the VPValue representing the value of this induction at the last unrolled part,...
unsigned getNumIncoming() const override
Returns the number of incoming values, also number of incoming blocks.
Type * getScalarType() const
Returns the scalar type of the induction.
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.
VPValue * getSplatVFValue()
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the VPUser only uses the first lane of operand Op.
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL=DebugLoc::getUnknown())
Intrinsic::ID getVectorIntrinsicID() const
Return the ID of the intrinsic.
bool mayReadFromMemory() const
Returns true if the intrinsic may read from memory.
StringRef getIntrinsicName() const
Return to name of the intrinsic as string.
VPWidenIntrinsicRecipe(CallInst &CI, Intrinsic::ID VectorIntrinsicID, ArrayRef< VPValue * > CallArguments, Type *Ty, DebugLoc DL=DebugLoc::getUnknown())
bool mayHaveSideEffects() const
Returns true if the intrinsic may have side-effects.
VPWidenIntrinsicRecipe * clone() override
Clone the current recipe.
bool mayWriteToMemory() const
Returns true if the intrinsic may write to memory.
~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.
void execute(VPTransformState &State) override
Produce a widened version of the vector intrinsic.
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this vector intrinsic.
bool IsMasked
Whether the memory access is masked.
bool Reverse
Whether the consecutive accessed addresses are in reverse order.
bool isConsecutive() const
Return whether the loaded-from / stored-to addresses are consecutive.
static bool classof(const VPUser *U)
void execute(VPTransformState &State) override
Generate the wide load/store.
VPWidenMemoryRecipe * clone() override
Clone the current recipe.
Instruction & getIngredient() const
bool Consecutive
Whether the accessed addresses are consecutive.
static bool classof(const VPRecipeBase *R)
VPValue * getMask() const
Return the mask used by this recipe.
Align Alignment
Alignment information for this memory access.
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I, std::initializer_list< VPValue * > Operands, bool Consecutive, bool Reverse, Align Alignment, const VPIRMetadata &Metadata, DebugLoc DL)
bool isMasked() const
Returns true if the recipe is masked.
void setMask(VPValue *Mask)
Align getAlign() const
Returns the alignment of the memory access.
VPValue * getAddr() const
Return the address accessed by this recipe.
bool isReverse() const
Return whether the consecutive loaded/stored addresses are in reverse order.
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start=nullptr, DebugLoc DL=DebugLoc::getUnknown(), const Twine &Name="")
Create a new VPWidenPHIRecipe for Phi with start value Start and debug location DL.
VPWidenPHIRecipe * clone() override
Clone the current recipe.
~VPWidenPHIRecipe() override=default
void execute(VPTransformState &State) override
Generate the phi/select nodes.
VPWidenPointerInductionRecipe * clone() override
Clone the current recipe.
~VPWidenPointerInductionRecipe() override=default
bool onlyScalarsGenerated(bool IsScalable)
Returns true if only scalar values will be generated.
void execute(VPTransformState &State) override
Generate vector values for the pointer induction.
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step, VPValue *NumUnrolledElems, const InductionDescriptor &IndDesc, bool IsScalarAfterVectorization, DebugLoc DL)
Create a new VPWidenPointerInductionRecipe for Phi with start value Start and the number of elements ...
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...
VPWidenRecipe * clone() override
Clone the current recipe.
VPWidenRecipe(Instruction &I, ArrayRef< VPValue * > Operands)
VPWidenRecipe(unsigned Opcode, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, const VPIRMetadata &Metadata, DebugLoc DL)
~VPWidenRecipe() override=default
unsigned getOpcode() const
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
void printDOT(raw_ostream &O) const
Print this VPlan in DOT format to O.
friend class VPSlotTracker
std::string getName() const
Return a string with the name of the plan and the applicable VFs and UFs.
bool hasVF(ElementCount VF) const
LLVMContext & getContext() const
VPBasicBlock * getEntry()
VPValue & getVectorTripCount()
The vector trip count.
void setName(const Twine &newName)
bool hasScalableVF() const
VPValue & getVFxUF()
Returns VF * UF of the vector loop region.
VPValue & getVF()
Returns the VF of the vector loop region.
VPValue * getTripCount() const
The trip count of the original loop.
VPValue * getTrue()
Return a VPValue wrapping i1 true.
VPValue * getOrCreateBackedgeTakenCount()
The backedge taken count of the original loop.
iterator_range< SmallSetVector< ElementCount, 2 >::iterator > vectorFactors() const
Returns an iterator range over all VFs of the plan.
VPlan(BasicBlock *ScalarHeaderBB, VPValue *TC)
Construct a VPlan with a new VPBasicBlock as entry, a VPIRBasicBlock wrapping ScalarHeaderBB and a tr...
VPIRBasicBlock * getExitBlock(BasicBlock *IRBB) const
Return the VPIRBasicBlock corresponding to IRBB.
LLVM_ABI_FOR_TEST ~VPlan()
const VPValue & getVF() const
bool isExitBlock(VPBlockBase *VPBB)
Returns true if VPBB is an exit block.
const VPBasicBlock * getEntry() const
friend class VPlanPrinter
VPValue * getConstantInt(const APInt &Val)
Return a VPValue wrapping a ConstantInt with the given APInt value.
VPRegionBlock * createReplicateRegion(VPBlockBase *Entry, VPBlockBase *Exiting, const std::string &Name="")
Create a new replicate region with Entry, Exiting and Name.
VPIRBasicBlock * createEmptyVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock wrapping IRBB, but do not create VPIRInstructions wrapping the instructions i...
bool hasUF(unsigned UF) const
ArrayRef< VPIRBasicBlock * > getExitBlocks() const
Return an ArrayRef containing VPIRBasicBlocks wrapping the exit blocks of the original scalar loop.
VPValue * getConstantInt(Type *Ty, uint64_t Val, bool IsSigned=false)
Return a VPValue wrapping a ConstantInt with the given type and value.
VPValue * getBackedgeTakenCount() const
void setVF(ElementCount VF)
bool isUnrolled() const
Returns true if the VPlan already has been unrolled, i.e.
LLVM_ABI_FOR_TEST VPRegionBlock * getVectorLoopRegion()
Returns the VPRegionBlock of the vector loop.
bool hasEarlyExit() const
Returns true if the VPlan is based on a loop with an early exit.
InstructionCost cost(ElementCount VF, VPCostContext &Ctx)
Return the cost of this plan.
const VPBasicBlock * getMiddleBlock() const
void setTripCount(VPValue *NewTripCount)
Set the trip count assuming it is currently null; if it is not - use resetTripCount().
void resetTripCount(VPValue *NewTripCount)
Resets the trip count for the VPlan.
VPBasicBlock * getMiddleBlock()
Returns the 'middle' block of the plan, that is the block that selects whether to execute the scalar ...
void setEntry(VPBasicBlock *VPBB)
VPBasicBlock * createVPBasicBlock(const Twine &Name, VPRecipeBase *Recipe=nullptr)
Create a new VPBasicBlock with Name and containing Recipe if present.
LLVM_ABI_FOR_TEST VPIRBasicBlock * createVPIRBasicBlock(BasicBlock *IRBB)
Create a VPIRBasicBlock from IRBB containing VPIRInstructions for all instructions in IRBB,...
VPValue * getFalse()
Return a VPValue wrapping i1 false.
VPValue * getOrAddLiveIn(Value *V)
Gets the live-in VPValue for V or adds a new live-in (if none exists yet) for V.
VPRegionBlock * createLoopRegion(const std::string &Name="", VPBlockBase *Entry=nullptr, VPBlockBase *Exiting=nullptr)
Create a new loop region with Name and entry and exiting blocks set to Entry and Exiting respectively...
LLVM_DUMP_METHOD void dump() const
Dump the plan to stderr (for debugging).
bool hasScalarVFOnly() const
VPBasicBlock * getScalarPreheader() const
Return the VPBasicBlock for the preheader of the scalar loop.
void execute(VPTransformState *State)
Generate the IR code for this VPlan.
ArrayRef< VPValue * > getLiveIns() const
Return the list of live-in VPValues available in the VPlan.
void print(raw_ostream &O) const
Print this VPlan to O.
void addVF(ElementCount VF)
VPIRBasicBlock * getScalarHeader() const
Return the VPIRBasicBlock wrapping the header of the scalar loop.
VPValue * getLiveIn(Value *V) const
Return the live-in VPValue for V, if there is one or nullptr otherwise.
VPValue * getConstantInt(unsigned BitWidth, uint64_t Val, bool IsSigned=false)
Return a VPValue wrapping a ConstantInt with the given bitwidth and value.
void printLiveIns(raw_ostream &O) const
Print the live-ins of this VPlan to O.
VPBasicBlock * getVectorPreheader()
Returns the preheader of the vector loop region, if one exists, or null otherwise.
bool hasScalarTail() const
Returns true if the scalar tail may execute after the vector loop.
VPlan * duplicate()
Clone the current VPlan, update all VPValues of the new VPlan and cloned recipes to refer to the clon...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
ilist_node_with_parent()=default
Increasing range of size_t indices.
base_list_type::const_reverse_iterator const_reverse_iterator
base_list_type::reverse_iterator reverse_iterator
base_list_type::const_iterator const_iterator
base_list_type::iterator iterator
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void getMetadataToPropagate(Instruction *Inst, SmallVectorImpl< std::pair< unsigned, MDNode * > > &Metadata)
Add metadata from Inst to Metadata, if it can be preserved after vectorization.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto cast_or_null(const Y &Val)
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
auto map_range(ContainerTy &&C, FuncTy F)
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
RecurKind
These are the kinds of recurrences that we support.
@ Mul
Product of integers.
@ Sub
Subtraction of integers.
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
constexpr unsigned BitWidth
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
DenseMap< Value *, VPValue * > Value2VPValueTy
std::unique_ptr< VPlan > VPlanPtr
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the recipe types implementing...
static VPPhiAccessors * doCastIfPossible(SrcTy f)
doCastIfPossible is used by dyn_cast<>.
CastInfo< VPPhiAccessors, SrcTy > Self
static VPPhiAccessors * doCast(SrcTy R)
doCast is used by cast<>.
This struct provides a method for customizing the way a cast is performed.
static bool isPossible(const VPRecipeBase *f)
This struct provides a way to check if a given cast is possible.
static bool isPossible(const SrcTy &f)
Struct to hold various analysis needed for cost computations.
void execute(VPTransformState &State) override
Generate the phi nodes.
VPFirstOrderRecurrencePHIRecipe * clone() override
Clone the current recipe.
VPFirstOrderRecurrencePHIRecipe(PHINode *Phi, VPValue &Start)
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this first-order recurrence phi recipe.
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
DisjointFlagsTy(bool IsDisjoint)
NonNegFlagsTy(bool IsNonNeg)
TruncFlagsTy(bool HasNUW, bool HasNSW)
WrapFlagsTy(bool HasNUW, bool HasNSW)
static bool classof(const VPRecipeBase *U)
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
static bool classof(const VPUser *U)
VPPhi * clone() override
Clone the current recipe.
const VPRecipeBase * getAsRecipe() const override
Return a VPRecipeBase* to the current object.
VPPhi(ArrayRef< VPValue * > Operands, DebugLoc DL, const Twine &Name="")
static bool classof(const VPSingleDefRecipe *SDR)
static bool classof(const VPValue *V)
A pure-virtual common base class for recipes defining a single VPValue and using IR flags.
static bool classof(const VPRecipeBase *R)
InstructionCost getCostForRecipeWithOpcode(unsigned Opcode, ElementCount VF, VPCostContext &Ctx) const
Compute the cost for this recipe for VF, using Opcode and Ctx.
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, Instruction &I)
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, const VPIRFlags &Flags, DebugLoc DL=DebugLoc::getUnknown())
static bool classof(const VPValue *V)
static bool classof(const VPSingleDefRecipe *U)
void execute(VPTransformState &State) override=0
The method which generates the output IR instructions that correspond to this VPRecipe,...
VPRecipeWithIRFlags * clone() override=0
Clone the current recipe.
static bool classof(const VPUser *U)
VPRecipeWithIRFlags(const unsigned char SC, ArrayRef< VPValue * > Operands, DebugLoc DL=DebugLoc::getUnknown())
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.
void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override
Print the recipe.
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue *Addr, VPValue &EVL, VPValue *Mask)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
A recipe for widening load operations, using the address to load from and an optional mask.
VP_CLASSOF_IMPL(VPDef::VPWidenLoadSC)
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
void execute(VPTransformState &State) override
Generate a wide load or gather.
VPWidenLoadRecipe * clone() override
Clone the current recipe.
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask, bool Consecutive, bool Reverse, Align Alignment, const VPIRMetadata &Metadata, DebugLoc DL)
bool isInvariantCond() const
VPWidenSelectRecipe * clone() override
Clone the current recipe.
VPWidenSelectRecipe(SelectInst &I, ArrayRef< VPValue * > Operands)
VPValue * getCond() const
unsigned getOpcode() const
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
~VPWidenSelectRecipe() override=default
VPValue * getStoredValue() const
Return the address accessed by this recipe.
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.
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue *Addr, VPValue &EVL, VPValue *Mask)
InstructionCost computeCost(ElementCount VF, VPCostContext &Ctx) const override
Return the cost of this VPWidenStoreEVLRecipe.
VPValue * getEVL() const
Return the EVL operand.
A recipe for widening store operations, using the stored value, the address to store to and an option...
bool onlyFirstLaneUsed(const VPValue *Op) const override
Returns true if the recipe only uses the first lane of operand Op.
VP_CLASSOF_IMPL(VPDef::VPWidenStoreSC)
VPValue * getStoredValue() const
Return the value stored by this recipe.
VPWidenStoreRecipe * clone() override
Clone the current recipe.
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal, VPValue *Mask, bool Consecutive, bool Reverse, Align Alignment, const VPIRMetadata &Metadata, DebugLoc DL)