Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / ir / OpSequences.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_SEQUENCES_H__
18 #define __ONERT_IR_OP_SEQUENCES_H__
19
20 #include "ir/Index.h"
21 #include "ir/OpSequence.h"
22 #include "util/ObjectManager.h"
23
24 namespace onert
25 {
26 namespace ir
27 {
28
29 /**
30  * @brief Class that manages OpSequence objects
31  */
32 class OpSequences : public util::ObjectManager<OpSequenceIndex, OpSequence>
33 {
34 public:
35   /**
36    * @brief Create an instance of OpSequence with given op and push it to objects
37    *
38    * @param[in] op_idx Operation index that is emplaced
39    * @param[in] layout OpSequence's layout
40    * @return OpSequenceIndex
41    */
42   OpSequenceIndex emplace(const OperationIndex &op_index, Layout layout);
43
44   /**
45    * @brief Push an instance of OpSequence to objects
46    *
47    * @param[in] op_seq An instance of OpSequence
48    * @return OpSequenceIndex
49    */
50   OpSequenceIndex emplace(std::unique_ptr<OpSequence> &&op_seq);
51   /**
52    * @brief Check if an operation does exist in any OpSequences
53    *
54    * @param operation_index Operation index to find
55    * @return true If such operation exists in any OpSequences otherwise false
56    */
57   bool containsOperation(const OperationIndex &operation_index) const;
58   /**
59    * @brief Find an operation from all OpSequences
60    *
61    * @param operation_index Operation index to find
62    * @return OpSequenceIndex Index of OpSequence that contains given operation index
63    */
64   OpSequenceIndex getOperation(const OperationIndex &operation_index) const;
65   /**
66    * @brief Dump OpSequences
67    *
68    * @param msg Message that will be displayed
69    * @param graph Graph that has information used for dump
70    */
71   void dump(const std::string &msg, const Operations &operations) const;
72   /**
73    * @brief Remove an operation from OpSequence
74    *
75    * @param operation_index Operation index to be removed
76    */
77   void removeFromOpSequence(const OperationIndex &operation_index);
78
79 private:
80   void cacheSequenceIndex(const OpSequenceIndex &seq_index, const OperationIndex &op_index) const;
81   OpSequenceIndex *findSequenceIndex(const OperationIndex &operation_index) const;
82
83   OpSequenceIndex findOperation(const OperationIndex &operation_index) const;
84   mutable std::unordered_map<OperationIndex, OpSequenceIndex> _seq_indexes;
85 };
86
87 } // namespace ir
88 } // namespace onert
89
90 #endif // __ONERT_IR_OP_SEQUENCES_H__