1 //===- TosaToMLProgramPass.cpp - Lowering Tosa to MLProgram Dialect--------===//
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
7 //===----------------------------------------------------------------------===//
9 // This transformation pass legalizes the TOSA dialect to the MLProgram dialect.
11 //===----------------------------------------------------------------------===//
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/Dialect/Tosa/Transforms/Passes.h"
17 #include "mlir/IR/PatternMatch.h"
18 #include "mlir/Pass/PassManager.h"
19 #include "mlir/Transforms/DialectConversion.h"
22 #define GEN_PASS_DEF_TOSATOMLPROGRAM
23 #include "mlir/Conversion/Passes.h.inc"
30 struct TosaToMLProgram
: public impl::TosaToMLProgramBase
<TosaToMLProgram
> {
32 void runOnOperation() override
{
33 auto *context
= &getContext();
34 auto moduleOp
= getOperation();
36 RewritePatternSet
patterns(context
);
37 ConversionTarget
target(*context
);
38 target
.addIllegalOp
<tosa::VariableOp
, tosa::VariableReadOp
,
39 tosa::VariableWriteOp
>();
40 target
.markUnknownOpDynamicallyLegal([](Operation
*) { return true; });
42 mlir::tosa::populateTosaToMLProgramConversionPatterns(&patterns
);
44 if (failed(applyPartialConversion(moduleOp
, target
, std::move(patterns
))))