Skip to content

Commit b613a54

Browse files
[mlir][IR][NFC] Cleanup insertion point API usage (#115415)
Use `setInsertionPointToStart` / `setInsertionPointToEnd` when possible.
1 parent 694719a commit b613a54

File tree

11 files changed

+13
-15
lines changed

11 files changed

+13
-15
lines changed

mlir/include/mlir/IR/Builders.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class OpBuilder : public Builder {
225225
explicit OpBuilder(Region *region, Listener *listener = nullptr)
226226
: OpBuilder(region->getContext(), listener) {
227227
if (!region->empty())
228-
setInsertionPoint(&region->front(), region->front().begin());
228+
setInsertionPointToStart(&region->front());
229229
}
230230
explicit OpBuilder(Region &region, Listener *listener = nullptr)
231231
: OpBuilder(&region, listener) {}

mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void GPUToSPIRVPass::runOnOperation() {
7676
// module inside the original GPU module, as that's the expectaion of the
7777
// normal GPU compilation pipeline.
7878
if (targetEnvSupportsKernelCapability(moduleOp)) {
79-
builder.setInsertionPoint(moduleOp.getBody(),
80-
moduleOp.getBody()->begin());
79+
builder.setInsertionPointToStart(moduleOp.getBody());
8180
} else {
8281
builder.setInsertionPoint(moduleOp.getOperation());
8382
}

mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ class ExecutionModePattern
706706
Block *block = rewriter.createBlock(&region);
707707

708708
// Initialize the struct and set the execution mode value.
709-
rewriter.setInsertionPoint(block, block->begin());
709+
rewriter.setInsertionPointToStart(block);
710710
Value structValue = rewriter.create<LLVM::UndefOp>(loc, structType);
711711
Value executionMode = rewriter.create<LLVM::ConstantOp>(
712712
loc, llvmI32Type,

mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ handleInlinedAllocas(Operation *call,
115115
stackPtr = builder.create<LLVM::StackSaveOp>(
116116
call->getLoc(), LLVM::LLVMPointerType::get(call->getContext()));
117117
}
118-
builder.setInsertionPoint(callerEntryBlock, callerEntryBlock->begin());
118+
builder.setInsertionPointToStart(callerEntryBlock);
119119
for (auto &[allocaOp, arraySize, shouldInsertLifetime] : allocasToMove) {
120120
auto newConstant = builder.create<LLVM::ConstantOp>(
121121
allocaOp->getLoc(), allocaOp.getArraySize().getType(), arraySize);

mlir/lib/Dialect/Linalg/Transforms/Promotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static std::optional<Value> allocateSubviewGPUMemoryInAddressSpace(
451451
shape.push_back(value.getSExtValue());
452452
}
453453

454-
builder.setInsertionPoint(&funcOp.front(), funcOp.front().begin());
454+
builder.setInsertionPointToStart(&funcOp.front());
455455
auto type = MemRefType::get(
456456
shape, subview.getType().getElementType(), MemRefLayoutAttrInterface{},
457457
gpu::AddressSpaceAttr::get(builder.getContext(), addressSpace));

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ mlir::scf::replaceAndCastForOpIterArg(RewriterBase &rewriter, scf::ForOp forOp,
805805
// 3. Inject an incoming cast op at the beginning of the block for the bbArg
806806
// corresponding to the `replacement` value.
807807
OpBuilder::InsertionGuard g(rewriter);
808-
rewriter.setInsertionPoint(&newBlock, newBlock.begin());
808+
rewriter.setInsertionPointToStart(&newBlock);
809809
BlockArgument newRegionIterArg = newForOp.getTiedLoopRegionIterArg(
810810
&newForOp->getOpOperand(operand.getOperandNumber()));
811811
Value castIn = castFn(rewriter, newForOp.getLoc(), oldType, newRegionIterArg);

mlir/lib/Dialect/SCF/Utils/Utils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ FailureOr<UnrolledLoopInfo> mlir::loopUnrollByFactor(
456456
// Create epilogue clean up loop starting at 'upperBoundUnrolled'.
457457
if (generateEpilogueLoop) {
458458
OpBuilder epilogueBuilder(forOp->getContext());
459-
epilogueBuilder.setInsertionPoint(forOp->getBlock(),
460-
std::next(Block::iterator(forOp)));
459+
epilogueBuilder.setInsertionPointAfter(forOp);
461460
auto epilogueForOp = cast<scf::ForOp>(epilogueBuilder.clone(*forOp));
462461
epilogueForOp.setLowerBound(upperBoundUnrolled);
463462

mlir/lib/Dialect/Shape/Transforms/OutlineShapeComputation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ createFuncFromCluster(OpBuilder &b, const SmallVector<Operation *, 8> &cluster,
7171
: b.getFunctionType(ValueRange(inputs).getTypes(), shape.getType());
7272
shape::FuncOp fnOp = b.create<shape::FuncOp>(loc, fnName, fnType);
7373
Block *block = fnOp.addEntryBlock();
74-
b.setInsertionPoint(block, block->end());
74+
b.setInsertionPointToEnd(block);
7575
IRMapping bvm;
7676
if (cluster.empty()) {
7777
bvm.map(shape, fnOp.getArgument(0));

mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ struct WarpOpScfForOp : public OpRewritePattern<WarpExecuteOnLane0Op> {
17201720
auto newForOp = rewriter.create<scf::ForOp>(
17211721
forOp.getLoc(), forOp.getLowerBound(), forOp.getUpperBound(),
17221722
forOp.getStep(), newOperands);
1723-
rewriter.setInsertionPoint(newForOp.getBody(), newForOp.getBody()->begin());
1723+
rewriter.setInsertionPointToStart(newForOp.getBody());
17241724

17251725
SmallVector<Value> warpInput(newForOp.getRegionIterArgs().begin(),
17261726
newForOp.getRegionIterArgs().end());
@@ -1747,7 +1747,7 @@ struct WarpOpScfForOp : public OpRewritePattern<WarpExecuteOnLane0Op> {
17471747
yieldOperands.push_back(operand);
17481748
rewriter.eraseOp(forOp.getBody()->getTerminator());
17491749
rewriter.mergeBlocks(forOp.getBody(), innerWarp.getBody(), argMapping);
1750-
rewriter.setInsertionPoint(innerWarp.getBody(), innerWarp.getBody()->end());
1750+
rewriter.setInsertionPointToEnd(innerWarp.getBody());
17511751
rewriter.create<vector::YieldOp>(innerWarp.getLoc(), yieldOperands);
17521752
rewriter.setInsertionPointAfter(innerWarp);
17531753
if (!innerWarp.getResults().empty())

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
20412041

20422042
// Insert the function at the end of the module.
20432043
OpBuilder::InsertionGuard guard(builder);
2044-
builder.setInsertionPoint(mlirModule.getBody(), mlirModule.getBody()->end());
2044+
builder.setInsertionPointToEnd(mlirModule.getBody());
20452045

20462046
Location loc = debugImporter->translateFuncLocation(func);
20472047
LLVMFuncOp funcOp = builder.create<LLVMFuncOp>(

mlir/lib/Transforms/Utils/FoldUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Value OperationFolder::getOrCreateConstant(Block *block, Dialect *dialect,
204204
// Find an insertion point for the constant.
205205
auto *insertRegion = getInsertionRegion(interfaces, block);
206206
auto &entry = insertRegion->front();
207-
rewriter.setInsertionPoint(&entry, entry.begin());
207+
rewriter.setInsertionPointToStart(&entry);
208208

209209
// Get the constant map for the insertion region of this operation.
210210
// Use erased location since the op is being built at the front of block.
@@ -242,7 +242,7 @@ OperationFolder::processFoldResults(Operation *op,
242242
// insertion region.
243243
auto *insertRegion = getInsertionRegion(interfaces, op->getBlock());
244244
auto &entry = insertRegion->front();
245-
rewriter.setInsertionPoint(&entry, entry.begin());
245+
rewriter.setInsertionPointToStart(&entry);
246246

247247
// Get the constant map for the insertion region of this operation.
248248
auto &uniquedConstants = foldScopes[insertRegion];

0 commit comments

Comments
 (0)