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 <cstdint>
30#include <memory>
31#include <set>
32
33namespace loco
34{
35
40{
41 virtual ~NodeAnnotation() = default;
42};
43
45{
46 Default, // Replace all the occurrences as "Use" (by default)
47};
48
49template <SubstQualifier Q> class Subst;
50
54class Node : public AnnotatedItem<NodeAnnotation>
55{
56public:
57 friend class Use;
58 friend class Subst<SubstQualifier::Default>;
60 friend std::set<Node *> succs(const Node *node);
61
62public:
63 Node() = default;
64
65 Node(const Node &) = delete;
66 Node(Node &&) = delete;
67
68 virtual ~Node();
69
70public:
71 Graph *graph(void) { return _graph; }
72 const Graph *graph(void) const { return _graph; }
73
74private:
80 void graph(Graph *g) { _graph = g; }
81
82public:
88 virtual const Dialect *dialect(void) const = 0;
89
90 virtual uint32_t opnum(void) const = 0;
91
92public:
94 virtual uint32_t arity(void) const = 0;
95
97 virtual Node *arg(uint32_t N) const = 0;
98
104 virtual void drop(void) = 0;
105
106private:
112 Graph *_graph = nullptr;
113
119 std::set<Use *> _uses;
120};
121
123std::set<Node *> preds(const Node *node);
125std::set<Node *> succs(const Node *node);
126
130template <> class Subst<SubstQualifier::Default>
131{
132public:
134
135private:
136 explicit Subst(Node *from);
137
138public:
139 void with(Node *into) const;
140
141private:
142 Node *_from;
143};
144
146
150template <typename T> T must_cast(Node *node) { return _must_cast<T, Node *>(node); }
151
152template <typename T> T must_cast(const Node *node) { return _must_cast<T, const Node *>(node); }
153
154} // namespace loco
155
156#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:55
virtual Node * arg(uint32_t N) const =0
Access N-th argument node.
Graph * graph(void)
Definition Node.h:71
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:72
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:45
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:40
virtual ~NodeAnnotation()=default