docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
loop_analysis.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_set>
6
7namespace sdfg {
8namespace analysis {
9
11
12#define LOOP_INFO_PROPERTIES \
13 X(int, loopnest_index, -1) \
14 X(sdfg::ElementId, element_id, 0) \
15 X(size_t, num_loops, 0) \
16 X(size_t, num_maps, 0) \
17 X(size_t, num_fors, 0) \
18 X(size_t, num_whiles, 0) \
19 X(size_t, max_depth, 0) \
20 X(bool, is_perfectly_nested, false) \
21 X(bool, is_perfectly_parallel, false) \
22 X(bool, is_elementwise, false) \
23 X(bool, has_side_effects, false) \
24 X(uint32_t, loop_level, 0) \
25 X(uint32_t, map_stack_depth, 0)
26
30
32
37
38struct LoopInfo {
39#define X(type, name, val) type name = val;
41#undef X
42};
43
75
76inline nlohmann::json loop_info_to_json(LoopInfo info) {
77 nlohmann::json j = nlohmann::json{
78 {"loopnest_index", info.loopnest_index},
79 {"element_id", info.element_id},
80 {"num_loops", info.num_loops},
81 {"num_maps", info.num_maps},
82 {"num_fors", info.num_fors},
83 {"num_whiles", info.num_whiles},
84 {"max_depth", info.max_depth},
85 {"is_perfectly_nested", info.is_perfectly_nested},
86 {"is_perfectly_parallel", info.is_perfectly_parallel},
87 {"is_elementwise", info.is_elementwise},
88 {"has_side_effects", info.has_side_effects},
89 {"loop_level", info.loop_level},
90 {"map_stack_depth", info.map_stack_depth}
91 };
92 return j;
93}
94
95void loop_info_local_to_json(nlohmann::json& j, const LocalLoopInfo& info);
96
97class LoopAnalysis : public Analysis {
98public:
107
108private:
109 std::vector<structured_control_flow::ControlFlowNode*> loops_; // currently required in Pre-order
110 std::unordered_map<structured_control_flow::ControlFlowNode*, structured_control_flow::ControlFlowNode*> loop_tree_;
111 std::unordered_map<structured_control_flow::ControlFlowNode*, std::vector<structured_control_flow::ControlFlowNode*>>
112 loop_children_;
113
114 std::unordered_map<structured_control_flow::ControlFlowNode*, LoopState> loop_infos_;
115
124 void init_new_loop_info(
125 LoopState& info,
126 uint32_t id,
127 uint32_t loop_level,
131 );
132
133 void
136 uint32_t loop_level);
137
139
140 std::list<std::vector<sdfg::structured_control_flow::ControlFlowNode*>> loop_tree_paths(
142 const std::unordered_map<
145 ) const;
146
147 LoopState& compute_loop_infos(structured_control_flow::ControlFlowNode* loop);
148
153 AggregatedResult aggregate_loop_info(structured_control_flow::ControlFlowNode* loop) const;
154
155 void reindex_loop_nest_idx();
156
165 uint32_t child_insertion_index(structured_control_flow::ControlFlowNode* new_parent, bool start_not_end) const;
166
173 void reindex(
174 std::vector<structured_control_flow::ControlFlowNode*>::iterator start,
175 std::vector<structured_control_flow::ControlFlowNode*>::iterator end
176 );
177
184 void propagate_changed_nest_info(std::vector<structured_control_flow::ControlFlowNode*>::iterator top);
185
186public:
188
189 std::string name() const override {
190 return "LoopAnalysis";
191 }
192
193 void run(analysis::AnalysisManager& analysis_manager) override;
194
201
205 const std::vector<structured_control_flow::ControlFlowNode*> loops() const;
206
211 const std::vector<structured_control_flow::ControlFlowNode*>& loops_in_pre_order() const;
212
217 const std::unordered_map<structured_control_flow::ControlFlowNode*, structured_control_flow::ControlFlowNode*>&
218 loop_tree() const;
219
221
223
225
227
228 const std::vector<structured_control_flow::ControlFlowNode*>& outermost_loops() const;
229
231
232 const std::vector<structured_control_flow::ControlFlowNode*> outermost_maps() const;
233
234 const std::vector<sdfg::structured_control_flow::ControlFlowNode*>&
236
237 std::list<std::vector<sdfg::structured_control_flow::ControlFlowNode*>>
239
240 std::unordered_set<sdfg::structured_control_flow::ControlFlowNode*>
242
243 std::unordered_set<sdfg::structured_control_flow::ControlFlowNode*>
245
246 std::vector<sdfg::structured_control_flow::ControlFlowNode*>::const_iterator
252 std::vector<sdfg::structured_control_flow::ControlFlowNode*>::const_iterator
254
255 void dump_to_file(std::filesystem::path file) const;
256
257 // update with changes
258
263 bool start_not_end = false
264
265 );
266
270 bool start_not_end = false
271 );
272
274
282 void added_local_contents(structured_control_flow::ControlFlowNode* loop, bool side_effects, bool non_perfectly_nested);
283};
284
285} // namespace analysis
286} // namespace sdfg
Definition structured_sdfg.h:30
Definition analysis.h:53
Analysis(StructuredSDFG &sdfg)
Definition assumptions_analysis.h:15
std::vector< sdfg::structured_control_flow::ControlFlowNode * >::const_iterator get_subtree_end(structured_control_flow::ControlFlowNode *loop)
For a given loop, return the end-iterator of its subtree (the iterator after the last descendant loop...
std::unordered_set< sdfg::structured_control_flow::ControlFlowNode * > ancestors(sdfg::structured_control_flow::ControlFlowNode *loop) const
void copied_loop(structured_control_flow::ControlFlowNode *existing_loop, structured_control_flow::ControlFlowNode *new_parent_loop, structured_control_flow::ControlFlowNode *new_loop, bool start_not_end=false)
const std::vector< structured_control_flow::ControlFlowNode * > & loops_in_pre_order() const
Loops in Pre-order.
std::vector< sdfg::structured_control_flow::ControlFlowNode * >::const_iterator get_loop_iterator(structured_control_flow::ControlFlowNode *loop)
bool invalidate(structured_control_flow::ControlFlowNode &changed) override
Updates the nest of the outermost loop around changed, the only nest whose infos depend on it,...
const LocalLoopInfo & loop_info_local(structured_control_flow::ControlFlowNode *loop) const
const std::vector< structured_control_flow::ControlFlowNode * > & outermost_loops() const
void removed_loop(structured_control_flow::ControlFlowNode *existing_loop)
LoopInfo loop_info(structured_control_flow::ControlFlowNode *loop) const
void dump_to_file(std::filesystem::path file) const
std::string name() const override
Definition loop_analysis.h:189
const std::vector< structured_control_flow::ControlFlowNode * > loops() const
Currently guaranteed to be in Pre-Order.
LoopAnalysis(StructuredSDFG &sdfg)
void moved_loop(structured_control_flow::ControlFlowNode *existing_loop, structured_control_flow::StructuredLoop *new_parent, bool start_not_end=false)
void run(analysis::AnalysisManager &analysis_manager) override
const std::vector< structured_control_flow::ControlFlowNode * > outermost_maps() const
std::unordered_set< sdfg::structured_control_flow::ControlFlowNode * > descendants(sdfg::structured_control_flow::ControlFlowNode *loop) const
void added_local_contents(structured_control_flow::ControlFlowNode *loop, bool side_effects, bool non_perfectly_nested)
structured_control_flow::ControlFlowNode * parent_loop(structured_control_flow::ControlFlowNode *loop) const
const std::unordered_map< structured_control_flow::ControlFlowNode *, structured_control_flow::ControlFlowNode * > & loop_tree() const
Tree of parents of nodes.
structured_control_flow::ControlFlowNode * find_loop_by_indvar(const std::string &indvar)
std::list< std::vector< sdfg::structured_control_flow::ControlFlowNode * > > loop_tree_paths(sdfg::structured_control_flow::ControlFlowNode *loop) const
const std::vector< sdfg::structured_control_flow::ControlFlowNode * > & children(sdfg::structured_control_flow::ControlFlowNode *node) const
bool is_outermost_loop(structured_control_flow::ControlFlowNode *loop) const
Base class for all structured control flow nodes in a StructuredSDFG.
Definition control_flow_node.h:44
Represents a parallel map loop with configurable scheduling.
Definition map.h:47
A sequential container of control flow nodes.
Definition sequence.h:52
Base class for structured loop constructs.
Definition structured_loop.h:244
#define LOOP_INFO_PROPERTIES
Definition loop_analysis.h:12
Definition analysis.h:8
nlohmann::json loop_info_to_json(LoopInfo info)
Definition loop_analysis.h:76
void loop_info_local_to_json(nlohmann::json &j, const LocalLoopInfo &info)
Definition analysis.h:7
Meant to contain only per-loop data (does not reflect what loops nested inside do / have) This is a p...
Definition loop_analysis.h:50
bool is_elementwise
Definition loop_analysis.h:64
uint32_t last_child_id
ID of the last child.
Definition loop_analysis.h:61
LoopType
Definition loop_analysis.h:51
@ For
Definition loop_analysis.h:51
@ While
Definition loop_analysis.h:51
@ Map
Definition loop_analysis.h:51
bool contains_non_perfectly_nested
The loop contains anything other than a direct child loop.
Definition loop_analysis.h:69
uint32_t loop_id
Unique ID for each loop, not just loop nests.
Definition loop_analysis.h:56
uint32_t loop_level
Definition loop_analysis.h:62
bool contains_side_effects
The loop contains side-effects directly in its body (does not include anything that happens in child ...
Definition loop_analysis.h:73
LoopType type
Definition loop_analysis.h:63
uint32_t last_child_id
Definition loop_analysis.h:104
LoopInfo nest
Definition loop_analysis.h:105
Definition loop_analysis.h:99
LocalLoopInfo local
Definition loop_analysis.h:100
LoopInfo nest
Definition loop_analysis.h:101
is_perfectly_nested: is the entire loop hierarchy with loop at the top perfectly nested on every leve...
Definition loop_analysis.h:38