[Mlir-commits] [mlir] [mlir][IR] Insert operations before `SingleBlock`'s terminator (PR #65959)
Matthias Springer
llvmlistbot at llvm.org
Sun Sep 17 03:24:31 PDT 2023
================
@@ -932,6 +932,10 @@ struct SingleBlock : public TraitBase<ConcreteType, SingleBlock> {
}
template <typename OpT = ConcreteType>
enable_if_single_region<OpT> insert(Block::iterator insertPt, Operation *op) {
+ Block *body = getBody();
+ // Insert op before the block's terminator if it has one
+ if (insertPt == body->end() && body->hasTerminator())
+ insertPt = Block::iterator(body->getTerminator());
----------------
matthias-springer wrote:
Before 0ac21e654f194a0f7c9f5afe42e11924c546f89e this was actually (somewhat?) safe. `SingleBlockImplicitTerminator<OpTy>` must be instantiated with an op type, which means that the terminator op must be known (registered?).
I'm wondering if it's better to just always insert at the end of the block. It would simplify the API: no special handling for terminators, it behaves like a `vector::push_back`.
https://github.com/llvm/llvm-project/pull/65959
More information about the Mlir-commits
mailing list