MLIR  20.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 
14 
20 #include "mlir/IR/PatternMatch.h"
21 #include "mlir/Pass/PassManager.h"
24 
25 namespace mlir {
26 #define GEN_PASS_DEF_TOSATOSCF
27 #include "mlir/Conversion/Passes.h.inc"
28 } // namespace mlir
29 
30 using namespace mlir;
31 using namespace tosa;
32 
33 namespace {
34 struct TosaToSCF : public impl::TosaToSCFBase<TosaToSCF> {
35 public:
36  void runOnOperation() override {
37  RewritePatternSet patterns(&getContext());
38  ConversionTarget target(getContext());
39  target.addLegalDialect<tensor::TensorDialect, scf::SCFDialect>();
40  target.addIllegalOp<tosa::IfOp, tosa::ScatterOp, tosa::WhileOp>();
41  target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
42 
43  auto *op = getOperation();
45  if (failed(applyPartialConversion(op, target, std::move(patterns))))
46  signalPassFailure();
47  }
48 };
49 } // namespace
50 
51 std::unique_ptr<Pass> mlir::tosa::createTosaToSCF() {
52  return std::make_unique<TosaToSCF>();
53 }
54 
56  pm.addNestedPass<func::FuncOp>(createTosaToSCF());
57 }
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
void addLegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as legal.
void markUnknownOpDynamicallyLegal(const DynamicLegalityCallbackFn &fn)
Register unknown operations as dynamically legal.
void addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
This class represents a pass manager that runs passes on either a specific operation type,...
Definition: PassManager.h:47
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:116
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
void addTosaToSCFPasses(OpPassManager &pm)
Populates passes to convert from TOSA to SCF.
void populateTosaToSCFConversionPatterns(RewritePatternSet *patterns)
Definition: TosaToSCF.cpp:176
std::unique_ptr< Pass > createTosaToSCF()
Include the generated interface declarations.
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.