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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Nov 15 12:17:52 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Akash Banerjee (TIFitis)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/72430.diff


2 Files Affected:

- (modified) mlir/include/mlir/IR/Value.h (+2-2) 
- (modified) mlir/lib/IR/Value.cpp (+3-3) 


``````````diff
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;
   });

``````````

</details>


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


More information about the Mlir-commits mailing list