forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeadargsignatureopt.sil
92 lines (79 loc) · 3.86 KB
/
deadargsignatureopt.sil
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -dead-arg-signature-opt %s | %FileCheck %s
import Builtin
import Swift
// Specialize to a function with removed dead argument.
// CHECK-LABEL: sil [thunk] [always_inline] @one_arg_dead
// CHECK: [[F:%[0-9]+]] = function_ref @_T012one_arg_deadTf4nnd_n
// CHECK: [[A:%[0-9]+]] = apply [[F]](%0, %1)
// CHECK: return [[A]]
sil @one_arg_dead : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool {
bb0(%0 : $Int32, %1 : $Int32, %2 : $@thin Int32.Type):
%5 = struct_extract %0 : $Int32, #Int32._value
%6 = struct_extract %1 : $Int32, #Int32._value
%7 = builtin "cmp_slt_Int32"(%5 : $Builtin.Int32, %6 : $Builtin.Int32) : $Builtin.Int1
%8 = struct $Bool (%7 : $Builtin.Int1)
return %8 : $Bool
}
// CHECK-LABEL: sil [thunk] [always_inline] @always_inline_one_arg_dead
// CHECK: [[F:%[0-9]+]] = function_ref @_T026always_inline_one_arg_deadTf4nnd_n
// CHECK: [[A:%[0-9]+]] = apply [[F]](%0, %1)
// CHECK: return [[A]]
sil [always_inline] @always_inline_one_arg_dead : $@convention(witness_method) (Int32, Int32, @thin Int32.Type) -> Bool {
bb0(%0 : $Int32, %1 : $Int32, %2 : $@thin Int32.Type):
%5 = struct_extract %0 : $Int32, #Int32._value
%6 = struct_extract %1 : $Int32, #Int32._value
%7 = builtin "cmp_slt_Int32"(%5 : $Builtin.Int32, %6 : $Builtin.Int32) : $Builtin.Int1
%8 = struct $Bool (%7 : $Builtin.Int1)
return %8 : $Bool
}
// Still delete only one dead arg as only one arg is partially applied.
// CHECK-LABEL: sil [thunk] [always_inline] @two_args_dead
// CHECK: [[F:%[0-9]+]] = function_ref @_T013two_args_deadTf4nnd_n
// CHECK: [[A:%[0-9]+]] = apply [[F]](%0, %1)
// CHECK: return [[A]]
sil @two_args_dead : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool {
bb0(%0 : $Int32, %1 : $Int32, %2 : $@thin Int32.Type):
%5 = struct_extract %0 : $Int32, #Int32._value
%7 = builtin "cmp_slt_Int32"(%5 : $Builtin.Int32, %5 : $Builtin.Int32) : $Builtin.Int1
%8 = struct $Bool (%7 : $Builtin.Int1)
return %8 : $Bool
}
// Don't specialize at this function is not partially applied.
// CHECK-LABEL: sil @not_used
// CHECK-NOT: apply
// CHECK: return
sil @not_used : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool {
bb0(%0 : $Int32, %1 : $Int32, %2 : $@thin Int32.Type):
%5 = struct_extract %0 : $Int32, #Int32._value
%6 = struct_extract %1 : $Int32, #Int32._value
%7 = builtin "cmp_slt_Int32"(%5 : $Builtin.Int32, %6 : $Builtin.Int32) : $Builtin.Int1
%8 = struct $Bool (%7 : $Builtin.Int1)
return %8 : $Bool
}
sil @partial_apply_one_arg_dead : $@convention(thin) () -> @owned @callee_owned (Int32, Int32) -> Bool {
bb0:
%0 = metatype $@thin Int32.Type
%1 = function_ref @one_arg_dead : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
%2 = partial_apply %1(%0) : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
return %2 : $@callee_owned (Int32, Int32) -> Bool
}
sil @partial_apply_always_inline_one_arg_dead : $@convention(thin) () -> @owned @callee_owned (Int32, Int32) -> Bool {
bb0:
%0 = metatype $@thin Int32.Type
%1 = function_ref @always_inline_one_arg_dead : $@convention(witness_method) (Int32, Int32, @thin Int32.Type) -> Bool
%2 = partial_apply %1(%0) : $@convention(witness_method) (Int32, Int32, @thin Int32.Type) -> Bool
return %2 : $@callee_owned (Int32, Int32) -> Bool
}
sil @partial_apply_two_args_dead : $@convention(thin) () -> @owned @callee_owned (Int32, Int32) -> Bool {
bb0:
%0 = metatype $@thin Int32.Type
%1 = function_ref @two_args_dead : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
%2 = partial_apply %1(%0) : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
return %2 : $@callee_owned (Int32, Int32) -> Bool
}
// CHECK-LABEL: sil @_T012one_arg_deadTf4nnd_n
// CHECK: builtin
// CHECK: return
// CHECK-LABEL: sil @_T013two_args_deadTf4nnd_n
// CHECK: builtin
// CHECK: return