2016-07-07 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / gcc / config / arm / arm-c.c
blobb98470fff45b20a5398c2534bc3bb3edfb7bfd01
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 "tm_p.h"
25 #include "c-family/c-pragma.h"
26 #include "stringpool.h"
28 /* Output C specific EABI object attributes. These can not be done in
29 arm.c because they require information from the C frontend. */
31 static void
32 arm_output_c_attributes (void)
34 int wchar_size = (int)(TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);
35 arm_emit_eabi_attribute ("Tag_ABI_PCS_wchar_t", 18, wchar_size);
39 /* Setup so that common code calls arm_output_c_attributes. */
41 void
42 arm_lang_object_attributes_init (void)
44 arm_lang_output_object_attributes_hook = arm_output_c_attributes;
47 #define builtin_define(TXT) cpp_define (pfile, TXT)
48 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
50 /* Define or undefine macros based on the current target. If the user does
51 #pragma GCC target, we need to adjust the macros dynamically. */
53 static void
54 def_or_undef_macro(struct cpp_reader* pfile, const char *name, bool def_p)
56 if (def_p)
57 cpp_define (pfile, name);
58 else
59 cpp_undef (pfile, name);
62 static void
63 arm_cpu_builtins (struct cpp_reader* pfile)
65 def_or_undef_macro (pfile, "__ARM_FEATURE_DSP", TARGET_DSP_MULTIPLY);
66 def_or_undef_macro (pfile, "__ARM_FEATURE_QBIT", TARGET_ARM_QBIT);
67 def_or_undef_macro (pfile, "__ARM_FEATURE_SAT", TARGET_ARM_SAT);
68 def_or_undef_macro (pfile, "__ARM_FEATURE_CRYPTO", TARGET_CRYPTO);
70 def_or_undef_macro (pfile, "__ARM_FEATURE_UNALIGNED", unaligned_access);
72 def_or_undef_macro (pfile, "__ARM_FEATURE_QRDMX", TARGET_NEON_RDMA);
74 if (TARGET_CRC32)
75 builtin_define ("__ARM_FEATURE_CRC32");
77 def_or_undef_macro (pfile, "__ARM_32BIT_STATE", TARGET_32BIT);
79 if (TARGET_ARM_FEATURE_LDREX)
80 builtin_define_with_int_value ("__ARM_FEATURE_LDREX",
81 TARGET_ARM_FEATURE_LDREX);
82 else
83 cpp_undef (pfile, "__ARM_FEATURE_LDREX");
85 def_or_undef_macro (pfile, "__ARM_FEATURE_CLZ",
86 ((TARGET_ARM_ARCH >= 5 && !TARGET_THUMB)
87 || TARGET_ARM_ARCH_ISA_THUMB >=2));
89 def_or_undef_macro (pfile, "__ARM_FEATURE_SIMD32", TARGET_INT_SIMD);
91 builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM",
92 flag_short_enums ? 1 : 4);
93 builtin_define_type_sizeof ("__ARM_SIZEOF_WCHAR_T", wchar_type_node);
94 if (TARGET_ARM_ARCH_PROFILE)
95 builtin_define_with_int_value ("__ARM_ARCH_PROFILE",
96 TARGET_ARM_ARCH_PROFILE);
98 /* Define __arm__ even when in thumb mode, for
99 consistency with armcc. */
100 builtin_define ("__arm__");
101 if (TARGET_ARM_ARCH)
102 builtin_define_with_int_value ("__ARM_ARCH", TARGET_ARM_ARCH);
103 if (arm_arch_notm)
104 builtin_define ("__ARM_ARCH_ISA_ARM");
105 builtin_define ("__APCS_32__");
107 def_or_undef_macro (pfile, "__thumb__", TARGET_THUMB);
108 def_or_undef_macro (pfile, "__thumb2__", TARGET_THUMB2);
109 if (TARGET_BIG_END)
110 def_or_undef_macro (pfile, "__THUMBEB__", TARGET_THUMB);
111 else
112 def_or_undef_macro (pfile, "__THUMBEL__", TARGET_THUMB);
114 if (TARGET_ARM_ARCH_ISA_THUMB)
115 builtin_define_with_int_value ("__ARM_ARCH_ISA_THUMB",
116 TARGET_ARM_ARCH_ISA_THUMB);
118 if (TARGET_BIG_END)
120 builtin_define ("__ARMEB__");
121 builtin_define ("__ARM_BIG_ENDIAN");
123 else
125 builtin_define ("__ARMEL__");
128 if (TARGET_SOFT_FLOAT)
129 builtin_define ("__SOFTFP__");
131 def_or_undef_macro (pfile, "__VFP_FP__", TARGET_VFP);
133 if (TARGET_ARM_FP)
134 builtin_define_with_int_value ("__ARM_FP", TARGET_ARM_FP);
135 else
136 cpp_undef (pfile, "__ARM_FP");
138 def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_IEEE",
139 arm_fp16_format == ARM_FP16_FORMAT_IEEE);
140 def_or_undef_macro (pfile, "__ARM_FP16_FORMAT_ALTERNATIVE",
141 arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
142 def_or_undef_macro (pfile, "__ARM_FP16_ARGS",
143 arm_fp16_format != ARM_FP16_FORMAT_NONE);
145 def_or_undef_macro (pfile, "__ARM_FEATURE_FMA", TARGET_FMA);
146 def_or_undef_macro (pfile, "__ARM_NEON__", TARGET_NEON);
147 def_or_undef_macro (pfile, "__ARM_NEON", TARGET_NEON);
149 if (TARGET_NEON_FP)
150 builtin_define_with_int_value ("__ARM_NEON_FP", TARGET_NEON_FP);
151 else
152 cpp_undef (pfile, "__ARM_NEON_FP");
154 /* Add a define for interworking. Needed when building libgcc.a. */
155 if (arm_cpp_interwork)
156 builtin_define ("__THUMB_INTERWORK__");
158 builtin_define (arm_arch_name);
159 if (arm_arch_xscale)
160 builtin_define ("__XSCALE__");
161 if (arm_arch_iwmmxt)
163 builtin_define ("__IWMMXT__");
164 builtin_define ("__ARM_WMMX");
166 if (arm_arch_iwmmxt2)
167 builtin_define ("__IWMMXT2__");
168 /* ARMv6KZ was originally identified as the misspelled __ARM_ARCH_6ZK__. To
169 preserve the existing behavior, the misspelled feature macro must still be
170 defined. */
171 if (arm_arch6kz)
172 builtin_define ("__ARM_ARCH_6ZK__");
173 if (TARGET_AAPCS_BASED)
175 if (arm_pcs_default == ARM_PCS_AAPCS_VFP)
176 builtin_define ("__ARM_PCS_VFP");
177 else if (arm_pcs_default == ARM_PCS_AAPCS)
178 builtin_define ("__ARM_PCS");
179 builtin_define ("__ARM_EABI__");
182 def_or_undef_macro (pfile, "__ARM_ARCH_EXT_IDIV__", TARGET_IDIV);
183 def_or_undef_macro (pfile, "__ARM_FEATURE_IDIV", TARGET_IDIV);
185 def_or_undef_macro (pfile, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified);
188 void
189 arm_cpu_cpp_builtins (struct cpp_reader * pfile)
191 builtin_assert ("cpu=arm");
192 builtin_assert ("machine=arm");
194 arm_cpu_builtins (pfile);
197 /* Hook to validate the current #pragma GCC target and set the arch custom
198 mode state. If ARGS is NULL, then POP_TARGET is used to reset
199 the options. */
201 static bool
202 arm_pragma_target_parse (tree args, tree pop_target)
204 tree prev_tree = target_option_current_node;
205 tree cur_tree;
206 struct cl_target_option *prev_opt;
207 struct cl_target_option *cur_opt;
209 if (! args)
211 cur_tree = ((pop_target) ? pop_target : target_option_default_node);
212 cl_target_option_restore (&global_options,
213 TREE_TARGET_OPTION (cur_tree));
215 else
217 cur_tree = arm_valid_target_attribute_tree (args, &global_options,
218 &global_options_set);
219 if (cur_tree == NULL_TREE)
221 cl_target_option_restore (&global_options,
222 TREE_TARGET_OPTION (prev_tree));
223 return false;
226 /* handle_pragma_pop_options and handle_pragma_reset_options will set
227 target_option_current_node, but not handle_pragma_target. */
228 target_option_current_node = cur_tree;
231 /* Update macros if target_node changes. The global state will be restored
232 by arm_set_current_function. */
233 prev_opt = TREE_TARGET_OPTION (prev_tree);
234 cur_opt = TREE_TARGET_OPTION (cur_tree);
236 gcc_assert (prev_opt);
237 gcc_assert (cur_opt);
239 if (cur_opt != prev_opt)
241 /* For the definitions, ensure all newly defined macros are considered
242 as used for -Wunused-macros. There is no point warning about the
243 compiler predefined macros. */
244 cpp_options *cpp_opts = cpp_get_options (parse_in);
245 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
247 cpp_opts->warn_unused_macros = 0;
249 /* Update macros. */
250 gcc_assert (cur_opt->x_target_flags == target_flags);
252 /* Don't warn for macros that have context sensitive values depending on
253 other attributes.
254 See warn_of_redefinition, reset after cpp_create_definition. */
255 tree acond_macro = get_identifier ("__ARM_NEON_FP");
256 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL ;
258 acond_macro = get_identifier ("__ARM_FP");
259 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL;
261 acond_macro = get_identifier ("__ARM_FEATURE_LDREX");
262 C_CPP_HASHNODE (acond_macro)->flags |= NODE_CONDITIONAL;
264 arm_cpu_builtins (parse_in);
266 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
268 /* Make sure that target_reinit is called for next function, since
269 TREE_TARGET_OPTION might change with the #pragma even if there is
270 no target attribute attached to the function. */
271 arm_reset_previous_fndecl ();
273 /* If going to the default mode, we restore the initial states.
274 if cur_tree is a new target, states will be saved/restored on a per
275 function basis in arm_set_current_function. */
276 if (cur_tree == target_option_default_node)
277 save_restore_target_globals (cur_tree);
280 return true;
283 /* Register target pragmas. We need to add the hook for parsing #pragma GCC
284 option here rather than in arm.c since it will pull in various preprocessor
285 functions, and those are not present in languages like fortran without a
286 preprocessor. */
288 void
289 arm_register_target_pragmas (void)
291 /* Update pragma hook to allow parsing #pragma GCC target. */
292 targetm.target_option.pragma_parse = arm_pragma_target_parse;
294 #ifdef REGISTER_SUBTARGET_PRAGMAS
295 REGISTER_SUBTARGET_PRAGMAS ();
296 #endif