10
10
// goal is to move this to include/mlir/IR/Matchers.h after the initial testing
11
11
// phase. The matchers in this file are:
12
12
//
13
- // - operation(args...): Matches an operation that matches all of the matchers
14
- // in the vector `matchers`.
13
+ // - operation(args...): Matches all of the matchers in the vector `matchers`.
15
14
//
16
15
// - argument(innerMatcher, index): Matches an operation argument that matches
17
16
// `innerMatcher` at the given `index`.
@@ -39,11 +38,9 @@ namespace extramatcher {
39
38
40
39
namespace detail {
41
40
42
- // TODO: Rename to AllOf
43
- // OperationMatcher takes a vector of DynMatchers and returns true if all
44
- // DynMatchers match the given operation.
45
- struct OperationMatcher {
46
- OperationMatcher (std::vector<matcher::DynMatcher> matchers)
41
+ // AllOf takes a vector of DynMatchers and returns true if all the DynMatchers match the given operation.
42
+ struct AllOfMatcher {
43
+ AllOfMatcher (std::vector<matcher::DynMatcher> matchers)
47
44
: matchers(matchers) {}
48
45
bool match (Operation *op) {
49
46
matcher::DynTypedNode node = matcher::DynTypedNode::create (op);
@@ -54,6 +51,19 @@ struct OperationMatcher {
54
51
std::vector<matcher::DynMatcher> matchers;
55
52
};
56
53
54
+ // AnyOf takes a vector of DynMatchers and returns true if any of the DynMatchers match the given operation.
55
+ struct AnyOfMatcher {
56
+ AnyOfMatcher (std::vector<matcher::DynMatcher> matchers)
57
+ : matchers(matchers) {}
58
+ bool match (Operation *op) {
59
+ matcher::DynTypedNode node = matcher::DynTypedNode::create (op);
60
+ return llvm::any_of (matchers, [&](const matcher::DynMatcher &matcher) {
61
+ return matcher.matches (node);
62
+ });
63
+ }
64
+ std::vector<matcher::DynMatcher> matchers;
65
+ };
66
+
57
67
// ArgumentMatcher matches the operand of an operation at a specific index.
58
68
struct ArgumentMatcher {
59
69
ArgumentMatcher (matcher::DynMatcher innerMatcher, unsigned index)
@@ -145,10 +155,14 @@ struct DefinedByMatcher {
145
155
146
156
} // namespace detail
147
157
148
- // TODO: Rename to allOf()
149
- inline detail::OperationMatcher operation (matcher::DynMatcher args...) {
158
+ inline detail::AllOfMatcher allOf (matcher::DynMatcher args...) {
159
+ std::vector<matcher::DynMatcher> matchers ({args});
160
+ return detail::AllOfMatcher (matchers);
161
+ }
162
+
163
+ inline detail::AnyOfMatcher anyOf (matcher::DynMatcher args...) {
150
164
std::vector<matcher::DynMatcher> matchers ({args});
151
- return detail::OperationMatcher (matchers);
165
+ return detail::AnyOfMatcher (matchers);
152
166
}
153
167
154
168
inline detail::ArgumentMatcher hasArgument (matcher::DynMatcher innerMatcher,
0 commit comments