29
29
// ```
30
30
//===----------------------------------------------------------------------===//
31
31
32
- import SIL
33
-
34
32
/// AccessBase describes the base address of a memory access (e.g. of a `load` or `store``).
35
33
/// The "base address" is defined as the address which is obtained from the access address by
36
34
/// looking through all address projections.
@@ -48,7 +46,7 @@ import SIL
48
46
/// ```
49
47
///
50
48
/// The base address is never inside an access scope.
51
- enum AccessBase : CustomStringConvertible , Hashable {
49
+ public enum AccessBase : CustomStringConvertible , Hashable {
52
50
53
51
/// The address of a boxed variable, i.e. a field of an `alloc_box`.
54
52
case box( ProjectBoxInst )
@@ -78,7 +76,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
78
76
/// This should be a very rare situation.
79
77
case unidentified
80
78
81
- init ( baseAddress: Value ) {
79
+ public init ( baseAddress: Value ) {
82
80
switch baseAddress {
83
81
case let rea as RefElementAddrInst : self = . class( rea)
84
82
case let rta as RefTailAddrInst : self = . tail( rta)
@@ -97,7 +95,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
97
95
}
98
96
}
99
97
100
- var description : String {
98
+ public var description : String {
101
99
switch self {
102
100
case . unidentified: return " ? "
103
101
case . box( let pbi) : return " box - \( pbi) "
@@ -112,7 +110,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
112
110
}
113
111
114
112
/// True, if this is an access to a class instance.
115
- var isObjectAccess : Bool {
113
+ public var isObjectAccess : Bool {
116
114
switch self {
117
115
case . class, . tail:
118
116
return true
@@ -122,7 +120,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
122
120
}
123
121
124
122
/// The reference value if this is an access to a referenced objecct (class, box, tail).
125
- var reference : Value ? {
123
+ public var reference : Value ? {
126
124
switch self {
127
125
case . box( let pbi) : return pbi. box
128
126
case . class( let rea) : return rea. instance
@@ -141,7 +139,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
141
139
///
142
140
/// This is not true for scoped storage such as alloc_stack and @in arguments.
143
141
///
144
- var hasLocalOwnershipLifetime : Bool {
142
+ public var hasLocalOwnershipLifetime : Bool {
145
143
if let reference = reference {
146
144
// Conservatively assume that everything which is a ref-counted object is within an ownership scope.
147
145
// TODO: we could e.g. exclude guaranteed function arguments.
@@ -151,7 +149,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
151
149
}
152
150
153
151
/// True, if the baseAddress is of an immutable property or global variable
154
- var isLet : Bool {
152
+ public var isLet : Bool {
155
153
switch self {
156
154
case . class( let rea) : return rea. fieldIsLet
157
155
case . global( let g) : return g. isLet
@@ -161,7 +159,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
161
159
}
162
160
163
161
/// True, if the address is immediately produced by an allocation in its function.
164
- var isLocal : Bool {
162
+ public var isLocal : Bool {
165
163
switch self {
166
164
case . box( let pbi) : return pbi. box is AllocBoxInst
167
165
case . class( let rea) : return rea. instance is AllocRefInstBase
@@ -173,7 +171,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
173
171
}
174
172
175
173
/// True, if the kind of storage of the access is known (e.g. a class property, or global variable).
176
- var hasKnownStorageKind : Bool {
174
+ public var hasKnownStorageKind : Bool {
177
175
switch self {
178
176
case . box, . class, . tail, . stack, . global:
179
177
return true
@@ -187,7 +185,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
187
185
/// `isEqual` abstracts away the projection instructions that are included as part of the AccessBase:
188
186
/// multiple `project_box` and `ref_element_addr` instructions are equivalent bases as long as they
189
187
/// refer to the same variable or class property.
190
- func isEqual( to other: AccessBase ) -> Bool {
188
+ public func isEqual( to other: AccessBase ) -> Bool {
191
189
switch ( self , other) {
192
190
case ( . box( let pb1) , . box( let pb2) ) :
193
191
return pb1. box. referenceRoot == pb2. box. referenceRoot
@@ -213,8 +211,8 @@ enum AccessBase : CustomStringConvertible, Hashable {
213
211
}
214
212
215
213
/// Returns `true` if the two access bases do not alias.
216
- func isDistinct( from other: AccessBase ) -> Bool {
217
-
214
+ public func isDistinct( from other: AccessBase ) -> Bool {
215
+
218
216
func isDifferentAllocation( _ lhs: Value , _ rhs: Value ) -> Bool {
219
217
switch ( lhs, rhs) {
220
218
case ( is Allocation , is Allocation ) :
@@ -273,21 +271,21 @@ enum AccessBase : CustomStringConvertible, Hashable {
273
271
274
272
/// An `AccessPath` is a pair of a `base: AccessBase` and a `projectionPath: Path`
275
273
/// which denotes the offset of the access from the base in terms of projections.
276
- struct AccessPath : CustomStringConvertible {
277
- let base : AccessBase
274
+ public struct AccessPath : CustomStringConvertible {
275
+ public let base : AccessBase
278
276
279
277
/// address projections only
280
- let projectionPath : SmallProjectionPath
278
+ public let projectionPath : SmallProjectionPath
281
279
282
- static func unidentified( ) -> AccessPath {
280
+ public static func unidentified( ) -> AccessPath {
283
281
return AccessPath ( base: . unidentified, projectionPath: SmallProjectionPath ( ) )
284
282
}
285
283
286
- var description : String {
284
+ public var description : String {
287
285
" \( projectionPath) : \( base) "
288
286
}
289
287
290
- func isDistinct( from other: AccessPath ) -> Bool {
288
+ public func isDistinct( from other: AccessPath ) -> Bool {
291
289
if base. isDistinct ( from: other. base) {
292
290
// We can already derived from the bases that there is no alias.
293
291
// No need to look at the projection paths.
@@ -308,11 +306,11 @@ struct AccessPath : CustomStringConvertible {
308
306
/// Note that this access _contains_ `other` if `other` has a _larger_ projection path than this acccess.
309
307
/// For example:
310
308
/// `%value.s0` contains `%value.s0.s1`
311
- func isEqualOrContains( _ other: AccessPath ) -> Bool {
309
+ public func isEqualOrContains( _ other: AccessPath ) -> Bool {
312
310
return getProjection ( to: other) != nil
313
311
}
314
312
315
- var materializableProjectionPath : SmallProjectionPath ? {
313
+ public var materializableProjectionPath : SmallProjectionPath ? {
316
314
if projectionPath. isMaterializable {
317
315
return projectionPath
318
316
}
@@ -325,7 +323,7 @@ struct AccessPath : CustomStringConvertible {
325
323
/// `%value.s0`.getProjection(to: `%value.s0.s1`)
326
324
/// yields
327
325
/// `s1`
328
- func getProjection( to other: AccessPath ) -> SmallProjectionPath ? {
326
+ public func getProjection( to other: AccessPath ) -> SmallProjectionPath ? {
329
327
if !base. isEqual ( to: other. base) {
330
328
return nil
331
329
}
@@ -339,7 +337,7 @@ struct AccessPath : CustomStringConvertible {
339
337
}
340
338
341
339
/// Like `getProjection`, but also requires that the resulting projection path is materializable.
342
- func getMaterializableProjection( to other: AccessPath ) -> SmallProjectionPath ? {
340
+ public func getMaterializableProjection( to other: AccessPath ) -> SmallProjectionPath ? {
343
341
if let projectionPath = getProjection ( to: other) ,
344
342
projectionPath. isMaterializable {
345
343
return projectionPath
@@ -364,7 +362,7 @@ private func canBeOperandOfIndexAddr(_ value: Value) -> Bool {
364
362
/// %ptr = address_to_pointer %orig_addr
365
363
/// %addr = pointer_to_address %ptr
366
364
/// ```
367
- extension PointerToAddressInst {
365
+ private extension PointerToAddressInst {
368
366
var originatingAddress : Value ? {
369
367
370
368
struct Walker : ValueUseDefWalker {
@@ -426,7 +424,7 @@ extension PointerToAddressInst {
426
424
/// %l3 = load %a3 : $*Int64
427
425
/// end_access %a3 : $*Int64
428
426
/// ```
429
- enum EnclosingScope {
427
+ public enum EnclosingScope {
430
428
case scope( BeginAccessInst )
431
429
case base( AccessBase )
432
430
}
@@ -512,30 +510,30 @@ extension Value {
512
510
// go through phi-arguments, the AccessPathWalker will allocate memnory in its cache.
513
511
514
512
/// Computes the access base of this address value.
515
- var accessBase : AccessBase { accessPath. base }
513
+ public var accessBase : AccessBase { accessPath. base }
516
514
517
515
/// Computes the access path of this address value.
518
- var accessPath : AccessPath {
516
+ public var accessPath : AccessPath {
519
517
var walker = AccessPathWalker ( )
520
518
walker. walk ( startAt: self )
521
519
return walker. result
522
520
}
523
521
524
- func getAccessPath( fromInitialPath: SmallProjectionPath ) -> AccessPath {
522
+ public func getAccessPath( fromInitialPath: SmallProjectionPath ) -> AccessPath {
525
523
var walker = AccessPathWalker ( )
526
524
walker. walk ( startAt: self , initialPath: fromInitialPath)
527
525
return walker. result
528
526
}
529
527
530
528
/// Computes the access path of this address value and also returns the scope.
531
- var accessPathWithScope : ( AccessPath , scope: BeginAccessInst ? ) {
529
+ public var accessPathWithScope : ( AccessPath , scope: BeginAccessInst ? ) {
532
530
var walker = AccessPathWalker ( )
533
531
walker. walk ( startAt: self )
534
532
return ( walker. result, walker. foundBeginAccess)
535
533
}
536
534
537
535
/// Computes the enclosing access scope of this address value.
538
- var enclosingAccessScope : EnclosingScope {
536
+ public var enclosingAccessScope : EnclosingScope {
539
537
var walker = AccessPathWalker ( )
540
538
walker. walk ( startAt: self )
541
539
if let ba = walker. foundBeginAccess {
@@ -545,7 +543,7 @@ extension Value {
545
543
}
546
544
547
545
/// The root definition of a reference, obtained by skipping casts, etc.
548
- var referenceRoot : Value {
546
+ public var referenceRoot : Value {
549
547
var value : Value = self
550
548
while true {
551
549
switch value {
@@ -583,7 +581,7 @@ extension ValueUseDefWalker where Path == SmallProjectionPath {
583
581
/// the `visit` function for all storage roots with a the corresponding path.
584
582
/// Returns true on success.
585
583
/// Returns false if not all storage roots could be identified or if `accessPath` has not a "reference" base.
586
- mutating func visitAccessStorageRoots( of accessPath: AccessPath ) -> Bool {
584
+ public mutating func visitAccessStorageRoots( of accessPath: AccessPath ) -> Bool {
587
585
walkUpCache. clear ( )
588
586
let path = accessPath. projectionPath
589
587
switch accessPath. base {
0 commit comments