[Mlir-commits] [mlir] [mlir] Enable perfect forwarding for `addWithLabel` and `insert` (PR #172939)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Dec 18 18:13:48 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Longsheng Mou (CoTinker)
<details>
<summary>Changes</summary>
This PR adds perfect forwarding support to `RewritePatternSet::addWithLabel` and `RewritePatternSet::insert`, preventing unnecessary copies when forwarding arguments, consistent with `RewritePatternSet::add`.
---
Full diff: https://github.com/llvm/llvm-project/pull/172939.diff
1 Files Affected:
- (modified) mlir/include/mlir/IR/PatternMatch.h (+6-2)
``````````diff
diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index 35f7290a235c2..1caab24ac7295 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -872,7 +872,9 @@ class RewritePatternSet {
ConstructorArgs &&...args) {
// The following expands a call to emplace_back for each of the pattern
// types 'Ts'.
- (addImpl<Ts>(debugLabels, arg, args...), ...);
+ (addImpl<Ts>(debugLabels, std::forward<ConstructorArg>(arg),
+ std::forward<ConstructorArgs>(args)...),
+ ...);
return *this;
}
@@ -938,7 +940,9 @@ class RewritePatternSet {
RewritePatternSet &insert(ConstructorArg &&arg, ConstructorArgs &&...args) {
// The following expands a call to emplace_back for each of the pattern
// types 'Ts'.
- (addImpl<Ts>(/*debugLabels=*/{}, arg, args...), ...);
+ (addImpl<Ts>(/*debugLabels=*/{}, std::forward<ConstructorArg>(arg),
+ std::forward<ConstructorArgs>(args)...),
+ ...);
return *this;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/172939
More information about the Mlir-commits
mailing list