diff --git a/gcc/common/config/msp430/msp430-common.c b/gcc/common/config/msp430/msp430-common.c index 0e261c40015..65be3194683 100644 --- a/gcc/common/config/msp430/msp430-common.c +++ b/gcc/common/config/msp430/msp430-common.c @@ -27,7 +27,7 @@ #include "opts.h" #include "flags.h" -/* Check for generic -mcpu= and -mmcu= names here. If found then we +/* Check for generic -mmcu= names here. If found then we convert to a baseline cpu name. Otherwise we allow the option to be passed on to the backend where it can be checked more fully. */ @@ -39,26 +39,6 @@ msp430_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, { switch (decoded->opt_index) { - case OPT_mcpu_: - if (strcasecmp (decoded->arg, "msp430x") == 0 - || strcasecmp (decoded->arg, "msp430xv2") == 0 - || strcasecmp (decoded->arg, "430x") == 0 - || strcasecmp (decoded->arg, "430xv2") == 0) - { - target_cpu = "msp430x"; - } - else if (strcasecmp (decoded->arg, "msp430") == 0 - || strcasecmp (decoded->arg, "430") == 0) - { - target_cpu = "msp430"; - } - else - { - error ("unrecognized argument of %<-mcpu%>: %s", decoded->arg); - return false; - } - break; - case OPT_mmcu_: /* For backwards compatibility we recognise two generic MCU 430X names. However we want to be able to generate special C @@ -66,13 +46,13 @@ msp430_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, to NULL. */ if (strcasecmp (decoded->arg, "msp430") == 0) { - target_cpu = "msp430"; + target_cpu = MSP430_CPU_MSP430; target_mcu = NULL; } else if (strcasecmp (decoded->arg, "msp430x") == 0 || strcasecmp (decoded->arg, "msp430xv2") == 0) { - target_cpu = "msp430x"; + target_cpu = MSP430_CPU_MSP430X; target_mcu = NULL; } break; diff --git a/gcc/config/msp430/msp430-opts.h b/gcc/config/msp430/msp430-opts.h index 4d208306367..fa64677cb0b 100644 --- a/gcc/config/msp430/msp430-opts.h +++ b/gcc/config/msp430/msp430-opts.h @@ -29,6 +29,18 @@ enum msp430_hwmult_types MSP430_HWMULT_F5SERIES }; +enum msp430_cpu_types +{ + MSP430_CPU_MSP430, + MSP430_CPU_430, + MSP430_CPU_MSP430X_DEFAULT, /* The default setting, which will be overriden + by any other -mcpu= value. */ + MSP430_CPU_MSP430X, + MSP430_CPU_430X, + MSP430_CPU_MSP430XV2, + MSP430_CPU_430XV2 +}; + enum msp430_regions { MSP430_REGION_ANY, diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c index 129b916715e..d0557fe9058 100644 --- a/gcc/config/msp430/msp430.c +++ b/gcc/config/msp430/msp430.c @@ -160,15 +160,7 @@ msp430_option_override (void) init_machine_status = msp430_init_machine_status; - if (target_cpu) - { - /* gcc/common/config/msp430-common.c will have - already canonicalised the string in target_cpu. */ - if (strcasecmp (target_cpu, "msp430x") == 0) - msp430x = true; - else /* target_cpu == "msp430" - already handled by the front end. */ - msp430x = false; - } + msp430x = target_cpu >= MSP430_CPU_MSP430X_DEFAULT; if (target_mcu) { @@ -180,7 +172,7 @@ msp430_option_override (void) if (msp430_warn_mcu) { - if (target_cpu && msp430x != xisa) + if (target_cpu != MSP430_CPU_MSP430X_DEFAULT && msp430x != xisa) warning (0, "MCU %qs supports %s ISA but %<-mcpu%> option " "is set to %s", target_mcu, xisa ? "430X" : "430", @@ -212,7 +204,10 @@ msp430_option_override (void) "but %<-mhwmult%> is set to f5series", target_mcu, hwmult_name (extracted_mcu_data.hwmpy)); } - msp430x = xisa; + /* Only override the default setting with the extracted ISA value if + the user has not passed -mcpu=. */ + if (target_cpu == MSP430_CPU_MSP430X_DEFAULT) + msp430x = xisa; } else { @@ -220,7 +215,7 @@ msp430_option_override (void) { if (msp430_warn_mcu) { - if (target_cpu == NULL) + if (target_cpu == MSP430_CPU_MSP430X_DEFAULT) warning (0, "Unrecognized MCU name %qs, assuming that it is " "just a MSP430X with no hardware multiply.\n" @@ -237,7 +232,7 @@ msp430_option_override (void) msp430_hwmult_type = MSP430_HWMULT_NONE; } - else if (target_cpu == NULL) + else if (target_cpu == MSP430_CPU_MSP430X_DEFAULT) { if (msp430_warn_mcu) warning (0, diff --git a/gcc/config/msp430/msp430.opt b/gcc/config/msp430/msp430.opt index 8134ca7ac95..692e7dccc9e 100644 --- a/gcc/config/msp430/msp430.opt +++ b/gcc/config/msp430/msp430.opt @@ -23,9 +23,30 @@ Target Report Var(msp430_warn_devices_csv) Init(1) Warn if devices.csv is not found or there are problem parsing it (default: on). mcpu= -Target Report Joined RejectNegative Var(target_cpu) +Target Report Joined RejectNegative Var(target_cpu) ToLower Enum(msp430_cpu_types) Init(MSP430_CPU_MSP430X_DEFAULT) Specify the ISA to build for: msp430, msp430x, msp430xv2. +Enum +Name(msp430_cpu_types) Type(enum msp430_cpu_types) + +EnumValue +Enum(msp430_cpu_types) String(msp430) Value(MSP430_CPU_MSP430) Canonical + +EnumValue +Enum(msp430_cpu_types) String(430) Value(MSP430_CPU_MSP430) + +EnumValue +Enum(msp430_cpu_types) String(msp430x) Value(MSP430_CPU_MSP430X) Canonical + +EnumValue +Enum(msp430_cpu_types) String(430x) Value(MSP430_CPU_MSP430X) + +EnumValue +Enum(msp430_cpu_types) String(msp430xv2) Value(MSP430_CPU_MSP430XV2) Canonical + +EnumValue +Enum(msp430_cpu_types) String(430xv2) Value(MSP430_CPU_MSP430XV2) + mlarge Target Report Mask(LARGE) RejectNegative Select large model - 20-bit addresses/pointers. diff --git a/gcc/testsuite/gcc.target/msp430/mcpu-is-430.c b/gcc/testsuite/gcc.target/msp430/mcpu-is-430.c new file mode 100644 index 00000000000..3139d2d52b0 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/mcpu-is-430.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-mcpu=*" "-mmcu=*" "-mlarge" } { "" } } */ +/* { dg-options "-mcpu=430" } */ + +/* Verify that the alternate way of selecting the 430 ISA (i.e. with the + value "430" instead of "msp430") successfully selects the correct ISA. */ + +#ifdef __MSP430X__ +#error +#endif diff --git a/gcc/testsuite/gcc.target/msp430/mcpu-is-430x.c b/gcc/testsuite/gcc.target/msp430/mcpu-is-430x.c new file mode 100644 index 00000000000..33100dc6bbd --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/mcpu-is-430x.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-mcpu=*" "-mmcu=*" } { "" } } */ +/* { dg-options "-mcpu=430x" } */ + +/* Verify that the alternate way of selecting the 430X ISA (i.e. with the + value "430x" instead of "msp430x") successfully selects the correct + ISA. */ + +#ifndef __MSP430X__ +#error +#endif + diff --git a/gcc/testsuite/gcc.target/msp430/mcpu-is-430xv2.c b/gcc/testsuite/gcc.target/msp430/mcpu-is-430xv2.c new file mode 100644 index 00000000000..7bc3da1d2a4 --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/mcpu-is-430xv2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-mcpu=*" "-mmcu=*" } { "" } } */ +/* { dg-options "-mcpu=430XV2" } */ + +/* Verify that the alternate way of selecting the 430XV2 ISA (i.e. with the + value "430XV2" instead of "msp430xv2") successfully selects the correct + ISA. 430xv2 doesn't actually have any observable effect on codegen, so we + have to just test for 430X. */ + +#ifndef __MSP430X__ +#error +#endif +