Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / include / luci / IR / Nodes / CircleIf.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 __LUCI_IR_CIRCLE_IF_H__
18 #define __LUCI_IR_CIRCLE_IF_H__
19
20 #include "luci/IR/CircleNodeDecl.h"
21 #include "luci/IR/CircleOpcode.h"
22
23 #include "luci/IR/VariadicArityNode.h"
24
25 #include <cassert>
26
27 namespace luci
28 {
29
30 /**
31  * @brief IF in Circle
32  */
33 class CircleIf final : public VariadicArityNode<CircleNodeImpl<CircleOpcode::IF>>
34 {
35 public:
36   CircleIf(uint32_t arity, uint32_t out)
37       : VariadicArityNode<CircleNodeImpl<CircleOpcode::IF>>(arity + 1), _output_count(out)
38   {
39     assert(arity > 0);
40     assert(out > 0);
41   }
42
43 public:
44   uint32_t input_count(void) const { return arity() - 1; }
45   uint32_t output_count(void) const { return _output_count; }
46
47 public:
48   Node *cond(void) const { return at(0)->node(); }
49   void cond(Node *node) { at(0)->node(node); }
50
51   Node *input(uint32_t index) const { return at(index + 1)->node(); }
52   void input(uint32_t index, Node *node) { at(index + 1)->node(node); }
53
54 public:
55   int32_t then_branch(void) const { return _then_branch; }
56   void then_branch(int32_t then_branch) { _then_branch = then_branch; }
57
58   int32_t else_branch(void) const { return _else_branch; }
59   void else_branch(int32_t else_branch) { _else_branch = else_branch; }
60
61 public:
62   loco::Graph *then_graph(void) const { return _then_graph; }
63   void then_graph(loco::Graph *then_graph) { _then_graph = then_graph; }
64
65   loco::Graph *else_graph(void) const { return _else_graph; }
66   void else_graph(loco::Graph *else_graph) { _else_graph = else_graph; }
67
68 private:
69   uint32_t _output_count{0};
70   int32_t _then_branch{-1};
71   int32_t _else_branch{-1};
72
73   loco::Graph *_then_graph{nullptr};
74   loco::Graph *_else_graph{nullptr};
75 };
76
77 } // namespace luci
78
79 #endif // __LUCI_IR_CIRCLE_IF_H__