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

daisytuner / sdfglib / 16069945621

04 Jul 2025 08:56AM UTC coverage: 64.375% (-0.2%) from 64.606%
16069945621

push

github

web-flow
Merge pull request #137 from daisytuner/clang-format

runs clang-format on codebase

609 of 827 new or added lines in 63 files covered. (73.64%)

46 existing lines in 30 files now uncovered.

8578 of 13325 relevant lines covered (64.38%)

177.24 hits per line

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

74.63
/src/codegen/code_generator.cpp
1
#include "sdfg/codegen/code_generator.h"
2
#include <symengine/constants.h>
3
#include <symengine/dict.h>
4
#include <symengine/number.h>
5
#include "sdfg/analysis/analysis.h"
6
#include "sdfg/analysis/mem_access_range_analysis.h"
7
#include "sdfg/codegen/instrumentation/capture_var_plan.h"
8
#include "sdfg/symbolic/symbolic.h"
9
#include "sdfg/types/structure.h"
10

11
namespace sdfg {
12
namespace codegen {
13

14
std::tuple<int, types::PrimitiveType> CodeGenerator::analyze_type_rec(
7✔
15
    symbolic::Expression* dims,
16
    int maxDim,
17
    int dimIdx,
18
    const types::IType& type,
19
    int argIdx,
20
    const analysis::MemAccessRange* range
21
) {
22
    if (dimIdx > maxDim) {
7✔
NEW
23
        std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << ": data nesting deeper than " << maxDim
×
NEW
24
                  << ", ignoring" << std::endl;
×
UNCOV
25
        return std::make_tuple(-1, types::Void);
×
26
    }
27

28
    if (auto* scalarType = dynamic_cast<const types::Scalar*>(&type)) {
7✔
29
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": scalar" << std::endl;
30
        return std::make_tuple(dimIdx, scalarType->primitive_type());
4✔
31
    } else if (auto structureType = dynamic_cast<const sdfg::types::Structure*>(&type)) {
3✔
32
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": struct" << std::endl;
33
        return std::make_tuple(dimIdx, types::Void);
×
34
    } else if (auto* arrayType = dynamic_cast<const types::Array*>(&type)) {
3✔
35
        dims[dimIdx] = arrayType->num_elements();
1✔
36
        auto& inner = arrayType->element_type();
1✔
37

38
        // std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": " <<
39
        // language_extension_.expression(dims[dimIdx]) << std::endl;
40

41
        return analyze_type_rec(dims, maxDim, dimIdx + 1, inner, argIdx, range);
1✔
42
    } else if (auto* ptrType = dynamic_cast<const types::Pointer*>(&type)) {
2✔
43
        if (range && !range->is_undefined()) {
2✔
44
            const auto& dim = range->dims()[dimIdx];
2✔
45

46
            if (symbolic::eq(symbolic::zero(), dim.first)) {
2✔
47
                dims[dimIdx] = symbolic::add(dim.second, symbolic::one());
2✔
48

49
                auto& inner = ptrType->pointee_type();
2✔
50

51
                return analyze_type_rec(dims, maxDim, dimIdx + 1, inner, argIdx, range);
2✔
52
            } else {
NEW
53
                std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx << ": has upper bound "
×
NEW
54
                          << dim.second->__str__() << ", but does not start at 0, cannot capture" << std::endl;
×
UNCOV
55
                return std::make_tuple(-2, types::Void);
×
56
            }
57
        } else {
NEW
58
            std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << " dim" << dimIdx
×
NEW
59
                      << ": missing range, cannot capture!" << std::endl;
×
UNCOV
60
            return std::make_tuple(-2, types::Void);
×
61
        }
62
    } else {
NEW
63
        std::cerr << "In '" << sdfg_.name() << "', arg" << argIdx << ": unsupported type " << type.print()
×
NEW
64
                  << ", cannot capture!" << std::endl;
×
UNCOV
65
        return std::make_tuple(-1, types::Void);
×
66
    }
67
}
7✔
68

69
bool CodeGenerator::add_capture_plan(
4✔
70
    const std::string& varName,
71
    int argIdx,
72
    bool isExternal,
73
    std::vector<CaptureVarPlan>& plan,
74
    const analysis::MemAccessRanges& ranges
75
) {
76
    auto& type = sdfg_.type(varName);
4✔
77

78
    const auto* range = ranges.get(varName);
4✔
79

80
    symbolic::Expression dims[3];
12✔
81

82
    int dimCount;
83
    types::PrimitiveType innerPrim;
84
    std::tie(dimCount, innerPrim) = analyze_type_rec(dims, 3, 0, type, argIdx, range);
4✔
85

86
    bool isRead = range ? range->saw_read() : true;
4✔
87
    bool isWritten = range ? range->saw_write() : true;
4✔
88

89
    if (dimCount == 0) {
4✔
90
        plan.emplace_back(isRead, false, CaptureVarType::CapRaw, argIdx, isExternal, innerPrim);
2✔
91
    } else if (dimCount == 1) {
4✔
92
        plan.emplace_back(isRead, isWritten, CaptureVarType::Cap1D, argIdx, isExternal, innerPrim, dims[0]);
1✔
93
    } else if (dimCount == 2) {
2✔
94
        plan.emplace_back(isRead, isWritten, CaptureVarType::Cap2D, argIdx, isExternal, innerPrim, dims[0], dims[1]);
1✔
95
    } else if (dimCount == 3) {
1✔
NEW
96
        plan.emplace_back(
×
NEW
97
            isRead, isWritten, CaptureVarType::Cap3D, argIdx, isExternal, innerPrim, dims[0], dims[1], dims[2]
×
98
        );
NEW
99
    } else {
×
NEW
100
        return false;
×
101
    }
102

103
    return true;
4✔
104
}
4✔
105

106
std::unique_ptr<std::vector<CaptureVarPlan>> CodeGenerator::create_capture_plans() {
1✔
107
    auto name = sdfg_.name();
1✔
108

109
    analysis::AnalysisManager analysis_manager(sdfg_);
1✔
110
    const auto& args = sdfg_.arguments();
1✔
111
    auto& exts = sdfg_.externals();
1✔
112
    const auto& ranges = analysis_manager.get<analysis::MemAccessRanges>();
1✔
113

114
    auto plan = std::make_unique<std::vector<CaptureVarPlan>>();
1✔
115

116
    bool working = true;
1✔
117

118
    int argIdx = -1;
1✔
119
    for (auto& argName : args) {
3✔
120
        ++argIdx;
2✔
121

122
        working &= add_capture_plan(argName, argIdx, false, *plan.get(), ranges);
2✔
123
    }
124

125
    for (auto& argName : exts) {
3✔
126
        ++argIdx;
2✔
127

128
        working &= add_capture_plan(argName, argIdx, true, *plan.get(), ranges);
2✔
129
    }
130

131
    return plan;
1✔
132
}
1✔
133

134
} // namespace codegen
135
} // 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

© 2025 Coveralls, Inc