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

daisytuner / sdfglib / 15710378262

17 Jun 2025 02:40PM UTC coverage: 63.835% (-0.7%) from 64.576%
15710378262

Pull #86

github

web-flow
Merge 33788b6e3 into 37980e90f
Pull Request #86: Add optimizer functionality

37 of 215 new or added lines in 9 files covered. (17.21%)

12 existing lines in 5 files now uncovered.

8063 of 12631 relevant lines covered (63.84%)

115.87 hits per line

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

69.57
/src/transformations/loop_tiling.cpp
1
#include "sdfg/transformations/loop_tiling.h"
2

3
#include "sdfg/analysis/loop_analysis.h"
4
#include "sdfg/analysis/scope_analysis.h"
5
#include "sdfg/builder/structured_sdfg_builder.h"
6
#include "sdfg/deepcopy/structured_sdfg_deep_copy.h"
7
#include "sdfg/passes/structured_control_flow/dead_cfg_elimination.h"
8
#include "sdfg/passes/structured_control_flow/sequence_fusion.h"
9
#include "sdfg/structured_control_flow/structured_loop.h"
10

11
namespace sdfg {
12
namespace transformations {
13

14
LoopTiling::LoopTiling(structured_control_flow::StructuredLoop& loop, size_t tile_size)
1✔
15
    : loop_(loop), tile_size_(tile_size) {};
1✔
16

NEW
17
std::string LoopTiling::name() const { return "LoopTiling"; };
×
18

19
bool LoopTiling::can_be_applied(builder::StructuredSDFGBuilder& builder,
1✔
20
                                analysis::AnalysisManager& analysis_manager) {
21
    if (this->tile_size_ <= 1) {
1✔
NEW
22
        return false;
×
23
    }
24
    // Criterion contiguous loop
25
    auto& loop_analysis = analysis_manager.get<analysis::LoopAnalysis>();
1✔
26
    return loop_analysis.is_contiguous(&loop_);
1✔
27
};
1✔
28

29
void LoopTiling::apply(builder::StructuredSDFGBuilder& builder,
1✔
30
                       analysis::AnalysisManager& analysis_manager) {
31
    auto& sdfg = builder.subject();
1✔
32

33
    auto& scope_analysis = analysis_manager.get<analysis::ScopeAnalysis>();
1✔
34
    auto parent =
1✔
35
        static_cast<structured_control_flow::Sequence*>(scope_analysis.parent_scope(&loop_));
1✔
36

37
    auto indvar = loop_.indvar();
1✔
38
    auto outer_indvar_str = builder.find_new_name(indvar->get_name() + "_tile");
1✔
39
    builder.add_container(outer_indvar_str, sdfg.type(loop_.indvar()->get_name()));
1✔
40
    auto outer_indvar = symbolic::symbol(outer_indvar_str);
1✔
41

42
    auto tile_size = symbolic::integer(this->tile_size_);
1✔
43

44
    auto condition = symbolic::subs(loop_.condition(), indvar, outer_indvar);
1✔
45
    auto update = symbolic::add(outer_indvar, tile_size);
1✔
46

47
    auto& outer_loop =
1✔
48
        builder.add_for_before(*parent, loop_, outer_indvar, condition, loop_.init(), update).first;
1✔
49

50
    auto& outer_body = outer_loop.root();
1✔
51

52
    auto inner_indvar = indvar;
1✔
53
    auto inner_init = outer_indvar;
1✔
54
    auto inner_condition_tile = symbolic::Lt(inner_indvar, symbolic::add(outer_indvar, tile_size));
1✔
55
    auto inner_condition_base = symbolic::subs(loop_.condition(), outer_indvar, inner_indvar);
1✔
56
    auto inner_condition = symbolic::And(inner_condition_tile, inner_condition_base);
1✔
57
    auto inner_update = symbolic::add(inner_indvar, symbolic::integer(1));
1✔
58

59
    // Add new loop with original body
60
    auto& tmp_root = builder.add_sequence_before(*parent, loop_).first;
1✔
61
    auto& inner_loop =
1✔
62
        builder.add_for(tmp_root, inner_indvar, inner_condition, inner_init, inner_update);
1✔
63

64
    deepcopy::StructuredSDFGDeepCopy copies(builder, inner_loop.root(), loop_.root());
1✔
65
    copies.copy();
1✔
66

67
    builder.clear_sequence(outer_body);
1✔
68

69
    deepcopy::StructuredSDFGDeepCopy copies2(builder, outer_body, tmp_root);
1✔
70
    copies2.copy();
1✔
71

72
    builder.remove_child(*parent, tmp_root);
1✔
73
    builder.remove_child(*parent, loop_);
1✔
74

75
    analysis_manager.invalidate_all();
1✔
76

77
    passes::SequenceFusion sf_pass;
1✔
78
    passes::DeadCFGElimination dce_pass;
1✔
79
    bool applies = false;
1✔
80
    do {
1✔
81
        applies = false;
2✔
82
        applies |= dce_pass.run(builder, analysis_manager);
2✔
83
        applies |= sf_pass.run(builder, analysis_manager);
2✔
84
    } while (applies);
2✔
85
};
1✔
86

NEW
87
void LoopTiling::to_json(nlohmann::json& j) const {
×
NEW
88
    std::cout << "Serializing LoopTiling transformation to JSON" << std::endl;
×
NEW
89
    std::cout << "Writing transformation type: " << this->name() << std::endl;
×
NEW
90
    j["transformation_type"] = this->name();
×
NEW
91
    std::cout << "Writing loop element ID " << std::endl;
×
NEW
92
    j["loop_element_id"] = loop_.element_id();
×
NEW
93
    std::cout << "Writing tile size " << std::endl;
×
NEW
94
    j["tile_size"] = tile_size_;
×
NEW
95
};
×
96

NEW
97
LoopTiling LoopTiling::from_json(builder::StructuredSDFGBuilder& builder,
×
98
                                 const nlohmann::json& desc) {
NEW
99
    auto loop_id = desc["loop_element_id"].get<size_t>();
×
NEW
100
    size_t tile_size = desc["tile_size"].get<size_t>();
×
NEW
101
    auto element = builder.find_element_by_id(loop_id);
×
NEW
102
    if (!element) {
×
NEW
103
        throw InvalidTransformationDescriptionException("Element with ID " +
×
NEW
104
                                                        std::to_string(loop_id) + " not found.");
×
105
    }
NEW
106
    auto loop = dynamic_cast<structured_control_flow::For*>(element);
×
107

NEW
UNCOV
108
    return LoopTiling(*loop, tile_size);
×
NEW
UNCOV
109
};
×
110

111
}  // namespace transformations
112
}  // 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