2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_IR_GRAPH_H__
18 #define __ONERT_IR_GRAPH_H__
21 #include <unordered_map>
23 #include "ir/Operands.h"
24 #include "ir/Operations.h"
25 #include "ir/OpSequence.h"
26 #include "ir/OpSequences.h"
27 #include "ir/Subgraphs.h"
37 } // namespace backend
60 OperandIndex addOperand(const Shape &shape, const TypeInfo &type);
61 OperationIndex addOperation(std::unique_ptr<Operation> &&node);
62 void setOperandValue(const OperandIndex &ind, std::shared_ptr<Data> data);
63 void addInput(const OperandIndex &ind);
64 void addOutput(const OperandIndex &ind);
65 void finishBuilding(void);
66 void removeOperand(const OperandIndex &ind) { _operands.remove(ind); }
67 bool isBuildingPhase(void) const { return _phase == Phase::BUILDING; }
68 void setLayout(Layout layout) { _layout = layout; }
69 void setSubgraphs(const std::shared_ptr<Subgraphs> &subgs) { _subgraphs = subgs; }
72 void initializeUseDef();
73 void sweepGarbageOperands();
75 // Custom operations support
78 bindKernelBuilder(const std::shared_ptr<onert::backend::custom::IKernelBuilder> &kernel_builder)
80 _kernel_builder = kernel_builder;
83 const std::shared_ptr<backend::custom::IKernelBuilder> &getKernelBuilder() const
85 return _kernel_builder;
89 std::shared_ptr<backend::custom::IKernelBuilder> _kernel_builder;
93 const OperandIndexSequence &getInputs() const { return _inputs; }
94 OperandIndexSequence &getInputs() { return _inputs; }
95 const OperandIndexSequence &getOutputs() const { return _outputs; }
96 OperandIndexSequence &getOutputs() { return _outputs; }
97 const Operands &operands() const { return _operands; }
98 Operands &operands() { return _operands; } // TODO Remove this non-const accessor
99 const Operations &operations() const { return _operations; }
100 Operations &operations() { return _operations; }
101 const std::shared_ptr<Subgraphs> &subgraphs() const { return _subgraphs; }
102 std::shared_ptr<Subgraphs> &subgraphs() { return _subgraphs; }
103 Layout layout() const { return _layout; }
106 Phase _phase{Phase::BUILDING};
107 Operations _operations;
109 OperandIndexSequence _inputs;
110 OperandIndexSequence _outputs;
112 std::shared_ptr<Subgraphs> _subgraphs;
113 // TFLite and circle's default layout is NHWC;
114 Layout _layout{Layout::NHWC};
120 #endif // __ONERT_IR_GRAPH_H__