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

daisytuner / sdfglib / 15717109772

17 Jun 2025 08:16PM UTC coverage: 64.66% (+0.08%) from 64.576%
15717109772

push

github

web-flow
Merge pull request #89 from daisytuner/leftover-logs

removes leftover logs

7992 of 12360 relevant lines covered (64.66%)

142.43 hits per line

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

88.64
/src/passes/structured_control_flow/for2map.cpp
1
#include "sdfg/passes/structured_control_flow/for2map.h"
2

3
#include "sdfg/analysis/loop_analysis.h"
4
#include "sdfg/analysis/loop_dependency_analysis.h"
5
#include "sdfg/analysis/scope_analysis.h"
6

7
namespace sdfg {
8
namespace passes {
9

10
For2Map::For2Map(builder::StructuredSDFGBuilder& builder,
6✔
11
                 analysis::AnalysisManager& analysis_manager)
12
    : visitor::StructuredSDFGVisitor(builder, analysis_manager) {
6✔
13

14
      };
6✔
15

16
bool For2Map::can_be_applied(structured_control_flow::For& for_stmt,
6✔
17
                             analysis::AnalysisManager& analysis_manager) {
18
    // Criterion: loop must be contiguous
19
    // Simplification to reason about memory offsets and bounds
20
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
6✔
21
    if (!loop_analysis.is_contiguous(&for_stmt)) {
6✔
22
        return false;
1✔
23
    }
24

25
    // Criterion: loop condition can be written as a closed-form expression.
26
    // Closed-form: i < expression_no_i
27
    // Example: i < N && i < M -> i < min(N, M)
28
    auto bound = loop_analysis.canonical_bound(&for_stmt);
5✔
29
    if (bound == SymEngine::null) {
5✔
30
        return false;
1✔
31
    }
32

33
    // Criterion: loop must be data-parallel w.r.t containers
34
    auto& loop_dependency_analysis = analysis_manager.get<analysis::LoopDependencyAnalysis>();
4✔
35
    auto dependencies = loop_dependency_analysis.get(for_stmt);
4✔
36

37
    // a. No true dependencies (RAW) between iterations
38
    for (auto& dep : dependencies) {
4✔
39
        if (dep.second == analysis::LoopCarriedDependency::RAW) {
×
40
            return false;
×
41
        }
42
    }
43

44
    // b. False dependencies (WAW) are limited to loop-local variables
45
    auto& users = analysis_manager.get<analysis::Users>();
4✔
46
    auto locals = users.locals(for_stmt.root());
4✔
47
    for (auto& dep : dependencies) {
4✔
48
        auto& container = dep.first;
×
49
        if (locals.find(container) == locals.end()) {
×
50
            return false;
×
51
        }
52
    }
53

54
    return true;
4✔
55
}
6✔
56

57
void For2Map::apply(structured_control_flow::For& for_stmt, builder::StructuredSDFGBuilder& builder,
4✔
58
                    analysis::AnalysisManager& analysis_manager) {
59
    // Contiguous and canonical bound -> we can compute the number of iterations
60
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
4✔
61
    auto init = for_stmt.init();
4✔
62
    auto num_iterations = symbolic::sub(loop_analysis.canonical_bound(&for_stmt), init);
4✔
63

64
    auto& scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
4✔
65
    auto parent =
4✔
66
        static_cast<structured_control_flow::Sequence*>(scope_analysis.parent_scope(&for_stmt));
4✔
67

68
    // convert for to map
69
    auto& map = builder.convert_for(*parent, for_stmt, num_iterations);
4✔
70
    auto& indvar = map.indvar();
4✔
71

72
    // Shift indvar by init in body
73
    auto shift = symbolic::add(indvar, init);
4✔
74
    map.root().replace(indvar, shift);
4✔
75

76
    // set indvar to last value of a sequential loop
77
    auto successor = builder.add_block_after(*parent, map);
4✔
78
    auto last_value = symbolic::add(init, num_iterations);
4✔
79
    successor.second.assignments().insert({indvar, last_value});
4✔
80
}
4✔
81

82
bool For2Map::accept(structured_control_flow::Sequence& parent,
6✔
83
                     structured_control_flow::For& node) {
84
    if (!this->can_be_applied(node, analysis_manager_)) {
6✔
85
        return false;
2✔
86
    }
87

88
    this->apply(node, builder_, analysis_manager_);
4✔
89
    return true;
4✔
90
}
6✔
91

92
}  // namespace passes
93
}  // 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