[Mlir-commits] [mlir] [mlir][IR] Fix `Block::without_terminator` for `NoTerminator` ops (PR #154498)

Mehdi Amini llvmlistbot at llvm.org
Wed Aug 20 03:58:06 PDT 2025


================
@@ -251,6 +251,15 @@ bool Block::mightHaveTerminator() {
   return !empty() && back().mightHaveTrait<OpTrait::IsTerminator>();
 }
 
+/// Check whether this block has no terminator.
+bool Block::hasNoTerminator() {
+  if (empty())
+    return true;
+  if (!back().isRegistered())
+    return false;
+  return !back().hasTrait<OpTrait::IsTerminator>();
+}
----------------
joker-eph wrote:

Can we split the method with a private `hasNoTerminatorImpl()` 
so that in the header we can have the body be:

```
// Check whether this block has no terminator.
bool Block::hasNoTerminator() {
  if (empty())
    return true;
  return hasNoTerminator();
 }
```

Which will make it inlinable and redundant `if(empty()` checks be eliminated.

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


More information about the Mlir-commits mailing list