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