@@ -234,12 +234,34 @@ private func getGlobalInitValue(address: Value, _ context: SimplifyContext) -> V
234234 }
235235 case let bai as BeginAccessInst :
236236 return getGlobalInitValue ( address: bai. address, context)
237+ case let rta as RefTailAddrInst :
238+ return getGlobalTailElement ( of: rta, index: 0 )
239+ case let ia as IndexAddrInst :
240+ if let rta = ia. base as? RefTailAddrInst ,
241+ let literal = ia. index as? IntegerLiteralInst ,
242+ let index = literal. value
243+ {
244+ return getGlobalTailElement ( of: rta, index: index)
245+ }
246+ case let rea as RefElementAddrInst :
247+ if let object = rea. instance. immutableGlobalObjectRoot {
248+ return object. baseOperands [ rea. fieldIndex] . value
249+ }
237250 default :
238251 break
239252 }
240253 return nil
241254}
242255
256+ private func getGlobalTailElement( of refTailAddr: RefTailAddrInst , index: Int ) -> Value ? {
257+ if let object = refTailAddr. instance. immutableGlobalObjectRoot,
258+ index >= 0 && index < object. tailOperands. count
259+ {
260+ return object. tailOperands [ index] . value
261+ }
262+ return nil
263+ }
264+
243265private func getInitializerFromInitFunction( of globalAddr: GlobalAddrInst , _ context: SimplifyContext ) -> Value ? {
244266 guard let dependentOn = globalAddr. dependencyToken,
245267 let builtinOnce = dependentOn as? BuiltinInst ,
@@ -321,6 +343,19 @@ private extension Value {
321343 }
322344 return ( baseAddress: self , offset: 0 )
323345 }
346+
347+ // If the reference-root of self references a global object, returns the `object` instruction of the
348+ // global's initializer. But only if the global is a let-global.
349+ var immutableGlobalObjectRoot : ObjectInst ? {
350+ if let gv = self . referenceRoot as? GlobalValueInst ,
351+ gv. global. isLet,
352+ let initval = gv. global. staticInitValue,
353+ let object = initval as? ObjectInst
354+ {
355+ return object
356+ }
357+ return nil
358+ }
324359}
325360
326361private extension Instruction {
0 commit comments