From b5709e098577a3f202e7f8a48655fc50d45731af Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 24 Aug 2020 10:09:57 -0700 Subject: [PATCH] Introduce a helper for registering all TF dialects (NFC) This is part of a series of patches intended to make MLIR Dialects explictly registered and remove the "always_link" global-constructor based registration. The registration is mainly for tools that need to parse a "TF" MLIR input. PiperOrigin-RevId: 328161577 Change-Id: I533930a804d2a22b76d0ef36b5970b80500542ea --- tensorflow/compiler/mlir/tensorflow/BUILD | 3 ++ .../mlir/tensorflow/dialect_registration.h | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tensorflow/compiler/mlir/tensorflow/dialect_registration.h diff --git a/tensorflow/compiler/mlir/tensorflow/BUILD b/tensorflow/compiler/mlir/tensorflow/BUILD index b8c7376ebd3..9e33a4489fd 100644 --- a/tensorflow/compiler/mlir/tensorflow/BUILD +++ b/tensorflow/compiler/mlir/tensorflow/BUILD @@ -513,6 +513,7 @@ cc_library( "ir/tf_saved_model.cc", ], hdrs = [ + "dialect_registration.h", "ir/tf_device.h", "ir/tf_executor.h", "ir/tf_ops.h", @@ -1088,6 +1089,7 @@ cc_library( srcs = ["translate/translate_tf_dialect_op.cc"], deps = [ ":export_tf_dialect_op", + ":tensorflow", "@llvm-project//llvm:Support", "@llvm-project//mlir:IR", "@llvm-project//mlir:Support", @@ -1408,6 +1410,7 @@ cc_library( deps = [ ":convert_graphdef", ":mlir_roundtrip_flags", + ":tensorflow", ":translate_cl_options", ":translate_lib", "//tensorflow/core:protos_all_cc", diff --git a/tensorflow/compiler/mlir/tensorflow/dialect_registration.h b/tensorflow/compiler/mlir/tensorflow/dialect_registration.h new file mode 100644 index 00000000000..a63bfd154ab --- /dev/null +++ b/tensorflow/compiler/mlir/tensorflow/dialect_registration.h @@ -0,0 +1,37 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_DIALECT_REGISTRATION_H_ +#define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_DIALECT_REGISTRATION_H_ + +#include "mlir/Dialect/StandardOps/IR/Ops.h" // from @llvm-project +#include "mlir/IR/Dialect.h" // from @llvm-project +#include "tensorflow/compiler/mlir/tensorflow/ir/tf_device.h" +#include "tensorflow/compiler/mlir/tensorflow/ir/tf_executor.h" +#include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h" +#include "tensorflow/compiler/mlir/tensorflow/ir/tf_saved_model.h" + +namespace mlir { +// Inserts all the TensorFlow dialects in the provided registry. This is +// intended for tools that need to register dialects before parsing .mlir files. +inline void RegisterAllTensorFlowDialects(DialectRegistry ®istry) { + registry.insert(); +} +} // namespace mlir + +#endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_DIALECT_REGISTRATION_H_ -- GitLab