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

daisytuner / sdfglib / 19224500338

10 Nov 2025 07:48AM UTC coverage: 61.286% (+0.1%) from 61.165%
19224500338

push

github

web-flow
Merge pull request #332 from daisytuner/constant-elimination

handle previous definitions before constants in elimination pass

14 of 19 new or added lines in 1 file covered. (73.68%)

9 existing lines in 4 files now uncovered.

10274 of 16764 relevant lines covered (61.29%)

101.34 hits per line

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

69.32
/src/structured_control_flow/sequence.cpp
1
#include "sdfg/structured_control_flow/sequence.h"
2

3
#include "sdfg/function.h"
4

5
namespace sdfg {
6
namespace structured_control_flow {
7

8
Transition::Transition(size_t element_id, const DebugInfo& debug_info, Sequence& parent)
×
9
    : Element(element_id, debug_info), parent_(&parent) {
×
10

11
      };
×
12

13
Transition::Transition(
873✔
14
    size_t element_id, const DebugInfo& debug_info, Sequence& parent, const control_flow::Assignments& assignments
15
)
16
    : Element(element_id, debug_info), parent_(&parent), assignments_(assignments) {
873✔
17

18
      };
873✔
19

20
void Transition::validate(const Function& function) const {
788✔
21
    for (const auto& entry : this->assignments_) {
991✔
22
        if (entry.first.is_null() || entry.second.is_null()) {
203✔
23
            throw InvalidSDFGException("Transition: Assignments cannot have null expressions");
×
24
        }
25
    }
26

27
    for (auto& entry : this->assignments_) {
991✔
28
        auto& lhs = entry.first;
203✔
29
        auto& type = function.type(lhs->get_name());
203✔
30
        if (type.type_id() != types::TypeID::Scalar) {
203✔
31
            throw InvalidSDFGException("Assignment - LHS: must be integer type");
×
32
        }
33
        if (!types::is_integer(type.primitive_type())) {
203✔
34
            throw InvalidSDFGException("Assignment - LHS: must be integer type");
×
35
        }
36

37
        auto& rhs = entry.second;
203✔
38
        bool is_relational = SymEngine::is_a_Relational(*rhs);
203✔
39
        for (auto& atom : symbolic::atoms(rhs)) {
280✔
40
            if (symbolic::is_nullptr(atom)) {
77✔
UNCOV
41
                if (!is_relational) {
×
42
                    throw InvalidSDFGException("Assignment - RHS: nullptr can only be used in comparisons");
×
43
                }
UNCOV
44
                continue;
×
45
            }
46
            auto& atom_type = function.type(atom->get_name());
77✔
47

48
            // Scalar integers
49
            if (atom_type.type_id() == types::TypeID::Scalar) {
77✔
50
                if (!types::is_integer(atom_type.primitive_type())) {
74✔
51
                    throw InvalidSDFGException("Assignment - RHS: must evaluate to integer type");
×
52
                }
53
                continue;
74✔
54
            }
55

56
            // Pointer types (only in comparisons)
57
            if (atom_type.type_id() == types::TypeID::Pointer) {
3✔
UNCOV
58
                if (!is_relational) {
×
59
                    throw InvalidSDFGException("Assignment - RHS: pointer types can only be used in comparisons");
×
60
                }
UNCOV
61
                continue;
×
62
            }
63
        }
64
    }
65
};
788✔
66

67
const control_flow::Assignments& Transition::assignments() const { return this->assignments_; };
49✔
68

69
control_flow::Assignments& Transition::assignments() { return this->assignments_; };
1,734✔
70

71
Sequence& Transition::parent() { return *this->parent_; };
6✔
72

73
const Sequence& Transition::parent() const { return *this->parent_; };
×
74

75
bool Transition::empty() const { return this->assignments_.empty(); };
17✔
76

77
size_t Transition::size() const { return this->assignments_.size(); };
50✔
78

79
void Transition::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
2✔
80
    if (SymEngine::is_a<SymEngine::Symbol>(*old_expression) && SymEngine::is_a<SymEngine::Symbol>(*new_expression)) {
2✔
81
        auto old_symbol = SymEngine::rcp_static_cast<const SymEngine::Symbol>(old_expression);
2✔
82
        auto new_symbol = SymEngine::rcp_static_cast<const SymEngine::Symbol>(new_expression);
2✔
83

84
        if (this->assignments().find(old_symbol) != this->assignments().end()) {
2✔
85
            this->assignments()[new_symbol] = this->assignments()[old_symbol];
×
86
            this->assignments().erase(old_symbol);
×
87
        }
×
88
    }
2✔
89

90
    for (auto& entry : this->assignments()) {
2✔
91
        entry.second = symbolic::subs(entry.second, old_expression, new_expression);
×
92
    }
93
};
2✔
94

95
Sequence::Sequence(size_t element_id, const DebugInfo& debug_info)
1,624✔
96
    : ControlFlowNode(element_id, debug_info) {
812✔
97

98
      };
812✔
99

100
void Sequence::validate(const Function& function) const {
646✔
101
    // children and transition have same length
102
    if (this->children_.size() != this->transitions_.size()) {
646✔
103
        throw InvalidSDFGException("Sequence must have the same number of children and transitions");
×
104
    }
105

106
    for (auto& child : this->children_) {
1,434✔
107
        child->validate(function);
788✔
108
    }
109
    for (auto& trans : this->transitions_) {
1,434✔
110
        trans->validate(function);
788✔
111
    }
112
};
646✔
113

114
size_t Sequence::size() const { return this->children_.size(); };
3,910✔
115

116
std::pair<const ControlFlowNode&, const Transition&> Sequence::at(size_t i) const {
158✔
117
    return {*this->children_.at(i), *this->transitions_.at(i)};
158✔
118
};
119

120
std::pair<ControlFlowNode&, Transition&> Sequence::at(size_t i) {
2,355✔
121
    return {*this->children_.at(i), *this->transitions_.at(i)};
2,355✔
122
};
123

124
int Sequence::index(const ControlFlowNode& child) const {
77✔
125
    for (size_t i = 0; i < this->children_.size(); i++) {
83✔
126
        if (this->children_.at(i).get() == &child) {
83✔
127
            return static_cast<int>(i);
77✔
128
        }
129
    }
6✔
130

131
    return -1;
×
132
};
77✔
133

134
int Sequence::index(const Transition& transition) const {
×
135
    for (size_t i = 0; i < this->transitions_.size(); i++) {
×
136
        if (this->transitions_.at(i).get() == &transition) {
×
137
            return static_cast<int>(i);
×
138
        }
139
    }
×
140

141
    return -1;
×
142
};
×
143

144
void Sequence::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {
2✔
145
    for (auto& child : this->children_) {
4✔
146
        child->replace(old_expression, new_expression);
2✔
147
    }
148

149
    for (auto& trans : this->transitions_) {
4✔
150
        trans->replace(old_expression, new_expression);
2✔
151
    }
152
};
2✔
153

154
} // namespace structured_control_flow
155
} // 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

© 2025 Coveralls, Inc