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

daisytuner / sdfglib / 18558780296

16 Oct 2025 10:49AM UTC coverage: 61.233% (-0.3%) from 61.523%
18558780296

push

github

web-flow
Merge pull request #279 from daisytuner/ext-prefix

Separate Dominance Analysis and Codegen for Linker with Prefixes

62 of 95 new or added lines in 26 files covered. (65.26%)

13 existing lines in 7 files now uncovered.

8981 of 14667 relevant lines covered (61.23%)

98.73 hits per line

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

0.0
/src/data_flow/library_nodes/call_node.cpp
1
#include "sdfg/data_flow/library_nodes/call_node.h"
2

3
namespace sdfg {
4
namespace data_flow {
5

6
CallNode::CallNode(
×
7
    size_t element_id,
8
    const DebugInfo& debug_info,
9
    const graph::Vertex vertex,
10
    data_flow::DataFlowGraph& parent,
11
    const std::string& callee_name,
12
    const std::vector<std::string>& outputs,
13
    const std::vector<std::string>& inputs,
14
    bool offloadable
15
)
16
    : LibraryNode(
×
17
          element_id,
×
18
          debug_info,
×
19
          vertex,
×
20
          parent,
×
21
          LibraryNodeType_Call,
22
          outputs,
×
23
          inputs,
×
24
          true,
25
          data_flow::ImplementationType_NONE
26
      ),
27
      callee_name_(callee_name), offloadable_(offloadable) {}
×
28

29
const std::string& CallNode::callee_name() const { return this->callee_name_; }
×
30

31
bool CallNode::offloadable() const { return this->offloadable_; }
×
32

33
bool CallNode::is_void(const Function& sdfg) const {
×
34
    return outputs_.empty() || outputs_.at(0) != "_ret";
×
35
}
36

37
bool CallNode::is_indirect_call(const Function& sdfg) const {
×
38
    auto& type = sdfg.type(this->callee_name_);
×
39
    return dynamic_cast<const types::Pointer*>(&type) != nullptr;
×
40
}
41

42
void CallNode::validate(const Function& function) const {
×
43
    if (!function.exists(this->callee_name_)) {
×
44
        throw InvalidSDFGException("CallNode: Function '" + this->callee_name_ + "' does not exist.");
×
45
    }
46
    auto& type = function.type(this->callee_name_);
×
47
    if (!dynamic_cast<const types::Function*>(&type) && !dynamic_cast<const types::Pointer*>(&type)) {
×
48
        throw InvalidSDFGException("CallNode: '" + this->callee_name_ + "' is not a function or pointer.");
×
49
    }
50

51
    if (auto func_type = dynamic_cast<const types::Function*>(&type)) {
×
52
        if (!function.is_external(this->callee_name_)) {
×
53
            throw InvalidSDFGException("CallNode: Function '" + this->callee_name_ +
×
54
                                        "' must be declared.");
55
        }
NEW
56
        if (!func_type->is_var_arg() && inputs_.size() != func_type->num_params()) {
×
57
            throw InvalidSDFGException(
×
58
                "CallNode: Number of inputs does not match number of function parameters. Expected " +
×
59
                std::to_string(func_type->num_params()) + ", got " + std::to_string(inputs_.size())
×
60
            );
61
        }
62
        if (!this->is_void(function) && outputs_.size() < 1) {
×
63
            throw InvalidSDFGException(
×
64
                "CallNode: Non-void function must have at least one output to store the return value."
×
65
            );
66
        }
67
    }
×
68
}
×
69

70
symbolic::SymbolSet CallNode::symbols() const { 
×
71
    return { symbolic::symbol(this->callee_name_) };
×
72
}
×
73

74
std::unique_ptr<data_flow::DataFlowNode> CallNode::
75
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
76
    return std::make_unique<CallNode>(element_id, debug_info_, vertex, parent, callee_name_, outputs_, inputs_);
×
77
}
78

79
void CallNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
80

81
nlohmann::json CallNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
82
    const CallNode& node = static_cast<const CallNode&>(library_node);
×
83

84
    nlohmann::json j;
×
85
    j["code"] = node.code().value();
×
86
    j["callee_name"] = node.callee_name();
×
87
    j["outputs"] = node.outputs();
×
88
    j["inputs"] = node.inputs();
×
89

90
    return j;
×
91
}
×
92

