MLIR  21.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 
17 #include "mlir/IR/PatternMatch.h"
19 
20 namespace mlir {
21 #define GEN_PASS_DEF_TOSATOARITHPASS
22 #include "mlir/Conversion/Passes.h.inc"
23 } // namespace mlir
24 
25 using namespace mlir;
26 using namespace tosa;
27 
28 namespace {
29 struct TosaToArith : public impl::TosaToArithPassBase<TosaToArith> {
30  using Base::Base;
31 
32  void runOnOperation() override {
34  ConversionTarget target(getContext());
35  target.addIllegalOp<tosa::ConstOp>();
36  target.addLegalDialect<arith::ArithDialect>();
37 
39 
40  if (this->includeApplyRescale) {
42  this->use32Bit);
43  target.addIllegalOp<tosa::ApplyScaleOp>();
44  }
45 
46  if (failed(applyPartialConversion(getOperation(), target,
47  std::move(patterns))))
48  signalPassFailure();
49  }
50 };
51 } // namespace
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 addIllegalOp(OperationName op)
Register the given operation as illegal, i.e.
void populateTosaRescaleToArithConversionPatterns(RewritePatternSet *patterns, bool include32Bit=false)
void populateTosaToArithConversionPatterns(RewritePatternSet *patterns)
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.