The -mcpu= option accepts only a handful of string values.
Using enums instead of strings to handle the accepted values removes the
need to have specific processing of the strings in the backend, and
simplifies any comparisons which need to be performed on the value.
It also allows the default value to have semantic equivalence to a user
set value, whilst retaining the ability to differentiate between them.
Practically, this allows a user set -mcpu= value to override the the ISA set by
-mmcu, whilst the default -mcpu= value can still have an explicit meaning.
gcc/ChangeLog:
* common/config/msp430/msp430-common.c (msp430_handle_option): Remove
OPT_mcpu_ handling.
Set target_cpu value to new enum values when parsing certain -mmcu=
values.
* config/msp430/msp430-opts.h (enum msp430_cpu_types): New.
* config/msp430/msp430.c (msp430_option_override): Handle new
target_cpu enum values.
Set target_cpu using extracted value for given MCU when -mcpu=
option is not passed by the user.
* config/msp430/msp430.opt: Handle -mcpu= values using enums.
gcc/testsuite/ChangeLog:
* gcc.target/msp430/mcpu-is-430.c: New test.
* gcc.target/msp430/mcpu-is-430x.c: New test.
* gcc.target/msp430/mcpu-is-430xv2.c: New test.
#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. */
{
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
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;
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,
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)
{
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",
"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
{
{
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"
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,
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.
--- /dev/null
+/* { 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
--- /dev/null
+/* { 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
+
--- /dev/null
+/* { 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
+