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 #include "mlir/Transforms/Passes.h" // from @llvm-project 16 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h" 17 #include "tensorflow/compiler/mlir/tfrt/transforms/passes.h" 18 19 namespace tensorflow { 20 namespace tfrt_compiler { 21 namespace { 22 23 class SetShapeInvariantInWhileOps 24 : public mlir::PassWrapper<SetShapeInvariantInWhileOps, 25 mlir::OperationPass<mlir::FuncOp>> { 26 public: runOnOperation()27 void runOnOperation() override { 28 mlir::FuncOp func_op = getOperation(); 29 30 auto shape_invariant = mlir::UnitAttr::get(&getContext()); 31 32 func_op.walk( 33 [&](mlir::TF::WhileOp op) { op.shape_invariantAttr(shape_invariant); }); 34 } 35 }; 36 37 } // namespace 38 39 std::unique_ptr<mlir::OperationPass<mlir::FuncOp>> CreateSetShapeInvariantInWhileOps()40CreateSetShapeInvariantInWhileOps() { 41 return std::make_unique<SetShapeInvariantInWhileOps>(); 42 } 43 44 } // namespace tfrt_compiler 45 } // namespace tensorflow 46