Jlm
Loading...
Searching...
No Matches
structural-node.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_STRUCTURAL_NODE_HPP
7#define JLM_RVSDG_STRUCTURAL_NODE_HPP
8
9#include <jlm/rvsdg/node.hpp>
10#include <jlm/rvsdg/region.hpp>
13
14namespace jlm::rvsdg
15{
16
17/* structural node */
18
19class StructuralInput;
20class StructuralOperation;
21class StructuralOutput;
22
23class StructuralNode : public Node
24{
29
32
33public:
35
37 StructuralNode(rvsdg::Region * region, size_t nsubregions);
38
39public:
40 std::string
42
43 inline size_t
45 {
46 return subregions_.size();
47 }
48
50 subregion(size_t index) const noexcept
51 {
52 JLM_ASSERT(index < nsubregions());
53 return subregions_[index].get();
54 }
55
58 {
60 }
61
63 Subregions() const
64 {
65 return { SubregionConstIterator(subregions_.begin()),
67 }
68
69 [[nodiscard]] inline StructuralInput *
70 input(size_t index) const noexcept;
71
72 [[nodiscard]] inline StructuralOutput *
73 output(size_t index) const noexcept;
74
75protected:
77 addInput(std::unique_ptr<StructuralInput> input, bool notifyRegion);
78
80 addOutput(std::unique_ptr<StructuralOutput> input);
81
82private:
83 std::vector<std::unique_ptr<rvsdg::Region>> subregions_;
84};
85
86/* structural input class */
87
90
92{
94
95public:
97
100 jlm::rvsdg::Output * origin,
101 std::shared_ptr<const rvsdg::Type> type);
102
105 {
106 return static_cast<StructuralNode *>(NodeInput::node());
107 }
108
110};
111
112/* structural output class */
113
116
118{
120
121public:
123
125
128 {
129 return static_cast<StructuralNode *>(NodeOutput::node());
130 }
131
133};
134
135/* structural node method definitions */
136
137inline StructuralInput *
138StructuralNode::input(size_t index) const noexcept
139{
140 return static_cast<StructuralInput *>(Node::input(index));
141}
142
143inline StructuralOutput *
144StructuralNode::output(size_t index) const noexcept
145{
146 return static_cast<StructuralOutput *>(Node::output(index));
147}
148
149inline StructuralInput *
150StructuralNode::addInput(std::unique_ptr<StructuralInput> input, bool notifyRegion)
151{
152 return static_cast<StructuralInput *>(Node::addInput(std::move(input), notifyRegion));
153}
154
155inline StructuralOutput *
156StructuralNode::addOutput(std::unique_ptr<StructuralOutput> output)
157{
158 return static_cast<StructuralOutput *>(Node::addOutput(std::move(output)));
159}
160
161template<class TOperation>
162bool
164{
165 static_assert(
166 std::is_base_of_v<Operation, TOperation>,
167 "Template parameter TOperation must be derived from rvsdg::Operation.");
168
169 for (auto & node : region.Nodes())
170 {
171 if (auto simpleNode = dynamic_cast<const SimpleNode *>(&node))
172 {
173 if (is<TOperation>(simpleNode->GetOperation()))
174 {
175 return true;
176 }
177 }
178
179 if (!checkSubregions)
180 {
181 continue;
182 }
183
184 if (auto structuralNode = dynamic_cast<const StructuralNode *>(&node))
185 {
186 for (size_t n = 0; n < structuralNode->nsubregions(); n++)
187 {
189 {
190 return true;
191 }
192 }
193 }
194 }
195
196 return false;
197}
198
199template<class TNodeType>
200bool
202{
203 static_assert(
204 std::is_base_of_v<Node, TNodeType>,
205 "Template parameter TNodeType must be derived from rvsdg::Node.");
206
207 for (auto & node : region.Nodes())
208 {
209 if (dynamic_cast<const TNodeType *>(&node))
210 {
211 return true;
212 }
213
214 if (!checkSubregions)
215 {
216 continue;
217 }
218
219 if (auto structuralNode = dynamic_cast<const StructuralNode *>(&node))
220 {
221 for (size_t n = 0; n < structuralNode->nsubregions(); n++)
222 {
224 {
225 return true;
226 }
227 }
228 }
229 }
230
231 return false;
232}
233
234}
235
236#endif
Output * origin() const noexcept
Definition node.hpp:58
Node * node() const noexcept
Definition node.hpp:560
Node * node() const noexcept
Definition node.hpp:572
NodeInput * input(size_t index) const noexcept
Definition node.hpp:615
NodeOutput * output(size_t index) const noexcept
Definition node.hpp:650
rvsdg::Region * region() const noexcept
Definition node.hpp:761
NodeOutput * addOutput(std::unique_ptr< NodeOutput > output)
Definition node.hpp:732
NodeInput * addInput(std::unique_ptr< NodeInput > input, bool notifyRegion)
Definition node.cpp:288
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
static bool containsNodeType(const Region &region, bool checkSubregions)
static bool containsOperation(const Region &region, bool checkSubregions)
rvsdg::StructuralNode * node() const noexcept
Definition region.hpp:301
NodeRange Nodes() noexcept
Definition region.hpp:375
~StructuralInput() noexcept override
StructuralNode * node() const noexcept
SubregionConstIteratorRange Subregions() const
util::PtrIterator< const Region, std::vector< std::unique_ptr< Region > >::const_iterator > SubregionConstIterator
std::string DebugString() const override
~StructuralNode() noexcept override
StructuralInput * addInput(std::unique_ptr< StructuralInput > input, bool notifyRegion)
StructuralOutput * addOutput(std::unique_ptr< StructuralOutput > input)
SubregionIteratorRange Subregions()
util::IteratorRange< SubregionIterator > SubregionIteratorRange
std::vector< std::unique_ptr< rvsdg::Region > > subregions_
util::PtrIterator< Region, std::vector< std::unique_ptr< Region > >::iterator > SubregionIterator
rvsdg::Region * subregion(size_t index) const noexcept
size_t nsubregions() const noexcept
StructuralOutput * output(size_t index) const noexcept
StructuralInput * input(size_t index) const noexcept
util::IteratorRange< SubregionConstIterator > SubregionConstIteratorRange
~StructuralOutput() noexcept override
StructuralNode * node() const noexcept
#define JLM_ASSERT(x)
Definition common.hpp:16
jlm::util::IntrusiveList< RegionResult, RegionResult::structural_output_accessor > result_list
jlm::util::IntrusiveList< RegionArgument, RegionArgument::structural_input_accessor > argument_list
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872