Skip to content

Commit 2a2c009

Browse files
committed
Swift AccessUtils: add convenient properties to get the AccessBase and AccessScope of a Value
1 parent 6072683 commit 2a2c009

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AccessUtils.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,27 @@ struct AccessPathWalker {
476476
}
477477
}
478478

479+
extension Value {
480+
// Convenient properties to avoid instantiating an explicit AccessPathWalker.
481+
//
482+
// Although an AccessPathWalker is created for each call of these properties,
483+
// it's very unlikely that this will end up in memory allocations.
484+
// Only in the rare case of `pointer_to_address` -> `address_to_pointer` pairs, which
485+
// go through phi-arguments, the AccessPathWalker will allocate memnory in its cache.
486+
487+
/// Computes the access base of this address value.
488+
var accessBase: AccessBase {
489+
var apWalker = AccessPathWalker()
490+
return apWalker.getAccessBase(of: self)
491+
}
492+
493+
/// Computes the enclosing access scope of this address value.
494+
var accessScope: EnclosingScope {
495+
var apWalker = AccessPathWalker()
496+
return apWalker.getAccessScope(of: self)
497+
}
498+
}
499+
479500
/// A ValueUseDef walker that identifies which values a reference of an access path might
480501
/// originate from.
481502
protocol AccessStoragePathWalker : ValueUseDefWalker where Path == SmallProjectionPath {

0 commit comments

Comments
 (0)