diff --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp --- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp @@ -72,7 +72,8 @@ SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - loop.getBody()->clear(); + for (Operation &nested : *loop.getBody()) + rewriter.eraseOp(&nested); loopIvs.push_back(loop.getInductionVar()); // Terminate the loop body and update the rewriter insertion point to the diff --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp --- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp @@ -72,7 +72,8 @@ SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - loop.getBody()->clear(); + for (Operation &nested : *loop.getBody()) + rewriter.eraseOp(&nested); loopIvs.push_back(loop.getInductionVar()); // Terminate the loop body and update the rewriter insertion point to the diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp --- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp @@ -69,7 +69,8 @@ auto step = rewriter.create(loc, 1); auto loop = rewriter.create(loc, lowerBound, upperBound, step); - loop.getBody()->clear(); + for (Operation &nested : *loop.getBody()) + rewriter.eraseOp(&nested); loopIvs.push_back(loop.getInductionVar()); // Terminate the loop body. diff --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp --- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp @@ -72,7 +72,8 @@ SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - loop.getBody()->clear(); + for (Operation &nested : *loop.getBody()) + rewriter.eraseOp(&nested); loopIvs.push_back(loop.getInductionVar()); // Terminate the loop body and update the rewriter insertion point to the diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp --- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp @@ -69,7 +69,8 @@ auto step = rewriter.create(loc, 1); auto loop = rewriter.create(loc, lowerBound, upperBound, step); - loop.getBody()->clear(); + for (Operation &nested : *loop.getBody()) + rewriter.eraseOp(&nested); loopIvs.push_back(loop.getInductionVar()); // Terminate the loop body. diff --git a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp --- a/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp +++ b/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp @@ -350,7 +350,7 @@ Value upperBound = lowerAffineUpperBound(op, rewriter); Value step = rewriter.create(loc, op.getStep()); auto f = rewriter.create(loc, lowerBound, upperBound, step); - f.region().getBlocks().clear(); + rewriter.eraseBlock(f.getBody()); rewriter.inlineRegionBefore(op.region(), f.region(), f.region().end()); rewriter.eraseOp(op); return success(); @@ -396,10 +396,10 @@ bool hasElseRegion = !op.elseRegion().empty(); auto ifOp = rewriter.create(loc, cond, hasElseRegion); rewriter.inlineRegionBefore(op.thenRegion(), &ifOp.thenRegion().back()); - ifOp.thenRegion().back().erase(); + rewriter.eraseBlock(&ifOp.thenRegion().back()); if (hasElseRegion) { rewriter.inlineRegionBefore(op.elseRegion(), &ifOp.elseRegion().back()); - ifOp.elseRegion().back().erase(); + rewriter.eraseBlock(&ifOp.elseRegion().back()); } // Ok, we're done! diff --git a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/ConvertGPUToSPIRV.cpp @@ -419,7 +419,7 @@ // The spv.module build method adds a block with a terminator. Remove that // block. The terminator of the module op in the remaining block will be // legalized later. - spvModuleRegion.back().erase(); + rewriter.eraseBlock(&spvModuleRegion.back()); rewriter.eraseOp(moduleOp); return success(); }