diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -204,6 +204,7 @@ : OpBuilder(block->getParent()->getContext(), listener) { setInsertionPoint(block, insertPoint); } + virtual ~OpBuilder() = default; /// Create a builder and set the insertion point to before the first operation /// in the block but still inside the block. @@ -474,6 +475,9 @@ return cast(cloneWithoutRegions(*op.getOperation())); } + /// This method erases an operation that is known to have no uses. + virtual void eraseOp(Operation *op); + private: /// The current block this builder is inserting into. Block *block = nullptr; diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -274,7 +274,7 @@ } /// This method erases an operation that is known to have no uses. - virtual void eraseOp(Operation *op); + virtual void eraseOp(Operation *op) override; /// This method erases all operations in a block. virtual void eraseBlock(Block *block); diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp --- a/mlir/lib/IR/Builders.cpp +++ b/mlir/lib/IR/Builders.cpp @@ -480,3 +480,8 @@ BlockAndValueMapping mapper; return clone(op, mapper); } + +void OpBuilder::eraseOp(Operation *op) { + assert(op->use_empty() && "expected 'op' to have no uses"); + op->erase(); +}