From b596ecdd574e3ec717f71950370d2f58ae44296f Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Tue, 2 Jun 2020 12:49:45 +0200 Subject: [PATCH] [mlir] Toy tutorial: avoid erasing and then re-creating loop terminators The lower-to-affine-loops pass in chapters 5-7 of the Toy tutorial has been creating affine loops, erasing their terminator and creating it anew using a PatternRewriter instance to work around the fact that implicit terminators were created without notifying the rewriter. Now that has been fixed in 3ccf4a5bd109, remove the code erasing and re-creating the terminators and rely on the default ones. --- mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp | 7 +------ mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp | 7 +------ mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp | 7 +------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp index 0514d8f6624b..ffcb0e2c014f 100644 --- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp @@ -72,14 +72,9 @@ static void lowerOpToLoops(Operation *op, ArrayRef operands, SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - 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 - // beginning of the loop. - rewriter.setInsertionPointToStart(loop.getBody()); - rewriter.create(loc); + // Update the rewriter insertion point to the beginning of the loop. rewriter.setInsertionPointToStart(loop.getBody()); } diff --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp index e7dceea44226..2c0482203a89 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp @@ -72,14 +72,9 @@ static void lowerOpToLoops(Operation *op, ArrayRef operands, SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - 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 - // beginning of the loop. - rewriter.setInsertionPointToStart(loop.getBody()); - rewriter.create(loc); + // Update the rewriter insertion point to the beginning of the loop. rewriter.setInsertionPointToStart(loop.getBody()); } diff --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp index 0514d8f6624b..ffcb0e2c014f 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp @@ -72,14 +72,9 @@ static void lowerOpToLoops(Operation *op, ArrayRef operands, SmallVector loopIvs; for (auto dim : tensorType.getShape()) { auto loop = rewriter.create(loc, /*lb=*/0, dim, /*step=*/1); - 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 - // beginning of the loop. - rewriter.setInsertionPointToStart(loop.getBody()); - rewriter.create(loc); + // Update the rewriter insertion point to the beginning of the loop. rewriter.setInsertionPointToStart(loop.getBody()); }