ONE - On-device Neural Engine
Loading...
Searching...
No Matches
VariadicArityNode.h
Go to the documentation of this file.
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 __LOCOEX_VARIADICARITYNODES_OP_H__
18#define __LOCOEX_VARIADICARITYNODES_OP_H__
19
20#include <loco/IR/Node.h>
21#include <loco/IR/Use.h>
22
23#include <vector>
24#include <memory>
25#include <cassert>
26
27namespace locoex
28{
29
33template <typename Base> class VariadicArityNode : public Base
34{
35public:
37 {
38 for (uint32_t n = 0; n < arity; ++n)
39 {
40 _args.emplace_back(std::move(std::unique_ptr<loco::Use>{new loco::Use{this}}));
41 }
42 };
43
44 virtual ~VariadicArityNode() = default;
45
46public:
47 uint32_t arity(void) const final { return _args.size(); }
48
49 loco::Node *arg(uint32_t n) const final
50 {
51 assert(n < _args.size());
52 return _args.at(n)->node();
53 }
54
55 void drop(void) final
56 {
57 for (uint32_t n = 0; n < _args.size(); ++n)
58 {
59 _args.at(n)->node(nullptr);
60 }
61 }
62
63protected:
64 // This API allows inherited classes to access "_args" field.
65 loco::Use *at(uint32_t n) const
66 {
67 assert(n < _args.size());
68 return _args.at(n).get();
69 }
70
71private:
72 std::vector<std::unique_ptr<loco::Use>> _args;
73};
74
75} // namespace locoex
76
77#endif // __LOCOEX_VARIADICARITYNODES_OP_H__
Logical unit of computation.
Definition Node.h:54
The edge between a node definition and its user.
Definition Use.h:37
Nodes with the variadic inputs.
loco::Node * arg(uint32_t n) const final
virtual ~VariadicArityNode()=default
uint32_t arity(void) const final
VariadicArityNode(uint32_t arity)
loco::Use * at(uint32_t n) const