[Mlir-commits] [mlir] [MLIR] Add 'const' qualifier to some functions (PR #72430)

Akash Banerjee llvmlistbot at llvm.org
Wed Nov 15 12:17:24 PST 2023


https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/72430

Add '`const`' qualifier to `mlir::Value::isUsedOutsideOfBlock` and `mlir::Value::replaceUsesWithIf`.

>From 57f519eede06a0b6fc304f876961bee6d3a64969 Mon Sep 17 00:00:00 2001
From: Akash Banerjee <Akash.Banerjee at amd.com>
Date: Wed, 15 Nov 2023 20:14:42 +0000
Subject: [PATCH] [MLIR] Add 'const' qualifier to some functions

Add 'const' qualifier to mlir::Value::isUsedOutsideOfBlock and mlir::Value::replaceUsesWithIf.
---
 mlir/include/mlir/IR/Value.h | 4 ++--
 mlir/lib/IR/Value.cpp        | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index dbcc10d4f4df80e..08ea7c88607bcf1 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -182,10 +182,10 @@ class Value {
   /// Replace all uses of 'this' value with 'newValue' if the given callback
   /// returns true.
   void replaceUsesWithIf(Value newValue,
-                         function_ref<bool(OpOperand &)> shouldReplace);
+                         function_ref<bool(OpOperand &)> shouldReplace) const;
 
   /// Returns true if the value is used outside of the given block.
-  bool isUsedOutsideOfBlock(Block *block);
+  bool isUsedOutsideOfBlock(Block *block) const;
 
   /// Shuffle the use list order according to the provided indices. It is
   /// responsibility of the caller to make sure that the indices map the current
diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp
index 6b5195da5e47ba2..33a0ee5c3c519b1 100644
--- a/mlir/lib/IR/Value.cpp
+++ b/mlir/lib/IR/Value.cpp
@@ -79,15 +79,15 @@ void Value::replaceAllUsesExcept(Value newValue,
 
 /// Replace all uses of 'this' value with 'newValue' if the given callback
 /// returns true.
-void Value::replaceUsesWithIf(Value newValue,
-                              function_ref<bool(OpOperand &)> shouldReplace) {
+void Value::replaceUsesWithIf(
+    Value newValue, function_ref<bool(OpOperand &)> shouldReplace) const {
   for (OpOperand &use : llvm::make_early_inc_range(getUses()))
     if (shouldReplace(use))
       use.set(newValue);
 }
 
 /// Returns true if the value is used outside of the given block.
-bool Value::isUsedOutsideOfBlock(Block *block) {
+bool Value::isUsedOutsideOfBlock(Block *block) const {
   return llvm::any_of(getUsers(), [block](Operation *user) {
     return user->getBlock() != block;
   });



More information about the Mlir-commits mailing list