brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 14dfd98 Raw
52 lines · cpp
1//===- TosaToSCFPass.cpp - Lowering Tosa to SCF 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 Tosa operations to the SCF dialect.10//11//===----------------------------------------------------------------------===//12 13#include "mlir/Conversion/TosaToSCF/TosaToSCF.h"14 15#include "mlir/Dialect/Func/IR/FuncOps.h"16#include "mlir/Dialect/SCF/IR/SCF.h"17#include "mlir/Dialect/Tensor/IR/Tensor.h"18#include "mlir/Dialect/Tosa/IR/TosaOps.h"19#include "mlir/IR/PatternMatch.h"20#include "mlir/Pass/PassManager.h"21#include "mlir/Transforms/DialectConversion.h"22 23namespace mlir {24#define GEN_PASS_DEF_TOSATOSCFPASS25#include "mlir/Conversion/Passes.h.inc"26} // namespace mlir27 28using namespace mlir;29using namespace tosa;30 31namespace {32struct TosaToSCF : public impl::TosaToSCFPassBase<TosaToSCF> {33public:34  void runOnOperation() override {35    RewritePatternSet patterns(&getContext());36    ConversionTarget target(getContext());37    target.addLegalDialect<tensor::TensorDialect, scf::SCFDialect>();38    target.addIllegalOp<tosa::IfOp, tosa::ScatterOp, tosa::WhileOp>();39    target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });40 41    auto *op = getOperation();42    mlir::tosa::populateTosaToSCFConversionPatterns(&patterns);43    if (failed(applyPartialConversion(op, target, std::move(patterns))))44      signalPassFailure();45  }46};47} // namespace48 49void mlir::tosa::addTosaToSCFPasses(OpPassManager &pm) {50  pm.addNestedPass<func::FuncOp>(createTosaToSCFPass());51}52