[Mlir-commits] [mlir] 0047b17 - [mlir][Linalg] NFC - Retire dead tilePadOp

Nicolas Vasilache llvmlistbot at llvm.org
Fri May 12 09:27:39 PDT 2023


Author: Nicolas Vasilache
Date: 2023-05-12T09:27:31-07:00
New Revision: 0047b1779eca0fc97e75eac4c3f99d161b1c28da

URL: https://github.com/llvm/llvm-project/commit/0047b1779eca0fc97e75eac4c3f99d161b1c28da
DIFF: https://github.com/llvm/llvm-project/commit/0047b1779eca0fc97e75eac4c3f99d161b1c28da.diff

LOG: [mlir][Linalg] NFC - Retire dead tilePadOp

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
    mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
index b538d0f0bf7a4..11cdaa2e4ad28 100644
--- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
+++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
@@ -1313,9 +1313,6 @@ void populateDecomposeConvolutionPatterns(RewritePatternSet &patterns,
 /// \see rewriteInIm2Col for more details.
 void populateConvertConv2DToImg2ColPatterns(RewritePatternSet &patterns);
 
-void populatePadTensorTilingPatterns(RewritePatternSet &patterns,
-                                     const LinalgTilingOptions &options);
-
 /// Populates `patterns` with patterns that vectorize tensor.pad.
 /// These patterns are meant to apply in a complementary fashion. Benefits
 /// are used to encode a certain ordering of pattern application. To avoid

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
index 57798fc78ea4b..1293d03f15bfc 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
@@ -804,18 +804,6 @@ FailureOr<linalg::ForallReductionTilingResult> linalg::tileReductionUsingForall(
   return results;
 }
 
-// Insert a tile `source` into the destination tensor `dest`. The position at
-// which the tile is inserted (as well as size of tile) is taken from a given
-// ExtractSliceOp `sliceOp`.
-static Value insertSliceIntoTensor(OpBuilder &b, Location loc,
-                                   tensor::ExtractSliceOp sliceOp, Value source,
-                                   Value dest) {
-  return b.create<tensor::InsertSliceOp>(
-      loc, sliceOp.getSource().getType(), source, dest, sliceOp.getOffsets(),
-      sliceOp.getSizes(), sliceOp.getStrides(), sliceOp.getStaticOffsets(),
-      sliceOp.getStaticSizes(), sliceOp.getStaticStrides());
-}
-
 template <typename LoopTy>
 FailureOr<TiledLinalgOp> static tileLinalgOpImpl(
     RewriterBase &b, LinalgOp op, const LinalgTilingOptions &options) {
@@ -851,93 +839,6 @@ mlir::linalg::tileLinalgOp(RewriterBase &b, LinalgOp op,
   return failure();
 }
 
-/// Generate a loop nest around a given tensor::PadOp (for tiling). `newPadOp`
-/// and `loopNest` are output parameters that return the new (tiled)
-/// tensor::PadOp and the loop nest.
-static LogicalResult tilePadOp(RewriterBase &builder, tensor::PadOp op,
-                               tensor::PadOp &newPadOp, LoopNest &loopNest,
-                               const LinalgTilingOptions &options) {
-  Location loc = op.getLoc();
-  OpBuilder::InsertionGuard g(builder);
-  builder.setInsertionPoint(op);
-
-  // Clone tensor::PadOp so that the existing op can be replaced more easily.
-  newPadOp = cast<tensor::PadOp>(builder.clone(*op.getOperation()));
-  // Get rank and tile sizes.
-  int64_t rank = op.getResultType().getRank();
-  SmallVector<OpFoldResult> tileSizes =
-      getAsOpFoldResult(options.tileSizeComputationFunction(builder, op));
-  // Normalize untiled padding dimensions to 0.
-  tileSizes.append(rank - tileSizes.size(), builder.getIndexAttr(0));
-  // Compute lower and upper bounds of the loop nest.
-  TilingInterface tilingInterface =
-      dyn_cast<TilingInterface>(op.getOperation());
-  SmallVector<Range> ranges = tilingInterface.getIterationDomain(builder);
-  SmallVector<Value> lbs, dims, steps;
-  SmallVector<OpFoldResult> allDims;
-  for (int64_t i = 0; i < rank; ++i) {
-    allDims.push_back(ranges[i].size);
-    if (!isZero(tileSizes[i])) {
-      lbs.push_back(
-          getValueOrCreateConstantIndexOp(builder, loc, ranges[i].offset));
-      dims.push_back(
-          getValueOrCreateConstantIndexOp(builder, loc, ranges[i].size));
-      steps.push_back(
-          getValueOrCreateConstantIndexOp(builder, loc, tileSizes[i]));
-    }
-  }
-  SmallVector<Value> destinationTensors;
-  if (failed(tensor::getOrCreateDestinations(builder, loc, tilingInterface,
-                                             destinationTensors)))
-    return failure();
-
-  loopNest = mlir::scf::buildLoopNest(
-      builder, loc, lbs, /*ubs=*/dims, steps, ValueRange(destinationTensors),
-      [&](OpBuilder &b, Location loc, ValueRange localIvs,
-          ValueRange iterArgs) -> scf::ValueVector {
-        // Compute offsets and sizes of ExtractSliceOp.
-        SmallVector<Value> localIVVector = llvm::to_vector(localIvs);
-        SmallVector<OpFoldResult> offsets = computeTileOffsets(
-            b, loc, getAsOpFoldResult(localIVVector), tileSizes);
-        SmallVector<OpFoldResult> sizes =
-            computeTileSizes(b, loc, tileSizes, allDims);
-        // Create ExtractSliceOp: Extract a tile from the tensor::PadOp.
-        // Note: The tensor::PadOp is located outside of the loop nest. It is
-        // later moved inside by ExtractSliceOfPadTensorSwapPattern.
-        auto map = AffineMap::getMultiDimIdentityMap(rank, b.getContext());
-        Value tiledOutput = makeTiledShape(
-            b, loc, newPadOp->getResult(0), tileSizes, map, offsets, allDims,
-            sizes, /*omitPartialTileCheck=*/false);
-        auto sliceOp = tiledOutput.getDefiningOp<tensor::ExtractSliceOp>();
-        assert(sliceOp && "expected ExtractSliceOp");
-        // Insert the tile into the output tensor.
-        Value yieldValue =
-            insertSliceIntoTensor(b, loc, sliceOp, sliceOp, iterArgs[0]);
-        return scf::ValueVector({yieldValue});
-      });
-  return success();
-}
-
-namespace {
-struct PadOpTilingPattern : public OpRewritePattern<tensor::PadOp> {
-  PadOpTilingPattern(MLIRContext *ctx, LinalgTilingOptions opt)
-      : OpRewritePattern<tensor::PadOp>(ctx), options(std::move(opt)) {}
-
-  LogicalResult matchAndRewrite(tensor::PadOp op,
-                                PatternRewriter &rewriter) const override {
-    tensor::PadOp newPadOp;
-    LoopNest loopNest;
-    if (failed(tilePadOp(rewriter, op, newPadOp, loopNest, options)))
-      return failure();
-    // Replace all uses of the original tensor::PadOp.
-    rewriter.replaceOp(op, loopNest.results.front());
-    return success();
-  }
-
-  LinalgTilingOptions options;
-};
-} // namespace
-
 namespace {
 /// Helper classes for type list expansion.
 template <typename... OpTypes>
@@ -993,9 +894,3 @@ void mlir::linalg::populateLinalgTilingCanonicalizationPatterns(
 #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
       >::insert(patterns);
 }
-
-void mlir::linalg::populatePadTensorTilingPatterns(
-    RewritePatternSet &patterns, const LinalgTilingOptions &options) {
-  auto *ctx = patterns.getContext();
-  patterns.add<PadOpTilingPattern>(ctx, options);
-}


        


More information about the Mlir-commits mailing list