ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Node.cpp
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#include "loco/IR/Node.h"
18#include "loco/IR/Use.h"
19
20#include <cassert>
21
22namespace loco
23{
24
26{
27 // To detect dangling references
28 assert(_uses.size() == 0);
29}
30
31std::set<Node *> preds(const Node *node)
32{
33 std::set<Node *> res;
34
35 for (uint32_t n = 0; n < node->arity(); ++n)
36 {
37 if (auto pred = node->arg(n))
38 {
39 res.insert(pred);
40 }
41 }
42
43 return res;
44}
45
46std::set<Node *> succs(const Node *node)
47{
48 std::set<Node *> res;
49
50 for (auto use : node->_uses)
51 {
52 auto user = use->user();
53 assert(user != nullptr);
54 res.insert(user);
55 }
56
57 return res;
58}
59
61{
62 // _from SHOULD be valid
63 assert(_from != nullptr);
64}
65
67{
68 if (_from == into)
69 {
70 return;
71 }
72
73 auto *uses = &(_from->_uses);
74
75 while (!uses->empty())
76 {
77 auto use = *(uses->begin());
78 use->node(into);
79 }
80}
81
83{
84 // Let's create Subst<SubstQualifier::Default>!
86}
87
88} // namespace loco
Logical unit of computation.
Definition Node.h:54
virtual Node * arg(uint32_t N) const =0
Access N-th argument node.
virtual uint32_t arity(void) const =0
Return the number of arguments.
virtual ~Node()
Definition Node.cpp:25
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
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82