forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixed_size_buffer_peepholes.sil
83 lines (71 loc) · 3.78 KB
/
fixed_size_buffer_peepholes.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
// RUN: %target-swift-frontend -emit-ir %s | FileCheck %s
import Builtin
sil @consume : $@convention(thin) <T> (@in T) -> ()
sil @produce : $@convention(thin) <T> (@out T) -> ()
// CHECK-LABEL: define void @join_alloc_stack_copy_addr
sil @join_alloc_stack_copy_addr : $@convention(thin) <T> (@in T) -> () {
entry(%x : $*T):
// CHECK: [[BUFFER:%.*]] = alloca [[BUFFER_TYPE:\[.* x i8\]]]
%a = alloc_stack $T
// CHECK: [[ADDR:%.*]] = call %swift.opaque* %initializeBufferWithCopy([[BUFFER_TYPE]]* [[BUFFER]], %swift.opaque* %0, %swift.type* %T)
copy_addr %x to [initialization] %a#1 : $*T
// CHECK: call void @consume(%swift.opaque* noalias nocapture [[ADDR]], %swift.type* %T)
%u = function_ref @consume : $@convention(thin) <T> (@in T) -> ()
%z = apply %u<T>(%a#1) : $@convention(thin) <T> (@in T) -> ()
dealloc_stack %a#0 : $*@local_storage T
return undef : $()
}
protocol P {}
// CHECK-LABEL: define void @join_init_existential_copy_addr(%P27fixed_size_buffer_peepholes1P_* noalias nocapture sret, %swift.opaque* noalias nocapture, %swift.type* %T, i8** %T.P)
// CHECK: [[BUFFER:%.*]] = getelementptr inbounds %P27fixed_size_buffer_peepholes1P_, %P27fixed_size_buffer_peepholes1P_* %0, i32 0, i32 0
// CHECK: call %swift.opaque* %initializeBufferWithTake([[BUFFER_TYPE]]* [[BUFFER]], %swift.opaque* %1
sil @join_init_existential_copy_addr : $@convention(thin) <T: P> (@out P, @in T) -> () {
entry(%p : $*P, %x: $*T):
%y = init_existential_addr %p : $*P, $T
copy_addr [take] %x to [initialization] %y : $*T
return undef : $()
}
// CHECK-LABEL: define void @dont_join_alloc_stack_copy_addr_if_intervening_use
sil @dont_join_alloc_stack_copy_addr_if_intervening_use : $@convention(thin) <T> (@in T) -> () {
entry(%x : $*T):
// CHECK: [[BUFFER:%.*]] = alloca [[BUFFER_TYPE:\[.* x i8\]]]
// CHECK: [[ADDR:%.*]] = call %swift.opaque* %allocateBuffer([[BUFFER_TYPE]]* [[BUFFER]], %swift.type* %T)
%a = alloc_stack $T
%p = function_ref @produce : $@convention(thin) <T> (@out T) -> ()
%y = apply %p<T>(%a#1) : $@convention(thin) <T> (@out T) -> ()
destroy_addr %a#1 : $*T
// CHECK: call %swift.opaque* %initializeWithCopy(%swift.opaque* [[ADDR]],
copy_addr %x to [initialization] %a#1 : $*T
%u = function_ref @consume : $@convention(thin) <T> (@in T) -> ()
%z = apply %u<T>(%a#1) : $@convention(thin) <T> (@in T) -> ()
dealloc_stack %a#0 : $*@local_storage T
return undef : $()
}
// CHECK-LABEL: define void @dont_join_alloc_stack_copy_addr_if_no_copy_addr
sil @dont_join_alloc_stack_copy_addr_if_no_copy_addr : $@convention(thin) <T> (@in T) -> () {
entry(%x : $*T):
// CHECK: [[BUFFER:%.*]] = alloca [[BUFFER_TYPE:\[.* x i8\]]]
// CHECK: [[ADDR:%.*]] = call %swift.opaque* %allocateBuffer([[BUFFER_TYPE]]* [[BUFFER]], %swift.type* %T)
%a = alloc_stack $T
%p = function_ref @produce : $@convention(thin) <T> (@out T) -> ()
%y = apply %p<T>(%a#1) : $@convention(thin) <T> (@out T) -> ()
destroy_addr %a#1 : $*T
dealloc_stack %a#0 : $*@local_storage T
return undef : $()
}
// CHECK-LABEL: define void @dont_join_alloc_stack_if_copy_addr_in_different_bb
sil @dont_join_alloc_stack_if_copy_addr_in_different_bb : $@convention(thin) <T> (@in T) -> () {
entry(%x : $*T):
// CHECK: [[BUFFER:%.*]] = alloca [[BUFFER_TYPE:\[.* x i8\]]]
// CHECK: [[ADDR:%.*]] = call %swift.opaque* %allocateBuffer([[BUFFER_TYPE]]* [[BUFFER]], %swift.type* %T)
%a = alloc_stack $T
br next
next:
// CHECK: call %swift.opaque* %initializeWithCopy(%swift.opaque* [[ADDR]],
copy_addr %x to [initialization] %a#1 : $*T
// CHECK: call void @consume(%swift.opaque* noalias nocapture [[ADDR]], %swift.type* %T)
%u = function_ref @consume : $@convention(thin) <T> (@in T) -> ()
%z = apply %u<T>(%a#1) : $@convention(thin) <T> (@in T) -> ()
dealloc_stack %a#0 : $*@local_storage T
return undef : $()
}