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