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

daisytuner / sdfglib / 20147202960

11 Dec 2025 08:57PM UTC coverage: 40.181% (-0.09%) from 40.268%
20147202960

push

github

lukastruemper
removes timing outputs of passes

13596 of 43795 branches covered (31.04%)

Branch coverage included in aggregate %.

11609 of 18933 relevant lines covered (61.32%)

93.45 hits per line

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

34.53
/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()
7✔
25
    : Pass() {
7✔
26

27
      };
7✔
28

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

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

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

36
    auto& root = sdfg.root();
6✔
37
    if (root.size() == 0) {
6!
38
        return false;
×
39
    }
40

41
    std::list<structured_control_flow::ControlFlowNode*> queue = {&sdfg.root()};
6!
42
    while (!queue.empty()) {
38✔
43
        auto curr = queue.front();
32✔
44
        queue.pop_front();
32✔
45

46
        if (auto sequence_stmt = dynamic_cast<structured_control_flow::Sequence*>(curr)) {
32!
47
            // Simplify
48
            size_t i = 0;
14✔
49
            while (i < sequence_stmt->size()) {
30!
50
                auto child = sequence_stmt->at(i);
18!
51

52
                // Return node found, everything after is dead
53
                if (auto return_node = dynamic_cast<structured_control_flow::Return*>(&child.first)) {
18!
54
                    if (child.second.assignments().size() > 0) {
2!
55
                        // Clear assignments
56
                        child.second.assignments().clear();
2!
57
                        applied = true;
2✔
58
                    }
2✔
59
                    for (size_t j = i + 1; j < sequence_stmt->size();) {
3!
60
                        builder.remove_child(*sequence_stmt, i + 1);
1!
61
                        applied = true;
1✔
62
                    }
63
                    break;
2✔
64
                }
65

66
                // Non-empty transitions are not safe to remove
67
                if (!child.second.empty()) {
16!
68
                    i++;
1✔
69
                    continue;
1✔
70
                }
71

72
                // Dead
73
                if (is_dead(child.first)) {
15!
74
                    builder.remove_child(*sequence_stmt, i);
×
75
                    applied = true;
×
76
                    continue;
×
77
                }
78

79
                // Trivial branch
80
                if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(&child.first)) {
15!
81
                    auto branch = if_else_stmt->at(0);
×
82
                    if (symbolic::is_true(branch.second)) {
×
83
                        builder.move_children(branch.first, *sequence_stmt, i + 1);
×
84
                        builder.remove_child(*sequence_stmt, i);
×
85
                        applied = true;
×
86
                        continue;
×
87
                    }
88
                }
×
89

90
                i++;
15✔
91
            }
92

93
            // Add to queue
94
            for (size_t j = 0; j < sequence_stmt->size(); j++) {
32!
95
                queue.push_back(&sequence_stmt->at(j).first);
18!
96
            }
18✔
97
        } else if (auto if_else_stmt = dynamic_cast<structured_control_flow::IfElse*>(curr)) {
32!
98
            // False branches are safe to remove
99
            size_t i = 0;
×
100
            while (i < if_else_stmt->size()) {
×
101
                auto child = if_else_stmt->at(i);
×
102
                if (symbolic::is_false(child.second)) {
×
103
                    builder.remove_case(*if_else_stmt, i);
×
104
                    applied = true;
×
105
                    continue;
×
106
                }
107

108
                i++;
×
109
            }
×
110

111
            // Trailing dead branches are safe to remove
112
            if (if_else_stmt->size() > 0) {
×
113
                if (is_dead(if_else_stmt->at(if_else_stmt->size() - 1).first)) {
×
114
                    builder.remove_case(*if_else_stmt, if_else_stmt->size() - 1);
×
115
                    applied = true;
×
116
                }
×
117
            }
×
118

119
            // If-else to simple if conversion
120
            if (if_else_stmt->size() == 2) {
×
121
                auto if_condition = if_else_stmt->at(0).second;
×
122
                auto else_condition = if_else_stmt->at(1).second;
×
123
                if (symbolic::eq(if_condition->logical_not(), else_condition)) {
×
124
                    if (is_dead(if_else_stmt->at(1).first)) {
×
125
                        builder.remove_case(*if_else_stmt, 1);
×
126
                        applied = true;
×
127
                    } else if (is_dead(if_else_stmt->at(0).first)) {
×
128
                        builder.remove_case(*if_else_stmt, 0);
×
129
                        applied = true;
×
130
                    }
×
131
                }
×
132
            }
×
133

134
            // Add to queue
135
            for (size_t j = 0; j < if_else_stmt->size(); j++) {
×
136
                queue.push_back(&if_else_stmt->at(j).first);
×
137
            }
×
138
        } else if (auto loop_stmt = dynamic_cast<structured_control_flow::While*>(curr)) {
18!
139
            auto& root = loop_stmt->root();
×
140
            queue.push_back(&root);
×
141
        } else if (auto sloop_stmt = dynamic_cast<structured_control_flow::StructuredLoop*>(curr)) {
18!
142
            auto& root = sloop_stmt->root();
8!
143
            queue.push_back(&root);
8!
144
        } else if (auto map_stmt = dynamic_cast<structured_control_flow::Map*>(curr)) {
18!
145
            auto& root = map_stmt->root();
×
146
            queue.push_back(&root);
×
147
        }
×
148
    }
149

150
    return applied;
6✔
151
};
6✔
152

153
} // namespace passes
154
} // 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