20
20
#include " llvm/CodeGen/MachineRegisterInfo.h"
21
21
#include " llvm/CodeGen/TargetOpcodes.h"
22
22
#include " llvm/IR/InstrTypes.h"
23
- #include < optional>
24
23
25
24
namespace llvm {
26
25
namespace MIPatternMatch {
@@ -88,12 +87,6 @@ inline std::optional<int64_t> matchConstant(Register Reg,
88
87
return getIConstantVRegSExtVal (Reg, MRI);
89
88
}
90
89
91
- template <>
92
- inline std::optional<uint64_t > matchConstant (Register Reg,
93
- const MachineRegisterInfo &MRI) {
94
- return getIConstantVRegZExtVal (Reg, MRI);
95
- }
96
-
97
90
template <typename ConstT> struct ConstantMatch {
98
91
ConstT &CR;
99
92
ConstantMatch (ConstT &C) : CR(C) {}
@@ -113,10 +106,6 @@ inline ConstantMatch<int64_t> m_ICst(int64_t &Cst) {
113
106
return ConstantMatch<int64_t >(Cst);
114
107
}
115
108
116
- inline ConstantMatch<uint64_t > m_ICst (uint64_t &Cst) {
117
- return ConstantMatch<uint64_t >(Cst);
118
- }
119
-
120
109
template <typename ConstT>
121
110
inline std::optional<ConstT> matchConstantSplat (Register,
122
111
const MachineRegisterInfo &);
@@ -133,12 +122,6 @@ matchConstantSplat(Register Reg, const MachineRegisterInfo &MRI) {
133
122
return getIConstantSplatSExtVal (Reg, MRI);
134
123
}
135
124
136
- template <>
137
- inline std::optional<uint64_t >
138
- matchConstantSplat (Register Reg, const MachineRegisterInfo &MRI) {
139
- return getIConstantSplatZExtVal (Reg, MRI);
140
- }
141
-
142
125
template <typename ConstT> struct ICstOrSplatMatch {
143
126
ConstT &CR;
144
127
ICstOrSplatMatch (ConstT &C) : CR(C) {}
@@ -165,10 +148,6 @@ inline ICstOrSplatMatch<int64_t> m_ICstOrSplat(int64_t &Cst) {
165
148
return ICstOrSplatMatch<int64_t >(Cst);
166
149
}
167
150
168
- inline ICstOrSplatMatch<uint64_t > m_ICstOrSplat (uint64_t &Cst) {
169
- return ICstOrSplatMatch<uint64_t >(Cst);
170
- }
171
-
172
151
struct GCstAndRegMatch {
173
152
std::optional<ValueAndVReg> &ValReg;
174
153
GCstAndRegMatch (std::optional<ValueAndVReg> &ValReg) : ValReg(ValReg) {}
@@ -927,176 +906,6 @@ m_Not(const SrcTy &&Src) {
927
906
return m_GXor (Src, m_AllOnesInt ());
928
907
}
929
908
930
- // / Matching combinators
931
- template <typename LTy, typename RTy> struct match_combine_or {
932
- LTy L;
933
- RTy R;
934
-
935
- match_combine_or (const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
936
-
937
- template <typename OpTy>
938
- bool match (const MachineRegisterInfo &MRI, OpTy &&Op) {
939
- if (L.match (MRI, Op))
940
- return true ;
941
- if (R.match (MRI, Op))
942
- return true ;
943
- return false ;
944
- }
945
- };
946
-
947
- template <typename LTy, typename RTy> struct match_combine_and {
948
- LTy L;
949
- RTy R;
950
-
951
- match_combine_and (const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
952
-
953
- template <typename OpTy>
954
- bool match (const MachineRegisterInfo &MRI, OpTy &&Op) {
955
- if (L.match (MRI, Op))
956
- if (R.match (MRI, Op))
957
- return true ;
958
- return false ;
959
- }
960
- };
961
-
962
- // / Combine two pattern matchers matching L || R
963
- template <typename LTy, typename RTy>
964
- inline match_combine_or<LTy, RTy> m_CombineOr (const LTy &L, const RTy &R) {
965
- return match_combine_or<LTy, RTy>(L, R);
966
- }
967
-
968
- // / Combine two pattern matchers matching L && R
969
- template <typename LTy, typename RTy>
970
- inline match_combine_and<LTy, RTy> m_CombineAnd (const LTy &L, const RTy &R) {
971
- return match_combine_and<LTy, RTy>(L, R);
972
- }
973
-
974
- template <typename Opnd_t> struct Argument_match {
975
- unsigned OpI;
976
- Opnd_t Val;
977
-
978
- Argument_match (unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
979
-
980
- template <typename OpTy>
981
- bool match (const MachineRegisterInfo &MRI, OpTy &&Op) {
982
- MachineInstr *TmpMI;
983
- if (mi_match (Op, MRI, m_MInstr (TmpMI)))
984
- return Val.match (
985
- MRI, TmpMI->getOperand (TmpMI->getNumDefs () + 1 + OpI).getReg ());
986
- return false ;
987
- }
988
- };
989
-
990
- // / Match an argument.
991
- template <unsigned OpI, typename Opnd_t>
992
- inline Argument_match<Opnd_t> m_Argument (const Opnd_t &Op) {
993
- return Argument_match<Opnd_t>(OpI, Op);
994
- }
995
-
996
- // / Intrinsic matchers.
997
- struct IntrinsicID_match {
998
- unsigned ID;
999
-
1000
- IntrinsicID_match (Intrinsic::ID IntrID) : ID(IntrID) {}
1001
-
1002
- template <typename OpTy>
1003
- bool match (const MachineRegisterInfo &MRI, OpTy &&Op) {
1004
- MachineInstr *TmpMI;
1005
- if (mi_match (Op, MRI, m_MInstr (TmpMI)))
1006
- if (auto *Intr = dyn_cast<GIntrinsic>(TmpMI))
1007
- return Intr->getIntrinsicID () == ID;
1008
- return false ;
1009
- }
1010
- };
1011
-
1012
- // / Intrinsic matches are combinations of ID matchers, and argument
1013
- // / matchers. Higher arity matcher are defined recursively in terms of and-ing
1014
- // / them with lower arity matchers. Here's some convenient typedefs for up to
1015
- // / several arguments, and more can be added as needed
1016
- template <typename T0 = void , typename T1 = void , typename T2 = void ,
1017
- typename T3 = void , typename T4 = void , typename T5 = void ,
1018
- typename T6 = void , typename T7 = void , typename T8 = void ,
1019
- typename T9 = void , typename T10 = void >
1020
- struct m_Intrinsic_Ty ;
1021
- template <typename T0> struct m_Intrinsic_Ty <T0> {
1022
- using Ty = match_combine_and<IntrinsicID_match, Argument_match<T0>>;
1023
- };
1024
- template <typename T0, typename T1> struct m_Intrinsic_Ty <T0, T1> {
1025
- using Ty =
1026
- match_combine_and<typename m_Intrinsic_Ty<T0>::Ty, Argument_match<T1>>;
1027
- };
1028
- template <typename T0, typename T1, typename T2>
1029
- struct m_Intrinsic_Ty <T0, T1, T2> {
1030
- using Ty = match_combine_and<typename m_Intrinsic_Ty<T0, T1>::Ty,
1031
- Argument_match<T2>>;
1032
- };
1033
- template <typename T0, typename T1, typename T2, typename T3>
1034
- struct m_Intrinsic_Ty <T0, T1, T2, T3> {
1035
- using Ty = match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2>::Ty,
1036
- Argument_match<T3>>;
1037
- };
1038
-
1039
- template <typename T0, typename T1, typename T2, typename T3, typename T4>
1040
- struct m_Intrinsic_Ty <T0, T1, T2, T3, T4> {
1041
- using Ty = match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty,
1042
- Argument_match<T4>>;
1043
- };
1044
-
1045
- template <typename T0, typename T1, typename T2, typename T3, typename T4,
1046
- typename T5>
1047
- struct m_Intrinsic_Ty <T0, T1, T2, T3, T4, T5> {
1048
- using Ty = match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2, T3, T4>::Ty,
1049
- Argument_match<T5>>;
1050
- };
1051
-
1052
- // / Match intrinsic calls like this:
1053
- // / m_Intrinsic<Intrinsic::fabs>(m_Value(X))
1054
- template <Intrinsic::ID IntrID> inline IntrinsicID_match m_GIntrinsic () {
1055
- return IntrinsicID_match (IntrID);
1056
- }
1057
-
1058
- template <Intrinsic::ID IntrID, typename T0>
1059
- inline typename m_Intrinsic_Ty<T0>::Ty m_GIntrinsic (const T0 &Op0) {
1060
- return m_CombineAnd (m_GIntrinsic<IntrID>(), m_Argument<0 >(Op0));
1061
- }
1062
-
1063
- template <Intrinsic::ID IntrID, typename T0, typename T1>
1064
- inline typename m_Intrinsic_Ty<T0, T1>::Ty m_GIntrinsic (const T0 &Op0,
1065
- const T1 &Op1) {
1066
- return m_CombineAnd (m_GIntrinsic<IntrID>(Op0), m_Argument<1 >(Op1));
1067
- }
1068
-
1069
- template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
1070
- inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
1071
- m_GIntrinsic (const T0 &Op0, const T1 &Op1, const T2 &Op2) {
1072
- return m_CombineAnd (m_GIntrinsic<IntrID>(Op0, Op1), m_Argument<2 >(Op2));
1073
- }
1074
-
1075
- template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1076
- typename T3>
1077
- inline typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty
1078
- m_GIntrinsic (const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
1079
- return m_CombineAnd (m_GIntrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3 >(Op3));
1080
- }
1081
-
1082
- template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1083
- typename T3, typename T4>
1084
- inline typename m_Intrinsic_Ty<T0, T1, T2, T3, T4>::Ty
1085
- m_GIntrinsic (const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
1086
- const T4 &Op4) {
1087
- return m_CombineAnd (m_GIntrinsic<IntrID>(Op0, Op1, Op2, Op3),
1088
- m_Argument<4 >(Op4));
1089
- }
1090
-
1091
- template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1092
- typename T3, typename T4, typename T5>
1093
- inline typename m_Intrinsic_Ty<T0, T1, T2, T3, T4, T5>::Ty
1094
- m_GIntrinsic (const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3,
1095
- const T4 &Op4, const T5 &Op5) {
1096
- return m_CombineAnd (m_GIntrinsic<IntrID>(Op0, Op1, Op2, Op3, Op4),
1097
- m_Argument<5 >(Op5));
1098
- }
1099
-
1100
909
} // namespace MIPatternMatch
1101
910
} // namespace llvm
1102
911
0 commit comments