ONE - On-device Neural Engine
Loading...
Searching...
No Matches
VariadicArityNode.h
Go to the documentation of this file.
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_VARIADICARITYNODES_H__
18#define __LUCI_IR_VARIADICARITYNODES_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 luci
28{
29
33template <typename Base> class VariadicArityNode : public Base
34{
35public:
37 {
38 for (uint32_t n = 0; n < arity; ++n)
39 {
40 _args.push_back(std::make_unique<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 { return _args.at(n)->node(); }
50
51 void drop(void) final
52 {
53 for (uint32_t n = 0; n < _args.size(); ++n)
54 {
55 _args.at(n)->node(nullptr);
56 }
57 }
58
59protected:
60 // This API allows inherited classes to access "_args" field.
61 loco::Use *at(uint32_t n) const { return _args.at(n).get(); }
62
63private:
64 std::vector<std::unique_ptr<loco::Use>> _args;
65};
66
67} // namespace luci
68
69#endif // __LUCI_IR_VARIADICARITYNODES_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
VariadicArityNode(uint32_t arity)
virtual ~VariadicArityNode()=default
loco::Use * at(uint32_t n) const
uint32_t arity(void) const final