| 316 | }; |
| 317 | |
| 318 | struct GraphFuncCallType : public NodeType { |
| 319 | GraphFuncCallType(GraphModule& json_module, std::string funcname, Result* resPtr) |
| 320 | : NodeType(json_module, std::move(funcname), ""), JModule(&json_module) { |
| 321 | Result& res = *resPtr; |
| 322 | |
| 323 | auto* mygraph = JModule->functionFromName(name()); |
| 324 | setDescription(mygraph->description()); |
| 325 | |
| 326 | if (mygraph == nullptr) { |
| 327 | res.addEntry("EINT", "Graph doesn't exist in module", |
| 328 | {{"Module Name", JModule->fullName()}, {"Requested Name", name()}}); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | setDataOutputs(mygraph->dataOutputs()); |
| 333 | |
| 334 | setDataInputs(mygraph->dataInputs()); |
| 335 | |
| 336 | setExecInputs(mygraph->execInputs()); |
| 337 | setExecOutputs(mygraph->execOutputs()); |
| 338 | } |
| 339 | |
| 340 | Result codegen(size_t execInputID, const llvm::DebugLoc& nodeLocation, |
| 341 | const std::vector<llvm::Value*>& io, llvm::BasicBlock* codegenInto, |
| 342 | const std::vector<llvm::BasicBlock*>& outputBlocks, |
| 343 | std::unordered_map<std::string, std::shared_ptr<void>>& compileCache) override { |
| 344 | Result res = {}; |
| 345 | |
| 346 | llvm::IRBuilder<> builder(codegenInto); |
| 347 | builder.SetCurrentDebugLocation(nodeLocation); |
| 348 | |
| 349 | auto func = codegenInto |
| 350 | -> |
| 351 | #if LLVM_VERSION_LESS_EQUAL(3, 6) |
| 352 | getParent() |
| 353 | ->getParent() |
| 354 | #else |
| 355 | getModule() |
| 356 | #endif |
| 357 | ->getFunction(mangleFunctionName(module().fullName(), name())); |
| 358 | |
| 359 | if (func == nullptr) { |
| 360 | res.addEntry("EINT", "Could not find function in llvm module", |
| 361 | {{"Requested Function", name()}}); |
| 362 | return res; |
| 363 | } |
| 364 | |
| 365 | // add the execInputID to the argument list |
| 366 | std::vector<llvm::Value*> passingIO; |
| 367 | passingIO.push_back(builder.getInt32(execInputID)); |
| 368 | |
| 369 | std::copy(io.begin(), io.end(), std::back_inserter(passingIO)); |
| 370 | |
| 371 | auto ret = builder.CreateCall(func, passingIO, "call_function"); |
| 372 | |
| 373 | // create switch on return |
| 374 | auto switchInst = builder.CreateSwitch(ret, outputBlocks[0]); // TODO: better default |
| 375 |
nothing calls this directly
no outgoing calls
no test coverage detected