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-exception
6//
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_TOSATOSCFPASS
25#include "mlir/Conversion/Passes.h.inc"
26} // namespace mlir
27
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(fn: [](Operation *) { return true; });
40
41 auto *op = getOperation();
42 mlir::tosa::populateTosaToSCFConversionPatterns(patterns: &patterns);
43 if (failed(Result: applyPartialConversion(op, target, patterns: std::move(patterns))))
44 signalPassFailure();
45 }
46};
47} // namespace
48
49void mlir::tosa::addTosaToSCFPasses(OpPassManager &pm) {
50 pm.addNestedPass<func::FuncOp>(pass: createTosaToSCFPass());
51}
52

source code of mlir/lib/Conversion/TosaToSCF/TosaToSCFPass.cpp