xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/common/config/arm/arm-common.c (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1 /* Common hooks for ARM.
2    Copyright (C) 1991-2017 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 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "memmodel.h"
25 #include "tm_p.h"
26 #include "common/common-target.h"
27 #include "common/common-target-def.h"
28 #include "opts.h"
29 #include "flags.h"
30 
31 /* Set default optimization options.  */
32 static const struct default_options arm_option_optimization_table[] =
33   {
34     /* Enable section anchors by default at -O1 or higher.  */
35     { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
36     { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
37     { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
38     { OPT_LEVELS_NONE, 0, NULL, 0 }
39   };
40 
41 /* Implement TARGET_EXCEPT_UNWIND_INFO.  */
42 
43 enum unwind_info_type
44 arm_except_unwind_info (struct gcc_options *opts)
45 {
46   /* Honor the --enable-sjlj-exceptions configure switch.  */
47 #ifdef CONFIG_SJLJ_EXCEPTIONS
48   if (CONFIG_SJLJ_EXCEPTIONS)
49     return UI_SJLJ;
50 #endif
51 
52   if (ARM_DWARF_UNWIND_TABLES)
53     return UI_DWARF2;
54 
55   /* If not using ARM EABI unwind tables... */
56   if (ARM_UNWIND_INFO)
57     {
58       /* For simplicity elsewhere in this file, indicate that all unwind
59 	 info is disabled if we're not emitting unwind tables.  */
60       if (!opts->x_flag_exceptions && !opts->x_flag_unwind_tables)
61 	return UI_NONE;
62       else
63 	return UI_TARGET;
64     }
65 
66   /* ... we use sjlj exceptions for backwards compatibility.  */
67   return UI_SJLJ;
68 }
69 
70 #define ARM_CPU_NAME_LENGTH 20
71 
72 /* Truncate NAME at the first '.' character seen, or return
73    NAME unmodified.  */
74 
75 const char *
76 arm_rewrite_selected_cpu (const char *name)
77 {
78   static char output_buf[ARM_CPU_NAME_LENGTH + 1] = {0};
79   char *arg_pos;
80 
81   strncpy (output_buf, name, ARM_CPU_NAME_LENGTH);
82   arg_pos = strchr (output_buf, '.');
83 
84   /* If we found a '.' truncate the entry at that point.  */
85   if (arg_pos)
86     *arg_pos = '\0';
87 
88   return output_buf;
89 }
90 
91 /* Called by the driver to rewrite a name passed to the -mcpu
92    argument in preparation to be passed to the assembler.  The
93    names passed from the command line will be in ARGV, we want
94    to use the right-most argument, which should be in
95    ARGV[ARGC - 1].  ARGC should always be greater than 0.  */
96 
97 const char *
98 arm_rewrite_mcpu (int argc, const char **argv)
99 {
100   gcc_assert (argc);
101   return arm_rewrite_selected_cpu (argv[argc - 1]);
102 }
103 
104 struct arm_arch_core_flag
105 {
106   const char *const name;
107   const enum isa_feature isa_bits[isa_num_bits];
108 };
109 
110 #include "config/arm/arm-cpu-cdata.h"
111 
112 /* Scan over a raw feature array BITS checking for BIT being present.
113    This is slower than the normal bitmask checks, but we would spend longer
114    initializing that than doing the check this way.  Returns true iff
115    BIT is found.  */
116 static bool
117 check_isa_bits_for (const enum isa_feature* bits, enum isa_feature bit)
118 {
119   while (*bits != isa_nobit)
120     if (*bits++ == bit)
121       return true;
122 
123   return false;
124 }
125 
126 /* Called by the driver to check whether the target denoted by current
127    command line options is a Thumb-only target.  ARGV is an array of
128    -march and -mcpu values (ie. it contains the rhs after the equal
129    sign) and we use the last one of them to make a decision.  The
130    number of elements in ARGV is given in ARGC.  */
131 const char *
132 arm_target_thumb_only (int argc, const char **argv)
133 {
134   unsigned int opt;
135 
136   if (argc)
137     {
138       for (opt = 0; opt < (ARRAY_SIZE (arm_arch_core_flags)); opt++)
139 	if ((strcmp (argv[argc - 1], arm_arch_core_flags[opt].name) == 0)
140 	    && !check_isa_bits_for (arm_arch_core_flags[opt].isa_bits,
141 				    isa_bit_notm))
142 	  return "-mthumb";
143 
144       return NULL;
145     }
146   else
147     return NULL;
148 }
149 
150 #undef ARM_CPU_NAME_LENGTH
151 
152 
153 #undef  TARGET_DEFAULT_TARGET_FLAGS
154 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | MASK_SCHED_PROLOG)
155 
156 #undef  TARGET_OPTION_OPTIMIZATION_TABLE
157 #define TARGET_OPTION_OPTIMIZATION_TABLE arm_option_optimization_table
158 
159 #undef TARGET_EXCEPT_UNWIND_INFO
160 #define TARGET_EXCEPT_UNWIND_INFO  arm_except_unwind_info
161 
162 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
163