MLIR  16.0.0git
TosaToSCFPass.cpp
Go to the documentation of this file.
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 "../PassDetail.h"
20 #include "mlir/IR/PatternMatch.h"
21 #include "mlir/Pass/PassManager.h"
24 
25 using namespace mlir;
26 using namespace tosa;
27 
28 namespace {
29 struct TosaToSCF : public TosaToSCFBase<TosaToSCF> {
30 public:
31  void runOnOperation() override {
32  RewritePatternSet patterns(&getContext());
33  ConversionTarget target(getContext());
34  target.addLegalDialect<tensor::TensorDialect, scf::SCFDialect>();
35  target.addIllegalOp<tosa::IfOp, tosa::WhileOp>();
36  target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
37 
38  auto *op = getOperation();
40  if (failed(applyPartialConversion(op, target, std::move(patterns))))
41  signalPassFailure();
42  }
43 };
44 } // namespace
45 
46 std::unique_ptr<Pass> mlir::tosa::createTosaToSCF() {
47  return std::make_unique<TosaToSCF>();
48 }
49 
51  pm.addNestedPass<func::FuncOp>(createTosaToSCF());
52 }
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
LogicalResult applyPartialConversion(ArrayRef< Operation *> ops, ConversionTarget &target, const FrozenRewritePatternSet &patterns, DenseSet< Operation *> *unconvertedOps=nullptr)
Below we define several entry points for operation conversion.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
Definition: LogicalResult.h:72
void populateTosaToSCFConversionPatterns(RewritePatternSet *patterns)
Definition: TosaToSCF.cpp:108
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
Definition: PassManager.h:120
void addTosaToSCFPasses(OpPassManager &pm)
Populates passes to convert from TOSA to SCF.
std::unique_ptr< Pass > createTosaToSCF()
This class describes a specific conversion target.
This class represents a pass manager that runs passes on either a specific operation type...
Definition: PassManager.h:52