Skip to content

Commit 2f325d9

Browse files
author
Emanuel Zephir
committed
[SILOptimizer] Refactor ObjC dependencies in sil_combine tests
Move functionality that requires ObjC interop into a new file and remove the XFAIL on Linux. Partially resolves SR-216.
1 parent 5ce3de8 commit 2f325d9

File tree

2 files changed

+150
-138
lines changed

2 files changed

+150
-138
lines changed

test/SILOptimizer/sil_combine.sil

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -verify-skip-unreachable-must-be-last | FileCheck %s
22

3-
// XFAIL: linux
4-
53
sil_stage canonical
64

75
import Builtin
@@ -694,48 +692,6 @@ bb0(%0 : $*X):
694692
return %19 : $()
695693
}
696694

697-
sil @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
698-
sil @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
699-
700-
// CHECK-LABEL: sil @dead_closure_elimination : $@convention(thin) (@owned _StringCore) -> ()
701-
// CHECK: bb0
702-
// CHECK-NEXT: release_value
703-
// CHECK-NEXT: tuple
704-
// CHECK-NEXT: return
705-
sil @dead_closure_elimination : $@convention(thin) (@owned _StringCore) -> () {
706-
bb0(%0 : $_StringCore):
707-
%1 = function_ref @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
708-
%2 = partial_apply %1(%0) : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
709-
%3 = function_ref @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
710-
%4 = partial_apply %3(%2) : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
711-
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
712-
%5 = tuple()
713-
return %5 : $()
714-
}
715-
716-
// CHECK-LABEL: sil @dead_closure_elimination2
717-
// CHECK: bb0
718-
// CHECK-NEXT: br bb1
719-
// CHECK: bb1
720-
// CHECK-NEXT: release_value
721-
// CHECK-NEXT: tuple
722-
// CHECK-NEXT: return
723-
sil @dead_closure_elimination2 : $@convention(thin) (@owned _StringCore) -> () {
724-
bb0(%0 : $_StringCore):
725-
%1 = function_ref @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
726-
%2 = partial_apply %1(%0) : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
727-
%3 = function_ref @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
728-
%4 = partial_apply %3(%2) : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
729-
br bb1
730-
731-
bb1:
732-
strong_retain %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
733-
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
734-
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
735-
%5 = tuple()
736-
return %5 : $()
737-
}
738-
739695
sil @unbalanced_closure : $@convention(thin) (@guaranteed B) -> ()
740696

741697
// CHECK-LABEL: sil @partial_apply_unbalanced_retain_release
@@ -1855,32 +1811,6 @@ bb3(%a : $ZZZ):
18551811
return %a : $ZZZ
18561812
}
18571813

1858-
1859-
// FIXME: <rdar://problem/20980377> Add dead array elimination to DeadObjectElimination
1860-
// CHECK-LABEL: test_dead_array
1861-
// CHECK: bb0(%0 : $ZZZ):
1862-
// DISABLED-CHECK-NEXT: strong_release %0
1863-
// DISABLED-CHECK-NEXT: tuple
1864-
// DISABLED-CHECK-NEXT: return
1865-
sil @test_dead_array : $@convention(thin) (@owned ZZZ) -> () {
1866-
bb0(%0 : $ZZZ):
1867-
%1 = integer_literal $Builtin.Word, 1
1868-
%2 = function_ref @_allocate_uninitialized_ZZZ : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
1869-
%3 = apply %2(%1) : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
1870-
%4 = tuple_extract %3 : $(Array<ZZZ>, Builtin.RawPointer), 0
1871-
%5 = tuple_extract %3 : $(Array<ZZZ>, Builtin.RawPointer), 1
1872-
%6 = pointer_to_address %5 : $Builtin.RawPointer to $*ZZZ
1873-
store %0 to %6 : $*ZZZ
1874-
%8 = struct_extract %4 : $Array<ZZZ>, #Array._buffer
1875-
%9 = struct_extract %8 : $_ArrayBuffer<ZZZ>, #_ArrayBuffer._storage
1876-
%10 = struct_extract %9 : $_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCoreType>, #_BridgeStorage.rawValue
1877-
strong_release %10 : $Builtin.BridgeObject
1878-
%12 = tuple ()
1879-
return %12 : $()
1880-
}
1881-
1882-
sil [_semantics "array.uninitialized"] @_allocate_uninitialized_ZZZ : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
1883-
18841814
struct FakeInt16 {
18851815
var val : Builtin.Int16
18861816
}
@@ -2602,55 +2532,6 @@ bb0(%0 : $Builtin.Int1):
26022532
return %2 : $Builtin.Int1
26032533
}
26042534

