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