• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / sdfglib / 15133758385

20 May 2025 09:19AM UTC coverage: 60.543% (-3.0%) from 63.542%
15133758385

push

github

web-flow
Merge pull request #22 from daisytuner/normalization

Removes normalization passes

7922 of 13085 relevant lines covered (60.54%)

104.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.48
/src/schedule.cpp
1
#include "sdfg/schedule.h"
2

3
#include "sdfg/builder/structured_sdfg_builder.h"
4
#include "sdfg/deepcopy/structured_sdfg_deep_copy.h"
5

6
namespace sdfg {
7

8
void Schedule::loop_tree(
×
9
    structured_control_flow::ControlFlowNode& root,
10
    structured_control_flow::ControlFlowNode* parent,
11
    std::unordered_map<structured_control_flow::ControlFlowNode*,
12
                       structured_control_flow::ControlFlowNode*>& tree) const {
13
    std::list<structured_control_flow::ControlFlowNode*> queue = {&root};
×
14
    while (!queue.empty()) {
×
15
        auto current = queue.front();
×
16
        queue.pop_front();
×
17
        if (auto for_loop = dynamic_cast<structured_control_flow::For*>(current)) {
×
18
            tree[for_loop] = parent;
×
19
        } else if (auto while_loop = dynamic_cast<structured_control_flow::While*>(current)) {
×
20
            tree[while_loop] = parent;
×
21
        }
×
22

23
        if (auto sequence_stmt = dynamic_cast<structured_control_flow::Sequence*>(current)) {
×
24
            for (size_t i = 0; i < sequence_stmt->size(); i++) {
×
25
                queue.push_back(&sequence_stmt->at(i).first);
×
26
            }
×
27
        } else if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(current)) {
×
28
            for (size_t i = 0; i < if_else_stmt->size(); i++) {
×
29
                queue.push_back(&if_else_stmt->at(i).first);
×
30
            }
×
31
        } else if (auto while_stmt = dynamic_cast<structured_control_flow::While*>(current)) {
×
32
            this->loop_tree(while_stmt->root(), while_stmt, tree);
×
33
        } else if (auto for_stmt = dynamic_cast<structured_control_flow::For*>(current)) {
×
34
            this->loop_tree(for_stmt->root(), for_stmt, tree);
×
35
        } else if (auto kern_stmt = dynamic_cast<structured_control_flow::Kernel*>(current)) {
×
36
            queue.push_back(&kern_stmt->root());
×
37
        }
×
38
    }
39
};
×
40

41
Schedule::Schedule(std::unique_ptr<StructuredSDFG>& sdfg)
54✔
42
    : assumptions_(),
27✔
43
      builder_(sdfg),
27✔
44
      analysis_manager_(builder_.subject(), assumptions_){
27✔
45

46
      };
27✔
47

48
Schedule::Schedule(std::unique_ptr<StructuredSDFG>& sdfg, const symbolic::Assumptions& assumptions)
432✔
49
    : assumptions_(assumptions),
216✔
50
      builder_(sdfg),
216✔
51
      analysis_manager_(builder_.subject(), assumptions_){
216✔
52

53
      };
216✔
54

55
symbolic::Assumptions& Schedule::assumptions() { return this->assumptions_; };
188✔
56

57
const symbolic::Assumptions& Schedule::assumptions() const { return this->assumptions_; };
×
58

59
builder::StructuredSDFGBuilder& Schedule::builder() { return this->builder_; };
237✔
60

61
const StructuredSDFG& Schedule::sdfg() const { return this->builder_.subject(); };
1,411✔
62

63
analysis::AnalysisManager& Schedule::analysis_manager() { return this->analysis_manager_; };
52✔
64

65
LoopSchedule Schedule::loop_schedule(
10✔
66
    const structured_control_flow::ControlFlowNode* loop) const {
67
    if (this->loop_schedules_.find(loop) == this->loop_schedules_.end()) {
10✔
68
        return LoopSchedule::SEQUENTIAL;
10✔
69
    }
70
    return this->loop_schedules_.at(loop);
×
71
};
10✔
72

73
void Schedule::loop_schedule(const structured_control_flow::ControlFlowNode* loop,
1✔
74
                             const LoopSchedule schedule) {
75
    if (schedule == LoopSchedule::SEQUENTIAL) {
1✔
76
        if (this->loop_schedules_.find(loop) == this->loop_schedules_.end()) {
1✔
77
            return;
1✔
78
        }
79
        this->loop_schedules_.erase(loop);
×
80
        return;
×
81
    }
82
    this->loop_schedules_.insert_or_assign(loop, schedule);
×
83
};
1✔
84

