Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsFrontend.def
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ ERROR(error_unknown_arg,none,
"unknown argument: '%0'", (StringRef))
ERROR(error_invalid_arg_value,none,
"invalid value '%1' in '%0'", (StringRef, StringRef))
ERROR(error_invalid_arg_combination,none,
"unsupported argument combination: '%0' and '%1'", (StringRef, StringRef))
WARNING(warning_invalid_locale_code,none,
"unsupported locale code; supported locale codes are: '%0'", (StringRef))
WARNING(warning_locale_path_not_found,none,
Expand Down
20 changes: 12 additions & 8 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def dependency_scan_cache_remarks : Flag<["-"], "Rdependency-scan-cache">,
HelpText<"Emit remarks indicating use of the serialized module dependency scanning cache.">;

def enable_copy_propagation : Flag<["-"], "enable-copy-propagation">,
HelpText<"Run SIL copy propagation to shorten object lifetime.">;
HelpText<"Run SIL copy propagation with lexical lifetimes to shorten object "
"lifetimes while preserving variable lifetimes.">;
def disable_copy_propagation : Flag<["-"], "disable-copy-propagation">,
HelpText<"Don't run SIL copy propagation to preserve object lifetime.">;

Expand Down Expand Up @@ -259,15 +260,18 @@ def enable_experimental_concurrency :
Flag<["-"], "enable-experimental-concurrency">,
HelpText<"Enable experimental concurrency model">;

def disable_lexical_lifetimes :
Flag<["-"], "disable-lexical-lifetimes">,
HelpText<"Disables early lexical lifetimes. Mutually exclusive with "
"-enable-lexical-lifetimes">;

def enable_lexical_borrow_scopes :
Joined<["-"], "enable-lexical-borrow-scopes=">,
HelpText<"Whether to emit lexical borrow scopes (default: true)">,
MetaVarName<"true|false">;
def enable_lexical_lifetimes :
Joined<["-"], "enable-lexical-lifetimes=">,
HelpText<"Whether to enable lexical lifetimes">,
MetaVarName<"true|false">;
def enable_lexical_lifetimes_noArg :
Flag<["-"], "enable-lexical-lifetimes">,
HelpText<"Enable lexical lifetimes. Mutually exclusive with "
"-disable-lexical-lifetimes">;
HelpText<"Enable lexical lifetimes">;

def enable_experimental_move_only :
Flag<["-"], "enable-experimental-move-only">,
Expand Down
91 changes: 79 additions & 12 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,21 +1449,88 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
// -Ounchecked might also set removal of runtime asserts (cond_fail).
Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts);

// If experimental move only is enabled, always enable lexical lifetime as
// well. Move only depends on lexical lifetimes.
bool enableExperimentalLexicalLifetimes =
Args.hasArg(OPT_enable_lexical_lifetimes) ||
Args.hasArg(OPT_enable_experimental_move_only);
// Error if both experimental lexical lifetimes and disable lexical lifetimes
// are both set.
if (enableExperimentalLexicalLifetimes &&
Args.hasArg(OPT_disable_lexical_lifetimes)) {
Optional<bool> enableLexicalBorrowScopesFlag;
if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) {
enableLexicalBorrowScopesFlag =
llvm::StringSwitch<Optional<bool>>(A->getValue())
.Case("true", true)
.Case("false", false)
.Default(None);
}
Optional<bool> enableLexicalLifetimesFlag;
if (Arg *A = Args.getLastArg(OPT_enable_lexical_lifetimes)) {
enableLexicalLifetimesFlag =
llvm::StringSwitch<Optional<bool>>(A->getValue())
.Case("true", true)
.Case("false", false)
.Default(None);
}
if (Args.getLastArg(OPT_enable_lexical_lifetimes_noArg)) {
if (!enableLexicalLifetimesFlag.getValueOr(true)) {
// Error if lexical lifetimes have been disabled via the meta-var form
// and enabled via the flag.
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
"enable-lexical-lifetimes",
"enable-lexical-lifetimes=false");
return true;
} else {
enableLexicalLifetimesFlag = true;
}
}

