//===- BubbleUpExtractSlice.cpp - bubble up tensor.extract_slice ----------===// // // 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 transforms linalg.<op> + // tensor.extract_slice into tensor.extract_slice + linalg.<op> to reduce // the computation for the linalg op. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arith/Utils/Utils.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" #include "mlir/Dialect/Linalg/Passes.h" #include "mlir/Dialect/Linalg/Transforms/Transforms.h" #include "mlir/Dialect/Linalg/Utils/Utils.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" usingnamespacemlir; usingnamespacemlir::linalg; namespace { /// Bubble up extract_slice above Linalg operation. /// /// A sequence of operations /// /// ```mlir /// %0 = linalg.<op> ... arg0, arg1, ... /// %1 = tensor.extract_slice %0 ... /// ``` /// /// can be replaced with /// /// ```mlir /// %0 = tensor.extract_slice %arg0 /// %1 = tensor.extract_slice %arg1 /// %2 = linalg.<op> ... %0, %1, ... /// ``` /// /// This results in the reduce computation of the linalg operation. /// struct BubbleUpExtractSliceOpPattern : OpRewritePattern<tensor::ExtractSliceOp> { … }; } // namespace void mlir::linalg::populateBubbleUpExtractSliceOpPatterns( RewritePatternSet &patterns) { … }