@@ -18,6 +18,7 @@ limitations under the License.
1818#include < memory>
1919#include < string>
2020
21+ #include " tensorflow/compiler/mlir/mlir_bridge_rollout_policy.h"
2122#include " absl/container/flat_hash_set.h"
2223#include " llvm/ADT/STLExtras.h"
2324#include " llvm/Support/FormatVariadic.h"
@@ -178,12 +179,7 @@ Status MlirFunctionOptimizationPass::Run(
178179 tensorflow::metrics::ScopedCounter<2 > timings (
179180 tensorflow::metrics::GetGraphOptimizationCounter (),
180181 {kTfMlirCategory , " graph_analysis" });
181- // Capture stats on graph properties analyzed before running the MLIR bridge.
182- // We set `uses_uninitialized_resource_args` to false here because function
183- // optimization is not affected by uninitialized resource args.
184- GetMlirBridgeRolloutPolicy (**graph, flib_def, config_proto,
185- /* uses_uninitialized_resource_args=*/ false ,
186- /* record_stats=*/ true );
182+
187183 timings.ReportAndStop ();
188184
189185 if (overall_state == MlirOptimizationPassState::Disabled) {
@@ -192,6 +188,13 @@ Status MlirFunctionOptimizationPass::Run(
192188 << " None of the MLIR Optimization Passes are enabled "
193189 << " (registered " << registry_->passes ().size () << " )" ;
194190 }
191+ // Capture stats on graph properties analyzed before running the MLIR
192+ // bridge. We set `uses_uninitialized_resource_args` to false here because
193+ // function optimization is not affected by uninitialized resource args.
194+ // TODO(b/241853328): Remove LogGraphFeatures when fixed
195+ LogGraphFeatures (**graph, flib_def, config_proto,
196+ /* uses_uninitialized_resource_args=*/ false ,
197+ /* is_v1_compat=*/ false );
195198 return OkStatus ();
196199 }
197200
@@ -244,6 +247,14 @@ Status MlirFunctionOptimizationPass::Run(
244247 std::move (module_ref_status.ValueOrDie ());
245248 AddDevicesToOp (*module_ref, &device_set);
246249
250+ // Capture stats on graph properties analyzed before running the MLIR
251+ // bridge. We set `uses_uninitialized_resource_args` to false here because
252+ // function optimization is not affected by uninitialized resource args.
253+ // TODO (b/241853328) Remove LogGraphFeatures when fixed
254+ LogGraphFeatures (**graph, flib_def, config_proto,
255+ /* uses_uninitialized_resource_args=*/ false ,
256+ /* is_v1_compat=*/ false );
257+
247258 int per_pass_state_index = 0 ;
248259 for (auto & pass_registration : registry_->passes ()) {
249260 llvm::StringRef name = pass_registration.pass ->name ();
@@ -381,11 +392,18 @@ Status MlirV1CompatGraphOptimizationPass::Run(
381392
382393 llvm::StringRef name = pass->name ();
383394 VLOG (2 ) << " Run MLIR V1 graph optimization pass: " << StringRefToView (name);
395+ // If we ever have more than one MlirV1CompatOptimization pass we need to
396+ // ensure the logging only happens once per graph to avoid redundant logging
397+ // (see how it is used in the MLIRFunctionOptimizationPass as an example)
398+ // TODO(b/241853328): Remove LogGraphFeatures when fixed
399+ LogGraphFeatures (**options.graph , options.flib_def ,
400+ options.session_options ->config ,
401+ /* uses_uninitialized_resource_args=*/ false ,
402+ /* is_v1_compat=*/ true );
384403
385404 if (VLOG_IS_ON (1 )) {
386405 DumpModule (*module_ref, llvm::formatv (" mlir_{0}_before_" , name));
387406 }
388-
389407 Status pass_status = pass->Run (options, *module_ref);
390408
391409 if (!pass_status.ok ()) {
0 commit comments