Skip to content

Commit 569f9e6

Browse files
Merge pull request #42216 from nate-chandler/cherrypick/release/5.7/destroy_hoisting/flag
[5.7] [SILOpt] Added flag to disable destroy hoisting.
2 parents add8eff + 768e6c7 commit 569f9e6

File tree

5 files changed

+140
-3
lines changed

5 files changed

+140
-3
lines changed

include/swift/AST/SILOptions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ enum class CopyPropagationOption : uint8_t {
5858
On
5959
};
6060

61+
enum class DestroyHoistingOption : uint8_t {
62+
// Do not run SSADestroyHoisting.
63+
Off = 0,
64+
65+
// Run SSADestroyHoisting pass after AllocBoxToStack in the function passes.
66+
On = 1
67+
};
68+
6169
class SILModule;
6270

6371
class SILOptions {
@@ -84,6 +92,11 @@ class SILOptions {
8492
/// When this is 'On' the pipeline has default behavior.
8593
CopyPropagationOption CopyPropagation = CopyPropagationOption::On;
8694

95+
/// Whether to run the SSADestroyHoisting pass.
96+
///
97+
/// When this 'On' the pipeline has the default behavior.
98+
DestroyHoistingOption DestroyHoisting = DestroyHoistingOption::On;
99+
87100
/// Controls whether the SIL ARC optimizations are run.
88101
bool EnableARCOptimizations = true;
89102

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ let Flags = [FrontendOption, NoDriverOption, HelpHidden, ModuleInterfaceOptionIg
248248
def enable_lexical_lifetimes_noArg :
249249
Flag<["-"], "enable-lexical-lifetimes">,
250250
HelpText<"Enable lexical lifetimes">;
251+
def enable_destroy_hoisting :
252+
Joined<["-"], "enable-destroy-hoisting=">,
253+
HelpText<"Whether to enable destroy hoisting">,
254+
MetaVarName<"true|false">;
251255
}
252256

253257
// Flags that are saved into module interfaces

lib/Frontend/CompilerInvocation.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,15 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
15561556
// -Ounchecked might also set removal of runtime asserts (cond_fail).
15571557
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);
15581558

1559+
Optional<DestroyHoistingOption> specifiedDestroyHoistingOption;
1560+
if (Arg *A = Args.getLastArg(OPT_enable_destroy_hoisting)) {
1561+
specifiedDestroyHoistingOption =
1562+
llvm::StringSwitch<Optional<DestroyHoistingOption>>(A->getValue())
1563+
.Case("true", DestroyHoistingOption::On)
1564+
.Case("false", DestroyHoistingOption::Off)
1565+
.Default(None);
1566+
}
1567+
15591568
Optional<CopyPropagationOption> specifiedCopyPropagationOption;
15601569
if (Arg *A = Args.getLastArg(OPT_copy_propagation_state_EQ)) {
15611570
specifiedCopyPropagationOption =
@@ -1657,13 +1666,17 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
16571666

16581667
// Unless overridden below, enabling copy propagation means enabling lexical
16591668
// lifetimes.
1660-
if (Opts.CopyPropagation == CopyPropagationOption::On)
1669+
if (Opts.CopyPropagation == CopyPropagationOption::On) {
16611670
Opts.LexicalLifetimes = LexicalLifetimesOption::On;
1671+
Opts.DestroyHoisting = DestroyHoistingOption::On;
1672+
}
16621673

16631674
// Unless overridden below, disable copy propagation means disabling lexical
16641675
// lifetimes.
1665-
if (Opts.CopyPropagation == CopyPropagationOption::Off)
1676+
if (Opts.CopyPropagation == CopyPropagationOption::Off) {
16661677
Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
1678+
Opts.DestroyHoisting = DestroyHoistingOption::Off;
1679+
}
16671680

16681681
// If move-only is enabled, always enable lexical lifetime as well. Move-only
16691682
// depends on lexical lifetimes.
@@ -1684,6 +1697,8 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
16841697
Opts.LexicalLifetimes = LexicalLifetimesOption::Off;
16851698
}
16861699
}
1700+
if (specifiedDestroyHoistingOption)
1701+
Opts.DestroyHoisting = *specifiedDestroyHoistingOption;
16871702

