MLIR  19.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_CONVERTTENSORTOLINALG
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::ConvertTensorToLinalgBase<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
48 
49 std::unique_ptr<OperationPass<ModuleOp>>
51  return std::make_unique<ConvertTensorToLinalgPass>();
52 }
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.
Include the generated interface declarations.
std::unique_ptr< OperationPass< ModuleOp > > createConvertTensorToLinalgPass()
Creates a pass to convert Tensor ops to Linalg ops.
void populateTensorToLinalgPatterns(RewritePatternSet &patterns)
Appends to a pattern list additional patterns for translating tensor ops to Linalg ops.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72