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

daisytuner / sdfglib / 16861237397

10 Aug 2025 12:12PM UTC coverage: 64.492% (+0.006%) from 64.486%
16861237397

push

github

web-flow
Merge pull request #185 from daisytuner/memlets-tasklets

References and Memlets: Validation

102 of 146 new or added lines in 7 files covered. (69.86%)

2 existing lines in 1 file now uncovered.

8965 of 13901 relevant lines covered (64.49%)

124.44 hits per line

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

53.42
/src/types/utils.cpp
1
#include "sdfg/types/utils.h"
2
#include <iostream>
3
#include <memory>
4
#include <string>
5

6
#include "sdfg/analysis/users.h"
7
#include "sdfg/codegen/utils.h"
8
#include "sdfg/data_flow/access_node.h"
9
#include "sdfg/function.h"
10
#include "sdfg/structured_sdfg.h"
11
#include "sdfg/symbolic/symbolic.h"
12

13
#include "sdfg/codegen/language_extensions/c_language_extension.h"
14
#include "sdfg/types/type.h"
15

16
namespace sdfg {
17
namespace types {
18

19
const types::IType&
20
infer_type_internal(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
1,116✔
21
    if (subset.empty()) {
1,116✔
22
        return type;
535✔
23
    }
24

25
    if (type.type_id() == TypeID::Scalar) {
581✔
26
        if (!subset.empty()) {
×
27
            throw InvalidSDFGException("Scalar type must have no subset");
×
28
        }
29

30
        return type;
×
31
    } else if (type.type_id() == TypeID::Array) {
581✔
32
        auto& array_type = static_cast<const types::Array&>(type);
580✔
33

34
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
580✔
35
        return infer_type_internal(function, array_type.element_type(), element_subset);
580✔
36
    } else if (type.type_id() == TypeID::Structure) {
581✔
37
        auto& structure_type = static_cast<const types::Structure&>(type);
1✔
38

39
        auto& definition = function.structure(structure_type.name());
1✔
40

41
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
1✔
42
        auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(subset.at(0));
1✔
43
        return infer_type_internal(function, definition.member_type(member), element_subset);
1✔
44
    } else if (type.type_id() == TypeID::Pointer) {
1✔
45
        throw InvalidSDFGException("Subset references non-contiguous memory");
×
46
    }
47

48
    throw InvalidSDFGException("Type inference failed because of unknown type");
×
49
};
1,116✔
50

51
const types::IType& infer_type(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
1,407✔
52
    if (subset.empty()) {
1,407✔
53
        return type;
872✔
54
    }
55

56
    if (type.type_id() == TypeID::Pointer) {
535✔
57
        auto& pointer_type = static_cast<const types::Pointer&>(type);
254✔
58
        if (!pointer_type.has_pointee_type()) {
254✔
NEW
59
            throw InvalidSDFGException("Opaque pointer with non-empty subset");
×
60
        }
61

62
        auto& pointee_type = pointer_type.pointee_type();
254✔
63
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
254✔
64
        return infer_type_internal(function, pointee_type, element_subset);
254✔
65
    } else {
254✔
66
        return infer_type_internal(function, type, subset);
281✔
67
    }
68
};
1,407✔
69

70
std::unique_ptr<types::IType> recombine_array_type(const types::IType& type, uint depth, const types::IType& inner_type) {
21✔
71
    if (depth == 0) {
21✔
72
        return inner_type.clone();
9✔
73
    } else {
74
        if (auto atype = dynamic_cast<const types::Array*>(&type)) {
12✔
75
            return std::make_unique<types::Array>(
12✔
76
                atype->storage_type(),
12✔
77
                atype->alignment(),
12✔
78
                atype->initializer(),
12✔
79
                *recombine_array_type(atype->element_type(), depth - 1, inner_type).get(),
12✔
80
                atype->num_elements()
12✔
81
            );
82
        } else {
83
            throw std::runtime_error("construct_type: Non array types are not supported yet!");
×
84
        }
85
    }
86
};
21✔
87

88
const IType& peel_to_innermost_element(const IType& type, int follow_ptr) {
13✔
89
    int next_follow = follow_ptr;
13✔
90
    if (follow_ptr == PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
13✔
91
        next_follow = 0; // only follow an outermost pointer
5✔
92
    }
5✔
93

94
    switch (type.type_id()) {
13✔
95
        case TypeID::Array:
96
            return peel_to_innermost_element(dynamic_cast<const types::Array&>(type).element_type(), next_follow);
3✔
97
        case TypeID::Reference:
98
            return peel_to_innermost_element(dynamic_cast<const codegen::Reference&>(type).reference_type(), next_follow);
×
99
        case TypeID::Pointer:
100
            if (follow_ptr != 0) {
6✔
101
                if (follow_ptr != PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
5✔
102
                    next_follow = follow_ptr - 1; // follow one less pointer
×
103
                }
×
104

105
                auto& pointer_type = dynamic_cast<const types::Pointer&>(type);
5✔
106
                if (pointer_type.has_pointee_type()) {
5✔
107
                    return peel_to_innermost_element(pointer_type.pointee_type(), next_follow);
5✔
108
                } else {
109
                    return type;
×
110
                }
111
            }
112
            // fall back to cut-off if we did not follow the pointer
113
        default:
114
            return type;
5✔
115
    }
116
}
13✔
117

118
symbolic::Expression get_contiguous_element_size(const types::IType& type, bool allow_comp_time_eval) {
5✔
119
    // need to peel explicitly, primitive_type() would follow ALL pointers, even ***, even though this is not contiguous
120
    auto& innermost = peel_to_innermost_element(type, PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR);
5✔
121

122
    return get_type_size(innermost, allow_comp_time_eval);
5✔
123
}
124

125
symbolic::Expression get_type_size(const types::IType& type, bool allow_comp_time_eval) {
13✔
126
    bool only_symbolic = false;
13✔
127

128
    auto id = type.type_id();
13✔
129
    if (id == TypeID::Pointer || id == TypeID::Reference || id == TypeID::Function) {
13✔
130
        // TODO NEED target info to know pointer size (4 or 8 bytes?) !!
131
        only_symbolic = true;
4✔
132
    } else if (id == TypeID::Structure) {
13✔
133
        // TODO if we have the target definition, we could evaluate the StructureDefinition to a size
134
        only_symbolic = true;
5✔
135
    } else if (id == TypeID::Array) {
9✔
136
        auto& arr = dynamic_cast<const types::Array&>(type);
1✔
137
        auto inner_element_size = get_type_size(arr.element_type(), allow_comp_time_eval);
1✔
138
        if (!inner_element_size.is_null()) {
1✔
139
            return symbolic::mul(inner_element_size, arr.num_elements());
1✔
140
        } else {
141
            return {};
×
142
        }
143
    }
1✔
144

145
    if (only_symbolic) {
12✔
146
        // Could not statically figure out the size
147
        // Could be struct we could evaluate by its definition or sth. we do not understand here
148
        if (allow_comp_time_eval) {
9✔
149
            return symbolic::size_of_type(type);
5✔
150
        } else { // size unknown
151
            return {};
4✔
152
        }
153
    } else { // should just be a primitive type
154
        auto prim_type = type.primitive_type();
3✔
155

156
        long size_of_type = static_cast<long>(types::bit_width(prim_type)) / 8;
3✔
157
        if (size_of_type != 0) {
3✔
158
            return symbolic::integer(size_of_type);
3✔
159
        } else {
160
            codegen::CLanguageExtension lang;
×
161
            std::cerr << "Unexpected primitive_type " << primitive_type_to_string(prim_type) << " of "
×
162
                      << lang.declaration("", type) << ", unknown size";
×
163
            return {};
×
164
        }
×
165
    }
166
}
13✔
167

168
const types::IType* infer_type_from_container(
×
169
    analysis::AnalysisManager& analysis_manager, const StructuredSDFG& sdfg, std::string container
170
) {
171
    if (sdfg.type(container).type_id() != types::TypeID::Pointer) {
×
172
        return &sdfg.type(container);
×
173
    }
174

175
    const types::IType* type = nullptr;
×
176
    auto& users = analysis_manager.get<analysis::Users>();
×
177

178
    for (auto user : users.reads(container)) {
×
179
        auto access_node = dynamic_cast<data_flow::AccessNode*>(user->element());
×
180
        for (auto& memlet : user->parent()->out_edges(*access_node)) {
×
181
            if (memlet.base_type().type_id() == types::TypeID::Pointer) {
×
182
                auto pointer_type = dynamic_cast<const types::Pointer*>(&memlet.base_type());
×
183
                if (!pointer_type->has_pointee_type()) {
×
184
                    continue;
×
185
                }
186
            }
×
187
            auto& base_type = memlet.base_type();
×
188
            if (type == nullptr) {
×
189
                type = &base_type;
×
190
                continue;
×
191
            }
192

193
            if (*type != base_type) {
×
194
                return nullptr;
×
195
            }
196
        }
197
    }
198

199
    for (auto user : users.writes(container)) {
×
200
        auto access_node = static_cast<data_flow::AccessNode*>(user->element());
×
201
        for (auto& memlet : user->parent()->in_edges(*access_node)) {
×
202
            if (memlet.base_type().type_id() == types::TypeID::Pointer) {
×
203
                auto pointer_type = dynamic_cast<const types::Pointer*>(&memlet.base_type());
×
204
                if (!pointer_type->has_pointee_type()) {
×
205
                    continue;
×
206
                }
207
            }
×
208
            auto& base_type = memlet.base_type();
×
209
            if (type == nullptr) {
×
210
                type = &base_type;
×
211
                continue;
×
212
            }
213

214
            if (*type != base_type) {
×
215
                return nullptr;
×
216
            }
217
        }
218
    }
219

220
    if (type == nullptr) {
×
221
        for (auto user : users.views(container)) {
×
222
            auto access_node = dynamic_cast<data_flow::AccessNode*>(user->element());
×
223
            for (auto& memlet : user->parent()->out_edges(*access_node)) {
×
224
                if (memlet.base_type().type_id() == types::TypeID::Pointer) {
×
225
                    auto pointer_type = dynamic_cast<const types::Pointer*>(&memlet.base_type());
×
226
                    if (!pointer_type->has_pointee_type()) {
×
227
                        continue;
×
228
                    }
229
                }
×
230
                auto& base_type = memlet.base_type();
×
231
                if (type == nullptr) {
×
232
                    type = &base_type;
×
233
                    continue;
×
234
                }
235

236
                if (*type != base_type) {
×
237
                    return nullptr;
×
238
                }
239
            }
240
        }
241
    }
×
242

243
    return type;
×
244
}
×
245

246
} // namespace types
247
} // 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