MLIR  21.0.0git
TosaToMLProgramPass.cpp
Go to the documentation of this file.
1 //===- TosaToMLProgramPass.cpp - Lowering Tosa to MLProgram 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 the TOSA dialect to the MLProgram dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
16 #include "mlir/IR/PatternMatch.h"
17 #include "mlir/Pass/PassManager.h"
19 
20 namespace mlir {
21 #define GEN_PASS_DEF_TOSATOMLPROGRAM
22 #include "mlir/Conversion/Passes.h.inc"
23 } // namespace mlir
24 
25 using namespace mlir;
26 using namespace tosa;
27 
28 namespace {
29 struct TosaToMLProgram : public impl::TosaToMLProgramBase<TosaToMLProgram> {
30 public:
31  void runOnOperation() override {
32  auto *context = &getContext();
33  auto moduleOp = getOperation();
34 
35  RewritePatternSet patterns(context);
36  ConversionTarget target(*context);
37  target.addIllegalOp<tosa::VariableOp, tosa::VariableReadOp,
38  tosa::VariableWriteOp>();
39  target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
40 
42 
43  if (failed(applyPartialConversion(moduleOp, target, std::move(patterns))))
44  signalPassFailure();
45  }
46 };
47 } // namespace
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
void markUnknownOpDynamicallyLegal(const DynamicLegalityCallbackFn &fn)
Register unknown operations as dynamically legal.
void addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
void populateTosaToMLProgramConversionPatterns(RewritePatternSet *patterns)
Include the generated interface declarations.
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.