10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import Basic
13
14
import SIL
14
15
15
16
/// Dumps access information for memory accesses (`load` and `store`)
16
17
/// instructions.
18
+ /// Also verifies that `AccessPath.isDistinct(from:)` is correct. This does not actually
19
+ /// dumps anything, but aborts if the result is wrong.
17
20
///
18
21
/// This pass is used for testing `AccessUtils`.
19
22
let accessDumper = FunctionPass ( name: " dump-access " , {
20
23
( function: Function , context: PassContext ) in
21
24
print ( " Accesses for \( function. name) " )
22
25
23
- var apw = AccessPathWalker ( )
24
- var arw = AccessStoragePathVisitor ( )
25
26
for block in function. blocks {
26
27
for instr in block. instructions {
27
28
switch instr {
28
29
case let st as StoreInst :
29
- printAccessInfo ( st. destinationOperand . value , & apw , & arw , context )
30
+ printAccessInfo ( address : st. destination )
30
31
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
+ }
32
42
default :
33
43
break
34
44
}
@@ -46,10 +56,11 @@ private struct AccessStoragePathVisitor : AccessStoragePathWalker {
46
56
}
47
57
}
48
58
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)
53
64
if let scope = scope {
54
65
switch scope {
55
66
case let . scope( ba) :
@@ -63,6 +74,30 @@ private func printAccessInfo(_ value: Value, _ apw: inout AccessPathWalker, _ as
63
74
print ( " Base: \( ap. base) " )
64
75
print ( " Path: \" \( ap. projectionPath) \" " )
65
76
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
67
98
}
99
+
100
+ print ( " in function " )
101
+ print ( apply. function)
102
+ fatalError ( )
68
103
}
0 commit comments