ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Node.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 __LOCO_IR_NODE_H__
18#define __LOCO_IR_NODE_H__
19
21
22#include "loco/IR/Use.h"
23#include "loco/IR/Dialect.h"
26#include "loco/IR/CastHelpers.h"
27
28#include <array>
29#include <memory>
30#include <set>
31
32namespace loco
33{
34
39{
40 virtual ~NodeAnnotation() = default;
41};
42
44{
45 Default, // Replace all the occurrences as "Use" (by default)
46};
47
48template <SubstQualifier Q> class Subst;
49
53class Node : public AnnotatedItem<NodeAnnotation>
54{
55public:
56 friend class Use;
57 friend class Subst<SubstQualifier::Default>;
58 friend class NodePool;
59 friend std::set<Node *> succs(const Node *node);
60
61public:
62 Node() = default;
63
64 Node(const Node &) = delete;
65 Node(Node &&) = delete;
66
67 virtual ~Node();
68
69public:
70 Graph *graph(void) { return _graph; }
71 const Graph *graph(void) const { return _graph; }
72
73private:
79 void graph(Graph *g) { _graph = g; }
80
81public:
87 virtual const Dialect *dialect(void) const = 0;
88
89 virtual uint32_t opnum(void) const = 0;
90
91public:
93 virtual uint32_t arity(void) const = 0;
94
96 virtual Node *arg(uint32_t N) const = 0;
97
103 virtual void drop(void) = 0;
104
105private:
111 Graph *_graph = nullptr;
112
118 std::set<Use *> _uses;
119};
120
122std::set<Node *> preds(const Node *node);
124std::set<Node *> succs(const Node *node);
125
129template <> class Subst<SubstQualifier::Default>
130{
131public:
133
134private:
135 explicit Subst(Node *from);
136
137public:
138 void with(Node *into) const;
139
140private:
141 Node *_from;
142};
143
145
149template <typename T> T must_cast(Node *node) { return _must_cast<T, Node *>(node); }
150
151template <typename T> T must_cast(const Node *node) { return _must_cast<T, const Node *>(node); }
152
153} // namespace loco
154
155#endif // __LOCO_IR_NODE_H__
Dialect interface.
Definition Dialect.h:37
A neural network graph.
Definition Graph.h:161
Logical unit of computation.
Definition Node.h:54
virtual Node * arg(uint32_t N) const =0
Access N-th argument node.
Graph * graph(void)
Definition Node.h:70
virtual uint32_t arity(void) const =0
Return the number of arguments.
virtual void drop(void)=0
Drop all the reference of arguments.
const Graph * graph(void) const
Definition Node.h:71
virtual const Dialect * dialect(void) const =0
Return "Dialect" identifier that this node belongs to.
friend std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
Definition Node.cpp:46
virtual uint32_t opnum(void) const =0
The edge between a node definition and its user.
Definition Use.h:37
SubstQualifier
Definition Node.h:44
std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
Definition Node.cpp:46
std::set< Node * > preds(const Node *node)
Enumerate all the predecessors of a given node.
Definition Node.cpp:31
T must_cast(FeatureEncoder *node)
A helper dynamic_cast that throws when failed.
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82
Extensible Node Metadata.
Definition Node.h:39
virtual ~NodeAnnotation()=default