Add support for -Oplayground and add some sanity tests for it.

Right now this is just like -Onone. We will add further optimizations as
needed.

<rdar://problem/19328293>

Swift SVN r25377
This commit is contained in:
Michael Gottesman
2015-02-18 22:30:26 +00:00
parent 4cf775f37a
commit a598b46fc1
4 changed files with 65 additions and 0 deletions

View File

@@ -247,6 +247,10 @@ def O : Flag<["-"], "O">, Group<O_Group>, Flags<[FrontendOption]>,
def Ounchecked : Flag<["-"], "Ounchecked">, Group<O_Group>,
Flags<[FrontendOption]>,
HelpText<"Compile with optimizations and remove runtime safety checks">;
def Oplayground : Flag<["-"], "Oplayground">, Group<O_Group>,
Flags<[FrontendOption]>,
HelpText<"Compile with optimizations appropriate for a playground">;
// Debug info options

View File

@@ -785,6 +785,9 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
// Removal of cond_fail (overflow on binary operations).
Opts.RemoveRuntimeAsserts = true;
Opts.AssertConfig = SILOptions::Fast;
} else if (A->getOption().matches(OPT_Oplayground)) {
// For now -Oplayground is equivalent to -Onone.
IRGenOpts.Optimize = false;
} else {
assert(A->getOption().matches(OPT_O));
IRGenOpts.Optimize = true;

View File

@@ -1,6 +1,7 @@
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Onone -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=DEBUG
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -O -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=RELEASE
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Ounchecked -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=UNCHECKED
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Oplayground -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=PLAYGROUND
// REQUIRES: optimized_stdlib
// REQUIRES: swift_stdlib_asserts
@@ -34,6 +35,12 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: "assertion failed"
// DEBUG: cond_fail
// In playground mode keep user asserts and runtime checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions11test_assertfT_FT1xSi1ySi_Si
// PLAYGROUND: "x smaller than y"
// PLAYGROUND: "assertion failed"
// PLAYGROUND: cond_fail
// In release mode remove user asserts and keep runtime checks.
// RELEASE-LABEL: _TF19OptimizationOptions11test_assertfT_FT1xSi1ySi_Si
// RELEASE-NOT: "x smaller than y"
@@ -54,6 +61,13 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// DEBUG: unreachable
// In playground mode keep verbose fatal errors.
// PLAYGROUND-LABEL: _TF19OptimizationOptions10test_fatalFTSiSi_Si
// PLAYGROUND-DAG: "Human nature ..."
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// In release mode keep succinct fatal errors (trap).
// RELEASE-LABEL: _TF19OptimizationOptions10test_fatalFTSiSi_Si
// RELEASE-NOT: "Human nature ..."
@@ -78,6 +92,14 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: unreachable
// DEBUG: return
// In playground mode keep verbose library precondition checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions23test_precondition_checkFTSiSi_Si
// PLAYGROUND-DAG: "fatal error"
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// PLAYGROUND: return
// In release mode keep succinct library precondition checks (trap).
// RELEASE-LABEL: _TF19OptimizationOptions23test_precondition_checkFTSiSi_Si
// RELEASE-NOT: "fatal error"
@@ -101,6 +123,13 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// DEBUG: unreachable
// In playground mode keep verbose partial safety checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions25test_partial_safety_checkFTSiSi_Si
// PLAYGROUND-DAG: "fatal error"
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// In release mode remove partial safety checks.
// RELEASE-LABEL: _TF19OptimizationOptions25test_partial_safety_checkFTSiSi_Si
// RELEASE-NOT: "fatal error"

View File

@@ -1,6 +1,7 @@
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Onone -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=DEBUG
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -O -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=RELEASE
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Ounchecked -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=UNCHECKED
// RUN: %target-swift-frontend -module-name OptimizationOptions -disable-func-sig-opts -Oplayground -emit-sil -primary-file %s 2>&1 | FileCheck %s --check-prefix=PLAYGROUND
// REQUIRES: optimized_stdlib
// REQUIRES: swift_stdlib_asserts
@@ -34,6 +35,12 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: "assertion failed"
// DEBUG: cond_fail
// In playground mode keep user asserts and runtime checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions11test_assertfT_FT1xSi1ySi_Si
// PLAYGROUND: "x smaller than y"
// PLAYGROUND: "assertion failed"
// PLAYGROUND: cond_fail
// In release mode remove user asserts and keep runtime checks.
// RELEASE-LABEL: _TF19OptimizationOptions11test_assertfT_FT1xSi1ySi_Si
// RELEASE-NOT: "x smaller than y"
@@ -54,6 +61,13 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// DEBUG: unreachable
// In playground mode keep verbose fatal errors.
// PLAYGROUND-LABEL: _TF19OptimizationOptions10test_fatalFTSiSi_Si
// PLAYGROUND-DAG: "Human nature ..."
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TTOS_nndd__TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// In release mode keep succinct fatal errors (trap).
// RELEASE-LABEL: _TF19OptimizationOptions10test_fatalFTSiSi_Si
// RELEASE-NOT: "Human nature ..."
@@ -78,6 +92,14 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: unreachable
// DEBUG: return
// In playground mode keep verbose library precondition checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions23test_precondition_checkFTSiSi_Si
// PLAYGROUND-DAG: "fatal error"
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TTOS_nndd__TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// PLAYGROUND: return
// In release mode keep succinct library precondition checks (trap).
// RELEASE-LABEL: _TF19OptimizationOptions23test_precondition_checkFTSiSi_Si
// RELEASE-NOT: "fatal error"
@@ -101,6 +123,13 @@ func test_partial_safety_check(x: Int, y: Int) -> Int {
// DEBUG: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// DEBUG: unreachable
// In playground mode keep verbose partial safety checks.
// PLAYGROUND-LABEL: _TF19OptimizationOptions25test_partial_safety_checkFTSiSi_Si
// PLAYGROUND-DAG: "fatal error"
// PLAYGROUND-DAG: %[[FATAL_ERROR:.+]] = function_ref @_TTOS_nndd__TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_
// PLAYGROUND: apply %[[FATAL_ERROR]]{{.*}} @noreturn
// PLAYGROUND: unreachable
// In release mode remove partial safety checks.
// RELEASE-LABEL: _TF19OptimizationOptions25test_partial_safety_checkFTSiSi_Si
// RELEASE-NOT: "fatal error"