Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / Operand.cc
1 /*
2  * Copyright (c) 2018 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 #include "ir/Operand.h"
18
19 namespace onert
20 {
21 namespace ir
22 {
23
24 size_t Operand::operandSize(void) const
25 {
26   const uint32_t ranks = shape().rank();
27   int32_t elements = 1;
28
29   for (uint32_t rank = 0; rank < ranks; rank++)
30   {
31     elements *= shape().dim(rank);
32   }
33
34   DataType type = typeInfo().type();
35   size_t element_size = sizeOfDataType(type);
36
37   // Value of type is matched with OperandCode enum in NeuralNetworks.h
38   return element_size * elements;
39 }
40
41 void Operand::insertUse(const OperationIndex &idx) { _uses.insert(idx); }
42
43 void Operand::removeUse(const OperationIndex &idx) { _uses.remove(idx); }
44
45 void Operand::setDef(const OperationIndex &idx) { _def = idx; }
46
47 void Operand::unsetDef() { _def = OperationIndex{}; }
48
49 } // namespace ir
50 } // namespace onert