@@ -52,10 +52,9 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
52
52
_ moduleContext: ModulePassContext ) {
53
53
while let f = worklist. pop ( ) {
54
54
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 )
57
57
}
58
- optimize ( function: f, context, moduleContext, & worklist)
59
58
}
60
59
61
60
// Generic specialization takes care of removing metatype arguments of generic functions.
@@ -316,8 +315,7 @@ private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlined
316
315
317
316
private extension FullApplySite {
318
317
func resultIsUsedInGlobalInitialization( ) -> SmallProjectionPath ? {
319
- guard parentFunction. isGlobalInitOnceFunction,
320
- let global = parentFunction. getInitializedGlobal ( ) else {
318
+ guard let global = parentFunction. initializedGlobal else {
321
319
return nil
322
320
}
323
321
@@ -441,25 +439,6 @@ private extension Value {
441
439
}
442
440
}
443
441
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
-
463
442
fileprivate struct FunctionWorklist {
464
443
private( set) var functions = Array < Function > ( )
465
444
private var pushedFunctions = Set < Function > ( )
@@ -481,20 +460,10 @@ fileprivate struct FunctionWorklist {
481
460
pushIfNotVisited ( f)
482
461
}
483
462
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)
498
467
}
499
468
}
500
469
}
0 commit comments