• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_MLIR_LITE_TRANSFORMS_PASSES_H_
17 #define TENSORFLOW_COMPILER_MLIR_LITE_TRANSFORMS_PASSES_H_
18 
19 #include <memory>
20 
21 #include "llvm/ADT/ArrayRef.h"
22 
23 namespace mlir {
24 class FuncOp;
25 class ModuleOp;
26 template <typename T>
27 class OperationPass;
28 
29 namespace TFL {
30 class QuantizationSpecs;
31 
32 // Creates an instance of the TensorFlow Lite dialect LegalizeTF pass.
33 // When the given run_tfl_runtime_verification value is true, it will check each
34 // TFL builtin op towards the TFL runtime capability and the incompatible TF ops
35 // will be left in the graph without getting legalized.
36 std::unique_ptr<OperationPass<FuncOp>> CreateLegalizeTFPass(
37     bool run_tfl_runtime_verification);
38 
39 // Creates an instance of the TensorFlow Lite dialect Optimize pass.
40 std::unique_ptr<OperationPass<FuncOp>> CreateOptimizePass();
41 
42 // Creates an instance of the TensorFlow Lite dialect PrepareTF pass.
43 std::unique_ptr<OperationPass<FuncOp>> CreatePrepareTFPass(
44     bool unfold_batch_matmul, bool allow_bf16_and_f16_type_legalization);
45 
46 // Creates an instance of the TensorFlow Lite dialect LowerStaticTensorList
47 // pass.
48 std::unique_ptr<OperationPass<ModuleOp>> CreateLowerStaticTensorListPass();
49 
50 // Creates an instance of the TensorFlow Lite dialect Quantize pass.
51 std::unique_ptr<OperationPass<FuncOp>> CreateQuantizePass(
52     bool verify_numeric = false, bool legacy_float_scale = false);
53 
54 // Creates an instance of the TensorFlow Lite dialect PrepareQuantize pass.
55 std::unique_ptr<OperationPass<FuncOp>> CreatePrepareQuantizePass(
56     const QuantizationSpecs& quant_specs);
57 
58 // Creates an instance of the TensorFlow Lite dialect PostQuantize pass.
59 std::unique_ptr<OperationPass<FuncOp>> CreatePostQuantizePass(
60     bool emit_quant_adaptor_ops);
61 
62 // Creates an instance of the TensorFlow Lite dialect TrimFunctions
63 // pass.
64 std::unique_ptr<OperationPass<ModuleOp>> CreateTrimFunctionsPass(
65     llvm::ArrayRef<std::string> trim_funcs_allowlist);
66 
67 // Creates an instance of the TensorFlow Lite dialect PrepareCompositeFunctions
68 // pass.
69 std::unique_ptr<OperationPass<ModuleOp>> CreatePrepareCompositeFunctionsPass();
70 
71 // Creates an instance of the TensorFlow Lite dialect SplitMergedOperandsPass.
72 std::unique_ptr<OperationPass<FuncOp>> CreateSplitMergedOperandsPass();
73 
74 // Creates an instance of the TensorFlow Lite dialect OptimizeFunctionalOpsPass.
75 std::unique_ptr<OperationPass<ModuleOp>> CreateOptimizeFunctionalOpsPass();
76 
77 // Creates an instance of the TensorFlow Lite dialect pass to add default
78 // quantization parameters.
79 std::unique_ptr<OperationPass<FuncOp>> CreateDefaultQuantParamsPass(
80     double default_min, double default_max, bool is_signed);
81 
82 // Creates an instance of the TensorFlow Lite dialect pass to convert dense
83 // tensor to sparse format.
84 std::unique_ptr<OperationPass<FuncOp>> CreateDenseToSparsePass();
85 
86 // Creates function pass to legalize TF While to TFL While.
87 std::unique_ptr<OperationPass<ModuleOp>> CreateLegalizeTFWhilePass();
88 
89 // Creates an instance of the TensorFlow Lite dialect WhileOp outline pass.
90 std::unique_ptr<OperationPass<ModuleOp>> CreateWhileOutlinePass();
91 
92 // Verifies runtime constraints.
93 std::unique_ptr<OperationPass<FuncOp>> CreateRuntimeVerifyPass();
94 
95 // Creates raise custom ops pass, which legalize custom ops to TFL::CustomOp
96 std::unique_ptr<OperationPass<FuncOp>> CreateRaiseCustomOpsPass();
97 
98 // Inserts an TFL::CallOnce op when the tf_saved_model's session initialzer is
99 // given.
100 std::unique_ptr<OperationPass<ModuleOp>>
101 CreateInsertCallOnceOpFromSessionInitializerPass();
102 
103 // Creates a pass which is responsible for legalizing TensorFlow variables to
104 // TensorFlow Lite variables.
105 std::unique_ptr<OperationPass<ModuleOp>> CreateLegalizeVariablesPass();
106 
107 // Creates a pass which removes any unused bounded input arguments to functions
108 // which corresponds to GlobalTensor.
109 std::unique_ptr<OperationPass<ModuleOp>> CreateRemoveArgsAndGlobalTensors();
110 
111 // Creates a pass which is responsible for initializing Tensorflow variables
112 // as Tensorflow Lite variables.
113 std::unique_ptr<OperationPass<ModuleOp>> CreateInitializeVariablesPass();
114 }  // namespace TFL
115 
116 }  // namespace mlir
117 
118 #endif  // TENSORFLOW_COMPILER_MLIR_LITE_TRANSFORMS_PASSES_H_
119