]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/common/config/aarch64/aarch64-common.c
[AArch64] Increase static buffer size in aarch64_rewrite_selected_cpu
[thirdparty/gcc.git] / gcc / common / config / aarch64 / aarch64-common.c
1 /* Common hooks for AArch64.
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.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 #include "errors.h"
31
32 #ifdef TARGET_BIG_ENDIAN_DEFAULT
33 #undef TARGET_DEFAULT_TARGET_FLAGS
34 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_END)
35 #endif
36
37 #undef TARGET_HANDLE_OPTION
38 #define TARGET_HANDLE_OPTION aarch64_handle_option
39
40 #undef TARGET_OPTION_OPTIMIZATION_TABLE
41 #define TARGET_OPTION_OPTIMIZATION_TABLE aarch_option_optimization_table
42
43 /* Set default optimization options. */
44 static const struct default_options aarch_option_optimization_table[] =
45 {
46 /* Enable section anchors by default at -O1 or higher. */
47 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
48 /* Enable -fsched-pressure by default when optimizing. */
49 { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 },
50 /* Enable redundant extension instructions removal at -O2 and higher. */
51 { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
52 { OPT_LEVELS_NONE, 0, NULL, 0 }
53 };
54
55 /* Implement TARGET_HANDLE_OPTION.
56 This function handles the target specific options for CPU/target selection.
57
58 -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU.
59 If either of -march or -mtune is given, they override their
60 respective component of -mcpu. This logic is implemented
61 in config/aarch64/aarch64.c:aarch64_override_options. */
62
63 static bool
64 aarch64_handle_option (struct gcc_options *opts,
65 struct gcc_options *opts_set ATTRIBUTE_UNUSED,
66 const struct cl_decoded_option *decoded,
67 location_t loc ATTRIBUTE_UNUSED)
68 {
69 size_t code = decoded->opt_index;
70 const char *arg = decoded->arg;
71
72 switch (code)
73 {
74 case OPT_march_:
75 opts->x_aarch64_arch_string = arg;
76 return true;
77
78 case OPT_mcpu_:
79 opts->x_aarch64_cpu_string = arg;
80 return true;
81
82 case OPT_mtune_:
83 opts->x_aarch64_tune_string = arg;
84 return true;
85
86 default:
87 return true;
88 }
89 }
90
91 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
92
93 #define AARCH64_CPU_NAME_LENGTH 128
94
95 /* Truncate NAME at the first '.' character seen up to the first '+'
96 or return NAME unmodified. */
97
98 const char *
99 aarch64_rewrite_selected_cpu (const char *name)
100 {
101 static char output_buf[AARCH64_CPU_NAME_LENGTH + 1] = {0};
102 const char *bL_sep;
103 const char *feats;
104 size_t pref_size;
105 size_t feat_size;
106
107 bL_sep = strchr (name, '.');
108 if (!bL_sep)
109 return name;
110
111 feats = strchr (name, '+');
112 feat_size = feats ? strnlen (feats, AARCH64_CPU_NAME_LENGTH) : 0;
113 pref_size = bL_sep - name;
114
115 if ((feat_size + pref_size) > AARCH64_CPU_NAME_LENGTH)
116 internal_error ("-mcpu string too large");
117
118 strncpy (output_buf, name, pref_size);
119 if (feats)
120 strncpy (output_buf + pref_size, feats, feat_size);
121
122 return output_buf;
123 }
124
125 /* Called by the driver to rewrite a name passed to the -mcpu
126 argument in preparation to be passed to the assembler. The
127 names passed from the commend line will be in ARGV, we want
128 to use the right-most argument, which should be in
129 ARGV[ARGC - 1]. ARGC should always be greater than 0. */
130
131 const char *
132 aarch64_rewrite_mcpu (int argc, const char **argv)
133 {
134 gcc_assert (argc);
135 return aarch64_rewrite_selected_cpu (argv[argc - 1]);
136 }
137
138 #undef AARCH64_CPU_NAME_LENGTH
139