gcc/
[official-gcc.git] / gcc / config / arm / arm-c.c
blob74417a6446dbac903da567f3de4f25b387846165
1 /* Copyright (C) 2007-2016 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
8 version.
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.
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 #include "config.h"
20 #include "system.h"
21 #include "coretypes.h"
22 #include "target.h"
23 #include "c-family/c-common.h"
24 #include "memmodel.h"
25 #include "tm_p.h"
26 #include "c-family/c-pragma.h"
27 #include "stringpool.h"
29 /* Output C specific EABI object attributes. These can not be done in
30 arm.c because they require information from the C frontend. */
32 static void
33 arm_output_c_attributes (void)
35 int wchar_size = (int)(TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);
36 arm_emit_eabi_attribute ("Tag_ABI_PCS_wchar_t", 18, wchar_size);
40 /* Setup so that common code calls arm_output_c_attributes. */
42 void
43 arm_lang_object_attributes_init (void)
45 arm_lang_output_object_attributes_hook = arm_output_c_attributes;
48 #define builtin_define(TXT) cpp_define (pfile, TXT)
49 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
51 /* Define or undefine macros based on the current target. If the user does
52 #pragma GCC target, we need to adjust the macros dynamically. */
54 static void
55 def_or_undef_macro(struct cpp_reader* pfile, const char *name, bool def_p)
57 if (def_p)
58 cpp_define (pfile, name);
59 else
60 cpp_undef (pfile, name);
63 static void
64 arm_cpu_builtins (struct cpp_reader* pfile)
66 def_or_undef_macro (pfile, "__ARM_FEATURE_DSP", TARGET_DSP_MULTIPLY);
67 def_or_undef_macro (pfile, "__ARM_FEATURE_QBIT", TARGET_ARM_QBIT);
68 def_or_undef_macro (pfile, "__ARM_FEATURE_SAT", TARGET_ARM_SAT);
69 def_or_undef_macro (pfile, "__ARM_FEATURE_CRYPTO", TARGET_CRYPTO);
71 def_or_undef_macro (pfile, "__ARM_FEATURE_UNALIGNED", unaligned_access);
73 def_or_undef_macro (pfile, "__ARM_FEATURE_QRDMX", TARGET_NEON_RDMA);
75 if (TARGET_CRC32)
76 builtin_define ("__ARM_FEATURE_CRC32");
78 def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT);
80 if (TARGET_ARM_FEATURE_LDREX)
81 builtin_define_with_int_value ("__ARM_FEATURE_LDREX",
82 TARGET_ARM_FEATURE_LDREX);
83 else
84 cpp_undef (pfile, "__ARM_FEATURE_LDREX");
86 def_or_undef_macro (pfile, "__ARM_FEATURE_CLZ",
87 ((TARGET_ARM_ARCH >= 5 && !TARGET_THUMB)
88 || TARGET_ARM_ARCH_ISA_THUMB >=2));
90 def_or_undef_macro (pfile, "__ARM_FEATURE_NUMERIC_MAXMIN",
91 TARGET_ARM_ARCH >= 8 && TARGET_NEON && TARGET_FPU_ARMV8);
93 def_or_undef_macro (pfile, "__ARM_FEATURE_SIMD32", TARGET_INT_SIMD);
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);
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__");
111 def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB);
112 def_or_undef_macro (pfile, "__thumb2__", TARGET_THUMB2);
113 if (TARGET_BIG_END)
114 def_or_undef_macro (pfile, "__THUMBEB__", TARGET_THUMB);
115 else
116 def_or_undef_macro (pfile, "__THUMBEL__", TARGET_THUMB);
118 if (TARGET_ARM_ARCH_ISA_THUMB)
119 builtin_define_with_int_value ("__ARM_ARCH_ISA_THUMB",
120 TARGET_ARM_ARCH_ISA_THUMB);
122 if (TARGET_BIG_END)
124 builtin_define ("__ARMEB__");
125 builtin_define ("__ARM_BIG_ENDIAN");
127 else
129 builtin_define ("__ARMEL__");
132 if (TARGET_SOFT_FLOAT)
133 builtin_define ("__SOFTFP__");
135 builtin_define ("__VFP_FP__");
137 if (TARGET_ARM_FP)
138 builtin_define_with_int_value ("__ARM_FP", TARGET_ARM_FP);
139 else
140 cpp_undef (pfile, "__ARM_FP");
142 def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_IEEE",
143 arm_fp16_format == ARM_FP16_FORMAT_IEEE);
144 def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_ALTERNATIVE",
145 arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
146 def_or_undef_macro (pfile, "__ARM_FP16_ARGS",
147 arm_fp16_format != ARM_FP16_FORMAT_NONE);
149 def_or_undef_macro (pfile, "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC",
150 TARGET_VFP_FP16INST);
151 def_or_undef_macro (pfile, "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC",
152 TARGET_NEON_FP16INST);
154 def_or_undef_macro (pfile, "__ARM_FEATURE_FMA", TARGET_FMA);
155 def_or_undef_macro (pfile, "__ARM_NEON__", TARGET_NEON);
156 def_or_undef_macro (pfile, "__ARM_NEON", TARGET_NEON);
158 if (TARGET_NEON_FP)
159 builtin_define_with_int_value ("__ARM_NEON_FP", TARGET_NEON_FP);
160 else
161 cpp_undef (pfile, "__ARM_NEON_FP");
163 /* Add a define for interworking. Needed when building libgcc.a. */
164 if (arm_cpp_interwork)
165 builtin_define ("__THUMB_INTERWORK__");
167 builtin_define (arm_arch_name);
168 if (arm_arch_xscale)
169 builtin_define ("__XSCALE__");
170 if (arm_arch_iwmmxt)
172 builtin_define ("__IWMMXT__");
173 builtin_define ("__ARM_WMMX");
175 if (arm_arch_iwmmxt2)
176 builtin_define ("__IWMMXT2__");
177 /* ARMv6KZ was originally identified as the misspelled __ARM_ARCH_6ZK__. To
178 preserve the existing behavior, the misspelled feature macro must still be
179 defined. */
180 if (arm_arch6kz)
181 builtin_define ("__ARM_ARCH_6ZK__");
182 if (TARGET_AAPCS_BASED)
184 if (arm_pcs_default == ARM_PCS_AAPCS_VFP)
185 builtin_define ("__ARM_PCS_VFP");
186 else if (arm_pcs_default == ARM_PCS_AAPCS)
187 builtin_define ("__ARM_PCS");
188 builtin_define ("__ARM_EABI__");
191 def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
192 def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
194 def_or_undef_macro (pfile, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified);
197 void
198 arm_cpu_cpp_builtins (struct cpp_reader * pfile)
200 builtin_assert ("cpu=arm");
201 builtin_assert ("machine=arm");
203 arm_cpu_builtins (pfile);
206 /* Hook to validate the current #pragma GCC target and set the arch custom
207 mode state. If ARGS is NULL, then POP_TARGET is used to reset
208 the options. */
210 static bool
211 arm_pragma_target_parse (tree args, tree pop_target)
213 tree prev_tree = target_option_current_node;
214 tree cur_tree;
215 struct cl_target_option *prev_opt;
216 struct cl_target_option *cur_opt;
218 if (! args)
220 cur_tree = ((pop_target) ? pop_target : target_option_default_node);
221 cl_target_option_restore (&global_options,
222 TREE_TARGET_OPTION (cur_tree));
224 else
226 cur_tree = arm_valid_target_attribute_tree (args, &global_options,
227 &global_options_set);
228 if (cur_tree == NULL_TREE)
230 cl_target_option_restore (&global_options,
231 TREE_TARGET_OPTION (prev_tree));
232 return false;
235 /* handle_pragma_pop_options and handle_pragma_reset_options will set
236 target_option_current_node, but not handle_pragma_target. */
237 target_option_current_node = cur_tree;
240 /* Update macros if target_node changes. The global state will be restored
241 by arm_set_current_function. */
242 prev_opt = TREE_TARGET_OPTION (prev_tree);
243 cur_opt = TREE_TARGET_OPTION (cur_tree);
245 gcc_assert (prev_opt);
246 gcc_assert (cur_opt);
248 if (cur_opt != prev_opt)
250 /* For the definitions, ensure all newly defined macros are considered
251 as used for -Wunused-macros. There is no point warning about the
252 compiler predefined macros. */
253 cpp_options *cpp_opts = cpp_get_options (parse_in);
254 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
256 cpp_opts->warn_unused_macros = 0;
258 /* Update macros. */
259 gcc_assert (cur_opt->x_target_flags == target_flags);
261 /* Don't warn for macros that have context sensitive values depending on
262 other attributes.
263 See warn_of_redefinition, reset after cpp_create_definition. */
264 tree acond_macro = get_identifier ("__ARM_NEON_FP");
265 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL ;
267 acond_macro = get_identifier ("__ARM_FP");
268 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL;
270 acond_macro = get_identifier ("__ARM_FEATURE_LDREX");
271 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL;
273 arm_cpu_builtins (parse_in);
275 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
277 /* Make sure that target_reinit is called for next function, since
278 TREE_TARGET_OPTION might change with the #pragma even if there is
279 no target attribute attached to the function. */
280 arm_reset_previous_fndecl ();
282 /* If going to the default mode, we restore the initial states.
283 if cur_tree is a new target, states will be saved/restored on a per
284 function basis in arm_set_current_function. */
285 if (cur_tree == target_option_default_node)
286 save_restore_target_globals (cur_tree);
289 return true;
292 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
293 option here rather than in arm.c since it will pull in various preprocessor
294 functions, and those are not present in languages like fortran without a
295 preprocessor. */
297 void
298 arm_register_target_pragmas (void)
300 /* Update pragma hook to allow parsing #pragma GCC target. */
301 targetm.target_option.pragma_parse = arm_pragma_target_parse;
303 #ifdef REGISTER_SUBTARGET_PRAGMAS
304 REGISTER_SUBTARGET_PRAGMAS ();
305 #endif