MLIR  22.0.0git
TensorToLinalgPass.cpp
Go to the documentation of this file.
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a pass to convert Tensor dialect to Linalg dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
19 
20 namespace mlir {
21 #define GEN_PASS_DEF_CONVERTTENSORTOLINALGPASS
22 #include "mlir/Conversion/Passes.h.inc"
23 } // namespace mlir
24 
25 using namespace mlir;
26 
27 namespace {
28 /// A pass converting MLIR Tensor operations into the Linalg dialect.
29 class ConvertTensorToLinalgPass
30  : public impl::ConvertTensorToLinalgPassBase<ConvertTensorToLinalgPass> {
31  void runOnOperation() override {
32  auto &context = getContext();
33  ConversionTarget target(context);
34  target
35  .addLegalDialect<mlir::arith::ArithDialect, mlir::linalg::LinalgDialect,
36  mlir::tensor::TensorDialect>();
37  target.addIllegalOp<mlir::tensor::PadOp>();
38 
39  RewritePatternSet patterns(&context);
41 
42  if (failed(applyPartialConversion(getOperation(), target,
43  std::move(patterns))))
44  return signalPassFailure();
45  }
46 };
47 } // namespace
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
void addLegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as legal.
void addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition: Remarks.h:491
Include the generated interface declarations.
void populateTensorToLinalgPatterns(RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating tensor ops to Linalg ops.
const FrozenRewritePatternSet & patterns
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.