Debian Codegraph @

gcc/common/config/arm/arm-common.cc

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