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 @@ -188,13 +188,21 @@ setInsertionPoint(op); } - explicit OpBuilder(Block *block) : OpBuilder(block, block->end()) {} - OpBuilder(Block *block, Block::iterator insertPoint) : OpBuilder(block->getParent()) { setInsertionPoint(block, insertPoint); } + /// Create a builder and set the insertion point to the specified location in + /// the Block. + static OpBuilder atBlockBegin(Block *block) { + return OpBuilder(block, block->begin()); + } + + static OpBuilder atBlockEnd(Block *block) { + return OpBuilder(block, block->end()); + } + /// This class represents a saved insertion point. class InsertPoint { public: diff --git a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVOps.cpp @@ -2076,7 +2076,7 @@ body().push_back(new Block()); auto *mergeBlock = new Block(); body().push_back(mergeBlock); - OpBuilder builder(mergeBlock); + OpBuilder builder = OpBuilder::atBlockEnd(mergeBlock); // Add a spv._merge op into the merge block. builder.create(getLoc()); @@ -2373,7 +2373,7 @@ assert(body().empty() && "entry and merge block already exist"); auto *mergeBlock = new Block(); body().push_back(mergeBlock); - OpBuilder builder(mergeBlock); + OpBuilder builder = OpBuilder::atBlockEnd(mergeBlock); // Add a spv._merge op into the merge block. builder.create(getLoc());