• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
31  private:
32   void runOnFunction() override;
33 };
34 
runOnFunction()35 void RuntimeVerifyPass::runOnFunction() {
36   getFunction().walk([&](TflRuntimeVerifyOpInterface op) {
37     if (failed(op.VerifyTflRuntimeConstraints(op.getOperation())))
38       signalPassFailure();
39   });
40 }
41 }  // namespace
42 
43 // Verifies TFL runtime constraints.
CreateRuntimeVerifyPass()44 std::unique_ptr<OperationPass<FuncOp>> CreateRuntimeVerifyPass() {
45   return std::make_unique<RuntimeVerifyPass>();
46 }
47 
48 static PassRegistration<RuntimeVerifyPass> pass("tfl-runtime-verify",
49                                                 "TFLite runtime verification");
50 
51 }  // namespace TFL
52 }  // namespace mlir
53