Skip to content

Commit 2ae8fb3

Browse files
committed
PerformanceInliner: protect against misuse of @inline(__always)
Inline-always should only be used on relatively small functions. It must not be used on recursive functions. Add a check that prevents that inlining of large @inline(__always) functions. #64319 rdar://106655649
1 parent bb1d321 commit 2ae8fb3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,29 @@ static bool returnsClosure(SILFunction *F) {
619619
return false;
620620
}
621621

622+
static bool hasMaxNumberOfBasicBlocks(SILFunction *f, int limit) {
623+
for (SILBasicBlock &block : *f) {
624+
(void)block;
625+
if (limit == 0)
626+
return false;
627+
limit--;
628+
}
629+
return true;
630+
}
631+
622632
static bool isInlineAlwaysCallSite(SILFunction *Callee) {
623633
if (Callee->isTransparent())
624634
return true;
625-
if (Callee->getInlineStrategy() == AlwaysInline)
626-
if (!Callee->getModule().getOptions().IgnoreAlwaysInline)
627-
return true;
635+
if (Callee->getInlineStrategy() == AlwaysInline &&
636+
!Callee->getModule().getOptions().IgnoreAlwaysInline &&
637+
638+
// Protect against misuse of @inline(__always).
639+
// Inline-always should only be used on relatively small functions.
640+
// It must not be used on recursive functions. This check prevents that
641+
// the compiler blows up if @inline(__always) is put on a recursive function.
642+
hasMaxNumberOfBasicBlocks(Callee, 100)) {
643+
return true;
644+
}
628645
return false;
629646
}
630647

0 commit comments

Comments
 (0)