Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / ir / OpSequence.h
1 /*
2  * Copyright (c) 2019 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_OP_SEQUENCE_H__
18 #define __ONERT_IR_OP_SEQUENCE_H__
19
20 #include <vector>
21 #include <string>
22 #include <memory>
23
24 #include "ir/Layout.h"
25 #include "ir/Index.h"
26 #include "ir/Operation.h"
27
28 namespace onert
29 {
30 namespace ir
31 {
32
33 class Operations;
34
35 class OpSequence
36 {
37 public:
38   explicit OpSequence(Layout layout);
39   OpSequence(const OpSequence &) = delete;
40
41 public:
42   void accept(OperationVisitor &v) const;
43
44 public:
45   const OperandIndexSequence &getInputs() const { return _inputs; }
46   const OperandIndexSequence &getOutputs() const { return _outputs; }
47   void setInputs(const OperandIndexSequence &indexes) { _inputs = indexes; }
48   void setOutputs(const OperandIndexSequence &indexes) { _outputs = indexes; }
49   void replaceInputs(const OperandIndex &from, const OperandIndex &to)
50   {
51     _inputs.replace(from, to);
52   }
53   void replaceOutputs(const OperandIndex &from, const OperandIndex &to)
54   {
55     _outputs.replace(from, to);
56   }
57
58   void appendOperation(const OperationIndex &index) { _operations.emplace_back(index); }
59
60   std::vector<OperationIndex> &operations(void) { return _operations; }
61
62   const std::vector<OperationIndex> &operations(void) const { return _operations; }
63
64   uint32_t size(void) const { return _operations.size(); }
65
66 public:
67   void remove(const OperationIndex &index);
68
69   bool exist(const OperationIndex &index) const;
70
71 public:
72   Layout getLayout() const { return _layout; }
73
74 public:
75   std::vector<OperationIndex>::const_iterator begin() const { return _operations.begin(); }
76   std::vector<OperationIndex>::const_iterator end() const { return _operations.end(); }
77
78 public:
79   /**
80    * @brief Set @c true if any operation in this opSequence has dynamic input
81    *        or dynamic output;
82    *        @c false if all operations' inputs and outputs are static tensors
83    */
84   void has_dynamic_tensor(bool has_dynamic_tensor) { _has_dynamic_tensor = has_dynamic_tensor; }
85   bool has_dynamic_tensor() const { return _has_dynamic_tensor; }
86
87 private:
88   OperandIndexSequence _inputs;
89   OperandIndexSequence _outputs;
90   std::vector<OperationIndex> _operations;
91
92 private:
93   Layout _layout;
94   bool _has_dynamic_tensor;
95 };
96
97 std::string getStrFromOpSeq(const OpSequence &op_seq, const Operations &operations);
98
99 } // namespace ir
100 } // namespace onert
101
102 #endif // __ONERT_IR_OP_SEQUENCE_H__