blob: d1ba9190f6d4abf922d5007486cb61d0425c074c [file] [log] [blame]
// Copyright 2019 The IREE Authors
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef IREE_INTEGRATIONS_TENSORFLOW_IREE_TF_COMPILER_TF_PASSES_H_
#define IREE_INTEGRATIONS_TENSORFLOW_IREE_TF_COMPILER_TF_PASSES_H_
#include "iree_tf_compiler/dialect/tf_strings/conversion/convert_tf_strings_to_strings.h"
#include "iree_tf_compiler/dialect/tf_strings/conversion/convert_tf_to_tf_strings.h"
#include "iree_tf_compiler/dialect/tf_tensorlist/conversion/convert_tf_tensorlist_to_tensorlist.h"
#include "iree_tf_compiler/dialect/tf_tensorlist/conversion/convert_tf_to_tf_tensorlist.h"
#include "mlir/Pass/Pass.h"
namespace mlir {
namespace iree_integrations {
namespace TF {
//===----------------------------------------------------------------------===//
// Helpers
//===----------------------------------------------------------------------===//
// Create a single pipeline that will run all the needed IREE-specific TF import
// passes in the right order.
void buildTFImportPassPipeline(OpPassManager &pm);
void registerTFImportPassPipeline();
//===----------------------------------------------------------------------===//
// IREE-specific Passes For TensorFlow Import
//===----------------------------------------------------------------------===//
// Converts the TF dialect to the XLA MHLO dialect.
std::unique_ptr<FunctionPass> createConvertToMHLOPass();
// In a module tagged with `tf_saved_model.semantics`, lowers
// `tf_saved_model.global_variable`'s to `flow.variable`'s.
//
// This pass should be run before adopting the exports, which transitions to
// a module that does not have `tf_saved_model.semantics`.
std::unique_ptr<OperationPass<ModuleOp>> createLowerGlobalTensorsPass();
// In a module tagged with `tf_saved_model.semantics`, lowers any tf_saved_model
// exported functions to IREE exported functions with appropriate reflection
// metadata.
std::unique_ptr<OperationPass<ModuleOp>> createLowerExportedFunctionsPass();
// In a module tagged with `tf_saved_model.semantics`, creates IREE ABI
// functions for any saved model exported functions.
std::unique_ptr<OperationPass<ModuleOp>> createSavedModelToIREEABIPass();
// Simplifies TensorFlow debug info for the purposes of making it easier to
// look at.
std::unique_ptr<OperationPass<ModuleOp>> createPrettifyDebugInfoPass();
// Push resource casts forward to better propagate resource related shapes.
std::unique_ptr<OperationPass<ModuleOp>> createPropagateResourceCastsPass();
// Strips tf.Assert ops.
std::unique_ptr<OperationPass<FuncOp>> createStripAssertsPass();
// Strips all TF-related attributes; none are needed by IREE.
std::unique_ptr<OperationPass<ModuleOp>> createStripModuleMetadataPass();
std::unique_ptr<OperationPass<FuncOp>> createStripFunctionMetadataPass();
// Validates whether any Tensorflow operations remain.
std::unique_ptr<OperationPass<FuncOp>> createVerifyFullyConvertedPass();
//===----------------------------------------------------------------------===//
// Registration
//===----------------------------------------------------------------------===//
void registerAllDialects(mlir::DialectRegistry &registry);
inline void registerAllPasses() {
registerTFImportPassPipeline();
createConvertToMHLOPass();
createLowerGlobalTensorsPass();
createLowerExportedFunctionsPass();
createPrettifyDebugInfoPass();
createPropagateResourceCastsPass();
createSavedModelToIREEABIPass();
createStripAssertsPass();
createStripModuleMetadataPass();
createStripFunctionMetadataPass();
createVerifyFullyConvertedPass();
tf_strings::createConvertTFToTFStringsPass();
tf_strings::createConvertTFStringsToStringsPass();
tf_tensorlist::createConvertTFTensorListToTensorListPass();
tf_tensorlist::createConvertTFToTFTensorListPass();
}
} // namespace TF
} // namespace iree_integrations
} // namespace mlir
#endif // IREE_INTEGRATIONS_TENSORFLOW_IREE_TF_COMPILER_TF_PASSES_H_