• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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 #ifndef TENSORFLOW_COMPILER_MLIR_TFRT_ANALYSIS_TENSOR_ARRAY_SIDE_EFFECT_ANALYSIS_H_
16 #define TENSORFLOW_COMPILER_MLIR_TFRT_ANALYSIS_TENSOR_ARRAY_SIDE_EFFECT_ANALYSIS_H_
17 
18 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
19 
20 namespace tensorflow {
21 namespace tfrt_compiler {
22 
23 // Return true if it is a TensorArrayOp, eg. TensorArrayV3Op.
24 bool IsTensorArrayOp(mlir::Operation* op);
25 
26 // This class provides utilities for analyzing side effects for TensorArray ops
27 // in the graph. mlir::TF::SideEffectAnalysis currently produces suboptimal
28 // side-effect analysis for TensorArray ops. On the other hand, control
29 // dependencies are already sorted out for TensorArray ops in the original TF
30 // graph. Each TensorArray op will take or produce a `flow` value and they are
31 // already properly chained in the origninal TF graph.
32 class TensorArraySideEffectAnalysis {
33  public:
34   explicit TensorArraySideEffectAnalysis(mlir::ModuleOp module);
35 
36   // Return if the function contains only non-side-effecting ops or TensorArray
37   // ops.
HasAtMostTensorArrayEffect(mlir::FuncOp func_op)38   bool HasAtMostTensorArrayEffect(mlir::FuncOp func_op) const {
39     return set_.count(func_op) > 0;
40   }
41 
42  private:
43   llvm::DenseSet<mlir::FuncOp> set_;
44 };
45 
46 }  // namespace tfrt_compiler
47 }  // namespace tensorflow
48 
49 #endif  // TENSORFLOW_COMPILER_MLIR_TFRT_ANALYSIS_TENSOR_ARRAY_SIDE_EFFECT_ANALYSIS_H_
50