2605-
// dead_array test helpers
2606-
sil [thunk] @dead_array_run_closure : $@convention(thin) (@owned @callee_owned () -> Bool) -> () {
2607-
bb0(%0 : $@callee_owned () -> Bool):
2608-
%1 = apply %0() : $@callee_owned () -> Bool
2609-
%2 = tuple ()
2610-
return %2 : $()
2611-
}
2612-
2613-
sil @dead_array_closure : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool {
2614-
bb0(%0 : $*_HeapBuffer<C, Int>):
2615-
%1 = struct_element_addr %0 : $*_HeapBuffer<C, Int>, #_HeapBuffer._storage // user: %2
2616-
%2 = is_unique %1 : $*Optional<Builtin.NativeObject> // user: %3
2617-
%3 = struct $Bool (%2 : $Builtin.Int1) // user: %4
2618-
return %3 : $Bool // id: %4
2619-
}
2620-
2621-
// Mimicks Swift._allocateUninitializedArray
2622-
sil [_semantics "array.uninitialized"] @dead_array_alloc : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
2623-
2624-
// <rdar://problem/20980377> HeapBuffer.swift test case spuriously reports a "unique" buffer
2625-
// CHECK-LABEL: sil @dead_array
2626-
// CHECK-NOT: release
2627-
// CHECK: retain_value %{{[0-9]+}} : $Optional<Builtin.NativeObject>
2628-
// CHECK: apply
2629-
// CHECK: strong_release %{{[0-9]+}} : $Builtin.BridgeObject
2630-
sil @dead_array : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> () {
2631-
bb0(%0 : $*_HeapBuffer<C, Int>):
2632-
%1 = integer_literal $Builtin.Word, 1 // user: %3
2633-
%2 = function_ref @dead_array_alloc : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
2634-
%3 = apply %2<_HeapBuffer<C, Int>>(%1) : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
2635-
%4 = tuple_extract %3 : $(Array<_HeapBuffer<C, Int>>, Builtin.RawPointer), 0 // user: %15
2636-
%5 = tuple_extract %3 : $(Array<_HeapBuffer<C, Int>>, Builtin.RawPointer), 1 // user: %6
2637-
%6 = pointer_to_address %5 : $Builtin.RawPointer to $*_HeapBuffer<C, Int> // user: %9
2638-
%7 = load %0 : $*_HeapBuffer<C, Int> // users: %8, %9
2639-
%8 = struct_extract %7 : $_HeapBuffer<C, Int>, #_HeapBuffer._storage // user: %13
2640-
store %7 to %6 : $*_HeapBuffer<C, Int> // id: %9
2641-
%10 = function_ref @dead_array_run_closure : $@convention(thin) (@owned @callee_owned () -> Bool) -> () // user: %14
2642-
%11 = function_ref @dead_array_closure : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool // user: %12
2643-
%12 = partial_apply %11(%0) : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool // user: %14
2644-
retain_value %8 : $Optional<Builtin.NativeObject> // id: %13
2645-
%14 = apply %10(%12) : $@convention(thin) (@owned @callee_owned () -> Bool) -> ()
2646-
%15 = struct_extract %4 : $Array<_HeapBuffer<C, Int>>, #Array._buffer // user: %16
2647-
%16 = struct_extract %15 : $_ArrayBuffer<_HeapBuffer<C, Int>>, #_ArrayBuffer._storage // user: %17
2648-
%17 = struct_extract %16 : $_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCoreType>, #_BridgeStorage.rawValue // user: %18
2649-
strong_release %17 : $Builtin.BridgeObject // id: %18
2650-
%19 = tuple () // user: %20
2651-
return %19 : $() // id: %20
2652-
}
2653-
26542535
struct NStruct {
26552536
var a:Int
26562537
var b:Int
@@ -2792,25 +2673,6 @@ bb0:
27922673
return %2 : $Builtin.Int1
27932674
}
27942675

