Skip to content

Commit 5426d50

Browse files
authored
Merge pull request swiftlang#39601 from meg-gupta/moveomeb4outliner
Move OME lower for non-transparent functions
2 parents e92656d + e63a68d commit 5426d50

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ static llvm::cl::opt<bool> SILViewSILGenCFG(
5555
"sil-view-silgen-cfg", llvm::cl::init(false),
5656
llvm::cl::desc("Enable the sil cfg viewer pass before diagnostics"));
5757

58+
59+
llvm::cl::opt<bool> SILDisableLateOMEByDefault(
60+
"sil-disable-late-ome-by-default", llvm::cl::init(false),
61+
llvm::cl::desc(
62+
"Disable late OME for non-transparent functions by default"));
63+
5864
//===----------------------------------------------------------------------===//
5965
// Diagnostic Pass Pipeline
6066
//===----------------------------------------------------------------------===//
@@ -518,18 +524,12 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
518524
// not blocked by any other passes' optimizations, so do it early.
519525
P.addDifferentiabilityWitnessDevirtualizer();
520526

521-
// Strip ownership from non-transparent functions when we are not compiling
522-
// the stdlib module. When compiling the stdlib, we eliminate ownership on
523-
// these functions later with a nromal call to
524-
// P.addNonTransparentFunctionOwnershipModelEliminator().
525-
//
526-
// This is done so we can push ownership through the pass pipeline first for
527-
// the stdlib and then everything else.
528-
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
529-
return;
527+
if (!P.getOptions().EnableOSSAModules && SILDisableLateOMEByDefault) {
528+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
529+
return;
530530

531-
if (!P.getOptions().EnableOSSAModules)
532531
P.addNonTransparentFunctionOwnershipModelEliminator();
532+
}
533533

534534
// Start by linking in referenced functions from other modules.
535535
P.addPerformanceSILLinker();
@@ -543,6 +543,13 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
543543
// optimization.
544544
P.addGlobalOpt();
545545

546+
if (!P.getOptions().EnableOSSAModules && !SILDisableLateOMEByDefault) {
547+
if (P.getOptions().StopOptimizationBeforeLoweringOwnership)
548+
return;
549+
550+
P.addNonTransparentFunctionOwnershipModelEliminator();
551+
}
552+
546553
// Add the outliner pass (Osize).
547554
P.addOutliner();
548555

test/SILOptimizer/OSLogFullOptTest.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,13 @@ func testNSObjectInterpolation(nsArray: NSArray) {
133133
// TODO: check why the ARC optimizer cannot eliminate the many retain/release pairs here.
134134
// CHECK: entry:
135135
// CHECK-NEXT: bitcast %TSo7NSArrayC* %0 to i8*
136-
// CHECK-NEXT: tail call i8* @llvm.objc.retain
137136
// CHECK-NEXT: [[NSARRAY_ARG:%.+]] = tail call i8* @llvm.objc.retain
138137
// CHECK: tail call swiftcc i1 @"${{.*}}isLoggingEnabled{{.*}}"()
139138
// CHECK-NEXT: br i1 {{%.*}}, label %[[ENABLED:[0-9]+]], label %[[NOT_ENABLED:[0-9]+]]
140139

141140
// CHECK: [[NOT_ENABLED]]:
142141
// CHECK-NEXT: tail call void @swift_release
143142
// CHECK-NEXT: tail call void @llvm.objc.release
144-
// CHECK-NEXT: tail call void @llvm.objc.release
145143
// CHECK-NEXT: br label %[[EXIT:[0-9]+]]
146144

147145
// CHECK: [[ENABLED]]:
@@ -172,7 +170,6 @@ func testNSObjectInterpolation(nsArray: NSArray) {
172170
// CHECK-NEXT: [[BITCASTED_SRC2:%.+]] = bitcast i8* [[NSARRAY_ARG]] to %TSo7NSArrayC*
173171
// CHECK-64-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 8
174172
// CHECK-32-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 4
175-
// CHECK-NEXT: tail call void @llvm.objc.release
176173
// CHECK-64-NEXT: tail call swiftcc void @"${{.*}}_os_log_impl_test{{.*}}"({{.*}}, {{.*}}, {{.*}}, {{.*}}, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @{{.*}}, i64 0, i64 0), i8* {{(nonnull )?}}[[BUFFER]], i32 12)
177174
// CHECK-32-NEXT: tail call swiftcc void @"${{.*}}_os_log_impl_test{{.*}}"({{.*}}, {{.*}}, {{.*}}, {{.*}}, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @{{.*}}, i32 0, i32 0), i8* {{(nonnull )?}}[[BUFFER]], i32 8)
178175
// CHECK-NEXT: [[BITCASTED_OBJ_STORAGE:%.+]] = bitcast i8* [[OBJ_STORAGE]] to %swift.opaque*

0 commit comments

Comments
 (0)