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

Longsheng Mou llvmlistbot at llvm.org
Thu Dec 18 18:13:16 PST 2025


https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/172939

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

>From e3d570a7f7a247c8812347b4729012335b9a062f Mon Sep 17 00:00:00 2001
From: Longsheng Mou <longshengmou at gmail.com>
Date: Fri, 19 Dec 2025 10:11:24 +0800
Subject: [PATCH] [mlir] Enable perfect forwarding for `addWithLabel` and
 `insert`

This PR adds perfect forwarding support to `RewritePatternSet::addWithLabel` and `RewritePatternSet::insert`, preventing unnecessary copies when forwarding arguments, consistent with `RewritePatternSet::add`.
---
 mlir/include/mlir/IR/PatternMatch.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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