Skip to content

Commit ed1b3f2

Browse files
committed
[SILOpt] Put DestroyHoisting behind flag.
Tested that import enum case is optimized appropriately without the classic DestroyHoisting pass.
1 parent 271bfdc commit ed1b3f2

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ llvm::cl::opt<bool> SILDisableLateOMEByDefault(
6666
llvm::cl::desc(
6767
"Disable late OME for non-transparent functions by default"));
6868

69+
llvm::cl::opt<bool>
70+
EnableDestroyHoisting("enable-destroy-hoisting", llvm::cl::init(true),
71+
llvm::cl::desc("Enable the DestroyHoisting pass."));
72+
6973
//===----------------------------------------------------------------------===//
7074
// Diagnostic Pass Pipeline
7175
//===----------------------------------------------------------------------===//
@@ -145,7 +149,7 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
145149
P.addSILSkippingChecker();
146150
#endif
147151

148-
if (Options.shouldOptimize()) {
152+
if (Options.shouldOptimize() && EnableDestroyHoisting) {
149153
P.addDestroyHoisting();
150154
}
151155
P.addMandatoryInlining();

test/SILOptimizer/enumpayload.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -O -Xllvm -enable-destroy-hoisting=false -module-name=test %s -o %t/a.out
3+
// RUN: %target-run %t/a.out | %FileCheck %s
4+
5+
// REQUIRES: executable_test,optimized_stdlib
6+
7+
final class Storage {
8+
var v : Int
9+
init(_ v : Int) {
10+
self.v = v
11+
}
12+
}
13+
14+
struct IntBox {
15+
var s : Storage
16+
17+
init(_ x : Int) {
18+
s = Storage(x)
19+
}
20+
21+
var value: Int { return s.v }
22+
23+
mutating func increment(_ delta: Int) {
24+
if (!isKnownUniquelyReferenced(&s)) {
25+
// We should never see this message
26+
print("## copy on write")
27+
s = Storage(s.v)
28+
}
29+
s.v += delta
30+
}
31+
}
32+
33+
enum E {
34+
case value(IntBox)
35+
case none
36+
37+
@inline(never)
38+
mutating func simpleIncrement() {
39+
switch self {
40+
case .value(var i):
41+
i.increment(1)
42+
self = .value(i)
43+
case .none:
44+
break
45+
}
46+
}
47+
}
48+
49+
func test_enum() {
50+
// CHECK: test_enum() simpleIncrement start
51+
print(#function, "simpleIncrement start")
52+
var e1 = E.value(IntBox(27))
53+
e1.simpleIncrement()
54+
// CHECK-NEXT: test_enum() simpleIncrement end: 28
55+
switch e1 {
56+
case .value(let i):
57+
print(#function, "simpleIncrement end:", i.s.v.description)
58+
case .none:
59+
print("none")
60+
}
61+
}
62+
63+
test_enum()

0 commit comments

Comments
 (0)