16881703
Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);
16891704
Opts.EnableOSSAModules |= Args.hasArg(OPT_enable_ossa_modules);

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ void addFunctionPasses(SILPassPipelinePlan &P,
354354
// Promote box allocations to stack allocations.
355355
P.addAllocBoxToStack();
356356

357-
P.addSSADestroyHoisting();
357+
if (P.getOptions().DestroyHoisting == DestroyHoistingOption::On) {
358+
P.addSSADestroyHoisting();
359+
}
358360

359361
// Propagate copies through stack locations. Should run after
360362
// box-to-stack promotion since it is limited to propagating through
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// RUN: %target-swift-frontend %s \
2+
// RUN: -O \
3+
// RUN: -Xllvm -sil-print-pass-name \
4+
// RUN: -emit-ir \
5+
// RUN: -o /dev/null \
6+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPUNSPEC-DHUNSPEC %s
7+
8+
// RUN: %target-swift-frontend %s \
9+
// RUN: -O \
10+
// RUN: -enable-destroy-hoisting=false \
11+
// RUN: -Xllvm -sil-print-pass-name \
12+
// RUN: -emit-ir \
13+
// RUN: -o /dev/null \
14+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPUNSPEC-DHOFF %s
15+
16+
// RUN: %target-swift-frontend %s \
17+
// RUN: -O \
18+
// RUN: -enable-destroy-hoisting=true \
19+
// RUN: -Xllvm -sil-print-pass-name \
20+
// RUN: -emit-ir \
21+
// RUN: -o /dev/null \
22+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPUNSPEC-DHON %s
23+
24+
// RUN: %target-swift-frontend %s \
25+
// RUN: -O \
26+
// RUN: -enable-copy-propagation=false \
27+
// RUN: -Xllvm -sil-print-pass-name \
28+
// RUN: -emit-ir \
29+
// RUN: -o /dev/null \
30+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPOFF-DHUNSPEC %s
31+
32+
// RUN: %target-swift-frontend %s \
33+
// RUN: -O \
34+
// RUN: -enable-copy-propagation=false \
35+
// RUN: -enable-destroy-hoisting=false \
36+
// RUN: -Xllvm -sil-print-pass-name \
37+
// RUN: -emit-ir \
38+
// RUN: -o /dev/null \
39+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPOFF-DHOFF %s
40+
41+
// RUN: %target-swift-frontend %s \
42+
// RUN: -O \
43+
// RUN: -enable-copy-propagation=false \
44+
// RUN: -enable-destroy-hoisting=true \
45+
// RUN: -Xllvm -sil-print-pass-name \
46+
// RUN: -emit-ir \
47+
// RUN: -o /dev/null \
48+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPOFF-DHON %s
49+
50+
// RUN: %target-swift-frontend %s \
51+
// RUN: -O \
52+
// RUN: -enable-copy-propagation=true \
53+
// RUN: -Xllvm -sil-print-pass-name \
54+
// RUN: -emit-ir \
55+
// RUN: -o /dev/null \
56+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPON-DHUNSPEC %s
57+
58+
// RUN: %target-swift-frontend %s \
59+
// RUN: -O \
60+
// RUN: -enable-copy-propagation=true \
61+
// RUN: -enable-destroy-hoisting=false \
62+
// RUN: -Xllvm -sil-print-pass-name \
63+
// RUN: -emit-ir \
64+
// RUN: -o /dev/null \
65+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPON-DHOFF %s
66+
67+
// RUN: %target-swift-frontend %s \
68+
// RUN: -O \
69+
// RUN: -enable-copy-propagation=true \
70+
// RUN: -enable-destroy-hoisting=true \
71+
// RUN: -Xllvm -sil-print-pass-name \
72+
// RUN: -emit-ir \
73+
// RUN: -o /dev/null \
74+
// RUN: 2>&1 | %FileCheck -check-prefix CHECK-CPON-DHON %s
75+
76+
// CHECK-CPUNSPEC-DHUNSPEC: copy-propagation
77+
// CHECK-CPUNSPEC-DHUNSPEC: ssa-destroy-hoisting
78+
79+
// CHECK-CPUNSPEC-DHOFF: copy-propagation
80+
// CHECK-CPUNSPEC-DHOFF-NOT: ssa-destroy-hoisting
81+
82+
// CHECK-CPUNSPEC-DHON: copy-propagation
83+
// CHECK-CPUNSPEC-DHON: ssa-destroy-hoisting
84+
85+
// CHECK-CPOFF-DHUNSPEC-NOT: copy-propagation
86+
// CHECK-CPOFF-DHUNSPEC-NOT: ssa-destroy-hoisting
87+
88+
// CHECK-CPOFF-DHOFF-NOT: copy-propagation
89+
// CHECK-CPOFF-DHOFF-NOT: ssa-destroy-hoisting
90+
91+
// CHECK-CPOFF-DHON-NOT: copy-propagation
92+
// CHECK-CPOFF-DHON: ssa-destroy-hoisting
93+
94+
// CHECK-CPON-DHUNSPEC: copy-propagation
95+
// CHECK-CPON-DHUNSPEC: ssa-destroy-hoisting
96+
97+
// CHECK-CPON-DHOFF: copy-propagation
98+
// CHECK-CPON-DHOFF-NOT: ssa-destroy-hoisting
99+
100+
// CHECK-CPON-DHON: copy-propagation
101+
// CHECK-CPON-DHON: ssa-destroy-hoisting
102+
103+
func foo() {}

0 commit comments

Comments
 (0)