]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/arm/arm-c.c
arm-arches.def: Add "armv6kz".
[thirdparty/gcc.git] / gcc / config / arm / arm-c.c
1 /* Copyright (C) 2007-2015 Free Software Foundation, Inc.
2
3 This file is part of GCC.
4
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
8 version.
9
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GCC; see the file COPYING3. If not see
17 <http://www.gnu.org/licenses/>. */
18
19 #include "config.h"
20 #include "system.h"
21 #include "coretypes.h"
22 #include "tm.h"
23 #include "tm_p.h"
24 #include "alias.h"
25 #include "tree.h"
26 #include "tm_p.h"
27 #include "c-family/c-common.h"
28 #include "target.h"
29 #include "c-family/c-pragma.h"
30
31 /* Output C specific EABI object attributes. These can not be done in
32 arm.c because they require information from the C frontend. */
33
34 static void
35 arm_output_c_attributes (void)
36 {
37 int wchar_size = (int)(TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);
38 arm_emit_eabi_attribute ("Tag_ABI_PCS_wchar_t", 18, wchar_size);
39 }
40
41
42 /* Setup so that common code calls arm_output_c_attributes. */
43
44 void
45 arm_lang_object_attributes_init (void)
46 {
47 arm_lang_output_object_attributes_hook = arm_output_c_attributes;
48 }
49
50 #define builtin_define(TXT) cpp_define (pfile, TXT)
51 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
52
53 /* Define or undefine macros based on the current target. If the user does
54 #pragma GCC target, we need to adjust the macros dynamically. */
55
56 static void
57 def_or_undef_macro(struct cpp_reader* pfile, const char *name, bool def_p)
58 {
59 if (def_p)
60 cpp_define (pfile, name);
61 else
62 cpp_undef (pfile, name);
63 }
64
65 void
66 arm_cpu_builtins (struct cpp_reader* pfile, int flags)
67 {
68 def_or_undef_macro (pfile, "__ARM_FEATURE_DSP",
69 TARGET_DSP_MULTIPLY_P (flags));
70 def_or_undef_macro (pfile, "__ARM_FEATURE_QBIT",
71 TARGET_ARM_QBIT_P (flags));
72 def_or_undef_macro (pfile, "__ARM_FEATURE_SAT",
73 TARGET_ARM_SAT_P (flags));
74 if (TARGET_CRYPTO)
75 builtin_define ("__ARM_FEATURE_CRYPTO");
76 if (unaligned_access)
77 builtin_define ("__ARM_FEATURE_UNALIGNED");
78 if (TARGET_CRC32)
79 builtin_define ("__ARM_FEATURE_CRC32");
80
81 def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT_P (flags));
82
83 if (TARGET_ARM_FEATURE_LDREX_P (flags))
84 builtin_define_with_int_value ("__ARM_FEATURE_LDREX",
85 TARGET_ARM_FEATURE_LDREX_P (flags));
86 else
87 cpp_undef (pfile, "__ARM_FEATURE_LDREX");
88
89 def_or_undef_macro (pfile, "__ARM_FEATURE_CLZ",
90 ((TARGET_ARM_ARCH >= 5 && !TARGET_THUMB_P (flags))
91 || TARGET_ARM_ARCH_ISA_THUMB >=2));
92
93 def_or_undef_macro (pfile, "__ARM_FEATURE_SIMD32", TARGET_INT_SIMD_P (flags));
94
95 builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM",
96 flag_short_enums ? 1 : 4);
97 builtin_define_type_sizeof ("__ARM_SIZEOF_WCHAR_T", wchar_type_node);
98 if (TARGET_ARM_ARCH_PROFILE)
99 builtin_define_with_int_value ("__ARM_ARCH_PROFILE",
100 TARGET_ARM_ARCH_PROFILE);
101
102 /* Define __arm__ even when in thumb mode, for
103 consistency with armcc. */
104 builtin_define ("__arm__");
105 if (TARGET_ARM_ARCH)
106 builtin_define_with_int_value ("__ARM_ARCH", TARGET_ARM_ARCH);
107 if (arm_arch_notm)
108 builtin_define ("__ARM_ARCH_ISA_ARM");
109 builtin_define ("__APCS_32__");
110
111 def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB_P (flags));
112 def_or_undef_macro (pfile, "__thumb2__", TARGET_THUMB2_P (flags));
113 if (TARGET_BIG_END)
114 def_or_undef_macro (pfile, "__THUMBEB__", TARGET_THUMB_P (flags));
115 else
116 def_or_undef_macro (pfile, "__THUMBEL__", TARGET_THUMB_P (flags));
117
118 if (TARGET_ARM_ARCH_ISA_THUMB)
119 builtin_define_with_int_value ("__ARM_ARCH_ISA_THUMB",
120 TARGET_ARM_ARCH_ISA_THUMB);
121
122 if (TARGET_BIG_END)
123 {
124 builtin_define ("__ARMEB__");
125 builtin_define ("__ARM_BIG_ENDIAN");
126 }
127 else
128 {
129 builtin_define ("__ARMEL__");
130 }
131
132 if (TARGET_SOFT_FLOAT)
133 builtin_define ("__SOFTFP__");
134
135 if (TARGET_VFP)
136 builtin_define ("__VFP_FP__");
137
138 if (TARGET_ARM_FP)
139 builtin_define_with_int_value ("__ARM_FP", TARGET_ARM_FP);
140 if (arm_fp16_format == ARM_FP16_FORMAT_IEEE)
141 builtin_define ("__ARM_FP16_FORMAT_IEEE");
142 if (arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE)
143 builtin_define ("__ARM_FP16_FORMAT_ALTERNATIVE");
144 if (TARGET_FMA)
145 builtin_define ("__ARM_FEATURE_FMA");
146
147 if (TARGET_NEON)
148 {
149 builtin_define ("__ARM_NEON__");
150 builtin_define ("__ARM_NEON");
151 }
152 if (TARGET_NEON_FP)
153 builtin_define_with_int_value ("__ARM_NEON_FP", TARGET_NEON_FP);
154
155 /* Add a define for interworking. Needed when building libgcc.a. */
156 if (arm_cpp_interwork)
157 builtin_define ("__THUMB_INTERWORK__");
158
159
160 builtin_define (arm_arch_name);
161 if (arm_arch_xscale)
162 builtin_define ("__XSCALE__");
163 if (arm_arch_iwmmxt)
164 {
165 builtin_define ("__IWMMXT__");
166 builtin_define ("__ARM_WMMX");
167 }
168 if (arm_arch_iwmmxt2)
169 builtin_define ("__IWMMXT2__");
170 /* ARMv6KZ was originally identified as the misspelled __ARM_ARCH_6ZK__. To
171 preserve the existing behaviour, the misspelled feature macro must still be
172 defined. */
173 if (arm_arch6kz)
174 builtin_define ("__ARM_ARCH_6ZK__");
175 if (TARGET_AAPCS_BASED)
176 {
177 if (arm_pcs_default == ARM_PCS_AAPCS_VFP)
178 builtin_define ("__ARM_PCS_VFP");
179 else if (arm_pcs_default == ARM_PCS_AAPCS)
180 builtin_define ("__ARM_PCS");
181 builtin_define ("__ARM_EABI__");
182 }
183
184 def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV_P (flags));
185 def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV_P (flags));
186
187 def_or_undef_macro (pfile, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified);
188 }
189
190 void
191 arm_cpu_cpp_builtins (struct cpp_reader * pfile)
192 {
193 builtin_assert ("cpu=arm");
194 builtin_assert ("machine=arm");
195
196 arm_cpu_builtins (pfile, target_flags);
197 }
198
199 /* Hook to validate the current #pragma GCC target and set the arch custom
200 mode state. If ARGS is NULL, then POP_TARGET is used to reset
201 the options. */
202 static bool
203 arm_pragma_target_parse (tree args, tree pop_target)
204 {
205 tree prev_tree = build_target_option_node (&global_options);
206 tree cur_tree;
207 struct cl_target_option *prev_opt;
208 struct cl_target_option *cur_opt;
209
210 if (! args)
211 {
212 cur_tree = ((pop_target) ? pop_target : target_option_default_node);
213 cl_target_option_restore (&global_options,
214 TREE_TARGET_OPTION (cur_tree));
215 }
216 else
217 {
218 cur_tree = arm_valid_target_attribute_tree (args, &global_options,
219 &global_options_set);
220 if (cur_tree == NULL_TREE)
221 {
222 cl_target_option_restore (&global_options,
223 TREE_TARGET_OPTION (prev_tree));
224 return false;
225 }
226 }
227
228 target_option_current_node = cur_tree;
229 arm_reset_previous_fndecl ();
230
231 /* Figure out the previous mode. */
232 prev_opt = TREE_TARGET_OPTION (prev_tree);
233 cur_opt = TREE_TARGET_OPTION (cur_tree);
234
235 gcc_assert (prev_opt);
236 gcc_assert (cur_opt);
237
238 if (cur_opt->x_target_flags != prev_opt->x_target_flags)
239 {
240 /* For the definitions, ensure all newly defined macros are considered
241 as used for -Wunused-macros. There is no point warning about the
242 compiler predefined macros. */
243 cpp_options *cpp_opts = cpp_get_options (parse_in);
244 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
245 cpp_opts->warn_unused_macros = 0;
246
247 /* Update macros. */
248 arm_cpu_builtins (parse_in, cur_opt->x_target_flags);
249
250 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
251 }
252
253 return true;
254 }
255
256 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
257 option here rather than in arm.c since it will pull in various preprocessor
258 functions, and those are not present in languages like fortran without a
259 preprocessor. */
260
261 void
262 arm_register_target_pragmas (void)
263 {
264 /* Update pragma hook to allow parsing #pragma GCC target. */
265 targetm.target_option.pragma_parse = arm_pragma_target_parse;
266
267 #ifdef REGISTER_SUBTARGET_PRAGMAS
268 REGISTER_SUBTARGET_PRAGMAS ();
269 #endif
270 }