Skip to content

Commit b329a10

Browse files
committed
Inliner: don't set the lexical flag on an argument alloc_stack if the inlined function is not a deinit barrier.
There is no need to do so. And this can enable other optimizations for non-lexical alloc-stacks.
1 parent dc5e34c commit b329a10

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ void SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
500500
if (!enableLexicalLifetimes)
501501
continue;
502502

503+
if (!Original.isDeinitBarrier())
504+
continue;
505+
503506
// Exclusive mutating accesses don't entail a lexical scope.
504507
if (paramInfo.getConvention() == ParameterConvention::Indirect_Inout)
505508
continue;

test/SILOptimizer/mandatory_inlining_ownership.sil

+35
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,41 @@ bb3:
619619
return %9999 : $()
620620
}
621621

622+
sil [transparent] [ossa] @deinit_barrier : $@convention(thin) (@in_guaranteed Int) -> () {
623+
[global: deinit_barrier]
624+
bb0(%0 : $*Int):
625+
%1 = tuple ()
626+
return %1
627+
}
628+
629+
sil [transparent] [ossa] @no_deinit_barrier : $@convention(thin) (@in_guaranteed Int) -> () {
630+
[global: ]
631+
bb0(%0 : $*Int):
632+
%1 = tuple ()
633+
return %1
634+
}
635+
636+
// CHECK-LABEL: sil [ossa] @inline_deinit_barrier :
637+
// CHECK: alloc_stack [lexical] $Int
638+
// CHECK: alloc_stack $Int
639+
// CHECK: } // end sil function 'inline_deinit_barrier'
640+
sil [ossa] @inline_deinit_barrier : $@convention(thin) (Int) -> () {
641+
bb0(%0 : $Int):
642+
%1 = alloc_stack $Int
643+
store %0 to [trivial] %1
644+
%2 = function_ref @deinit_barrier : $@convention(thin) (@in_guaranteed Int) -> ()
645+
apply %2(%1) : $@convention(thin) (@in_guaranteed Int) -> ()
646+
dealloc_stack %1
647+
648+
%10 = alloc_stack $Int
649+
store %0 to [trivial] %10
650+
%12 = function_ref @no_deinit_barrier : $@convention(thin) (@in_guaranteed Int) -> ()
651+
apply %12(%10) : $@convention(thin) (@in_guaranteed Int) -> ()
652+
dealloc_stack %10
653+
654+
%r = tuple ()
655+
return %r
656+
}
622657

623658
sil_vtable C2 {
624659
#C2.i!modify: (C2) -> () -> () : @devirt_callee

0 commit comments

Comments
 (0)