ONE - On-device Neural Engine
Loading...
Searching...
No Matches
NodeMixins.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 __DIALECT_IR_NODEMIXINS_H__
18#define __DIALECT_IR_NODEMIXINS_H__
19
20#include <loco/IR/Node.h>
21
22namespace locoex
23{
24
30template <unsigned N, typename Base> class FixedArityNode : public Base
31{
32public:
34 {
35 for (uint32_t n = 0; n < N; ++n)
36 {
37 _args[n] = std::unique_ptr<loco::Use>(new loco::Use{this});
38 }
39 }
40
41 virtual ~FixedArityNode() = default;
42
43public:
44 unsigned arity(void) const final { return N; }
45
46 loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); }
47
48 void drop(void) final
49 {
50 for (uint32_t n = 0; n < N; ++n)
51 {
52 _args.at(n)->node(nullptr);
53 }
54 }
55
56protected:
57 // This API allows inherited classes to access "_args" field.
58 loco::Use *at(unsigned n) const { return _args.at(n).get(); }
59
60private:
61 std::array<std::unique_ptr<loco::Use>, N> _args{};
62};
63
64} // namespace locoex
65
66#endif // __DIALECT_IR_NODEMIXINS_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 fixed number of inputs.
Definition NodeMixins.h:31
virtual ~FixedArityNode()=default
loco::Node * arg(uint32_t n) const final
Definition NodeMixins.h:46
unsigned arity(void) const final
Definition NodeMixins.h:44
void drop(void) final
Definition NodeMixins.h:48
loco::Use * at(unsigned n) const
Definition NodeMixins.h:58