Skip to content

Commit e31c155

Browse files
Merge pull request swiftlang#40555 from nate-chandler/copy_propagation/rename-disabled-flags
Clarified copy-prop/lexical-lifetime flags.
2 parents b025679 + 27d758d commit e31c155

37 files changed

+244
-115
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ def dependency_scan_cache_remarks : Flag<["-"], "Rdependency-scan-cache">,
215215
def enable_copy_propagation : Flag<["-"], "enable-copy-propagation">,
216216
HelpText<"Run SIL copy propagation with lexical lifetimes to shorten object "
217217
"lifetimes while preserving variable lifetimes.">;
218-
def disable_copy_propagation : Flag<["-"], "disable-copy-propagation">,
219-
HelpText<"Don't run SIL copy propagation to preserve object lifetime.">;
218+
def copy_propagation_state_EQ :
219+
Joined<["-"], "enable-copy-propagation=">,
220+
HelpText<"Whether to enable copy propagation">,
221+
MetaVarName<"true|requested-passes-only|false">;
220222

221223
def enable_infer_public_concurrent_value : Flag<["-"], "enable-infer-public-sendable">,
222224
HelpText<"Enable inference of Sendable conformances for public structs and enums">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,42 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
14661466
// -Ounchecked might also set removal of runtime asserts (cond_fail).
14671467
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);
14681468

1469+
Optional<CopyPropagationOption> specifiedCopyPropagationOption;
1470+
if (Arg *A = Args.getLastArg(OPT_copy_propagation_state_EQ)) {
1471+
specifiedCopyPropagationOption =
1472+
llvm::StringSwitch<Optional<CopyPropagationOption>>(A->getValue())
1473+
.Case("true", CopyPropagationOption::On)
1474+
.Case("false", CopyPropagationOption::Off)
1475+
.Case("requested-passes-only",
1476+
CopyPropagationOption::RequestedPassesOnly)
1477+
.Default(None);
1478+
}
1479+
if (Args.hasArg(OPT_enable_copy_propagation)) {
1480+
if (specifiedCopyPropagationOption) {
1481+
if (*specifiedCopyPropagationOption == CopyPropagationOption::Off) {
1482+
// Error if copy propagation has been set to ::Off via the meta-var form
1483+
// and enabled via the flag.
1484+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
1485+
"enable-copy-propagation",
1486+
"enable-copy-propagation=false");
1487+
return true;
1488+
} else if (*specifiedCopyPropagationOption ==
1489+
CopyPropagationOption::RequestedPassesOnly) {
1490+
// Error if copy propagation has been set to ::RequestedPassesOnly via
1491+
// the meta-var form and enabled via the flag.
1492+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
1493+
"enable-copy-propagation",
1494+
"enable-copy-propagation=requested-passes-only");
1495+
return true;
1496+
}
1497+
} else {
1498+
specifiedCopyPropagationOption = CopyPropagationOption::On;
1499+
}
1500+
}
1501+
if (specifiedCopyPropagationOption) {
1502+
Opts.CopyPropagation = *specifiedCopyPropagationOption;
1503+
}
1504+
14691505
Optional<bool> enableLexicalBorrowScopesFlag;
14701506
if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) {
14711507
enableLexicalBorrowScopesFlag =
@@ -1525,13 +1561,14 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
15251561
return true;
15261562
}
15271563

1528-
// -enable-copy-propagation implies -enable-lexical-lifetimes unless
1529-
// otherwise specified.
1530-
if (Args.hasArg(OPT_enable_copy_propagation))
1564+
// Unless overridden below, enabling copy propagation means enabling lexical
1565+
// lifetimes.
1566+
if (Opts.CopyPropagation == CopyPropagationOption::On)
15311567
Opts.LexicalLifetimes = LexicalLifetimesOption::On;
15321568

1533-
// -disable-copy-propagation implies -enable-lexical-lifetimes=false
1534-
if (Args.hasArg(OPT_disable_copy_propagation))
1569+
// Unless overridden below, disable copy propagation means disabling lexical
1570+
// lifetimes.
1571+
if (Opts.CopyPropagation == CopyPropagationOption::Off)
15351572
Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
15361573

15371574
// If move-only is enabled, always enable lexical lifetime as well. Move-only
@@ -1554,24 +1591,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
15541591
}
15551592
}
15561593

1557-
if (Args.hasArg(OPT_enable_copy_propagation) &&
1558-
Args.hasArg(OPT_disable_copy_propagation)) {
1559-
// Error if copy propagation is enabled and copy propagation is disabled.
1560-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
1561-
"enable-copy-propagation", "disable-copy-propagation");
1562-
return true;
1563-
} else if (Args.hasArg(OPT_enable_copy_propagation) &&
1564-
!Args.hasArg(OPT_disable_copy_propagation)) {
1565-
Opts.CopyPropagation = CopyPropagationOption::On;
1566-
} else if (!Args.hasArg(OPT_enable_copy_propagation) &&
1567-
Args.hasArg(OPT_disable_copy_propagation)) {
1568-
Opts.CopyPropagation = CopyPropagationOption::Off;
1569-
} else /*if (!Args.hasArg(OPT_enable_copy_propagation) &&
1570-
!Args.hasArg(OPT_disable_copy_propagation))*/
1571-
{
1572-
Opts.CopyPropagation = CopyPropagationOption::RequestedPassesOnly;
1573-
}
1574-
15751594
Opts.EnableARCOptimizations &= !Args.hasArg(OPT_disable_arc_opts);
15761595
Opts.EnableOSSAModules |= Args.hasArg(OPT_enable_ossa_modules);
15771596
Opts.EnableOSSAOptimizations &= !Args.hasArg(OPT_disable_ossa_opts);

