-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir] Expose optional PatternBenefit
to func
populate functions (NFC)
#159986
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
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 @llvm/pr-subscribers-mlir-func Author: Matthias Springer (matthias-springer) ChangesPattern benefit allows users to give priority to a pattern. Full diff: https://github.com/llvm/llvm-project/pull/159986.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h b/mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h
index 642f704c14430..4f3bbb00fe62a 100644
--- a/mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h
+++ b/mlir/include/mlir/Dialect/Func/Transforms/FuncConversions.h
@@ -23,13 +23,15 @@ class BranchOpInterface;
class ConversionTarget;
class MLIRContext;
class Operation;
+class PatternBenefit;
class TypeConverter;
class RewritePatternSet;
/// Add a pattern to the given pattern list to convert the operand and result
/// types of a CallOp with the given type converter.
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
- const TypeConverter &converter);
+ const TypeConverter &converter,
+ PatternBenefit benefit = 1);
/// Add a pattern to the given pattern list to rewrite branch operations to use
/// operands that have been legalized by the conversion framework. This can only
@@ -43,7 +45,8 @@ void populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
void populateBranchOpInterfaceTypeConversionPattern(
RewritePatternSet &patterns, const TypeConverter &converter,
function_ref<bool(BranchOpInterface branchOp, int idx)>
- shouldConvertBranchOperand = nullptr);
+ shouldConvertBranchOperand = nullptr,
+ PatternBenefit benefit = 1);
/// Return true if op is a BranchOpInterface op whose operands are all legal
/// according to converter.
@@ -53,7 +56,8 @@ bool isLegalForBranchOpInterfaceTypeConversionPattern(
/// Add a pattern to the given pattern list to rewrite `return` ops to use
/// operands that have been legalized by the conversion framework.
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns,
- const TypeConverter &converter);
+ const TypeConverter &converter,
+ PatternBenefit benefit = 1);
/// For ReturnLike ops (except `return`), return True. If op is a `return` &&
/// returnOpAlwaysLegal is false, legalize op according to converter. Otherwise,
diff --git a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
index b6c8cdf2f495a..216401a80c9f8 100644
--- a/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
+++ b/mlir/lib/Dialect/Func/Transforms/FuncConversions.cpp
@@ -65,8 +65,10 @@ struct CallOpSignatureConversion : public OpConversionPattern<CallOp> {
} // namespace
void mlir::populateCallOpTypeConversionPattern(RewritePatternSet &patterns,
- const TypeConverter &converter) {
- patterns.add<CallOpSignatureConversion>(converter, patterns.getContext());
+ const TypeConverter &converter,
+ PatternBenefit benefit) {
+ patterns.add<CallOpSignatureConversion>(converter, patterns.getContext(),
+ benefit);
}
namespace {
@@ -81,8 +83,9 @@ class BranchOpInterfaceTypeConversion
BranchOpInterfaceTypeConversion(
const TypeConverter &typeConverter, MLIRContext *ctx,
- function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand)
- : OpInterfaceConversionPattern(typeConverter, ctx, /*benefit=*/1),
+ function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand,
+ PatternBenefit benefit)
+ : OpInterfaceConversionPattern(typeConverter, ctx, benefit),
shouldConvertBranchOperand(shouldConvertBranchOperand) {}
LogicalResult
@@ -135,9 +138,11 @@ class ReturnOpTypeConversion : public OpConversionPattern<ReturnOp> {
void mlir::populateBranchOpInterfaceTypeConversionPattern(
RewritePatternSet &patterns, const TypeConverter &typeConverter,
- function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand) {
+ function_ref<bool(BranchOpInterface, int)> shouldConvertBranchOperand,
+ PatternBenefit benefit) {
patterns.add<BranchOpInterfaceTypeConversion>(
- typeConverter, patterns.getContext(), shouldConvertBranchOperand);
+ typeConverter, patterns.getContext(), shouldConvertBranchOperand,
+ benefit);
}
bool mlir::isLegalForBranchOpInterfaceTypeConversionPattern(
@@ -157,8 +162,10 @@ bool mlir::isLegalForBranchOpInterfaceTypeConversionPattern(
}
void mlir::populateReturnOpTypeConversionPattern(
- RewritePatternSet &patterns, const TypeConverter &typeConverter) {
- patterns.add<ReturnOpTypeConversion>(typeConverter, patterns.getContext());
+ RewritePatternSet &patterns, const TypeConverter &typeConverter,
+ PatternBenefit benefit) {
+ patterns.add<ReturnOpTypeConversion>(typeConverter, patterns.getContext(),
+ benefit);
}
bool mlir::isLegalForReturnOpTypeConversionPattern(
|
adaab99
to
1708f01
Compare
chelini
approved these changes
Sep 21, 2025
ckoparkar
added a commit
to ckoparkar/llvm-project
that referenced
this pull request
Sep 23, 2025
* main: (1562 commits) Document Policy on supporting newer C++ standard in LLVM codebase (llvm#156823) [MLIR][Transform][SMT] Introduce transform.smt.constrain_params (llvm#159450) Reapply "[compiler-rt] Remove %T from shared object substitutions (llvm#155302)" [NFC] [IndVarSimplify] Add non-overflowing usub test (llvm#159683) [Github] Remove separate tools checkout from pr-code workflows (llvm#159967) [clang] fix using enum redecl in template regression (llvm#159996) [DAG] Skip `mstore` combine for `<1 x ty>` vectors (llvm#159915) [mlir] Expose optional `PatternBenefit` to `func` populate functions (NFC) (llvm#159986) [LV] Set correct costs for interleave group members. [clang] ast-dump: use template pattern for `instantiated_from` (llvm#159952) [ARM] ha-alignstack-call.ll - regenerate test checks (llvm#159988) [LLD][MachO] Silence warning when building with MSVC [llvm][Analysis] Silence warning when building with MSVC [LV] Skip select cost for invariant divisors in legacy cost model. [Clang] Fix an error-recovery crash after d1a80de (llvm#159976) [VPlanPatternMatch] Introduce m_ConstantInt (llvm#159558) [GlobalISel] Add G_ABS computeKnownBits (llvm#154413) [gn build] Port 4cabd1e Reland "[clangd] Add feature modules registry" (llvm#154836) [LV] Also handle non-uniform scalarized loads when processing AddrDefs. ...
SeongjaeP
pushed a commit
to SeongjaeP/llvm-project
that referenced
this pull request
Sep 23, 2025
…(NFC) (llvm#159986) Pattern benefit allows users to give priority to a pattern.
YixingZhang007
pushed a commit
to YixingZhang007/llvm-project
that referenced
this pull request
Sep 27, 2025
…(NFC) (llvm#159986) Pattern benefit allows users to give priority to a pattern.
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.