brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 5acfcfe Raw
48 lines · cpp
1//===- TensorToLinalgPass.cpp - Tensor to Linalg Passes -------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a pass to convert Tensor dialect to Linalg dialect.10//11//===----------------------------------------------------------------------===//12 13#include "mlir/Conversion/TensorToLinalg/TensorToLinalgPass.h"14 15#include "mlir/Conversion/TensorToLinalg/TensorToLinalg.h"16#include "mlir/Dialect/Arith/IR/Arith.h"17#include "mlir/Dialect/Linalg/IR/Linalg.h"18#include "mlir/Dialect/Tensor/IR/Tensor.h"19 20namespace mlir {21#define GEN_PASS_DEF_CONVERTTENSORTOLINALGPASS22#include "mlir/Conversion/Passes.h.inc"23} // namespace mlir24 25using namespace mlir;26 27namespace {28/// A pass converting MLIR Tensor operations into the Linalg dialect.29class ConvertTensorToLinalgPass30    : public impl::ConvertTensorToLinalgPassBase<ConvertTensorToLinalgPass> {31  void runOnOperation() override {32    auto &context = getContext();33    ConversionTarget target(context);34    target35        .addLegalDialect<mlir::arith::ArithDialect, mlir::linalg::LinalgDialect,36                         mlir::tensor::TensorDialect>();37    target.addIllegalOp<mlir::tensor::PadOp>();38 39    RewritePatternSet patterns(&context);40    populateTensorToLinalgPatterns(patterns);41 42    if (failed(applyPartialConversion(getOperation(), target,43                                      std::move(patterns))))44      return signalPassFailure();45  }46};47} // namespace48