Files
clang-p2996/mlir/lib/Conversion/TensorToLinalg/TensorToLinalgPass.cpp
Tres Popp 1dce51b888 [mlir] Add TensorToLinalgPass
This pass is to handle computationally complex operations like
tensor.pad which are not simply lowered to the exact same operation in
the memref dialect.

Differential Revision: https://reviews.llvm.org/D125384
2022-05-13 12:17:22 +02: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 "../PassDetail.h"
#include "mlir/Conversion/TensorToLinalg/TensorToLinalg.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
using namespace mlir;
namespace {
/// A pass converting MLIR Tensor operations into the Linalg dialect.
class ConvertTensorToLinalgPass
: public ConvertTensorToLinalgBase<ConvertTensorToLinalgPass> {
void runOnOperation() override {
auto &context = getContext();
ConversionTarget target(context);
target.addLegalDialect<mlir::arith::ArithmeticDialect,
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
std::unique_ptr<OperationPass<ModuleOp>>
mlir::createConvertTensorToLinalgPass() {
return std::make_unique<ConvertTensorToLinalgPass>();
}