@@ -241,16 +241,18 @@ template <typename PatternT>
241241class SplitMatchAndRewriteImpl : public PatternT {
242242 using PatternT::PatternT;
243243
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+
244250 // / Rewrite the IR rooted at the specified operation with the result of
245251 // / this pattern, generating any new operations with the specified
246252 // / rewriter.
247253 virtual void rewrite (typename PatternT::OperationT op,
248254 PatternRewriter &rewriter) const = 0;
249255
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-
254256 LogicalResult matchAndRewrite (typename PatternT::OperationT op,
255257 PatternRewriter &rewriter) const final {
256258 if (succeeded (match (op))) {
@@ -263,9 +265,7 @@ class SplitMatchAndRewriteImpl : public PatternT {
263265} // namespace detail
264266
265267// / 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+
269269class RewritePattern : public Pattern {
270270public:
271271 using OperationT = Operation *;
@@ -274,8 +274,11 @@ class RewritePattern : public Pattern {
274274 virtual ~RewritePattern () = default ;
275275
276276 // / 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".
279282 virtual LogicalResult matchAndRewrite (Operation *op,
280283 PatternRewriter &rewriter) const = 0;
281284
0 commit comments