[Mlir-commits] [mlir] [mlir][IR] Mark `getParentBlock()` and `getParentRegion()` as const (NFC) (PR #151915)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 4 01:11:47 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Longsheng Mou (CoTinker)

<details>
<summary>Changes</summary>

This PR marks `Value::getParentBlock()` and `Value::getParentRegion()` as `const` member functions. These methods do not modify the internal state of `Value` and are often used in read-only contexts. Marking them as `const` improves API clarity, allows greater flexibility in calling code.

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


2 Files Affected:

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


``````````diff
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index 4d6d89fa69a07..e773d199c3c23 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -131,10 +131,10 @@ class Value {
   void setLoc(Location loc);
 
   /// Return the Region in which this Value is defined.
-  Region *getParentRegion();
+  Region *getParentRegion() const;
 
   /// Return the Block in which this Value is defined.
-  Block *getParentBlock();
+  Block *getParentBlock() const;
 
   //===--------------------------------------------------------------------===//
   // UseLists
diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp
index fa550e4d5d5d0..2cffb962f8543 100644
--- a/mlir/lib/IR/Value.cpp
+++ b/mlir/lib/IR/Value.cpp
@@ -36,14 +36,14 @@ void Value::setLoc(Location loc) {
 }
 
 /// Return the Region in which this Value is defined.
-Region *Value::getParentRegion() {
+Region *Value::getParentRegion() const {
   if (auto *op = getDefiningOp())
     return op->getParentRegion();
   return llvm::cast<BlockArgument>(*this).getOwner()->getParent();
 }
 
 /// Return the Block in which this Value is defined.
-Block *Value::getParentBlock() {
+Block *Value::getParentBlock() const {
   if (Operation *op = getDefiningOp())
     return op->getBlock();
   return llvm::cast<BlockArgument>(*this).getOwner();

``````````

</details>


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


More information about the Mlir-commits mailing list