Skip to content

Commit e50a93a

Browse files
committed
Generic specializer: don't use pre-specialization for Array._endMutation
Pre-specialization of `Array._endMutation` (for AnyObject) prevents inlining this function and that results in sub-optimal code. This function is basically a no-op. So it should be inlined. Unfortunately we cannot remove the specialize-attributes anymore because the pre-specialized function(s) are now part of the stdlib's ABI. Therefore make an exception for `Array._endMutation` in the generic specializer.
1 parent c975023 commit e50a93a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2982,6 +2982,13 @@ static bool usePrespecialized(
29822982
if (refF->getSpecializeAttrs().empty())
29832983
return false;
29842984

2985+
// `Array._endMutation` was added for pre-specialization by mistake. But we
2986+
// cannot remove the specialize-attributes anymore because the pre-specialized
2987+
// functions are now part of the stdlib's ABI.
2988+
// Therefore make an exception for `Array._endMutation` here.
2989+
if (refF->getName() == "$sSa12_endMutationyyF")
2990+
return false;
2991+
29852992
SmallVector<std::tuple<unsigned, ReabstractionInfo, AvailabilityRange>, 4>
29862993
layoutMatches;
29872994

test/SILOptimizer/static_arrays.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ func takeUnsafePointer(ptr : UnsafePointer<SwiftClass>, len: Int) {
267267
// This should be a single basic block, and the array should end up being stack
268268
// allocated.
269269
//
270-
// CHECK-LABEL: sil [noinline] @{{.*passArrayOfClasses.*}} : $@convention(thin) (@guaranteed SwiftClass, @guaranteed SwiftClass, @guaranteed SwiftClass) -> () {
270+
// CHECK-LABEL: sil [noinline] @$s4test18passArrayOfClasses1a1b1cyAA10SwiftClassC_A2GtF : $@convention(thin) (@guaranteed SwiftClass, @guaranteed SwiftClass, @guaranteed SwiftClass) -> () {
271271
// CHECK: bb0(%0 : $SwiftClass, %1 : $SwiftClass, %2 : $SwiftClass):
272-
// CHECK-NOT: bb1(
273-
// CHECK: alloc_ref{{(_dynamic)?}} {{.*}}[tail_elems $SwiftClass *
274-
// CHECK-NOT: bb1(
275-
// CHECK: } // end sil function '{{.*passArrayOfClasses.*}}'
272+
// CHECK-NOT: bb1
273+
// CHECK: alloc_ref{{.*}}[stack] [tail_elems $SwiftClass *
274+
// CHECK-NOT: bb1
275+
// CHECK: } // end sil function '$s4test18passArrayOfClasses1a1b1cyAA10SwiftClassC_A2GtF'
276276
@inline(never)
277277
public func passArrayOfClasses(a: SwiftClass, b: SwiftClass, c: SwiftClass) {
278278
let arr = [a, b, c]

0 commit comments

Comments
 (0)