@@ -145,6 +145,10 @@ llvm::cl::opt<int> OSizeClassMethodBenefit(
145
145
llvm::cl::desc(" The benefit of inlining class methods with -Osize. We only "
146
146
" inline very small class methods with -Osize." ));
147
147
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
+
148
152
llvm::cl::opt<int > TrivialFunctionThreshold (
149
153
" sil-inline-trivial-function-threshold" , llvm::cl::init(18 ),
150
154
llvm::cl::desc(" Approximately up to this cost level a function can be "
@@ -445,6 +449,14 @@ bool isFunctionAutodiffVJP(SILFunction *callee) {
445
449
return false ;
446
450
}
447
451
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
+
448
460
bool isProfitableToInlineAutodiffVJP (SILFunction *vjp, SILFunction *caller,
449
461
InlineSelection whatToInline,
450
462
StringRef stageName) {
@@ -785,6 +797,12 @@ bool SILPerformanceInliner::isProfitableToInline(
785
797
Benefit = std::max (Benefit, ExclusivityBenefitWeight);
786
798
}
787
799
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
+
788
806
if (AI.getFunction ()->isThunk ()) {
789
807
// Only inline trivial functions into thunks (which will not increase the
790
808
// code size).
0 commit comments