Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/IR/PatternMatch.h
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | |||||
/// matching and rewriting against an instance of a derived operation class as | /// matching and rewriting against an instance of a derived operation class as | ||||
/// opposed to a raw Operation. | /// opposed to a raw Operation. | ||||
template <typename SourceOp> struct OpRewritePattern : public RewritePattern { | template <typename SourceOp> struct OpRewritePattern : public RewritePattern { | ||||
/// Patterns must specify the root operation name they match against, and can | /// Patterns must specify the root operation name they match against, and can | ||||
/// also specify the benefit of the pattern matching. | /// also specify the benefit of the pattern matching. | ||||
OpRewritePattern(MLIRContext *context, PatternBenefit benefit = 1) | OpRewritePattern(MLIRContext *context, PatternBenefit benefit = 1) | ||||
: RewritePattern(SourceOp::getOperationName(), benefit, context) {} | : RewritePattern(SourceOp::getOperationName(), benefit, context) {} | ||||
/// Patterns must specify the root operation name they match against, and can | |||||
/// also specify the benefit of the pattern matching. | |||||
/// `generatedNames` contains the names of operations that may be generated | |||||
/// during a successful rewrite. | |||||
OpRewritePattern(MLIRContext *context, ArrayRef<StringRef> generatedNames, | |||||
PatternBenefit benefit = 1) | |||||
: RewritePattern(SourceOp::getOperationName(), generatedNames, benefit, | |||||
context) {} | |||||
/// Wrappers around the RewritePattern methods that pass the derived op type. | /// Wrappers around the RewritePattern methods that pass the derived op type. | ||||
void rewrite(Operation *op, PatternRewriter &rewriter) const final { | void rewrite(Operation *op, PatternRewriter &rewriter) const final { | ||||
rewrite(cast<SourceOp>(op), rewriter); | rewrite(cast<SourceOp>(op), rewriter); | ||||
} | } | ||||
LogicalResult match(Operation *op) const final { | LogicalResult match(Operation *op) const final { | ||||
return match(cast<SourceOp>(op)); | return match(cast<SourceOp>(op)); | ||||
} | } | ||||
LogicalResult matchAndRewrite(Operation *op, | LogicalResult matchAndRewrite(Operation *op, | ||||
▲ Show 20 Lines • Show All 370 Lines • Show Last 20 Lines |