Skip to content

Commit 93a514c

Browse files
committed
Enable the CopyPropagation pass.
For now simply run the pass before SemanticARCOpts. This will probably be called as a utility from within SemanticARCOpts so it can be iteratively applied after other ARC-related transformations.
1 parent a6b8552 commit 93a514c

File tree

6 files changed

+20
-66
lines changed

6 files changed

+20
-66
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ void addFunctionPasses(SILPassPipelinePlan &P,
304304

305305
// We earlier eliminated ownership if we are not compiling the stdlib. Now
306306
// handle the stdlib functions, re-simplifying, eliminating ARC as we do.
307+
P.addCopyPropagation();
307308
P.addSemanticARCOpts();
308309
P.addNonTransparentFunctionOwnershipModelEliminator();
309310

@@ -447,6 +448,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
447448
// Cleanup after SILGen: remove trivial copies to temporaries.
448449
P.addTempRValueOpt();
449450
// Cleanup after SILGen: remove unneeded borrows/copies.
451+
P.addCopyPropagation();
450452
P.addSemanticARCOpts();
451453

452454
// Devirtualizes differentiability witnesses into functions that reference them.

test/Interpreter/builtin_bridge_object.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -parse-stdlib %s -o %t/a.out
3-
// RUN: %target-codesign %t/a.out
4-
// RUN: %target-run %t/a.out | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-Onone -parse-stdlib) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG
2+
// RUN: %target-run-simple-swift(-O -parse-stdlib) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s
53

64
// REQUIRES: executable_test
75
// REQUIRES: objc_interop
@@ -66,6 +64,7 @@ if true {
6664
print(x === x1)
6765
// CHECK-NEXT: true
6866
print(x === x2)
67+
// CHECK-OPT-NEXT: deallocated
6968

7069
print(nonPointerBits(bo) == 0)
7170
// CHECK-NEXT: true
@@ -79,7 +78,7 @@ if true {
7978
_fixLifetime(bo3)
8079
_fixLifetime(bo4)
8180
}
82-
// CHECK-NEXT: deallocated
81+
// CHECK-DBG-NEXT: deallocated
8382
// CHECK-NEXT: deallocated
8483

8584
// Try with all spare bits set.
@@ -94,6 +93,7 @@ if true {
9493
print(x === x1)
9594
// CHECK-NEXT: true
9695
print(x === x2)
96+
// CHECK-OPT-NEXT: deallocated
9797

9898
print(nonPointerBits(bo) == NATIVE_SPARE_BITS)
9999
// CHECK-NEXT: true
@@ -107,7 +107,7 @@ if true {
107107
_fixLifetime(bo3)
108108
_fixLifetime(bo4)
109109
}
110-
// CHECK-NEXT: deallocated
110+
// CHECK-DBG-NEXT: deallocated
111111
// CHECK-NEXT: deallocated
112112

113113

test/SILOptimizer/OSLogFullOptTest.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func testNSObjectInterpolation(nsArray: NSArray) {
140140
// CHECK: [[NOT_ENABLED]]:
141141
// CHECK-NEXT: tail call void @swift_release
142142
// CHECK-NEXT: tail call void @llvm.objc.release
143+
// CHECK-NEXT: tail call void @llvm.objc.release
143144
// CHECK-NEXT: br label %[[EXIT:[0-9]+]]
144145

145146
// CHECK: [[ENABLED]]:
@@ -170,7 +171,7 @@ func testNSObjectInterpolation(nsArray: NSArray) {
170171
// CHECK-NEXT: [[BITCASTED_SRC2:%.+]] = bitcast i8* [[NSARRAY_ARG]] to %TSo7NSArrayC*
171172
// CHECK-64-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 8
172173
// CHECK-32-NEXT: store %TSo7NSArrayC* [[BITCASTED_SRC2]], %TSo7NSArrayC** [[BITCASTED_DEST2]], align 4
173-
174+
// CHECK-NEXT: tail call void @llvm.objc.release
174175
// 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)
175176
// 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)
176177
// CHECK-NEXT: [[BITCASTED_OBJ_STORAGE:%.+]] = bitcast i8* [[OBJ_STORAGE]] to %swift.opaque*
@@ -181,7 +182,6 @@ func testNSObjectInterpolation(nsArray: NSArray) {
181182
// CHECK-NEXT: br label %[[EXIT]]
182183

183184
// CHECK: [[EXIT]]:
184-
// CHECK-NEXT: tail call void @llvm.objc.release(i8* [[NSARRAY_ARG]])
185185
// CHECK-NEXT: ret void
186186
}
187187

@@ -349,7 +349,6 @@ func testMetatypeInterpolation<T>(of type: T.Type) {
349349

350350
// CHECK: [[NOT_ENABLED]]:
351351
// CHECK-NEXT: call void @swift_release
352-
// CHECK-NEXT: br label %[[EXIT:[0-9]+]]
353352

354353
// CHECK: [[ENABLED]]:
355354
//

test/SILOptimizer/opt-remark-generator-yaml.swift

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public func getGlobal() -> Klass {
4848
// CHECK-NEXT: Pass: sil-opt-remark-gen
4949
// CHECK-NEXT: Name: sil.memory
5050
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
51-
// CHECK-NEXT: Line: [[# @LINE + 51]], Column: 11 }
51+
// CHECK-NEXT: Line: [[# @LINE + 23]], Column: 11 }
5252
// CHECK-NEXT: Function: 'useGlobal()'
5353
// CHECK-NEXT: Args:
5454
// CHECK-NEXT: - String: 'heap allocated ref of type '''
@@ -59,51 +59,19 @@ public func getGlobal() -> Klass {
5959
// CHECK-NEXT: Pass: sil-opt-remark-gen
6060
// CHECK-NEXT: Name: sil.memory
6161
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
62-
// CHECK-NEXT: Line: [[# @LINE + 40]], Column: 5 }
63-
// CHECK-NEXT: Function: 'useGlobal()'
64-
// CHECK-NEXT: Args:
65-
// CHECK-NEXT: - String: 'retain of type '''
66-
// CHECK-NEXT: - ValueType: Klass
67-
// CHECK-NEXT: - String: ''''
68-
// CHECK-NEXT: - InferredValue: 'of ''x'''
69-
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
70-
// CHECK-NEXT: Line: [[# @LINE + 29]], Column: 9 }
71-
// CHECK-NEXT: ...
72-
// CHECK-NEXT: --- !Missed
73-
// CHECK-NEXT: Pass: sil-opt-remark-gen
74-
// CHECK-NEXT: Name: sil.memory
75-
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
76-
// CHECK-NEXT: Line: [[# @LINE + 26]], Column: 12 }
62+
// CHECK-NEXT: Line: [[# @LINE + 12]], Column: 12 }
7763
// CHECK-NEXT: Function: 'useGlobal()'
7864
// CHECK-NEXT: Args:
7965
// CHECK-NEXT: - String: 'release of type '''
8066
// CHECK-NEXT: - ValueType:
8167
// CHECK-NEXT: - String: ''''
8268
// CHECK-NEXT: ...
83-
// CHECK-NEXT: --- !Missed
84-
// CHECK-NEXT: Pass: sil-opt-remark-gen
85-
// CHECK-NEXT: Name: sil.memory
86-
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
87-
// CHECK-NEXT: Line: [[# @LINE + 15]], Column: 12 }
88-
// CHECK-NEXT: Function: 'useGlobal()'
89-
// CHECK-NEXT: Args:
90-
// CHECK-NEXT: - String: 'release of type '''
91-
// CHECK-NEXT: - ValueType: Klass
92-
// CHECK-NEXT: - String: ''''
93-
// CHECK-NEXT: - InferredValue: 'of ''x'''
94-
// CHECK-NEXT: DebugLoc: { File: '{{.*}}opt-remark-generator-yaml.swift',
95-
// CHECK-NEXT: Line: [[# @LINE + 4]], Column: 9 }
96-
// CHECK-NEXT: ...
9769

9870
public func useGlobal() {
9971
let x = getGlobal()
10072
// Make sure that the retain msg is at the beginning of the print and the
10173
// releases are the end of the print.
10274
print(x) // expected-remark @:11 {{heap allocated ref of type}}
103-
// expected-remark @-1:5 {{retain of type 'Klass'}}
104-
// expected-note @-5:9 {{of 'x'}}
10575
// We test the type emission above since FileCheck can handle regex.
106-
// expected-remark @-4:12 {{release of type}}
107-
// expected-remark @-5:12 {{release of type 'Klass'}}
108-
// expected-note @-9:9 {{of 'x'}}
76+
// expected-remark @-2:12 {{release of type}}
10977
}

test/SILOptimizer/opt-remark-generator.swift

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ public func getGlobal() -> Klass {
2222
public func useGlobal() {
2323
let x = getGlobal()
2424
print(x) // expected-remark @:11 {{heap allocated ref of type}}
25-
// expected-remark @-1:5 {{retain of type 'Klass'}}
26-
// expected-note @-3:9 {{of 'x'}}
27-
// expected-remark @-3:12 {{release of type}}
28-
// expected-remark @-4:12 {{release of type 'Klass'}}
29-
// expected-note @-6:9 {{of 'x'}}
25+
// expected-remark @-1:12 {{release of type}}
3026
}
3127

3228
public enum TrivialState {
@@ -188,21 +184,13 @@ func castAsQuestionDiamondGEP2(x: KlassPair) {
188184
// expected-note @-4 {{of 'x.rhs'}}
189185
case let (.some(x1), .some(x2)):
190186
print(x1, x2) // expected-remark @:15 {{heap allocated ref of type}}
191-
// expected-remark @-1 {{retain of type 'Optional<SubKlass>'}}
192-
// expected-remark @-2 {{retain of type 'Optional<SubKlass>'}}
193-
// expected-remark @-3 {{release of type}}
194-
// expected-remark @-4 {{release of type 'Optional<SubKlass>'}}
195-
// expected-remark @-5 {{release of type 'Optional<SubKlass>'}}
187+
// expected-remark @-1 {{release of type}}
196188
case let (.some(x1), nil):
197189
print(x1) // expected-remark @:15 {{heap allocated ref of type}}
198-
// expected-remark @-1 {{retain of type 'SubKlass'}}
199-
// expected-remark @-2 {{release of type}}
200-
// expected-remark @-3 {{release of type 'Optional<SubKlass>'}}
190+
// expected-remark @-1 {{release of type}}
201191
case let (nil, .some(x2)):
202192
print(x2) // expected-remark @:15 {{heap allocated ref of type}}
203-
// expected-remark @-1 {{retain of type 'SubKlass'}}
204-
// expected-remark @-2 {{release of type}}
205-
// expected-remark @-3 {{release of type 'Optional<SubKlass>'}}
193+
// expected-remark @-1 {{release of type}}
206194
case (nil, nil):
207195
break
208196
}
@@ -278,9 +266,5 @@ func allocateValue() {
278266
let k = Klass() // expected-remark @:13 {{heap allocated ref of type 'Klass'}}
279267
// expected-note @-1:9 {{of 'k'}}
280268
print(k) // expected-remark @:11 {{heap allocated ref of type}}
281-
// expected-remark @-1:5 {{retain of type 'Klass'}}
282-
// expected-note @-4:9 {{of 'k'}}
283-
// expected-remark @-3:12 {{release of type}}
284-
// expected-remark @-4:12 {{release of type 'Klass'}}
285-
// expected-note @-7:9 {{of 'k'}}
269+
// expected-remark @-1:12 {{release of type}}
286270
}

test/SILOptimizer/outliner.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public class MyGizmo {
4040
// CHECK: apply [[FUN]]({{.*}}) : $@convention(thin) (@owned String, Int, Optional<AnyObject>, Gizmo) -> @owned Optional<String>
4141
// CHECK: [[FUN:%.*]] = function_ref @$sSo5GizmoC11doSomethingyypSgSaySSGSgFToTembgnn_
4242
// CHECK: apply [[FUN]]({{.*}}) : $@convention(thin) (@guaranteed Array<String>, Gizmo) -> @owned Optional<AnyObject>
43-
// CHECK: apply [[FUN]]({{.*}}) : $@convention(thin) (@guaranteed Array<String>, Gizmo) -> @owned Optional<AnyObject>
43+
// CHECK: [[FUN:%.*]] = function_ref @$sSo5GizmoC11doSomethingyypSgSaySSGSgFToTembnn_
44+
// CHECK: apply [[FUN]]({{.*}}) : $@convention(thin) (@owned Array<String>, Gizmo) -> @owned Optional<AnyObject>
4445
// CHECK: return
4546
// CHECK: } // end sil function '$s8outliner13testOutliningyyF'
4647
public func testOutlining() {

0 commit comments

Comments
 (0)