@@ -145,6 +145,10 @@ llvm::cl::opt<int> OSizeClassMethodBenefit(
145145 llvm::cl::desc(" The benefit of inlining class methods with -Osize. We only "
146146 " inline very small class methods with -Osize." ));
147147
148+ llvm::cl::opt<int > GlobalInitBenefit (
149+ " sil-inline-global-init-benefit" , llvm::cl::init(100 ),
150+ llvm::cl::desc(" The benefit of inlining constructors into global initializers." ));
151+
148152llvm::cl::opt<int > TrivialFunctionThreshold (
149153 " sil-inline-trivial-function-threshold" , llvm::cl::init(18 ),
150154 llvm::cl::desc(" Approximately up to this cost level a function can be "
@@ -445,6 +449,14 @@ bool isFunctionAutodiffVJP(SILFunction *callee) {
445449 return false ;
446450}
447451
452+ bool isAllocator (SILFunction *callee) {
453+ swift::Demangle::Context Ctx;
454+ if (auto *Root = Ctx.demangleSymbolAsNode (callee->getName ())) {
455+ return Root->findByKind (swift::Demangle::Node::Kind::Allocator, 3 ) != nullptr ;
456+ }
457+ return false ;
458+ }
459+
448460bool isProfitableToInlineAutodiffVJP (SILFunction *vjp, SILFunction *caller,
449461 InlineSelection whatToInline,
450462 StringRef stageName) {
@@ -785,6 +797,12 @@ bool SILPerformanceInliner::isProfitableToInline(
785797 Benefit = std::max (Benefit, ExclusivityBenefitWeight);
786798 }
787799
800+ if (AI.getFunction ()->isGlobalInitOnceFunction () && isAllocator (Callee)) {
801+ // Inlining constructors into global initializers increase the changes that
802+ // the global can be initialized statically.
803+ CallerWeight.updateBenefit (Benefit, GlobalInitBenefit);
804+ }
805+
788806 if (AI.getFunction ()->isThunk ()) {
789807 // Only inline trivial functions into thunks (which will not increase the
790808 // code size).
0 commit comments