LLVM 22.0.0git
VPlanPatternMatch.h
Go to the documentation of this file.
1//===- VPlanPatternMatch.h - Match on VPValues and recipes ------*- 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// This file provides a simple and efficient mechanism for performing general
10// tree-based pattern matches on the VPlan values and recipes, based on
11// LLVM's IR pattern matchers.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORM_VECTORIZE_VPLANPATTERNMATCH_H
16#define LLVM_TRANSFORM_VECTORIZE_VPLANPATTERNMATCH_H
17
18#include "VPlan.h"
19
20namespace llvm {
22
23template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
24 return P.match(V);
25}
26
27template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
28 auto *R = dyn_cast<VPRecipeBase>(U);
29 return R && match(R, P);
30}
31
32template <typename Val, typename Pattern> struct VPMatchFunctor {
33 const Pattern &P;
34 VPMatchFunctor(const Pattern &P) : P(P) {}
35 bool operator()(Val *V) const { return match(V, P); }
36};
37
38/// A match functor that can be used as a UnaryPredicate in functional
39/// algorithms like all_of.
40template <typename Val = VPUser, typename Pattern>
44
45template <typename Class> struct class_match {
46 template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
47};
48
49/// Match an arbitrary VPValue and ignore it.
51
52template <typename Class> struct bind_ty {
53 Class *&VR;
54
55 bind_ty(Class *&V) : VR(V) {}
56
57 template <typename ITy> bool match(ITy *V) const {
58 if (auto *CV = dyn_cast<Class>(V)) {
59 VR = CV;
60 return true;
61 }
62 return false;
63 }
64};
65
66/// Match a specified VPValue.
68 const VPValue *Val;
69
70 specificval_ty(const VPValue *V) : Val(V) {}
71
72 bool match(VPValue *VPV) const { return VPV == Val; }
73};
74
75inline specificval_ty m_Specific(const VPValue *VPV) { return VPV; }
76
77/// Stores a reference to the VPValue *, not the VPValue * itself,
78/// thus can be used in commutative matchers.
80 VPValue *const &Val;
81
82 deferredval_ty(VPValue *const &V) : Val(V) {}
83
84 bool match(VPValue *const V) const { return V == Val; }
85};
86
87/// Like m_Specific(), but works if the specific value to match is determined
88/// as part of the same match() expression. For example:
89/// m_Mul(m_VPValue(X), m_Specific(X)) is incorrect, because m_Specific() will
90/// bind X before the pattern match starts.
91/// m_Mul(m_VPValue(X), m_Deferred(X)) is correct, and will check against
92/// whichever value m_VPValue(X) populated.
93inline deferredval_ty m_Deferred(VPValue *const &V) { return V; }
94
95/// Match an integer constant or vector of constants if Pred::isValue returns
96/// true for the APInt. \p BitWidth optionally specifies the bitwidth the
97/// matched constant must have. If it is 0, the matched constant can have any
98/// bitwidth.
99template <typename Pred, unsigned BitWidth = 0> struct int_pred_ty {
100 Pred P;
101
102 int_pred_ty(Pred P) : P(std::move(P)) {}
103 int_pred_ty() : P() {}
104
105 bool match(VPValue *VPV) const {
106 if (!VPV->isLiveIn())
107 return false;
108 Value *V = VPV->getLiveInIRValue();
109 if (!V)
110 return false;
111 assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
112 const auto *CI = dyn_cast<ConstantInt>(V);
113 if (!CI)
114 return false;
115
116 if (BitWidth != 0 && CI->getBitWidth() != BitWidth)
117 return false;
118 return P.isValue(CI->getValue());
119 }
120};
121
122/// Match a specified integer value or vector of all elements of that
123/// value. \p BitWidth optionally specifies the bitwidth the matched constant
124/// must have. If it is 0, the matched constant can have any bitwidth.
127
129
130 bool isValue(const APInt &C) const { return APInt::isSameValue(Val, C); }
131};
132
133template <unsigned Bitwidth = 0>
135
139
143
147
149 bool isValue(const APInt &C) const { return C.isAllOnes(); }
150};
151
152/// Match an integer or vector with all bits set.
153/// For vectors, this includes constants with undefined elements.
157
159 bool isValue(const APInt &C) const { return C.isZero(); }
160};
161
162struct is_one {
163 bool isValue(const APInt &C) const { return C.isOne(); }
164};
165
166/// Match an integer 0 or a vector with all elements equal to 0.
167/// For vectors, this includes constants with undefined elements.
171
172/// Match an integer 1 or a vector with all elements equal to 1.
173/// For vectors, this includes constants with undefined elements.
175
177 const APInt *&Res;
178
179 bind_apint(const APInt *&Res) : Res(Res) {}
180
181 bool match(VPValue *VPV) const {
182 if (!VPV->isLiveIn())
183 return false;
184 Value *V = VPV->getLiveInIRValue();
185 if (!V)
186 return false;
187 assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
188 const auto *CI = dyn_cast<ConstantInt>(V);
189 if (!CI)
190 return false;
191 Res = &CI->getValue();
192 return true;
193 }
194};
195
196inline bind_apint m_APInt(const APInt *&C) { return C; }
197
200
202
203 bool match(VPValue *VPV) const {
204 const APInt *APConst;
205 if (!bind_apint(APConst).match(VPV))
206 return false;
207 if (auto C = APConst->tryZExtValue()) {
208 Res = *C;
209 return true;
210 }
211 return false;
212 }
213};
214
215/// Match a plain integer constant no wider than 64-bits, capturing it if we
216/// match.
218
219/// Matching combinators
220template <typename LTy, typename RTy> struct match_combine_or {
221 LTy L;
222 RTy R;
223
224 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
225
226 template <typename ITy> bool match(ITy *V) const {
227 return L.match(V) || R.match(V);
228 }
229};
230
231template <typename LTy, typename RTy> struct match_combine_and {
232 LTy L;
233 RTy R;
234
235 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
236
237 template <typename ITy> bool match(ITy *V) const {
238 return L.match(V) && R.match(V);
239 }
240};
241
242/// Combine two pattern matchers matching L || R
243template <typename LTy, typename RTy>
244inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
245 return match_combine_or<LTy, RTy>(L, R);
246}
247
248/// Combine two pattern matchers matching L && R
249template <typename LTy, typename RTy>
250inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
251 return match_combine_and<LTy, RTy>(L, R);
252}
253
254/// Match a VPValue, capturing it if we match.
255inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
256
257/// Match a VPInstruction, capturing if we match.
259
260template <typename Ops_t, unsigned Opcode, bool Commutative,
261 typename... RecipeTys>
263 Ops_t Ops;
264
265 template <typename... OpTy> Recipe_match(OpTy... Ops) : Ops(Ops...) {
266 static_assert(std::tuple_size<Ops_t>::value == sizeof...(Ops) &&
267 "number of operands in constructor doesn't match Ops_t");
268 static_assert((!Commutative || std::tuple_size<Ops_t>::value == 2) &&
269 "only binary ops can be commutative");
270 }
271
272 bool match(const VPValue *V) const {
273 auto *DefR = V->getDefiningRecipe();
274 return DefR && match(DefR);
275 }
276
277 bool match(const VPSingleDefRecipe *R) const {
278 return match(static_cast<const VPRecipeBase *>(R));
279 }
280
281 bool match(const VPRecipeBase *R) const {
282 if (std::tuple_size_v<Ops_t> == 0) {
283 auto *VPI = dyn_cast<VPInstruction>(R);
284 return VPI && VPI->getOpcode() == Opcode;
285 }
286
287 if ((!matchRecipeAndOpcode<RecipeTys>(R) && ...))
288 return false;
289
290 if (R->getNumOperands() != std::tuple_size<Ops_t>::value) {
291 assert(Opcode == Instruction::PHI &&
292 "non-variadic recipe with matched opcode does not have the "
293 "expected number of operands");
294 return false;
295 }
296
297 auto IdxSeq = std::make_index_sequence<std::tuple_size<Ops_t>::value>();
298 if (all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
299 return Op.match(R->getOperand(Idx));
300 }))
301 return true;
302
303 return Commutative &&
304 all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
305 return Op.match(R->getOperand(R->getNumOperands() - Idx - 1));
306 });
307 }
308
309private:
310 template <typename RecipeTy>
311 static bool matchRecipeAndOpcode(const VPRecipeBase *R) {
312 auto *DefR = dyn_cast<RecipeTy>(R);
313 // Check for recipes that do not have opcodes.
314 if constexpr (std::is_same_v<RecipeTy, VPScalarIVStepsRecipe> ||
315 std::is_same_v<RecipeTy, VPCanonicalIVPHIRecipe> ||
316 std::is_same_v<RecipeTy, VPDerivedIVRecipe> ||
317 std::is_same_v<RecipeTy, VPVectorEndPointerRecipe>)
318 return DefR;
319 else
320 return DefR && DefR->getOpcode() == Opcode;
321 }
322
323 /// Helper to check if predicate \p P holds on all tuple elements in Ops using
324 /// the provided index sequence.
325 template <typename Fn, std::size_t... Is>
326 bool all_of_tuple_elements(std::index_sequence<Is...>, Fn P) const {
327 return (P(std::get<Is>(Ops), Is) && ...);
328 }
329};
330
331template <unsigned Opcode, typename... OpTys>
333 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ false,
336
337template <unsigned Opcode, typename... OpTys>
339 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ true,
341
342template <unsigned Opcode, typename... OpTys>
343using VPInstruction_match = Recipe_match<std::tuple<OpTys...>, Opcode,
344 /*Commutative*/ false, VPInstruction>;
345
346template <unsigned Opcode, typename... OpTys>
347inline VPInstruction_match<Opcode, OpTys...>
348m_VPInstruction(const OpTys &...Ops) {
349 return VPInstruction_match<Opcode, OpTys...>(Ops...);
350}
351
352/// BuildVector is matches only its opcode, w/o matching its operands as the
353/// number of operands is not fixed.
357
358template <typename Op0_t>
360m_Freeze(const Op0_t &Op0) {
362}
363
367
368template <typename Op0_t>
370m_BranchOnCond(const Op0_t &Op0) {
372}
373
374template <typename Op0_t>
376m_Broadcast(const Op0_t &Op0) {
378}
379
380template <typename Op0_t>
382m_EVL(const Op0_t &Op0) {
384}
385
386template <typename Op0_t>
391
392template <typename Op0_t, typename Op1_t>
394m_ExtractElement(const Op0_t &Op0, const Op1_t &Op1) {
396}
397
398template <typename Op0_t>
403
404template <typename Op0_t, typename Op1_t, typename Op2_t>
406m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
408}
409
413
414template <typename Op0_t, typename Op1_t>
416m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
418}
419
420template <typename Op0_t>
422m_AnyOf(const Op0_t &Op0) {
424}
425
426template <typename Op0_t>
431
432template <unsigned Opcode, typename Op0_t>
433inline AllRecipe_match<Opcode, Op0_t> m_Unary(const Op0_t &Op0) {
435}
436
437template <typename Op0_t>
441
442template <typename Op0_t>
446
447template <typename Op0_t>
451
452template <typename Op0_t>
455m_ZExtOrSExt(const Op0_t &Op0) {
456 return m_CombineOr(m_ZExt(Op0), m_SExt(Op0));
457}
458
459template <typename Op0_t>
461m_ZExtOrSelf(const Op0_t &Op0) {
462 return m_CombineOr(m_ZExt(Op0), Op0);
463}
464
465template <unsigned Opcode, typename Op0_t, typename Op1_t>
467 const Op1_t &Op1) {
469}
470
471template <unsigned Opcode, typename Op0_t, typename Op1_t>
473m_c_Binary(const Op0_t &Op0, const Op1_t &Op1) {
475}
476
477template <typename Op0_t, typename Op1_t>
479m_c_Add(const Op0_t &Op0, const Op1_t &Op1) {
481}
482
483template <typename Op0_t, typename Op1_t>
485 const Op1_t &Op1) {
487}
488
489template <typename Op0_t, typename Op1_t>
491 const Op1_t &Op1) {
493}
494
495template <typename Op0_t, typename Op1_t>
497m_c_Mul(const Op0_t &Op0, const Op1_t &Op1) {
499}
500
501/// Match a binary AND operation.
502template <typename Op0_t, typename Op1_t>
504m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1) {
506}
507
508/// Match a binary OR operation. Note that while conceptually the operands can
509/// be matched commutatively, \p Commutative defaults to false in line with the
510/// IR-based pattern matching infrastructure. Use m_c_BinaryOr for a commutative
511/// version of the matcher.
512template <typename Op0_t, typename Op1_t>
514m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
516}
517
518template <typename Op0_t, typename Op1_t>
520m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
522}
523
524/// Cmp_match is a variant of BinaryRecipe_match that also binds the comparison
525/// predicate. Opcodes must either be Instruction::ICmp or Instruction::FCmp, or
526/// both.
527template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
528struct Cmp_match {
529 static_assert((sizeof...(Opcodes) == 1 || sizeof...(Opcodes) == 2) &&
530 "Expected one or two opcodes");
531 static_assert(
532 ((Opcodes == Instruction::ICmp || Opcodes == Instruction::FCmp) && ...) &&
533 "Expected a compare instruction opcode");
534
536 Op0_t Op0;
538
539 Cmp_match(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
540 : Predicate(&Pred), Op0(Op0), Op1(Op1) {}
541 Cmp_match(const Op0_t &Op0, const Op1_t &Op1) : Op0(Op0), Op1(Op1) {}
542
543 bool match(const VPValue *V) const {
544 auto *DefR = V->getDefiningRecipe();
545 return DefR && match(DefR);
546 }
547
548 bool match(const VPRecipeBase *V) const {
549 if ((m_Binary<Opcodes>(Op0, Op1).match(V) || ...)) {
550 if (Predicate)
551 *Predicate = cast<VPRecipeWithIRFlags>(V)->getPredicate();
552 return true;
553 }
554 return false;
555 }
556};
557
558/// SpecificCmp_match is a variant of Cmp_match that matches the comparison
559/// predicate, instead of binding it.
560template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
563 Op0_t Op0;
565
566 SpecificCmp_match(CmpPredicate Pred, const Op0_t &LHS, const Op1_t &RHS)
567 : Predicate(Pred), Op0(LHS), Op1(RHS) {}
568
569 bool match(const VPValue *V) const {
570 CmpPredicate CurrentPred;
571 return Cmp_match<Op0_t, Op1_t, Opcodes...>(CurrentPred, Op0, Op1)
572 .match(V) &&
574 }
575};
576
577template <typename Op0_t, typename Op1_t>
579 const Op1_t &Op1) {
581}
582
583template <typename Op0_t, typename Op1_t>
584inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp>
585m_ICmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
586 return Cmp_match<Op0_t, Op1_t, Instruction::ICmp>(Pred, Op0, Op1);
587}
588
589template <typename Op0_t, typename Op1_t>
590inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp>
591m_SpecificICmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
593 Op1);
594}
595
596template <typename Op0_t, typename Op1_t>
597inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
598m_Cmp(const Op0_t &Op0, const Op1_t &Op1) {
600 Op1);
601}
602
603template <typename Op0_t, typename Op1_t>
604inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
605m_Cmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
607 Pred, Op0, Op1);
608}
609
610template <typename Op0_t, typename Op1_t>
611inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
612m_SpecificCmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
614 MatchPred, Op0, Op1);
615}
616
617template <typename Op0_t, typename Op1_t>
619 Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
620 /*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe>,
624
625template <typename Op0_t, typename Op1_t>
627 const Op1_t &Op1) {
628 return m_CombineOr(
629 Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
630 /*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe>(
631 Op0, Op1),
635 Op1)));
636}
637
638template <typename Op0_t, typename Op1_t, typename Op2_t>
640m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
642 {Op0, Op1, Op2});
643}
644
645template <typename Op0_t>
648 Instruction::Xor, int_pred_ty<is_all_ones>, Op0_t>>
653
654template <typename Op0_t, typename Op1_t>
655inline match_combine_or<
658m_LogicalAnd(const Op0_t &Op0, const Op1_t &Op1) {
659 return m_CombineOr(
661 m_Select(Op0, Op1, m_False()));
662}
663
664template <typename Op0_t, typename Op1_t>
666m_LogicalOr(const Op0_t &Op0, const Op1_t &Op1) {
667 return m_Select(Op0, m_True(), Op1);
668}
669
670template <typename Op0_t, typename Op1_t, typename Op2_t>
672 false, VPScalarIVStepsRecipe>;
673
674template <typename Op0_t, typename Op1_t, typename Op2_t>
676m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
677 return VPScalarIVSteps_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
678}
679
680template <typename Op0_t, typename Op1_t, typename Op2_t>
683
684template <typename Op0_t, typename Op1_t, typename Op2_t>
686m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
687 return VPDerivedIV_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
688}
689
690template <typename Addr_t, typename Mask_t> struct Load_match {
691 Addr_t Addr;
692 Mask_t Mask;
693
694 Load_match(Addr_t Addr, Mask_t Mask) : Addr(Addr), Mask(Mask) {}
695
696 template <typename OpTy> bool match(const OpTy *V) const {
697 auto *Load = dyn_cast<VPWidenLoadRecipe>(V);
698 if (!Load || !Addr.match(Load->getAddr()) || !Load->isMasked() ||
699 !Mask.match(Load->getMask()))
700 return false;
701 return true;
702 }
703};
704
705/// Match a (possibly reversed) masked load.
706template <typename Addr_t, typename Mask_t>
707inline Load_match<Addr_t, Mask_t> m_MaskedLoad(const Addr_t &Addr,
708 const Mask_t &Mask) {
709 return Load_match<Addr_t, Mask_t>(Addr, Mask);
710}
711
712template <typename Addr_t, typename Val_t, typename Mask_t> struct Store_match {
713 Addr_t Addr;
714 Val_t Val;
715 Mask_t Mask;
716
717 Store_match(Addr_t Addr, Val_t Val, Mask_t Mask)
718 : Addr(Addr), Val(Val), Mask(Mask) {}
719
720 template <typename OpTy> bool match(const OpTy *V) const {
721 auto *Store = dyn_cast<VPWidenStoreRecipe>(V);
722 if (!Store || !Addr.match(Store->getAddr()) ||
723 !Val.match(Store->getStoredValue()) || !Store->isMasked() ||
724 !Mask.match(Store->getMask()))
725 return false;
726 return true;
727 }
728};
729
730/// Match a (possibly reversed) masked store.
731template <typename Addr_t, typename Val_t, typename Mask_t>
732inline Store_match<Addr_t, Val_t, Mask_t>
733m_MaskedStore(const Addr_t &Addr, const Val_t &Val, const Mask_t &Mask) {
734 return Store_match<Addr_t, Val_t, Mask_t>(Addr, Val, Mask);
735}
736
737template <typename Op0_t, typename Op1_t>
740 /*Commutative*/ false, VPVectorEndPointerRecipe>;
741
742template <typename Op0_t, typename Op1_t>
747
748/// Match a call argument at a given argument index.
749template <typename Opnd_t> struct Argument_match {
750 /// Call argument index to match.
751 unsigned OpI;
752 Opnd_t Val;
753
754 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
755
756 template <typename OpTy> bool match(OpTy *V) const {
757 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
758 return Val.match(R->getOperand(OpI));
759 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
760 return Val.match(R->getOperand(OpI));
761 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
762 if (isa<CallInst>(R->getUnderlyingInstr()))
763 return Val.match(R->getOperand(OpI + 1));
764 return false;
765 }
766};
767
768/// Match a call argument.
769template <unsigned OpI, typename Opnd_t>
770inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
771 return Argument_match<Opnd_t>(OpI, Op);
772}
773
774/// Intrinsic matchers.
776 unsigned ID;
777
778 IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
779
780 template <typename OpTy> bool match(OpTy *V) const {
781 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
782 return R->getVectorIntrinsicID() == ID;
783 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
784 return R->getCalledScalarFunction()->getIntrinsicID() == ID;
785 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
786 if (const auto *CI = dyn_cast<CallInst>(R->getUnderlyingInstr()))
787 if (const auto *F = CI->getCalledFunction())
788 return F->getIntrinsicID() == ID;
789 return false;
790 }
791};
792
793/// Intrinsic matches are combinations of ID matchers, and argument
794/// matchers. Higher arity matcher are defined recursively in terms of and-ing
795/// them with lower arity matchers. Here's some convenient typedefs for up to
796/// several arguments, and more can be added as needed
797template <typename T0 = void, typename T1 = void, typename T2 = void,
798 typename T3 = void>
799struct m_Intrinsic_Ty;
800template <typename T0> struct m_Intrinsic_Ty<T0> {
802};
803template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
804 using Ty =
806};
807template <typename T0, typename T1, typename T2>
812template <typename T0, typename T1, typename T2, typename T3>
817
818/// Match intrinsic calls like this:
819/// m_Intrinsic<Intrinsic::fabs>(m_VPValue(X), ...)
820template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
821 return IntrinsicID_match(IntrID);
822}
823
824template <Intrinsic::ID IntrID, typename T0>
825inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
827}
828
829template <Intrinsic::ID IntrID, typename T0, typename T1>
830inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
831 const T1 &Op1) {
833}
834
835template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
836inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
837m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
838 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
839}
840
841template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
842 typename T3>
844m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
845 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
846}
847
849 template <typename ITy> bool match(ITy *V) const {
850 VPValue *Val = dyn_cast<VPValue>(V);
851 return Val && Val->isLiveIn();
852 }
853};
854
856
857template <typename SubPattern_t> struct OneUse_match {
858 SubPattern_t SubPattern;
859
860 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
861
862 template <typename OpTy> bool match(OpTy *V) {
863 return V->hasOneUse() && SubPattern.match(V);
864 }
865};
866
867template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
868 return SubPattern;
869}
870
871} // namespace VPlanPatternMatch
872} // namespace llvm
873
874#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:55
#define T
#define T1
MachineInstr unsigned OpIdx
#define P(N)
This file contains the declarations of the Vectorization Plan base classes:
Value * RHS
Value * LHS
Class for arbitrary precision integers.
Definition APInt.h:78
std::optional< uint64_t > tryZExtValue() const
Get zero extended value if possible.
Definition APInt.h:1552
static bool isSameValue(const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!...
Definition APInt.h:553
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition VPlan.h:3642
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:976
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:386
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:2875
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3711
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition VPlan.h:517
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:199
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:48
Value * getLiveInIRValue() const
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition VPlanValue.h:176
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition VPlanValue.h:171
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:1848
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1489
A recipe for handling GEP instructions.
Definition VPlan.h:1776
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1446
LLVM Value Representation.
Definition Value.h:75
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
AllRecipe_match< Instruction::Select, Op0_t, Op1_t, Op2_t > m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
VPInstruction_match< Instruction::Freeze, Op0_t > m_Freeze(const Op0_t &Op0)
AllRecipe_commutative_match< Instruction::And, Op0_t, Op1_t > m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1)
Match a binary AND operation.
AllRecipe_match< Instruction::ZExt, Op0_t > m_ZExt(const Op0_t &Op0)
AllRecipe_match< Instruction::Or, Op0_t, Op1_t > m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
Match a binary OR operation.
int_pred_ty< is_specific_int, Bitwidth > specific_intval
Store_match< Addr_t, Val_t, Mask_t > m_MaskedStore(const Addr_t &Addr, const Val_t &Val, const Mask_t &Mask)
Match a (possibly reversed) masked store.
int_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
SpecificCmp_match< Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp > m_SpecificCmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1)
match_combine_or< VPInstruction_match< VPInstruction::Not, Op0_t >, AllRecipe_commutative_match< Instruction::Xor, int_pred_ty< is_all_ones >, Op0_t > > m_Not(const Op0_t &Op0)
int_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
AllRecipe_commutative_match< Opcode, Op0_t, Op1_t > m_c_Binary(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_commutative_match< Instruction::Add, Op0_t, Op1_t > m_c_Add(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_commutative_match< Instruction::Or, Op0_t, Op1_t > m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
match_combine_or< AllRecipe_match< Instruction::ZExt, Op0_t >, AllRecipe_match< Instruction::SExt, Op0_t > > m_ZExtOrSExt(const Op0_t &Op0)
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
SpecificCmp_match< Op0_t, Op1_t, Instruction::ICmp > m_SpecificICmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1)
VPInstruction_match< VPInstruction::AnyOf, Op0_t > m_AnyOf(const Op0_t &Op0)
VPScalarIVSteps_match< Op0_t, Op1_t, Op2_t > m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
GEPLikeRecipe_match< Op0_t, Op1_t > m_GetElementPtr(const Op0_t &Op0, const Op1_t &Op1)
Recipe_match< std::tuple< OpTys... >, Opcode, false, VPInstruction > VPInstruction_match
VPInstruction_match< VPInstruction::ExtractLastLanePerPart, Op0_t > m_ExtractLastLanePerPart(const Op0_t &Op0)
VPInstruction_match< VPInstruction::ExtractLastElement, Op0_t > m_ExtractLastElement(const Op0_t &Op0)
AllRecipe_match< Opcode, Op0_t, Op1_t > m_Binary(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_match< Opcode, Op0_t > m_Unary(const Op0_t &Op0)
Load_match< Addr_t, Mask_t > m_MaskedLoad(const Addr_t &Addr, const Mask_t &Mask)
Match a (possibly reversed) masked load.
AllRecipe_commutative_match< Instruction::Mul, Op0_t, Op1_t > m_c_Mul(const Op0_t &Op0, const Op1_t &Op1)
Cmp_match< Op0_t, Op1_t, Instruction::ICmp > m_ICmp(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_match< Instruction::Mul, Op0_t, Op1_t > m_Mul(const Op0_t &Op0, const Op1_t &Op1)
specificval_ty m_Specific(const VPValue *VPV)
match_combine_or< Recipe_match< std::tuple< Op0_t, Op1_t >, Instruction::GetElementPtr, false, VPReplicateRecipe, VPWidenGEPRecipe >, match_combine_or< VPInstruction_match< VPInstruction::PtrAdd, Op0_t, Op1_t >, VPInstruction_match< VPInstruction::WidePtrAdd, Op0_t, Op1_t > > > GEPLikeRecipe_match
VPInstruction_match< Instruction::ExtractElement, Op0_t, Op1_t > m_ExtractElement(const Op0_t &Op0, const Op1_t &Op1)
specific_intval< 1 > m_False()
VPDerivedIV_match< Op0_t, Op1_t, Op2_t > m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
VPMatchFunctor< Val, Pattern > match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
specific_intval< 0 > m_SpecificInt(uint64_t V)
VPInstruction_match< VPInstruction::ActiveLaneMask, Op0_t, Op1_t, Op2_t > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
VPInstruction_match< VPInstruction::BranchOnCount > m_BranchOnCount()
Recipe_match< std::tuple< Op0_t, Op1_t, Op2_t >, 0, false, VPDerivedIVRecipe > VPDerivedIV_match
AllRecipe_match< Instruction::Sub, Op0_t, Op1_t > m_Sub(const Op0_t &Op0, const Op1_t &Op1)
AllRecipe_match< Instruction::SExt, Op0_t > m_SExt(const Op0_t &Op0)
specific_intval< 1 > m_True()
Recipe_match< std::tuple< OpTys... >, Opcode, false, VPWidenRecipe, VPReplicateRecipe, VPWidenCastRecipe, VPInstruction, VPWidenSelectRecipe > AllRecipe_match
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_VPValue(X), ...)
Recipe_match< std::tuple< OpTys... >, Opcode, true, VPWidenRecipe, VPReplicateRecipe, VPInstruction > AllRecipe_commutative_match
deferredval_ty m_Deferred(VPValue *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
VectorEndPointerRecipe_match< Op0_t, Op1_t > m_VecEndPtr(const Op0_t &Op0, const Op1_t &Op1)
VPInstruction_match< VPInstruction::Broadcast, Op0_t > m_Broadcast(const Op0_t &Op0)
bool match(Val *V, const Pattern &P)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
OneUse_match< T > m_OneUse(const T &SubPattern)
VPInstruction_match< VPInstruction::ExplicitVectorLength, Op0_t > m_EVL(const Op0_t &Op0)
VPInstruction_match< VPInstruction::BuildVector > m_BuildVector()
BuildVector is matches only its opcode, w/o matching its operands as the number of operands is not fi...
AllRecipe_match< Instruction::Trunc, Op0_t > m_Trunc(const Op0_t &Op0)
Recipe_match< std::tuple< Op0_t, Op1_t >, 0, false, VPVectorEndPointerRecipe > VectorEndPointerRecipe_match
match_combine_or< AllRecipe_match< Instruction::ZExt, Op0_t >, Op0_t > m_ZExtOrSelf(const Op0_t &Op0)
VPInstruction_match< VPInstruction::FirstActiveLane, Op0_t > m_FirstActiveLane(const Op0_t &Op0)
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match a call argument.
bind_ty< VPInstruction > m_VPInstruction(VPInstruction *&V)
Match a VPInstruction, capturing if we match.
Recipe_match< std::tuple< Op0_t, Op1_t, Op2_t >, 0, false, VPScalarIVStepsRecipe > VPScalarIVSteps_match
int_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
VPInstruction_match< VPInstruction::BranchOnCond > m_BranchOnCond()
bind_apint m_APInt(const APInt *&C)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1867
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
Intrinsic matches are combinations of ID matchers, and argument matchers.
A recipe for widening select instructions.
Definition VPlan.h:1730
Match a call argument at a given argument index.
unsigned OpI
Call argument index to match.
Argument_match(unsigned OpIdx, const Opnd_t &V)
Cmp_match is a variant of BinaryRecipe_match that also binds the comparison predicate.
Cmp_match(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
Cmp_match(const Op0_t &Op0, const Op1_t &Op1)
bool match(const VPValue *V) const
bool match(const VPRecipeBase *V) const
Load_match(Addr_t Addr, Mask_t Mask)
bool match(const VPSingleDefRecipe *R) const
bool match(const VPValue *V) const
bool match(const VPRecipeBase *R) const
SpecificCmp_match is a variant of Cmp_match that matches the comparison predicate,...
SpecificCmp_match(CmpPredicate Pred, const Op0_t &LHS, const Op1_t &RHS)
Store_match(Addr_t Addr, Val_t Val, Mask_t Mask)
Stores a reference to the VPValue *, not the VPValue * itself, thus can be used in commutative matche...
Match an integer constant or vector of constants if Pred::isValue returns true for the APInt.
bool isValue(const APInt &C) const
Match a specified integer value or vector of all elements of that value.
match_combine_and< typename m_Intrinsic_Ty< T0, T1 >::Ty, Argument_match< T2 > > Ty
match_combine_and< typename m_Intrinsic_Ty< T0 >::Ty, Argument_match< T1 > > Ty
match_combine_and< IntrinsicID_match, Argument_match< T0 > > Ty
Intrinsic matches are combinations of ID matchers, and argument matchers.
match_combine_and< typename m_Intrinsic_Ty< T0, T1, T2 >::Ty, Argument_match< T3 > > Ty
match_combine_and(const LTy &Left, const RTy &Right)
match_combine_or(const LTy &Left, const RTy &Right)