xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/tf2xla/const_analysis.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2017 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_TF2XLA_CONST_ANALYSIS_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_CONST_ANALYSIS_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/core/graph/graph.h"
22 #include "tensorflow/core/lib/core/status.h"
23 
24 namespace tensorflow {
25 
26 // Backwards dataflow analysis that finds nodes in a graph that must be
27 // compile-time constants for us to be able to lower the graph to XLA.
28 //
29 // The indices of the arguments to `graph` that must be constant are returned in
30 // `compile_time_const_arg_indices`, if `compile_time_const_arg_indices` is not
31 // null.
32 //
33 // The ids of the nodes in `graph` that must be constant are returned in
34 // `compile_time_const_nodes`, if `compile_time_const_nodes` is not null.
35 //
36 // If `edge_filter` is non-null, only propagate const-ness along edges for which
37 // `edge_filter` returns true.
38 Status BackwardsConstAnalysis(
39     const Graph& g, std::vector<bool>* compile_time_const_arg_indices,
40     std::vector<bool>* compile_time_const_nodes,
41     FunctionLibraryRuntime* flib_runtime,
42     std::function<bool(const Edge&)> edge_filter_input = nullptr);
43 
44 // Given an op kernel and function library runtime, return all the indices of
45 // inputs that need to be compile time constant.
46 Status GetCompileTimeConstInputs(const OpKernel* op_kernel,
47                                  std::vector<int>* const_input_idxs,
48                                  FunctionLibraryRuntime* flib_runtime);
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_COMPILER_TF2XLA_CONST_ANALYSIS_H_
52