On Wed, Sep 30, 2020 at 03:56:32PM -0500, Segher Boessenkool wrote:
> On Wed, Sep 30, 2020 at 05:01:45PM +0930, Alan Modra wrote:
> >     * config/rs6000/linux64.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Don't
> >     set -mcmodel=small for -mno-minimal-toc when pcrel.
> 
> > -         SET_CMODEL (CMODEL_SMALL);                        \
> > +         if (TARGET_MINIMAL_TOC                            \
> > +             || !(TARGET_PCREL                             \
> > +                  || (PCREL_SUPPORTED_BY_OS                \
> > +                      && (rs6000_isa_flags_explicit        \
> > +                          & OPTION_MASK_PCREL) == 0)))     \
> > +           SET_CMODEL (CMODEL_SMALL);                      \
> 
> Please write this in a more readable way?  With some "else" statements,
> perhaps.
> 
> It is also fine to SET_CMODEL twice if that makes for simpler code.

Committed as per your suggestion.  I was looking at it again today
with the aim of converting this ugly macro to a function, and spotted
the duplication in freebsd64.h.  Which has some bit-rot.

Do you like the following?  rs6000_linux64_override_options is
functionally the same as what was in linux64.h.  I built various
configurations to test the change, powerpc64-linux, powerpc64le-linux
without any 32-bit targets enabled, powerpc64-freebsd12.0.

        * config/rs6000/freebsd64.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Use
        rs6000_linux64_override_options.
        * config/rs6000/linux64.h (SUBSUBTARGET_OVERRIDE_OPTIONS): Break
        out to..
        * config/rs6000/rs6000.c (rs6000_linux64_override_options): ..this,
        new function.  Tweak non-biarch test and clearing of
        profile_kernel to work with freebsd64.h.

diff --git a/gcc/config/rs6000/freebsd64.h b/gcc/config/rs6000/freebsd64.h
index c9913638ffb..6984ca5a107 100644
--- a/gcc/config/rs6000/freebsd64.h
+++ b/gcc/config/rs6000/freebsd64.h
@@ -78,65 +78,7 @@ extern int dot_symbols;
 
 #undef  SUBSUBTARGET_OVERRIDE_OPTIONS
 #define SUBSUBTARGET_OVERRIDE_OPTIONS                          \
-  do                                                           \
-    {                                                          \
-      if (!global_options_set.x_rs6000_alignment_flags)                \
-       rs6000_alignment_flags = MASK_ALIGN_NATURAL;            \
-      if (TARGET_64BIT)                                                \
-       {                                                       \
-         if (DEFAULT_ABI != ABI_AIX)                           \
-           {                                                   \
-             rs6000_current_abi = ABI_AIX;                     \
-             error (INVALID_64BIT, "call");                    \
-           }                                                   \
-         dot_symbols = !strcmp (rs6000_abi_name, "aixdesc");   \
-         if (rs6000_isa_flags & OPTION_MASK_RELOCATABLE)       \
-           {                                                   \
-             rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE;     \
-             error (INVALID_64BIT, "relocatable");             \
-           }                                                   \
-         if (ELFv2_ABI_CHECK)                                  \
-           {                                                   \
-             rs6000_current_abi = ABI_ELFv2;                   \
-             if (dot_symbols)                                  \
-               error ("%<-mcall-aixdesc%> incompatible with %<-mabi=elfv2%>"); 
\
-           }                                                   \
-         if (rs6000_isa_flags & OPTION_MASK_EABI)              \
-           {                                                   \
-             rs6000_isa_flags &= ~OPTION_MASK_EABI;            \
-             error (INVALID_64BIT, "eabi");                    \
-           }                                                   \
-         if (TARGET_PROTOTYPE)                                 \
-           {                                                   \
-             target_prototype = 0;                             \
-             error (INVALID_64BIT, "prototype");               \
-           }                                                   \
-         if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) == 0)  \
-           {                                                   \
-             rs6000_isa_flags |= OPTION_MASK_POWERPC64;        \
-             error ("%<-m64%> requires a PowerPC64 cpu");              \
-           }                                                   \
-          if ((rs6000_isa_flags_explicit                       \
-               & OPTION_MASK_MINIMAL_TOC) != 0)                \
-           {                                                   \
-             if (global_options_set.x_rs6000_current_cmodel    \
-                 && rs6000_current_cmodel != CMODEL_SMALL)     \
-               error ("%<-mcmodel%> incompatible with other toc options"); \
-             SET_CMODEL (CMODEL_SMALL);                        \
-           }                                                   \
-         else                                                  \
-           {                                                   \
-             if (!global_options_set.x_rs6000_current_cmodel)  \
-               SET_CMODEL (CMODEL_MEDIUM);                     \
-             if (rs6000_current_cmodel != CMODEL_SMALL)        \
-               {                                               \
-                 TARGET_NO_FP_IN_TOC = 0;                      \
-                 TARGET_NO_SUM_IN_TOC = 0;                     \
-               }                                               \
-           }                                                   \
-       }                                                       \
-    }                                                          \
-  while (0)
+  do rs6000_linux64_override_options (); while (0)
 
 #undef ASM_SPEC
 #undef LINK_OS_FREEBSD_SPEC
diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
index 5c9f8e3d7af..73b6c01874c 100644
--- a/gcc/config/rs6000/linux64.h
+++ b/gcc/config/rs6000/linux64.h
@@ -96,99 +96,7 @@ extern int dot_symbols;
 
 #undef SUBSUBTARGET_OVERRIDE_OPTIONS
 #define        SUBSUBTARGET_OVERRIDE_OPTIONS                           \
-  do                                                           \
-    {                                                          \
-      if (!global_options_set.x_rs6000_alignment_flags)                \
-       rs6000_alignment_flags = MASK_ALIGN_NATURAL;            \
-      if (rs6000_isa_flags & OPTION_MASK_64BIT)                        \
-       {                                                       \
-         if (DEFAULT_ABI != ABI_AIX)                           \
-           {                                                   \
-             rs6000_current_abi = ABI_AIX;                     \
-             error (INVALID_64BIT, "call");                    \
-           }                                                   \
-         dot_symbols = !strcmp (rs6000_abi_name, "aixdesc");   \
-         if (ELFv2_ABI_CHECK)                                  \
-           {                                                   \
-             rs6000_current_abi = ABI_ELFv2;                   \
-             if (dot_symbols)                                  \
-               error ("%<-mcall-aixdesc%> incompatible with %<-mabi=elfv2%>"); 
\
-           }                                                   \
-         if (rs6000_isa_flags & OPTION_MASK_RELOCATABLE)       \
-           {                                                   \
-             rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE;     \
-             error (INVALID_64BIT, "relocatable");             \
-           }                                                   \
-         if (rs6000_isa_flags & OPTION_MASK_EABI)              \
-           {                                                   \
-             rs6000_isa_flags &= ~OPTION_MASK_EABI;            \
-             error (INVALID_64BIT, "eabi");                    \
-           }                                                   \
-         if (TARGET_PROTOTYPE)                                 \
-           {                                                   \
-             target_prototype = 0;                             \
-             error (INVALID_64BIT, "prototype");               \
-           }                                                   \
-         if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) == 0)  \
-           {                                                   \
-             rs6000_isa_flags |= OPTION_MASK_POWERPC64;        \
-             error ("%<-m64%> requires a PowerPC64 cpu");      \
-           }                                                   \
-         if (!global_options_set.x_rs6000_current_cmodel)      \
-           SET_CMODEL (CMODEL_MEDIUM);                         \
-         if ((rs6000_isa_flags_explicit                        \
-              & OPTION_MASK_MINIMAL_TOC) != 0)                 \
-           {                                                   \
-             if (global_options_set.x_rs6000_current_cmodel    \
-                 && rs6000_current_cmodel != CMODEL_SMALL)     \
-               error ("%<-mcmodel incompatible with other toc options%>"); \
-             if (TARGET_MINIMAL_TOC)                           \
-               SET_CMODEL (CMODEL_SMALL);                      \
-             else if (TARGET_PCREL                             \
-                      || (PCREL_SUPPORTED_BY_OS                \
-                          && (rs6000_isa_flags_explicit        \
-                              & OPTION_MASK_PCREL) == 0))      \
-               /* Ignore -mno-minimal-toc.  */                 \
-               ;                                               \
-             else                                              \
-               SET_CMODEL (CMODEL_SMALL);                      \
-           }                                                   \
-         else                                                  \
-           {                                                   \
-             if (rs6000_current_cmodel != CMODEL_SMALL)        \
-               {                                               \
-                 if (!global_options_set.x_TARGET_NO_FP_IN_TOC) \
-                   TARGET_NO_FP_IN_TOC                         \
-                     = rs6000_current_cmodel == CMODEL_MEDIUM; \
-                 if (!global_options_set.x_TARGET_NO_SUM_IN_TOC) \
-                   TARGET_NO_SUM_IN_TOC = 0;                   \
-               }                                               \
-           }                                                   \
-         if (TARGET_PLTSEQ && DEFAULT_ABI != ABI_ELFv2)        \
-           {                                                   \
-             if (global_options_set.x_rs6000_pltseq)           \
-               warning (0, "%qs unsupported for this ABI",     \
-                        "-mpltseq");                           \
-             rs6000_pltseq = false;                            \
-           }                                                   \
-       }                                                       \
-      else                                                     \
-       {                                                       \
-         if (!RS6000_BI_ARCH_P)                                \
-           error (INVALID_32BIT, "32");                        \
-         if (TARGET_PROFILE_KERNEL)                            \
-           {                                                   \
-             TARGET_PROFILE_KERNEL = 0;                        \
-             error (INVALID_32BIT, "profile-kernel");          \
-           }                                                   \
-         if (global_options_set.x_rs6000_current_cmodel)       \
-           {                                                   \
-             SET_CMODEL (CMODEL_SMALL);                        \
-             error (INVALID_32BIT, "cmodel");                  \
-           }                                                   \
-       }                                                       \
-    }                                                          \
-  while (0)
+  do rs6000_linux64_override_options (); while (0)
 
 #undef ASM_SPEC
 #undef LINK_OS_LINUX_SPEC
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index d0924d59a65..48f3cdec440 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -3451,6 +3451,102 @@ rs6000_override_options_after_change (void)
     flag_cunroll_grow_size = flag_peel_loops || optimize >= 3;
 }
 
