Go to the documentation of this file.
13 #ifndef LLVM_CODEGEN_GLOBALISEL_MIPATTERNMATCH_H
14 #define LLVM_CODEGEN_GLOBALISEL_MIPATTERNMATCH_H
22 namespace MIPatternMatch {
24 template <
typename Reg,
typename Pattern>
26 return P.match(
MRI, R);
29 template <
typename Pattern>
44 template <
typename SubPat>
58 template <
typename SubPat>
63 template <
typename ConstT>
82 if (
auto MaybeCst = matchConstant<ConstT>(
Reg,
MRI)) {
97 template <
typename ConstT>
117 if (
auto MaybeCst = matchConstant<ConstT>(
Reg,
MRI)) {
122 if (
auto MaybeCstSplat = matchConstantSplat<ConstT>(
Reg,
MRI)) {
175 inline GFCstOrSplatGFCstMatch
227 inline SpecificConstantOrSplatMatch
255 template <
typename... Preds>
struct And {
256 template <
typename MatchSrc>
262 template <
typename Pred,
typename... Preds>
263 struct And<Pred, Preds...> :
And<Preds...> {
268 template <
typename MatchSrc>
274 template <
typename... Preds>
struct Or {
275 template <
typename MatchSrc>
281 template <
typename Pred,
typename... Preds>
282 struct Or<Pred, Preds...> :
Or<Preds...> {
285 :
Or<Preds...>(
std::forward<Preds>(
preds)...),
P(
std::forward<Pred>(
p)) {}
286 template <
typename MatchSrc>
293 return And<Preds...>(std::forward<Preds>(
preds)...);
297 return Or<Preds...>(std::forward<Preds>(
preds)...);
361 template <
typename LHS_P,
typename RHS_P,
unsigned Opcode,
368 template <
typename OpTy>
384 template <
typename LHS_P,
typename RHS_P,
bool Commutable = false>
392 template <
typename OpTy>
408 template <
typename LHS,
typename RHS>
414 template <
typename LHS,
typename RHS>
415 inline BinaryOpc_match<LHS, RHS, true>
420 template <
typename LHS,
typename RHS>
426 template <
typename LHS,
typename RHS>
432 template <
typename LHS,
typename RHS>
438 template <
typename LHS,
typename RHS>
444 template <
typename LHS,
typename RHS>
450 template <
typename LHS,
typename RHS>
456 template <
typename LHS,
typename RHS>
462 template <
typename LHS,
typename RHS>
468 template <
typename LHS,
typename RHS>
474 template <
typename LHS,
typename RHS>
480 template <
typename LHS,
typename RHS>
486 template <
typename LHS,
typename RHS>
492 template <
typename LHS,
typename RHS>
498 template <
typename LHS,
typename RHS>
504 template <
typename LHS,
typename RHS>
515 template <
typename OpTy>
527 template <
typename SrcTy>
528 inline UnaryOp_match<SrcTy, TargetOpcode::G_ANYEXT>
533 template <
typename SrcTy>
538 template <
typename SrcTy>
543 template <
typename SrcTy>
548 template <
typename SrcTy>
553 template <
typename SrcTy>
554 inline UnaryOp_match<SrcTy, TargetOpcode::G_BITCAST>
559 template <
typename SrcTy>
560 inline UnaryOp_match<SrcTy, TargetOpcode::G_PTRTOINT>
565 template <
typename SrcTy>
566 inline UnaryOp_match<SrcTy, TargetOpcode::G_INTTOPTR>
571 template <
typename SrcTy>
572 inline UnaryOp_match<SrcTy, TargetOpcode::G_FPTRUNC>
577 template <
typename SrcTy>
582 template <
typename SrcTy>
587 template <
typename SrcTy>
592 template <
typename SrcTy>
599 template <
typename Pred_P,
typename LHS_P,
typename RHS_P,
unsigned Opcode>
608 template <
typename OpTy>
616 if (!
P.match(
MRI, TmpPred))
624 template <
typename Pred,
typename LHS,
typename RHS>
625 inline CompareOp_match<Pred, LHS, RHS, TargetOpcode::G_ICMP>
630 template <
typename Pred,
typename LHS,
typename RHS>
631 inline CompareOp_match<Pred, LHS, RHS, TargetOpcode::G_FCMP>
648 template <
typename Src0Ty,
typename Src1Ty,
typename Src2Ty,
unsigned Opcode>
656 template <
typename OpTy>
669 template <
typename Src0Ty,
typename Src1Ty,
typename Src2Ty>
670 inline TernaryOp_match<Src0Ty, Src1Ty, Src2Ty,
671 TargetOpcode::G_INSERT_VECTOR_ELT>
674 TargetOpcode::G_INSERT_VECTOR_ELT>(Src0, Src1, Src2);
677 template <
typename Src0Ty,
typename Src1Ty,
typename Src2Ty>
678 inline TernaryOp_match<Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_SELECT>
679 m_GISelect(
const Src0Ty &Src0,
const Src1Ty &Src1,
const Src2Ty &Src2) {
686 template <
typename SrcTy>
694 template <
typename SrcTy>
ICstOrSplatMatch< APInt > m_ICstOrSplat(APInt &Cst)
Optional< int64_t > getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT fits in int64_t returns it.
bool match(const MachineRegisterInfo &MRI, MachineOperand *MO)
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
This is an optimization pass for GlobalISel generic memory operations.
static bool bind(const MachineRegisterInfo &MRI, LLT Ty, Register Reg)
SpecificConstantSplatMatch m_SpecificICstSplat(int64_t RequestedValue)
Matches a constant splat of RequestedValue.
UnaryOp_match(const SrcTy &LHS)
Optional< FPValueAndVReg > & FPValReg
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
UnaryOp_match< SrcTy, TargetOpcode::G_FPEXT > m_GFPExt(const SrcTy &Src)
UnaryOp_match< SrcTy, TargetOpcode::G_FNEG > m_GFNeg(const SrcTy &Src)
operand_type_match m_Reg()
BinaryOp_match< LHS, RHS, TargetOpcode::G_AND, true > m_GAnd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SHL, false > m_GShl(const LHS &L, const RHS &R)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
BinaryOp_match< LHS, RHS, TargetOpcode::G_LSHR, false > m_GLShr(const LHS &L, const RHS &R)
OneNonDBGUse_match< SubPat > m_OneNonDBGUse(const SubPat &SP)
GCstAndRegMatch(Optional< ValueAndVReg > &ValReg)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SUB > m_GSub(const LHS &L, const RHS &R)
Optional< ConstT > matchConstantSplat(Register, const MachineRegisterInfo &)
Reg
All possible values of the reg field in the ModR/M byte.
UnaryOp_match< SrcTy, TargetOpcode::G_TRUNC > m_GTrunc(const SrcTy &Src)
BinaryOp_match< LHS, RHS, TargetOpcode::G_FSUB, false > m_GFSub(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMAX, false > m_GSMax(const LHS &L, const RHS &R)
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_ICMP > m_GICmp(const Pred &P, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_FADD, true > m_GFAdd(const LHS &L, const RHS &R)
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMIN, false > m_GSMin(const LHS &L, const RHS &R)
bool match(const MachineRegisterInfo &MRI, ITy &&V)
the resulting code requires compare and branches when and if * p
BinaryOpc_match(unsigned Opcode, const LHS_P &LHS, const RHS_P &RHS)
BinaryOp_match< LHS, RHS, TargetOpcode::G_PTR_ADD, false > m_GPtrAdd(const LHS &L, const RHS &R)
UnaryOp_match< SrcTy, TargetOpcode::G_PTRTOINT > m_GPtrToInt(const SrcTy &Src)
UnaryOp_match< SrcTy, TargetOpcode::G_FABS > m_GFabs(const SrcTy &Src)
unsigned getNumDefs() const
Returns the total number of definitions.
bool match(const MachineRegisterInfo &MRI, Register Reg)
GFCstAndRegMatch m_GFCst(Optional< FPValueAndVReg > &FPValReg)
UnaryOp_match< SrcTy, TargetOpcode::G_SEXT > m_GSExt(const SrcTy &Src)
BinaryOp_match< LHS, RHS, TargetOpcode::G_MUL, true > m_GMul(const LHS &L, const RHS &R)
TernaryOp_match(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
UnaryOp_match< SrcTy, TargetOpcode::G_ZEXT > m_GZExt(const SrcTy &Src)
OneNonDBGUse_match(const SubPatternT &SP)
(vector float) vec_cmpeq(*A, *B) C
const MachineOperand & getOperand(unsigned i) const
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
bool match(const MachineRegisterInfo &MRI, Register Reg)
Matcher for a specific constant or constant splat.
UnaryOp_match< SrcTy, TargetOpcode::G_INTTOPTR > m_GIntToPtr(const SrcTy &Src)
MachineOperand class - Representation of each machine instruction operand.
SpecificConstantMatch m_ZeroInt()
{ Convenience matchers for specific integer values.
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
GFCstOrSplatGFCstMatch m_GFCstOrSplat(Optional< FPValueAndVReg > &FPValReg)
ConstantFP - Floating Point Values [float, double].
Or(Pred &&p, Preds &&... preds)
static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI, Register Reg)
SpecificConstantMatch m_SpecificICst(int64_t RequestedValue)
Matches a constant equal to RequestedValue.
OneUse_match(const SubPatternT &SP)
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
bind_ty< MachineInstr * > m_MInstr(MachineInstr *&MI)
bind_ty< CmpInst::Predicate > m_Pred(CmpInst::Predicate &P)
CheckType m_SpecificType(LLT Ty)
Optional< FPValueAndVReg > & FPValReg
UnaryOp_match< SrcTy, TargetOpcode::G_ANYEXT > m_GAnyExt(const SrcTy &Src)
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
SpecificConstantMatch(int64_t RequestedVal)
BinaryOp_match< LHS, RHS, TargetOpcode::G_OR, true > m_GOr(const LHS &L, const RHS &R)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Representation of each machine instruction.
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
BinaryOpc_match< LHS, RHS, true > m_CommutativeBinOp(unsigned Opcode, const LHS &L, const RHS &R)
Optional< ConstT > matchConstant(Register, const MachineRegisterInfo &)
SpecificConstantMatch m_AllOnesInt()
bool match(const MachineRegisterInfo &MRI, Register Reg)
unsigned getPredicate() const
bool match(const MachineRegisterInfo &MRI, Register Reg)
bind_ty< LLT > m_Type(LLT Ty)
bool match(const MachineRegisterInfo &MRI, Register Reg)
Optional< APInt > getIConstantVRegVal(Register VReg, const MachineRegisterInfo &MRI)
If VReg is defined by a G_CONSTANT, return the corresponding value.
Register getReg() const
getReg - Returns the register number.
bool match(const MachineRegisterInfo &MRI, Register Reg)
Optional< int64_t > getIConstantSplatSExtVal(const Register Reg, const MachineRegisterInfo &MRI)
Class for arbitrary precision integers.
bool match(const MachineRegisterInfo &MRI, OpTy &&Op)
bool match(const MachineRegisterInfo &MRI, Register Reg)
GFCstAndRegMatch(Optional< FPValueAndVReg > &FPValReg)
Optional< ValueAndVReg > getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_CONSTANT returns its...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Or< Preds... > m_any_of(Preds &&... preds)
BinaryOp_match< LHS, RHS, TargetOpcode::G_XOR, true > m_GXor(const LHS &L, const RHS &R)
static bool bind(const MachineRegisterInfo &MRI, BindTy &VR, BindTy &V)
UnaryOp_match< SrcTy, TargetOpcode::COPY > m_Copy(SrcTy &&Src)
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
SpecificConstantOrSplatMatch m_SpecificICstOrSplat(int64_t RequestedValue)
Matches a RequestedValue constant or a constant splat of RequestedValue.
bool match(const MachineRegisterInfo &MRI, Register Reg)
BinaryOp_match< LHS, RHS, TargetOpcode::G_ASHR, false > m_GAShr(const LHS &L, const RHS &R)
bool match(const MachineRegisterInfo &MRI, MatchSrc &&src)
ConstantMatch< APInt > m_ICst(APInt &Cst)
CompareOp_match< Pred, LHS, RHS, TargetOpcode::G_FCMP > m_GFCmp(const Pred &P, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_ADD, true > m_GAdd(const LHS &L, const RHS &R)
UnaryOp_match< SrcTy, TargetOpcode::G_FSQRT > m_GFSqrt(const SrcTy &Src)
ICstOrSplatMatch(ConstT &C)
GCstAndRegMatch m_GCst(Optional< ValueAndVReg > &ValReg)
Optional< APInt > getIConstantSplatVal(const Register Reg, const MachineRegisterInfo &MRI)
bool match(const MachineRegisterInfo &MRI, Register Reg)
TernaryOp_match< Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_SELECT > m_GISelect(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
Optional< FPValueAndVReg > getFConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI, bool LookThroughInstrs=true)
If VReg is defined by a statically evaluable chain of instructions rooted on a G_FCONSTANT returns it...
bool match(const MachineRegisterInfo &MRI, Register Reg)
CompareOp_match(const Pred_P &Pred, const LHS_P &LHS, const RHS_P &RHS)
SpecificConstantOrSplatMatch(int64_t RequestedVal)
static bool bind(const MachineRegisterInfo &MRI, const ConstantFP *&F, Register Reg)
UnaryOp_match< SrcTy, TargetOpcode::G_FPTRUNC > m_GFPTrunc(const SrcTy &Src)
UnaryOp_match< SrcTy, TargetOpcode::G_BITCAST > m_GBitcast(const SrcTy &Src)
Optional< FPValueAndVReg > getFConstantSplat(Register VReg, const MachineRegisterInfo &MRI, bool AllowUndef=true)
Returns a floating point scalar constant of a build vector splat if it exists.
SpecificConstantSplatMatch(int64_t RequestedVal)
unsigned getNumOperands() const
Retuns the total number of operands.
BinaryOp_match< LHS, RHS, TargetOpcode::G_FMUL, true > m_GFMul(const LHS &L, const RHS &R)
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
GFCstOrSplatGFCstMatch(Optional< FPValueAndVReg > &FPValReg)
BinaryOp_match(const LHS_P &LHS, const RHS_P &RHS)
bool isBuildVectorConstantSplat(const Register Reg, const MachineRegisterInfo &MRI, int64_t SplatValue, bool AllowUndef)
Return true if the specified register is defined by G_BUILD_VECTOR or G_BUILD_VECTOR_TRUNC where all ...
static bool bind(const MachineRegisterInfo &MRI, MachineInstr *&MI, MachineInstr *Inst)
const ConstantFP * getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI)
And< Preds... > m_all_of(Preds &&... preds)
Optional< ValueAndVReg > & ValReg
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
bool match(const MachineRegisterInfo &MRI, Register Reg)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOpc_match< LHS, RHS, false > m_BinOp(unsigned Opcode, const LHS &L, const RHS &R)
TernaryOp_match< Src0Ty, Src1Ty, Src2Ty, TargetOpcode::G_INSERT_VECTOR_ELT > m_GInsertVecElt(const Src0Ty &Src0, const Src1Ty &Src1, const Src2Ty &Src2)
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
Matcher for a specific constant value.
bool match(const MachineRegisterInfo &MRI, Register Reg)
Matcher for a specific constant splat.
And(Pred &&p, Preds &&... preds)