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_FLATBUFFER_IMPORT_H_ 17 #define TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_IMPORT_H_ 18 19 #include "absl/strings/string_view.h" 20 #include "mlir/IR/Location.h" // TF:llvm-project 21 #include "mlir/IR/MLIRContext.h" // TF:llvm-project 22 #include "mlir/IR/Module.h" // TF:llvm-project 23 24 namespace tflite { 25 // Converts a TFLite flatbuffer stored in `buffer` to a MLIR module 26 // The buffer must live for the duration of the function call, 27 // The caller receives ownership of the module. 28 // `base_loc` is used for error reporting and debug info. 29 // If ordered_output_arrays is not empty, then the imported mlir function will 30 // only return nodes in ordered_output_arrays in the same order. Returns nullptr 31 // on failure, and more specific errors will be emitted via the context. 32 // If `use_external_constant` is true, it will create `tfl.external_const` 33 // instead of `tfl.const`. 34 // If `experimental_prune_unreachable_nodes_unconditionally` is true, nodes that 35 // are not ancestors of the output nodes will be pruned. 36 mlir::OwningModuleRef FlatBufferToMlir( 37 absl::string_view buffer, mlir::MLIRContext* context, 38 mlir::Location base_loc, 39 const std::vector<std::string>& ordered_output_arrays, 40 bool use_external_constant = false, 41 bool experimental_prune_unreachable_nodes_unconditionally = false); 42 } // namespace tflite 43 44 #endif // TENSORFLOW_COMPILER_MLIR_LITE_FLATBUFFER_IMPORT_H_ 45