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

daisytuner / sdfglib / 17368505925

01 Sep 2025 05:29AM UTC coverage: 58.982% (-0.8%) from 59.781%
17368505925

push

github

web-flow
Merge pull request #216 from daisytuner/transitions-bug

Updates API for Sequence transitions to prevent leakage of assignments

239 of 547 new or added lines in 25 files covered. (43.69%)

75 existing lines in 12 files now uncovered.

9190 of 15581 relevant lines covered (58.98%)

115.89 hits per line

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

44.9
/src/passes/structured_control_flow/dead_cfg_elimination.cpp
1
#include "sdfg/passes/structured_control_flow/dead_cfg_elimination.h"
2

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

5
namespace sdfg {
6
namespace passes {
7

8
bool DeadCFGElimination::is_dead(const structured_control_flow::ControlFlowNode& node) {
15✔
9
    if (auto block_stmt = dynamic_cast<const structured_control_flow::Block*>(&node)) {
15✔
10
        return (block_stmt->dataflow().nodes().size() == 0);
8✔
11
    } else if (auto sequence_stmt = dynamic_cast<const structured_control_flow::Sequence*>(&node)) {
7✔
12
        return (sequence_stmt->size() == 0);
×
13
    } else if (auto if_else_stmt = dynamic_cast<const structured_control_flow::IfElse*>(&node)) {
7✔
14
        return (if_else_stmt->size() == 0);
×
15
    } else if (auto while_stmt = dynamic_cast<const structured_control_flow::While*>(&node)) {
7✔
16
        return is_dead(while_stmt->root());
×
17
    } else if (dynamic_cast<const structured_control_flow::For*>(&node)) {
7✔
18
        return false;
7✔
19
    }
20

21
    return false;
×
22
};
15✔
23

24
DeadCFGElimination::DeadCFGElimination()
5✔
25
    : Pass() {
5✔
26

27
      };
5✔
28

29
std::string DeadCFGElimination::name() { return "DeadCFGElimination"; };
×
30

31
bool DeadCFGElimination::run_pass(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager) {
4✔
32
    bool applied = false;
4✔
33

34
    auto& sdfg = builder.subject();
4✔
35

36
    auto& root = sdfg.root();
4✔
37
    if (root.size() == 0) {
4✔
38
        return false;
×
39
    }
40
    auto last = root.at(root.size() - 1);
4✔
41
    if (last.second.empty() && dynamic_cast<structured_control_flow::Return*>(&last.first)) {
4✔
42
        builder.remove_child(root, root.size() - 1);
×
43
        applied = true;
×
44
    }
×
45

46
    std::list<structured_control_flow::ControlFlowNode*> queue = {&sdfg.root()};
4✔
47
    while (!queue.empty()) {
32✔
48
        auto curr = queue.front();
28✔
49
        queue.pop_front();
28✔
50

51
        if (auto sequence_stmt = dynamic_cast<structured_control_flow::Sequence*>(curr)) {
28✔
52
            // Simplify
53
            size_t i = 0;
12✔
54
            while (i < sequence_stmt->size()) {
28✔
55
                auto child = sequence_stmt->at(i);
16✔
56
                if (!child.second.empty()) {
16✔
57
                    i++;
1✔
58
                    continue;
1✔
59
                }
60

61
                // Dead
62
                if (is_dead(child.first)) {
15✔
63
                    builder.remove_child(*sequence_stmt, i);
×
64
                    applied = true;
×
65
                    continue;
×
66
                }
67

68
                // Trivial branch
69
                if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(&child.first)) {
15✔
UNCOV
70
                    auto branch = if_else_stmt->at(0);
×
71
                    if (symbolic::is_true(branch.second)) {
×
NEW
72
                        builder.move_children(branch.first, *sequence_stmt, i + 1);
×
73
                        builder.remove_child(*sequence_stmt, i);
×
74
                        applied = true;
×
75
                        continue;
×
76
                    }
77
                }
×
78

79
                i++;
15✔
80
            }
81

82
            // Add to queue
83
            for (size_t j = 0; j < sequence_stmt->size(); j++) {
28✔
84
                queue.push_back(&sequence_stmt->at(j).first);
16✔
85
            }
16✔
86
        } else if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(curr)) {
28✔
87
            // False branches are safe to remove
88
            size_t i = 0;
×
89
            while (i < if_else_stmt->size()) {
×
90
                auto child = if_else_stmt->at(i);
×
91
                if (symbolic::is_false(child.second)) {
×
92
                    builder.remove_case(*if_else_stmt, i);
×
93
                    applied = true;
×
94
                    continue;
×
95
                }
96

97
                i++;
×
98
            }
99

100
            // Trailing dead branches are safe to remove
101
            if (if_else_stmt->size() > 0) {
×
102
                if (is_dead(if_else_stmt->at(if_else_stmt->size() - 1).first)) {
×
103
                    builder.remove_case(*if_else_stmt, if_else_stmt->size() - 1);
×
104
                    applied = true;
×
105
                }
×
106
            }
×
107

108
            // If-else to simple if conversion
109
            if (if_else_stmt->size() == 2) {
×
110
                auto if_condition = if_else_stmt->at(0).second;
×
111
                auto else_condition = if_else_stmt->at(1).second;
×
112
                if (symbolic::eq(if_condition->logical_not(), else_condition)) {
×
113
                    if (is_dead(if_else_stmt->at(1).first)) {
×
114
                        builder.remove_case(*if_else_stmt, 1);
×
115
                        applied = true;
×
116
                    } else if (is_dead(if_else_stmt->at(0).first)) {
×
117
                        builder.remove_case(*if_else_stmt, 0);
×
118
                        applied = true;
×
119
                    }
×
120
                }
×
121
            }
×
122

123
            // Add to queue
124
            for (size_t j = 0; j < if_else_stmt->size(); j++) {
×
125
                queue.push_back(&if_else_stmt->at(j).first);
×
126
            }
×
127
        } else if (auto loop_stmt = dynamic_cast<structured_control_flow::While*>(curr)) {
16✔
128
            auto& root = loop_stmt->root();
×
129
            queue.push_back(&root);
×
130
        } else if (auto sloop_stmt = dynamic_cast<structured_control_flow::StructuredLoop*>(curr)) {
16✔
131
            auto& root = sloop_stmt->root();
8✔
132
            queue.push_back(&root);
8✔
133
        } else if (auto map_stmt = dynamic_cast<structured_control_flow::Map*>(curr)) {
16✔
134
            auto& root = map_stmt->root();
×
135
            queue.push_back(&root);
×
136
        }
×
137
    }
138

139
    return applied;
4✔
140
};
4✔
141

142
} // namespace passes
143
} // 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