Skip to content

Commit 8b52d62

Browse files
[mlir] Expose optional PatternBenefit to func populate functions (NFC) (llvm#159986)
Pattern benefit allows users to give priority to a pattern.
1 parent 49605a4 commit 8b52d62

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
1414
#define MLIR_DIALECT_FUNC_TRANSFORMS_FUNCCONVERSIONS_H_
1515

16+
#include "mlir/IR/PatternMatch.h"
1617
#include "mlir/Support/LLVM.h"
1718
#include "llvm/ADT/STLExtras.h"
1819

@@ -29,7 +30,8 @@ class RewritePatternSet;
2930
/// Add a pattern to the given pattern list to convert the operand and result
3031
/// types of a CallOp with the given type converter.
3132
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
32-
const TypeConverter &converter);
33+
const TypeConverter &converter,
34+
PatternBenefit benefit = 1);
3335

3436
/// Add a pattern to the given pattern list to rewrite branch operations to use
3537
/// operands that have been legalized by the conversion framework. This can only
@@ -43,7 +45,8 @@ void populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
4345
void populateBranchOpInterfaceTypeConversionPattern(
4446
RewritePatternSet &patterns, const TypeConverter &converter,
4547
function_ref<bool(BranchOpInterface branchOp, int idx)>
46-
shouldConvertBranchOperand = nullptr);
48+
shouldConvertBranchOperand = nullptr,
49+
PatternBenefit benefit = 1);
4750

4851
/// Return true if op is a BranchOpInterface op whose operands are all legal
4952
/// according to converter.
@@ -53,7 +56,8 @@ bool isLegalForBranchOpInterfaceTypeConversionPattern(
5356
/// Add a pattern to the given pattern list to rewrite `return` ops to use
5457
/// operands that have been legalized by the conversion framework.
5558
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns,
56-
const TypeConverter &converter);
59+
const TypeConverter &converter,
60+
PatternBenefit benefit = 1);
5761

5862
/// For ReturnLike ops (except `return`), return True. If op is a `return` &&
5963
/// returnOpAlwaysLegal is false, legalize op according to converter. Otherwise,

mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ struct CallOpSignatureConversion : public OpConversionPattern<CallOp> {
6565
} // namespace
6666

6767
void mlir::populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
68-
const TypeConverter &converter) {
69-
patterns.add<CallOpSignatureConversion>(converter, patterns.getContext());
68+
const TypeConverter &converter,
69+
PatternBenefit benefit) {
70+
patterns.add<CallOpSignatureConversion>(converter, patterns.getContext(),
71+
benefit);
7072
}
7173

7274
namespace {
@@ -81,8 +83,9 @@ class BranchOpInterfaceTypeConversion
8183

8284
BranchOpInterfaceTypeConversion(
8385
const TypeConverter &typeConverter, MLIRContext *ctx,
84-
function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand)
85-
: OpInterfaceConversionPattern(typeConverter, ctx, /*benefit=*/1),
86+
function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand,
87+
PatternBenefit benefit)
88+
: OpInterfaceConversionPattern(typeConverter, ctx, benefit),
8689
shouldConvertBranchOperand(shouldConvertBranchOperand) {}
8790

8891
LogicalResult
@@ -135,9 +138,11 @@ class ReturnOpTypeConversion : public OpConversionPattern<ReturnOp> {
135138

136139
void mlir::populateBranchOpInterfaceTypeConversionPattern(
137140
RewritePatternSet &patterns, const TypeConverter &typeConverter,
138-
function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand) {
141+
function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand,
142+
PatternBenefit benefit) {
139143
patterns.add<BranchOpInterfaceTypeConversion>(
140-
typeConverter, patterns.getContext(), shouldConvertBranchOperand);
144+
typeConverter, patterns.getContext(), shouldConvertBranchOperand,
145+
benefit);
141146
}
142147

143148
bool mlir::isLegalForBranchOpInterfaceTypeConversionPattern(
@@ -157,8 +162,10 @@ bool mlir::isLegalForBranchOpInterfaceTypeConversionPattern(
157162
}
158163

159164
void mlir::populateReturnOpTypeConversionPattern(
160-
RewritePatternSet &patterns, const TypeConverter &typeConverter) {
161-
patterns.add<ReturnOpTypeConversion>(typeConverter, patterns.getContext());
165+
RewritePatternSet &patterns, const TypeConverter &typeConverter,
166+
PatternBenefit benefit) {
167+
patterns.add<ReturnOpTypeConversion>(typeConverter, patterns.getContext(),
168+
benefit);
162169
}
163170

164171
bool mlir::isLegalForReturnOpTypeConversionPattern(

0 commit comments

Comments
 (0)