* Check whether function F is inlinable and, if so, what globals need to be * imported. * * References to external functions from, potentially recursively, inlined * functions are added to the passed in worklist. */
| 565 | * functions are added to the passed in worklist. |
| 566 | */ |
| 567 | static bool |
| 568 | function_inlinable(llvm::Function &F, |
| 569 | int threshold, |
| 570 | FunctionInlineStates &functionStates, |
| 571 | InlineWorkList &worklist, |
| 572 | InlineSearchPath &searchpath, |
| 573 | llvm::SmallPtrSet<const llvm::Function *, 8> &visitedFunctions, |
| 574 | int &running_instcount, |
| 575 | llvm::StringSet<> &importVars) |
| 576 | { |
| 577 | int subThreshold = threshold * inline_cost_decay_factor; |
| 578 | llvm::SmallPtrSet<llvm::GlobalVariable *, 8> referencedVars; |
| 579 | llvm::SmallPtrSet<llvm::Function *, 8> referencedFunctions; |
| 580 | |
| 581 | /* can't rely on what may be inlined */ |
| 582 | if (F.isInterposable()) |
| 583 | return false; |
| 584 | |
| 585 | /* |
| 586 | * Can't rely on function being present. Alternatively we could create a |
| 587 | * static version of these functions? |
| 588 | */ |
| 589 | if (F.hasAvailableExternallyLinkage()) |
| 590 | return false; |
| 591 | |
| 592 | ilog(DEBUG1, "checking inlinability of %s", F.getName().data()); |
| 593 | |
| 594 | if (F.materialize()) |
| 595 | elog(FATAL, "failed to materialize metadata"); |
| 596 | |
| 597 | #if LLVM_VERSION_MAJOR < 14 |
| 598 | #define hasFnAttr hasFnAttribute |
| 599 | #endif |
| 600 | |
| 601 | if (F.getAttributes().hasFnAttr(llvm::Attribute::NoInline)) |
| 602 | { |
| 603 | ilog(DEBUG1, "ineligibile to import %s due to noinline", |
| 604 | F.getName().data()); |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | function_references(F, running_instcount, referencedVars, referencedFunctions); |
| 609 | |
| 610 | for (llvm::GlobalVariable* rv: referencedVars) |
| 611 | { |
| 612 | if (rv->materialize()) |
| 613 | elog(FATAL, "failed to materialize metadata"); |
| 614 | |
| 615 | /* |
| 616 | * Don't inline functions that access thread local variables. That |
| 617 | * doesn't work on current LLVM releases (but might in future). |
| 618 | */ |
| 619 | if (rv->isThreadLocal()) |
| 620 | { |
| 621 | ilog(DEBUG1, "cannot inline %s due to thread-local variable %s", |
| 622 | F.getName().data(), rv->getName().data()); |
| 623 | return false; |
| 624 | } |
no test coverage detected