MLIR  19.0.0git
TosaToMLProgramPass.cpp
Go to the documentation of this file.
1 //===- TosaToMLProgramPass.cpp - Lowering Tosa to MLProgram 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 the TOSA dialect to the MLProgram dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
17 #include "mlir/IR/PatternMatch.h"
18 #include "mlir/Pass/PassManager.h"
20 
21 namespace mlir {
22 #define GEN_PASS_DEF_TOSATOMLPROGRAM
23 #include "mlir/Conversion/Passes.h.inc"
24 } // namespace mlir
25 
26 using namespace mlir;
27 using namespace tosa;
28 
29 namespace {
30 struct TosaToMLProgram : public impl::TosaToMLProgramBase<TosaToMLProgram> {
31 public:
32  void runOnOperation() override {
33  auto *context = &getContext();
34  auto moduleOp = getOperation();
35 
36  RewritePatternSet patterns(context);
37  ConversionTarget target(*context);
38  target.addIllegalOp<tosa::VariableOp, tosa::VariableReadOp,
39  tosa::VariableWriteOp>();
40  target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
41 
43 
44  if (failed(applyPartialConversion(moduleOp, target, std::move(patterns))))
45  signalPassFailure();
46  }
47 };
48 } // namespace
static MLIRContext * getContext(OpFoldResult val)
This class describes a specific conversion target.
void markUnknownOpDynamicallyLegal(const DynamicLegalityCallbackFn &fn)
Register unknown operations as dynamically legal.
void addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
void populateTosaToMLProgramConversionPatterns(RewritePatternSet *patterns)
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.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72