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

daisytuner / sdfglib / 16810010027

07 Aug 2025 04:19PM UTC coverage: 64.654% (+0.3%) from 64.316%
16810010027

push

github

web-flow
Merge pull request #176 from daisytuner/condition-elimination

New ConditionElimination Pass

28 of 33 new or added lines in 2 files covered. (84.85%)

8910 of 13781 relevant lines covered (64.65%)

117.84 hits per line

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

84.38
/src/passes/structured_control_flow/condition_elimination.cpp
1
#include "sdfg/passes/structured_control_flow/condition_elimination.h"
2

3
#include "sdfg/analysis/users.h"
4
#include "sdfg/deepcopy/structured_sdfg_deep_copy.h"
5

6
namespace sdfg {
7
namespace passes {
8

9
bool ConditionElimination::eliminate_condition(
1✔
10
    structured_control_flow::Sequence& root,
11
    structured_control_flow::IfElse& match,
12
    structured_control_flow::StructuredLoop& loop,
13
    const symbolic::Condition& condition
14
) {
15
    auto loop_indvar = loop.indvar();
1✔
16
    auto loop_init = loop.init();
1✔
17
    auto loop_condition = loop.condition();
1✔
18

19
    // indvar must be a local, because it will be written before the condition is checked
20
    analysis::Users& users = this->analysis_manager_.get<analysis::Users>();
1✔
21
    auto locals = users.locals(match);
1✔
22
    if (locals.find(loop_indvar->get_name()) == locals.end()) {
1✔
NEW
23
        return false;
×
24
    }
25

26
    // If loop condition for iter 0 is equals to condition, we can eliminate the match
27
    auto loop_iter0_condition = symbolic::subs(loop_condition, loop_indvar, loop_init);
1✔
28
    if (symbolic::eq(loop_iter0_condition, condition)) {
1✔
29
        auto& new_seq = this->builder_.add_sequence_before(root, match).first;
1✔
30
        this->builder_.insert(loop, match.at(0).first, new_seq, match.debug_info());
1✔
31
        this->builder_.remove_child(root, match);
1✔
32

33
        return true;
1✔
34
    }
35

NEW
36
    return false;
×
37
};
1✔
38

39
ConditionElimination::
40
    ConditionElimination(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager)
1✔
41
    : StructuredSDFGVisitor(builder, analysis_manager) {
1✔
42

43
      };
1✔
44

45

46
bool ConditionElimination::accept(structured_control_flow::Sequence& parent, structured_control_flow::IfElse& node) {
1✔
47
    if (node.size() != 1) {
1✔
NEW
48
        return false;
×
49
    }
50
    auto branch = node.at(0);
1✔
51
    auto& condition = branch.second;
1✔
52

53
    auto& root = branch.first;
1✔
54
    if (root.size() != 1) {
1✔
NEW
55
        return false;
×
56
    }
57

58
    if (!dynamic_cast<structured_control_flow::StructuredLoop*>(&root.at(0).first)) {
1✔
NEW
59
        return false;
×
60
    }
61
    auto& loop = static_cast<structured_control_flow::StructuredLoop&>(root.at(0).first);
1✔
62

63
    return this->eliminate_condition(parent, node, loop, condition);
1✔
64
};
1✔
65

66
} // namespace passes
67
} // 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