[Mlir-commits] [mlir] [MLIR][IR] Drop `bool Block::hasTerminator()` (PR #66870)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Sep 20 01:11:42 PDT 2023


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

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. As this also adds little to no value, this commit removes that function.

>From dc336f1ef6b0b08dbe13dbbac29f4fae49a98a42 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] [MLIR][IR] Drop `bool Block::hasTerminator()`

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. As this also
adds little to no value, this commit removes that function.
---
 mlir/include/mlir/IR/Block.h | 3 ---
 mlir/lib/IR/Block.cpp        | 7 +------
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h
index 4b50a0aec945c65..eb56290fbe77180 100644
--- a/mlir/include/mlir/IR/Block.h
+++ b/mlir/include/mlir/IR/Block.h
@@ -214,9 +214,6 @@ class Block : public IRObjectWithUseList<BlockOperand>,
   /// the block has a valid terminator operation.
   Operation *getTerminator();
 
-  /// Check whether this block has a terminator.
-  bool hasTerminator();
-
   //===--------------------------------------------------------------------===//
   // Predecessors and successors.
   //===--------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp
index 029864d9ea47b98..fbbba96468a2a19 100644
--- a/mlir/lib/IR/Block.cpp
+++ b/mlir/lib/IR/Block.cpp
@@ -236,15 +236,10 @@ 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(!empty() && back().mightHaveTrait<OpTrait::IsTerminator>());
   return &back();
 }
 
-/// Check whether this block has a terminator.
-bool Block::hasTerminator() {
-  return !empty() && back().mightHaveTrait<OpTrait::IsTerminator>();
-}
-
 // Indexed successor access.
 unsigned Block::getNumSuccessors() {
   return empty() ? 0 : back().getNumSuccessors();



More information about the Mlir-commits mailing list