if (enableLexicalLifetimesFlag.getValueOr(false) &&
!enableLexicalBorrowScopesFlag.getValueOr(true)) {
// Error if lexical lifetimes have been enabled but lexical borrow scopes--
// on which they are dependent--have been disabled.
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
"enable-lexical-lifetimes=true",
"enable-lexical-borrow-scopes=false");
return true;
} else {
if (enableExperimentalLexicalLifetimes)
}

if (Args.hasArg(OPT_enable_experimental_move_only) &&
(enableLexicalBorrowScopesFlag.getValueOr(false))) {
// Error if move-only is enabled and lexical borrow scopes--on which it
// depends--has been disabled.
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
"enable-experimental-move-only",
"enable-lexical-borrow-scopes=false");
return true;
}

if (Args.hasArg(OPT_enable_experimental_move_only) &&
(enableLexicalLifetimesFlag.getValueOr(false))) {
// Error if move-only is enabled and lexical lifetimes--on which it
// depends--has been disabled.
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination,
"enable-experimental-move-only",
"enable-lexical-lifetimes=false");
return true;
}

// -enable-copy-propagation implies -enable-lexical-lifetimes unless
// otherwise specified.
if (Args.hasArg(OPT_enable_copy_propagation))
Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate;

// If move-only is enabled, always enable lexical lifetime as well. Move-only
// depends on lexical lifetimes.
if (Args.hasArg(OPT_enable_experimental_move_only))
Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate;

if (enableLexicalLifetimesFlag) {
if (*enableLexicalLifetimesFlag) {
Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate;
if (Args.hasArg(OPT_disable_lexical_lifetimes))
} else {
Opts.LexicalLifetimes = LexicalLifetimesOption::Early;
}
}
if (enableLexicalBorrowScopesFlag) {
if (*enableLexicalBorrowScopesFlag) {
Opts.LexicalLifetimes = LexicalLifetimesOption::Early;
} else {
Opts.LexicalLifetimes = LexicalLifetimesOption::Off;
}
}

Opts.EnableCopyPropagation |= Args.hasArg(OPT_enable_copy_propagation);
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ broadenSingleElementStores(StoreInst *storeInst,
/// borrow scope--copy/destroy is insufficient by itself.
///
/// FIXME: Technically this should be guarded by a compiler flag like
/// -enable-copy-propagation until SILGen protects scoped variables by borrow
/// scopes.
/// -enable-copy-propagation until SILGen protects scoped variables by
/// borrow scopes.
static SILBasicBlock::iterator
eliminateSimpleCopies(CopyValueInst *cvi, CanonicalizeInstruction &pass) {
auto next = std::next(cvi->getIterator());
Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/validation-test/array.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes)
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)

// REQUIRES: executable_test

Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/validation-test/optional.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes)
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)

// REQUIRES: executable_test

Expand Down
4 changes: 2 additions & 2 deletions test/AutoDiff/validation-test/optional_property.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes)
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -disable-lexical-lifetimes -module-name null -o /dev/null 2>&1 %s | %FileCheck %s
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -enable-lexical-borrow-scopes=false -module-name null -o /dev/null 2>&1 %s | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: asserts
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/Runtime/async_properties_actor.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -enable-copy-propagation -Xfrontend -disable-availability-checking %import-libdispatch) | %FileCheck %s
// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-availability-checking %import-libdispatch) | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/if-branchlocations.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend %s -emit-sil -disable-copy-propagation -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-NCP
// RUN: %target-swift-frontend %s -emit-sil -enable-copy-propagation -disable-lexical-lifetimes -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-CP
// 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

class NSURL {}

Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/linetable-do.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle %s -emit-ir -g -o - | %FileCheck %s
// 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
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-copy-propagation -disable-lexical-lifetimes %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-CP %s
// 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
import StdlibUnittest

