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

daisytuner / sdfglib / 15612270835

12 Jun 2025 01:44PM UTC coverage: 60.871% (-0.8%) from 61.71%
15612270835

push

github

web-flow
Merge pull request #68 from daisytuner/loop-types

refactors symbolic analysis into polynomials, extreme values and cnf

638 of 862 new or added lines in 24 files covered. (74.01%)

334 existing lines in 20 files now uncovered.

6571 of 10795 relevant lines covered (60.87%)

100.35 hits per line

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

64.71
/src/analysis/loop_analysis.cpp
1
#include "sdfg/analysis/loop_analysis.h"
2

3
#include "sdfg/analysis/assumptions_analysis.h"
4
#include "sdfg/structured_control_flow/structured_loop.h"
5
#include "sdfg/symbolic/series.h"
6

7
namespace sdfg {
8
namespace analysis {
9

10
LoopAnalysis::LoopAnalysis(StructuredSDFG& sdfg) : Analysis(sdfg) {}
32✔
11

12
void LoopAnalysis::run(structured_control_flow::ControlFlowNode& scope,
72✔
13
                       structured_control_flow::ControlFlowNode* parent_loop) {
14
    std::list<structured_control_flow::ControlFlowNode*> queue = {&scope};
72✔
15
    while (!queue.empty()) {
237✔
16
        auto current = queue.front();
165✔
17
        queue.pop_front();
165✔
18

19
        // Loop detected
20
        if (auto while_stmt = dynamic_cast<structured_control_flow::While*>(current)) {
165✔
NEW
21
            this->loops_.insert(while_stmt);
×
22
            this->loop_tree_[while_stmt] = parent_loop;
×
23
        } else if (auto loop_stmt =
165✔
24
                       dynamic_cast<structured_control_flow::StructuredLoop*>(current)) {
165✔
25
            this->loops_.insert(loop_stmt);
40✔
26
            this->loop_tree_[loop_stmt] = parent_loop;
40✔
27
        }
40✔
28

29
        if (dynamic_cast<structured_control_flow::Block*>(current)) {
165✔
30
            continue;
53✔
31
        } else if (auto sequence_stmt = dynamic_cast<structured_control_flow::Sequence*>(current)) {
112✔
32
            for (size_t i = 0; i < sequence_stmt->size(); i++) {
165✔
33
                queue.push_back(&sequence_stmt->at(i).first);
93✔
34
            }
93✔
35
        } else if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(current)) {
112✔
36
            for (size_t i = 0; i < if_else_stmt->size(); i++) {
×
37
                queue.push_back(&if_else_stmt->at(i).first);
×
38
            }
×
39
        } else if (auto while_stmt = dynamic_cast<structured_control_flow::While*>(current)) {
40✔
40
            this->run(while_stmt->root(), while_stmt);
×
41
        } else if (auto for_stmt =
40✔
42
                       dynamic_cast<structured_control_flow::StructuredLoop*>(current)) {
40✔
43
            this->run(for_stmt->root(), for_stmt);
40✔
44
        } else if (dynamic_cast<structured_control_flow::Break*>(current)) {
40✔
45
            continue;
×
46
        } else if (dynamic_cast<structured_control_flow::Continue*>(current)) {
×
47
            continue;
×
48
        } else if (dynamic_cast<structured_control_flow::Return*>(current)) {
×
49
            continue;
×
50
        } else {
51
            throw std::runtime_error("Unsupported control flow node type");
×
52
        }
53
    }
54
}
72✔
55

56
void LoopAnalysis::run(AnalysisManager& analysis_manager) {
32✔
57
    this->loops_.clear();
32✔
58
    this->loop_tree_.clear();
32✔
59
    this->run(this->sdfg_.root(), nullptr);
32✔
60
}
32✔
61

62
const std::unordered_set<structured_control_flow::ControlFlowNode*> LoopAnalysis::loops() const {
30✔
63
    return this->loops_;
30✔
64
}
65

66
bool LoopAnalysis::is_monotonic(structured_control_flow::StructuredLoop* loop) const {
37✔
67
    AnalysisManager manager(this->sdfg_);
37✔
68
    auto& assums_analysis = manager.get<AssumptionsAnalysis>();
37✔
69
    auto assums = assums_analysis.get(*loop);
37✔
70

71
    return symbolic::is_monotonic(loop->update(), loop->indvar(), assums);
37✔
72
}
37✔
73

74
bool LoopAnalysis::is_contiguous(structured_control_flow::StructuredLoop* loop) const {
5✔
75
    AnalysisManager manager(this->sdfg_);
5✔
76
    auto& assums_analysis = manager.get<AssumptionsAnalysis>();
5✔
77
    auto assums = assums_analysis.get(*loop);
5✔
78

79
    return symbolic::is_contiguous(loop->update(), loop->indvar(), assums);
5✔
80
}
5✔
81

82
const std::unordered_map<structured_control_flow::ControlFlowNode*,
83
                         structured_control_flow::ControlFlowNode*>&
NEW
84
LoopAnalysis::loop_tree() const {
×
85
    return this->loop_tree_;
×
86
}
87

NEW
88
structured_control_flow::ControlFlowNode* LoopAnalysis::parent_loop(
×
89
    structured_control_flow::ControlFlowNode* loop) const {
90
    return this->loop_tree_.at(loop);
×
91
}
92

NEW
93
const std::vector<structured_control_flow::ControlFlowNode*> LoopAnalysis::outermost_loops() const {
×
94
    std::vector<structured_control_flow::ControlFlowNode*> outermost_loops_;
×
95
    for (const auto& [loop, parent] : this->loop_tree_) {
×
96
        if (parent == nullptr) {
×
97
            outermost_loops_.push_back(loop);
×
98
        }
×
99
    }
100
    return outermost_loops_;
×
101
}
×
102

103
}  // namespace analysis
104
}  // 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