Skip to content

Commit 210b39d

Browse files
authored
Merge pull request swiftlang#60646 from eeckstein/improve-accessutils
Swift AccessUtils: improvements and bug fixes
2 parents cf337a7 + 20a8f45 commit 210b39d

File tree

10 files changed

+559
-284
lines changed

10 files changed

+559
-284
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AccessDumper.swift

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,35 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SIL
1415

1516
/// Dumps access information for memory accesses (`load` and `store`)
1617
/// instructions.
18+
/// Also verifies that `AccessPath.isDistinct(from:)` is correct. This does not actually
19+
/// dumps anything, but aborts if the result is wrong.
1720
///
1821
/// This pass is used for testing `AccessUtils`.
1922
let accessDumper = FunctionPass(name: "dump-access", {
2023
(function: Function, context: PassContext) in
2124
print("Accesses for \(function.name)")
2225

23-
var apw = AccessPathWalker()
24-
var arw = AccessStoragePathVisitor()
2526
for block in function.blocks {
2627
for instr in block.instructions {
2728
switch instr {
2829
case let st as StoreInst:
29-
printAccessInfo(st.destinationOperand.value, &apw, &arw, context)
30+
printAccessInfo(address: st.destination)
3031
case let load as LoadInst:
31-
printAccessInfo(load.operand, &apw, &arw, context)
32+
printAccessInfo(address: load.operand)
33+
case let apply as ApplyInst:
34+
guard let callee = apply.referencedFunction else {
35+
break
36+
}
37+
if callee.name == "_isDistinct" {
38+
checkAliasInfo(forArgumentsOf: apply, expectDistinct: true)
39+
} else if callee.name == "_isNotDistinct" {
40+
checkAliasInfo(forArgumentsOf: apply, expectDistinct: false)
41+
}
3242
default:
3343
break
3444
}
@@ -46,10 +56,11 @@ private struct AccessStoragePathVisitor : AccessStoragePathWalker {
4656
}
4757
}
4858

49-
private func printAccessInfo(_ value: Value, _ apw: inout AccessPathWalker, _ aspw: inout AccessStoragePathVisitor,
50-
_ ctx: PassContext) {
51-
print("Value: \(value)")
52-
let (ap, scope) = apw.getAccessPathWithScope(of: value)
59+
private func printAccessInfo(address: Value) {
60+
print("Value: \(address)")
61+
62+
var apw = AccessPathWalker()
63+
let (ap, scope) = apw.getAccessPathWithScope(of: address)
5364
if let scope = scope {
5465
switch scope {
5566
case let .scope(ba):
@@ -63,6 +74,30 @@ private func printAccessInfo(_ value: Value, _ apw: inout AccessPathWalker, _ as
6374
print(" Base: \(ap.base)")
6475
print(" Path: \"\(ap.projectionPath)\"")
6576

66-
aspw.getAccessStorage(for: ap)
77+
var arw = AccessStoragePathVisitor()
78+
if !arw.visitAccessStorageRoots(of: ap) {
79+
print(" no Storage paths")
80+
}
81+
}
82+
}
83+
84+
private func checkAliasInfo(forArgumentsOf apply: ApplyInst, expectDistinct: Bool) {
85+
let address1 = apply.arguments[0]
86+
let address2 = apply.arguments[1]
87+
var apw = AccessPathWalker()
88+
guard let path1 = apw.getAccessPath(of: address1),
89+
let path2 = apw.getAccessPath(of: address2) else {
90+
return
91+
}
92+
if path1.isDistinct(from: path2) != expectDistinct {
93+
print("wrong isDistinct result of \(apply)")
94+
} else if path2.isDistinct(from: path1) != expectDistinct {
95+
print("wrong reverse isDistinct result of \(apply)")
96+
} else {
97+
return
6798
}
99+
100+
print("in function")
101+
print(apply.function)
102+
fatalError()
68103
}

0 commit comments

Comments
 (0)