85
std::unordered_map<structured_control_flow::ControlFlowNode*,
86
                   structured_control_flow::ControlFlowNode*>
87
Schedule::loop_tree() const {
×
88
    std::unordered_map<structured_control_flow::ControlFlowNode*,
×
89
                       structured_control_flow::ControlFlowNode*>
90
        loop_tree_;
×
91
    this->loop_tree(this->builder_.subject().root(), nullptr, loop_tree_);
×
92
    return loop_tree_;
×
93
};
×
94

95
/***** Allocation Management *****/
96

97
const structured_control_flow::ControlFlowNode* Schedule::allocation_lifetime(
17✔
98
    const std::string& container) const {
99
    if (this->allocation_lifetimes_.find(container) == this->allocation_lifetimes_.end()) {
17✔
100
        return &this->sdfg().root();
11✔
101
    }
102
    return this->allocation_lifetimes_.at(container);
6✔
103
};
17✔
104

105
void Schedule::allocation_lifetime(const std::string& container,
6✔
106
                                   const structured_control_flow::ControlFlowNode* node) {
107
    this->allocation_lifetimes_.insert_or_assign(container, node);
6✔
108
};
6✔
109

110
AllocationType Schedule::allocation_type(const std::string& container) const {
9✔
111
    if (this->allocation_types_.find(container) == this->allocation_types_.end()) {
9✔
112
        return AllocationType::DECLARE;
3✔
113
    }
114
    return this->allocation_types_.at(container);
6✔
115
};
9✔
116

117
void Schedule::allocation_type(const std::string& container, AllocationType allocation_type) {
6✔
118
    if (allocation_type == AllocationType::DECLARE) {
6✔
119
        if (this->allocation_types_.find(container) != this->allocation_types_.end()) {
1✔
120
            this->allocation_types_.erase(container);
×
121
        }
×
122
        return;
1✔
123
    }
124
    this->allocation_types_.insert_or_assign(container, allocation_type);
5✔
125
};
6✔
126

127
std::unordered_set<std::string> Schedule::node_allocations(
3✔
128
    const structured_control_flow::ControlFlowNode* node) const {
129
    std::unordered_set<std::string> allocated;
3✔
130
    if (node == &this->sdfg().root()) {
3✔
131
        for (auto& container : this->sdfg().containers()) {
5✔
132
            if (!this->sdfg().is_transient(container)) {
4✔
133
                continue;
2✔
134
            }
135
            if (this->allocation_lifetimes_.find(container) == this->allocation_lifetimes_.end()) {
2✔
136
                allocated.insert(container);
×
137
            }
×
138
        }
139
    } else {
1✔
140
        for (auto& [container, lifetime] : this->allocation_lifetimes_) {
6✔
141
            if (lifetime == node) {
4✔
142
                allocated.insert(container);
4✔
143
            }
4✔
144
        }
145
    }
146
    return allocated;
3✔
147
};
3✔
148

149
std::unordered_set<std::string> Schedule::allocations(
2✔
150
    const structured_control_flow::ControlFlowNode* node) const {
151
    std::unordered_set<std::string> allocated;
2✔
152

153
    std::list<const structured_control_flow::ControlFlowNode*> queue = {node};
2✔
154
    while (!queue.empty()) {
5✔
155
        auto current = queue.front();
3✔
156
        queue.pop_front();
3✔
157

158
        auto node_allocations = this->node_allocations(current);
3✔
159
        allocated.insert(node_allocations.begin(), node_allocations.end());
3✔
160

161
        if (auto sequence_stmt = dynamic_cast<const structured_control_flow::Sequence*>(current)) {
3✔
162
            for (size_t i = 0; i < sequence_stmt->size(); i++) {
2✔
163
                queue.push_front(&sequence_stmt->at(i).first);
1✔
164
            }
1✔
165
        } else if (auto if_else_stmt =
3✔
166
                       dynamic_cast<const structured_control_flow::IfElse*>(current)) {
2✔
167
            for (size_t i = 0; i < if_else_stmt->size(); i++) {
×
168
                queue.push_front(&if_else_stmt->at(i).first);
×
169
            }
×
170
        } else if (auto while_stmt = dynamic_cast<const structured_control_flow::While*>(current)) {
2✔
171
            queue.push_front(&while_stmt->root());
×
172
        } else if (auto for_stmt = dynamic_cast<const structured_control_flow::For*>(current)) {
2✔
173
            queue.push_front(&for_stmt->root());
×
174
        }
×
175
    }
3✔
176

177
    return allocated;
2✔
178
};
2✔
179

180
}  // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc