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

daisytuner / sdfglib / 20694719239

04 Jan 2026 02:58PM UTC coverage: 39.623% (-0.02%) from 39.64%
20694719239

push

github

web-flow
Merge pull request #426 from daisytuner/memlet-linearization-fix

account for pointer dimension in memlet lonearization

15070 of 49497 branches covered (30.45%)

Branch coverage included in aggregate %.

15 of 17 new or added lines in 1 file covered. (88.24%)

2 existing lines in 1 file now uncovered.

12942 of 21199 relevant lines covered (61.05%)

91.51 hits per line

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

67.18
/src/passes/dataflow/memlet_linearization.cpp
1
#include "sdfg/passes/dataflow/memlet_linearization.h"
2

3
#include "sdfg/data_flow/data_flow_graph.h"
4
#include "sdfg/data_flow/memlet.h"
5
#include "sdfg/structured_control_flow/block.h"
6
#include "sdfg/symbolic/symbolic.h"
7
#include "sdfg/types/array.h"
8
#include "sdfg/types/pointer.h"
9
#include "sdfg/types/utils.h"
10
#include "sdfg/visitor/structured_sdfg_visitor.h"
11

12
namespace sdfg {
13
namespace passes {
14

15
MemletLinearization::
16
    MemletLinearization(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager)
4✔
17
    : visitor::NonStoppingStructuredSDFGVisitor(builder, analysis_manager) {}
4✔
18

19
bool MemletLinearization::accept(structured_control_flow::Block& block) {
4✔
20
    bool applied = false;
4✔
21
    auto& dfg = block.dataflow();
4✔
22

23
    for (auto& memlet : dfg.edges()) {
8✔
24
        if (memlet.subset().empty()) {
4!
NEW
25
            continue;
×
26
        }
27
        auto& base_type = memlet.base_type();
4✔
28
        if (base_type.type_id() != types::TypeID::Pointer) {
4!
UNCOV
29
            continue;
×
30
        }
31
        auto& pointer_type = dynamic_cast<const types::Pointer&>(base_type);
4!
32
        if (!pointer_type.has_pointee_type()) {
4!
33
            continue;
×
34
        }
35

36
        // Check if pointee type contains arrays
37
        auto& pointee_type = pointer_type.pointee_type();
4✔
38
        const types::IType* current_type = &pointee_type;
4✔
39
        std::vector<symbolic::Expression> array_dimensions = {symbolic::one()};
4!
40

41
        // Collect all array dimensions
42
        while (current_type->type_id() == types::TypeID::Array) {
11!
43
            auto array_type = dynamic_cast<const types::Array*>(current_type);
7!
44
            array_dimensions.push_back(array_type->num_elements());
7!
45
            current_type = &array_type->element_type();
7!
46
        }
47
        if (current_type->type_id() != types::TypeID::Scalar) {
4!
NEW
48
            continue;
×
49
        }
50
        if (array_dimensions.size() == 1) {
4✔
51
            continue;
1✔
52
        }
53

54
        auto storage = pointer_type.storage_type();
3!
55
        auto alignment = pointer_type.alignment();
3!
56
        auto initializer = pointer_type.initializer();
3!
57
        types::Pointer new_pointer_type(storage, alignment, initializer, *current_type);
3!
58

59
        // Linearize subset
60
        auto old_subset = memlet.subset();
3!
61
        data_flow::Subset new_subset;
3✔
62

63
        symbolic::Expression linearized_index = symbolic::zero();
3!
64

65
        for (size_t i = 0; i < old_subset.size(); ++i) {
13✔
66
            symbolic::Expression stride = symbolic::one();
10!
67

68
            // Calculate stride: product of all dimensions after current dimension
69
            for (size_t j = i + 1; j < array_dimensions.size(); ++j) {
22✔
70
                stride = symbolic::mul(stride, array_dimensions[j]);
12!
71
            }
12✔
72
            linearized_index = symbolic::add(linearized_index, symbolic::mul(old_subset[i], stride));
10!
73
        }
10✔
74

75
        new_subset.push_back(linearized_index);
3!
76
        memlet.set_base_type(new_pointer_type);
3!
77
        memlet.set_subset(new_subset);
3!
78

79
        applied = true;
3✔
80
    }
4!
81

82
    return applied;
4✔
UNCOV
83
}
×
84

85
} // namespace passes
86
} // 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