[Mlir-commits] [mlir] 185f5fd - [mlir] Enable perfect forwarding for `addWithLabel` and `insert` (NFC) (#172939)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Dec 21 17:33:30 PST 2025


Author: Longsheng Mou
Date: 2025-12-22T09:33:25+08:00
New Revision: 185f5fd5ce4c65116ca8cf6df467a682ef090499

URL: https://github.com/llvm/llvm-project/commit/185f5fd5ce4c65116ca8cf6df467a682ef090499
DIFF: https://github.com/llvm/llvm-project/commit/185f5fd5ce4c65116ca8cf6df467a682ef090499.diff

LOG: [mlir] Enable perfect forwarding for `addWithLabel` and `insert` (NFC) (#172939)

This PR adds perfect forwarding support to
`RewritePatternSet::addWithLabel` and `RewritePatternSet::insert`,
preventing unnecessary copies when forwarding arguments, consistent with
`RewritePatternSet::add`.

Added: 
    

Modified: 
    mlir/include/mlir/IR/PatternMatch.h

Removed: 
    


################################################################################
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;
   }
 


        


More information about the Mlir-commits mailing list