From 3d3db60ed7c3161f8265086e33f9944adba4a6b9 Mon Sep 17 00:00:00 2001 From: Victor Perez 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 --- 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 4b50a0aec945c..9abbef7d554b9 100644 --- a/mlir/include/mlir/IR/Block.h +++ b/mlir/include/mlir/IR/Block.h @@ -215,7 +215,7 @@ class Block : public IRObjectWithUseList, 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 dc004cd14dc0f..23284e14461d8 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 029864d9ea47b..62fd119ec43ab 100644 --- a/mlir/lib/IR/Block.cpp +++ b/mlir/lib/IR/Block.cpp @@ -236,12 +236,12 @@ void Block::eraseArguments(function_ref 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(); } From 2ed0a7ff5caec1e2ea2c86d80db4582c1c9cdebd Mon Sep 17 00:00:00 2001 From: Victor Perez 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 9abbef7d554b9..3d00c405ead37 100644 --- a/mlir/include/mlir/IR/Block.h +++ b/mlir/include/mlir/IR/Block.h @@ -211,10 +211,10 @@ class Block : public IRObjectWithUseList, //===--------------------------------------------------------------------===// /// 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 62fd119ec43ab..82ea303cf0171 100644 --- a/mlir/lib/IR/Block.cpp +++ b/mlir/lib/IR/Block.cpp @@ -234,13 +234,13 @@ void Block::eraseArguments(function_ref 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(); }