test/ClangImporter/serialization-sil.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module-path %t/Test.swiftmodule -emit-sil -o /dev/null -module-name Test %s -sdk "" -import-objc-header %S/Inputs/serialization-sil.h
2+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -emit-module-path %t/Test.swiftmodule -emit-sil -o /dev/null -module-name Test %s -sdk "" -import-objc-header %S/Inputs/serialization-sil.h
33
// RUN: %target-sil-func-extractor %t/Test.swiftmodule -sil-print-debuginfo -func='$s4Test16testPartialApplyyySoAA_pF' -o - | %FileCheck %s
44

55
// REQUIRES: objc_interop

test/DebugInfo/allocstack.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2-
// RUN: %target-swift-frontend %s -emit-sil -g -o - | %FileCheck -check-prefix=CHECK-SIL %s
1+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false %s -emit-ir -g -o - | %FileCheck %s
2+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false %s -emit-sil -g -o - | %FileCheck -check-prefix=CHECK-SIL %s
33
import StdlibUnittest
44

55
// Test that debug info for local variables is preserved by the

test/DebugInfo/if-branchlocations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-sil -disable-copy-propagation -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-NCP
1+
// RUN: %target-swift-frontend %s -emit-sil -enable-copy-propagation=false -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-NCP
22
// RUN: %target-swift-frontend %s -emit-sil -enable-copy-propagation -enable-lexical-borrow-scopes=false -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-CP
33

44
class NSURL {}

test/DebugInfo/linetable-do.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle %s -emit-ir -g -o - | %FileCheck %s
2-
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -disable-copy-propagation %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-NCP %s
2+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-copy-propagation=false %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-NCP %s
33
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-copy-propagation -enable-lexical-borrow-scopes=false %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-CP %s
44
import StdlibUnittest
55

test/DebugInfo/returnlocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -g -emit-ir %s -o %t.ll
1+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -g -emit-ir %s -o %t.ll
22

33
// REQUIRES: objc_interop
44

test/DebugInfo/sil_based_dbg.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %s -O -sil-based-debuginfo -Xllvm -sil-print-debuginfo -emit-ir -o %t/out.ir
2+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false %s -O -sil-based-debuginfo -Xllvm -sil-print-debuginfo -emit-ir -o %t/out.ir
33
// RUN: %FileCheck %s < %t/out.ir
44
// RUN: %FileCheck %s --check-prefix=CHECK_OUT_SIL < %t/out.ir.sil_dbg_0.sil
55

66
// Second test: check that we don't crash with multi-threaded IRGen
7-
// RUN: %target-swift-frontend -c %s %S/Inputs/testclass.swift -wmo -O -num-threads 1 -sil-based-debuginfo -o %t/sil_based_dbg.o -o %t/testclass.o
7+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -c %s %S/Inputs/testclass.swift -wmo -O -num-threads 1 -sil-based-debuginfo -o %t/sil_based_dbg.o -o %t/testclass.o
88

99
// CHECK: !DIFile(filename: "{{.+}}sil_based_dbg.swift", directory: "{{.+}}")
1010
// CHECK: [[F:![0-9]+]] = !DIFile(filename: "{{.+}}out.ir.sil_dbg_0.sil",
@@ -19,10 +19,10 @@ public func testit() {
1919
// in sil-based-dbg mode.
2020
// To create something like `alloc_stack ..., (name "foo", loc ..., scope 0)...`
2121
// as our testing input, we're only running SROA over the input swift code.
22-
// RUN: %target-swift-frontend %s -disable-debugger-shadow-copies -emit-sil -g -o %t/stage1.sil
23-
// RUN: %target-sil-opt -sil-print-debuginfo -access-marker-elim -sroa %t/stage1.sil -o %t/stage2.sil
22+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false %s -disable-debugger-shadow-copies -emit-sil -g -o %t/stage1.sil
23+
// RUN: %target-sil-opt -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -sil-print-debuginfo -access-marker-elim -sroa %t/stage1.sil -o %t/stage2.sil
2424
// The verification shouldn't fail
25-
// RUN: %target-swift-frontend %t/stage2.sil -sil-verify-all -sil-based-debuginfo -g -emit-sil -o %t/out.sil
25+
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false %t/stage2.sil -sil-verify-all -sil-based-debuginfo -g -emit-sil -o %t/out.sil
2626
// RUN: %FileCheck %s --check-prefix=CHECK_DBG_SCOPE < %t/out.sil
2727
struct TheStruct {
2828
var the_member : Int

test/SILGen/addressors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
// RUN: %target-swift-emit-sil -parse-stdlib %s | %FileCheck %s
3-
// RUN: %target-swift-emit-silgen -parse-stdlib %s | %FileCheck %s -check-prefix=SILGEN
4-
// RUN: %target-swift-emit-ir -parse-stdlib %s
2+
// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -parse-stdlib %s | %FileCheck %s
3+
// RUN: %target-swift-emit-silgen -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -parse-stdlib %s | %FileCheck %s -check-prefix=SILGEN
4+
// RUN: %target-swift-emit-ir -enable-copy-propagation=requested-passes-only -enable-lexical-lifetimes=false -parse-stdlib %s
55

66
// This test includes some calls to transparent stdlib functions.
77
// We pattern match for the absence of access markers in the inlined code.

test/SILGen/copy_operator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-emit-silgen -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-experimental-move-only | %FileCheck %s
2-
// RUN: %target-swift-emit-sil -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL %s
3-
// RUN: %target-swift-emit-sil -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL-OPT %s
1+
// RUN: %target-swift-emit-silgen -enable-copy-propagation=requested-passes-only -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-experimental-move-only | %FileCheck %s
2+
// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL %s
3+
// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL-OPT %s
44

55
import Swift
66

0 commit comments

Comments
 (0)