@@ -52,10 +52,9 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
5252 _ moduleContext: ModulePassContext ) {
5353 while let f = worklist. pop ( ) {
5454 moduleContext. transform ( function: f) { context in
55- if ! context. loadFunction ( function: f, loadCalleesRecursively: true ) {
56- return
55+ if context. loadFunction ( function: f, loadCalleesRecursively: true ) {
56+ optimize ( function : f , context , moduleContext , & worklist )
5757 }
58- optimize ( function: f, context, moduleContext, & worklist)
5958 }
6059
6160 // Generic specialization takes care of removing metatype arguments of generic functions.
@@ -316,8 +315,7 @@ private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlined
316315
317316private extension FullApplySite {
318317 func resultIsUsedInGlobalInitialization( ) -> SmallProjectionPath ? {
319- guard parentFunction. isGlobalInitOnceFunction,
320- let global = parentFunction. getInitializedGlobal ( ) else {
318+ guard let global = parentFunction. initializedGlobal else {
321319 return nil
322320 }
323321
@@ -441,25 +439,6 @@ private extension Value {
441439 }
442440}
443441
444- private extension Function {
445- /// Analyzes the global initializer function and returns global it initializes (from `alloc_global` instruction).
446- func getInitializedGlobal( ) -> GlobalVariable ? {
447- if !isDefinition {
448- return nil
449- }
450- for inst in self . entryBlock. instructions {
451- switch inst {
452- case let agi as AllocGlobalInst :
453- return agi. global
454- default :
455- break
456- }
457- }
458-
459- return nil
460- }
461- }
462-
463442fileprivate struct FunctionWorklist {
464443 private( set) var functions = Array < Function > ( )
465444 private var pushedFunctions = Set < Function > ( )
@@ -481,20 +460,10 @@ fileprivate struct FunctionWorklist {
481460 pushIfNotVisited ( f)
482461 }
483462
484- // Annotated global init-once functions
485- if f. isGlobalInitOnceFunction {
486- if let global = f. getInitializedGlobal ( ) ,
487- global. mustBeInitializedStatically {
488- pushIfNotVisited ( f)
489- }
490- }
491-
492- // @const global init-once functions
493- if f. isGlobalInitOnceFunction {
494- if let global = f. getInitializedGlobal ( ) ,
495- global. mustBeInitializedStatically {
496- pushIfNotVisited ( f)
497- }
463+ // Initializers of globals which must be initialized statically.
464+ if let global = f. initializedGlobal,
465+ global. mustBeInitializedStatically {
466+ pushIfNotVisited ( f)
498467 }
499468 }
500469 }
0 commit comments