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
13#include "mlir/Conversion/TosaToMLProgram/TosaToMLProgram.h"
14#include "mlir/Dialect/MLProgram/IR/MLProgram.h"
15#include "mlir/Dialect/Tosa/IR/TosaOps.h"
16#include "mlir/IR/PatternMatch.h"
17#include "mlir/Pass/PassManager.h"
18#include "mlir/Transforms/DialectConversion.h"
19
20namespace mlir {
21#define GEN_PASS_DEF_TOSATOMLPROGRAM
22#include "mlir/Conversion/Passes.h.inc"
23} // namespace mlir
24
25using namespace mlir;
26using namespace tosa;
27
28namespace {
29struct TosaToMLProgram : public impl::TosaToMLProgramBase<TosaToMLProgram> {
30public:
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(fn: [](Operation *) { return true; });
40
41 mlir::tosa::populateTosaToMLProgramConversionPatterns(patterns: &patterns);
42
43 if (failed(Result: applyPartialConversion(op: moduleOp, target, patterns: std::move(patterns))))
44 signalPassFailure();
45 }
46};
47} // namespace
48

source code of mlir/lib/Conversion/TosaToMLProgram/TosaToMLProgramPass.cpp