[Mlir-commits] [mlir] [NFC] Simplify the tiling implementation using cloning. (PR #72178)
Nicolas Vasilache
llvmlistbot at llvm.org
Wed Nov 15 04:34:09 PST 2023
================
@@ -544,17 +554,56 @@ mlir::scf::tileAndFuseProducerOfSlice(RewriterBase &rewriter,
loops);
if (!fusableProducer)
return std::nullopt;
+ unsigned resultNumber = fusableProducer.getResultNumber();
- // 2. Generate the tiled implementation of the producer of the source
OpBuilder::InsertionGuard g(rewriter);
rewriter.setInsertionPoint(candidateSliceOp);
+
+ // 2. Clone the fused producer
+ // 2a. Compute the destination operands to use for the cloned operation.
+ SmallVector<Value> origDestinationTensors, clonedOpDestinationTensors;
+ Operation *fusableProducerOp = fusableProducer.getOwner();
+ if (isa<DestinationStyleOpInterface>(fusableProducerOp)) {
+ if (failed(tensor::getOrCreateDestinations(
+ rewriter, fusableProducerOp->getLoc(), fusableProducerOp,
+ origDestinationTensors))) {
+ return std::nullopt;
+ }
+ }
+ clonedOpDestinationTensors = origDestinationTensors;
+ if (destinationInitArg &&
+ isa<DestinationStyleOpInterface>(fusableProducerOp)) {
+ // 2b. If the producer is also destination style, then to maintain the
+ // destination passing style, update the destination of the producer to be
+ // the source of the slice.
+ clonedOpDestinationTensors[resultNumber] = candidateSliceOp.getSource();
+ }
+ // 2c. Clone the fused producer.
+ Operation *clonedProducerOp = cloneOpAndUpdateDestinationArgs(
+ rewriter, fusableProducerOp, clonedOpDestinationTensors);
+ // 2d. Update the source of the candidateSlice to be the cloned producer.
+ // Easier to just clone the slice with different source since replacements
+ // and DCE of cloned ops becomes easier
+ SmallVector<Value> candidateSliceOpOperands =
+ llvm::to_vector(candidateSliceOp->getOperands());
+ candidateSliceOpOperands[0] = clonedProducerOp->getResult(resultNumber);
+ tensor::ExtractSliceOp clonedCandidateSliceOp =
+ mlir::clone(rewriter, candidateSliceOp,
----------------
nicolasvasilache wrote:
IANM, I see this going through OpBuilder::insert which uses the listener, so it seems fine to me.
https://github.com/llvm/llvm-project/pull/72178
More information about the Mlir-commits
mailing list