1//===-- Passes.h - TOSA optimization pass declarations ----------*- C++ -*-===//
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 file declares the optimization passes for the TOSA Dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_TOSA_TRANSFORMS_PASSES_H
14#define MLIR_DIALECT_TOSA_TRANSFORMS_PASSES_H
15
16#include "mlir/Dialect/Tensor/IR/Tensor.h"
17#include "mlir/Dialect/Tosa/Transforms/PassesEnums.h.inc"
18#include "mlir/Pass/Pass.h"
19
20namespace mlir {
21namespace tosa {
22
23#define GEN_PASS_DECL
24#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
25
26// Expose Rewrite Functions that decompose TOSA Ops into further TOSA Ops.
27// The rewrites can be selectively added to a conversion pass.
28void populateTosaDecomposeConv2D(MLIRContext *ctx, RewritePatternSet &patterns);
29void populateTosaDecomposeTransposeConv(MLIRContext *ctx,
30 RewritePatternSet &patterns);
31void populateTosaDecomposeDepthwise(MLIRContext *ctx,
32 RewritePatternSet &patterns);
33void populateTosaFoldConstantReciprocalPatterns(MLIRContext *ctx,
34 RewritePatternSet &patterns);
35void populateTosaFoldConstantTransposePatterns(MLIRContext *ctx,
36 RewritePatternSet &patterns);
37void populateTosaConstantReduction(MLIRContext *ctx,
38 RewritePatternSet &patterns,
39 bool aggressiveReduceConstant);
40
41std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass();
42std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass(
43 const TosaLayerwiseConstantFoldPassOptions &options);
44std::unique_ptr<Pass> createTosaInferShapesPass();
45std::unique_ptr<Pass> createTosaMakeBroadcastablePass();
46std::unique_ptr<Pass> createTosaTestQuantUtilAPIPass();
47std::unique_ptr<Pass> createTosaOptionalDecompositions();
48
49struct ValidationOptions {
50 /// Validate if operations match for the given profile.
51 TosaProfileEnum profile = TosaProfileEnum::Undefined;
52 ValidationOptions &setProfile(TosaProfileEnum profile) {
53 this->profile = profile;
54 return *this;
55 }
56 /// Verify if the properties of certain operations align the spec requirement.
57 bool strictOperationSpecAlignment = false;
58 ValidationOptions &enableStrictOperationSpecAlignment(bool enable = true) {
59 strictOperationSpecAlignment = enable;
60 return *this;
61 }
62 /// Validate if operator parameters are within specfication for the given
63 /// level.
64 TosaLevelEnum level = TosaLevelEnum::EightK;
65 ValidationOptions &setLevel(TosaLevelEnum level) {
66 this->level = level;
67 return *this;
68 }
69};
70
71#define GEN_PASS_REGISTRATION
72#include "mlir/Dialect/Tosa/Transforms/Passes.h.inc"
73
74} // namespace tosa
75} // namespace mlir
76
77#endif // MLIR_DIALECT_TOSA_TRANSFORMS_PASSES_H
78

source code of mlir/include/mlir/Dialect/Tosa/Transforms/Passes.h