1 /* Copyright (C) 2007-2018 Free Software Foundation, Inc.
3 This file is part of GCC.
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
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
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/>. */
19 #define IN_TARGET_CODE 1
23 #include "coretypes.h"
25 #include "c-family/c-common.h"
28 #include "c-family/c-pragma.h"
29 #include "stringpool.h"
31 /* Output C specific EABI object attributes. These can not be done in
32 arm.c because they require information from the C frontend. */
35 arm_output_c_attributes (void)
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
);
42 /* Setup so that common code calls arm_output_c_attributes. */
45 arm_lang_object_attributes_init (void)
47 arm_lang_output_object_attributes_hook
= arm_output_c_attributes
;
50 #define builtin_define(TXT) cpp_define (pfile, TXT)
51 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
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. */
57 def_or_undef_macro(struct cpp_reader
* pfile
, const char *name
, bool def_p
)
60 cpp_define (pfile
, name
);
62 cpp_undef (pfile
, name
);
66 arm_cpu_builtins (struct cpp_reader
* pfile
)
68 def_or_undef_macro (pfile
, "__ARM_FEATURE_DSP", TARGET_DSP_MULTIPLY
);
69 def_or_undef_macro (pfile
, "__ARM_FEATURE_QBIT", TARGET_ARM_QBIT
);
70 def_or_undef_macro (pfile
, "__ARM_FEATURE_SAT", TARGET_ARM_SAT
);
71 def_or_undef_macro (pfile
, "__ARM_FEATURE_CRYPTO", TARGET_CRYPTO
);
73 def_or_undef_macro (pfile
, "__ARM_FEATURE_UNALIGNED", unaligned_access
);
75 def_or_undef_macro (pfile
, "__ARM_FEATURE_QRDMX", TARGET_NEON_RDMA
);
77 def_or_undef_macro (pfile
, "__ARM_FEATURE_CRC32", TARGET_CRC32
);
78 def_or_undef_macro (pfile
, "__ARM_FEATURE_DOTPROD", TARGET_DOTPROD
);
79 def_or_undef_macro (pfile
, "__ARM_32BIT_STATE", TARGET_32BIT
);
81 cpp_undef (pfile
, "__ARM_FEATURE_CMSE");
82 if (arm_arch8
&& !arm_arch_notm
)
84 if (arm_arch_cmse
&& use_cmse
)
85 builtin_define_with_int_value ("__ARM_FEATURE_CMSE", 3);
87 builtin_define ("__ARM_FEATURE_CMSE");
90 cpp_undef (pfile
, "__ARM_FEATURE_LDREX");
91 if (TARGET_ARM_FEATURE_LDREX
)
92 builtin_define_with_int_value ("__ARM_FEATURE_LDREX",
93 TARGET_ARM_FEATURE_LDREX
);
95 def_or_undef_macro (pfile
, "__ARM_FEATURE_CLZ",
96 ((TARGET_ARM_ARCH
>= 5 && !TARGET_THUMB
)
97 || TARGET_ARM_ARCH_ISA_THUMB
>=2));
99 def_or_undef_macro (pfile
, "__ARM_FEATURE_NUMERIC_MAXMIN",
100 TARGET_ARM_ARCH
>= 8 && TARGET_NEON
&& TARGET_VFP5
);
102 def_or_undef_macro (pfile
, "__ARM_FEATURE_SIMD32", TARGET_INT_SIMD
);
104 builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM",
105 flag_short_enums
? 1 : 4);
106 builtin_define_type_sizeof ("__ARM_SIZEOF_WCHAR_T", wchar_type_node
);
108 cpp_undef (pfile
, "__ARM_ARCH_PROFILE");
109 if (TARGET_ARM_ARCH_PROFILE
)
110 builtin_define_with_int_value ("__ARM_ARCH_PROFILE",
111 TARGET_ARM_ARCH_PROFILE
);
113 /* Define __arm__ even when in thumb mode, for
114 consistency with armcc. */
115 builtin_define ("__arm__");
118 cpp_undef (pfile
, "__ARM_ARCH");
119 builtin_define_with_int_value ("__ARM_ARCH", TARGET_ARM_ARCH
);
122 builtin_define ("__ARM_ARCH_ISA_ARM");
123 builtin_define ("__APCS_32__");
125 def_or_undef_macro (pfile
, "__thumb__", TARGET_THUMB
);
126 def_or_undef_macro (pfile
, "__thumb2__", TARGET_THUMB2
);
128 def_or_undef_macro (pfile
, "__THUMBEB__", TARGET_THUMB
);
130 def_or_undef_macro (pfile
, "__THUMBEL__", TARGET_THUMB
);
132 cpp_undef (pfile
, "__ARM_ARCH_ISA_THUMB");
133 if (TARGET_ARM_ARCH_ISA_THUMB
)
134 builtin_define_with_int_value ("__ARM_ARCH_ISA_THUMB",
135 TARGET_ARM_ARCH_ISA_THUMB
);
139 builtin_define ("__ARMEB__");
140 builtin_define ("__ARM_BIG_ENDIAN");
144 builtin_define ("__ARMEL__");
147 if (TARGET_SOFT_FLOAT
)
148 builtin_define ("__SOFTFP__");
150 builtin_define ("__VFP_FP__");
152 cpp_undef (pfile
, "__ARM_FP");
154 builtin_define_with_int_value ("__ARM_FP", TARGET_ARM_FP
);
156 def_or_undef_macro (pfile
, "__ARM_FP16_FORMAT_IEEE",
157 arm_fp16_format
== ARM_FP16_FORMAT_IEEE
);
158 def_or_undef_macro (pfile
, "__ARM_FP16_FORMAT_ALTERNATIVE",
159 arm_fp16_format
== ARM_FP16_FORMAT_ALTERNATIVE
);
160 def_or_undef_macro (pfile
, "__ARM_FP16_ARGS",
161 arm_fp16_format
!= ARM_FP16_FORMAT_NONE
);
163 def_or_undef_macro (pfile
, "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC",
164 TARGET_VFP_FP16INST
);
165 def_or_undef_macro (pfile
, "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC",
166 TARGET_NEON_FP16INST
);
167 def_or_undef_macro (pfile
, "__ARM_FEATURE_FP16_FML", TARGET_FP16FML
);
169 def_or_undef_macro (pfile
, "__ARM_FEATURE_FMA", TARGET_FMA
);
170 def_or_undef_macro (pfile
, "__ARM_NEON__", TARGET_NEON
);
171 def_or_undef_macro (pfile
, "__ARM_NEON", TARGET_NEON
);
173 cpp_undef (pfile
, "__ARM_NEON_FP");
175 builtin_define_with_int_value ("__ARM_NEON_FP", TARGET_NEON_FP
);
177 /* Add a define for interworking. Needed when building libgcc.a. */
178 if (arm_cpp_interwork
)
179 builtin_define ("__THUMB_INTERWORK__");
181 builtin_define (arm_arch_name
);
183 builtin_define ("__XSCALE__");
186 builtin_define ("__IWMMXT__");
187 builtin_define ("__ARM_WMMX");
189 if (arm_arch_iwmmxt2
)
190 builtin_define ("__IWMMXT2__");
191 /* ARMv6KZ was originally identified as the misspelled __ARM_ARCH_6ZK__. To
192 preserve the existing behavior, the misspelled feature macro must still be
195 builtin_define ("__ARM_ARCH_6ZK__");
196 if (TARGET_AAPCS_BASED
)
198 if (arm_pcs_default
== ARM_PCS_AAPCS_VFP
)
199 builtin_define ("__ARM_PCS_VFP");
200 else if (arm_pcs_default
== ARM_PCS_AAPCS
)
201 builtin_define ("__ARM_PCS");
202 builtin_define ("__ARM_EABI__");
205 def_or_undef_macro (pfile
, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV
);
206 def_or_undef_macro (pfile
, "__ARM_FEATURE_IDIV", TARGET_IDIV
);
208 def_or_undef_macro (pfile
, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified
);
210 cpp_undef (pfile
, "__ARM_FEATURE_COPROC");
211 if (TARGET_32BIT
&& arm_arch4
&& !(arm_arch8
&& arm_arch_notm
))
213 int coproc_level
= 0x1;
222 builtin_define_with_int_value ("__ARM_FEATURE_COPROC", coproc_level
);
227 arm_cpu_cpp_builtins (struct cpp_reader
* pfile
)
229 builtin_assert ("cpu=arm");
230 builtin_assert ("machine=arm");
232 arm_cpu_builtins (pfile
);
235 /* Hook to validate the current #pragma GCC target and set the arch custom
236 mode state. If ARGS is NULL, then POP_TARGET is used to reset
240 arm_pragma_target_parse (tree args
, tree pop_target
)
242 tree prev_tree
= target_option_current_node
;
244 struct cl_target_option
*prev_opt
;
245 struct cl_target_option
*cur_opt
;
249 cur_tree
= ((pop_target
) ? pop_target
: target_option_default_node
);
250 cl_target_option_restore (&global_options
,
251 TREE_TARGET_OPTION (cur_tree
));
255 cur_tree
= arm_valid_target_attribute_tree (args
, &global_options
,
256 &global_options_set
);
257 if (cur_tree
== NULL_TREE
)
259 cl_target_option_restore (&global_options
,
260 TREE_TARGET_OPTION (prev_tree
));
264 /* handle_pragma_pop_options and handle_pragma_reset_options will set
265 target_option_current_node, but not handle_pragma_target. */
266 target_option_current_node
= cur_tree
;
267 arm_configure_build_target (&arm_active_target
,
268 TREE_TARGET_OPTION (cur_tree
),
269 &global_options_set
, false);
272 /* Update macros if target_node changes. The global state will be restored
273 by arm_set_current_function. */
274 prev_opt
= TREE_TARGET_OPTION (prev_tree
);
275 cur_opt
= TREE_TARGET_OPTION (cur_tree
);
277 gcc_assert (prev_opt
);
278 gcc_assert (cur_opt
);
280 if (cur_opt
!= prev_opt
)
282 /* For the definitions, ensure all newly defined macros are considered
283 as used for -Wunused-macros. There is no point warning about the
284 compiler predefined macros. */
285 cpp_options
*cpp_opts
= cpp_get_options (parse_in
);
286 unsigned char saved_warn_unused_macros
= cpp_opts
->warn_unused_macros
;
288 cpp_opts
->warn_unused_macros
= 0;
291 gcc_assert (cur_opt
->x_target_flags
== target_flags
);
293 /* Don't warn for macros that have context sensitive values depending on
295 See warn_of_redefinition, reset after cpp_create_definition. */
296 tree acond_macro
= get_identifier ("__ARM_NEON_FP");
297 C_CPP_HASHNODE (acond_macro
)->flags
|= NODE_CONDITIONAL
;
299 acond_macro
= get_identifier ("__ARM_FP");
300 C_CPP_HASHNODE (acond_macro
)->flags
|= NODE_CONDITIONAL
;
302 acond_macro
= get_identifier ("__ARM_FEATURE_LDREX");
303 C_CPP_HASHNODE (acond_macro
)->flags
|= NODE_CONDITIONAL
;
305 arm_cpu_builtins (parse_in
);
307 cpp_opts
->warn_unused_macros
= saved_warn_unused_macros
;
309 /* Make sure that target_reinit is called for next function, since
310 TREE_TARGET_OPTION might change with the #pragma even if there is
311 no target attribute attached to the function. */
312 arm_reset_previous_fndecl ();
314 /* If going to the default mode, we restore the initial states.
315 if cur_tree is a new target, states will be saved/restored on a per
316 function basis in arm_set_current_function. */
317 if (cur_tree
== target_option_default_node
)
318 save_restore_target_globals (cur_tree
);
324 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
325 option here rather than in arm.c since it will pull in various preprocessor
326 functions, and those are not present in languages like fortran without a
330 arm_register_target_pragmas (void)
332 /* Update pragma hook to allow parsing #pragma GCC target. */
333 targetm
.target_option
.pragma_parse
= arm_pragma_target_parse
;
335 #ifdef REGISTER_SUBTARGET_PRAGMAS
336 REGISTER_SUBTARGET_PRAGMAS ();