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 {
21namespace VPlanPatternMatch {
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 Class> struct class_match {
33 template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
34};
35
36/// Match an arbitrary VPValue and ignore it.
38
39template <typename Class> struct bind_ty {
40 Class *&VR;
41
42 bind_ty(Class *&V) : VR(V) {}
43
44 template <typename ITy> bool match(ITy *V) const {
45 if (auto *CV = dyn_cast<Class>(V)) {
46 VR = CV;
47 return true;
48 }
49 return false;
50 }
51};
52
53/// Match a specified VPValue.
55 const VPValue *Val;
56
57 specificval_ty(const VPValue *V) : Val(V) {}
58
59 bool match(VPValue *VPV) const { return VPV == Val; }
60};
61
62inline specificval_ty m_Specific(const VPValue *VPV) { return VPV; }
63
64/// Stores a reference to the VPValue *, not the VPValue * itself,
65/// thus can be used in commutative matchers.
67 VPValue *const &Val;
68
69 deferredval_ty(VPValue *const &V) : Val(V) {}
70
71 bool match(VPValue *const V) const { return V == Val; }
72};
73
74/// Like m_Specific(), but works if the specific value to match is determined
75/// as part of the same match() expression. For example:
76/// m_Mul(m_VPValue(X), m_Specific(X)) is incorrect, because m_Specific() will
77/// bind X before the pattern match starts.
78/// m_Mul(m_VPValue(X), m_Deferred(X)) is correct, and will check against
79/// whichever value m_VPValue(X) populated.
80inline deferredval_ty m_Deferred(VPValue *const &V) { return V; }
81
82/// Match an integer constant or vector of constants if Pred::isValue returns
83/// true for the APInt. \p BitWidth optionally specifies the bitwidth the
84/// matched constant must have. If it is 0, the matched constant can have any
85/// bitwidth.
86template <typename Pred, unsigned BitWidth = 0> struct int_pred_ty {
87 Pred P;
88
89 int_pred_ty(Pred P) : P(std::move(P)) {}
90 int_pred_ty() : P() {}
91
92 bool match(VPValue *VPV) const {
93 if (!VPV->isLiveIn())
94 return false;
95 Value *V = VPV->getLiveInIRValue();
96 if (!V)
97 return false;
98 const auto *CI = dyn_cast<ConstantInt>(V);
99 if (!CI && V->getType()->isVectorTy())
100 if (const auto *C = dyn_cast<Constant>(V))
101 CI = dyn_cast_or_null<ConstantInt>(
102 C->getSplatValue(/*AllowPoison=*/false));
103 if (!CI)
104 return false;
105
106 if (BitWidth != 0 && CI->getBitWidth() != BitWidth)
107 return false;
108 return P.isValue(CI->getValue());
109 }
110};
111
112/// Match a specified integer value or vector of all elements of that
113/// value. \p BitWidth optionally specifies the bitwidth the matched constant
114/// must have. If it is 0, the matched constant can have any bitwidth.
117
119
120 bool isValue(const APInt &C) const { return APInt::isSameValue(Val, C); }
121};
122
123template <unsigned Bitwidth = 0>
125
128}
129
132}
133
136}
137
139 bool isValue(const APInt &C) const { return C.isAllOnes(); }
140};
141
142/// Match an integer or vector with all bits set.
143/// For vectors, this includes constants with undefined elements.
146}
147
149 bool isValue(const APInt &C) const { return C.isZero(); }
150};
151
152/// Match an integer 0 or a vector with all elements equal to 0.
153/// For vectors, this includes constants with undefined elements.
156}
157
158/// Matching combinators
159template <typename LTy, typename RTy> struct match_combine_or {
160 LTy L;
161 RTy R;
162
163 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
164
165 template <typename ITy> bool match(ITy *V) const {
166 return L.match(V) || R.match(V);
167 }
168};
169
170template <typename LTy, typename RTy> struct match_combine_and {
171 LTy L;
172 RTy R;
173
174 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
175
176 template <typename ITy> bool match(ITy *V) const {
177 return L.match(V) && R.match(V);
178 }
179};
180
181/// Combine two pattern matchers matching L || R
182template <typename LTy, typename RTy>
183inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
184 return match_combine_or<LTy, RTy>(L, R);
185}
186
187/// Combine two pattern matchers matching L && R
188template <typename LTy, typename RTy>
189inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
190 return match_combine_and<LTy, RTy>(L, R);
191}
192
193/// Match a VPValue, capturing it if we match.
194inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
195
196/// Match a VPInstruction, capturing if we match.
198
199template <typename Ops_t, unsigned Opcode, bool Commutative,
200 typename... RecipeTys>
202 Ops_t Ops;
203
204 template <typename... OpTy> Recipe_match(OpTy... Ops) : Ops(Ops...) {
205 static_assert(std::tuple_size<Ops_t>::value == sizeof...(Ops) &&
206 "number of operands in constructor doesn't match Ops_t");
207 static_assert((!Commutative || std::tuple_size<Ops_t>::value == 2) &&
208 "only binary ops can be commutative");
209 }
210
211 bool match(const VPValue *V) const {
212 auto *DefR = V->getDefiningRecipe();
213 return DefR && match(DefR);
214 }
215
216 bool match(const VPSingleDefRecipe *R) const {
217 return match(static_cast<const VPRecipeBase *>(R));
218 }
219
220 bool match(const VPRecipeBase *R) const {
221 if (std::tuple_size<Ops_t>::value == 0) {
223 "can only match BuildVector with empty ops");
224 auto *VPI = dyn_cast<VPInstruction>(R);
225 return VPI && VPI->getOpcode() == VPInstruction::BuildVector;
226 }
227
228 if ((!matchRecipeAndOpcode<RecipeTys>(R) && ...))
229 return false;
230
231 if (R->getNumOperands() != std::tuple_size<Ops_t>::value) {
232 assert(Opcode == Instruction::PHI &&
233 "non-variadic recipe with matched opcode does not have the "
234 "expected number of operands");
235 return false;
236 }
237
238 auto IdxSeq = std::make_index_sequence<std::tuple_size<Ops_t>::value>();
239 if (all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
240 return Op.match(R->getOperand(Idx));
241 }))
242 return true;
243
244 return Commutative &&
245 all_of_tuple_elements(IdxSeq, [R](auto Op, unsigned Idx) {
246 return Op.match(R->getOperand(R->getNumOperands() - Idx - 1));
247 });
248 }
249
250private:
251 template <typename RecipeTy>
252 static bool matchRecipeAndOpcode(const VPRecipeBase *R) {
253 auto *DefR = dyn_cast<RecipeTy>(R);
254 // Check for recipes that do not have opcodes.
255 if constexpr (std::is_same<RecipeTy, VPScalarIVStepsRecipe>::value ||
256 std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
257 std::is_same<RecipeTy, VPDerivedIVRecipe>::value ||
258 std::is_same<RecipeTy, VPWidenGEPRecipe>::value)
259 return DefR;
260 else
261 return DefR && DefR->getOpcode() == Opcode;
262 }
263
264 /// Helper to check if predicate \p P holds on all tuple elements in Ops using
265 /// the provided index sequence.
266 template <typename Fn, std::size_t... Is>
267 bool all_of_tuple_elements(std::index_sequence<Is...>, Fn P) const {
268 return (P(std::get<Is>(Ops), Is) && ...);
269 }
270};
271
272template <unsigned Opcode, typename... OpTys>
274 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ false,
277
278template <unsigned Opcode, typename... OpTys>
280 Recipe_match<std::tuple<OpTys...>, Opcode, /*Commutative*/ true,
282
283template <unsigned Opcode, typename... OpTys>
284using VPInstruction_match = Recipe_match<std::tuple<OpTys...>, Opcode,
285 /*Commutative*/ false, VPInstruction>;
286
287template <unsigned Opcode, typename... OpTys>
288inline VPInstruction_match<Opcode, OpTys...>
289m_VPInstruction(const OpTys &...Ops) {
290 return VPInstruction_match<Opcode, OpTys...>(Ops...);
291}
292
293/// BuildVector is matches only its opcode, w/o matching its operands as the
294/// number of operands is not fixed.
296 return m_VPInstruction<VPInstruction::BuildVector>();
297}
298
299template <typename Op0_t>
300inline VPInstruction_match<Instruction::Freeze, Op0_t>
301m_Freeze(const Op0_t &Op0) {
302 return m_VPInstruction<Instruction::Freeze>(Op0);
303}
304
305template <typename Op0_t>
306inline VPInstruction_match<VPInstruction::BranchOnCond, Op0_t>
308 return m_VPInstruction<VPInstruction::BranchOnCond>(Op0);
309}
310
311template <typename Op0_t>
312inline VPInstruction_match<VPInstruction::Broadcast, Op0_t>
313m_Broadcast(const Op0_t &Op0) {
314 return m_VPInstruction<VPInstruction::Broadcast>(Op0);
315}
316
317template <typename Op0_t>
318inline VPInstruction_match<VPInstruction::ExplicitVectorLength, Op0_t>
319m_EVL(const Op0_t &Op0) {
320 return m_VPInstruction<VPInstruction::ExplicitVectorLength>(Op0);
321}
322
323template <typename Op0_t>
324inline VPInstruction_match<VPInstruction::ExtractLastElement, Op0_t>
326 return m_VPInstruction<VPInstruction::ExtractLastElement>(Op0);
327}
328
329template <typename Op0_t, typename Op1_t>
330inline VPInstruction_match<VPInstruction::ActiveLaneMask, Op0_t, Op1_t>
331m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1) {
332 return m_VPInstruction<VPInstruction::ActiveLaneMask>(Op0, Op1);
333}
334
335template <typename Op0_t, typename Op1_t>
336inline VPInstruction_match<VPInstruction::BranchOnCount, Op0_t, Op1_t>
337m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
338 return m_VPInstruction<VPInstruction::BranchOnCount>(Op0, Op1);
339}
340
341template <unsigned Opcode, typename Op0_t>
344}
345
346template <typename Op0_t>
348 return m_Unary<Instruction::Trunc, Op0_t>(Op0);
349}
350
351template <typename Op0_t>
353 return m_Unary<Instruction::ZExt, Op0_t>(Op0);
354}
355
356template <typename Op0_t>
358 return m_Unary<Instruction::SExt, Op0_t>(Op0);
359}
360
361template <typename Op0_t>
363 AllRecipe_match<Instruction::SExt, Op0_t>>
364m_ZExtOrSExt(const Op0_t &Op0) {
365 return m_CombineOr(m_ZExt(Op0), m_SExt(Op0));
366}
367
368template <typename Op0_t>
370m_ZExtOrSelf(const Op0_t &Op0) {
371 return m_CombineOr(m_ZExt(Op0), Op0);
372}
373
374template <unsigned Opcode, typename Op0_t, typename Op1_t>
376 const Op1_t &Op1) {
378}
379
380template <unsigned Opcode, typename Op0_t, typename Op1_t>
381inline AllRecipe_commutative_match<Opcode, Op0_t, Op1_t>
382m_c_Binary(const Op0_t &Op0, const Op1_t &Op1) {
384}
385
386template <typename Op0_t, typename Op1_t>
387inline AllRecipe_commutative_match<Instruction::Add, Op0_t, Op1_t>
388m_c_Add(const Op0_t &Op0, const Op1_t &Op1) {
389 return m_c_Binary<Instruction::Add, Op0_t, Op1_t>(Op0, Op1);
390}
391
392template <typename Op0_t, typename Op1_t>
394 const Op1_t &Op1) {
395 return m_Binary<Instruction::Sub, Op0_t, Op1_t>(Op0, Op1);
396}
397
398template <typename Op0_t, typename Op1_t>
400 const Op1_t &Op1) {
401 return m_Binary<Instruction::Mul, Op0_t, Op1_t>(Op0, Op1);
402}
403
404template <typename Op0_t, typename Op1_t>
405inline AllRecipe_commutative_match<Instruction::Mul, Op0_t, Op1_t>
406m_c_Mul(const Op0_t &Op0, const Op1_t &Op1) {
407 return m_c_Binary<Instruction::Mul, Op0_t, Op1_t>(Op0, Op1);
408}
409
410/// Match a binary AND operation.
411template <typename Op0_t, typename Op1_t>
412inline AllRecipe_commutative_match<Instruction::And, Op0_t, Op1_t>
413m_c_BinaryAnd(const Op0_t &Op0, const Op1_t &Op1) {
414 return m_c_Binary<Instruction::And, Op0_t, Op1_t>(Op0, Op1);
415}
416
417/// Match a binary OR operation. Note that while conceptually the operands can
418/// be matched commutatively, \p Commutative defaults to false in line with the
419/// IR-based pattern matching infrastructure. Use m_c_BinaryOr for a commutative
420/// version of the matcher.
421template <typename Op0_t, typename Op1_t>
422inline AllRecipe_match<Instruction::Or, Op0_t, Op1_t>
423m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
424 return m_Binary<Instruction::Or, Op0_t, Op1_t>(Op0, Op1);
425}
426
427template <typename Op0_t, typename Op1_t>
428inline AllRecipe_commutative_match<Instruction::Or, Op0_t, Op1_t>
429m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1) {
430 return m_c_Binary<Instruction::Or, Op0_t, Op1_t>(Op0, Op1);
431}
432
433/// Cmp_match is a variant of BinaryRecipe_match that also binds the comparison
434/// predicate. Opcodes must either be Instruction::ICmp or Instruction::FCmp, or
435/// both.
436template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
437struct Cmp_match {
438 static_assert((sizeof...(Opcodes) == 1 || sizeof...(Opcodes) == 2) &&
439 "Expected one or two opcodes");
440 static_assert(
441 ((Opcodes == Instruction::ICmp || Opcodes == Instruction::FCmp) && ...) &&
442 "Expected a compare instruction opcode");
443
447
448 Cmp_match(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1)
449 : Predicate(&Pred), Op0(Op0), Op1(Op1) {}
450 Cmp_match(const Op0_t &Op0, const Op1_t &Op1) : Op0(Op0), Op1(Op1) {}
451
452 bool match(const VPValue *V) const {
453 auto *DefR = V->getDefiningRecipe();
454 return DefR && match(DefR);
455 }
456
457 bool match(const VPRecipeBase *V) const {
458 if ((m_Binary<Opcodes>(Op0, Op1).match(V) || ...)) {
459 if (Predicate)
460 *Predicate = cast<VPRecipeWithIRFlags>(V)->getPredicate();
461 return true;
462 }
463 return false;
464 }
465};
466
467/// SpecificCmp_match is a variant of Cmp_match that matches the comparison
468/// predicate, instead of binding it.
469template <typename Op0_t, typename Op1_t, unsigned... Opcodes>
474
476 : Predicate(Pred), Op0(LHS), Op1(RHS) {}
477
478 bool match(const VPValue *V) const {
479 CmpPredicate CurrentPred;
480 return Cmp_match<Op0_t, Op1_t, Opcodes...>(CurrentPred, Op0, Op1)
481 .match(V) &&
483 }
484};
485
486template <typename Op0_t, typename Op1_t>
488 const Op1_t &Op1) {
490}
491
492template <typename Op0_t, typename Op1_t>
493inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp>
494m_ICmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
495 return Cmp_match<Op0_t, Op1_t, Instruction::ICmp>(Pred, Op0, Op1);
496}
497
498template <typename Op0_t, typename Op1_t>
499inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp>
500m_SpecificICmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
502 Op1);
503}
504
505template <typename Op0_t, typename Op1_t>
506inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
507m_Cmp(const Op0_t &Op0, const Op1_t &Op1) {
509 Op1);
510}
511
512template <typename Op0_t, typename Op1_t>
513inline Cmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
514m_Cmp(CmpPredicate &Pred, const Op0_t &Op0, const Op1_t &Op1) {
516 Pred, Op0, Op1);
517}
518
519template <typename Op0_t, typename Op1_t>
520inline SpecificCmp_match<Op0_t, Op1_t, Instruction::ICmp, Instruction::FCmp>
521m_SpecificCmp(CmpPredicate MatchPred, const Op0_t &Op0, const Op1_t &Op1) {
523 MatchPred, Op0, Op1);
524}
525
526template <typename Op0_t, typename Op1_t>
528 Recipe_match<std::tuple<Op0_t, Op1_t>, Instruction::GetElementPtr,
529 /*Commutative*/ false, VPWidenRecipe, VPReplicateRecipe,
531
532template <typename Op0_t, typename Op1_t>
534 const Op1_t &Op1) {
535 return GEPLikeRecipe_match<Op0_t, Op1_t>(Op0, Op1);
536}
537
538template <typename Op0_t, typename Op1_t, typename Op2_t>
539inline AllRecipe_match<Instruction::Select, Op0_t, Op1_t, Op2_t>
540m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
542 {Op0, Op1, Op2});
543}
544
545template <typename Op0_t>
548 Instruction::Xor, int_pred_ty<is_all_ones>, Op0_t>>
549m_Not(const Op0_t &Op0) {
550 return m_CombineOr(m_VPInstruction<VPInstruction::Not>(Op0),
551 m_c_Binary<Instruction::Xor>(m_AllOnes(), Op0));
552}
553
554template <typename Op0_t, typename Op1_t>
555inline match_combine_or<
556 VPInstruction_match<VPInstruction::LogicalAnd, Op0_t, Op1_t>,
557 AllRecipe_match<Instruction::Select, Op0_t, Op1_t, specific_intval<1>>>
558m_LogicalAnd(const Op0_t &Op0, const Op1_t &Op1) {
559 return m_CombineOr(
560 m_VPInstruction<VPInstruction::LogicalAnd, Op0_t, Op1_t>(Op0, Op1),
561 m_Select(Op0, Op1, m_False()));
562}
563
564template <typename Op0_t, typename Op1_t>
565inline AllRecipe_match<Instruction::Select, Op0_t, specific_intval<1>, Op1_t>
566m_LogicalOr(const Op0_t &Op0, const Op1_t &Op1) {
567 return m_Select(Op0, m_True(), Op1);
568}
569
570template <typename Op0_t, typename Op1_t, typename Op2_t>
572 false, VPScalarIVStepsRecipe>;
573
574template <typename Op0_t, typename Op1_t, typename Op2_t>
576m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
577 return VPScalarIVSteps_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
578}
579
580template <typename Op0_t, typename Op1_t, typename Op2_t>
583
584template <typename Op0_t, typename Op1_t, typename Op2_t>
586m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
587 return VPDerivedIV_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
588}
589
590/// Match a call argument at a given argument index.
591template <typename Opnd_t> struct Argument_match {
592 /// Call argument index to match.
593 unsigned OpI;
594 Opnd_t Val;
595
596 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
597
598 template <typename OpTy> bool match(OpTy *V) const {
599 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
600 return Val.match(R->getOperand(OpI));
601 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
602 return Val.match(R->getOperand(OpI));
603 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
604 if (isa<CallInst>(R->getUnderlyingInstr()))
605 return Val.match(R->getOperand(OpI + 1));
606 return false;
607 }
608};
609
610/// Match a call argument.
611template <unsigned OpI, typename Opnd_t>
612inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
613 return Argument_match<Opnd_t>(OpI, Op);
614}
615
616/// Intrinsic matchers.
618 unsigned ID;
619
620 IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
621
622 template <typename OpTy> bool match(OpTy *V) const {
623 if (const auto *R = dyn_cast<VPWidenIntrinsicRecipe>(V))
624 return R->getVectorIntrinsicID() == ID;
625 if (const auto *R = dyn_cast<VPWidenCallRecipe>(V))
626 return R->getCalledScalarFunction()->getIntrinsicID() == ID;
627 if (const auto *R = dyn_cast<VPReplicateRecipe>(V))
628 if (const auto *CI = dyn_cast<CallInst>(R->getUnderlyingInstr()))
629 if (const auto *F = CI->getCalledFunction())
630 return F->getIntrinsicID() == ID;
631 return false;
632 }
633};
634
635/// Intrinsic matches are combinations of ID matchers, and argument
636/// matchers. Higher arity matcher are defined recursively in terms of and-ing
637/// them with lower arity matchers. Here's some convenient typedefs for up to
638/// several arguments, and more can be added as needed
639template <typename T0 = void, typename T1 = void, typename T2 = void,
640 typename T3 = void>
641struct m_Intrinsic_Ty;
642template <typename T0> struct m_Intrinsic_Ty<T0> {
644};
645template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
646 using Ty =
648};
649template <typename T0, typename T1, typename T2>
650struct m_Intrinsic_Ty<T0, T1, T2> {
653};
654template <typename T0, typename T1, typename T2, typename T3>
658};
659
660/// Match intrinsic calls like this:
661/// m_Intrinsic<Intrinsic::fabs>(m_VPValue(X), ...)
662template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
663 return IntrinsicID_match(IntrID);
664}
665
666template <Intrinsic::ID IntrID, typename T0>
667inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
668 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
669}
670
671template <Intrinsic::ID IntrID, typename T0, typename T1>
672inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
673 const T1 &Op1) {
674 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
675}
676
677template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
678inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
679m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
680 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
681}
682
683template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
684 typename T3>
686m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
687 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
688}
689
690} // namespace VPlanPatternMatch
691} // namespace llvm
692
693#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define F(x, y, z)
Definition: MD5.cpp:55
#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
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...
Definition: CmpPredicate.h:23
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
This class represents an Operation in the Expression.
A recipe for converting the input value IV value to the corresponding value of an IV with different s...
Definition: VPlan.h:3460
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:967
@ BuildVector
Creates a fixed-width vector containing all operands.
Definition: VPlan.h:993
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:391
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition: VPlan.h:2731
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition: VPlan.h:3529
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition: VPlan.h:518
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition: VPlanValue.h:197
Value * getLiveInIRValue() const
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
Definition: VPlanValue.h:174
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
Definition: VPlanValue.h:169
VPWidenCastRecipe is a recipe to create vector cast instructions.
Definition: VPlan.h:1467
A recipe for handling GEP instructions.
Definition: VPlan.h:1753
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition: VPlan.h:1424
LLVM Value Representation.
Definition: Value.h:75
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
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.
Definition: PatternMatch.h:105
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_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)
VPInstruction_match< VPInstruction::ActiveLaneMask, Op0_t, Op1_t > m_ActiveLaneMask(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)
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)
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)
AllRecipe_commutative_match< Instruction::Mul, Op0_t, Op1_t > m_c_Mul(const Op0_t &Op0, const Op1_t &Op1)
Recipe_match< std::tuple< OpTys... >, Opcode, true, VPWidenRecipe, VPReplicateRecipe, VPInstruction > AllRecipe_commutative_match
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)
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)
specific_intval< 0 > m_SpecificInt(uint64_t V)
VPInstruction_match< VPInstruction::BranchOnCount, Op0_t, Op1_t > m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1)
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()
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_VPValue(X), ...)
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()...
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.
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)
match_combine_or< AllRecipe_match< Instruction::ZExt, Op0_t >, Op0_t > m_ZExtOrSelf(const Op0_t &Op0)
VPInstruction_match< VPInstruction::BranchOnCond, Op0_t > m_BranchOnCond(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.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:223
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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
Intrinsic matches are combinations of ID matchers, and argument matchers.
A recipe for widening select instructions.
Definition: VPlan.h:1707
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
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)
Stores a reference to the VPValue *, not the VPValue * itself, thus can be used in commutative matche...
bool match(VPValue *const V) const
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.
bool isValue(const APInt &C) const
Intrinsic matches are combinations of ID matchers, and argument matchers.
match_combine_and(const LTy &Left, const RTy &Right)
match_combine_or(const LTy &Left, const RTy &Right)