MLIR  20.0.0git
TosaToTensorPass.cpp
Go to the documentation of this file.
1 //===- TosaToTensorPass.cpp - Lowering Tosa to Tensor Dialect -------------===//
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 transformation pass legalizes Tosa operations to the Tensor dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
19 #include "mlir/IR/PatternMatch.h"
20 #include "mlir/Pass/PassManager.h"
23 
24 namespace mlir {
25 #define GEN_PASS_DEF_TOSATOTENSOR
26 #include "mlir/Conversion/Passes.h.inc"
27 } // namespace mlir
28 
29 using namespace mlir;
30 using namespace tosa;
31 
32 namespace {
33 struct TosaToTensor : public impl::TosaToTensorBase<TosaToTensor> {
34 public:
35  void runOnOperation() override {
36  RewritePatternSet patterns(&getContext());
37  ConversionTarget target(getContext());
38  target.addIllegalOp<tosa::ConcatOp>();
39  target.addIllegalOp<tosa::ReshapeOp>();
40  target.addIllegalOp<tosa::SliceOp>();
41  target.addIllegalOp<tosa::PadOp>();
42  target.addLegalDialect<arith::ArithDialect>();
43  target.addLegalDialect<tensor::TensorDialect>();
44 
45  TypeConverter converter;
47 
49 
50  if (failed(applyPartialConversion(getOperation(), target,
51  std::move(patterns))))
52  signalPassFailure();
53  }
54 };
55 } // namespace
56 
57 std::unique_ptr<Pass> mlir::tosa::createTosaToTensor() {
58  return std::make_unique<TosaToTensor>();
59 }
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.
Type conversion class.
void populateTosaTypeConversion(TypeConverter &converter)
void populateTosaToTensorConversionPatterns(const TypeConverter &converter, RewritePatternSet *patterns)
std::unique_ptr< Pass > createTosaToTensor()
Include the generated interface declarations.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.