1 /* Copyright 2020 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_MLIR_TENSORFLOW_TRANSFORMS_RESOURCE_OP_LIFTING_CLEANUP_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_RESOURCE_OP_LIFTING_CLEANUP_H_
18 
19 #include "mlir/Dialect/Func/IR/FuncOps.h"  // from @llvm-project
20 #include "mlir/IR/BuiltinOps.h"  // from @llvm-project
21 #include "mlir/IR/TypeUtilities.h"  // from @llvm-project
22 #include "mlir/IR/Types.h"  // from @llvm-project
23 
24 // Performs IR cleanup and canonicalization in preparation for Resource Op
25 // Lifting pass. It does several things:
26 // - Eliminate identity nodes to remove (most) of resource aliasing
27 // - Canonicalize functional control flow. For functional control flow we
28 //   expect that any resource output of these ops matches the corresponding
29 //   input, and then forward that input to the output. Fails if this is not the
30 //   case. If successful, the following invariants will hold true:
31 //   (a) For if/case, any resource type results will be deleted.
32 //   (b) For while, any resource type results will be unused.
33 // - Canonicalize region based control flow. Again, any resource outputs are
34 //   expected to be resolved to be one of the captured resource inputs. Fails
35 //   if this is not the case. If successful, the following invariants will hold
36 //   true:
37 //   (a) For if/case, any resource type results will be deleted.
38 //   (b) For while, any resource type results will be unused.
39 namespace mlir {
40 namespace TF {
41 LogicalResult CleanupAndCanonicalizeForResourceOpLifting(ModuleOp module);
42 LogicalResult CleanupAndCanonicalizeForResourceOpLifting(func::FuncOp func);
43 
44 }  // namespace TF
45 }  // namespace mlir
46 
47 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_TRANSFORMS_RESOURCE_OP_LIFTING_CLEANUP_H_
48