]>
Commit | Line | Data |
---|---|---|
8d9254fc | 1 | /* Copyright (C) 2007-2020 Free Software Foundation, Inc. |
ad41bd84 | 2 | |
58e9ddb1 | 3 | This file is part of GCC. |
ad41bd84 | 4 | |
58e9ddb1 NC |
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. | |
ad41bd84 | 9 | |
58e9ddb1 NC |
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. | |
ad41bd84 | 14 | |
58e9ddb1 NC |
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/>. */ | |
ad41bd84 | 18 | |
8fcc61f8 RS |
19 | #define IN_TARGET_CODE 1 |
20 | ||
b76c3c4b PB |
21 | #include "config.h" |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
c84f825c | 24 | #include "target.h" |
e11c4407 | 25 | #include "c-family/c-common.h" |
4d0cdd0c | 26 | #include "memmodel.h" |
e11c4407 | 27 | #include "tm_p.h" |
c84f825c | 28 | #include "c-family/c-pragma.h" |
81b9a3d9 | 29 | #include "stringpool.h" |
b76c3c4b | 30 | |
67914693 | 31 | /* Output C specific EABI object attributes. These cannot be done in |
b76c3c4b PB |
32 | arm.c because they require information from the C frontend. */ |
33 | ||
58e9ddb1 NC |
34 | static void |
35 | arm_output_c_attributes (void) | |
b76c3c4b | 36 | { |
34dd397b SB |
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); | |
b76c3c4b PB |
39 | } |
40 | ||
41 | ||
42 | /* Setup so that common code calls arm_output_c_attributes. */ | |
43 | ||
58e9ddb1 NC |
44 | void |
45 | arm_lang_object_attributes_init (void) | |
b76c3c4b PB |
46 | { |
47 | arm_lang_output_object_attributes_hook = arm_output_c_attributes; | |
48 | } | |
7049e4eb CB |
49 | |
50 | #define builtin_define(TXT) cpp_define (pfile, TXT) | |
51 | #define builtin_assert(TXT) cpp_assert (pfile, TXT) | |
52 | ||
08793a38 CB |
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 | |
c8b6aa7c | 57 | def_or_undef_macro(struct cpp_reader* pfile, const char *name, bool def_p) |
08793a38 CB |
58 | { |
59 | if (def_p) | |
c8b6aa7c CB |
60 | cpp_define (pfile, name); |
61 | else | |
62 | cpp_undef (pfile, name); | |
63 | } | |
08793a38 | 64 | |
c8b6aa7c CB |
65 | static void |
66 | arm_cpu_builtins (struct cpp_reader* pfile) | |
7049e4eb | 67 | { |
c8b6aa7c | 68 | def_or_undef_macro (pfile, "__ARM_FEATURE_DSP", TARGET_DSP_MULTIPLY); |
c4808382 | 69 | def_or_undef_macro (pfile, "__ARM_FEATURE_QBIT", TARGET_ARM_QBIT); |
c8b6aa7c | 70 | def_or_undef_macro (pfile, "__ARM_FEATURE_SAT", TARGET_ARM_SAT); |
c9106282 CB |
71 | def_or_undef_macro (pfile, "__ARM_FEATURE_CRYPTO", TARGET_CRYPTO); |
72 | ||
5797378a CB |
73 | def_or_undef_macro (pfile, "__ARM_FEATURE_UNALIGNED", unaligned_access); |
74 | ||
c4808382 MW |
75 | def_or_undef_macro (pfile, "__ARM_FEATURE_QRDMX", TARGET_NEON_RDMA); |
76 | ||
ba09dd21 TC |
77 | def_or_undef_macro (pfile, "__ARM_FEATURE_CRC32", TARGET_CRC32); |
78 | def_or_undef_macro (pfile, "__ARM_FEATURE_DOTPROD", TARGET_DOTPROD); | |
c2b7062d | 79 | def_or_undef_macro (pfile, "__ARM_FEATURE_COMPLEX", TARGET_COMPLEX); |
c4808382 | 80 | def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT); |
08793a38 | 81 | |
ba09dd21 | 82 | cpp_undef (pfile, "__ARM_FEATURE_CMSE"); |
de7b5723 AV |
83 | if (arm_arch8 && !arm_arch_notm) |
84 | { | |
85 | if (arm_arch_cmse && use_cmse) | |
86 | builtin_define_with_int_value ("__ARM_FEATURE_CMSE", 3); | |
87 | else | |
88 | builtin_define ("__ARM_FEATURE_CMSE"); | |
89 | } | |
90 | ||
0079ae88 | 91 | cpp_undef (pfile, "__ARM_FEATURE_LDREX"); |
c8b6aa7c | 92 | if (TARGET_ARM_FEATURE_LDREX) |
c4808382 | 93 | builtin_define_with_int_value ("__ARM_FEATURE_LDREX", |
c8b6aa7c | 94 | TARGET_ARM_FEATURE_LDREX); |
08793a38 CB |
95 | |
96 | def_or_undef_macro (pfile, "__ARM_FEATURE_CLZ", | |
c8b6aa7c | 97 | ((TARGET_ARM_ARCH >= 5 && !TARGET_THUMB) |
08793a38 CB |
98 | || TARGET_ARM_ARCH_ISA_THUMB >=2)); |
99 | ||
9fc158eb | 100 | def_or_undef_macro (pfile, "__ARM_FEATURE_NUMERIC_MAXMIN", |
c2fc3462 | 101 | TARGET_ARM_ARCH >= 8 && TARGET_NEON && TARGET_VFP5); |
9fc158eb | 102 | |
c8b6aa7c | 103 | def_or_undef_macro (pfile, "__ARM_FEATURE_SIMD32", TARGET_INT_SIMD); |
7049e4eb CB |
104 | |
105 | builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM", | |
106 | flag_short_enums ? 1 : 4); | |
107 | builtin_define_type_sizeof ("__ARM_SIZEOF_WCHAR_T", wchar_type_node); | |
0079ae88 TC |
108 | |
109 | cpp_undef (pfile, "__ARM_ARCH_PROFILE"); | |
7049e4eb CB |
110 | if (TARGET_ARM_ARCH_PROFILE) |
111 | builtin_define_with_int_value ("__ARM_ARCH_PROFILE", | |
112 | TARGET_ARM_ARCH_PROFILE); | |
113 | ||
114 | /* Define __arm__ even when in thumb mode, for | |
115 | consistency with armcc. */ | |
116 | builtin_define ("__arm__"); | |
117 | if (TARGET_ARM_ARCH) | |
d10ac880 TC |
118 | { |
119 | cpp_undef (pfile, "__ARM_ARCH"); | |
120 | builtin_define_with_int_value ("__ARM_ARCH", TARGET_ARM_ARCH); | |
121 | } | |
7049e4eb CB |
122 | if (arm_arch_notm) |
123 | builtin_define ("__ARM_ARCH_ISA_ARM"); | |
124 | builtin_define ("__APCS_32__"); | |
35ba842f RH |
125 | |
126 | def_or_undef_macro (pfile, "__GCC_ASM_FLAG_OUTPUTS__", !TARGET_THUMB1); | |
08793a38 | 127 | |
c8b6aa7c CB |
128 | def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB); |
129 | def_or_undef_macro (pfile, "__thumb2__", TARGET_THUMB2); | |
08793a38 | 130 | if (TARGET_BIG_END) |
c8b6aa7c | 131 | def_or_undef_macro (pfile, "__THUMBEB__", TARGET_THUMB); |
08793a38 | 132 | else |
c8b6aa7c | 133 | def_or_undef_macro (pfile, "__THUMBEL__", TARGET_THUMB); |
08793a38 | 134 | |
0079ae88 | 135 | cpp_undef (pfile, "__ARM_ARCH_ISA_THUMB"); |
7049e4eb CB |
136 | if (TARGET_ARM_ARCH_ISA_THUMB) |
137 | builtin_define_with_int_value ("__ARM_ARCH_ISA_THUMB", | |
138 | TARGET_ARM_ARCH_ISA_THUMB); | |
139 | ||
140 | if (TARGET_BIG_END) | |
141 | { | |
142 | builtin_define ("__ARMEB__"); | |
143 | builtin_define ("__ARM_BIG_ENDIAN"); | |
7049e4eb CB |
144 | } |
145 | else | |
146 | { | |
147 | builtin_define ("__ARMEL__"); | |
7049e4eb CB |
148 | } |
149 | ||
150 | if (TARGET_SOFT_FLOAT) | |
151 | builtin_define ("__SOFTFP__"); | |
152 | ||
00ea1506 | 153 | builtin_define ("__VFP_FP__"); |
c9106282 | 154 | |
0079ae88 | 155 | cpp_undef (pfile, "__ARM_FP"); |
7049e4eb CB |
156 | if (TARGET_ARM_FP) |
157 | builtin_define_with_int_value ("__ARM_FP", TARGET_ARM_FP); | |
b8c7c62b | 158 | |
1b81a1c1 MW |
159 | def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_IEEE", |
160 | arm_fp16_format == ARM_FP16_FORMAT_IEEE); | |
161 | def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_ALTERNATIVE", | |
162 | arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE); | |
163 | def_or_undef_macro (pfile, "__ARM_FP16_ARGS", | |
164 | arm_fp16_format != ARM_FP16_FORMAT_NONE); | |
7049e4eb | 165 | |
536b9f42 MW |
166 | def_or_undef_macro (pfile, "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", |
167 | TARGET_VFP_FP16INST); | |
168 | def_or_undef_macro (pfile, "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", | |
169 | TARGET_NEON_FP16INST); | |
06e95715 | 170 | def_or_undef_macro (pfile, "__ARM_FEATURE_FP16_FML", TARGET_FP16FML); |
536b9f42 | 171 | |
b8c7c62b | 172 | def_or_undef_macro (pfile, "__ARM_FEATURE_FMA", TARGET_FMA); |
c9106282 CB |
173 | def_or_undef_macro (pfile, "__ARM_NEON__", TARGET_NEON); |
174 | def_or_undef_macro (pfile, "__ARM_NEON", TARGET_NEON); | |
175 | ||
0079ae88 | 176 | cpp_undef (pfile, "__ARM_NEON_FP"); |
7049e4eb CB |
177 | if (TARGET_NEON_FP) |
178 | builtin_define_with_int_value ("__ARM_NEON_FP", TARGET_NEON_FP); | |
c9106282 | 179 | |
7049e4eb CB |
180 | /* Add a define for interworking. Needed when building libgcc.a. */ |
181 | if (arm_cpp_interwork) | |
182 | builtin_define ("__THUMB_INTERWORK__"); | |
183 | ||
7049e4eb CB |
184 | builtin_define (arm_arch_name); |
185 | if (arm_arch_xscale) | |
186 | builtin_define ("__XSCALE__"); | |
187 | if (arm_arch_iwmmxt) | |
188 | { | |
189 | builtin_define ("__IWMMXT__"); | |
190 | builtin_define ("__ARM_WMMX"); | |
191 | } | |
192 | if (arm_arch_iwmmxt2) | |
193 | builtin_define ("__IWMMXT2__"); | |
39c12541 | 194 | /* ARMv6KZ was originally identified as the misspelled __ARM_ARCH_6ZK__. To |
9c582551 | 195 | preserve the existing behavior, the misspelled feature macro must still be |
39c12541 MW |
196 | defined. */ |
197 | if (arm_arch6kz) | |
198 | builtin_define ("__ARM_ARCH_6ZK__"); | |
7049e4eb CB |
199 | if (TARGET_AAPCS_BASED) |
200 | { | |
201 | if (arm_pcs_default == ARM_PCS_AAPCS_VFP) | |
202 | builtin_define ("__ARM_PCS_VFP"); | |
203 | else if (arm_pcs_default == ARM_PCS_AAPCS) | |
204 | builtin_define ("__ARM_PCS"); | |
205 | builtin_define ("__ARM_EABI__"); | |
206 | } | |
08793a38 | 207 | |
8b63716e CL |
208 | def_or_undef_macro (pfile, "__FDPIC__", TARGET_FDPIC); |
209 | ||
c8b6aa7c CB |
210 | def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV); |
211 | def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV); | |
08793a38 CB |
212 | |
213 | def_or_undef_macro (pfile, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified); | |
b5c7b957 | 214 | |
d10ac880 | 215 | cpp_undef (pfile, "__ARM_FEATURE_COPROC"); |
b5c7b957 TP |
216 | if (TARGET_32BIT && arm_arch4 && !(arm_arch8 && arm_arch_notm)) |
217 | { | |
218 | int coproc_level = 0x1; | |
219 | ||
c3f808d3 | 220 | if (arm_arch5t) |
b5c7b957 | 221 | coproc_level |= 0x2; |
c3f808d3 | 222 | if (arm_arch5te) |
b5c7b957 TP |
223 | coproc_level |= 0x4; |
224 | if (arm_arch6) | |
225 | coproc_level |= 0x8; | |
226 | ||
227 | builtin_define_with_int_value ("__ARM_FEATURE_COPROC", coproc_level); | |
228 | } | |
f782b667 DZ |
229 | |
230 | def_or_undef_macro (pfile, "__ARM_FEATURE_MATMUL_INT8", TARGET_I8MM); | |
231 | def_or_undef_macro (pfile, "__ARM_FEATURE_BF16_SCALAR_ARITHMETIC", | |
232 | TARGET_BF16_FP); | |
233 | def_or_undef_macro (pfile, "__ARM_FEATURE_BF16_VECTOR_ARITHMETIC", | |
234 | TARGET_BF16_SIMD); | |
235 | def_or_undef_macro (pfile, "__ARM_BF16_FORMAT_ALTERNATIVE", | |
236 | TARGET_BF16_FP || TARGET_BF16_SIMD); | |
7049e4eb | 237 | } |
c84f825c CB |
238 | |
239 | void | |
240 | arm_cpu_cpp_builtins (struct cpp_reader * pfile) | |
241 | { | |
242 | builtin_assert ("cpu=arm"); | |
243 | builtin_assert ("machine=arm"); | |
244 | ||
c8b6aa7c | 245 | arm_cpu_builtins (pfile); |
c84f825c CB |
246 | } |
247 | ||
248 | /* Hook to validate the current #pragma GCC target and set the arch custom | |
249 | mode state. If ARGS is NULL, then POP_TARGET is used to reset | |
250 | the options. */ | |
e8449dec | 251 | |
c84f825c CB |
252 | static bool |
253 | arm_pragma_target_parse (tree args, tree pop_target) | |
254 | { | |
dab73e73 | 255 | tree prev_tree = target_option_current_node; |
c84f825c CB |
256 | tree cur_tree; |
257 | struct cl_target_option *prev_opt; | |
258 | struct cl_target_option *cur_opt; | |
259 | ||
260 | if (! args) | |
261 | { | |
262 | cur_tree = ((pop_target) ? pop_target : target_option_default_node); | |
263 | cl_target_option_restore (&global_options, | |
264 | TREE_TARGET_OPTION (cur_tree)); | |
265 | } | |
266 | else | |
267 | { | |
268 | cur_tree = arm_valid_target_attribute_tree (args, &global_options, | |
269 | &global_options_set); | |
270 | if (cur_tree == NULL_TREE) | |
271 | { | |
272 | cl_target_option_restore (&global_options, | |
273 | TREE_TARGET_OPTION (prev_tree)); | |
274 | return false; | |
275 | } | |
dab73e73 CB |
276 | |
277 | /* handle_pragma_pop_options and handle_pragma_reset_options will set | |
278 | target_option_current_node, but not handle_pragma_target. */ | |
279 | target_option_current_node = cur_tree; | |
a53613c4 RE |
280 | arm_configure_build_target (&arm_active_target, |
281 | TREE_TARGET_OPTION (cur_tree), | |
851966d6 | 282 | &global_options_set, false); |
c84f825c CB |
283 | } |
284 | ||
dab73e73 CB |
285 | /* Update macros if target_node changes. The global state will be restored |
286 | by arm_set_current_function. */ | |
287 | prev_opt = TREE_TARGET_OPTION (prev_tree); | |
288 | cur_opt = TREE_TARGET_OPTION (cur_tree); | |
c84f825c CB |
289 | |
290 | gcc_assert (prev_opt); | |
291 | gcc_assert (cur_opt); | |
292 | ||
c9106282 | 293 | if (cur_opt != prev_opt) |
c84f825c CB |
294 | { |
295 | /* For the definitions, ensure all newly defined macros are considered | |
296 | as used for -Wunused-macros. There is no point warning about the | |
297 | compiler predefined macros. */ | |
298 | cpp_options *cpp_opts = cpp_get_options (parse_in); | |
299 | unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros; | |
c9106282 | 300 | |
c84f825c CB |
301 | cpp_opts->warn_unused_macros = 0; |
302 | ||
303 | /* Update macros. */ | |
c8b6aa7c | 304 | gcc_assert (cur_opt->x_target_flags == target_flags); |
81b9a3d9 CB |
305 | |
306 | /* Don't warn for macros that have context sensitive values depending on | |
307 | other attributes. | |
e8449dec | 308 | See warn_of_redefinition, reset after cpp_create_definition. */ |
81b9a3d9 CB |
309 | tree acond_macro = get_identifier ("__ARM_NEON_FP"); |
310 | C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL ; | |
311 | ||
312 | acond_macro = get_identifier ("__ARM_FP"); | |
313 | C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL; | |
314 | ||
315 | acond_macro = get_identifier ("__ARM_FEATURE_LDREX"); | |
316 | C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL; | |
c9106282 | 317 | |
c8b6aa7c | 318 | arm_cpu_builtins (parse_in); |
c84f825c CB |
319 | |
320 | cpp_opts->warn_unused_macros = saved_warn_unused_macros; | |
eeb085f3 CB |
321 | |
322 | /* Make sure that target_reinit is called for next function, since | |
323 | TREE_TARGET_OPTION might change with the #pragma even if there is | |
324 | no target attribute attached to the function. */ | |
325 | arm_reset_previous_fndecl (); | |
326 | ||
327 | /* If going to the default mode, we restore the initial states. | |
328 | if cur_tree is a new target, states will be saved/restored on a per | |
329 | function basis in arm_set_current_function. */ | |
330 | if (cur_tree == target_option_default_node) | |
331 | save_restore_target_globals (cur_tree); | |
c84f825c CB |
332 | } |
333 | ||
334 | return true; | |
335 | } | |
336 | ||
337 | /* Register target pragmas. We need to add the hook for parsing #pragma GCC | |
338 | option here rather than in arm.c since it will pull in various preprocessor | |
339 | functions, and those are not present in languages like fortran without a | |
340 | preprocessor. */ | |
341 | ||
342 | void | |
343 | arm_register_target_pragmas (void) | |
344 | { | |
345 | /* Update pragma hook to allow parsing #pragma GCC target. */ | |
346 | targetm.target_option.pragma_parse = arm_pragma_target_parse; | |
347 | ||
348 | #ifdef REGISTER_SUBTARGET_PRAGMAS | |
349 | REGISTER_SUBTARGET_PRAGMAS (); | |
350 | #endif | |
351 | } |