[Mlir-commits] [mlir] [MLIR][IR] Rename `Block::hasTerminator` to `mightHaveTerminator` (PR #66870)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Sep 20 13:05:43 PDT 2023


https://github.com/victor-eds updated https://github.com/llvm/llvm-project/pull/66870

>From 3d3db60ed7c3161f8265086e33f9944adba4a6b9 Mon Sep 17 00:00:00 2001
From: Victor Perez <victor.perez at codeplay.com>
Date: Wed, 20 Sep 2023 09:06:37 +0100
Subject: [PATCH 1/2] [MLIR][IR] Rename `Block::hasTerminator` to
 `mightHaveTerminator()`

This `Block` member function introduced in
87d77d3cfb5049b3b3714f95b2e48bbc78d8c5f9 may be misleading to users as
the last operation in the block might have not been registered, so
there would be no way to ensure that is a terminator.

Signed-off-by: Victor Perez <victor.perez at codeplay.com>
---
 mlir/include/mlir/IR/Block.h                   | 2 +-
 mlir/lib/Dialect/Transform/IR/TransformOps.cpp | 2 +-
 mlir/lib/IR/Block.cpp                          | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index 4b50a0aec945c65..9abbef7d554b94f 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -215,7 +215,7 @@ class Block : public IRObjectWithUseList<BlockOperand>,
   Operation *getTerminator();
 
   /// Check whether this block has a terminator.
-  bool hasTerminator();
+  bool mightHaveTerminator();
 
   //===--------------------------------------------------------------------===//
   // Predecessors and successors.
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index dc004cd14dc0fbf..23284e14461d8f2 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -2188,7 +2188,7 @@ LogicalResult transform::SequenceOp::verify() {
     }
   }
 
-  if (!getBodyBlock()->hasTerminator())
+  if (!getBodyBlock()->mightHaveTerminator())
     return emitOpError() << "expects to have a terminator in the body";
 
   if (getBodyBlock()->getTerminator()->getOperandTypes() !=
diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp
index 029864d9ea47b98..62fd119ec43ab98 100644
--- a/mlir/lib/IR/Block.cpp
+++ b/mlir/lib/IR/Block.cpp
@@ -236,12 +236,12 @@ void Block::eraseArguments(function_ref<bool(BlockArgument)> shouldEraseFn) {
 /// Get the terminator operation of this block. This function asserts that
 /// the block has a valid terminator operation.
 Operation *Block::getTerminator() {
-  assert(hasTerminator());
+  assert(mightHaveTerminator());
   return &back();
 }
 
 /// Check whether this block has a terminator.
-bool Block::hasTerminator() {
+bool Block::mightHaveTerminator() {
   return !empty() && back().mightHaveTrait<OpTrait::IsTerminator>();
 }
 

>From 2ed0a7ff5caec1e2ea2c86d80db4582c1c9cdebd Mon Sep 17 00:00:00 2001
From: Victor Perez <victor.perez at codeplay.com>
Date: Wed, 20 Sep 2023 21:05:27 +0100
Subject: [PATCH 2/2] Update comments

---
 mlir/include/mlir/IR/Block.h | 4 ++--
 mlir/lib/IR/Block.cpp        | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index 9abbef7d554b94f..3d00c405ead374b 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -211,10 +211,10 @@ class Block : public IRObjectWithUseList<BlockOperand>,
   //===--------------------------------------------------------------------===//
 
   /// Get the terminator operation of this block. This function asserts that
-  /// the block has a valid terminator operation.
+  /// the block might have a valid terminator operation.
   Operation *getTerminator();
 
-  /// Check whether this block has a terminator.
+  /// Check whether this block might have a terminator.
   bool mightHaveTerminator();
 
   //===--------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp
index 62fd119ec43ab98..82ea303cf0171f3 100644
--- a/mlir/lib/IR/Block.cpp
+++ b/mlir/lib/IR/Block.cpp
@@ -234,13 +234,13 @@ void Block::eraseArguments(function_ref<bool(BlockArgument)> shouldEraseFn) {
 //===----------------------------------------------------------------------===//
 
 /// Get the terminator operation of this block. This function asserts that
-/// the block has a valid terminator operation.
+/// the block might have a valid terminator operation.
 Operation *Block::getTerminator() {
   assert(mightHaveTerminator());
   return &back();
 }
 
-/// Check whether this block has a terminator.
+/// Check whether this block might have a terminator.
 bool Block::mightHaveTerminator() {
   return !empty() && back().mightHaveTrait<OpTrait::IsTerminator>();
 }



More information about the Mlir-commits mailing list