MLIR  22.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 
19 #include "mlir/IR/PatternMatch.h"
20 #include "mlir/Pass/PassManager.h"
22 
23 namespace mlir {
24 #define GEN_PASS_DEF_TOSATOSCFPASS
25 #include "mlir/Conversion/Passes.h.inc"
26 } // namespace mlir
27 
28 using namespace mlir;
29 using namespace tosa;
30 
31 namespace {
32 struct TosaToSCF : public impl::TosaToSCFPassBase<TosaToSCF> {
33 public:
34  void runOnOperation() override {
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();
43  if (failed(applyPartialConversion(op, target, std::move(patterns))))
44  signalPassFailure();
45  }
46 };
47 } // namespace
48 
50  pm.addNestedPass<func::FuncOp>(createTosaToSCFPass());
51 }
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:46
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:115
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition: Remarks.h:491
void addTosaToSCFPasses(OpPassManager &pm)
Populates passes to convert from TOSA to SCF.
void populateTosaToSCFConversionPatterns(RewritePatternSet *patterns)
Definition: TosaToSCF.cpp:174
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
LogicalResult applyPartialConversion(ArrayRef< Operation * > ops, const ConversionTarget &target, const FrozenRewritePatternSet &patterns, ConversionConfig config=ConversionConfig())
Below we define several entry points for operation conversion.