[llvm-branch-commits] [mlir] [mlir][IR][NFC] Make `replaceAllUsesWith` non-templatized (PR #84722)

Matthias Springer via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Mar 10 22:24:01 PDT 2024


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/84722

Turn `RewriterBase::replaceAllUsesWith` into a non-templatized implementation, so that it can be made virtual and be overridden in the `ConversionPatternRewriter` in a subsequent change.

This change is in preparation of adding dialect conversion support for `replaceAllUsesWith`.

>From e70c754e4a0f9b16fa6588e2d398dcaf0e7e995f Mon Sep 17 00:00:00 2001
From: Matthias Springer <springerm at google.com>
Date: Mon, 11 Mar 2024 05:22:26 +0000
Subject: [PATCH] [mlir][IR][NFC] Make `replaceAllUsesWith` non-templatized

Turn `RewriterBase::replaceAllUsesWith` into a non-templatized implementation, so that it can be made virtual and be overridden in the `ConversionPatternRewriter` in a subsequent change.

This change is in preparation of adding dialect conversion support for `replaceAllUsesWith`.
---
 mlir/include/mlir/IR/PatternMatch.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index c1408c3f90a53b..2be1e2e2b40276 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -615,11 +615,13 @@ class RewriterBase : public OpBuilder {
   /// Find uses of `from` and replace them with `to`. Also notify the listener
   /// about every in-place op modification (for every use that was replaced).
   void replaceAllUsesWith(Value from, Value to) {
-    return replaceAllUsesWith(from.getImpl(), to);
+    for (OpOperand &operand : llvm::make_early_inc_range(from.getUses())) {
+      Operation *op = operand.getOwner();
+      modifyOpInPlace(op, [&]() { operand.set(to); });
+    }
   }
-  template <typename OperandType, typename ValueT>
-  void replaceAllUsesWith(IRObjectWithUseList<OperandType> *from, ValueT &&to) {
-    for (OperandType &operand : llvm::make_early_inc_range(from->getUses())) {
+  void replaceAllUsesWith(Block *from, Block *to) {
+    for (BlockOperand &operand : llvm::make_early_inc_range(from->getUses())) {
       Operation *op = operand.getOwner();
       modifyOpInPlace(op, [&]() { operand.set(to); });
     }



More information about the llvm-branch-commits mailing list