//===- FusePadOpWithLinalgProducer.cpp ---- Fuse pad with linalg producer -===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements patterns that fuses a linalg.generic -> tensor.pad op // chain into a tensor.extract_slice -> linalg.generic -> tensor.insert_slice // op chain. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Linalg/Transforms/Transforms.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" usingnamespacemlir; namespace { /// A sequence of operations /// /// ```mlir /// %0 = linalg. ... /// %1 = tensor.pad %0 ... /// ``` /// /// can be replaced with /// /// ```mlir /// %0 = linalg.fill /// %1 = tensor.extract_slice %0 ... /// %2 = linalg. .... outs(..., %1, ....) .... /// %3 = tensor.insert_slice %2 into %1 ... /// ``` /// /// if the `linalg.generic` has all parallel iterator types. struct FusePadOp : OpRewritePattern<tensor::PadOp> { … }; } // namespace void mlir::linalg::populateFuseTensorPadWithProducerLinalgOpPatterns( RewritePatternSet &patterns) { … }