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_TF2XLA_KERNELS_IF_WHILE_UTILS_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_KERNELS_IF_WHILE_UTILS_H_
18 
19 #include "tensorflow/compiler/tf2xla/xla_op_kernel.h"
20 #include "tensorflow/core/lib/core/status.h"
21 
22 namespace tensorflow {
23 
24 extern const char kPropagateCompileTimeConsts[];
25 
26 // Convert arguments in `args` to constants provided they are compile-time
27 // constants and they satisfy the condition in `should_resolve_constant`. The
28 // argument `xla_expression_offset` determines what offset is needed to get the
29 // input expression from context given the argument index in `args`.
30 //
31 // Returns a list of indices which were converted to constants.
32 absl::InlinedVector<int, 5> ConvertCompileTimeConstArgumentsToConst(
33     XlaOpKernelContext* ctx, std::vector<XlaCompiler::Argument>* args,
34     int xla_expression_offset,
35     std::function<bool(int arg_idx)> should_resolve_constant);
36 
37 // Find and populate `must_be_const_nodes` and `body` of the function
38 // corresponding to the kernel with context `ctx` with name `func_name`.
39 Status FindMustBeConstNodes(XlaOpKernelContext* ctx,
40                             const NameAttrList& func_name,
41                             std::vector<bool>* must_be_const_nodes,
42                             const FunctionBody** body);
43 
44 }  // namespace tensorflow
45 
46 #endif  // TENSORFLOW_COMPILER_TF2XLA_KERNELS_IF_WHILE_UTILS_H_
47