brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · dba6f79 Raw
48 lines · cpp
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-exception6//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_TOSATOMLPROGRAM22#include "mlir/Conversion/Passes.h.inc"23} // namespace mlir24 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([](Operation *) { return true; });40 41    mlir::tosa::populateTosaToMLProgramConversionPatterns(&patterns);42 43    if (failed(applyPartialConversion(moduleOp, target, std::move(patterns))))44      signalPassFailure();45  }46};47} // namespace48