@@ -1455,25 +1455,131 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
14551455 // -Ounchecked might also set removal of runtime asserts (cond_fail).
14561456 Opts.RemoveRuntimeAsserts |= Args.hasArg (OPT_RemoveRuntimeAsserts);
14571457
1458- // If experimental move only is enabled, always enable lexical lifetime as
1459- // well. Move only depends on lexical lifetimes.
1460- bool enableExperimentalLexicalLifetimes =
1461- Args.hasArg (OPT_enable_lexical_lifetimes) ||
1462- Args.hasArg (OPT_enable_experimental_move_only);
1463- // Error if both experimental lexical lifetimes and disable lexical lifetimes
1464- // are both set.
1465- if (enableExperimentalLexicalLifetimes &&
1466- Args.hasArg (OPT_disable_lexical_lifetimes)) {
1458+ Optional<CopyPropagationOption> specifiedCopyPropagationOption;
1459+ if (Arg *A = Args.getLastArg (OPT_copy_propagation_state_EQ)) {
1460+ specifiedCopyPropagationOption =
1461+ llvm::StringSwitch<Optional<CopyPropagationOption>>(A->getValue ())
1462+ .Case (" true" , CopyPropagationOption::On)
1463+ .Case (" false" , CopyPropagationOption::Off)
1464+ .Case (" requested-passes-only" ,
1465+ CopyPropagationOption::RequestedPassesOnly)
1466+ .Default (None);
1467+ }
1468+ if (Args.hasArg (OPT_enable_copy_propagation)) {
1469+ if (specifiedCopyPropagationOption) {
1470+ if (*specifiedCopyPropagationOption == CopyPropagationOption::Off) {
1471+ // Error if copy propagation has been set to ::Off via the meta-var form
1472+ // and enabled via the flag.
1473+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1474+ " enable-copy-propagation" ,
1475+ " enable-copy-propagation=false" );
1476+ return true ;
1477+ } else if (*specifiedCopyPropagationOption ==
1478+ CopyPropagationOption::RequestedPassesOnly) {
1479+ // Error if copy propagation has been set to ::RequestedPassesOnly via
1480+ // the meta-var form and enabled via the flag.
1481+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1482+ " enable-copy-propagation" ,
1483+ " enable-copy-propagation=requested-passes-only" );
1484+ return true ;
1485+ }
1486+ } else {
1487+ specifiedCopyPropagationOption = CopyPropagationOption::On;
1488+ }
1489+ }
1490+ if (specifiedCopyPropagationOption) {
1491+ Opts.CopyPropagation = *specifiedCopyPropagationOption;
1492+ }
1493+
1494+ Optional<bool > enableLexicalBorrowScopesFlag;
1495+ if (Arg *A = Args.getLastArg (OPT_enable_lexical_borrow_scopes)) {
1496+ enableLexicalBorrowScopesFlag =
1497+ llvm::StringSwitch<Optional<bool >>(A->getValue ())
1498+ .Case (" true" , true )
1499+ .Case (" false" , false )
1500+ .Default (None);
1501+ }
1502+ Optional<bool > enableLexicalLifetimesFlag;
1503+ if (Arg *A = Args.getLastArg (OPT_enable_lexical_lifetimes)) {
1504+ enableLexicalLifetimesFlag =
1505+ llvm::StringSwitch<Optional<bool >>(A->getValue ())
1506+ .Case (" true" , true )
1507+ .Case (" false" , false )
1508+ .Default (None);
1509+ }
1510+ if (Args.getLastArg (OPT_enable_lexical_lifetimes_noArg)) {
1511+ if (!enableLexicalLifetimesFlag.getValueOr (true )) {
1512+ // Error if lexical lifetimes have been disabled via the meta-var form
1513+ // and enabled via the flag.
1514+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1515+ " enable-lexical-lifetimes" ,
1516+ " enable-lexical-lifetimes=false" );
1517+ return true ;
1518+ } else {
1519+ enableLexicalLifetimesFlag = true ;
1520+ }
1521+ }
1522+
1523+ if (enableLexicalLifetimesFlag.getValueOr (false ) &&
1524+ !enableLexicalBorrowScopesFlag.getValueOr (true )) {
1525+ // Error if lexical lifetimes have been enabled but lexical borrow scopes--
1526+ // on which they are dependent--have been disabled.
1527+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1528+ " enable-lexical-lifetimes=true" ,
1529+ " enable-lexical-borrow-scopes=false" );
14671530 return true ;
1468- } else {
1469- if (enableExperimentalLexicalLifetimes)
1470- Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate;
1471- if (Args.hasArg (OPT_disable_lexical_lifetimes))
1531+ }
1532+
1533+ if (Args.hasArg (OPT_enable_experimental_move_only) &&
1534+ !enableLexicalBorrowScopesFlag.getValueOr (true )) {
1535+ // Error if move-only is enabled and lexical borrow scopes--on which it
1536+ // depends--has been disabled.
1537+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1538+ " enable-experimental-move-only" ,
1539+ " enable-lexical-borrow-scopes=false" );
1540+ return true ;
1541+ }
1542+
1543+ if (Args.hasArg (OPT_enable_experimental_move_only) &&
1544+ !enableLexicalLifetimesFlag.getValueOr (true )) {
1545+ // Error if move-only is enabled and lexical lifetimes--on which it
1546+ // depends--has been disabled.
1547+ Diags.diagnose (SourceLoc (), diag::error_invalid_arg_combination,
1548+ " enable-experimental-move-only" ,
1549+ " enable-lexical-lifetimes=false" );
1550+ return true ;
1551+ }
1552+
1553+ // Unless overridden below, enabling copy propagation means enabling lexical
1554+ // lifetimes.
1555+ if (Opts.CopyPropagation == CopyPropagationOption::On)
1556+ Opts.LexicalLifetimes = LexicalLifetimesOption::On;
1557+
1558+ // Unless overridden below, disable copy propagation means disabling lexical
1559+ // lifetimes.
1560+ if (Opts.CopyPropagation == CopyPropagationOption::Off)
1561+ Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
1562+
1563+ // If move-only is enabled, always enable lexical lifetime as well. Move-only
1564+ // depends on lexical lifetimes.
1565+ if (Args.hasArg (OPT_enable_experimental_move_only))
1566+ Opts.LexicalLifetimes = LexicalLifetimesOption::On;
1567+
1568+ if (enableLexicalLifetimesFlag) {
1569+ if (*enableLexicalLifetimesFlag) {
1570+ Opts.LexicalLifetimes = LexicalLifetimesOption::On;
1571+ } else {
1572+ Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
1573+ }
1574+ }
1575+ if (enableLexicalBorrowScopesFlag) {
1576+ if (*enableLexicalBorrowScopesFlag) {
1577+ Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
1578+ } else {
14721579 Opts.LexicalLifetimes = LexicalLifetimesOption::Off;
1580+ }
14731581 }
14741582
1475- Opts.EnableCopyPropagation |= Args.hasArg (OPT_enable_copy_propagation);
1476- Opts.DisableCopyPropagation |= Args.hasArg (OPT_disable_copy_propagation);
14771583 Opts.EnableARCOptimizations &= !Args.hasArg (OPT_disable_arc_opts);
14781584 Opts.EnableOSSAModules |= Args.hasArg (OPT_enable_ossa_modules);
14791585 Opts.EnableOSSAOptimizations &= !Args.hasArg (OPT_disable_ossa_opts);
0 commit comments