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.

test/SILOptimizer/globalopt_let_propagation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s | %FileCheck %s
21
// RUN: %target-swift-frontend -parse-as-library -O -emit-sil -primary-file %s | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-LIB %s
32

3+
// REQUIRES: swift_in_compiler
4+
45
// Check that values of static let and global let variables are propagated into their uses
56
// and enable further optimizations like constant propagation, simplifications, etc.
67

test/SILOptimizer/globalopt_resilience.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -O -module-name=test -enable-library-evolution -emit-sil -primary-file %s | %FileCheck %s
22

3+
// REQUIRES: swift_in_compiler
4+
35
// Check if GlobalOpt generates the optimal getter for a static property with a resilient type.
46
// The (resilient) getter should just return the literal (and not lazily initialize a global variable).
57

test/SILOptimizer/globalopt_resilience_testing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %target-swift-frontend -emit-sil -O -enable-library-evolution -primary-file %s | %FileCheck %s
22
// RUN: %target-swift-frontend -emit-sil -O -enable-library-evolution -enable-testing -primary-file %s | %FileCheck %s --check-prefix=CHECK-TESTING
33

4+
// REQUIRES: swift_in_compiler
5+
46
// If a global variable with a resilient type has public linkage, we have to
57
// allocate a buffer for it even if the type has a fixed size in its
68
// defining module.

test/SILOptimizer/optimizer_counters.sil

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ sil @fatalError : $@convention(thin) () -> Never
1919

2020
// Check that module level statistics are produced.
2121
//
22-
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, PerformanceConstantPropagation, {{.*}}, 14, 11
23-
// CHECK-SIL-STATS-MODULES: module, block, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 5, 3
24-
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 11, 6
22+
// CHECK-SIL-STATS-MODULES: module, block, PrepareOptimizationPasses, Simplification, {{.*}}, 6, 3
23+
// CHECK-SIL-STATS-MODULES: module, inst, PrepareOptimizationPasses, Simplification, {{.*}}, 15, 6
2524

2625
// Check that module level statistics are produced.
2726
//

test/SILOptimizer/performance-annotations.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-swift-frontend -experimental-performance-annotations -emit-sil %s -o /dev/null -verify
22
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
3+
// REQUIRES: swift_in_compiler
34

45
protocol P {
56
func protoMethod(_ a: Int) -> Int

test/SILOptimizer/remove_unused_global_vars.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -primary-file %s -O -module-name=test -emit-sil | %FileCheck %s
1+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -module-name=test -emit-sil | %FileCheck %s
22

33
import SwiftShims
44

@@ -16,8 +16,8 @@ struct Foo {
1616
private let unused1 = 0
1717
// CHECK-NOT: sil_global private {{.*}}unused2{{.*}}
1818
private var unused2 = 42
19-
// CHECK: sil_global private [let] @${{.*}}used1{{.*}} : $Int
20-
private let used1 = 0
19+
// CHECK: sil_global private @${{.*}}used1{{.*}} : $Int
20+
private var used1 = 0
2121
// CHECK: sil_global private @${{.*}}used2{{.*}} : $Int
2222
private var used2 = 0
2323

@@ -48,8 +48,6 @@ var unused6 = 0
4848

4949
// CHECK-LABEL: sil [Onone] @${{.*}}test{{.*}}
5050
@_optimize(none) public func test(x: Int) -> Int {
51-
// CHECK: %{{[0-9]+}} = global_addr @${{.*}}used2{{.*}}
52-
// CHECK: %{{[0-9]+}} = global_addr @${{.*}}used1{{.*}}
5351
return used1 + used2 + x
5452
}
5553

test/SILOptimizer/target-const-prop.swift

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

88
// REQUIRES: executable_test,swift_stdlib_no_asserts,optimized_stdlib
9+
// REQUIRES: swift_in_compiler
910

1011

1112
struct S {

test/SILOptimizer/zeroInitializer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -O -parse-stdlib -emit-ir -module-name ZeroInit -verify %s | %FileCheck %s
22

3+
// REQUIRES: swift_in_compiler
4+
35
import Swift
46

57
@frozen

test/sil-passpipeline-dump/basic.test-sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
// CHECK: ---
99
// CHECK: name: Non-Diagnostic Mandatory Optimizations
10-
// CHECK: passes: [ "for-each-loop-unroll", "onone-simplification", "mandatory-arc-opts",
11-
// CHECK: "onone-prespecializer" ]
10+
// CHECK: passes: [ "for-each-loop-unroll", "mandatory-arc-opts", "onone-prespecializer" ]
1211
// CHECK: ---
1312
// CHECK: name: Serialization
1413
// CHECK: passes: [ "serialize-sil", "sil-moved-async-var-dbginfo-propagator",

0 commit comments

Comments
 (0)