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/IR/OperationSupport.h" // from @llvm-project 17 #include "mlir/Pass/Pass.h" // from @llvm-project 18 #include "tensorflow/compiler/mlir/lite/ir/tfl_ops.h" 19 #include "tensorflow/compiler/mlir/lite/transforms/passes.h" 20 21 namespace mlir { 22 #include "tensorflow/compiler/mlir/lite/ir/tfl_ops_interface.h.inc" 23 namespace TFL { 24 namespace { 25 #define GEN_PASS_CLASSES 26 #include "tensorflow/compiler/mlir/lite/transforms/passes.h.inc" 27 28 // This pass verifies that the TFL ops meet the TFL runtime constraints. 29 class RuntimeVerifyPass : public RuntimeVerifyPassBase<RuntimeVerifyPass> { 30 public: 31 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(RuntimeVerifyPass) 32 RuntimeVerifyPass()33 explicit RuntimeVerifyPass() {} 34 35 private: 36 void runOnOperation() override; 37 }; 38 runOnOperation()39void RuntimeVerifyPass::runOnOperation() { 40 getOperation().walk([&](TflRuntimeVerifyOpInterface op) { 41 if (failed(op.VerifyTflRuntimeConstraints( 42 op.getOperation(), /*emit_error_on_verify_fail=*/true))) 43 signalPassFailure(); 44 }); 45 } 46 } // namespace 47 48 // Verifies TFL runtime constraints. CreateRuntimeVerifyPass()49std::unique_ptr<OperationPass<func::FuncOp>> CreateRuntimeVerifyPass() { 50 return std::make_unique<RuntimeVerifyPass>(); 51 } 52 53 } // namespace TFL 54 } // namespace mlir 55