@@ -66,6 +66,8 @@ struct LifetimeDependence : CustomStringConvertible {
6666 /// A local variable scope without ownership. The scope must be introduced by either move_value or
6767 /// begin_borrow. LinearLiveness computes the scope boundary.
6868 case local( VariableScopeInstruction )
69+ /// A directly accessed global variable without exclusivity. Presumably immutable and therefore immortal.
70+ case global( GlobalAddrInst )
6971 /// Singly-initialized addressable storage (likely for an immutable address-only value). The lifetime extends until
7072 /// the memory is destroyed. e.g. A value produced by an @in FunctionArgument, an @out apply, or an @inout
7173 /// FunctionArgument that is never modified inside the callee. Modified @inout FunctionArguments have caller scoped
@@ -82,6 +84,7 @@ struct LifetimeDependence : CustomStringConvertible {
8284 case let . owned( value) : return value
8385 case let . borrowed( beginBorrow) : return beginBorrow. value
8486 case let . local( varScope) : return varScope. scopeBegin
87+ case let . global( ga) : return ga
8588 case let . initialized( initializer) : return initializer. initialAddress
8689 case let . unknown( value) : return value
8790 }
@@ -91,7 +94,7 @@ struct LifetimeDependence : CustomStringConvertible {
9194 switch self {
9295 case let . caller( argument) :
9396 precondition ( argument. ownership != . owned, " only guaranteed or inout arguments have a caller scope " )
94- case . access, . local, . unknown:
97+ case . access, . local, . global , . unknown:
9598 break
9699 case let . yield( value) :
97100 precondition ( value. definingInstruction is BeginApplyInst )
@@ -119,6 +122,7 @@ struct LifetimeDependence : CustomStringConvertible {
119122 case . owned: return " Owned: "
120123 case . borrowed: return " Borrowed: "
121124 case . local: return " Local: "
125+ case . global: return " Global: "
122126 case . initialized: return " Initialized: "
123127 case . unknown: return " Unknown: "
124128 }
@@ -254,8 +258,15 @@ extension LifetimeDependence.Scope {
254258 case let . box( projectBox) :
255259 // Note: the box may be in a borrow scope.
256260 self . init ( base: projectBox. operand. value, context)
257- case . stack, . global, . class, . tail, . pointer, . index, . unidentified:
258- self = . unknown( accessBase. address ?? address)
261+ case . stack, . class, . tail, . pointer, . index, . unidentified:
262+ self = . unknown( accessBase. address!)
263+ case . global:
264+ // TODO: When AccessBase stores global_addr, we don't need a check here and don't need to pass 'address' in.
265+ if let ga = address as? GlobalAddrInst {
266+ self = . global( ga)
267+ } else {
268+ self = . unknown( accessBase. address!)
269+ }
259270 case let . argument( arg) :
260271 if arg. convention. isIndirectIn {
261272 if arg. convention. isGuaranteed {
@@ -321,6 +332,8 @@ extension LifetimeDependence.Scope {
321332 self = . caller( arg)
322333 } else if let varScope = VariableScopeInstruction ( value. definingInstruction) {
323334 self = . local( varScope)
335+ } else if let ga = value as? GlobalAddrInst {
336+ self = . global( ga)
324337 } else {
325338 self = . unknown( value)
326339 }
@@ -365,7 +378,7 @@ extension LifetimeDependence.Scope {
365378 /// Note: The caller must deinitialize the returned range.
366379 func computeRange( _ context: Context ) -> InstructionRange ? {
367380 switch self {
368- case . caller:
381+ case . caller, . global :
369382 return nil
370383 case let . access( beginAccess) :
371384 var range = InstructionRange ( begin: beginAccess, context)
0 commit comments