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/Dialect/Tosa/Transforms/Passes.h" 17 #include "mlir/IR/PatternMatch.h" 18 #include "mlir/Pass/PassManager.h" 19 #include "mlir/Transforms/DialectConversion.h" 20 21 namespace mlir { 22 #define GEN_PASS_DEF_TOSATOMLPROGRAM 23 #include "mlir/Conversion/Passes.h.inc" 24 } // namespace mlir 25 26 using namespace mlir; 27 using namespace tosa; 28 29 namespace { 30 struct TosaToMLProgram : public impl::TosaToMLProgramBase<TosaToMLProgram> { 31 public: runOnOperation__anon56ef5e0d0111::TosaToMLProgram32 void runOnOperation() override { 33 auto *context = &getContext(); 34 auto moduleOp = getOperation(); 35 36 RewritePatternSet patterns(context); 37 ConversionTarget target(*context); 38 target.addIllegalOp<tosa::VariableOp, tosa::VariableReadOp, 39 tosa::VariableWriteOp>(); 40 target.markUnknownOpDynamicallyLegal([](Operation *) { return true; }); 41 42 mlir::tosa::populateTosaToMLProgramConversionPatterns(&patterns); 43 44 if (failed(applyPartialConversion(moduleOp, target, std::move(patterns)))) 45 signalPassFailure(); 46 } 47 }; 48 } // namespace 49