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 Pred>
struct Not {
366 template <
typename MatchContext>
368 return !
P.match(Ctx,
N);
379template <
typename... Preds>
And<Preds...>
m_AllOf(Preds &&...preds) {
380 return And<Preds...>(std::forward<Preds>(preds)...);
383template <
typename... Preds>
Or<Preds...>
m_AnyOf(Preds &&...preds) {
384 return Or<Preds...>(std::forward<Preds>(preds)...);
387template <
typename... Preds>
auto m_NoneOf(Preds &&...preds) {
393 template <
typename MatchContext>
396 return N->getNumOperands() == OpIdx;
400template <
unsigned OpIdx,
typename OpndPred,
typename... OpndPreds>
407 std::forward<OpndPreds>(preds)...),
408 P(
std::forward<OpndPred>(p)) {}
410 template <
typename MatchContext>
412 if (OpIdx < N->getNumOperands())
413 return P.match(Ctx,
N->getOperand(OpIdx)) &&
421template <
typename... OpndPreds>
422auto m_Node(
unsigned Opcode, OpndPreds &&...preds) {
424 std::forward<OpndPreds>(preds)...));
434 const unsigned TotalNumOps =
N->getNumOperands();
436 for (
unsigned I = 0;
I < TotalNumOps; ++
I) {
439 EVT VT =
N->getOperand(
I).getValueType();
440 if (VT != MVT::Glue && VT != MVT::Other) {
457template <
typename LHS_P,
typename RHS_P,
bool Commutable =
false,
458 bool ExcludeChain =
false>
467 template <
typename MatchContext>
474 (Commutable &&
LHS.match(Ctx,
N->getOperand(EO.
FirstIndex + 1)) &&
482template <
typename LHS,
typename RHS>
487template <
typename LHS,
typename RHS>
493template <
typename LHS,
typename RHS>
494inline BinaryOpc_match<LHS, RHS, false, true>
498template <
typename LHS,
typename RHS>
499inline BinaryOpc_match<LHS, RHS, true, true>
505template <
typename LHS,
typename RHS>
510template <
typename LHS,
typename RHS>
515template <
typename LHS,
typename RHS>
520template <
typename LHS,
typename RHS>
525template <
typename LHS,
typename RHS>
530template <
typename LHS,
typename RHS>
535template <
typename LHS,
typename RHS>
540template <
typename LHS,
typename RHS>
545template <
typename LHS,
typename RHS>
550template <
typename LHS,
typename RHS>
555template <
typename LHS,
typename RHS>
559template <
typename LHS,
typename RHS>
564template <
typename LHS,
typename RHS>
568template <
typename LHS,
typename RHS>
573template <
typename LHS,
typename RHS>
578template <
typename LHS,
typename RHS>
582template <
typename LHS,
typename RHS>
587template <
typename LHS,
typename RHS>
592template <
typename LHS,
typename RHS>
597template <
typename LHS,
typename RHS>
602template <
typename LHS,
typename RHS>
607template <
typename LHS,
typename RHS>
619 template <
typename MatchContext>
631template <
typename Opnd>
635template <
typename Opnd>
641template <
typename Opnd>
650template <
typename Opnd>
inline auto m_SExt(Opnd &&
Op) {
678template <
typename Opnd>
681 std::forward<Opnd>(
Op));
686template <
typename Opnd>
689 std::forward<Opnd>(
Op));
698 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
703 if (
auto *
C = dyn_cast_or_null<ConstantSDNode>(
N.getNode())) {
725 template <
typename MatchContext>
749 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
765 return ConstVal.
isOne();
769 return (ConstVal & 0x01) == 1;
788 return (ConstVal & 0x01) == 0;
804 template <
typename MatchContext>
bool match(
const MatchContext &,
SDValue N) {
805 if (
auto *
CC = dyn_cast<CondCodeSDNode>(
N.getNode())) {
830template <
typename ValTy>
836template <
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.
@ SIGN_EXTEND_INREG
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
@ 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.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
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)
auto m_ZExtOrSelf(Opnd &&Op)
Match a zext or identity Allows to peek through optional extensions.
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)
auto m_NoneOf(Preds &&...preds)
UnaryOpc_match< Opnd > m_Trunc(const Opnd &Op)
BinaryOpc_match< LHS, RHS, false > m_Sra(const LHS &L, const RHS &R)
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.
BinaryOpc_match< LHS, RHS, true > m_UMin(const LHS &L, const RHS &R)
Not< Pred > m_Unless(const Pred &P)
Match if the inner pattern does NOT match.
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)
UnaryOpc_match< Opnd > m_BitReverse(const Opnd &Op)
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.
BinaryOpc_match< ValTy, AllOnes_match, true > m_Not(const ValTy &V)
Match a Not as a xor(v, -1) or xor(-1, v)
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)
CondCode_match m_SpecificCondCode(ISD::CondCode CC)
Match a conditional code SDNode with a specific ISD::CondCode.
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.
auto m_SExtOrSelf(Opnd &&Op)
Match a sext or identity Allows to peek through optional extensions.
NUses_match< 1, Value_match > m_OneUse()
auto m_False()
Match false boolean value based on the information provided by TargetLowering.
CondCode_match m_CondCode()
Match any conditional code SDNode.
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.
AllOnes_match m_AllOnes()
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.
This is an optimization pass for GlobalISel generic memory operations.
bool isAllOnesOrAllOnesSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI, bool AllowUndefs=false)
Return true if the value is a constant -1 integer or a splatted vector of a constant -1 integer (with...
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.
bool match(const MatchContext &, SDValue N)
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)
CondCode_match(ISD::CondCode CC)
bool match(const MatchContext &, SDValue N)
CondCode_match(ISD::CondCode *CC)
std::optional< ISD::CondCode > CCToMatch
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)
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)