forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem-behavior.sil
129 lines (109 loc) · 4.74 KB
/
mem-behavior.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// RUN: %target-sil-opt %s -aa=basic-aa -mem-behavior-dump -o /dev/null | FileCheck %s
// REQUIRES: asserts
import Builtin
import Swift
class X {
@sil_stored var a: Int32
@sil_stored var x: X
init()
}
sil @unknown_func : $@convention(thin) (Int32, @inout Int32) -> ()
sil @nouser_func : $@convention(thin) () -> ()
sil @store_to_int : $@convention(thin) (Int32, @inout Int32) -> () {
bb0(%0 : $Int32, %1 : $*Int32):
store %0 to %1 : $*Int32
%r = tuple ()
return %r : $()
}
sil @only_retain : $@convention(thin) (@guaranteed X) -> () {
bb0(%0 : $X):
strong_retain %0 : $X
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: @call_unknown_func
// CHECK: PAIR #1.
// CHECK-NEXT: (0): %4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %1 = argument of bb0 : $*Int32 // user: %4
// CHECK-NEXT: r=1,w=1,se=1
// CHECK: PAIR #2.
// CHECK-NEXT: (0): %4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %2 = argument of bb0 : $*Int32
// CHECK-NEXT: r=1,w=1,se=1
sil @call_unknown_func : $@convention(thin) (Int32, @inout Int32, @inout Int32) -> () {
bb0(%0 : $Int32, %1 : $*Int32, %2 : $*Int32):
%3 = function_ref @unknown_func : $@convention(thin) (Int32, @inout Int32) -> ()
%4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: @call_store_to_int_not_aliased
// CHECK: PAIR #1.
// CHECK-NEXT: (0): %4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %1 = argument of bb0 : $*Int32 // user: %4
// CHECK-NEXT: r=0,w=1,se=1
// CHECK: PAIR #2.
// CHECK-NEXT: (0): %4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %2 = argument of bb0 : $*Int32
// CHECK-NEXT: r=0,w=0,se=0
sil @call_store_to_int_not_aliased : $@convention(thin) (Int32, @inout Int32, @inout Int32) -> () {
bb0(%0 : $Int32, %1 : $*Int32, %2 : $*Int32):
%3 = function_ref @store_to_int : $@convention(thin) (Int32, @inout Int32) -> ()
%4 = apply %3(%0, %1) : $@convention(thin) (Int32, @inout Int32) -> ()
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: @call_store_to_int_aliased
// CHECK: PAIR #3.
// CHECK-NEXT: (0): %6 = apply %5(%0, %3) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %3 = ref_element_addr %1 : $X, #X.a // user: %6
// CHECK-NEXT: r=0,w=1,se=1
// CHECK: PAIR #4.
// CHECK-NEXT: (0): %6 = apply %5(%0, %3) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (0): %4 = ref_element_addr %2 : $X, #X.a
// CHECK-NEXT: r=0,w=1,se=1
sil @call_store_to_int_aliased : $@convention(thin) (Int32, @guaranteed X, @guaranteed X) -> () {
bb0(%0 : $Int32, %1 : $X, %2 : $X):
%3 = ref_element_addr %1 : $X, #X.a
%4 = ref_element_addr %2 : $X, #X.a
%5 = function_ref @store_to_int : $@convention(thin) (Int32, @inout Int32) -> ()
%6 = apply %5(%0, %3) : $@convention(thin) (Int32, @inout Int32) -> ()
%r = tuple ()
return %r : $()
}
sil @call_only_retain : $@convention(thin) (@guaranteed X, @guaranteed X) -> () {
bb0(%0 : $X, %1 : $X):
%2 = function_ref @only_retain : $@convention(thin) (@guaranteed X) -> ()
%3 = apply %2(%0) : $@convention(thin) (@guaranteed X) -> ()
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: @allocstack_apply_no_side_effect
// CHECK: PAIR #2
// CHECK-NEXT: (0): %3 = apply %2() : $@convention(thin) () -> ()
// CHECK-NEXT: (1): %1 = alloc_stack $Int32 // user: %5
// CHECK-NEXT: r=0,w=0,se=0
sil @allocstack_apply_no_side_effect : $@convention(thin) (Int32) -> () {
bb0(%0 : $Int32):
%1 = alloc_stack $Int32 // user: %5
%2 = function_ref @nouser_func : $@convention(thin) () -> () // user: %3
%3 = apply %2() : $@convention(thin) () -> ()
%4 = tuple () // user: %6
dealloc_stack %1#0 : $*@local_storage Int32 // id: %5
return %4 : $()
}
// CHECK-LABEL: @allocstack_apply_side_effect
// CHECK: PAIR #2.
// CHECK-NEXT: (0): %3 = apply %2(%0, %1#1) : $@convention(thin) (Int32, @inout Int32) -> ()
// CHECK-NEXT: (1): %1 = alloc_stack $Int32
// CHECK-NEXT: r=0,w=1,se=1
sil @allocstack_apply_side_effect : $@convention(thin) (Int32) -> () {
bb0(%0 : $Int32):
%1 = alloc_stack $Int32 // users: %3, %5
// function_ref store_to_int
%2 = function_ref @store_to_int : $@convention(thin) (Int32, @inout Int32) -> () // user: %3
%3 = apply %2(%0, %1#1) : $@convention(thin) (Int32, @inout Int32) -> ()
%4 = tuple () // user: %6
dealloc_stack %1#0 : $*@local_storage Int32 // id: %5
return %4 : $() // id: %6
}