@@ -52,6 +52,101 @@ inline cst_pred_ty<is_all_ones> m_scev_AllOnes() {
52
52
return cst_pred_ty<is_all_ones>();
53
53
}
54
54
55
+ template <typename Class> struct class_match {
56
+ template <typename ITy> bool match (ITy *V) const { return isa<Class>(V); }
57
+ };
58
+
59
+ template <typename Class> struct bind_ty {
60
+ Class *&VR;
61
+
62
+ bind_ty (Class *&V) : VR(V) {}
63
+
64
+ template <typename ITy> bool match (ITy *V) const {
65
+ if (auto *CV = dyn_cast<Class>(V)) {
66
+ VR = CV;
67
+ return true ;
68
+ }
69
+ return false ;
70
+ }
71
+ };
72
+
73
+ // / Match a SCEV, capturing it if we match.
74
+ inline bind_ty<const SCEV> m_SCEV (const SCEV *&V) { return V; }
75
+ inline bind_ty<const SCEVConstant> m_SCEVConstant (const SCEVConstant *&V) {
76
+ return V;
77
+ }
78
+ inline bind_ty<const SCEVUnknown> m_SCEVUnknown (const SCEVUnknown *&V) {
79
+ return V;
80
+ }
81
+
82
+ // / Match a specified const SCEV *.
83
+ struct specificscev_ty {
84
+ const SCEV *Expr;
85
+
86
+ specificscev_ty (const SCEV *Expr) : Expr(Expr) {}
87
+
88
+ template <typename ITy> bool match (ITy *S) { return S == Expr; }
89
+ };
90
+
91
+ // / Match if we have a specific specified SCEV.
92
+ inline specificscev_ty m_Specific (const SCEV *S) { return S; }
93
+
94
+ // / Match a unary SCEV.
95
+ template <typename SCEVTy, typename Op0_t> struct SCEVUnaryExpr_match {
96
+ Op0_t Op0;
97
+
98
+ SCEVUnaryExpr_match (Op0_t Op0) : Op0(Op0) {}
99
+
100
+ bool match (const SCEV *S) {
101
+ auto *E = dyn_cast<SCEVTy>(S);
102
+ return E && E->getNumOperands () == 1 && Op0.match (E->getOperand (0 ));
103
+ }
104
+ };
105
+
106
+ template <typename SCEVTy, typename Op0_t>
107
+ inline SCEVUnaryExpr_match<SCEVTy, Op0_t> m_scev_Unary (const Op0_t &Op0) {
108
+ return SCEVUnaryExpr_match<SCEVTy, Op0_t>(Op0);
109
+ }
110
+
111
+ template <typename Op0_t>
112
+ inline SCEVUnaryExpr_match<SCEVSignExtendExpr, Op0_t>
113
+ m_scev_SExt (const Op0_t &Op0) {
114
+ return m_scev_Unary<SCEVSignExtendExpr>(Op0);
115
+ }
116
+
117
+ template <typename Op0_t>
118
+ inline SCEVUnaryExpr_match<SCEVZeroExtendExpr, Op0_t>
119
+ m_scev_ZExt (const Op0_t &Op0) {
120
+ return m_scev_Unary<SCEVZeroExtendExpr>(Op0);
121
+ }
122
+
123
+ // / Match a binary SCEV.
124
+ template <typename SCEVTy, typename Op0_t, typename Op1_t>
125
+ struct SCEVBinaryExpr_match {
126
+ Op0_t Op0;
127
+ Op1_t Op1;
128
+
129
+ SCEVBinaryExpr_match (Op0_t Op0, Op1_t Op1) : Op0(Op0), Op1(Op1) {}
130
+
131
+ bool match (const SCEV *S) {
132
+ auto *E = dyn_cast<SCEVTy>(S);
133
+ return E && E->getNumOperands () == 2 && Op0.match (E->getOperand (0 )) &&
134
+ Op1.match (E->getOperand (1 ));
135
+ }
136
+ };
137
+
138
+ template <typename SCEVTy, typename Op0_t, typename Op1_t>
139
+ inline SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t>
140
+ m_scev_Binary (const Op0_t &Op0, const Op1_t &Op1) {
141
+ return SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t>(Op0, Op1);
142
+ }
143
+
144
+ template <typename Op0_t, typename Op1_t>
145
+ inline SCEVBinaryExpr_match<SCEVAddExpr, Op0_t, Op1_t>
146
+ m_scev_Add (const Op0_t &Op0, const Op1_t &Op1) {
147
+ return m_scev_Binary<SCEVAddExpr>(Op0, Op1);
148
+ }
149
+
55
150
} // namespace SCEVPatternMatch
56
151
} // namespace llvm
57
152
0 commit comments