@@ -155,6 +155,71 @@ struct Opcode_match {
155155 }
156156};
157157
158+ // === Patterns combinators ===
159+ template <typename ... Preds> struct And {
160+ template <typename MatchContext> bool match (const MatchContext &, SDValue N) {
161+ return true ;
162+ }
163+ };
164+
165+ template <typename Pred, typename ... Preds>
166+ struct And <Pred, Preds...> : And<Preds...> {
167+ Pred P;
168+ And (const Pred &p, const Preds &...preds) : And<Preds...>(preds...), P(p) {}
169+
170+ template <typename MatchContext>
171+ bool match (const MatchContext &Ctx, SDValue N) {
172+ return P.match (Ctx, N) && And<Preds...>::match (Ctx, N);
173+ }
174+ };
175+
176+ template <typename ... Preds> struct Or {
177+ template <typename MatchContext> bool match (const MatchContext &, SDValue N) {
178+ return false ;
179+ }
180+ };
181+
182+ template <typename Pred, typename ... Preds>
183+ struct Or <Pred, Preds...> : Or<Preds...> {
184+ Pred P;
185+ Or (const Pred &p, const Preds &...preds) : Or<Preds...>(preds...), P(p) {}
186+
187+ template <typename MatchContext>
188+ bool match (const MatchContext &Ctx, SDValue N) {
189+ return P.match (Ctx, N) || Or<Preds...>::match (Ctx, N);
190+ }
191+ };
192+
193+ template <typename Pred> struct Not {
194+ Pred P;
195+
196+ explicit Not (const Pred &P) : P(P) {}
197+
198+ template <typename MatchContext>
199+ bool match (const MatchContext &Ctx, SDValue N) {
200+ return !P.match (Ctx, N);
201+ }
202+ };
203+ // Explicit deduction guide.
204+ template <typename Pred> Not (const Pred &P) -> Not<Pred>;
205+
206+ // / Match if the inner pattern does NOT match.
207+ template <typename Pred> inline Not<Pred> m_Unless (const Pred &P) {
208+ return Not{P};
209+ }
210+
211+ template <typename ... Preds> And<Preds...> m_AllOf (const Preds &...preds) {
212+ return And<Preds...>(preds...);
213+ }
214+
215+ template <typename ... Preds> Or<Preds...> m_AnyOf (const Preds &...preds) {
216+ return Or<Preds...>(preds...);
217+ }
218+
219+ template <typename ... Preds> auto m_NoneOf (const Preds &...preds) {
220+ return m_Unless (m_AnyOf (preds...));
221+ }
222+
158223inline Opcode_match m_Opc (unsigned Opcode) { return Opcode_match (Opcode); }
159224
160225inline Opcode_match m_Undef () { return Opcode_match (ISD::UNDEF); }
@@ -373,71 +438,6 @@ template <typename Pattern> inline auto m_LegalType(const Pattern &P) {
373438 P};
374439}
375440
376- // === Patterns combinators ===
377- template <typename ... Preds> struct And {
378- template <typename MatchContext> bool match (const MatchContext &, SDValue N) {
379- return true ;
380- }
381- };
382-
383- template <typename Pred, typename ... Preds>
384- struct And <Pred, Preds...> : And<Preds...> {
385- Pred P;
386- And (const Pred &p, const Preds &...preds) : And<Preds...>(preds...), P(p) {}
387-
388- template <typename MatchContext>
389- bool match (const MatchContext &Ctx, SDValue N) {
390- return P.match (Ctx, N) && And<Preds...>::match (Ctx, N);
391- }
392- };
393-
394- template <typename ... Preds> struct Or {
395- template <typename MatchContext> bool match (const MatchContext &, SDValue N) {
396- return false ;
397- }
398- };
399-
400- template <typename Pred, typename ... Preds>
401- struct Or <Pred, Preds...> : Or<Preds...> {
402- Pred P;
403- Or (const Pred &p, const Preds &...preds) : Or<Preds...>(preds...), P(p) {}
404-
405- template <typename MatchContext>
406- bool match (const MatchContext &Ctx, SDValue N) {
407- return P.match (Ctx, N) || Or<Preds...>::match (Ctx, N);
408- }
409- };
410-
411- template <typename Pred> struct Not {
412- Pred P;
413-
414- explicit Not (const Pred &P) : P(P) {}
415-
416- template <typename MatchContext>
417- bool match (const MatchContext &Ctx, SDValue N) {
418- return !P.match (Ctx, N);
419- }
420- };
421- // Explicit deduction guide.
422- template <typename Pred> Not (const Pred &P) -> Not<Pred>;
423-
424- // / Match if the inner pattern does NOT match.
425- template <typename Pred> inline Not<Pred> m_Unless (const Pred &P) {
426- return Not{P};
427- }
428-
429- template <typename ... Preds> And<Preds...> m_AllOf (const Preds &...preds) {
430- return And<Preds...>(preds...);
431- }
432-
433- template <typename ... Preds> Or<Preds...> m_AnyOf (const Preds &...preds) {
434- return Or<Preds...>(preds...);
435- }
436-
437- template <typename ... Preds> auto m_NoneOf (const Preds &...preds) {
438- return m_Unless (m_AnyOf (preds...));
439- }
440-
441441// === Generic node matching ===
442442template <unsigned OpIdx, typename ... OpndPreds> struct Operands_match {
443443 template <typename MatchContext>
0 commit comments