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_COMMON_TFL_PASS_CONFIG_H_ 17 #define TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "llvm/ADT/ArrayRef.h" 23 #include "tensorflow/compiler/mlir/lite/quantization/quantization_config.h" 24 25 namespace mlir { 26 namespace TFL { 27 28 // A config that controls which passes get run as part TFLite converter. 29 struct PassConfig { PassConfigPassConfig30 explicit PassConfig(QuantizationSpecs specs) 31 : emit_builtin_tflite_ops(true), 32 lower_tensor_list_ops(false), 33 trim_functions_whitelist({}), 34 quant_specs(std::move(specs)), 35 skip_control_dialect(false), 36 form_clusters(false), 37 inline_functions(true), 38 unfold_batch_matmul(true) {} 39 40 // If `emit_builtin_tflite_ops` is true, TF Lite legalization passes will be 41 // added, which produces TF Lite ops. 42 bool emit_builtin_tflite_ops; 43 // If `lower_tensor_list_ops` is true, tensorlist ops will be lowered to basic 44 // TF ops before legalization to TF Lite dialect. 45 bool lower_tensor_list_ops; 46 // The whitelist of functions that would be preserved after trimming. 47 llvm::ArrayRef<std::string> trim_functions_whitelist; 48 // All information about quantization. 49 QuantizationSpecs quant_specs; 50 // If `skip_control_dialect` is true, TF executor dialect is not converted to 51 // TF control dialect prior to legalization to TF Lite. 52 // TODO(b/142911013): Remove flag once control dialect is removed. 53 bool skip_control_dialect; 54 // If `form_clusters` is true (and `skip_control_dialect` is true), clusters 55 // are formed by grouping consecutive ops of the same device, under a 56 // `tf_device.launch` op. 57 bool form_clusters; 58 // Inline function calls within the main function in the MLIR module, prior 59 // to legalization to TFLite. 60 bool inline_functions; 61 // if `unfold_batch_matmul` is true, the tf.BatchMatMul is unfolded to a set 62 // of tfl.fully_connected ops. 63 bool unfold_batch_matmul; 64 }; 65 66 } // namespace TFL 67 } // namespace mlir 68 69 #endif // TENSORFLOW_COMPILER_MLIR_LITE_COMMON_TFL_PASS_CONFIG_H_ 70