Skip to content

Commit e45b82f

Browse files
committed
AccessUtils: add AccessBase.hasLocalOwnershipLifetime
1 parent 7ca5998 commit e45b82f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/AccessUtils.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ enum AccessBase : CustomStringConvertible, Hashable {
131131
return nil
132132
}
133133
}
134+
135+
/// True if this access base may be derived from a reference that is only valid within a locally
136+
/// scoped OSSA lifetime. For example:
137+
///
138+
/// %reference = begin_borrow %1
139+
/// %base = ref_tail_addr %reference <- %base must not be used outside the borrow scope
140+
/// end_borrow %reference
141+
///
142+
/// This is not true for scoped storage such as alloc_stack and @in arguments.
143+
///
144+
var hasLocalOwnershipLifetime: Bool {
145+
if let reference = reference {
146+
// Conservatively assume that everything which is a ref-counted object is within an ownership scope.
147+
// TODO: we could e.g. exclude guaranteed function arguments.
148+
return reference.ownership != .none
149+
}
150+
return false
151+
}
152+
134153
/// True, if the baseAddress is of an immutable property or global variable
135154
var isLet: Bool {
136155
switch self {

0 commit comments

Comments
 (0)