docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
structured_sdfg_walker.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace sdfg::visitor {
7
48public:
50
51 static constexpr std::string_view scope_to_string(Scope scope) {
52 switch (scope) {
53 case Scope::NONE:
54 return "NONE";
55 case Scope::ENTRY:
56 return "ENTRY";
57 case Scope::EXIT:
58 return "EXIT";
59 case Scope::IF_ENTRY:
60 return "IF_ENTRY";
61 case Scope::IF_EXIT:
62 return "IF_EXIT";
64 return "IF_NEXT_BRANCH";
65 }
66 return "UNKNOWN";
67 }
68
69 class Iterator;
70
71 class ParentScopeLoc {
72 friend StructuredSDFGWalker;
73 friend Iterator;
74
75 ControlFlowNode* node_;
76 int32_t idx_;
77 ParentScopeLoc(ControlFlowNode* node, int32_t idx) : node_(node), idx_(idx) {
78 }
79 };
80
81 class Iterator {
82 friend StructuredSDFGWalker;
83
84 private:
85 ControlFlowNode* node_;
86 int32_t idx_;
87 std::list<ParentScopeLoc> parent_cache_;
88
89 Iterator(ControlFlowNode* node, int32_t idx);
90
91 Iterator& next_internal(bool descend);
92
93 void move_to_parent_next(ControlFlowNode* child, bool descend);
94
95 //
96 void move_to_next_child(ControlFlowNode* parent, int32_t prev_idx, bool descend, ParentScopeLoc* parent_cache);
97 void move_to_next_seq_child(Sequence* parent, int32_t prev_idx, bool descend, ParentScopeLoc* parent_cache);
98 void move_to_next_ifelse_child(IfElse* parent, int32_t prev_idx, bool descend, ParentScopeLoc* parent_cache);
99 void move_to_next_loop_child(ControlFlowNode* parent, ParentScopeLoc* parent_cache);
100
101 void set_enter_node_idx(ControlFlowNode& child, bool descend);
102
103 public:
104 bool operator!=(const Iterator& other) const;
105 Iterator& operator++();
106
110 Iterator& next();
111
115 Iterator& next_no_descend();
116 std::pair<ControlFlowNode&, Scope> operator*() const;
117 };
118
119private:
120 static constexpr int32_t NO_SCOPE_FLAG = 0x80000000;
121 static constexpr int32_t SCOPE_MASK = 0x8000007F;
122 static constexpr int32_t SCOPE_ANY_MASK = 0x70;
123 static constexpr int32_t SCOPE_ENTRY_FLAG = 0x00000001;
124 static constexpr int32_t SCOPE_EXIT_FLAG = 0x00000002;
125 static constexpr int32_t SEQ_FLAG = 0x80000010;
126 static constexpr int32_t SEQ_MASK = 0x8000001F;
127 static constexpr int32_t SEQ_ENTER = SEQ_FLAG | SCOPE_ENTRY_FLAG;
128 static constexpr int32_t SEQ_EXIT = SEQ_FLAG | SCOPE_EXIT_FLAG;
129 static constexpr int32_t LOOP_FLAG = 0x80000020;
130 static constexpr int32_t LOOP_MASK = 0x8000002F;
131 static constexpr int32_t LOOP_ENTER = LOOP_FLAG | SCOPE_ENTRY_FLAG;
132 static constexpr int32_t LOOP_EXIT = LOOP_FLAG | SCOPE_EXIT_FLAG;
133 static constexpr int32_t IFELSE_FLAG = 0x80000040;
134 static constexpr int32_t IFELSE_MASK = 0x8000004F;
135 static constexpr int32_t IFELSE_ENTER = IFELSE_FLAG | SCOPE_ENTRY_FLAG;
136 static constexpr int32_t IFELSE_EXIT = IFELSE_FLAG | SCOPE_EXIT_FLAG;
137
138public:
142 static Iterator ifelse_exit(IfElse& ifelse);
143 static Iterator loop_exit(While& loop);
145 static Iterator end();
146
148
149protected:
150};
151
152inline std::ostream& operator<<(std::ostream& os, StructuredSDFGWalker::Scope scope) {
154 return os;
155}
156
157} // namespace sdfg::visitor
Definition structured_sdfg.h:30
Base class for all structured control flow nodes in a StructuredSDFG.
Definition control_flow_node.h:44
Represents a conditional if-else control flow node with multiple cases.
Definition if_else.h:47
A sequential container of control flow nodes.
Definition sequence.h:52
Base class for structured loop constructs.
Definition structured_loop.h:244
Represents a while-loop with condition-controlled iteration.
Definition while.h:37
Definition structured_sdfg_walker.h:81
std::pair< ControlFlowNode &, Scope > operator*() const
Iterator & next_no_descend()
Move to next entry in exec order, but do not descend into scopes, just visit scopes as Leafs.
Iterator & next()
Move to next entry in exec order.
bool operator!=(const Iterator &other) const
Definition structured_sdfg_walker.h:71
A sequential walker for traversing structured control flow nodes in a StructuredSDFG with iterators I...
Definition structured_sdfg_walker.h:47
static Iterator loop_exit(StructuredLoop &loop)
static Iterator from_node(ControlFlowNode &node)
static Iterator root(StructuredSDFG &sdfg)
static constexpr std::string_view scope_to_string(Scope scope)
Definition structured_sdfg_walker.h:51
static Iterator ifelse_exit(IfElse &ifelse)
static Iterator loop_exit(While &loop)
static Iterator from_after(ControlFlowNode &node)
Scope
Definition structured_sdfg_walker.h:49
@ ENTRY
Definition structured_sdfg_walker.h:49
@ IF_EXIT
Definition structured_sdfg_walker.h:49
@ IF_NEXT_BRANCH
Definition structured_sdfg_walker.h:49
@ EXIT
Definition structured_sdfg_walker.h:49
@ NONE
Definition structured_sdfg_walker.h:49
@ IF_ENTRY
Definition structured_sdfg_walker.h:49
static Iterator sequence_exit(Sequence &seq)
Definition control_flow_node.h:16
std::ostream & operator<<(std::ostream &os, StructuredSDFGWalker::Scope scope)
Definition structured_sdfg_walker.h:152
Definition analysis.h:7