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 20 namespace mlir { 21 #include "tensorflow/compiler/mlir/lite/ir/tfl_ops_interface.h.inc" 22 namespace TFL { 23 namespace { 24 25 // This pass verifies that the TFL ops meet the TFL runtime constraints. 26 class RuntimeVerifyPass 27 : public mlir::PassWrapper<RuntimeVerifyPass, FunctionPass> { 28 public: RuntimeVerifyPass()29 explicit RuntimeVerifyPass() {} 30 getArgument() const31 StringRef getArgument() const final { 32 // This is the argument used to refer to the pass in 33 // the textual format (on the commandline for example). 34 return "tfl-runtime-verify"; 35 } getDescription() const36 StringRef getDescription() const final { 37 // This is a brief description of the pass. 38 return "TFLite runtime verification"; 39 } 40 41 private: 42 void runOnFunction() override; 43 }; 44 runOnFunction()45void RuntimeVerifyPass::runOnFunction() { 46 getFunction().walk([&](TflRuntimeVerifyOpInterface op) { 47 if (failed(op.VerifyTflRuntimeConstraints(op.getOperation()))) 48 signalPassFailure(); 49 }); 50 } 51 } // namespace 52 53 // Verifies TFL runtime constraints. CreateRuntimeVerifyPass()54std::unique_ptr<OperationPass<FuncOp>> CreateRuntimeVerifyPass() { 55 return std::make_unique<RuntimeVerifyPass>(); 56 } 57 58 static PassRegistration<RuntimeVerifyPass> pass; 59 60 } // namespace TFL 61 } // namespace mlir 62