+#ifdef TARGET_USES_LINUX64_OPT
+static void
+rs6000_linux64_override_options ()
+{
+  if (!global_options_set.x_rs6000_alignment_flags)
+    rs6000_alignment_flags = MASK_ALIGN_NATURAL;
+  if (rs6000_isa_flags & OPTION_MASK_64BIT)
+    {
+      if (DEFAULT_ABI != ABI_AIX)
+       {
+         rs6000_current_abi = ABI_AIX;
+         error (INVALID_64BIT, "call");
+       }
+      dot_symbols = !strcmp (rs6000_abi_name, "aixdesc");
+      if (ELFv2_ABI_CHECK)
+       {
+         rs6000_current_abi = ABI_ELFv2;
+         if (dot_symbols)
+           error ("%<-mcall-aixdesc%> incompatible with %<-mabi=elfv2%>");
+       }
+      if (rs6000_isa_flags & OPTION_MASK_RELOCATABLE)
+       {
+         rs6000_isa_flags &= ~OPTION_MASK_RELOCATABLE;
+         error (INVALID_64BIT, "relocatable");
+       }
+      if (rs6000_isa_flags & OPTION_MASK_EABI)
+       {
+         rs6000_isa_flags &= ~OPTION_MASK_EABI;
+         error (INVALID_64BIT, "eabi");
+       }
+      if (TARGET_PROTOTYPE)
+       {
+         target_prototype = 0;
+         error (INVALID_64BIT, "prototype");
+       }
+      if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) == 0)
+       {
+         rs6000_isa_flags |= OPTION_MASK_POWERPC64;
+         error ("%<-m64%> requires a PowerPC64 cpu");
+       }
+      if (!global_options_set.x_rs6000_current_cmodel)
+       SET_CMODEL (CMODEL_MEDIUM);
+      if ((rs6000_isa_flags_explicit
+          & OPTION_MASK_MINIMAL_TOC) != 0)
+       {
+         if (global_options_set.x_rs6000_current_cmodel
+             && rs6000_current_cmodel != CMODEL_SMALL)
+           error ("%<-mcmodel incompatible with other toc options%>");
+         if (TARGET_MINIMAL_TOC)
+           SET_CMODEL (CMODEL_SMALL);
+         else if (TARGET_PCREL
+                  || (PCREL_SUPPORTED_BY_OS
+                      && (rs6000_isa_flags_explicit
+                          & OPTION_MASK_PCREL) == 0))
+           /* Ignore -mno-minimal-toc.  */
+           ;
+         else
+           SET_CMODEL (CMODEL_SMALL);
+       }
+      else
+       {
+         if (rs6000_current_cmodel != CMODEL_SMALL)
+           {
+             if (!global_options_set.x_TARGET_NO_FP_IN_TOC)
+               TARGET_NO_FP_IN_TOC
+                 = rs6000_current_cmodel == CMODEL_MEDIUM;
+             if (!global_options_set.x_TARGET_NO_SUM_IN_TOC)
+               TARGET_NO_SUM_IN_TOC = 0;
+           }
+       }
+      if (TARGET_PLTSEQ && DEFAULT_ABI != ABI_ELFv2)
+       {
+         if (global_options_set.x_rs6000_pltseq)
+           warning (0, "%qs unsupported for this ABI",
+                    "-mpltseq");
+         rs6000_pltseq = false;
+       }
+    }
+  else if (TARGET_64BIT)
+    error (INVALID_32BIT, "32");
+  else
+    {
+      if (TARGET_PROFILE_KERNEL)
+       {
+         profile_kernel = 0;
+         error (INVALID_32BIT, "profile-kernel");
+       }
+      if (global_options_set.x_rs6000_current_cmodel)
+       {
+         SET_CMODEL (CMODEL_SMALL);
+         error (INVALID_32BIT, "cmodel");
+       }
+    }
+}
+#endif
+
 /* Override command line options.
 
    Combine build-specific configuration information with options


-- 
Alan Modra
Australia Development Lab, IBM

Reply via email to