Skip to content

Commit 1e6511e

Browse files
committed
Pass Pipeline: replace the old GlobalOpt with the new InitializeStaticGlobals and ReadOnlyGlobalVariablesPass passes.
1 parent 960ca70 commit 1e6511e

19 files changed

+45
-33
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
231231
P.addDiagnoseLifetimeIssues();
232232
}
233233

234-
P.addGlobalOpt();
234+
P.addOnoneSimplification();
235+
P.addInitializeStaticGlobals();
236+
235237
P.addPerformanceDiagnostics();
236238

237239
// Canonical swift requires all non cond_br critical edges to be split.
@@ -627,10 +629,6 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
627629
// is linked in from the stdlib.
628630
P.addTempRValueOpt();
629631

630-
// Needed to serialize static initializers of globals for cross-module
631-
// optimization.
632-
P.addGlobalOpt();
633-
634632
// Add the outliner pass (Osize).
635633
P.addOutliner();
636634
}
@@ -674,7 +672,6 @@ static void addHighLevelModulePipeline(SILPassPipelinePlan &P) {
674672
P.addComputeSideEffects();
675673
P.addStackPromotion();
676674

677-
P.addGlobalOpt();
678675
P.addLetPropertiesOpt();
679676
}
680677

@@ -699,25 +696,26 @@ static void addMidLevelFunctionPipeline(SILPassPipelinePlan &P) {
699696
static void addClosureSpecializePassPipeline(SILPassPipelinePlan &P) {
700697
P.startPipeline("ClosureSpecialize");
701698
P.addDeadFunctionAndGlobalElimination();
699+
P.addReadOnlyGlobalVariablesPass();
702700
P.addTargetConstantFolding();
703701
P.addDeadStoreElimination();
704702
P.addDeadObjectElimination();
705703

706-
// These few passes are needed to cleanup between loop unrolling and GlobalOpt.
704+
// These few passes are needed to cleanup between loop unrolling and InitializeStaticGlobals.
707705
// This is needed to fully optimize static small String constants.
708706
P.addSimplifyCFG();
709707
P.addSILCombine();
710708
P.addPerformanceConstantPropagation();
711709
P.addSimplifyCFG();
712-
710+
P.addSimplification();
711+
712+
P.addInitializeStaticGlobals();
713+
713714
// ComputeEffects should be done at the end of a function-pipeline. The next
714-
// pass (GlobalOpt) is a module pass, so this is the end of a function-pipeline.
715+
// pass (LetPropertiesOpt) is a module pass, so this is the end of a function-pipeline.
715716
P.addComputeEscapeEffects();
716717
P.addComputeSideEffects();
717718

718-
// Hoist globals out of loops.
719-
// Global-init functions should not be inlined GlobalOpt is done.
720-
P.addGlobalOpt();
721719
P.addLetPropertiesOpt();
722720

723721
// Propagate constants into closures and convert to static dispatch. This
@@ -984,7 +982,6 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
984982
// in the editor.
985983
P.startPipeline("Non-Diagnostic Mandatory Optimizations");
986984
P.addForEachLoopUnroll();
987-
P.addOnoneSimplification();
988985

989986
// TODO: MandatoryARCOpts should be subsumed by CopyPropagation. There should
990987
// be no need to run another analysis of copies at -Onone.

test/IRGen/globals.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
22

3-
// REQUIRES: CPU=x86_64
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: PTRSIZE=64
45

56
var g0 : Int = 1
67
var g1 : (Void, Int, Void)

test/SILGen/fragile_globals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -parse-as-library -o %t %S/Inputs/ModuleA.swift
33
// RUN: %target-swift-frontend -emit-module -parse-as-library -o %t %S/Inputs/ModuleB.swift
4-
// RUN: %target-swift-emit-sil -parse-as-library -I%t %s -Xllvm -sil-disable-pass=GlobalOpt -O | %FileCheck %s
4+
// RUN: %target-swift-emit-sil -parse-as-library -I%t %s -Xllvm -sil-disable-pass=initialize-static-globals -O | %FileCheck %s
55

66
import ModuleA
77
import ModuleB

test/SILGen/global_resilience.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// RUN: %target-swift-emit-silgen -I %t -enable-library-evolution -parse-as-library %s | %FileCheck %s
44
// RUN: %target-swift-emit-sil -I %t -O -enable-library-evolution -parse-as-library %s | %FileCheck --check-prefix=CHECK-OPT %s
55

6+
// REQUIRES: swift_in_compiler
7+
68
import resilient_global
79

810
public struct MyEmptyStruct {}

test/SILOptimizer/cross-module-optimization.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// RUN: %target-run %t/a.out | %FileCheck %s -check-prefix=CHECK-OUTPUT
1919

2020
// REQUIRES: executable_test
21+
// REQUIRES: swift_in_compiler
2122

2223
// Second test: check if CMO really imports the SIL of functions in other modules.
2324

test/SILOptimizer/dead_function_elimination.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ public func keepPtrAlive() {
198198
// CHECK-TESTING: sil {{.*}}publicClassMethod
199199
// CHECK-TESTING: sil {{.*}}DeadWitness
200200

201-
// CHECK-LABEL: sil_global {{.*}}@$s25dead_function_elimination5GFStrV12aliveFuncPtryycvpZ
202201
// CHECK-LABEL: @$s25dead_function_elimination14donotEliminateyyF
203202
// CHECK-LABEL: sil @$s25dead_function_elimination12keepPtrAliveyyF
204203

test/SILOptimizer/default-cmo.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@
77

88
// RUN: %target-build-swift -O -wmo -module-name=Main -I%t -I%S/Inputs/cross-module %s -emit-sil | %FileCheck %s
99

10+
// REQUIRES: swift_in_compiler
1011

1112
import Module
1213
import ModuleTBD
1314

14-
// CHECK-LABEL: sil_global public_external [serialized] @$s6Module0A6StructV21publicFunctionPointeryS2icvpZ : $@callee_guaranteed (Int) -> Int = {
15-
// CHECK: %0 = function_ref @$s6Module16incrementByThreeyS2iF
16-
17-
// CHECK-LABEL: sil_global public_external @$s6Module0A6StructV22privateFunctionPointeryS2icvpZ : $@callee_guaranteed (Int) -> Int{{$}}
15+
// CHECK-LABEL: sil_global public_external [let] @$s6Module0A6StructV22privateFunctionPointeryS2icvpZ : $@callee_guaranteed (Int) -> Int{{$}}
1816

1917
public func callPublicFunctionPointer(_ x: Int) -> Int {
2018
return Module.ModuleStruct.publicFunctionPointer(x)
2119
}
2220

21+
// CHECK-LABEL: sil @$s4Main25callPublicFunctionPointeryS2iF :
22+
// CHECK-NOT: global_addr
23+
// CHECK-NOT: apply
24+
// CHECK: builtin "sadd
25+
// CHECK-NOT: global_addr
26+
// CHECK-NOT: apply
27+
// CHECK: } // end sil function '$s4Main25callPublicFunctionPointeryS2iF'
2328
public func callPrivateFunctionPointer(_ x: Int) -> Int {
2429
return Module.ModuleStruct.privateFunctionPointer(x)
2530
}

test/SILOptimizer/global-c-functionptr.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// RUN: %target-build-swift -O -module-name=Test %s -emit-sil | %FileCheck %s -check-prefix=CHECK-SIL
1313

1414
// REQUIRES: executable_test
15+
// REQUIRES: swift_in_compiler
1516

1617

1718
internal func cFn(_ i: Int) -> Int {

test/SILOptimizer/global_init_with_empty.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: %target-codesign %t/a.out
77
// RUN: %target-run %t/a.out | %FileCheck %s -check-prefix=CHECK-OUTPUT
88
// REQUIRES: executable_test,optimized_stdlib
9+
// REQUIRES: swift_in_compiler
910

1011
struct Empty { }
1112

test/SILOptimizer/globalopt_global_propagation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
2-
// RUN: %target-swift-frontend -O -wmo -emit-sil %s | %FileCheck -check-prefix=CHECK-WMO %s
31
// RUN: %target-swift-frontend -parse-as-library -O -emit-sil %s | %FileCheck %s
42
// RUN: %target-swift-frontend -parse-as-library -O -wmo -emit-sil %s | %FileCheck -check-prefix=CHECK-WMO %s
53

4+
// REQUIRES: swift_in_compiler
5+
66
// Check that values of internal and private global variables, which are provably assigned only
77
// once, are propagated into their uses and enable further optimizations like constant
88
// propagation, simplifications, etc.

0 commit comments

Comments
 (0)