MLIR  19.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 
46 
47  if (failed(applyPartialConversion(getOperation(), target,
48  std::move(patterns))))
49  signalPassFailure();
50  }
51 };
52 } // namespace
53 
54 std::unique_ptr<Pass> mlir::tosa::createTosaToTensor() {
55  return std::make_unique<TosaToTensor>();
56 }
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.
void populateTosaToTensorConversionPatterns(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.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72