2ea8000e5a9eec941080d00672927b3e0ccbf3a3
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / OperationValidator.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __ONERT_IR_OPERATION_VALIDATOR_H__
18 #define __ONERT_IR_OPERATION_VALIDATOR_H__
19
20 #include "ir/OperationVisitor.h"
21
22 namespace onert
23 {
24 namespace ir
25 {
26 class Graph;
27 class Operands;
28 } // namespace ir
29 } // namespace onert
30
31 namespace onert
32 {
33 namespace ir
34 {
35
36 class OperationValidator : public OperationVisitor
37 {
38 public:
39   OperationValidator(void) = delete;
40   OperationValidator(const Graph &graph);
41
42 public:
43   void operator()();
44
45 public:
46   void visit(const operation::AddN &node) override;
47   void visit(const operation::BatchMatMul &node) override;
48   void visit(const operation::BatchToSpaceND &node) override;
49   void visit(const operation::BinaryArithmetic &node) override;
50   void visit(const operation::Comparison &node) override;
51   void visit(const operation::DepthToSpace &node) override;
52   void visit(const operation::DepthwiseConv2D &node) override;
53   void visit(const operation::ElementwiseActivation &node) override;
54   void visit(const operation::ElementwiseBinary &node) override;
55   void visit(const operation::ElementwiseUnary &node) override;
56   void visit(const operation::EmbeddingLookup &node) override;
57   void visit(const operation::ExpandDims &node) override;
58   void visit(const operation::HashtableLookup &node) override;
59   void visit(const operation::Pack &node) override;
60   void visit(const operation::Pad &node) override;
61   void visit(const operation::Rank &node) override;
62   void visit(const operation::ResizeBilinear &node) override;
63   void visit(const operation::Reverse &node) override;
64   void visit(const operation::Select &node) override;
65   void visit(const operation::Shape &node) override;
66   void visit(const operation::SpaceToBatchND &node) override;
67   void visit(const operation::SpaceToDepth &node) override;
68   void visit(const operation::Split &node) override;
69   void visit(const operation::SquaredDifference &node) override;
70   void visit(const operation::StridedSlice &node) override;
71   void visit(const operation::TransposeConv &node) override;
72   void visit(const operation::Unpack &node) override;
73   void visit(const operation::While &node) override;
74
75 private:
76   DataType operandType(const OperandIndex &idx);
77   bool isConstant(const OperandIndex &idx);
78   bool isSameType(const OperandIndex &idx1, const OperandIndex &idx2);
79   bool isValidType(const OperandIndex &idx, const DataType &type);
80   bool isValidType(const OperandIndex &idx, std::initializer_list<DataType> valid_types);
81
82 private:
83   const Operations &_operations;
84   const Operands &_operands;
85 };
86
87 } // namespace ir
88 } // namespace onert
89
90 #endif // __ONERT_IR_OPERATION_VALIDATOR_H__