diff --git a/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp @@ -89,24 +89,11 @@ genericOp.iterator_types(), genericOp.docAttr(), genericOp.library_callAttr()); - // Create a new block in the region of the new Generic Op. - Block *oldBlock = genericOp.getBody(); - Region &newRegion = newGenericOp.region(); - Block *newBlock = rewriter.createBlock(&newRegion, newRegion.begin(), - oldBlock->getArgumentTypes()); - - // Clone the body of the old block to the new block. - BlockAndValueMapping mapping; - mapping.map(oldBlock->getArguments(), newBlock->getArguments()); - - OpBuilder::InsertionGuard guard(rewriter); - rewriter.setInsertionPointToEnd(newBlock); - for (auto &op : oldBlock->getOperations()) { - Operation *clonedOp = rewriter.clone(op, mapping); - mapping.map(op.getResults(), clonedOp->getResults()); - } + rewriter.inlineRegionBefore(genericOp.getRegion(), newGenericOp.region(), + newGenericOp.region().begin()); return newGenericOp; } + assert(linalgOp->getNumRegions() == 0); SmallVector newOperands = inputs; newOperands.append(outputs.begin(), outputs.end()); return linalgOp.clone(rewriter, linalgOp.getLoc(), @@ -344,9 +331,8 @@ BufferizeTypeConverter typeConverter; // Mark all Standard operations legal. - target.addLegalDialect(); + target.addLegalDialect(); target.addIllegalOp();