-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir] Expose optional PatternBenefit
to function / SCF populate functions (NFC)
#159752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthias-springer
merged 1 commit into
main
from
users/matthias-springer/pattern_benefit
Sep 19, 2025
Merged
[mlir] Expose optional PatternBenefit
to function / SCF populate functions (NFC)
#159752
matthias-springer
merged 1 commit into
main
from
users/matthias-springer/pattern_benefit
Sep 19, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesPattern benefit allows users to give priority to a pattern. Full diff: https://github.com/llvm/llvm-project/pull/159752.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h b/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
index 00c8a5c0c517b..cfe68f61a7a42 100644
--- a/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
+++ b/mlir/include/mlir/Dialect/SCF/Transforms/Patterns.h
@@ -51,12 +51,13 @@ class ForLoopPipeliningPattern : public OpRewritePattern<ForOp> {
/// TypeConverter, but otherwise don't care what type conversions are happening.
void populateSCFStructuralTypeConversionsAndLegality(
const TypeConverter &typeConverter, RewritePatternSet &patterns,
- ConversionTarget &target);
+ ConversionTarget &target, PatternBenefit benefit = 1);
/// Similar to `populateSCFStructuralTypeConversionsAndLegality` but does not
/// populate the conversion target.
void populateSCFStructuralTypeConversions(const TypeConverter &typeConverter,
- RewritePatternSet &patterns);
+ RewritePatternSet &patterns,
+ PatternBenefit benefit = 1);
/// Updates the ConversionTarget with dynamic legality of SCF operations based
/// on the provided type converter.
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index 6ef649e8fc13a..ed7e2a08ebfd9 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -811,17 +811,19 @@ convertOpResultTypes(Operation *op, ValueRange operands,
/// ops which use FunctionType to represent their type.
void populateFunctionOpInterfaceTypeConversionPattern(
StringRef functionLikeOpName, RewritePatternSet &patterns,
- const TypeConverter &converter);
+ const TypeConverter &converter, PatternBenefit benefit = 1);
template <typename FuncOpT>
void populateFunctionOpInterfaceTypeConversionPattern(
- RewritePatternSet &patterns, const TypeConverter &converter) {
- populateFunctionOpInterfaceTypeConversionPattern(FuncOpT::getOperationName(),
- patterns, converter);
+ RewritePatternSet &patterns, const TypeConverter &converter,
+ PatternBenefit benefit = 1) {
+ populateFunctionOpInterfaceTypeConversionPattern(
+ FuncOpT::getOperationName(), patterns, converter, benefit);
}
void populateAnyFunctionOpInterfaceTypeConversionPattern(
- RewritePatternSet &patterns, const TypeConverter &converter);
+ RewritePatternSet &patterns, const TypeConverter &converter,
+ PatternBenefit benefit = 1);
//===----------------------------------------------------------------------===//
// Conversion PatternRewriter
diff --git a/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp b/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
index 072bc501aa5c6..b0c781c7aff11 100644
--- a/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/StructuralTypeConversions.cpp
@@ -217,10 +217,11 @@ class ConvertConditionOpTypes : public OpConversionPattern<ConditionOp> {
} // namespace
void mlir::scf::populateSCFStructuralTypeConversions(
- const TypeConverter &typeConverter, RewritePatternSet &patterns) {
+ const TypeConverter &typeConverter, RewritePatternSet &patterns,
+ PatternBenefit benefit) {
patterns.add<ConvertForOpTypes, ConvertIfOpTypes, ConvertYieldOpTypes,
ConvertWhileOpTypes, ConvertConditionOpTypes>(
- typeConverter, patterns.getContext());
+ typeConverter, patterns.getContext(), benefit);
}
void mlir::scf::populateSCFStructuralTypeConversionTarget(
@@ -240,7 +241,7 @@ void mlir::scf::populateSCFStructuralTypeConversionTarget(
void mlir::scf::populateSCFStructuralTypeConversionsAndLegality(
const TypeConverter &typeConverter, RewritePatternSet &patterns,
- ConversionTarget &target) {
- populateSCFStructuralTypeConversions(typeConverter, patterns);
+ ConversionTarget &target, PatternBenefit benefit) {
+ populateSCFStructuralTypeConversions(typeConverter, patterns, benefit);
populateSCFStructuralTypeConversionTarget(typeConverter, target);
}
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index f7565cfb0e45e..ff1e31536cea7 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -3802,8 +3802,9 @@ namespace {
struct FunctionOpInterfaceSignatureConversion : public ConversionPattern {
FunctionOpInterfaceSignatureConversion(StringRef functionLikeOpName,
MLIRContext *ctx,
- const TypeConverter &converter)
- : ConversionPattern(converter, functionLikeOpName, /*benefit=*/1, ctx) {}
+ const TypeConverter &converter,
+ PatternBenefit benefit)
+ : ConversionPattern(converter, functionLikeOpName, benefit, ctx) {}
LogicalResult
matchAndRewrite(Operation *op, ArrayRef<Value> /*operands*/,
@@ -3848,15 +3849,16 @@ mlir::convertOpResultTypes(Operation *op, ValueRange operands,
void mlir::populateFunctionOpInterfaceTypeConversionPattern(
StringRef functionLikeOpName, RewritePatternSet &patterns,
- const TypeConverter &converter) {
+ const TypeConverter &converter, PatternBenefit benefit) {
patterns.add<FunctionOpInterfaceSignatureConversion>(
- functionLikeOpName, patterns.getContext(), converter);
+ functionLikeOpName, patterns.getContext(), converter, benefit);
}
void mlir::populateAnyFunctionOpInterfaceTypeConversionPattern(
- RewritePatternSet &patterns, const TypeConverter &converter) {
+ RewritePatternSet &patterns, const TypeConverter &converter,
+ PatternBenefit benefit) {
patterns.add<AnyFunctionOpInterfaceSignatureConversion>(
- converter, patterns.getContext());
+ converter, patterns.getContext(), benefit);
}
//===----------------------------------------------------------------------===//
|
PatternBenefit
to function / SCF populate functions
PatternBenefit
to function / SCF populate functionsPatternBenefit
to function / SCF populate functions (NFC)
joker-eph
approved these changes
Sep 19, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pattern benefit allows users to give priority to a pattern.