]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
MSP430: Use enums to handle -mcpu= values
authorJozef Lawrynowicz <jozef.l@mittosystems.com>
Tue, 8 Sep 2020 09:10:17 +0000 (10:10 +0100)
committerJozef Lawrynowicz <jozef.l@mittosystems.com>
Tue, 8 Sep 2020 09:12:25 +0000 (10:12 +0100)
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.

gcc/common/config/msp430/msp430-common.c
gcc/config/msp430/msp430-opts.h
gcc/config/msp430/msp430.c
gcc/config/msp430/msp430.opt
gcc/testsuite/gcc.target/msp430/mcpu-is-430.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/mcpu-is-430x.c [new file with mode: 0644]
gcc/testsuite/gcc.target/msp430/mcpu-is-430xv2.c [new file with mode: 0644]

index 0e261c4001580eeb4358777262e2a0ae09dd27f9..65be3194683143e7392e120cfff5c8719c5c4ac0 100644 (file)
@@ -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;
index 4d20830636703e7b486b631f9c7f5fc2b611492e..fa64677cb0b2a18596b170561a862d7f421bd10b 100644 (file)
@@ -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,
index 129b916715e1fdc4bcc85996d590bbed6b1754a9..d0557fe9058c953f5127eb1f7f8a79fa8a61e121 100644 (file)
@@ -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,
index 8134ca7ac95ca5c105b3d5c8dcade80fadbaf964..692e7dccc9ecfa430a0b15c125d3aa0c1740983a 100644 (file)
@@ -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 (file)
index 0000000..3139d2d
--- /dev/null
@@ -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 (file)
index 0000000..33100dc
--- /dev/null
@@ -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 (file)
index 0000000..7bc3da1
--- /dev/null
@@ -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
+