20#ifndef LLVM_TRANSFORM_VECTORIZE_VPLANPATTERNMATCH_H
21#define LLVM_TRANSFORM_VECTORIZE_VPLANPATTERNMATCH_H
26namespace VPlanPatternMatch {
28template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
33 auto *R = dyn_cast<VPRecipeBase>(U);
38 template <
typename ITy>
bool match(ITy *V)
const {
return isa<Class>(V); }
49 template <
typename ITy>
bool match(ITy *V)
const {
50 if (
auto *CV = dyn_cast<Class>(V)) {
81 const auto *CI = dyn_cast<ConstantInt>(V);
82 if (!CI && V->getType()->isVectorTy())
83 if (
const auto *
C = dyn_cast<Constant>(V))
84 CI = dyn_cast_or_null<ConstantInt>(
85 C->getSplatValue(
false));
110 template <
typename ITy>
bool match(ITy *V)
const {
119template <
typename LTy,
typename RTy>
132template <
unsigned Opcode,
typename RecipeTy>
135 auto *DefR = dyn_cast<RecipeTy>(R);
137 if constexpr (std::is_same<RecipeTy, VPScalarIVStepsRecipe>::value ||
138 std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
139 std::is_same<RecipeTy, VPWidenSelectRecipe>::value)
142 return DefR && DefR->getOpcode() == Opcode;
146template <
unsigned Opcode,
typename RecipeTy,
typename... RecipeTys>
153template <
typename TupleTy,
typename Fn, std::size_t... Is>
155 return (
P(std::get<Is>(Ops), Is) && ...);
159template <
typename TupleTy,
typename Fn>
162 Ops,
P, std::make_index_sequence<std::tuple_size<TupleTy>::value>{});
166template <
typename Ops_t,
unsigned Opcode,
bool Commutative,
167 typename... RecipeTys>
172 static_assert(std::tuple_size<Ops_t>::value == 0 &&
173 "constructor can only be used with zero operands");
176 template <
typename A_t,
typename B_t>
178 static_assert(std::tuple_size<Ops_t>::value == 2 &&
179 "constructor can only be used for binary matcher");
183 auto *DefR = V->getDefiningRecipe();
184 return DefR &&
match(DefR);
194 assert(R->getNumOperands() == std::tuple_size<Ops_t>::value &&
195 "recipe with matched opcode the expected number of operands");
198 return Op.match(R->getOperand(
Idx));
202 return Commutative &&
204 return Op.match(R->getOperand(R->getNumOperands() -
Idx - 1));
209template <
typename Op0_t,
unsigned Opcode,
typename... RecipeTys>
213template <
typename Op0_t,
unsigned Opcode>
217template <
typename Op0_t,
unsigned Opcode>
222template <
typename Op0_t,
typename Op1_t,
unsigned Opcode,
bool Commutative,
223 typename... RecipeTys>
227template <
typename Op0_t,
typename Op1_t,
unsigned Opcode>
232template <
typename Op0_t,
typename Op1_t,
unsigned Opcode,
233 bool Commutative =
false>
238template <
unsigned Opcode,
typename Op0_t>
244template <
unsigned Opcode,
typename Op0_t,
typename Op1_t>
245inline BinaryVPInstruction_match<Op0_t, Op1_t, Opcode>
250template <
typename Op0_t>
251inline UnaryVPInstruction_match<Op0_t, VPInstruction::Not>
253 return m_VPInstruction<VPInstruction::Not>(Op0);
256template <
typename Op0_t>
257inline UnaryVPInstruction_match<Op0_t, VPInstruction::BranchOnCond>
259 return m_VPInstruction<VPInstruction::BranchOnCond>(Op0);
262template <
typename Op0_t,
typename Op1_t>
263inline BinaryVPInstruction_match<Op0_t, Op1_t, VPInstruction::ActiveLaneMask>
265 return m_VPInstruction<VPInstruction::ActiveLaneMask>(Op0, Op1);
268template <
typename Op0_t,
typename Op1_t>
269inline BinaryVPInstruction_match<Op0_t, Op1_t, VPInstruction::BranchOnCount>
271 return m_VPInstruction<VPInstruction::BranchOnCount>(Op0, Op1);
274template <
unsigned Opcode,
typename Op0_t>
279template <
typename Op0_t>
280inline AllUnaryRecipe_match<Op0_t, Instruction::Trunc>
282 return m_Unary<Instruction::Trunc, Op0_t>(Op0);
285template <
typename Op0_t>
287 return m_Unary<Instruction::ZExt, Op0_t>(Op0);
290template <
typename Op0_t>
292 return m_Unary<Instruction::SExt, Op0_t>(Op0);
295template <
typename Op0_t>
297 AllUnaryRecipe_match<Op0_t, Instruction::SExt>>
302template <
unsigned Opcode,
typename Op0_t,
typename Op1_t,
303 bool Commutative =
false>
304inline AllBinaryRecipe_match<Op0_t, Op1_t, Opcode, Commutative>
309template <
typename Op0_t,
typename Op1_t>
310inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::Mul>
311m_Mul(
const Op0_t &Op0,
const Op1_t &Op1) {
312 return m_Binary<Instruction::Mul, Op0_t, Op1_t>(Op0, Op1);
315template <
typename Op0_t,
typename Op1_t>
319 return m_Binary<Instruction::Mul, Op0_t, Op1_t, true>(Op0, Op1);
326template <
typename Op0_t,
typename Op1_t,
bool Commutative = false>
327inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::Or, Commutative>
329 return m_Binary<Instruction::Or, Op0_t, Op1_t, Commutative>(Op0, Op1);
332template <
typename Op0_t,
typename Op1_t>
336 return m_BinaryOr<Op0_t, Op1_t,
true>(Op0, Op1);
339template <
typename Op0_t,
typename Op1_t,
typename Op2_t,
unsigned Opcode>
344template <
typename Op0_t,
typename Op1_t,
typename Op2_t>
346m_Select(
const Op0_t &Op0,
const Op1_t &Op1,
const Op2_t &Op2) {
351template <
typename Op0_t,
typename Op1_t>
353 BinaryVPInstruction_match<Op0_t, Op1_t, VPInstruction::LogicalAnd>,
354 AllTernaryRecipe_match<Op0_t, Op1_t, specific_intval<1>,
355 Instruction::Select>>
358 m_VPInstruction<VPInstruction::LogicalAnd, Op0_t, Op1_t>(Op0, Op1),
362template <
typename Op0_t,
typename Op1_t>
363inline AllTernaryRecipe_match<Op0_t, specific_intval<1>, Op1_t,
376template <
typename Op0_t,
typename Op1_t>
380template <
typename Op0_t,
typename Op1_t>
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains the declarations of the Vectorization Plan base classes:
Class for arbitrary precision integers.
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!...
This class represents an Operation in the Expression.
Canonical scalar induction phi of the vector loop.
This is a concrete Recipe that models a single VPlan-level instruction.
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Value * getLiveInIRValue()
Returns the underlying IR value, if this VPValue is defined outside the scope of VPlan.
bool isLiveIn() const
Returns true if this VPValue is a live-in, i.e. defined outside the VPlan.
VPWidenCastRecipe is a recipe to create vector cast instructions.
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
bool CheckTupleElements(const TupleTy &Ops, Fn P, std::index_sequence< Is... >)
bool all_of_tuple_elements(const TupleTy &Ops, Fn P)
Helper to check if predicate P holds on all tuple elements in Ops.
AllBinaryRecipe_match< Op0_t, Op1_t, Instruction::Or, Commutative > m_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
Match a binary OR operation.
AllTernaryRecipe_match< Op0_t, Op1_t, Op2_t, Instruction::Select > m_Select(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2)
AllUnaryRecipe_match< Op0_t, Opcode > m_Unary(const Op0_t &Op0)
AllBinaryRecipe_match< Op0_t, Op1_t, Instruction::Or, true > m_c_BinaryOr(const Op0_t &Op0, const Op1_t &Op1)
BinaryVPInstruction_match< Op0_t, Op1_t, VPInstruction::ActiveLaneMask > m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
UnaryVPInstruction_match< Op0_t, Opcode > m_VPInstruction(const Op0_t &Op0)
AllBinaryRecipe_match< Op0_t, Op1_t, Opcode, Commutative > m_Binary(const Op0_t &Op0, const Op1_t &Op1)
UnaryVPInstruction_match< Op0_t, VPInstruction::Not > m_Not(const Op0_t &Op0)
VPCanonicalIVPHI_match m_CanonicalIV()
AllUnaryRecipe_match< Op0_t, Instruction::Trunc > m_Trunc(const Op0_t &Op0)
VPScalarIVSteps_match< Op0_t, Op1_t > m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1)
AllBinaryRecipe_match< Op0_t, Op1_t, Instruction::Mul, true > m_c_Mul(const Op0_t &Op0, const Op1_t &Op1)
BinaryVPInstruction_match< Op0_t, Op1_t, VPInstruction::BranchOnCount > m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1)
specificval_ty m_Specific(const VPValue *VPV)
specific_intval< 1 > m_False()
specific_intval< 0 > m_SpecificInt(uint64_t V)
AllBinaryRecipe_match< Op0_t, Op1_t, Instruction::Mul > m_Mul(const Op0_t &Op0, const Op1_t &Op1)
specific_intval< 1 > m_True()
UnaryVPInstruction_match< Op0_t, VPInstruction::BranchOnCond > m_BranchOnCond(const Op0_t &Op0)
bool match(Val *V, const Pattern &P)
class_match< VPValue > m_VPValue()
Match an arbitrary VPValue and ignore it.
BinaryRecipe_match< Op0_t, Op1_t, Opcode, Commutative, VPWidenRecipe, VPReplicateRecipe, VPWidenCastRecipe, VPInstruction > AllBinaryRecipe_match
AllUnaryRecipe_match< Op0_t, Instruction::SExt > m_SExt(const Op0_t &Op0)
AllUnaryRecipe_match< Op0_t, Instruction::ZExt > m_ZExt(const Op0_t &Op0)
Recipe_match< std::tuple<>, 0, false, VPCanonicalIVPHIRecipe > VPCanonicalIVPHI_match
match_combine_or< AllUnaryRecipe_match< Op0_t, Instruction::ZExt >, AllUnaryRecipe_match< Op0_t, Instruction::SExt > > m_ZExtOrSExt(const Op0_t &Op0)
This is an optimization pass for GlobalISel generic memory operations.
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.
Implement std::hash so that hash_code can be used in STL containers.
A recipe for widening select instructions.
bool match(const VPSingleDefRecipe *R) const
bool match(const VPValue *V) const
Recipe_match(A_t A, B_t B)
bool match(const VPRecipeBase *R) const
static bool match(const VPRecipeBase *R)
static bool match(const VPRecipeBase *R)
A helper to match an opcode against multiple recipe types.
match_combine_or(const LTy &Left, const RTy &Right)
Match a specified integer value or vector of all elements of that value.
bool match(VPValue *VPV) const
Match a specified VPValue.
specificval_ty(const VPValue *V)
bool match(VPValue *VPV) const