93
data_flow::LibraryNode& CallNodeSerializer::deserialize(
×
94
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
95
) {
96
    assert(j.contains("code"));
×
97
    assert(j.contains("callee_name"));
×
98
    assert(j.contains("outputs"));
×
99
    assert(j.contains("inputs"));
×
100
    assert(j.contains("debug_info"));
×
101

102
    auto code = j["code"].get<std::string>();
×
103
    if (code != LibraryNodeType_Call.value()) {
×
104
        throw InvalidSDFGException("Invalid library node code");
×
105
    }
106

107
    sdfg::serializer::JSONSerializer serializer;
×
108
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
109

110
    std::string callee_name = j["callee_name"].get<std::string>();
×
111
    auto outputs = j["outputs"].get<std::vector<std::string>>();
×
112
    auto inputs = j["inputs"].get<std::vector<std::string>>();
×
113

114
    return builder.add_library_node<CallNode>(parent, debug_info, callee_name, outputs, inputs);
×
115
}
×
116

117
CallNodeDispatcher::CallNodeDispatcher(
×
118
    codegen::LanguageExtension& language_extension,
119
    const Function& function,
120
    const data_flow::DataFlowGraph& data_flow_graph,
121
    const CallNode& node
122
)
123
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
124

125
void CallNodeDispatcher::dispatch_code(
×
126
    codegen::PrettyPrinter& stream,
127
    codegen::PrettyPrinter& globals_stream,
128
    codegen::CodeSnippetFactory& library_snippet_factory
129
) {
130
    auto& node = static_cast<const CallNode&>(node_);
×
131

132
    if (!node.is_void(function_)) {
×
133
        stream << node.outputs().at(0) << " = ";
×
134
    }
×
135
    if (node.is_indirect_call(function_)) {
×
136
        auto& graph = node.get_parent();
×
137

138
        // Collect return memlet
139
        const data_flow::Memlet* ret_memlet = nullptr;
×
140
        for (auto& oedge : graph.out_edges(node)) {
×
141
            if (oedge.src_conn() == "_ret") {
×
142
                ret_memlet = &oedge;
×
143
                break;
×
144
            }
145
        }
146

147
        // Collect input memlets
148
        std::unordered_map<std::string, const data_flow::Memlet*> input_memlets;
×
149
        for (auto& iedge : graph.in_edges(node)) {
×
150
            input_memlets[iedge.dst_conn()] = &iedge;
×
151
        }
152

153
        // Cast callee to function pointer type
154
        std::string func_ptr_type;
×
155

156
        // Return type
157
        if (ret_memlet) {
×
158
            auto& ret_type = ret_memlet->result_type(function_);
×
159
            func_ptr_type = language_extension_.declaration("", ret_type) + " (*)";
×
160
        } else {
×
161
            func_ptr_type = "void (*)";
×
162
        }
163

164
        // Parameters
165
        func_ptr_type += "(";
×
166
        for (size_t i = 0; i < node.inputs().size(); i++) {
×
167
            auto memlet_in = input_memlets.find(node.inputs().at(i));
×
168
            assert(memlet_in != input_memlets.end());
×
169
            auto& in_type = memlet_in->second->result_type(function_);
×
170
            func_ptr_type += language_extension_.declaration("", in_type);
×
171
            if (i < node.inputs().size() - 1) {
×
172
                func_ptr_type += ", ";
×
173
            }
×
174
        }
×
175
        func_ptr_type += ")";
×
176

177
        if (this->language_extension_.language() == "C") {
×
178
            stream << "((" << func_ptr_type << ") " << node.callee_name() << ")" << "(";
×
179
        } else if (this->language_extension_.language() == "C++") {
×
180
            stream << "reinterpret_cast<" << func_ptr_type << ">(" << node.callee_name() << ")" << "(";
×
181
        }
×
182
    } else {
×
NEW
183
        stream << this->language_extension_.external_prefix() << node.callee_name() << "(";
×
184
    }
185
    for (size_t i = 0; i < node.inputs().size(); ++i) {
×
186
        stream << node.inputs().at(i);
×
187
        if (i < node.inputs().size() - 1) {
×
188
            stream << ", ";
×
189
        }
×
190
    }
×
191
    stream << ")" << ";";
×
192
    stream << std::endl;
×
193
}
×
194

195
} // namespace data_flow
196
} // 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