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

daisytuner / sdfglib / 16439520920

22 Jul 2025 08:53AM UTC coverage: 65.927% (+0.8%) from 65.094%
16439520920

Pull #153

github

web-flow
Merge a0eea6968 into abe57c083
Pull Request #153: Restricts memlets to contiguous memory

211 of 300 new or added lines in 29 files covered. (70.33%)

66 existing lines in 7 files now uncovered.

8314 of 12611 relevant lines covered (65.93%)

128.5 hits per line

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

84.27
/src/types/utils.cpp
1
#include "sdfg/types/utils.h"
2

3
#include "sdfg/codegen/utils.h"
4
#include "sdfg/symbolic/symbolic.h"
5

6
#include "sdfg/codegen/language_extensions/c_language_extension.h"
7

8
namespace sdfg {
9
namespace types {
10

11
const types::IType&
12
infer_type_internal(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
340✔
13
    if (subset.empty()) {
340✔
14
        return type;
170✔
15
    }
16

17
    if (type.type_id() == TypeID::Scalar) {
170✔
18
        if (!subset.empty()) {
×
19
            throw InvalidSDFGException("Scalar type must have no subset");
×
20
        }
21

NEW
22
        return type;
×
23
    } else if (type.type_id() == TypeID::Array) {
170✔
24
        auto& array_type = static_cast<const types::Array&>(type);
169✔
25

26
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
169✔
27
        return infer_type_internal(function, array_type.element_type(), element_subset);
169✔
28
    } else if (type.type_id() == TypeID::Structure) {
170✔
29
        auto& structure_type = static_cast<const types::Structure&>(type);
1✔
30

31
        auto& definition = function.structure(structure_type.name());
1✔
32

33
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
1✔
34
        auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(subset.at(0));
1✔
35
        return infer_type_internal(function, definition.member_type(member), element_subset);
1✔
36
    } else if (type.type_id() == TypeID::Pointer) {
1✔
NEW
37
        throw InvalidSDFGException("Subset references non-contiguous memory");
×
38
    }
39

NEW
40
    throw InvalidSDFGException("Type inference failed because of unknown type");
×
41
};
340✔
42

43
const types::IType& infer_type(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
444✔
44
    if (subset.empty()) {
444✔
45
        return type;
274✔
46
    }
47

48
    if (type.type_id() == TypeID::Pointer) {
170✔
49
        auto& pointer_type = static_cast<const types::Pointer&>(type);
87✔
50
        auto& pointee_type = pointer_type.pointee_type();
87✔
51

52
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
87✔
53
        return infer_type_internal(function, pointee_type, element_subset);
87✔
54
    } else {
87✔
55
        return infer_type_internal(function, type, subset);
83✔
56
    }
57
};
444✔
58

59
std::unique_ptr<types::IType> recombine_array_type(const types::IType& type, uint depth, const types::IType& inner_type) {
21✔
60
    if (depth == 0) {
21✔
61
        return inner_type.clone();
9✔
62
    } else {
63
        if (auto atype = dynamic_cast<const types::Array*>(&type)) {
12✔
64
            return std::make_unique<types::Array>(
12✔
65
                atype->storage_type(),
12✔
66
                atype->alignment(),
12✔
67
                atype->initializer(),
12✔
68
                *recombine_array_type(atype->element_type(), depth - 1, inner_type).get(),
12✔
69
                atype->num_elements()
12✔
70
            );
71
        } else {
72
            throw std::runtime_error("construct_type: Non array types are not supported yet!");
×
73
        }
74
    }
75
};
21✔
76

77
const IType& peel_to_innermost_element(const IType& type, int follow_ptr) {
13✔
78
    int next_follow = follow_ptr;
13✔
79
    if (follow_ptr == PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
13✔
80
        next_follow = 0; // only follow an outermost pointer
5✔
81
    }
5✔
82

83
    switch (type.type_id()) {
13✔
84
        case TypeID::Array:
85
            return peel_to_innermost_element(dynamic_cast<const types::Array&>(type).element_type(), next_follow);
3✔
86
        case TypeID::Reference:
87
            return peel_to_innermost_element(dynamic_cast<const codegen::Reference&>(type).reference_type(), next_follow);
×
88
        case TypeID::Pointer:
89
            if (follow_ptr != 0) {
6✔
90
                if (follow_ptr != PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
5✔
91
                    next_follow = follow_ptr - 1; // follow one less pointer
×
92
                }
×
93

94
                return peel_to_innermost_element(dynamic_cast<const types::Pointer&>(type).pointee_type(), next_follow);
5✔
95
            }
96
            // fall back to cut-off if we did not follow the pointer
97
        default:
98
            return type;
5✔
99
    }
100
}
13✔
101

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

106
    return get_type_size(innermost, allow_comp_time_eval);
5✔
107
}
108

109
symbolic::Expression get_type_size(const types::IType& type, bool allow_comp_time_eval) {
13✔
110
    bool only_symbolic = false;
13✔
111

112
    auto id = type.type_id();
13✔
113
    if (id == TypeID::Pointer || id == TypeID::Reference || id == TypeID::Function) {
13✔
114
        // TODO NEED target info to know pointer size (4 or 8 bytes?) !!
115
        only_symbolic = true;
4✔
116
    } else if (id == TypeID::Structure) {
13✔
117
        // TODO if we have the target definition, we could evaluate the StructureDefinition to a size
118
        only_symbolic = true;
5✔
119
    } else if (id == TypeID::Array) {
9✔
120
        auto& arr = dynamic_cast<const types::Array&>(type);
1✔
121
        auto inner_element_size = get_type_size(arr.element_type(), allow_comp_time_eval);
1✔
122
        if (!inner_element_size.is_null()) {
1✔
123
            return symbolic::mul(inner_element_size, arr.num_elements());
1✔
124
        } else {
125
            return {};
×
126
        }
127
    }
1✔
128

129
    if (only_symbolic) {
12✔
130
        // Could not statically figure out the size
131
        // Could be struct we could evaluate by its definition or sth. we do not understand here
132
        if (allow_comp_time_eval) {
9✔
133
            return symbolic::size_of_type(type);
5✔
134
        } else { // size unknown
135
            return {};
4✔
136
        }
137
    } else { // should just be a primitive type
138
        auto prim_type = type.primitive_type();
3✔
139

140
        long size_of_type = static_cast<long>(types::bit_width(prim_type)) / 8;
3✔
141
        if (size_of_type != 0) {
3✔
142
            return symbolic::integer(size_of_type);
3✔
143
        } else {
144
            codegen::CLanguageExtension lang;
×
145
            std::cerr << "Unexpected primitive_type " << primitive_type_to_string(prim_type) << " of "
×
146
                      << lang.declaration("", type) << ", unknown size";
×
147
            return {};
×
148
        }
149
    }
150
}
13✔
151

152
} // namespace types
153
} // 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