Skip to content

Commit 7386444

Browse files
authored
Merge pull request #39776 from meg-gupta/moveb4mem2reg
Move non-transparent OME to just before Mem2Reg
2 parents 97559e1 + a52b896 commit 7386444

File tree

4 files changed

+23
-38
lines changed

4 files changed

+23
-38
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ void addFunctionPasses(SILPassPipelinePlan &P,
362362
P.addSROA();
363363
}
364364

365+
if (!P.getOptions().EnableOSSAModules && !SILDisableLateOMEByDefault) {
366+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
367+
return;
368+
369+
if (SILPrintFinalOSSAModule) {
370+
addModulePrinterPipeline(P, "SIL Print Final OSSA Module");
371+
}
372+
P.addNonTransparentFunctionOwnershipModelEliminator();
373+
}
374+
365375
// Promote stack allocations to values.
366376
P.addMem2Reg();
367377

@@ -571,16 +581,6 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
571581
// optimization.
572582
P.addGlobalOpt();
573583

574-
if (!P.getOptions().EnableOSSAModules && !SILDisableLateOMEByDefault) {
575-
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
576-
return;
577-
578-
if (SILPrintFinalOSSAModule) {
579-
addModulePrinterPipeline(P, "SIL Print Final OSSA Module");
580-
}
581-
P.addNonTransparentFunctionOwnershipModelEliminator();
582-
}
583-
584584
// Add the outliner pass (Osize).
585585
P.addOutliner();
586586
}
@@ -826,17 +826,17 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
826826
// This also performs early OSSA based optimizations on *all* swift code.
827827
addPerfEarlyModulePassPipeline(P);
828828

829-
// Then if we were asked to stop optimization before lowering OSSA (causing us
830-
// to exit early from addPerfEarlyModulePassPipeline), exit early.
831-
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
832-
return P;
833-
834829
// Then run an iteration of the high-level SSA passes.
835830
//
836831
// FIXME: When *not* emitting a .swiftmodule, skip the high-level function
837832
// pipeline to save compile time.
838833
addHighLevelFunctionPipeline(P);
839834

835+
// Then if we were asked to stop optimization before lowering OSSA (causing us
836+
// to exit early from addHighLevelFunctionPipeline), exit early.
837+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
838+
return P;
839+
840840
addHighLevelModulePipeline(P);
841841

842842
// Run one last copy propagation/semantic arc opts run before serialization/us

test/SILOptimizer/assemblyvision_remark/cast_remarks.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public func forcedCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T {
4242
var x = ns
4343
x = ns2
4444
return x as! T // expected-remark @:12 {{unconditional runtime cast of value with type 'NS' to 'T'}}
45+
// expected-note @-9:44 {{of 'ns2'}}
4546
}
4647