class Obj {}
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/debug_poison.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s -DINT=i%target-ptrsize

// Test debug_value [poison] emission

Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/unmanaged_objc_throw_func.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir -enable-copy-propagation %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -enable-copy-propagation -enable-lexical-lifetimes=false %s | %FileCheck %s
// REQUIRES: objc_interop
// REQUIRES: optimized_stdlib

Expand Down
4 changes: 2 additions & 2 deletions test/Interpreter/builtin_bridge_object.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -disable-lexical-lifetimes) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG
// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -disable-lexical-lifetimes) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s
// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-borrow-scopes=false) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG
// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-borrow-scopes=false) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s

// REQUIRES: executable_test
// REQUIRES: objc_interop
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/OSLogFullOptTest.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -enable-copy-propagation -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -enable-copy-propagation -enable-lexical-lifetimes=false -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
//
// REQUIRES: VENDOR=apple
// REQUIRES: swift_stdlib_no_asserts
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/allocbox_to_stack.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -disable-lexical-lifetimes | %FileCheck %s
// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -enable-lexical-borrow-scopes=false | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/allocbox_to_stack_ownership.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -disable-lexical-lifetimes | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-lexical-borrow-scopes=false | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/assemblyvision_remark/basic.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -disable-lexical-lifetimes
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -enable-lexical-borrow-scopes=false
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts

public class Klass {
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/assemblyvision_remark/basic_yaml.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -disable-lexical-lifetimes
// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -enable-lexical-borrow-scopes=false

// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml -Xfrontend -disable-lexical-lifetimes %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s
// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml -Xfrontend -enable-lexical-borrow-scopes=false %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s

// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/diagnose_lifetime_issues.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-sil -disable-lexical-lifetimes -enable-copy-propagation %s -o /dev/null -verify
// RUN: %target-swift-frontend -emit-sil -enable-lexical-borrow-scopes=false -enable-copy-propagation %s -o /dev/null -verify

class Delegate {
func foo() { }
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/diagnose_lifetime_issues_objc.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-sil %s -disable-lexical-lifetimes -enable-copy-propagation -o /dev/null -verify
// RUN: %target-swift-frontend -emit-sil %s -enable-lexical-borrow-scopes=false -enable-copy-propagation -o /dev/null -verify
// REQUIRES: objc_interop

import Foundation
Expand Down
3 changes: 2 additions & 1 deletion test/SILOptimizer/opaque_values_mandatory.sil
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// RUN: %target-sil-opt -diagnostics -enable-sil-opaque-values %s | \
// RUN: %target-sil-opt -Onone-performance -enable-sil-verify-all \
// RUN: -enable-sil-opaque-values -emit-sorted-sil \
// RUN: -enable-ossa-modules -enable-copy-propagation | \
// RUN: -enable-ossa-modules -enable-copy-propagation \
// RUN: -enable-lexical-borrow-scopes | \
// RUN: %FileCheck %s

import Builtin
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/outliner.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s
// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s
// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s
// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: optimized_stdlib
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/sil_combine_apply_ossa.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-ossa-modules -enable-copy-propagation -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s
// RUN: %target-sil-opt -enable-ossa-modules -enable-copy-propagation -enable-lexical-lifetimes=false -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s

import Swift
import Builtin
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/sil_combine_ossa.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -generic-specializer | %FileCheck %s --check-prefix=CHECK_FORWARDING_OWNERSHIP_KIND
//
// FIXME: check copy-propagation output instead once it is the default mode
// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -enable-copy-propagation | %FileCheck %s --check-prefix=CHECK_COPYPROP
// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -enable-copy-propagation -enable-lexical-lifetimes=false | %FileCheck %s --check-prefix=CHECK_COPYPROP

// Declare this SIL to be canonical because some tests break raw SIL
// conventions. e.g. address-type block args. -enforce-exclusivity=none is also
Expand Down
Loading