@@ -241,16 +241,18 @@ template <typename PatternT>
241
241
class SplitMatchAndRewriteImpl : public PatternT {
242
242
using PatternT::PatternT;
243
243
244
+ // / Attempt to match against IR rooted at the specified operation, which is
245
+ // / the same operation kind as getRootKind().
246
+ // /
247
+ // / Note: This function must not modify the IR.
248
+ virtual LogicalResult match (typename PatternT::OperationT op) const = 0;
249
+
244
250
// / Rewrite the IR rooted at the specified operation with the result of
245
251
// / this pattern, generating any new operations with the specified
246
252
// / rewriter.
247
253
virtual void rewrite (typename PatternT::OperationT op,
248
254
PatternRewriter &rewriter) const = 0;
249
255
250
- // / Attempt to match against code rooted at the specified operation,
251
- // / which is the same operation code as getRootKind().
252
- virtual LogicalResult match (typename PatternT::OperationT op) const = 0;
253
-
254
256
LogicalResult matchAndRewrite (typename PatternT::OperationT op,
255
257
PatternRewriter &rewriter) const final {
256
258
if (succeeded (match (op))) {
@@ -263,9 +265,7 @@ class SplitMatchAndRewriteImpl : public PatternT {
263
265
} // namespace detail
264
266
265
267
// / RewritePattern is the common base class for all DAG to DAG replacements.
266
- // / By overloading the "matchAndRewrite" function, the user can perform the
267
- // / rewrite in the same call as the match.
268
- // /
268
+
269
269
class RewritePattern : public Pattern {
270
270
public:
271
271
using OperationT = Operation *;
@@ -274,8 +274,11 @@ class RewritePattern : public Pattern {
274
274
virtual ~RewritePattern () = default ;
275
275
276
276
// / Attempt to match against code rooted at the specified operation,
277
- // / which is the same operation code as getRootKind(). If successful, this
278
- // / function will automatically perform the rewrite.
277
+ // / which is the same operation code as getRootKind(). If successful, perform
278
+ // / the rewrite.
279
+ // /
280
+ // / Note: Implementations must modify the IR if and only if the function
281
+ // / returns "success".
279
282
virtual LogicalResult matchAndRewrite (Operation *op,
280
283
PatternRewriter &rewriter) const = 0;
281
284
0 commit comments