Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 0992e77

Browse files
authored
Enable GenericSpecializer on OSSA by default (swiftlang#34899)
1 parent b9a895f commit 0992e77

13 files changed

+111
-19
lines changed

lib/SILOptimizer/Transforms/GenericSpecializer.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
using namespace swift;
3030

31-
// For testing during bring up.
32-
static llvm::cl::opt<bool> EnableGenericSpecializerWithOwnership(
33-
"sil-generic-specializer-enable-ownership", llvm::cl::init(false));
34-
3531
namespace {
3632

3733
class GenericSpecializer : public SILFunctionTransform {
@@ -42,10 +38,6 @@ class GenericSpecializer : public SILFunctionTransform {
4238
void run() override {
4339
SILFunction &F = *getFunction();
4440

45-
// TODO: We should be able to handle ownership.
46-
if (F.hasOwnership() && !EnableGenericSpecializerWithOwnership)
47-
return;
48-
4941
LLVM_DEBUG(llvm::dbgs() << "***** GenericSpecializer on function:"
5042
<< F.getName() << " *****\n");
5143

test/IRGen/objc_super.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,5 @@ class GenericRuncer<T> : Gizmo {
136136
}
137137

138138
// CHECK: define internal swiftcc void [[PARTIAL_FORWARDING_THUNK]](%swift.refcounted* swiftself %0) {{.*}} {
139-
// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_"
139+
// CHECK: @"$ss12StaticStringV14withUTF8BufferyxxSRys5UInt8VGXElFxAFXEfU_yt_Tgq5"
140140
// CHECK: }

test/SILOptimizer/optionset.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let globalTestOptions: TestOptions = [.first, .second, .third, .fourth]
2323
// CHECK-NEXT: builtin
2424
// CHECK-NEXT: integer_literal {{.*}}, 15
2525
// CHECK-NEXT: struct $Int
26-
// CHECK-NEXT: struct $TestOptions
26+
// CHECK: struct $TestOptions
2727
// CHECK-NEXT: return
2828
public func returnTestOptions() -> TestOptions {
2929
return [.first, .second, .third, .fourth]
@@ -32,8 +32,8 @@ public func returnTestOptions() -> TestOptions {
3232
// CHECK-LABEL: sil @{{.*}}returnEmptyTestOptions{{.*}}
3333
// CHECK-NEXT: bb0:
3434
// CHECK-NEXT: integer_literal {{.*}}, 0
35-
// CHECK-NEXT: builtin "onFastPath"() : $()
3635
// CHECK-NEXT: struct $Int
36+
// CHECK: builtin "onFastPath"() : $()
3737
// CHECK-NEXT: struct $TestOptions
3838
// CHECK-NEXT: return
3939
public func returnEmptyTestOptions() -> TestOptions {

test/SILOptimizer/specialize_default_witness_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -sil-generic-specializer-enable-ownership -generic-specializer %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
22

33
sil_stage canonical
44

test/SILOptimizer/specialize_default_witness_resilience_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-library-evolution -enable-sil-verify-all -generic-specializer -sil-generic-specializer-enable-ownership %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-library-evolution -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
22

33
sil_stage canonical
44

test/SILOptimizer/specialize_inherited_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer -module-name inherit -sil-generic-specializer-enable-ownership %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer -module-name inherit %s | %FileCheck %s
22

33
import Builtin
44
import Swift
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -generic-specializer | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// This test checks that we properly distinguish in between the specialized
6+
// functions for the @thick, @thin, and @objc_metatype metatypes.
7+
//
8+
// This can occur if we do not properly mangle in the metatype representation
9+
// into the name of functions and thus reuse the incorrect already specialized
10+
// method instead of the new specialized method.
11+
12+
sil_stage canonical
13+
14+
import Builtin
15+
16+
protocol AnyObject {}
17+
18+
sil [noinline] @tmp : $@convention(thin) <T> () -> (@out T) {
19+
bb0(%0 : $*T):
20+
%1 = tuple()
21+
return %1 : $()
22+
}
23+
24+
// CHECK-LABEL: sil [ossa] @tmp2 : $@convention(thin) () -> () {
25+
// CHECK: [[FUN1:%[0-9]+]] = function_ref @$s3tmp4main9AnyObject_pXmT_Tg5 : $@convention(thin) () -> @thick AnyObject.Type
26+
// CHECK-NEXT: apply [[FUN1]]
27+
// CHECK: [[FUN2:%[0-9]+]] = function_ref @$s3tmp4main9AnyObject_pXmo_Tg5 : $@convention(thin) () -> @objc_metatype AnyObject.Type
28+
// CHECK-NEXT: apply [[FUN2]]
29+
// CHECK: [[FUN3:%[0-9]+]] = function_ref @$s3tmpBi32_XMT_Tg5 : $@convention(thin) () -> @thick Builtin.Int32.Type
30+
// CHECK-NEXT: apply [[FUN3]]
31+
// CHECK: [[FUN4:%[0-9]+]] = function_ref @$s3tmpBi32_XMo_Tg5 : $@convention(thin) () -> @objc_metatype Builtin.Int32.Type
32+
// CHECK-NEXT: apply [[FUN4]]
33+
// CHECK: [[FUN5:%[0-9]+]] = function_ref @$s3tmpBi32_XMt_Tg5 : $@convention(thin) () -> @thin Builtin.Int32.Type
34+
// CHECK-NEXT: apply [[FUN5]]
35+
sil [ossa] @tmp2 : $@convention(thin) () -> () {
36+
bb0:
37+
%0 = function_ref @tmp : $@convention(thin) <T> () -> (@out T)
38+
%1 = alloc_box $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type>
39+
%1a = project_box %1 : $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type>, 0
40+
%2 = alloc_box $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type>
41+
%2a = project_box %2 : $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type>, 0
42+
%4 = apply %0<@thick AnyObject.Type>(%1a) : $@convention(thin) <T> () -> (@out T)
43+
%5 = apply %0<@objc_metatype AnyObject.Type>(%2a) : $@convention(thin) <T> () -> (@out T)
44+
45+
%6 = alloc_box $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type>
46+
%6a = project_box %6 : $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type>, 0
47+
%7 = alloc_box $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type>
48+
%7a = project_box %7 : $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type>, 0
49+
%8 = alloc_box $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type>
50+
%8a = project_box %8 : $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type>, 0
51+
%9 = apply %0<@thick Builtin.Int32.Type>(%6a) : $@convention(thin) <T> () -> (@out T)
52+
%10 = apply %0<@objc_metatype Builtin.Int32.Type>(%7a) : $@convention(thin) <T> () -> (@out T)
53+
%11 = apply %0<@thin Builtin.Int32.Type>(%8a) : $@convention(thin) <T> () -> (@out T)
54+
destroy_value %8 : $<τ_0_0> { var τ_0_0 } <@thin Builtin.Int32.Type>
55+
destroy_value %7 : $<τ_0_0> { var τ_0_0 } <@objc_metatype Builtin.Int32.Type>
56+
destroy_value %6 : $<τ_0_0> { var τ_0_0 } <@thick Builtin.Int32.Type>
57+
destroy_value %2 : $<τ_0_0> { var τ_0_0 } <@objc_metatype AnyObject.Type>
58+
destroy_value %1 : $<τ_0_0> { var τ_0_0 } <@thick AnyObject.Type>
59+
%9999 = tuple()
60+
return %9999 : $()
61+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer -save-optimization-record-path=%t.yaml -o /dev/null %/s
2+
// RUN: %FileCheck %s < %t.yaml
3+
4+
import Builtin
5+
import Swift
6+
7+
sil_stage canonical
8+
9+
// CHECK: --- !Missed
10+
// CHECK-NEXT: Pass: sil-generic-specializer
11+
// CHECK-NEXT: Name: sil.NoDef
12+
// CHECK-NEXT: DebugLoc:
13+
// CHECK: File: {{.*}}/specialize_no_definition_ossa.sil
14+
// CHECK: Line: 33
15+
// CHECK: Column: 8
16+
// CHECK-NEXT: Function: foo
17+
// CHECK-NEXT: Args:
18+
// CHECK-NEXT: - String: 'Unable to specialize generic function '
19+
// CHECK-NEXT: - Callee: '"bar"'
20+
// CHECK-NEXT: DebugLoc:
21+
// CHECK: File: {{.*}}/specialize_no_definition_ossa.sil
22+
// CHECK: Line: 32
23+
// CHECK: Column: 21
24+
// CHECK-NEXT: - String: ' since definition is not visible'
25+
// CHECK-NEXT: ...
26+
sil hidden [ossa] @foo : $@convention(thin) () -> () {
27+
bb0:
28+
%0 = integer_literal $Builtin.Int64, 2
29+
%1 = struct $Int64 (%0 : $Builtin.Int64)
30+
%2 = alloc_stack $Int64
31+
store %1 to [trivial] %2 : $*Int64
32+
%4 = function_ref @bar : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
33+
%5 = apply %4<Int64>(%2) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
34+
dealloc_stack %2 : $*Int64
35+
%7 = tuple ()
36+
return %7 : $()
37+
}
38+
39+
sil hidden_external @bar : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()

test/SILOptimizer/specialize_opaque_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-opaque-values -enable-sil-verify-all -generic-specializer -sil-generic-specializer-enable-ownership %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-opaque-values -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
22

33
sil_stage canonical
44

test/SILOptimizer/specialize_opaque_result_types_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -disable-availability-checking %S/Inputs/opaque_result_types.swift -module-name External -emit-module -emit-module-path %t/External.swiftmodule
3-
// RUN: %target-sil-opt -I %t -enable-sil-verify-all %s -generic-specializer -sil-generic-specializer-enable-ownership | %FileCheck %s
3+
// RUN: %target-sil-opt -I %t -enable-sil-verify-all %s -generic-specializer | %FileCheck %s
44

55
// REQUIRES: CPU=x86_64
66

test/SILOptimizer/specialize_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -sil-partial-specialization -generic-specializer -sil-generic-specializer-enable-ownership %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all -sil-partial-specialization -generic-specializer %s | %FileCheck %s
22

33
sil_stage canonical
44

test/SILOptimizer/specialize_reabstraction_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer -sil-generic-specializer-enable-ownership %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
22

33
sil_stage canonical
44

test/SILOptimizer/specialize_recursive_generics_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all %s -generic-specializer -cse -sil-generic-specializer-enable-ownership | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -generic-specializer -cse | %FileCheck %s
22

33
// Check that SIL cloner can correctly handle specialization of recursive
44
// functions with generic arguments.

0 commit comments

Comments
 (0)