Skip to content

Commit c2c125f

Browse files
address comments
1 parent 3759dbf commit c2c125f

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

mlir/include/mlir/IR/PatternMatch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ class RewriterBase : public OpBuilder {
504504
}
505505

506506
/// This method erases an operation that is known to have no uses.
507+
///
508+
/// If the current insertion point is before the erased operation, it is
509+
/// adjusted to the following operation (or the end of the block). If the
510+
/// current insertion point is within the erased operation, the insertion
511+
/// point is left in an invalid state.
507512
virtual void eraseOp(Operation *op);
508513

509514
/// This method erases all operations in a block.

mlir/lib/IR/PatternMatch.cpp

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,44 +152,17 @@ void RewriterBase::replaceOp(Operation *op, Operation *newOp) {
152152
eraseOp(op);
153153
}
154154

155-
/// Returns the given block iterator if it lies within the block `b`.
156-
/// Otherwise, otherwise finds the ancestor of the given block iterator that
157-
/// lies within `b`. Returns and "empty" iterator if the latter fails.
158-
///
159-
/// Note: This is a variant of Block::findAncestorOpInBlock that operates on
160-
/// block iterators instead of ops.
161-
static std::pair<Block *, Block::iterator>
162-
findAncestorIteratorInBlock(Block *b, Block *itBlock, Block::iterator it) {
163-
// Case 1: The iterator lies within the block.
164-
if (itBlock == b)
165-
return std::make_pair(itBlock, it);
166-
167-
// Otherwise: Find ancestor iterator. Bail if we run out of parent ops.
168-
Operation *parentOp = itBlock->getParentOp();
169-
if (!parentOp)
170-
return std::make_pair(static_cast<Block *>(nullptr), Block::iterator());
171-
Operation *op = b->findAncestorOpInBlock(*parentOp);
172-
if (!op)
173-
return std::make_pair(static_cast<Block *>(nullptr), Block::iterator());
174-
return std::make_pair(op->getBlock(), op->getIterator());
175-
}
176-
177155
/// This method erases an operation that is known to have no uses. The uses of
178156
/// the given operation *must* be known to be dead.
179157
void RewriterBase::eraseOp(Operation *op) {
180158
assert(op->use_empty() && "expected 'op' to have no uses");
181159
auto *rewriteListener = dyn_cast_if_present<Listener>(listener);
182160

183-
// If the current insertion point is before/within the erased operation, we
184-
// need to adjust the insertion point to be after the operation.
185-
if (getInsertionBlock()) {
186-
Block *insertionBlock;
187-
Block::iterator insertionPoint;
188-
std::tie(insertionBlock, insertionPoint) = findAncestorIteratorInBlock(
189-
op->getBlock(), getInsertionBlock(), getInsertionPoint());
190-
if (insertionBlock && insertionPoint == op->getIterator())
191-
setInsertionPointAfter(op);
192-
}
161+
// If the current insertion point is before the erased operation, we adjust
162+
// the insertion point to be after the operation.
163+
if (getInsertionBlock() == op->getBlock() &&
164+
getInsertionPoint() == op->getIterator())
165+
setInsertionPointAfter(op);
193166

194167
// Fast path: If no listener is attached, the op can be dropped in one go.
195168
if (!rewriteListener) {

0 commit comments

Comments
 (0)