4748
public func condCast<NS, T>(_ ns: NS) -> T? {
@@ -79,6 +80,7 @@ public func condCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T? {
7980
var x = ns
8081
x = ns2
8182
return x as? T // expected-remark @:12 {{conditional runtime cast of value with type 'NS' to 'T'}}
83+
// expected-note @-9:42 {{of 'ns2'}}
8284
}
8385

8486
public func condCast5<NS, T>(_ ns: NS) -> T? {
@@ -249,6 +251,7 @@ public func forcedCast4(_ ns: Existential1, _ ns2: Existential1) -> Existential2
249251
var x = ns
250252
x = ns2
251253
return x as! Existential2 // expected-remark @:12 {{unconditional runtime cast of value with type 'Existential1' to 'Existential2'}}
254+
// expected-note @-5:47 {{of 'ns2'}}
252255
}
253256

254257
public func condCast(_ ns: Existential1) -> Existential2? {
@@ -283,6 +286,7 @@ public func condCast4(_ ns: Existential1, _ ns2: Existential1) -> Existential2?
283286
var x = ns
284287
x = ns2
285288
return x as? Existential2 // expected-remark @:12 {{conditional runtime cast of value with type 'Existential1' to 'Existential2'}}
289+
// expected-note @-5:45 {{of 'ns2'}}
286290
}
287291

288292
public func condCast5(_ ns: Existential1) -> Existential2? {

test/SILOptimizer/assemblyvision_remark/cast_remarks_objc.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public func forcedCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T {
4545
var x = ns
4646
x = ns2
4747
return x as! T // expected-remark @:12 {{unconditional runtime cast of value with type 'NS' to 'T'}}
48+
// expected-note @-9:44 {{of 'ns2'}}
4849
}
4950

5051
public func condCast<NS, T>(_ ns: NS) -> T? {
@@ -82,6 +83,7 @@ public func condCast4<NS, T>(_ ns: NS, _ ns2: NS) -> T? {
8283
var x = ns
8384
x = ns2
8485
return x as? T // expected-remark @:12 {{conditional runtime cast of value with type 'NS' to 'T'}}
86+
// expected-note @-9:42 {{of 'ns2'}}
8587
}
8688

8789
public func condCast5<NS, T>(_ ns: NS) -> T? {

test/SILOptimizer/outliner.swift

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ public class MyGizmo {
1515
}
1616

1717
// CHECK-LABEL: sil @$s8outliner7MyGizmoC11usePropertyyyF :
18-
// CHECK: [[A_FUN:%.*]] = function_ref @$sSo5GizmoC14stringPropertySSSgvgToTeab_
19-
// CHECK: apply [[A_FUN]]({{.*}}) : $@convention(thin) (@in_guaranteed Gizmo) -> @owned Optional<String>
20-
// CHECK-NOT: return
2118
// CHECK: [[P_FUN:%.*]] = function_ref @$sSo5GizmoC14stringPropertySSSgvgToTepb_
2219
// CHECK: apply [[P_FUN]]({{.*}}) : $@convention(thin) (Gizmo) -> @owned Optional<String>
20+
// CHECK-NOT: return
21+
// CHECK: apply [[P_FUN]]({{.*}}) : $@convention(thin) (Gizmo) -> @owned Optional<String>
2322
// CHECK: return
2423
// CHECK: } // end sil function '$s8outliner7MyGizmoC11usePropertyyyF'
2524
public func useProperty() {
@@ -66,26 +65,6 @@ public func testOutlining() {
6665
// CHECK: switch_enum [[RES]]
6766
// CHECK: } // end sil function '$s8outliner9dontCrash1ayyp_tF'
6867

69-
// CHECK-LABEL: sil shared [noinline] @$sSo5GizmoC14stringPropertySSSgvgToTeab_ : $@convention(thin) (@in_guaranteed Gizmo) -> @owned Optional<String>
70-
// CHECK: bb0(%0 : $*Gizmo):
71-
// CHECK: %1 = load %0 : $*Gizmo
72-
// CHECK: %2 = objc_method %1 : $Gizmo, #Gizmo.stringProperty!getter.foreign : (Gizmo) -> () -> String?
73-
// CHECK: %3 = apply %2(%1) : $@convention(objc_method) (Gizmo) -> @autoreleased Optional<NSString>
74-
// CHECK: switch_enum %3 : $Optional<NSString>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
75-
// CHECK: bb1(%5 : $NSString):
76-
// CHECK: %6 = function_ref @$sSS10FoundationE36_unconditionallyBridgeFromObjectiveCySSSo8NSStringCSgFZ : $@convention(method) (@guaranteed Optional<NSString>, @thin String.Type) -> @owned String
77-
// CHECK: %7 = metatype $@thin String.Type
78-
// CHECK: %8 = apply %6(%3, %7) : $@convention(method) (@guaranteed Optional<NSString>, @thin String.Type) -> @owned String
79-
// CHECK: release_value %3 : $Optional<NSString>
80-
// CHECK: %10 = enum $Optional<String>, #Optional.some!enumelt, %8 : $String
81-
// CHECK: br bb3(%10 : $Optional<String>)
82-
// CHECK: bb2:
83-
// CHECK: %12 = enum $Optional<String>, #Optional.none!enumelt
84-
// CHECK: br bb3(%12 : $Optional<String>)
85-
// CHECK: bb3(%14 : $Optional<String>):
86-
// CHECK: return %14 : $Optional<String>
87-
// CHECK: } // end sil function '$sSo5GizmoC14stringPropertySSSgvgToTeab_'
88-
8968
// CHECK-LABEL: sil shared [noinline] @$sSo5GizmoC14stringPropertySSSgvgToTepb_ : $@convention(thin) (Gizmo) -> @owned Optional<String>
9069
// CHECK: bb0(%0 : $Gizmo):
9170
// CHECK: %1 = objc_method %0 : $Gizmo, #Gizmo.stringProperty!getter.foreign : (Gizmo) -> () -> String?

0 commit comments

Comments
 (0)