Home | History | Annotate | Line # | Download | only in arm
      1  1.1  mrg /* Common hooks for ARM.
      2  1.1  mrg    Copyright (C) 1991-2022 Free Software Foundation, Inc.
      3  1.1  mrg 
      4  1.1  mrg    This file is part of GCC.
      5  1.1  mrg 
      6  1.1  mrg    GCC is free software; you can redistribute it and/or modify it
      7  1.1  mrg    under the terms of the GNU General Public License as published
      8  1.1  mrg    by the Free Software Foundation; either version 3, or (at your
      9  1.1  mrg    option) any later version.
     10  1.1  mrg 
     11  1.1  mrg    GCC is distributed in the hope that it will be useful, but WITHOUT
     12  1.1  mrg    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     13  1.1  mrg    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     14  1.1  mrg    License for more details.
     15  1.1  mrg 
     16  1.1  mrg    You should have received a copy of the GNU General Public License
     17  1.1  mrg    along with GCC; see the file COPYING3.  If not see
     18  1.1  mrg    <http://www.gnu.org/licenses/>.  */
     19  1.1  mrg 
     20  1.1  mrg #define INCLUDE_LIST
     21  1.1  mrg #define INCLUDE_VECTOR
     22  1.1  mrg #define INCLUDE_ALGORITHM
     23  1.1  mrg #include "config.h"
     24  1.1  mrg #include "system.h"
     25  1.1  mrg #include "coretypes.h"
     26  1.1  mrg #include "tm.h"
     27  1.1  mrg #include "memmodel.h"
     28  1.1  mrg #include "tm_p.h"
     29  1.1  mrg #include "common/common-target.h"
     30  1.1  mrg #include "common/common-target-def.h"
     31  1.1  mrg #include "opts.h"
     32  1.1  mrg #include "flags.h"
     33  1.1  mrg #include "sbitmap.h"
     34  1.1  mrg #include "diagnostic.h"
     35  1.1  mrg 
     36  1.1  mrg #include "configargs.h"
     37  1.1  mrg 
     38  1.1  mrg /* Set default optimization options.  */
     39  1.1  mrg static const struct default_options arm_option_optimization_table[] =
     40  1.1  mrg   {
     41  1.1  mrg     /* Enable section anchors by default at -O1 or higher.  */
     42  1.1  mrg     { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
     43  1.1  mrg     { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
     44  1.1  mrg     { OPT_LEVELS_NONE, 0, NULL, 0 }
     45  1.1  mrg   };
     46  1.1  mrg 
     47  1.1  mrg /* Implement TARGET_EXCEPT_UNWIND_INFO.  */
     48  1.1  mrg 
     49  1.1  mrg enum unwind_info_type
     50  1.1  mrg arm_except_unwind_info (struct gcc_options *opts)
     51  1.1  mrg {
     52  1.1  mrg   /* Honor the --enable-sjlj-exceptions configure switch.  */
     53  1.1  mrg #ifdef CONFIG_SJLJ_EXCEPTIONS
     54  1.1  mrg   if (CONFIG_SJLJ_EXCEPTIONS)
     55  1.1  mrg     return UI_SJLJ;
     56  1.1  mrg #endif
     57  1.1  mrg 
     58  1.1  mrg   if (ARM_DWARF_UNWIND_TABLES)
     59  1.1  mrg     return UI_DWARF2;
     60  1.1  mrg 
     61  1.1  mrg   /* If not using ARM EABI unwind tables... */
     62  1.1  mrg   if (ARM_UNWIND_INFO)
     63  1.1  mrg     {
     64  1.1  mrg       /* For simplicity elsewhere in this file, indicate that all unwind
     65  1.1  mrg 	 info is disabled if we're not emitting unwind tables.  */
     66  1.1  mrg       if (!opts->x_flag_exceptions && !opts->x_flag_unwind_tables)
     67  1.1  mrg 	return UI_NONE;
     68  1.1  mrg       else
     69  1.1  mrg 	return UI_TARGET;
     70  1.1  mrg     }
     71  1.1  mrg 
     72  1.1  mrg   /* ... honor target configurations requesting DWARF2 EH...  */
     73  1.1  mrg #ifdef DWARF2_UNWIND_INFO
     74  1.1  mrg   if (DWARF2_UNWIND_INFO)
     75  1.1  mrg     return UI_DWARF2;
     76  1.1  mrg #endif
     77  1.1  mrg 
     78  1.1  mrg   /* ... or fallback to sjlj exceptions for backwards compatibility.  */
     79  1.1  mrg   return UI_SJLJ;
     80  1.1  mrg }
     81  1.1  mrg 
     82  1.1  mrg #define ARM_CPU_NAME_LENGTH 20
     83  1.1  mrg 
     84  1.1  mrg /* Truncate NAME at the first '.' or '+' character seen, or return
     85  1.1  mrg    NAME unmodified.  */
     86  1.1  mrg 
     87  1.1  mrg const char *
     88  1.1  mrg arm_rewrite_selected_cpu (const char *name)
     89  1.1  mrg {
     90  1.1  mrg   static char output_buf[ARM_CPU_NAME_LENGTH + 1] = {0};
     91  1.1  mrg   char *arg_pos;
     92  1.1  mrg 
     93  1.1  mrg   strncpy (output_buf, name, ARM_CPU_NAME_LENGTH);
     94  1.1  mrg   output_buf[ARM_CPU_NAME_LENGTH] = 0;
     95  1.1  mrg 
     96  1.1  mrg   arg_pos = strchr (output_buf, '.');
     97  1.1  mrg 
     98  1.1  mrg   /* If we found a '.' truncate the entry at that point.  */
     99  1.1  mrg   if (arg_pos)
    100  1.1  mrg     *arg_pos = '\0';
    101  1.1  mrg 
    102  1.1  mrg   arg_pos = strchr (output_buf, '+');
    103  1.1  mrg 
    104  1.1  mrg   /* If we found a '+' truncate the entry at that point.  */
    105  1.1  mrg   if (arg_pos)
    106  1.1  mrg     *arg_pos = '\0';
    107  1.1  mrg 
    108  1.1  mrg   return output_buf;
    109  1.1  mrg }
    110  1.1  mrg 
    111  1.1  mrg /* Called by the driver to rewrite a name passed to the -mcpu
    112  1.1  mrg    argument in preparation to be passed to the assembler.  The
    113  1.1  mrg    names passed from the command line will be in ARGV, we want
    114  1.1  mrg    to use the right-most argument, which should be in
    115  1.1  mrg    ARGV[ARGC - 1].  ARGC should always be greater than 0.  */
    116  1.1  mrg 
    117  1.1  mrg const char *
    118  1.1  mrg arm_rewrite_mcpu (int argc, const char **argv)
    119  1.1  mrg {
    120  1.1  mrg   gcc_assert (argc);
    121  1.1  mrg 
    122  1.1  mrg #ifdef HAVE_GAS_ARM_EXTENDED_ARCH
    123  1.1  mrg   return argv[argc - 1];
    124  1.1  mrg #else
    125  1.1  mrg   return arm_rewrite_selected_cpu (argv[argc - 1]);
    126  1.1  mrg #endif
    127  1.1  mrg }
    128  1.1  mrg 
    129  1.1  mrg /* Comparator for arm_rewrite_selected_arch.  Compare the two arch extension
    130  1.1  mrg    strings FIRST and SECOND and return TRUE if FIRST is less than SECOND
    131  1.1  mrg    alphabetically.  */
    132  1.1  mrg 
    133  1.1  mrg static bool
    134  1.1  mrg compare_opt_names (const char *first, const char *second)
    135  1.1  mrg {
    136  1.1  mrg   return strcmp (first, second) <= 0;
    137  1.1  mrg }
    138  1.1  mrg 
    139  1.1  mrg /* Rewrite the architecture string for passing to the assembler.
    140  1.1  mrg    Although the syntax is similar we cannot assume that it supports
    141  1.1  mrg    the newer FP related options.  So strip any option that only
    142  1.1  mrg    defines features in the standard -mfpu options out.  We'll generate
    143  1.1  mrg    a suitable -mfpu option elsewhere to carry that information.  NAME
    144  1.1  mrg    should already have been canonicalized, so we do not expect to
    145  1.1  mrg    encounter +no.. options that remove features.  A final problem is
    146  1.1  mrg    that the assembler expects the feature extensions to be listed
    147  1.1  mrg    alphabetically, so we build a list of required options and then
    148  1.1  mrg    sort them into canonical order in the resulting string.  */
    149  1.1  mrg const char *
    150  1.1  mrg arm_rewrite_selected_arch (const char *name)
    151  1.1  mrg {
    152  1.1  mrg   /* The result we return needs to be semi persistent, so handle being
    153  1.1  mrg      re-invoked.  */
    154  1.1  mrg   static char *asm_arch = NULL;
    155  1.1  mrg 
    156  1.1  mrg   if (asm_arch)
    157  1.1  mrg     {
    158  1.1  mrg       free (asm_arch);
    159  1.1  mrg       asm_arch = NULL;
    160  1.1  mrg     }
    161  1.1  mrg 
    162  1.1  mrg   const char *arg_pos = strchr (name, '+');
    163  1.1  mrg 
    164  1.1  mrg   /* No extension options? just return the original string.  */
    165  1.1  mrg   if (arg_pos == NULL)
    166  1.1  mrg     return name;
    167  1.1  mrg 
    168  1.1  mrg   const arch_option *arch_opt
    169  1.1  mrg     = arm_parse_arch_option_name (all_architectures, "-march", name);
    170  1.1  mrg 
    171  1.1  mrg   auto_sbitmap fpu_bits (isa_num_bits);
    172  1.1  mrg   static const enum isa_feature fpu_bitlist[]
    173  1.1  mrg     = { ISA_ALL_FPU_INTERNAL, isa_nobit };
    174  1.1  mrg 
    175  1.1  mrg   arm_initialize_isa (fpu_bits, fpu_bitlist);
    176  1.1  mrg 
    177  1.1  mrg   auto_sbitmap opt_bits (isa_num_bits);
    178  1.1  mrg 
    179  1.1  mrg   /* Ensure that the resulting string is large enough for the result.  We
    180  1.1  mrg      never add options, so using strdup here will ensure that.  */
    181  1.1  mrg   asm_arch = xstrdup (name);
    182  1.1  mrg   asm_arch[arg_pos - name] = '\0';
    183  1.1  mrg 
    184  1.1  mrg   std::vector<const char *>optlist;
    185  1.1  mrg 
    186  1.1  mrg   while (arg_pos)
    187  1.1  mrg     {
    188  1.1  mrg       const char *end = strchr (arg_pos + 1, '+');
    189  1.1  mrg       size_t len = end ? end - arg_pos : strlen (arg_pos);
    190  1.1  mrg 
    191  1.1  mrg       for (const cpu_arch_extension *entry = arch_opt->common.extensions;
    192  1.1  mrg 	   entry->name != NULL;
    193  1.1  mrg 	   entry++)
    194  1.1  mrg 	{
    195  1.1  mrg 	  if (strncmp (entry->name, arg_pos + 1, len - 1) == 0
    196  1.1  mrg 	      && entry->name[len - 1] == '\0')
    197  1.1  mrg 	    {
    198  1.1  mrg 	      /* Don't expect removal options.  */
    199  1.1  mrg 	      gcc_assert (!entry->remove);
    200  1.1  mrg 	      arm_initialize_isa (opt_bits, entry->isa_bits);
    201  1.1  mrg 	      if (!bitmap_subset_p (opt_bits, fpu_bits))
    202  1.1  mrg 		optlist.push_back (entry->name);
    203  1.1  mrg 	      bitmap_clear (opt_bits);
    204  1.1  mrg 	      break;
    205  1.1  mrg 	    }
    206  1.1  mrg 	}
    207  1.1  mrg 
    208  1.1  mrg       arg_pos = end;
    209  1.1  mrg     }
    210  1.1  mrg 
    211  1.1  mrg   std::sort (optlist.begin (), optlist.end (), compare_opt_names);
    212  1.1  mrg 
    213  1.1  mrg   for (std::vector<const char *>::iterator opt_iter = optlist.begin ();
    214  1.1  mrg        opt_iter != optlist.end ();
    215  1.1  mrg        ++opt_iter)
    216  1.1  mrg     {
    217  1.1  mrg       strcat (asm_arch, "+");
    218  1.1  mrg       strcat (asm_arch, (*opt_iter));
    219  1.1  mrg     }
    220  1.1  mrg 
    221  1.1  mrg   return asm_arch;
    222  1.1  mrg }
    223  1.1  mrg 
    224  1.1  mrg /* Called by the driver to rewrite a name passed to the -march
    225  1.1  mrg    argument in preparation to be passed to the assembler.  The
    226  1.1  mrg    names passed from the command line will be in ARGV, we want
    227  1.1  mrg    to use the right-most argument, which should be in
    228  1.1  mrg    ARGV[ARGC - 1].  ARGC should always be greater than 0.  */
    229  1.1  mrg 
    230  1.1  mrg const char *
    231  1.1  mrg arm_rewrite_march (int argc, const char **argv)
    232  1.1  mrg {
    233  1.1  mrg   gcc_assert (argc);
    234  1.1  mrg 
    235  1.1  mrg #ifdef HAVE_GAS_ARM_EXTENDED_ARCH
    236  1.1  mrg   return argv[argc - 1];
    237  1.1  mrg #else
    238  1.1  mrg   return arm_rewrite_selected_arch (argv[argc - 1]);
    239  1.1  mrg #endif
    240  1.1  mrg }
    241  1.1  mrg 
    242  1.1  mrg #include "arm-cpu-cdata.h"
    243  1.1  mrg 
    244  1.1  mrg /* Scan over a raw feature array BITS checking for BIT being present.
    245  1.1  mrg    This is slower than the normal bitmask checks, but we would spend longer
    246  1.1  mrg    initializing that than doing the check this way.  Returns true iff
    247  1.1  mrg    BIT is found.  */
    248  1.1  mrg static bool
    249  1.1  mrg check_isa_bits_for (const enum isa_feature* bits, enum isa_feature bit)
    250  1.1  mrg {
    251  1.1  mrg   while (*bits != isa_nobit)
    252  1.1  mrg     if (*bits++ == bit)
    253  1.1  mrg       return true;
    254  1.1  mrg 
    255  1.1  mrg   return false;
    256  1.1  mrg }
    257  1.1  mrg 
    258  1.1  mrg /* Look up NAME in the configuration defaults for this build of the
    259  1.1  mrg    the compiler.  Return the value associated with that name, or NULL
    260  1.1  mrg    if no value is found.  */
    261  1.1  mrg static const char *
    262  1.1  mrg arm_config_default (const char *name)
    263  1.1  mrg {
    264  1.1  mrg   unsigned i;
    265  1.1  mrg 
    266  1.1  mrg   if (configure_default_options[0].name == NULL)
    267  1.1  mrg     return NULL;
    268  1.1  mrg 
    269  1.1  mrg   for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
    270  1.1  mrg     if (strcmp (configure_default_options[i].name, name) == 0)
    271  1.1  mrg       return configure_default_options[i].value;
    272  1.1  mrg 
    273  1.1  mrg   return NULL;
    274  1.1  mrg }
    275  1.1  mrg 
    276  1.1  mrg /* Called by the driver to check whether the target denoted by current
    277  1.1  mrg    command line options is a Thumb-only, or ARM-only, target.  ARGV is
    278  1.1  mrg    an array of tupples (normally only one) where the first element of
    279  1.1  mrg    the tupple is 'cpu' or 'arch' and the second is the option passed
    280  1.1  mrg    to the compiler for that.  An architecture tupple is always taken
    281  1.1  mrg    in preference to a cpu tupple and the last of each type always
    282  1.1  mrg    overrides any earlier setting.  */
    283  1.1  mrg 
    284  1.1  mrg const char *
    285  1.1  mrg arm_target_mode (int argc, const char **argv)
    286  1.1  mrg {
    287  1.1  mrg   const char *arch = NULL;
    288  1.1  mrg   const char *cpu = NULL;
    289  1.1  mrg 
    290  1.1  mrg   if (argc % 2 != 0)
    291  1.1  mrg     fatal_error (input_location,
    292  1.1  mrg 		 "%%:%<target_mode_check%> takes an even number of parameters");
    293  1.1  mrg 
    294  1.1  mrg   while (argc)
    295  1.1  mrg     {
    296  1.1  mrg       if (strcmp (argv[0], "arch") == 0)
    297  1.1  mrg 	arch = argv[1];
    298  1.1  mrg       else if (strcmp (argv[0], "cpu") == 0)
    299  1.1  mrg 	cpu = argv[1];
    300  1.1  mrg       else
    301  1.1  mrg 	fatal_error (input_location, "unrecognized option passed to %%:"
    302  1.1  mrg 		     "%<target_mode_check%>");
    303  1.1  mrg       argc -= 2;
    304  1.1  mrg       argv += 2;
    305  1.1  mrg     }
    306  1.1  mrg 
    307  1.1  mrg   /* No architecture, or CPU, has option extensions that change
    308  1.1  mrg      whether or not we have a Thumb-only device, so there is no need
    309  1.1  mrg      to scan any option extensions specified.  */
    310  1.1  mrg 
    311  1.1  mrg   /* If the architecture is specified, that overrides any CPU setting.  */
    312  1.1  mrg   if (arch)
    313  1.1  mrg     {
    314  1.1  mrg       const arch_option *arch_opt
    315  1.1  mrg 	= arm_parse_arch_option_name (all_architectures, "-march", arch,
    316  1.1  mrg 				      false);
    317  1.1  mrg 
    318  1.1  mrg       if (arch_opt && !check_isa_bits_for (arch_opt->common.isa_bits,
    319  1.1  mrg 					   isa_bit_notm))
    320  1.1  mrg 	return "-mthumb";
    321  1.1  mrg       if (arch_opt && !check_isa_bits_for (arch_opt->common.isa_bits,
    322  1.1  mrg 					   isa_bit_thumb))
    323  1.1  mrg 	return "-marm";
    324  1.1  mrg     }
    325  1.1  mrg   else if (cpu)
    326  1.1  mrg     {
    327  1.1  mrg       const cpu_option *cpu_opt
    328  1.1  mrg 	= arm_parse_cpu_option_name (all_cores, "-mcpu", cpu, false);
    329  1.1  mrg 
    330  1.1  mrg       if (cpu_opt && !check_isa_bits_for (cpu_opt->common.isa_bits,
    331  1.1  mrg 					  isa_bit_notm))
    332  1.1  mrg 	return "-mthumb";
    333  1.1  mrg       if (cpu_opt && !check_isa_bits_for (cpu_opt->common.isa_bits,
    334  1.1  mrg 					   isa_bit_thumb))
    335  1.1  mrg 	return "-marm";
    336  1.1  mrg     }
    337  1.1  mrg 
    338  1.1  mrg   const char *default_mode = arm_config_default ("mode");
    339  1.1  mrg   if (default_mode)
    340  1.1  mrg     {
    341  1.1  mrg       if (strcmp (default_mode, "thumb") == 0)
    342  1.1  mrg 	return "-mthumb";
    343  1.1  mrg       else if (strcmp (default_mode, "arm") == 0)
    344  1.1  mrg 	return "-marm";
    345  1.1  mrg       else
    346  1.1  mrg 	gcc_unreachable ();
    347  1.1  mrg     }
    348  1.1  mrg 
    349  1.1  mrg   /* Compiler hasn't been configured with a default, and the CPU
    350  1.1  mrg      doesn't require Thumb, so default to ARM.  */
    351  1.1  mrg   return "-marm";
    352  1.1  mrg }
    353  1.1  mrg 
    354  1.1  mrg /* List the permitted CPU option names.  If TARGET is a near miss for an
    355  1.1  mrg    entry, print out the suggested alternative.  */
    356  1.1  mrg static void
    357  1.1  mrg arm_print_hint_for_cpu_option (const char *target,
    358  1.1  mrg 			       const cpu_option *list)
    359  1.1  mrg {
    360  1.1  mrg   auto_vec<const char*> candidates;
    361  1.1  mrg   for (; list->common.name != NULL; list++)
    362  1.1  mrg     {
    363  1.1  mrg       candidates.safe_push (list->common.name);
    364  1.1  mrg       if (list->aliases)
    365  1.1  mrg 	{
    366  1.1  mrg 	  for (const cpu_alias *alias = list->aliases; alias->name != NULL;
    367  1.1  mrg 	       alias++)
    368  1.1  mrg 	    if (alias->visible)
    369  1.1  mrg 	      candidates.safe_push (alias->name);
    370  1.1  mrg 	}
    371  1.1  mrg     }
    372  1.1  mrg 
    373  1.1  mrg #ifdef HAVE_LOCAL_CPU_DETECT
    374  1.1  mrg   /* Add also "native" as possible value.  */
    375  1.1  mrg   candidates.safe_push ("native");
    376  1.1  mrg #endif
    377  1.1  mrg 
    378  1.1  mrg   char *s;
    379  1.1  mrg   const char *hint = candidates_list_and_hint (target, s, candidates);
    380  1.1  mrg   if (hint)
    381  1.1  mrg     inform (input_location, "valid arguments are: %s; did you mean %qs?",
    382  1.1  mrg 	    s, hint);
    383  1.1  mrg   else
    384  1.1  mrg     inform (input_location, "valid arguments are: %s", s);
    385  1.1  mrg 
    386  1.1  mrg   XDELETEVEC (s);
    387  1.1  mrg }
    388  1.1  mrg 
    389  1.1  mrg /* Parse the base component of a CPU selection in LIST.  Return a
    390  1.1  mrg    pointer to the entry in the architecture table.  OPTNAME is the
    391  1.1  mrg    name of the option we are parsing and can be used if a diagnostic
    392  1.1  mrg    is needed.  If COMPLAIN is true (the default) emit error
    393  1.1  mrg    messages and hints on invalid input.  */
    394  1.1  mrg const cpu_option *
    395  1.1  mrg arm_parse_cpu_option_name (const cpu_option *list, const char *optname,
    396  1.1  mrg 			   const char *target, bool complain)
    397  1.1  mrg {
    398  1.1  mrg   const cpu_option *entry;
    399  1.1  mrg   const char *end  = strchr (target, '+');
    400  1.1  mrg   size_t len = end ? end - target : strlen (target);
    401  1.1  mrg 
    402  1.1  mrg   for (entry = list; entry->common.name != NULL; entry++)
    403  1.1  mrg     {
    404  1.1  mrg       if (strncmp (entry->common.name, target, len) == 0
    405  1.1  mrg 	  && entry->common.name[len] == '\0')
    406  1.1  mrg 	return entry;
    407  1.1  mrg 
    408  1.1  mrg       /* Match against any legal alias for this CPU candidate.  */
    409  1.1  mrg       if (entry->aliases)
    410  1.1  mrg 	{
    411  1.1  mrg 	  for (const cpu_alias *alias = entry->aliases; alias->name != NULL;
    412  1.1  mrg 	       alias++)
    413  1.1  mrg 	    if (strncmp (alias->name, target, len) == 0
    414  1.1  mrg 		&& alias->name[len] == '\0')
    415  1.1  mrg 	      return entry;
    416  1.1  mrg 	}
    417  1.1  mrg     }
    418  1.1  mrg 
    419  1.1  mrg   if (complain)
    420  1.1  mrg     {
    421  1.1  mrg       error_at (input_location, "unrecognized %s target: %s", optname, target);
    422  1.1  mrg       arm_print_hint_for_cpu_option (target, list);
    423  1.1  mrg     }
    424  1.1  mrg   return NULL;
    425  1.1  mrg }
    426  1.1  mrg 
    427  1.1  mrg /* List the permitted architecture option names.  If TARGET is a near
    428  1.1  mrg    miss for an entry, print out the suggested alternative.  */
    429  1.1  mrg static void
    430  1.1  mrg arm_print_hint_for_arch_option (const char *target,
    431  1.1  mrg 			       const arch_option *list)
    432  1.1  mrg {
    433  1.1  mrg   auto_vec<const char*> candidates;
    434  1.1  mrg   for (; list->common.name != NULL; list++)
    435  1.1  mrg     candidates.safe_push (list->common.name);
    436  1.1  mrg 
    437  1.1  mrg #ifdef HAVE_LOCAL_CPU_DETECT
    438  1.1  mrg   /* Add also "native" as possible value.  */
    439  1.1  mrg   candidates.safe_push ("native");
    440  1.1  mrg #endif
    441  1.1  mrg 
    442  1.1  mrg   char *s;
    443  1.1  mrg   const char *hint = candidates_list_and_hint (target, s, candidates);
    444  1.1  mrg   if (hint)
    445  1.1  mrg     inform (input_location, "valid arguments are: %s; did you mean %qs?",
    446  1.1  mrg 	    s, hint);
    447  1.1  mrg   else
    448  1.1  mrg     inform (input_location, "valid arguments are: %s", s);
    449  1.1  mrg 
    450  1.1  mrg   XDELETEVEC (s);
    451  1.1  mrg }
    452  1.1  mrg 
    453  1.1  mrg /* Parse the base component of a CPU or architecture selection in
    454  1.1  mrg    LIST.  Return a pointer to the entry in the architecture table.
    455  1.1  mrg    OPTNAME is the name of the option we are parsing and can be used if
    456  1.1  mrg    a diagnostic is needed.  If COMPLAIN is true (the default) emit error
    457  1.1  mrg    messages and hints on invalid input.  */
    458  1.1  mrg const arch_option *
    459  1.1  mrg arm_parse_arch_option_name (const arch_option *list, const char *optname,
    460  1.1  mrg 			    const char *target, bool complain)
    461  1.1  mrg {
    462  1.1  mrg   const arch_option *entry;
    463  1.1  mrg   const char *end  = strchr (target, '+');
    464  1.1  mrg   size_t len = end ? end - target : strlen (target);
    465  1.1  mrg 
    466  1.1  mrg   for (entry = list; entry->common.name != NULL; entry++)
    467  1.1  mrg     {
    468  1.1  mrg       if (strncmp (entry->common.name, target, len) == 0
    469  1.1  mrg 	  && entry->common.name[len] == '\0')
    470  1.1  mrg 	return entry;
    471  1.1  mrg     }
    472  1.1  mrg 
    473  1.1  mrg   if (complain)
    474  1.1  mrg     {
    475  1.1  mrg       error_at (input_location, "unrecognized %s target: %s", optname, target);
    476  1.1  mrg       arm_print_hint_for_arch_option (target, list);
    477  1.1  mrg     }
    478  1.1  mrg   return NULL;
    479  1.1  mrg }
    480  1.1  mrg 
    481  1.1  mrg /* List the permitted architecture option names.  If TARGET is a near
    482  1.1  mrg    miss for an entry, print out the suggested alternative.  */
    483  1.1  mrg static void
    484  1.1  mrg arm_print_hint_for_fpu_option (const char *target)
    485  1.1  mrg {
    486  1.1  mrg   auto_vec<const char*> candidates;
    487  1.1  mrg   for (int i = 0; i < TARGET_FPU_auto; i++)
    488  1.1  mrg     candidates.safe_push (all_fpus[i].name);
    489  1.1  mrg   char *s;
    490  1.1  mrg   const char *hint = candidates_list_and_hint (target, s, candidates);
    491  1.1  mrg   if (hint)
    492  1.1  mrg     inform (input_location, "valid arguments are: %s; did you mean %qs?",
    493  1.1  mrg 	    s, hint);
    494  1.1  mrg   else
    495  1.1  mrg     inform (input_location, "valid arguments are: %s", s);
    496  1.1  mrg 
    497  1.1  mrg   XDELETEVEC (s);
    498  1.1  mrg }
    499  1.1  mrg 
    500  1.1  mrg static const arm_fpu_desc *
    501  1.1  mrg arm_parse_fpu_option (const char *opt)
    502  1.1  mrg {
    503  1.1  mrg   int i;
    504  1.1  mrg 
    505  1.1  mrg   for (i = 0; i < TARGET_FPU_auto; i++)
    506  1.1  mrg     {
    507  1.1  mrg       if (strcmp (all_fpus[i].name, opt) == 0)
    508  1.1  mrg 	return all_fpus + i;
    509  1.1  mrg     }
    510  1.1  mrg 
    511  1.1  mrg   error_at (input_location, "unrecognized %<-mfpu%> target: %s", opt);
    512  1.1  mrg   arm_print_hint_for_fpu_option (opt);
    513  1.1  mrg   return NULL;
    514  1.1  mrg }
    515  1.1  mrg 
    516  1.1  mrg /* Convert a static initializer array of feature bits to sbitmap
    517  1.1  mrg    representation.  */
    518  1.1  mrg void
    519  1.1  mrg arm_initialize_isa (sbitmap isa, const enum isa_feature *isa_bits)
    520  1.1  mrg {
    521  1.1  mrg   bitmap_clear (isa);
    522  1.1  mrg   while (*isa_bits != isa_nobit)
    523  1.1  mrg     bitmap_set_bit (isa, *(isa_bits++));
    524  1.1  mrg }
    525  1.1  mrg 
    526  1.1  mrg /* OPT isn't a recognized feature.  Print a suitable error message and
    527  1.1  mrg    suggest a possible value.  Always print the list of permitted
    528  1.1  mrg    values.  */
    529  1.1  mrg static void
    530  1.1  mrg arm_unrecognized_feature (const char *opt, size_t len,
    531  1.1  mrg 			  const cpu_arch_option *target)
    532  1.1  mrg {
    533  1.1  mrg   char *this_opt = XALLOCAVEC (char, len+1);
    534  1.1  mrg   auto_vec<const char*> candidates;
    535  1.1  mrg 
    536  1.1  mrg   strncpy (this_opt, opt, len);
    537  1.1  mrg   this_opt[len] = 0;
    538  1.1  mrg 
    539  1.1  mrg   error_at (input_location, "%qs does not support feature %qs", target->name,
    540  1.1  mrg 	    this_opt);
    541  1.1  mrg   for (const cpu_arch_extension *list = target->extensions;
    542  1.1  mrg        list->name != NULL;
    543  1.1  mrg        list++)
    544  1.1  mrg     candidates.safe_push (list->name);
    545  1.1  mrg 
    546  1.1  mrg   char *s;
    547  1.1  mrg   const char *hint = candidates_list_and_hint (this_opt, s, candidates);
    548  1.1  mrg 
    549  1.1  mrg   if (hint)
    550  1.1  mrg     inform (input_location, "valid feature names are: %s; did you mean %qs?",
    551  1.1  mrg 	    s, hint);
    552  1.1  mrg   else
    553  1.1  mrg     inform (input_location, "valid feature names are: %s", s);
    554  1.1  mrg 
    555  1.1  mrg   XDELETEVEC (s);
    556  1.1  mrg }
    557  1.1  mrg 
    558  1.1  mrg /* Parse any feature extensions to add to (or remove from) the
    559  1.1  mrg    permitted ISA selection.  */
    560  1.1  mrg void
    561  1.1  mrg arm_parse_option_features (sbitmap isa, const cpu_arch_option *target,
    562  1.1  mrg 			   const char *opts_in)
    563  1.1  mrg {
    564  1.1  mrg   const char *opts = opts_in;
    565  1.1  mrg 
    566  1.1  mrg   if (!opts)
    567  1.1  mrg     return;
    568  1.1  mrg 
    569  1.1  mrg   if (!target->extensions)
    570  1.1  mrg     {
    571  1.1  mrg       error_at (input_location, "%s does not take any feature options",
    572  1.1  mrg 		target->name);
    573  1.1  mrg       return;
    574  1.1  mrg     }
    575  1.1  mrg 
    576  1.1  mrg   while (opts)
    577  1.1  mrg     {
    578  1.1  mrg       gcc_assert (*opts == '+');
    579  1.1  mrg       const struct cpu_arch_extension *entry;
    580  1.1  mrg       const char *end = strchr (++opts, '+');
    581  1.1  mrg       size_t len = end ? end - opts : strlen (opts);
    582  1.1  mrg       bool matched = false;
    583  1.1  mrg 
    584  1.1  mrg       for (entry = target->extensions;
    585  1.1  mrg 	   !matched && entry->name != NULL;
    586  1.1  mrg 	   entry++)
    587  1.1  mrg 	{
    588  1.1  mrg 	  if (strncmp (entry->name, opts, len) == 0
    589  1.1  mrg 	      && entry->name[len] == '\0')
    590  1.1  mrg 	    {
    591  1.1  mrg 	      if (isa)
    592  1.1  mrg 		{
    593  1.1  mrg 		  const enum isa_feature *f = entry->isa_bits;
    594  1.1  mrg 		  if (entry->remove)
    595  1.1  mrg 		    {
    596  1.1  mrg 		      while (*f != isa_nobit)
    597  1.1  mrg 			bitmap_clear_bit (isa, *(f++));
    598  1.1  mrg 		    }
    599  1.1  mrg 		  else
    600  1.1  mrg 		    {
    601  1.1  mrg 		      while (*f != isa_nobit)
    602  1.1  mrg 			bitmap_set_bit (isa, *(f++));
    603  1.1  mrg 		    }
    604  1.1  mrg 		}
    605  1.1  mrg 	      matched = true;
    606  1.1  mrg 	    }
    607  1.1  mrg 	}
    608  1.1  mrg 
    609  1.1  mrg       if (!matched)
    610  1.1  mrg 	arm_unrecognized_feature (opts, len, target);
    611  1.1  mrg 
    612  1.1  mrg       opts = end;
    613  1.1  mrg     }
    614  1.1  mrg }
    615  1.1  mrg 
    616  1.1  mrg class candidate_extension
    617  1.1  mrg {
    618  1.1  mrg public:
    619  1.1  mrg   const cpu_arch_extension *extension;
    620  1.1  mrg   sbitmap isa_bits;
    621  1.1  mrg   bool required;
    622  1.1  mrg 
    623  1.1  mrg   candidate_extension (const cpu_arch_extension *ext, sbitmap bits)
    624  1.1  mrg     : extension (ext), isa_bits (bits), required (true)
    625  1.1  mrg     {}
    626  1.1  mrg   ~candidate_extension ()
    627  1.1  mrg     {
    628  1.1  mrg       sbitmap_free (isa_bits);
    629  1.1  mrg     }
    630  1.1  mrg };
    631  1.1  mrg 
    632  1.1  mrg /* Generate a canonical representation of the -march option from the
    633  1.1  mrg    current -march string (if given) and other options on the command
    634  1.1  mrg    line that might affect the architecture.  This aids multilib selection
    635  1.1  mrg    by ensuring that:
    636  1.1  mrg    a) the option is always present
    637  1.1  mrg    b) only the minimal set of options are used
    638  1.1  mrg    c) when there are multiple extensions, they are in a consistent order.
    639  1.1  mrg 
    640  1.1  mrg    The options array consists of couplets of information where the
    641  1.1  mrg    first item in each couplet is the string describing which option
    642  1.1  mrg    name was selected (arch, cpu, fpu) and the second is the value
    643  1.1  mrg    passed for that option.
    644  1.1  mrg 
    645  1.1  mrg    arch_for_multilib is boolean variable taking value true or false.
    646  1.1  mrg    arch_for_multilib is false when the canonical representation is for -march
    647  1.1  mrg    option and it is true when canonical representation is for -mlibarch option.
    648  1.1  mrg    On passing arch_for_multilib true the canonical string generated will be
    649  1.1  mrg    without the compiler options which are not required for multilib linking.  */
    650  1.1  mrg static const char *
    651  1.1  mrg arm_canon_arch_option_1 (int argc, const char **argv, bool arch_for_multilib)
    652  1.1  mrg {
    653  1.1  mrg   const char *arch = NULL;
    654  1.1  mrg   const char *cpu = NULL;
    655  1.1  mrg   const char *fpu = NULL;
    656  1.1  mrg   const char *abi = NULL;
    657  1.1  mrg   static char *canonical_arch = NULL;
    658  1.1  mrg 
    659  1.1  mrg   /* Just in case we're called more than once.  */
    660  1.1  mrg   if (canonical_arch)
    661  1.1  mrg     {
    662  1.1  mrg       free (canonical_arch);
    663  1.1  mrg       canonical_arch = NULL;
    664  1.1  mrg     }
    665  1.1  mrg 
    666  1.1  mrg   if (argc & 1)
    667  1.1  mrg     fatal_error (input_location,
    668  1.1  mrg 		 "%%:%<canon_for_mlib%> takes 1 or more pairs of parameters");
    669  1.1  mrg 
    670  1.1  mrg   while (argc)
    671  1.1  mrg     {
    672  1.1  mrg       if (strcmp (argv[0], "arch") == 0)
    673  1.1  mrg 	arch = argv[1];
    674  1.1  mrg       else if (strcmp (argv[0], "cpu") == 0)
    675  1.1  mrg 	cpu = argv[1];
    676  1.1  mrg       else if (strcmp (argv[0], "fpu") == 0)
    677  1.1  mrg 	fpu = argv[1];
    678  1.1  mrg       else if (strcmp (argv[0], "abi") == 0)
    679  1.1  mrg 	abi = argv[1];
    680  1.1  mrg       else
    681  1.1  mrg 	fatal_error (input_location,
    682  1.1  mrg 		     "unrecognized operand to %%:%<canon_for_mlib%>");
    683  1.1  mrg 
    684  1.1  mrg       argc -= 2;
    685  1.1  mrg       argv += 2;
    686  1.1  mrg     }
    687  1.1  mrg 
    688  1.1  mrg   auto_sbitmap target_isa (isa_num_bits);
    689  1.1  mrg   auto_sbitmap base_isa (isa_num_bits);
    690  1.1  mrg   auto_sbitmap fpu_isa (isa_num_bits);
    691  1.1  mrg 
    692  1.1  mrg   bitmap_clear (fpu_isa);
    693  1.1  mrg 
    694  1.1  mrg   const arch_option *selected_arch = NULL;
    695  1.1  mrg 
    696  1.1  mrg   /* At least one of these must be defined by either the specs or the
    697  1.1  mrg      user.  */
    698  1.1  mrg   gcc_assert (cpu || arch);
    699  1.1  mrg 
    700  1.1  mrg   if (!fpu)
    701  1.1  mrg     fpu = FPUTYPE_AUTO;
    702  1.1  mrg 
    703  1.1  mrg   if (!abi)
    704  1.1  mrg     {
    705  1.1  mrg       if (TARGET_DEFAULT_FLOAT_ABI == ARM_FLOAT_ABI_SOFT)
    706  1.1  mrg 	abi = "soft";
    707  1.1  mrg       else if (TARGET_DEFAULT_FLOAT_ABI == ARM_FLOAT_ABI_SOFTFP)
    708  1.1  mrg 	abi = "softfp";
    709  1.1  mrg       else if (TARGET_DEFAULT_FLOAT_ABI == ARM_FLOAT_ABI_HARD)
    710  1.1  mrg 	abi = "hard";
    711  1.1  mrg     }
    712  1.1  mrg 
    713  1.1  mrg   /* First build up a bitmap describing the target architecture.  */
    714  1.1  mrg   if (arch)
    715  1.1  mrg     {
    716  1.1  mrg       selected_arch = arm_parse_arch_option_name (all_architectures, "-march",
    717  1.1  mrg 						  arch, !arch_for_multilib);
    718  1.1  mrg 
    719  1.1  mrg       if (selected_arch == NULL)
    720  1.1  mrg 	return "";
    721  1.1  mrg 
    722  1.1  mrg       arm_initialize_isa (target_isa, selected_arch->common.isa_bits);
    723  1.1  mrg       arm_parse_option_features (target_isa, &selected_arch->common,
    724  1.1  mrg 				 strchr (arch, '+'));
    725  1.1  mrg       if (arch_for_multilib)
    726  1.1  mrg 	{
    727  1.1  mrg 	  const enum isa_feature removable_bits[] = {ISA_IGNORE_FOR_MULTILIB,
    728  1.1  mrg 						     isa_nobit};
    729  1.1  mrg 	  sbitmap isa_bits = sbitmap_alloc (isa_num_bits);
    730  1.1  mrg 	  arm_initialize_isa (isa_bits, removable_bits);
    731  1.1  mrg 	  bitmap_and_compl (target_isa, target_isa, isa_bits);
    732  1.1  mrg 	}
    733  1.1  mrg 
    734  1.1  mrg       if (fpu && strcmp (fpu, "auto") != 0)
    735  1.1  mrg 	{
    736  1.1  mrg 	  /* We assume that architectures do not have any FPU bits
    737  1.1  mrg 	     enabled by default.  If they did, we would need to strip
    738  1.1  mrg 	     these out first.  */
    739  1.1  mrg 	  const arm_fpu_desc *target_fpu = arm_parse_fpu_option (fpu);
    740  1.1  mrg 	  if (target_fpu == NULL)
    741  1.1  mrg 	    return "";
    742  1.1  mrg 
    743  1.1  mrg 	  arm_initialize_isa (fpu_isa, target_fpu->isa_bits);
    744  1.1  mrg 	  bitmap_ior (target_isa, target_isa, fpu_isa);
    745  1.1  mrg 	}
    746  1.1  mrg     }
    747  1.1  mrg   else if (cpu)
    748  1.1  mrg     {
    749  1.1  mrg       const cpu_option *selected_cpu
    750  1.1  mrg 	= arm_parse_cpu_option_name (all_cores, "-mcpu", cpu,
    751  1.1  mrg 				     !arch_for_multilib);
    752  1.1  mrg 
    753  1.1  mrg       if (selected_cpu == NULL)
    754  1.1  mrg 	return "";
    755  1.1  mrg 
    756  1.1  mrg       arm_initialize_isa (target_isa, selected_cpu->common.isa_bits);
    757  1.1  mrg       arm_parse_option_features (target_isa, &selected_cpu->common,
    758  1.1  mrg 				 strchr (cpu, '+'));
    759  1.1  mrg       if (fpu && strcmp (fpu, "auto") != 0)
    760  1.1  mrg 	{
    761  1.1  mrg 	  /* The easiest and safest way to remove the default fpu
    762  1.1  mrg 	     capabilities is to look for a '+no..' option that removes
    763  1.1  mrg 	     the base FPU bit (isa_bit_vfpv2).  If that doesn't exist
    764  1.1  mrg 	     then the best we can do is strip out all the bits that
    765  1.1  mrg 	     might be part of the most capable FPU we know about,
    766  1.1  mrg 	     which is "crypto-neon-fp-armv8".  */
    767  1.1  mrg 	  bool default_fpu_found = false;
    768  1.1  mrg 	  if (selected_cpu->common.extensions)
    769  1.1  mrg 	    {
    770  1.1  mrg 	      const cpu_arch_extension *ext;
    771  1.1  mrg 	      for (ext = selected_cpu->common.extensions; ext->name != NULL;
    772  1.1  mrg 		   ++ext)
    773  1.1  mrg 		{
    774  1.1  mrg 		  if (ext->remove
    775  1.1  mrg 		      && check_isa_bits_for (ext->isa_bits, isa_bit_vfpv2))
    776  1.1  mrg 		    {
    777  1.1  mrg 		      arm_initialize_isa (fpu_isa, ext->isa_bits);
    778  1.1  mrg 		      bitmap_and_compl (target_isa, target_isa, fpu_isa);
    779  1.1  mrg 		      default_fpu_found = true;
    780  1.1  mrg 		    }
    781  1.1  mrg 		}
    782  1.1  mrg 
    783  1.1  mrg 	    }
    784  1.1  mrg 
    785  1.1  mrg 	  if (!default_fpu_found)
    786  1.1  mrg 	    {
    787  1.1  mrg 	      arm_initialize_isa
    788  1.1  mrg 		(fpu_isa,
    789  1.1  mrg 		 all_fpus[TARGET_FPU_crypto_neon_fp_armv8].isa_bits);
    790  1.1  mrg 	      bitmap_and_compl (target_isa, target_isa, fpu_isa);
    791  1.1  mrg 	    }
    792  1.1  mrg 
    793  1.1  mrg 	  const arm_fpu_desc *target_fpu = arm_parse_fpu_option (fpu);
    794  1.1  mrg 	  if (target_fpu == NULL)
    795  1.1  mrg 	    return "";
    796  1.1  mrg 
    797  1.1  mrg 	  arm_initialize_isa (fpu_isa, target_fpu->isa_bits);
    798  1.1  mrg 	  bitmap_ior (target_isa, target_isa, fpu_isa);
    799  1.1  mrg 	}
    800  1.1  mrg 
    801  1.1  mrg       selected_arch = all_architectures + selected_cpu->arch;
    802  1.1  mrg     }
    803  1.1  mrg 
    804  1.1  mrg   /* If we have a soft-float ABI, disable the FPU.  */
    805  1.1  mrg   if (abi && strcmp (abi, "soft") == 0)
    806  1.1  mrg     {
    807  1.1  mrg       /* Clearing the VFPv2 bit is sufficient to stop any extention that
    808  1.1  mrg 	 builds on the FPU from matching.  */
    809  1.1  mrg       bitmap_clear_bit (target_isa, isa_bit_vfpv2);
    810  1.1  mrg     }
    811  1.1  mrg 
    812  1.1  mrg   /* If we don't have a selected architecture by now, something's
    813  1.1  mrg      badly wrong.  */
    814  1.1  mrg   gcc_assert (selected_arch);
    815  1.1  mrg 
    816  1.1  mrg   arm_initialize_isa (base_isa, selected_arch->common.isa_bits);
    817  1.1  mrg 
    818  1.1  mrg   /* Architecture has no extension options, so just return the canonical
    819  1.1  mrg      architecture name.  */
    820  1.1  mrg   if (selected_arch->common.extensions == NULL)
    821  1.1  mrg     return selected_arch->common.name;
    822  1.1  mrg 
    823  1.1  mrg   /* We're only interested in extension bits.  */
    824  1.1  mrg   bitmap_and_compl (target_isa, target_isa, base_isa);
    825  1.1  mrg 
    826  1.1  mrg   /* There are no extensions needed.  Just return the canonical architecture
    827  1.1  mrg      name.  */
    828  1.1  mrg   if (bitmap_empty_p (target_isa))
    829  1.1  mrg     return selected_arch->common.name;
    830  1.1  mrg 
    831  1.1  mrg   /* What is left is the architecture that the compiler will target.  We
    832  1.1  mrg      now need to map that back into a suitable option+features list.
    833  1.1  mrg 
    834  1.1  mrg      The list is built in two passes.  First we scan every additive
    835  1.1  mrg      option feature supported by the architecture.  If the option
    836  1.1  mrg      provides a subset of the features we need we add it to the list
    837  1.1  mrg      of candidates.  We then scan backwards over the list of
    838  1.1  mrg      candidates and if we find a feature that adds nothing to one that
    839  1.1  mrg      was later in the list we mark it as redundant.  The result is a
    840  1.1  mrg      minimal list of required features for the target
    841  1.1  mrg      architecture.  */
    842  1.1  mrg 
    843  1.1  mrg   std::list<candidate_extension *> extensions;
    844  1.1  mrg 
    845  1.1  mrg   auto_sbitmap target_isa_unsatisfied (isa_num_bits);
    846  1.1  mrg   bitmap_copy (target_isa_unsatisfied, target_isa);
    847  1.1  mrg 
    848  1.1  mrg   sbitmap isa_bits = NULL;
    849  1.1  mrg   for (const cpu_arch_extension *cand = selected_arch->common.extensions;
    850  1.1  mrg        cand->name != NULL;
    851  1.1  mrg        cand++)
    852  1.1  mrg     {
    853  1.1  mrg       if (cand->remove || cand->alias)
    854  1.1  mrg 	continue;
    855  1.1  mrg 
    856  1.1  mrg       if (isa_bits == NULL)
    857  1.1  mrg 	isa_bits = sbitmap_alloc (isa_num_bits);
    858  1.1  mrg 
    859  1.1  mrg       arm_initialize_isa (isa_bits, cand->isa_bits);
    860  1.1  mrg       if (bitmap_subset_p (isa_bits, target_isa))
    861  1.1  mrg 	{
    862  1.1  mrg 	  extensions.push_back (new candidate_extension (cand, isa_bits));
    863  1.1  mrg 	  bitmap_and_compl (target_isa_unsatisfied, target_isa_unsatisfied,
    864  1.1  mrg 			    isa_bits);
    865  1.1  mrg 	  isa_bits = NULL;
    866  1.1  mrg 	}
    867  1.1  mrg     }
    868  1.1  mrg 
    869  1.1  mrg   /* There's one extra case to consider, which is that the user has
    870  1.1  mrg      specified an FPU that is less capable than this architecture
    871  1.1  mrg      supports.  In that case the code above will fail to find a
    872  1.1  mrg      suitable feature.  We handle this by scanning the list of options
    873  1.1  mrg      again, matching the first option that provides an FPU that is
    874  1.1  mrg      more capable than the selected FPU.
    875  1.1  mrg 
    876  1.1  mrg      Note that the other case (user specified a more capable FPU than
    877  1.1  mrg      this architecture supports) should end up selecting the most
    878  1.1  mrg      capable FPU variant that we do support.  This is sufficient for
    879  1.1  mrg      multilib selection.  */
    880  1.1  mrg 
    881  1.1  mrg   if (bitmap_bit_p (target_isa_unsatisfied, isa_bit_vfpv2)
    882  1.1  mrg       && bitmap_bit_p (fpu_isa, isa_bit_vfpv2))
    883  1.1  mrg     {
    884  1.1  mrg       std::list<candidate_extension *>::iterator ipoint = extensions.begin ();
    885  1.1  mrg 
    886  1.1  mrg       for (const cpu_arch_extension *cand = selected_arch->common.extensions;
    887  1.1  mrg 	   cand->name != NULL;
    888  1.1  mrg 	   cand++)
    889  1.1  mrg 	{
    890  1.1  mrg 	  if (cand->remove || cand->alias)
    891  1.1  mrg 	    continue;
    892  1.1  mrg 
    893  1.1  mrg 	  if (isa_bits == NULL)
    894  1.1  mrg 	    isa_bits = sbitmap_alloc (isa_num_bits);
    895  1.1  mrg 
    896  1.1  mrg 	  /* We need to keep the features in canonical order, so move the
    897  1.1  mrg 	     insertion point if this feature is a candidate.  */
    898  1.1  mrg 	  if (ipoint != extensions.end ()
    899  1.1  mrg 	      && (*ipoint)->extension == cand)
    900  1.1  mrg 	    ++ipoint;
    901  1.1  mrg 
    902  1.1  mrg 	  arm_initialize_isa (isa_bits, cand->isa_bits);
    903  1.1  mrg 	  if (bitmap_subset_p (fpu_isa, isa_bits))
    904  1.1  mrg 	    {
    905  1.1  mrg 	      extensions.insert (ipoint,
    906  1.1  mrg 				 new candidate_extension (cand, isa_bits));
    907  1.1  mrg 	      isa_bits = NULL;
    908  1.1  mrg 	      break;
    909  1.1  mrg 	    }
    910  1.1  mrg 	}
    911  1.1  mrg     }
    912  1.1  mrg 
    913  1.1  mrg   if (isa_bits)
    914  1.1  mrg     sbitmap_free (isa_bits);
    915  1.1  mrg 
    916  1.1  mrg   bitmap_clear (target_isa);
    917  1.1  mrg   size_t len = 1;
    918  1.1  mrg   for (std::list<candidate_extension *>::reverse_iterator riter
    919  1.1  mrg 	 = extensions.rbegin ();
    920  1.1  mrg        riter != extensions.rend (); ++riter)
    921  1.1  mrg     {
    922  1.1  mrg       if (bitmap_subset_p ((*riter)->isa_bits, target_isa))
    923  1.1  mrg 	(*riter)->required = false;
    924  1.1  mrg       else
    925  1.1  mrg 	{
    926  1.1  mrg 	  bitmap_ior (target_isa, target_isa, (*riter)->isa_bits);
    927  1.1  mrg 	  len += strlen ((*riter)->extension->name) + 1;
    928  1.1  mrg 	}
    929  1.1  mrg     }
    930  1.1  mrg 
    931  1.1  mrg   canonical_arch
    932  1.1  mrg     = (char *) xmalloc (len + strlen (selected_arch->common.name));
    933  1.1  mrg 
    934  1.1  mrg   strcpy (canonical_arch, selected_arch->common.name);
    935  1.1  mrg 
    936  1.1  mrg   for (std::list<candidate_extension *>::iterator iter = extensions.begin ();
    937  1.1  mrg        iter != extensions.end (); ++iter)
    938  1.1  mrg     {
    939  1.1  mrg       if ((*iter)->required)
    940  1.1  mrg 	{
    941  1.1  mrg 	  strcat (canonical_arch, "+");
    942  1.1  mrg 	  strcat (canonical_arch, (*iter)->extension->name);
    943  1.1  mrg 	}
    944  1.1  mrg       delete (*iter);
    945  1.1  mrg     }
    946  1.1  mrg 
    947  1.1  mrg   return canonical_arch;
    948  1.1  mrg }
    949  1.1  mrg 
    950  1.1  mrg /* If building big-endian on a BE8 target generate a --be8 option for
    951  1.1  mrg    the linker.  Takes four types of option: "little" - little-endian;
    952  1.1  mrg    "big" - big-endian; "be8" - force be8 iff big-endian; and "arch"
    953  1.1  mrg    "<arch-name>" (two arguments) - the target architecture.  The
    954  1.1  mrg    parameter names are generated by the driver from the command-line
    955  1.1  mrg    options.  */
    956  1.1  mrg const char *
    957  1.1  mrg arm_be8_option (int argc, const char **argv)
    958  1.1  mrg {
    959  1.1  mrg   int endian = TARGET_ENDIAN_DEFAULT;
    960  1.1  mrg   const char *arch = NULL;
    961  1.1  mrg   int arg;
    962  1.1  mrg   bool force = false;
    963  1.1  mrg 
    964  1.1  mrg   for (arg = 0; arg < argc; arg++)
    965  1.1  mrg     {
    966  1.1  mrg       if (strcmp (argv[arg], "little") == 0)
    967  1.1  mrg 	endian = 0;
    968  1.1  mrg       else if (strcmp (argv[arg], "big") == 0)
    969  1.1  mrg 	endian = 1;
    970  1.1  mrg       else if (strcmp (argv[arg], "be8") == 0)
    971  1.1  mrg 	force = true;
    972  1.1  mrg       else if (strcmp (argv[arg], "arch") == 0)
    973  1.1  mrg 	{
    974  1.1  mrg 	  arg++;
    975  1.1  mrg 	  gcc_assert (arg < argc);
    976  1.1  mrg 	  arch = argv[arg];
    977  1.1  mrg 	}
    978  1.1  mrg       else
    979  1.1  mrg 	gcc_unreachable ();
    980  1.1  mrg     }
    981  1.1  mrg 
    982  1.1  mrg   /* Little endian - no be8 option.  */
    983  1.1  mrg   if (!endian)
    984  1.1  mrg     return "";
    985  1.1  mrg 
    986  1.1  mrg   if (force)
    987  1.1  mrg     return "--be8";
    988  1.1  mrg 
    989  1.1  mrg   /* Arch might not be set iff arm_canon_arch (above) detected an
    990  1.1  mrg      error.  Do nothing in that case.  */
    991  1.1  mrg   if (!arch)
    992  1.1  mrg     return "";
    993  1.1  mrg 
    994  1.1  mrg   const arch_option *selected_arch
    995  1.1  mrg     = arm_parse_arch_option_name (all_architectures, "-march", arch);
    996  1.1  mrg 
    997  1.1  mrg   /* Similarly if the given arch option was itself invalid.  */
    998  1.1  mrg   if (!selected_arch)
    999  1.1  mrg     return "";
   1000  1.1  mrg 
   1001  1.1  mrg   if (check_isa_bits_for (selected_arch->common.isa_bits, isa_bit_be8))
   1002  1.1  mrg     return "--be8";
   1003  1.1  mrg 
   1004  1.1  mrg   return "";
   1005  1.1  mrg }
   1006  1.1  mrg 
   1007  1.1  mrg /* Generate a -mfpu= option for passing to the assembler.  This is
   1008  1.1  mrg    only called when -mfpu was set (possibly defaulted) to auto and is
   1009  1.1  mrg    needed to ensure that the assembler knows the correct FPU to use.
   1010  1.1  mrg    It wouldn't really be needed except that the compiler can be used
   1011  1.1  mrg    to invoke the assembler directly on hand-written files that lack
   1012  1.1  mrg    the necessary internal .fpu directives.  We assume that the architecture
   1013  1.1  mrg    canonicalization calls have already been made so that we have a final
   1014  1.1  mrg    -march= option to derive the fpu from.  */
   1015  1.1  mrg const char*
   1016  1.1  mrg arm_asm_auto_mfpu (int argc, const char **argv)
   1017  1.1  mrg {
   1018  1.1  mrg   static char *auto_fpu = NULL;
   1019  1.1  mrg   const char *arch = NULL;
   1020  1.1  mrg   static const enum isa_feature fpu_bitlist[]
   1021  1.1  mrg     = { ISA_ALL_FPU_INTERNAL, isa_nobit };
   1022  1.1  mrg   const arch_option *selected_arch;
   1023  1.1  mrg   static const char* fpuname = "softvfp";
   1024  1.1  mrg 
   1025  1.1  mrg   /* Handle multiple calls to this routine.  */
   1026  1.1  mrg   if (auto_fpu)
   1027  1.1  mrg     {
   1028  1.1  mrg       free (auto_fpu);
   1029  1.1  mrg       auto_fpu = NULL;
   1030  1.1  mrg     }
   1031  1.1  mrg 
   1032  1.1  mrg   while (argc)
   1033  1.1  mrg     {
   1034  1.1  mrg       if (strcmp (argv[0], "arch") == 0)
   1035  1.1  mrg 	arch = argv[1];
   1036  1.1  mrg       else
   1037  1.1  mrg 	fatal_error (input_location,
   1038  1.1  mrg 		     "unrecognized operand to %%:%<asm_auto_mfpu%>");
   1039  1.1  mrg       argc -= 2;
   1040  1.1  mrg       argv += 2;
   1041  1.1  mrg     }
   1042  1.1  mrg 
   1043  1.1  mrg   auto_sbitmap target_isa (isa_num_bits);
   1044  1.1  mrg   auto_sbitmap fpubits (isa_num_bits);
   1045  1.1  mrg 
   1046  1.1  mrg   gcc_assert (arch != NULL);
   1047  1.1  mrg   selected_arch = arm_parse_arch_option_name (all_architectures,
   1048  1.1  mrg 					      "-march", arch);
   1049  1.1  mrg   if (selected_arch == NULL)
   1050  1.1  mrg     return "";
   1051  1.1  mrg 
   1052  1.1  mrg   arm_initialize_isa (target_isa, selected_arch->common.isa_bits);
   1053  1.1  mrg   arm_parse_option_features (target_isa, &selected_arch->common,
   1054  1.1  mrg 			     strchr (arch, '+'));
   1055  1.1  mrg   arm_initialize_isa (fpubits, fpu_bitlist);
   1056  1.1  mrg 
   1057  1.1  mrg   bitmap_and (fpubits, fpubits, target_isa);
   1058  1.1  mrg 
   1059  1.1  mrg   /* The logic below is essentially identical to that in
   1060  1.1  mrg      arm.cc:arm_identify_fpu_from_isa(), but that only works in the main
   1061  1.1  mrg      part of the compiler.  */
   1062  1.1  mrg 
   1063  1.1  mrg   /* If there are no FPU capability bits, we just pass -mfpu=softvfp.  */
   1064  1.1  mrg   if (!bitmap_empty_p (fpubits))
   1065  1.1  mrg     {
   1066  1.1  mrg       unsigned int i;
   1067  1.1  mrg       auto_sbitmap cand_fpubits (isa_num_bits);
   1068  1.1  mrg       for (i = 0; i < TARGET_FPU_auto; i++)
   1069  1.1  mrg 	{
   1070  1.1  mrg 	  arm_initialize_isa (cand_fpubits, all_fpus[i].isa_bits);
   1071  1.1  mrg 	  if (bitmap_equal_p (fpubits, cand_fpubits))
   1072  1.1  mrg 	    {
   1073  1.1  mrg 	      fpuname = all_fpus[i].name;
   1074  1.1  mrg 	      break;
   1075  1.1  mrg 	    }
   1076  1.1  mrg 	}
   1077  1.1  mrg 
   1078  1.1  mrg       gcc_assert (i != TARGET_FPU_auto
   1079  1.1  mrg 		  || bitmap_bit_p (target_isa, isa_bit_vfp_base));
   1080  1.1  mrg     }
   1081  1.1  mrg 
   1082  1.1  mrg   auto_fpu = (char *) xmalloc (strlen (fpuname) + sizeof ("-mfpu="));
   1083  1.1  mrg   strcpy (auto_fpu, "-mfpu=");
   1084  1.1  mrg   strcat (auto_fpu, fpuname);
   1085  1.1  mrg   return auto_fpu;
   1086  1.1  mrg }
   1087  1.1  mrg 
   1088  1.1  mrg #undef ARM_CPU_NAME_LENGTH
   1089  1.1  mrg 
   1090  1.1  mrg 
   1091  1.1  mrg #undef  TARGET_DEFAULT_TARGET_FLAGS
   1092  1.1  mrg #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
   1093  1.1  mrg 
   1094  1.1  mrg #undef  TARGET_OPTION_OPTIMIZATION_TABLE
   1095  1.1  mrg #define TARGET_OPTION_OPTIMIZATION_TABLE arm_option_optimization_table
   1096  1.1  mrg 
   1097  1.1  mrg #undef TARGET_EXCEPT_UNWIND_INFO
   1098  1.1  mrg #define TARGET_EXCEPT_UNWIND_INFO  arm_except_unwind_info
   1099  1.1  mrg 
   1100  1.1  mrg struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
   1101  1.1  mrg 
   1102  1.1  mrg /* Returns a canonical representation of the -march option from the current
   1103  1.1  mrg    -march string (if given) and other options on the command line that might
   1104  1.1  mrg    affect the architecture.  */
   1105  1.1  mrg const char *
   1106  1.1  mrg arm_canon_arch_option (int argc, const char **argv)
   1107  1.1  mrg {
   1108  1.1  mrg   return arm_canon_arch_option_1 (argc, argv, false);
   1109  1.1  mrg }
   1110  1.1  mrg 
   1111  1.1  mrg /* Returns a canonical representation of the -mlibarch option from the current
   1112  1.1  mrg    -march string (if given) and other options on the command line that might
   1113  1.1  mrg    affect the architecture after removing the compiler extension options which
   1114  1.1  mrg    are not required for multilib linking.  */
   1115  1.1  mrg const char *
   1116  1.1  mrg arm_canon_arch_multilib_option (int argc, const char **argv)
   1117  1.1  mrg {
   1118  1.1  mrg   return arm_canon_arch_option_1 (argc, argv, true);
   1119  1.1  mrg }
   1120