2795-
// Check that it does not crash the compiler.
2796-
// Int is ObjC-bridgeable in this case, but its conformance is not know,
2797-
// because Foundation is not imported yet.
2798-
// Therefore the cast may succeed from the compiler point of view.
2799-
// CHECK-LABEL: sil @cast_of_class_to_int
2800-
// CHECK: unconditional_checked_cast_addr
2801-
// CHECK: return
2802-
sil @cast_of_class_to_int : $@convention(thin) (C) -> Int {
2803-
bb0(%0 : $C):
2804-
%1 = alloc_stack $Int
2805-
%2 = alloc_stack $C
2806-
store %0 to %2#1 : $*C
2807-
unconditional_checked_cast_addr take_always C in %2#1 : $*C to Int in %1#1 : $*Int
2808-
%4 = load %1#1 : $*Int
2809-
dealloc_stack %2#0 : $*@local_storage C
2810-
dealloc_stack %1#0 : $*@local_storage Int
2811-
return %4 : $Int
2812-
}
2813-
28142676
class CC1 {
28152677
deinit
28162678
init()
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -verify-skip-unreachable-must-be-last | FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
sil_stage canonical
5+
6+
import Builtin
7+
import Swift
8+
9+
class ZZZ {
10+
@objc deinit
11+
init()
12+
}
13+
14+
class C {}
15+
16+
sil @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
17+
sil @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
18+
19+
// CHECK-LABEL: sil @dead_closure_elimination : $@convention(thin) (@owned _StringCore) -> ()
20+
// CHECK: bb0
21+
// CHECK-NEXT: release_value
22+
// CHECK-NEXT: tuple
23+
// CHECK-NEXT: return
24+
sil @dead_closure_elimination : $@convention(thin) (@owned _StringCore) -> () {
25+
bb0(%0 : $_StringCore):
26+
%1 = function_ref @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
27+
%2 = partial_apply %1(%0) : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
28+
%3 = function_ref @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
29+
%4 = partial_apply %3(%2) : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
30+
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
31+
%5 = tuple()
32+
return %5 : $()
33+
}
34+
35+
// CHECK-LABEL: sil @dead_closure_elimination2
36+
// CHECK: bb0
37+
// CHECK-NEXT: br bb1
38+
// CHECK: bb1
39+
// CHECK-NEXT: release_value
40+
// CHECK-NEXT: tuple
41+
// CHECK-NEXT: return
42+
sil @dead_closure_elimination2 : $@convention(thin) (@owned _StringCore) -> () {
43+
bb0(%0 : $_StringCore):
44+
%1 = function_ref @stringcore_invariant_check : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
45+
%2 = partial_apply %1(%0) : $@convention(thin) (@owned _StringCore) -> @owned Optional<_CocoaStringType>
46+
%3 = function_ref @reabstraction_thunk : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
47+
%4 = partial_apply %3(%2) : $@convention(thin) (@out Optional<_CocoaStringType>, @owned @callee_owned () -> @owned Optional<_CocoaStringType>) -> ()
48+
br bb1
49+
50+
bb1:
51+
strong_retain %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
52+
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
53+
strong_release %4 : $@callee_owned (@out Optional<_CocoaStringType>) -> ()
54+
%5 = tuple()
55+
return %5 : $()
56+
}
57+
58+
// FIXME: <rdar://problem/20980377> Add dead array elimination to DeadObjectElimination
59+
// CHECK-LABEL: test_dead_array
60+
// CHECK: bb0(%0 : $ZZZ):
61+
// DISABLED-CHECK-NEXT: strong_release %0
62+
// DISABLED-CHECK-NEXT: tuple
63+
// DISABLED-CHECK-NEXT: return
64+
sil @test_dead_array : $@convention(thin) (@owned ZZZ) -> () {
65+
bb0(%0 : $ZZZ):
66+
%1 = integer_literal $Builtin.Word, 1
67+
%2 = function_ref @_allocate_uninitialized_ZZZ : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
68+
%3 = apply %2(%1) : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
69+
%4 = tuple_extract %3 : $(Array<ZZZ>, Builtin.RawPointer), 0
70+
%5 = tuple_extract %3 : $(Array<ZZZ>, Builtin.RawPointer), 1
71+
%6 = pointer_to_address %5 : $Builtin.RawPointer to $*ZZZ
72+
store %0 to %6 : $*ZZZ
73+
%8 = struct_extract %4 : $Array<ZZZ>, #Array._buffer
74+
%9 = struct_extract %8 : $_ArrayBuffer<ZZZ>, #_ArrayBuffer._storage
75+
%10 = struct_extract %9 : $_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCoreType>, #_BridgeStorage.rawValue
76+
strong_release %10 : $Builtin.BridgeObject
77+
%12 = tuple ()
78+
return %12 : $()
79+
}
80+
81+
sil [_semantics "array.uninitialized"] @_allocate_uninitialized_ZZZ : $@convention(thin) (Builtin.Word) -> @owned (Array<ZZZ>, Builtin.RawPointer)
82+
83+
// dead_array test helpers
84+
sil [thunk] @dead_array_run_closure : $@convention(thin) (@owned @callee_owned () -> Bool) -> () {
85+
bb0(%0 : $@callee_owned () -> Bool):
86+
%1 = apply %0() : $@callee_owned () -> Bool
87+
%2 = tuple ()
88+
return %2 : $()
89+
}
90+
91+
sil @dead_array_closure : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool {
92+
bb0(%0 : $*_HeapBuffer<C, Int>):
93+
%1 = struct_element_addr %0 : $*_HeapBuffer<C, Int>, #_HeapBuffer._storage // user: %2
94+
%2 = is_unique %1 : $*Optional<Builtin.NativeObject> // user: %3
95+
%3 = struct $Bool (%2 : $Builtin.Int1) // user: %4
96+
return %3 : $Bool // id: %4
97+
}
98+
99+
// Mimicks Swift._allocateUninitializedArray
100+
sil [_semantics "array.uninitialized"] @dead_array_alloc : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
101+
102+
// <rdar://problem/20980377> HeapBuffer.swift test case spuriously reports a "unique" buffer
103+
// CHECK-LABEL: sil @dead_array
104+
// CHECK-NOT: release
105+
// CHECK: retain_value %{{[0-9]+}} : $Optional<Builtin.NativeObject>
106+
// CHECK: apply
107+
// CHECK: strong_release %{{[0-9]+}} : $Builtin.BridgeObject
108+
sil @dead_array : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> () {
109+
bb0(%0 : $*_HeapBuffer<C, Int>):
110+
%1 = integer_literal $Builtin.Word, 1 // user: %3
111+
%2 = function_ref @dead_array_alloc : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
112+
%3 = apply %2<_HeapBuffer<C, Int>>(%1) : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer)
113+
%4 = tuple_extract %3 : $(Array<_HeapBuffer<C, Int>>, Builtin.RawPointer), 0 // user: %15
114+
%5 = tuple_extract %3 : $(Array<_HeapBuffer<C, Int>>, Builtin.RawPointer), 1 // user: %6
115+
%6 = pointer_to_address %5 : $Builtin.RawPointer to $*_HeapBuffer<C, Int> // user: %9
116+
%7 = load %0 : $*_HeapBuffer<C, Int> // users: %8, %9
117+
%8 = struct_extract %7 : $_HeapBuffer<C, Int>, #_HeapBuffer._storage // user: %13
118+
store %7 to %6 : $*_HeapBuffer<C, Int> // id: %9
119+
%10 = function_ref @dead_array_run_closure : $@convention(thin) (@owned @callee_owned () -> Bool) -> () // user: %14
120+
%11 = function_ref @dead_array_closure : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool // user: %12
121+
%12 = partial_apply %11(%0) : $@convention(thin) (@inout _HeapBuffer<C, Int>) -> Bool // user: %14
122+
retain_value %8 : $Optional<Builtin.NativeObject> // id: %13
123+
%14 = apply %10(%12) : $@convention(thin) (@owned @callee_owned () -> Bool) -> ()
124+
%15 = struct_extract %4 : $Array<_HeapBuffer<C, Int>>, #Array._buffer // user: %16
125+
%16 = struct_extract %15 : $_ArrayBuffer<_HeapBuffer<C, Int>>, #_ArrayBuffer._storage // user: %17
126+
%17 = struct_extract %16 : $_BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCoreType>, #_BridgeStorage.rawValue // user: %18
127+
strong_release %17 : $Builtin.BridgeObject // id: %18
128+
%19 = tuple () // user: %20
129+
return %19 : $() // id: %20
130+
}
131+
132+
// Check that it does not crash the compiler.
133+
// Int is ObjC-bridgeable in this case, but its conformance is not know,
134+
// because Foundation is not imported yet.
135+
// Therefore the cast may succeed from the compiler point of view.
136+
// CHECK-LABEL: sil @cast_of_class_to_int
137+
// CHECK: unconditional_checked_cast_addr
138+
// CHECK: return
139+
sil @cast_of_class_to_int : $@convention(thin) (C) -> Int {
140+
bb0(%0 : $C):
141+
%1 = alloc_stack $Int
142+
%2 = alloc_stack $C
143+
store %0 to %2#1 : $*C
144+
unconditional_checked_cast_addr take_always C in %2#1 : $*C to Int in %1#1 : $*Int
145+
%4 = load %1#1 : $*Int
146+
dealloc_stack %2#0 : $*@local_storage C
147+
dealloc_stack %1#0 : $*@local_storage Int
148+
return %4 : $Int
149+
}
150+

0 commit comments

Comments
 (0)