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 #include "mlir/Pass/Pass.h" // from @llvm-project 17 #include "mlir/Pass/PassRegistry.h" // from @llvm-project 18 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_device.h" 19 #include "tensorflow/compiler/mlir/tensorflow/ir/tf_ops.h" 20 #include "tensorflow/compiler/mlir/tensorflow/transforms/passes_detail.h" 21 22 namespace mlir { 23 namespace TF { 24 25 namespace { 26 27 constexpr char kShapeInvariantAttr[] = "shape_invariant"; 28 29 class DropWhileShapeInvariantPass 30 : public DropWhileShapeInvariantPassBase<DropWhileShapeInvariantPass> { 31 void runOnOperation() override; 32 }; 33 34 class DropWhileShapeInvariantInDeviceClusterPass 35 : public DropWhileShapeInvariantInDeviceClusterPassBase< 36 DropWhileShapeInvariantInDeviceClusterPass> { 37 void runOnOperation() override; 38 }; 39 DropWhileShapeInvariantAttr(Operation * op)40void DropWhileShapeInvariantAttr(Operation* op) { 41 if (llvm::isa<WhileOp, WhileRegionOp>(op)) 42 op->removeAttr(kShapeInvariantAttr); 43 } runOnOperation()44void DropWhileShapeInvariantPass::runOnOperation() { 45 getOperation().walk([](Operation* op) { DropWhileShapeInvariantAttr(op); }); 46 } 47 runOnOperation()48void DropWhileShapeInvariantInDeviceClusterPass::runOnOperation() { 49 getOperation().walk([](tf_device::ClusterOp cluster) { 50 cluster.walk([](Operation* op) { DropWhileShapeInvariantAttr(op); }); 51 }); 52 } 53 } // namespace 54 55 std::unique_ptr<OperationPass<func::FuncOp>> CreateDropWhileShapeInvariantPass()56CreateDropWhileShapeInvariantPass() { 57 return std::make_unique<DropWhileShapeInvariantPass>(); 58 } 59 60 std::unique_ptr<OperationPass<func::FuncOp>> CreateDropWhileShapeInvariantInDeviceClusterPass()61CreateDropWhileShapeInvariantInDeviceClusterPass() { 62 return std::make_unique<DropWhileShapeInvariantInDeviceClusterPass>(); 63 } 64 65 } // namespace TF 66 } // namespace mlir 67