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 Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
33 return P.match(static_cast<const VPRecipeBase *>(R));
34}
35
36template <typename Val, typename Pattern> struct VPMatchFunctor {
37 const Pattern &P;
38 VPMatchFunctor(const Pattern &P) : P(P) {}
39 bool operator()(Val *V) const { return match(V, P); }
40};
41
42/// A match functor that can be used as a UnaryPredicate in functional
43/// algorithms like all_of.
44template <typename Val = VPUser, typename Pattern>
48
49template <typename Class> struct class_match {
50 template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
51};
52
53/// Match an arbitrary VPValue and ignore it.
55
56template <typename Class> struct bind_ty {
57 Class *&VR;
58
59 bind_ty(Class *&V) : VR(V) {}
60
61 template <typename ITy> bool match(ITy *V) const {
62 if (auto *CV = dyn_cast<Class>(V)) {
63 VR = CV;
64 return true;
65 }
66 return false;
67 }
68};
69
70/// Match a specified VPValue.
72 const VPValue *Val;
73
74 specificval_ty(const VPValue *V) : Val(V) {}
75
76 bool match(VPValue *VPV) const { return VPV == Val; }
77};
78
79inline specificval_ty m_Specific(const VPValue *VPV) { return VPV; }
80
81/// Stores a reference to the VPValue *, not the VPValue * itself,
82/// thus can be used in commutative matchers.
84 VPValue *const &Val;
85
86 deferredval_ty(VPValue *const &V) : Val(V) {}
87
88 bool match(VPValue *const V) const { return V == Val; }
89};
90
91/// Like m_Specific(), but works if the specific value to match is determined
92/// as part of the same match() expression. For example:
93/// m_Mul(m_VPValue(X), m_Specific(X)) is incorrect, because m_Specific() will
94/// bind X before the pattern match starts.
95/// m_Mul(m_VPValue(X), m_Deferred(X)) is correct, and will check against
96/// whichever value m_VPValue(X) populated.
97inline deferredval_ty m_Deferred(VPValue *const &V) { return V; }
98
99/// Match an integer constant or vector of constants if Pred::isValue returns
100/// true for the APInt. \p BitWidth optionally specifies the bitwidth the
101/// matched constant must have. If it is 0, the matched constant can have any
102/// bitwidth.
103template <typename Pred, unsigned BitWidth = 0> struct int_pred_ty {
104 Pred P;
105
106 int_pred_ty(Pred P) : P(std::move(P)) {}
107 int_pred_ty() : P() {}
108
109 bool match(VPValue *VPV) const {
110 if (!VPV->isLiveIn())
111 return false;
112 Value *V = VPV->getLiveInIRValue();
113 if (!V)
114 return false;
115 assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
116 const auto *CI = dyn_cast<ConstantInt>(V);
117 if (!CI)
118 return false;
119
120 if (BitWidth != 0 && CI->getBitWidth() != BitWidth)
121 return false;
122 return P.isValue(CI->getValue());
123 }
124};
125
126/// Match a specified integer value or vector of all elements of that
127/// value. \p BitWidth optionally specifies the bitwidth the matched constant
128/// must have. If it is 0, the matched constant can have any bitwidth.
131
133
134 bool isValue(const APInt &C) const { return APInt::isSameValue(Val, C); }
135};
136
137template <unsigned Bitwidth = 0>
139
143
147
151
153 bool isValue(const APInt &C) const { return C.isAllOnes(); }
154};
155
156/// Match an integer or vector with all bits set.
157/// For vectors, this includes constants with undefined elements.
161
163 bool isValue(const APInt &C) const { return C.isZero(); }
164};
165
166struct is_one {
167 bool isValue(const APInt &C) const { return C.isOne(); }
168};
169
170/// Match an integer 0 or a vector with all elements equal to 0.
171/// For vectors, this includes constants with undefined elements.
175
176/// Match an integer 1 or a vector with all elements equal to 1.
177/// For vectors, this includes constants with undefined elements.
179
181 const APInt *&Res;
182
183 bind_apint(const APInt *&Res) : Res(Res) {}
184
185 bool match(VPValue *VPV) const {
186 if (!VPV->isLiveIn())
187 return false;
188 Value *V = VPV->getLiveInIRValue();
189 if (!V)
190 return false;
191 assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
192 const auto *CI = dyn_cast<ConstantInt>(V);
193 if (!CI)
194 return false;
195 Res = &CI->getValue();
196 return true;
197 }
198};
199
200inline bind_apint m_APInt(const APInt *&C) { return C; }
201
204
206
207 bool match(VPValue *VPV) const {
208 const APInt *APConst;
209 if (!bind_apint(APConst).match(VPV))
210 return false;
211 if (auto C = APConst->tryZExtValue()) {
212 Res = *C;
213 return true;
214 }
215 return false;
216 }
217};
218
219/// Match a plain integer constant no wider than 64-bits, capturing it if we
220/// match.
222
223/// Matching combinators
224template <typename LTy, typename RTy> struct match_combine_or {
225 LTy L;
226 RTy R;
227
228 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
229
230 template <typename ITy> bool match(ITy *V) const {
231 return L.match(V) || R.match(V);
232 }
233};
234
235template <typename LTy, typename RTy> struct match_combine_and {
236 LTy L;
237 RTy R;
238
239 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
240
241 template <typename ITy> bool match(ITy *V) const {
242 return L.match(V) && R.match(V);
243 }
244};
245
246/// Combine two pattern matchers matching L || R
247template <typename LTy, typename RTy>
248inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
249 return match_combine_or<LTy, RTy>(L, R);
250}
251
252/// Combine two pattern matchers matching L && R
253template <typename LTy, typename RTy>
254inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
255 return match_combine_and<LTy, RTy>(L, R);
256}
257
258/// Match a VPValue, capturing it if we match.
259inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
260
261/// Match a VPInstruction, capturing if we match.
263
264template <typename Ops_t, unsigned Opcode, bool Commutative,
265 typename... RecipeTys>
267 Ops_t Ops;
268
269 template <typename... OpTy> Recipe_match(OpTy... Ops) : Ops(Ops...) {
270 static_assert(std::tuple_size<Ops_t>::value == sizeof...(Ops) &&
271 "number of operands in constructor doesn't match Ops_t");
272 static_assert((!Commutative || std::tuple_size<Ops_t>::value == 2) &&
273 "only binary ops can be commutative");
274 }
275
276 bool match(const VPValue *V) const {
277 auto *DefR = V->getDefiningRecipe();
278 return DefR && match(DefR);
279 }
280
281 bool match(const VPSingleDefRecipe *R) const {
282 return match(static_cast<const VPRecipeBase *>(R));
283 }
284
285 bool match(const VPRecipeBase *R) const {
286 if (std::tuple_size_v<Ops_t> == 0) {
287 auto *VPI = dyn_cast<VPInstruction>(R);
288 return VPI && VPI->getOpcode() == Opcode;
289 }
290
291 if ((!matchRecipeAndOpcode<RecipeTys>(R) && ...))
292 return false;
293
294 if (R->getNumOperands() != std::tuple_size<Ops_t>::value) {
295 assert(Opcode == Instruction::PHI &&
296 "non-variadic recipe with matched opcode does not have the "
297 "expected number of operands");
298 return false;
299 }
300
301 auto IdxSeq = std::make_index_sequence<std::tuple_size<Ops_t>::value>();
302 if (all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
303 return Op.match(R->getOperand(Idx));
304 }))
305 return true;
306
307 return Commutative &&
308 all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
309 return Op.match(R->getOperand(R->getNumOperands() - Idx - 1));
310 });
311 }
312
313private:
314 template <typename RecipeTy>
315 static bool matchRecipeAndOpcode(const VPRecipeBase *R) {
316 auto *DefR = dyn_cast<RecipeTy>(R);
317 // Check for recipes that do not have opcodes.
318 if constexpr (std::is_same_v<RecipeTy, VPScalarIVStepsRecipe> ||
319 std::is_same_v<RecipeTy, VPCanonicalIVPHIRecipe> ||
320 std::is_same_v<RecipeTy, VPDerivedIVRecipe> ||
321 std::is_same_v<RecipeTy, VPVectorEndPointerRecipe>)
322 return DefR;
323 else
324 return DefR && DefR->getOpcode() == Opcode;
325 }
326
327 /// Helper to check if predicate \p P holds on all tuple elements in Ops using
328 /// the provided index sequence.
329 template <typename Fn, std::size_t... Is>
330 bool all_of_tuple_elements(std::index_sequence<Is...>, Fn P) const {
331 return (P(std::get<Is>(Ops), Is) && ...);
332 }
333};
334
335template <unsigned Opcode, typename... OpTys>
337 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ false,
340
341template <unsigned Opcode, typename... OpTys>
343 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ true,
345
346template <unsigned Opcode, typename... OpTys>
347using VPInstruction_match = Recipe_match<std::tuple<OpTys...>, Opcode,
348 /*Commutative*/ false, VPInstruction>;
349
350template <unsigned Opcode, typename... OpTys>
351inline VPInstruction_match<Opcode, OpTys...>
352m_VPInstruction(const OpTys &...Ops) {
353 return VPInstruction_match<Opcode, OpTys...>(Ops...);
354}
355
356/// BuildVector is matches only its opcode, w/o matching its operands as the
357/// number of operands is not fixed.
361
362template <typename Op0_t>
364m_Freeze(const Op0_t &Op0) {
366}
367
371
372template <typename Op0_t>
374m_BranchOnCond(const Op0_t &Op0) {
376}
377
378template <typename Op0_t>
380m_Broadcast(const Op0_t &Op0) {
382}
383
384template <typename Op0_t>
386m_EVL(const Op0_t &Op0) {
388}
389
390template <typename Op0_t>
395
396template <typename Op0_t, typename Op1_t>
398m_ExtractElement(const Op0_t &Op0, const Op1_t &Op1) {
400}
401
402template <typename Op0_t>
407
408template <typename Op0_t, typename Op1_t, typename Op2_t>
410m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
412}
413
417
418template <typename Op0_t, typename Op1_t>
420m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
422}
423
424template <typename Op0_t>
426m_AnyOf(const Op0_t &Op0) {
428}
429
430template <typename Op0_t>
435
436template <unsigned Opcode, typename Op0_t>
437inline AllRecipe_match<Opcode, Op0_t> m_Unary(const Op0_t &Op0) {
439}
440
441template <typename Op0_t>
445
446template <typename Op0_t>
450
451template <typename Op0_t>
455
456template <typename Op0_t>
459m_ZExtOrSExt(const Op0_t &Op0) {
460 return m_CombineOr(m_ZExt(Op0), m_SExt(Op0));
461}
462
463template <typename Op0_t>
465m_ZExtOrSelf(const Op0_t &Op0) {
466 return m_CombineOr(m_ZExt(Op0), Op0);
467}
468
469template <unsigned Opcode, typename Op0_t, typename Op1_t>
471 const Op1_t &Op1) {
473}
474
475template <unsigned Opcode, typename Op0_t, typename Op1_t>
477m_c_Binary(const Op0_t &Op0, const Op1_t &Op1) {
479}
480
481template <typename Op0_t, typename Op1_t>
483 const Op1_t &Op1) {
485}
486
487template <typename Op0_t, typename Op1_t>
489m_c_Add(const Op0_t &Op0, const Op1_t &Op1) {
491}
492
493template <typename Op0_t, typename Op1_t>
495 const Op1_t &Op1) {
497}
498
499template <typename Op0_t, typename Op1_t>
501 const Op1_t &Op1) {
503}
504
505template <typename Op0_t, typename Op1_t>
507m_c_Mul(const Op0_t &Op0, const Op1_t &Op1) {
509}
510
511/// Match a binary AND operation.
512template <typename Op0_t, typename Op1_t>
514m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1) {
516}
517
518/// Match a binary OR operation. Note that while conceptually the operands can
519/// be matched commutatively, \p Commutative defaults to false in line with the
520/// IR-based pattern matching infrastructure. Use m_c_BinaryOr for a commutative
521/// version of the matcher.
522template <typename Op0_t, typename Op1_t>
524m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
526}
527
528template <typename Op0_t, typename Op1_t>
530m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
532}
533
534/// Cmp_match is a variant of BinaryRecipe_match that also binds the comparison
535/// predicate. Opcodes must either be Instruction::ICmp or Instruction::FCmp, or
536/// both.
537template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
538struct Cmp_match {
539 static_assert((sizeof...(Opcodes) == 1 || sizeof...(Opcodes) == 2) &&
540 "Expected one or two opcodes");
541 static_assert(
542 ((Opcodes == Instruction::ICmp || Opcodes == Instruction::FCmp) && ...) &&
543 "Expected a compare instruction opcode");
544
546 Op0_t Op0;
548
549 Cmp_match(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
550 : Predicate(&Pred), Op0(Op0), Op1(Op1) {}
551 Cmp_match(const Op0_t &Op0, const Op1_t &Op1) : Op0(Op0), Op1(Op1) {}
552
553 bool match(const VPValue *V) const {
554 auto *DefR = V->getDefiningRecipe();
555 return DefR && match(DefR);
556 }
557
558 bool match(const VPRecipeBase *V) const {
559 if ((m_Binary<Opcodes>(Op0, Op1).match(V) || ...)) {
560 if (Predicate)
561 *Predicate = cast<VPRecipeWithIRFlags>(V)->getPredicate();
562 return true;
563 }
564 return false;
565 }
566};
567
568/// SpecificCmp_match is a variant of Cmp_match that matches the comparison
569/// predicate, instead of binding it.
570template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
573 Op0_t Op0;
575
576 SpecificCmp_match(CmpPredicate Pred, const Op0_t &LHS, const Op1_t &RHS)
577 : Predicate(Pred), Op0(LHS), Op1(RHS) {}
578
579 bool match(const VPValue *V) const {
580 CmpPredicate CurrentPred;
581 return Cmp_match<Op0_t, Op1_t, Opcodes...>(CurrentPred, Op0, Op1)
582 .match(V) &&
584 }
585};
586
587template <typename Op0_t, typename Op1_t>
589 const Op1_t &Op1) {
591}
592
593template <typename Op0_t, typename Op1_t>
594inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp>
595m_ICmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
596 return Cmp_match<Op0_t, Op1_t, Instruction::ICmp>(Pred, Op0, Op1);
597}
598
599template <typename Op0_t, typename Op1_t>
600inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp>
601m_SpecificICmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
603 Op1);
604}
605
606template <typename Op0_t, typename Op1_t>
607inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
608m_Cmp(const Op0_t &Op0, const Op1_t &Op1) {
610 Op1);
611}
612
613template <typename Op0_t, typename Op1_t>
614inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
615m_Cmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
617 Pred, Op0, Op1);
618}
619
620template <typename Op0_t, typename Op1_t>
621inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
622m_SpecificCmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
624 MatchPred, Op0, Op1);
625}
626
627template <typename Op0_t, typename Op1_t>
629 Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
630 /*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe>,
634
635template <typename Op0_t, typename Op1_t>
637 const Op1_t &Op1) {
638 return m_CombineOr(
639 Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
640 /*Commutative*/ false, VPReplicateRecipe, VPWidenGEPRecipe>(
641 Op0, Op1),
645 Op1)));
646}
647
648template <typename Op0_t, typename Op1_t, typename Op2_t>
650m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
652 {Op0, Op1, Op2});
653}
654
655template <typename Op0_t>
658 Instruction::Xor, int_pred_ty<is_all_ones>, Op0_t>>
663
664template <typename Op0_t, typename Op1_t>
665inline match_combine_or<
668m_LogicalAnd(const Op0_t &Op0, const Op1_t &Op1) {
669 return m_CombineOr(
671 m_Select(Op0, Op1, m_False()));
672}
673
674template <typename Op0_t, typename Op1_t>
676m_LogicalOr(const Op0_t &Op0, const Op1_t &Op1) {
677 return m_Select(Op0, m_True(), Op1);
678}
679
680template <typename Op0_t, typename Op1_t, typename Op2_t>
682 false, VPScalarIVStepsRecipe>;
683
684template <typename Op0_t, typename Op1_t, typename Op2_t>
686m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
687 return VPScalarIVSteps_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
688}
689
690template <typename Op0_t, typename Op1_t, typename Op2_t>
693
694template <typename Op0_t, typename Op1_t, typename Op2_t>
696m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
697 return VPDerivedIV_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
698}
699
700template <typename Addr_t, typename Mask_t> struct Load_match {
701 Addr_t Addr;
702 Mask_t Mask;
703
704 Load_match(Addr_t Addr, Mask_t Mask) : Addr(Addr), Mask(Mask) {}
705
706 template <typename OpTy> bool match(const OpTy *V) const {
707 auto *Load = dyn_cast<VPWidenLoadRecipe>(V);
708 if (!Load || !Addr.match(Load->getAddr()) || !Load->isMasked() ||
709 !Mask.match(Load->getMask()))
710 return false;
711 return true;
712 }
713};
714
715/// Match a (possibly reversed) masked load.
716template <typename Addr_t, typename Mask_t>
717inline Load_match<Addr_t, Mask_t> m_MaskedLoad(const Addr_t &Addr,
718 const Mask_t &Mask) {
719 return Load_match<Addr_t, Mask_t>(Addr, Mask);
720}
721
722template <typename Addr_t, typename Val_t, typename Mask_t> struct Store_match {
723 Addr_t Addr;
724 Val_t Val;
725 Mask_t Mask;
726
727 Store_match(Addr_t Addr, Val_t Val, Mask_t Mask)
728 : Addr(Addr), Val(Val), Mask(Mask) {}
729
730 template <typename OpTy> bool match(const OpTy *V) const {
731 auto *Store = dyn_cast<VPWidenStoreRecipe>(V);
732 if (!Store || !Addr.match(Store->getAddr()) ||
733 !Val.match(Store->getStoredValue()) || !Store->isMasked() ||
734 !Mask.match(Store->getMask()))
735 return false;
736 return true;
737 }
738};
739
740/// Match a (possibly reversed) masked store.
741template <typename Addr_t, typename Val_t, typename Mask_t>
742inline Store_match<Addr_t, Val_t, Mask_t>
743m_MaskedStore(const Addr_t &Addr, const Val_t &Val, const Mask_t &Mask) {
744 return Store_match<Addr_t, Val_t, Mask_t>(Addr, Val, Mask);
745}
746
747template <typename Op0_t, typename Op1_t>
750 /*Commutative*/ false, VPVectorEndPointerRecipe>;
751
752template <typename Op0_t, typename Op1_t>
757
758/// Match a call argument at a given argument index.
759template <typename Opnd_t> struct Argument_match {
760 /// Call argument index to match.
761 unsigned OpI;
762 Opnd_t Val;
763
764 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
765
766 template <typename OpTy> bool match(OpTy *V) const {
767 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
768 return Val.match(R->getOperand(OpI));
769 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
770 return Val.match(R->getOperand(OpI));
771 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
772 if (isa<CallInst>(R->getUnderlyingInstr()))
773 return Val.match(R->getOperand(OpI + 1));
774 return false;
775 }
776};
777
778/// Match a call argument.
779template <unsigned OpI, typename Opnd_t>
780inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
781 return Argument_match<Opnd_t>(OpI, Op);
782}
783
784/// Intrinsic matchers.
786 unsigned ID;
787
788 IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
789
790 template <typename OpTy> bool match(OpTy *V) const {
791 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
792 return R->getVectorIntrinsicID() == ID;
793 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
794 return R->getCalledScalarFunction()->getIntrinsicID() == ID;
795 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
796 if (const auto *CI = dyn_cast<CallInst>(R->getUnderlyingInstr()))
797 if (const auto *F = CI->getCalledFunction())
798 return F->getIntrinsicID() == ID;
799 return false;
800 }
801};
802
803/// Intrinsic matches are combinations of ID matchers, and argument
804/// matchers. Higher arity matcher are defined recursively in terms of and-ing
805/// them with lower arity matchers. Here's some convenient typedefs for up to
806/// several arguments, and more can be added as needed
807template <typename T0 = void, typename T1 = void, typename T2 = void,
808 typename T3 = void>
809struct m_Intrinsic_Ty;
810template <typename T0> struct m_Intrinsic_Ty<T0> {
812};
813template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
814 using Ty =
816};
817template <typename T0, typename T1, typename T2>
822template <typename T0, typename T1, typename T2, typename T3>
827
828/// Match intrinsic calls like this:
829/// m_Intrinsic<Intrinsic::fabs>(m_VPValue(X), ...)
830template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
831 return IntrinsicID_match(IntrID);
832}
833
834template <Intrinsic::ID IntrID, typename T0>
835inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
837}
838
839template <Intrinsic::ID IntrID, typename T0, typename T1>
840inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
841 const T1 &Op1) {
843}
844
845template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
846inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
847m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
848 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
849}
850
851template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
852 typename T3>
854m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
855 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
856}
857
859 template <typename ITy> bool match(ITy *V) const {
860 VPValue *Val = dyn_cast<VPValue>(V);
861 return Val && Val->isLiveIn();
862 }
863};
864
866
867template <typename SubPattern_t> struct OneUse_match {
868 SubPattern_t SubPattern;
869
870 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
871
872 template <typename OpTy> bool match(OpTy *V) {
873 return V->hasOneUse() && SubPattern.match(V);
874 }
875};
876
877template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
878 return SubPattern;
879}
880
881} // namespace VPlanPatternMatch
882} // namespace llvm
883
884#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:54
#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:1553
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:554
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:3701
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:992
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:2920
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:3771
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition VPlan.h:530
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:207
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:183
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition VPlanValue.h:178
A recipe to compute a pointer to the last element of each part of a widened memory access for widened...
Definition VPlan.h:1878
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition VPlan.h:1506
A recipe for handling GEP instructions.
Definition VPlan.h:1802
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1458
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.
AllRecipe_match< Instruction::Add, Op0_t, Op1_t > m_Add(const Op0_t &Op0, const Op1_t &Op1)
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:1755
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)