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 #include "mlir/IR/BuiltinTypes.h" // from @llvm-project 17 #include "mlir/Pass/Pass.h" // from @llvm-project 18 #include "mlir/Support/LLVM.h" // from @llvm-project 19 #include "mlir/Support/LogicalResult.h" // from @llvm-project 20 #include "tensorflow/compiler/mlir/tensorflow/transforms/passes_detail.h" 21 #include "tensorflow/compiler/mlir/tensorflow/transforms/shape_inference.h" 22 #include "tensorflow/core/framework/shape_inference.h" 23 24 namespace mlir { 25 namespace TF { 26 27 namespace { 28 29 // This transformation pass propagate shapes on the TensorFlow graph. 30 // It is a ModulePass in order to be able to change function types. 31 class ShapeInference : public TensorFlowShapeInferencePassBase<ShapeInference> { 32 public: runOnOperation()33 void runOnOperation() override { 34 if (failed(InferModuleShape(getOperation(), max_iterations_))) 35 return signalPassFailure(); 36 } 37 }; 38 39 } // namespace 40 CreateTFShapeInferencePass()41std::unique_ptr<OperationPass<ModuleOp>> CreateTFShapeInferencePass() { 42 return std::make_unique<ShapeInference>(); 43 } 44 45 } // namespace TF 46 } // namespace mlir 47