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

daisytuner / sdfglib / 15512041711

07 Jun 2025 09:59PM UTC coverage: 57.416% (+0.1%) from 57.315%
15512041711

push

github

web-flow
Merge pull request #44 from daisytuner/StructuredLoops

Add Structured Loops

51 of 102 new or added lines in 20 files covered. (50.0%)

10 existing lines in 8 files now uncovered.

7618 of 13268 relevant lines covered (57.42%)

116.01 hits per line

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

0.0
/src/analysis/loop_tree_analysis.cpp
1
#include "sdfg/analysis/loop_tree_analysis.h"
2

3
#include "sdfg/structured_control_flow/structured_loop.h"
4

5
namespace sdfg {
6
namespace analysis {
7

8
LoopTreeAnalysis::LoopTreeAnalysis(StructuredSDFG& sdfg) : Analysis(sdfg) {}
×
9

10
void LoopTreeAnalysis::run(structured_control_flow::ControlFlowNode& scope,
×
11
                           structured_control_flow::ControlFlowNode* parent_loop) {
12
    std::list<structured_control_flow::ControlFlowNode*> queue = {&scope};
×
13
    while (!queue.empty()) {
×
14
        auto current = queue.front();
×
15
        queue.pop_front();
×
16

17
        // Loop detected
18
        if (auto while_stmt = dynamic_cast<structured_control_flow::While*>(current)) {
×
19
            this->loop_tree_[while_stmt] = parent_loop;
×
NEW
20
        } else if (auto for_stmt =
×
NEW
21
                       dynamic_cast<structured_control_flow::StructuredLoop*>(current)) {
×
22
            this->loop_tree_[for_stmt] = parent_loop;
×
23
        }
×
24

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

52
void LoopTreeAnalysis::run(AnalysisManager& analysis_manager) {
×
53
    this->loop_tree_.clear();
×
54
    this->run(this->sdfg_.root(), nullptr);
×
55
}
×
56

57
const std::unordered_map<structured_control_flow::ControlFlowNode*,
58
                         structured_control_flow::ControlFlowNode*>&
59
LoopTreeAnalysis::loop_tree() const {
×
60
    return this->loop_tree_;
×
61
}
62

63
structured_control_flow::ControlFlowNode* LoopTreeAnalysis::parent_loop(
×
64
    structured_control_flow::ControlFlowNode* loop) const {
65
    return this->loop_tree_.at(loop);
×
66
}
67

68
const std::vector<structured_control_flow::ControlFlowNode*> LoopTreeAnalysis::outermost_loops()
×
69
    const {
70
    std::vector<structured_control_flow::ControlFlowNode*> outermost_loops_;
×
71
    for (const auto& [loop, parent] : this->loop_tree_) {
×
72
        if (parent == nullptr) {
×
73
            outermost_loops_.push_back(loop);
×
74
        }
×
75
    }
76
    return outermost_loops_;
×
77
}
×
78

79
}  // namespace analysis
80
}  // 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