MLIR  20.0.0git
TosaToArithPass.cpp
Go to the documentation of this file.
1 //===- TosaToArithPass.cpp - Lowering Tosa to Linalg 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 Arith dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 
18 #include "mlir/IR/PatternMatch.h"
19 #include "mlir/Pass/PassManager.h"
22 
23 namespace mlir {
24 #define GEN_PASS_DEF_TOSATOARITH
25 #include "mlir/Conversion/Passes.h.inc"
26 } // namespace mlir
27 
28 using namespace mlir;
29 using namespace tosa;
30 
31 namespace {
32 struct TosaToArith : public impl::TosaToArithBase<TosaToArith> {
33 public:
34  TosaToArith(TosaToArithOptions &options) : TosaToArithBase(options) {}
35 
36  void runOnOperation() override {
37  RewritePatternSet patterns(&getContext());
38  ConversionTarget target(getContext());
39  target.addIllegalOp<tosa::ConstOp>();
40  target.addLegalDialect<arith::ArithDialect>();
41 
43 
44  if (this->includeApplyRescale) {
46  this->use32Bit);
47  target.addIllegalOp<tosa::ApplyScaleOp>();
48  }
49 
50  if (failed(applyPartialConversion(getOperation(), target,
51  std::move(patterns))))
52  signalPassFailure();
53  }
54 };
55 } // namespace
56 
57 std::unique_ptr<Pass> mlir::tosa::createTosaToArith(bool includeApplyRescale,
58  bool use32BitApplyRescale) {
59  TosaToArithOptions options = {includeApplyRescale, use32BitApplyRescale};
60  return std::make_unique<TosaToArith>(options);
61 }
static MLIRContext * getContext(OpFoldResult val)
static llvm::ManagedStatic< PassManagerOptions > options
This class describes a specific conversion target.
void addLegalDialect(StringRef name, Names... names)
Register the operations of the given dialects as legal.
void addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
std::unique_ptr< Pass > createTosaToArith(bool includeApplyRescale=false, bool use32BitApplyRescale=false)
void populateTosaRescaleToArithConversionPatterns(RewritePatternSet *patterns, bool include32Bit=false)
void populateTosaToArithConversionPatterns(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.