13#ifndef LLVM_CODEGEN_SDPATTERNMATCH_H
14#define LLVM_CODEGEN_SDPATTERNMATCH_H
23namespace SDPatternMatch {
35 : DAG(DAG), TLI(DAG ? &DAG->getTargetLoweringInfo() : nullptr) {}
38 : DAG(nullptr), TLI(TLI) {}
48 return N->getOpcode() == Opcode;
52template <
typename Pattern,
typename MatchContext>
55 return P.match(Ctx,
N);
58template <
typename Pattern,
typename MatchContext>
64template <
typename Pattern>
69template <
typename Pattern>
74template <
typename Pattern>
79template <
typename Pattern>
92 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
112 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
131 template <
typename MatchContext>
144 template <
typename MatchContext>
149 return P.
match(Ctx,
N) &&
N->hasNUsesOfValue(NumUses,
N.getResNo());
153template <
typename Pattern>
157template <
unsigned N,
typename Pattern>
174 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
189 template <
typename MatchContext>
191 assert(Ctx.getTLI() &&
"TargetLowering is required for this pattern.");
197template <
typename PredFuncT,
typename Pattern>
212 const NewMatchContext &
Ctx;
215 template <
typename OrigMatchContext>
221template <
typename MatchContext,
typename Pattern>
233 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
249 template <
typename MatchContext>
256template <
typename PredFuncT,
typename Pattern>
261template <
typename Pattern>
324template <
typename... Preds>
struct And {
325 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
330template <
typename Pred,
typename... Preds>
331struct And<Pred, Preds...> :
And<Preds...> {
333 And(Pred &&p, Preds &&...preds)
334 :
And<Preds...>(
std::forward<Preds>(preds)...),
P(
std::forward<Pred>(p)) {
337 template <
typename MatchContext>
343template <
typename... Preds>
struct Or {
344 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
349template <
typename Pred,
typename... Preds>
350struct Or<Pred, Preds...> :
Or<Preds...> {
352 Or(Pred &&p, Preds &&...preds)
353 :
Or<Preds...>(
std::forward<Preds>(preds)...),
P(
std::forward<Pred>(p)) {}
355 template <
typename MatchContext>
361template <
typename... Preds>
And<Preds...>
m_AllOf(Preds &&...preds) {
362 return And<Preds...>(std::forward<Preds>(preds)...);
365template <
typename... Preds>
Or<Preds...>
m_AnyOf(Preds &&...preds) {
366 return Or<Preds...>(std::forward<Preds>(preds)...);
371 template <
typename MatchContext>
374 return N->getNumOperands() == OpIdx;
378template <
unsigned OpIdx,
typename OpndPred,
typename... OpndPreds>
385 std::forward<OpndPreds>(preds)...),
386 P(
std::forward<OpndPred>(p)) {}
388 template <
typename MatchContext>
390 if (OpIdx < N->getNumOperands())
391 return P.match(Ctx,
N->getOperand(OpIdx)) &&
399template <
typename... OpndPreds>
400auto m_Node(
unsigned Opcode, OpndPreds &&...preds) {
402 std::forward<OpndPreds>(preds)...));
412 const unsigned TotalNumOps =
N->getNumOperands();
414 for (
unsigned I = 0;
I < TotalNumOps; ++
I) {
417 EVT VT =
N->getOperand(
I).getValueType();
418 if (VT != MVT::Glue && VT != MVT::Other) {
435template <
typename LHS_P,
typename RHS_P,
bool Commutable =
false,
436 bool ExcludeChain =
false>
445 template <
typename MatchContext>
452 (Commutable &&
LHS.match(Ctx,
N->getOperand(EO.
FirstIndex + 1)) &&
460template <
typename LHS,
typename RHS>
465template <
typename LHS,
typename RHS>
471template <
typename LHS,
typename RHS>
472inline BinaryOpc_match<LHS, RHS, false, true>
476template <
typename LHS,
typename RHS>
477inline BinaryOpc_match<LHS, RHS, true, true>
483template <
typename LHS,
typename RHS>
488template <
typename LHS,
typename RHS>
493template <
typename LHS,
typename RHS>
498template <
typename LHS,
typename RHS>
503template <
typename LHS,
typename RHS>
508template <
typename LHS,
typename RHS>
513template <
typename LHS,
typename RHS>
518template <
typename LHS,
typename RHS>
523template <
typename LHS,
typename RHS>
528template <
typename LHS,
typename RHS>
533template <
typename LHS,
typename RHS>
537template <
typename LHS,
typename RHS>
542template <
typename LHS,
typename RHS>
546template <
typename LHS,
typename RHS>
551template <
typename LHS,
typename RHS>
556template <
typename LHS,
typename RHS>
560template <
typename LHS,
typename RHS>
565template <
typename LHS,
typename RHS>
570template <
typename LHS,
typename RHS>
575template <
typename LHS,
typename RHS>
580template <
typename LHS,
typename RHS>
585template <
typename LHS,
typename RHS>
597 template <
typename MatchContext>
609template <
typename Opnd>
613template <
typename Opnd>
637template <
typename Opnd>
640 std::forward<Opnd>(
Op));
645template <
typename Opnd>
648 std::forward<Opnd>(
Op));
653template <
typename Opnd>
656 std::forward<Opnd>(
Op));
661template <
typename Opnd>
664 std::forward<Opnd>(
Op));
673 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
678 if (
auto *
C = dyn_cast_or_null<ConstantSDNode>(
N.getNode())) {
700 template <
typename MatchContext>
730 return ConstVal.
isOne();
734 return (ConstVal & 0x01) == 1;
753 return (ConstVal & 0x01) == 0;
762template <
typename ValTy>
768template <
typename ValTy>
This file implements a class to represent arbitrary precision integral constant values and operations...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file describes how to lower LLVM code to machine code.
Class for arbitrary precision integers.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
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!...
bool isOne() const
Determine if this is a value of 1.
This class represents an Operation in the Expression.
MatchResult match(StringRef Buffer, const SourceMgr &SM) const
Matches the pattern string against the input buffer Buffer.
Represents one node in the SelectionDAG.
MatchContext can repurpose existing patterns to behave differently under a certain context.
const TargetLowering * getTLI() const
const SelectionDAG * getDAG() const
BasicMatchContext(const TargetLowering *TLI)
BasicMatchContext(const SelectionDAG *DAG)
bool match(SDValue N, unsigned Opcode) const
Return true if N effectively has opcode Opcode.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
BooleanContent getBooleanContents(bool isVec, bool isFloat) const
For targets without i1 registers, this gives the nature of the high-bits of boolean values held in ty...
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
bool isOperationLegal(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target.
@ ZeroOrOneBooleanContent
@ UndefinedBooleanContent
@ ZeroOrNegativeOneBooleanContent
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
@ C
The default llvm calling convention, compatible with C.
@ ADD
Simple integer binary arithmetic operators.
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ FADD
Simple binary floating point operators.
@ SIGN_EXTEND
Conversion operators.
@ SHL
Shift and rotation operations.
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ SMIN
[US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned integers.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
bool isConstantSplatVector(const SDNode *N, APInt &SplatValue)
Node predicates.
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Opcode_match m_Opc(unsigned Opcode)
BinaryOpc_match< LHS, RHS, false > m_FDiv(const LHS &L, const RHS &R)
auto m_SpecificVT(EVT RefVT, const Pattern &P)
Match a specific ValueType.
BinaryOpc_match< LHS, RHS, true > m_Mul(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false > m_SRem(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, true > m_Or(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false, true > m_ChainedBinOp(unsigned Opc, const LHS &L, const RHS &R)
UnaryOpc_match< Opnd > m_SExt(const Opnd &Op)
BinaryOpc_match< LHS, RHS, true > m_SMin(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false > m_Sub(const LHS &L, const RHS &R)
BinaryOpc_match< ValTy, SpecificInt_match, true > m_Not(const ValTy &V)
Match a Not as a xor(v, -1) or xor(-1, v)
UnaryOpc_match< Opnd > m_Trunc(const Opnd &Op)
BinaryOpc_match< LHS, RHS, false > m_Sra(const LHS &L, const RHS &R)
Or< UnaryOpc_match< Opnd >, Opnd > m_ZExtOrSelf(Opnd &&Op)
Match a zext or identity Allows to peek through optional extensions.
BinaryOpc_match< LHS, RHS, true, true > m_c_ChainedBinOp(unsigned Opc, const LHS &L, const RHS &R)
auto m_ScalableVectorVT()
auto m_LegalType(const Pattern &P)
Match legal ValueTypes based on the information provided by TargetLowering.
SpecificInt_match m_AllOnes()
BinaryOpc_match< LHS, RHS, true > m_UMin(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, true > m_SMax(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false > m_Srl(const LHS &L, const RHS &R)
NUses_match< N, Value_match > m_NUses()
UnaryOpc_match< Opnd, true > m_ChainedUnaryOp(unsigned Opc, const Opnd &Op)
SpecificInt_match m_SpecificInt(APInt V)
Match a specific integer constant or constant splat value.
Value_match m_Specific(SDValue N)
BinaryOpc_match< LHS, RHS, true > m_And(const LHS &L, const RHS &R)
ValueType_bind m_VT(EVT &VT)
Retreive the ValueType of the current SDValue.
SpecificInt_match m_One()
BinaryOpc_match< LHS, RHS, false > m_SDiv(const LHS &L, const RHS &R)
And< Preds... > m_AllOf(Preds &&...preds)
SpecificInt_match m_Zero()
UnaryOpc_match< Opnd > m_AnyExt(const Opnd &Op)
BinaryOpc_match< LHS, RHS, false > m_FRem(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false > m_Shl(const LHS &L, const RHS &R)
Or< UnaryOpc_match< Opnd >, Opnd > m_TruncOrSelf(Opnd &&Op)
Match a trunc or identity Allows to peek through optional truncations.
BinaryOpc_match< LHS, RHS, false > m_UDiv(const LHS &L, const RHS &R)
BinaryOpc_match< SpecificInt_match, ValTy > m_Neg(const ValTy &V)
Match a negate as a sub(0, v)
SwitchContext< MatchContext, Pattern > m_Context(const MatchContext &Ctx, Pattern &&P)
BinaryOpc_match< LHS, RHS, true > m_FAdd(const LHS &L, const RHS &R)
Or< Preds... > m_AnyOf(Preds &&...preds)
BinaryOpc_match< LHS, RHS, true > m_UMax(const LHS &L, const RHS &R)
bool sd_match(SDNode *N, const SelectionDAG *DAG, Pattern &&P)
UnaryOpc_match< Opnd > m_UnaryOp(unsigned Opc, const Opnd &Op)
BinaryOpc_match< LHS, RHS, true > m_Xor(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, false > m_FSub(const LHS &L, const RHS &R)
auto m_Node(unsigned Opcode, OpndPreds &&...preds)
UnaryOpc_match< Opnd > m_ZExt(const Opnd &Op)
Value_match m_Value()
Match any valid SDValue.
BinaryOpc_match< LHS, RHS, false > m_URem(const LHS &L, const RHS &R)
BinaryOpc_match< LHS, RHS, true > m_Add(const LHS &L, const RHS &R)
auto m_LegalOp(const Pattern &P)
Match legal SDNodes based on the information provided by TargetLowering.
auto m_True()
Match true boolean value based on the information provided by TargetLowering.
NUses_match< 1, Value_match > m_OneUse()
auto m_False()
Match false boolean value based on the information provided by TargetLowering.
BinaryOpc_match< LHS, RHS, true > m_c_BinOp(unsigned Opc, const LHS &L, const RHS &R)
DeferredValue_match m_Deferred(SDValue &V)
Similar to m_Specific, but the specific value to match is determined by another sub-pattern in the sa...
Or< UnaryOpc_match< Opnd >, Opnd > m_AExtOrSelf(Opnd &&Op)
Match a aext or identity Allows to peek through optional extensions.
bool sd_context_match(SDValue N, const MatchContext &Ctx, Pattern &&P)
BinaryOpc_match< LHS, RHS, true > m_FMul(const LHS &L, const RHS &R)
ConstantInt_match m_ConstInt()
Match any interger constants or splat of an integer constant.
Or< UnaryOpc_match< Opnd >, Opnd > m_SExtOrSelf(Opnd &&Op)
Match a sext or identity Allows to peek through optional extensions.
This is an optimization pass for GlobalISel generic memory operations.
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.
And(Pred &&p, Preds &&...preds)
bool match(const MatchContext &Ctx, SDValue N)
bool match(const MatchContext &, SDValue N)
bool match(const MatchContext &Ctx, SDValue N)
BinaryOpc_match(unsigned Opc, const LHS_P &L, const RHS_P &R)
ConstantInt_match(APInt *V)
bool match(const MatchContext &, SDValue N)
bool match(const MatchContext &, SDValue N)
DeferredValue_match(SDValue &Match)
EffectiveOperands(SDValue N)
Provide number of operands that are not chain or glue, as well as the first index of such operand.
EffectiveOperands(SDValue N)
bool match(const MatchContext &Ctx, SDValue N)
NUses_match(const Pattern &P)
bool match(const MatchContext &Ctx, SDValue N)
Opcode_match(unsigned Opc)
Operands_match(OpndPred &&p, OpndPreds &&...preds)
bool match(const MatchContext &Ctx, SDValue N)
bool match(const MatchContext &Ctx, SDValue N)
bool match(const MatchContext &Ctx, SDValue N)
Or(Pred &&p, Preds &&...preds)
bool match(const MatchContext &, SDValue N)
SpecificInt_match(APInt APV)
bool match(const MatchContext &Ctx, SDValue N)
Switch to a different MatchContext for subsequent patterns.
const NewMatchContext & Ctx
bool match(const OrigMatchContext &, SDValue N)
bool match(const MatchContext &Ctx, SDValue N)
TLI_pred_match(const PredFuncT &Pred, const Pattern &P)
bool match(const MatchContext &Ctx, SDValue N)
UnaryOpc_match(unsigned Opc, const Opnd_P &Op)
bool match(const MatchContext &, SDValue N)
ValueType_bind(EVT &Bind)
ValueType_match(const PredFuncT &Pred, const Pattern &P)
bool match(const MatchContext &Ctx, SDValue N)
bool match(const MatchContext &, SDValue N)
bool match(const MatchContext &, SDValue N)
Value_match(SDValue Match)