MCPcopy Create free account
hub / github.com/apache/cloudberry / llvm_execute_inline_plan

Function llvm_execute_inline_plan

src/backend/jit/llvm/llvmjit_inline.cpp:369–459  ·  view source on GitHub ↗

* Perform the actual inlining of external functions (and their dependencies) * into mod. */

Source from the content-addressed store, hash-verified

367 * into mod.
368 */
369static void
370llvm_execute_inline_plan(llvm::Module *mod, ImportMapTy *globalsToInline)
371{
372 llvm::IRMover Mover(*mod);
373
374 for (const auto& toInline : *globalsToInline)
375 {
376 const llvm::StringRef& modPath = toInline.first();
377 const llvm::StringSet<>& modGlobalsToInline = toInline.second;
378 llvm::SetVector<llvm::GlobalValue *> GlobalsToImport;
379
380 Assert(module_cache->count(modPath));
381 std::unique_ptr<llvm::Module> importMod(std::move((*module_cache)[modPath]));
382 module_cache->erase(modPath);
383
384 if (modGlobalsToInline.empty())
385 continue;
386
387 for (auto &glob: modGlobalsToInline)
388 {
389 llvm::StringRef SymbolName = glob.first();
390 char *modname;
391 char *funcname;
392
393 llvm_split_symbol_name(SymbolName.data(), &modname, &funcname);
394
395 llvm::GlobalValue *valueToImport = importMod->getNamedValue(funcname);
396
397 if (!valueToImport)
398 elog(FATAL, "didn't refind value %s to import", SymbolName.data());
399
400 /*
401 * For functions (global vars are only inlined if already static),
402 * mark imported variables as being clones from other
403 * functions. That a) avoids symbol conflicts b) allows the
404 * optimizer to perform inlining.
405 */
406 if (llvm::isa<llvm::Function>(valueToImport))
407 {
408 llvm::Function *F = llvm::dyn_cast<llvm::Function>(valueToImport);
409 typedef llvm::GlobalValue::LinkageTypes LinkageTypes;
410
411 /*
412 * Per-function info isn't necessarily stripped yet, as the
413 * module is lazy-loaded when stripped above.
414 */
415 llvm::stripDebugInfo(*F);
416
417 /*
418 * If the to-be-imported function is one referenced including
419 * its module name, create a tiny inline function that just
420 * forwards the call. One might think a GlobalAlias would do
421 * the trick, but a) IRMover doesn't override a declaration
422 * with an alias pointing to a definition (instead renaming
423 * it), b) Aliases can't be AvailableExternally.
424 */
425 if (modname)
426 {

Callers 1

llvm_inlineFunction · 0.85

Calls 4

llvm_split_symbol_nameFunction · 0.85
firstMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected