Skip to content

Commit ebc16d9

Browse files
committed
EscapeInfoDumper: dump address-reachable-from-object information
1 parent 355d162 commit ebc16d9

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

SwiftCompilerSources/Sources/Optimizer/TestPasses/EscapeInfoDumper.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,24 @@ let addressEscapeInfoDumper = FunctionPass(name: "dump-addr-escape-info", {
130130
let projLhs = lhs.at(AliasAnalysis.getPtrOrAddressPath(for: lhs))
131131
let projRhs = rhs.at(AliasAnalysis.getPtrOrAddressPath(for: rhs))
132132
let mayAlias = projLhs.canAddressAlias(with: projRhs, context)
133-
assert(mayAlias == projRhs.canAddressAlias(with: projLhs, context),
134-
"canAddressAlias(with:) must be symmetric")
133+
if mayAlias != projRhs.canAddressAlias(with: projLhs, context) {
134+
fatalError("canAddressAlias(with:) must be symmetric")
135+
}
135136

137+
let addrReachable: Bool
138+
if lhs.type.isAddress && !rhs.type.isAddress {
139+
let anythingReachableFromRhs = rhs.at(SmallProjectionPath(.anything))
140+
addrReachable = projLhs.canAddressAlias(with: anythingReachableFromRhs, context)
141+
if mayAlias && !addrReachable {
142+
fatalError("mayAlias implies addrReachable")
143+
}
144+
} else {
145+
addrReachable = false
146+
}
136147
if mayAlias {
137148
print("may alias")
149+
} else if addrReachable {
150+
print("address reachable but no alias")
138151
} else {
139152
print("no alias")
140153
}

test/SILOptimizer/addr_escape_info.sil

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,44 @@ bb0:
133133
return %5 : $X
134134
}
135135

136+
sil @return_x : $@convention(thin) (@guaranteed X) -> @owned X
137+
138+
// CHECK-LABEL: Address escape information for test_class_argument:
139+
// CHECK: pair 0 - 1
140+
// CHECK-NEXT: %0 = alloc_ref $X
141+
// CHECK-NEXT: %3 = ref_element_addr %2 : $X, #X.s
142+
// CHECK-NEXT: may alias
143+
// CHECK: End function test_class_argument
144+
sil @test_class_argument : $@convention(thin) () -> () {
145+
bb0:
146+
%0 = alloc_ref $X
147+
%1 = function_ref @return_x : $@convention(thin) (@guaranteed X) -> @owned X
148+
%2 = apply %1(%0) : $@convention(thin) (@guaranteed X) -> @owned X
149+
%3 = ref_element_addr %2 : $X, #X.s
150+
fix_lifetime %0 : $X
151+
fix_lifetime %3 : $*Str
152+
%12 = tuple ()
153+
return %12 : $()
154+
}
155+
156+
// CHECK-LABEL: Address escape information for test_reachable_no_alias:
157+
// CHECK: pair 0 - 1
158+
// CHECK-NEXT: %3 = ref_element_addr %2 : $X, #X.s
159+
// CHECK-NEXT: %0 = alloc_ref $XandIntClass
160+
// CHECK-NEXT: address reachable but no alias
161+
// CHECK: End function test_reachable_no_alias
162+
sil @test_reachable_no_alias : $@convention(thin) () -> () {
163+
bb0:
164+
%0 = alloc_ref $XandIntClass
165+
%1 = ref_element_addr %0 : $XandIntClass, #XandIntClass.x
166+
%2 = load %1 : $*X
167+
%3 = ref_element_addr %2 : $X, #X.s
168+
fix_lifetime %3 : $*Str
169+
fix_lifetime %0 : $XandIntClass
170+
%12 = tuple ()
171+
return %12 : $()
172+
}
173+
136174
// CHECK-LABEL: Address escape information for test_struct_with_class:
137175
// CHECK: value: %1 = struct $Container (%0 : $X)
138176
// CHECK-NEXT: ==> %7 = apply %6(%1) : $@convention(thin) (@guaranteed Container) -> ()

0 commit comments

Comments
 (0)