Files
clang-p2996/mlir/lib/Conversion/TensorToLinalg/TensorToLinalgPass.cpp
lorenzo chelini c1a2292526 [MLIR][NFC] Retire let constructor for passes in Conversion directory (part1) (#127403)
`let constructor` is deprecated since the table gen backend emits most
of the glue logic to build a pass. This PR retires the td method for
most (I need another pass) passes in the Conversion directory.
2025-02-17 10:55:27 +01:00

48 lines
1.7 KiB
C++

//===- TensorToLinalgPass.cpp - Tensor to Linalg Passes -------------------===//
//
// 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 a pass to convert Tensor dialect to Linalg dialect.
//
//===----------------------------------------------------------------------===//
#include "mlir/Conversion/TensorToLinalg/TensorToLinalgPass.h"
#include "mlir/Conversion/TensorToLinalg/TensorToLinalg.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
namespace mlir {
#define GEN_PASS_DEF_CONVERTTENSORTOLINALGPASS
#include "mlir/Conversion/Passes.h.inc"
} // namespace mlir
using namespace mlir;
namespace {
/// A pass converting MLIR Tensor operations into the Linalg dialect.
class ConvertTensorToLinalgPass
: public impl::ConvertTensorToLinalgPassBase<ConvertTensorToLinalgPass> {
void runOnOperation() override {
auto &context = getContext();
ConversionTarget target(context);
target
.addLegalDialect<mlir::arith::ArithDialect, mlir::linalg::LinalgDialect,
mlir::tensor::TensorDialect>();
target.addIllegalOp<mlir::tensor::PadOp>();
RewritePatternSet patterns(&context);
populateTensorToLinalgPatterns(patterns);
if (failed(applyPartialConversion(getOperation(), target,
std::move(patterns))))
return signalPassFailure();
}
};
} // namespace