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