]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/common/config/aarch64/aarch64-common.c
[AArch64] Fix behaviour of -mcpu option to match ARM.
[thirdparty/gcc.git] / gcc / common / config / aarch64 / aarch64-common.c
1 /* Common hooks for AArch64.
2 Copyright (C) 2012-2014 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
31 #ifdef TARGET_BIG_ENDIAN_DEFAULT
32 #undef TARGET_DEFAULT_TARGET_FLAGS
33 #define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_END)
34 #endif
35
36 #undef TARGET_HANDLE_OPTION
37 #define TARGET_HANDLE_OPTION aarch64_handle_option
38
39 #undef TARGET_OPTION_OPTIMIZATION_TABLE
40 #define TARGET_OPTION_OPTIMIZATION_TABLE aarch_option_optimization_table
41
42 /* Set default optimization options. */
43 static const struct default_options aarch_option_optimization_table[] =
44 {
45 /* Enable section anchors by default at -O1 or higher. */
46 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
47 /* Enable redundant extension instructions removal at -O2 and higher. */
48 { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
49 { OPT_LEVELS_NONE, 0, NULL, 0 }
50 };
51
52 /* Implement TARGET_HANDLE_OPTION.
53 This function handles the target specific options for CPU/target selection.
54
55 -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU.
56 If either of -march or -mtune is given, they override their
57 respective component of -mcpu. This logic is implemented
58 in config/aarch64/aarch64.c:aarch64_override_options. */
59
60 static bool
61 aarch64_handle_option (struct gcc_options *opts,
62 struct gcc_options *opts_set ATTRIBUTE_UNUSED,
63 const struct cl_decoded_option *decoded,
64 location_t loc ATTRIBUTE_UNUSED)
65 {
66 size_t code = decoded->opt_index;
67 const char *arg = decoded->arg;
68
69 switch (code)
70 {
71 case OPT_march_:
72 opts->x_aarch64_arch_string = arg;
73 return true;
74
75 case OPT_mcpu_:
76 opts->x_aarch64_cpu_string = arg;
77 return true;
78
79 case OPT_mtune_:
80 opts->x_aarch64_tune_string = arg;
81 return true;
82
83 default:
84 return true;
85 }
86 }
87
88 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
89
90 #define AARCH64_CPU_NAME_LENGTH 20
91
92 /* Truncate NAME at the first '.' character seen, or return
93 NAME unmodified. */
94
95 const char *
96 aarch64_rewrite_selected_cpu (const char *name)
97 {
98 static char output_buf[AARCH64_CPU_NAME_LENGTH + 1] = {0};
99 char *arg_pos;
100
101 strncpy (output_buf, name, AARCH64_CPU_NAME_LENGTH);
102 arg_pos = strchr (output_buf, '.');
103
104 /* If we found a '.' truncate the entry at that point. */
105 if (arg_pos)
106 *arg_pos = '\0';
107
108 return output_buf;
109 }
110
111 /* Called by the driver to rewrite a name passed to the -mcpu
112 argument in preparation to be passed to the assembler. The
113 name will be in ARGV[0], ARGC should always be 1. */
114
115 const char *
116 aarch64_rewrite_mcpu (int argc, const char **argv)
117 {
118 gcc_assert (argc == 1);
119 return aarch64_rewrite_selected_cpu (argv[0]);
120 }
121
122 #undef AARCH64_CPU_NAME_LENGTH
123