]>
Commit | Line | Data |
---|---|---|
1 | /* Target-specific code for C family languages. | |
2 | Copyright (C) 2015-2017 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "config.h" | |
21 | #include "system.h" | |
22 | #include "coretypes.h" | |
23 | #include "tm.h" | |
24 | #include "input.h" | |
25 | #include "memmodel.h" | |
26 | #include "tm_p.h" | |
27 | #include "flags.h" | |
28 | #include "c-family/c-common.h" | |
29 | #include "cpplib.h" | |
30 | #include "c-family/c-pragma.h" | |
31 | #include "langhooks.h" | |
32 | #include "target.h" | |
33 | ||
34 | ||
35 | #define builtin_define(TXT) cpp_define (pfile, TXT) | |
36 | #define builtin_assert(TXT) cpp_assert (pfile, TXT) | |
37 | ||
38 | ||
39 | static void | |
40 | aarch64_def_or_undef (bool def_p, const char *macro, cpp_reader *pfile) | |
41 | { | |
42 | if (def_p) | |
43 | cpp_define (pfile, macro); | |
44 | else | |
45 | cpp_undef (pfile, macro); | |
46 | } | |
47 | ||
48 | /* Define the macros that we always expect to have on AArch64. */ | |
49 | ||
50 | static void | |
51 | aarch64_define_unconditional_macros (cpp_reader *pfile) | |
52 | { | |
53 | builtin_define ("__aarch64__"); | |
54 | builtin_define ("__ARM_64BIT_STATE"); | |
55 | ||
56 | builtin_define ("__ARM_ARCH_ISA_A64"); | |
57 | builtin_define_with_int_value ("__ARM_ALIGN_MAX_PWR", 28); | |
58 | builtin_define_with_int_value ("__ARM_ALIGN_MAX_STACK_PWR", 16); | |
59 | ||
60 | /* __ARM_ARCH_8A is not mandated by ACLE but we define it unconditionally | |
61 | as interoperability with the same arm macro. */ | |
62 | builtin_define ("__ARM_ARCH_8A"); | |
63 | ||
64 | builtin_define_with_int_value ("__ARM_ARCH_PROFILE", 'A'); | |
65 | builtin_define ("__ARM_FEATURE_CLZ"); | |
66 | builtin_define ("__ARM_FEATURE_IDIV"); | |
67 | builtin_define ("__ARM_FEATURE_UNALIGNED"); | |
68 | builtin_define ("__ARM_PCS_AAPCS64"); | |
69 | builtin_define_with_int_value ("__ARM_SIZEOF_WCHAR_T", WCHAR_TYPE_SIZE / 8); | |
70 | } | |
71 | ||
72 | /* Undefine/redefine macros that depend on the current backend state and may | |
73 | need to change when a target pragma modifies the backend state. */ | |
74 | ||
75 | static void | |
76 | aarch64_update_cpp_builtins (cpp_reader *pfile) | |
77 | { | |
78 | aarch64_def_or_undef (flag_unsafe_math_optimizations, "__ARM_FP_FAST", pfile); | |
79 | ||
80 | builtin_define_with_int_value ("__ARM_ARCH", aarch64_architecture_version); | |
81 | ||
82 | builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM", | |
83 | flag_short_enums ? 1 : 4); | |
84 | aarch64_def_or_undef (TARGET_BIG_END, "__AARCH64EB__", pfile); | |
85 | aarch64_def_or_undef (TARGET_BIG_END, "__ARM_BIG_ENDIAN", pfile); | |
86 | aarch64_def_or_undef (!TARGET_BIG_END, "__AARCH64EL__", pfile); | |
87 | ||
88 | aarch64_def_or_undef (TARGET_FLOAT, "__ARM_FEATURE_FMA", pfile); | |
89 | ||
90 | if (TARGET_FLOAT || TARGET_SIMD) | |
91 | { | |
92 | builtin_define_with_int_value ("__ARM_FP", 0x0E); | |
93 | builtin_define ("__ARM_FP16_FORMAT_IEEE"); | |
94 | builtin_define ("__ARM_FP16_ARGS"); | |
95 | } | |
96 | else | |
97 | cpp_undef (pfile, "__ARM_FP"); | |
98 | ||
99 | aarch64_def_or_undef (TARGET_FP_F16INST, | |
100 | "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", pfile); | |
101 | aarch64_def_or_undef (TARGET_SIMD_F16INST, | |
102 | "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", pfile); | |
103 | ||
104 | aarch64_def_or_undef (TARGET_SIMD, "__ARM_FEATURE_NUMERIC_MAXMIN", pfile); | |
105 | aarch64_def_or_undef (TARGET_SIMD, "__ARM_NEON", pfile); | |
106 | ||
107 | ||
108 | aarch64_def_or_undef (TARGET_CRC32, "__ARM_FEATURE_CRC32", pfile); | |
109 | aarch64_def_or_undef (TARGET_DOTPROD, "__ARM_FEATURE_DOTPROD", pfile); | |
110 | ||
111 | cpp_undef (pfile, "__AARCH64_CMODEL_TINY__"); | |
112 | cpp_undef (pfile, "__AARCH64_CMODEL_SMALL__"); | |
113 | cpp_undef (pfile, "__AARCH64_CMODEL_LARGE__"); | |
114 | ||
115 | switch (aarch64_cmodel) | |
116 | { | |
117 | case AARCH64_CMODEL_TINY: | |
118 | case AARCH64_CMODEL_TINY_PIC: | |
119 | builtin_define ("__AARCH64_CMODEL_TINY__"); | |
120 | break; | |
121 | case AARCH64_CMODEL_SMALL: | |
122 | case AARCH64_CMODEL_SMALL_PIC: | |
123 | builtin_define ("__AARCH64_CMODEL_SMALL__"); | |
124 | break; | |
125 | case AARCH64_CMODEL_LARGE: | |
126 | builtin_define ("__AARCH64_CMODEL_LARGE__"); | |
127 | break; | |
128 | default: | |
129 | break; | |
130 | } | |
131 | ||
132 | aarch64_def_or_undef (TARGET_ILP32, "_ILP32", pfile); | |
133 | aarch64_def_or_undef (TARGET_ILP32, "__ILP32__", pfile); | |
134 | ||
135 | aarch64_def_or_undef (TARGET_CRYPTO, "__ARM_FEATURE_CRYPTO", pfile); | |
136 | aarch64_def_or_undef (TARGET_SIMD_RDMA, "__ARM_FEATURE_QRDMX", pfile); | |
137 | ||
138 | /* Not for ACLE, but required to keep "float.h" correct if we switch | |
139 | target between implementations that do or do not support ARMv8.2-A | |
140 | 16-bit floating-point extensions. */ | |
141 | cpp_undef (pfile, "__FLT_EVAL_METHOD__"); | |
142 | builtin_define_with_int_value ("__FLT_EVAL_METHOD__", | |
143 | c_flt_eval_method (true)); | |
144 | cpp_undef (pfile, "__FLT_EVAL_METHOD_C99__"); | |
145 | builtin_define_with_int_value ("__FLT_EVAL_METHOD_C99__", | |
146 | c_flt_eval_method (false)); | |
147 | } | |
148 | ||
149 | /* Implement TARGET_CPU_CPP_BUILTINS. */ | |
150 | ||
151 | void | |
152 | aarch64_cpu_cpp_builtins (cpp_reader *pfile) | |
153 | { | |
154 | aarch64_define_unconditional_macros (pfile); | |
155 | aarch64_update_cpp_builtins (pfile); | |
156 | } | |
157 | ||
158 | /* Hook to validate the current #pragma GCC target and set the state, and | |
159 | update the macros based on what was changed. If ARGS is NULL, then | |
160 | POP_TARGET is used to reset the options. */ | |
161 | ||
162 | static bool | |
163 | aarch64_pragma_target_parse (tree args, tree pop_target) | |
164 | { | |
165 | /* If args is not NULL then process it and setup the target-specific | |
166 | information that it specifies. */ | |
167 | if (args) | |
168 | { | |
169 | if (!aarch64_process_target_attr (args, "pragma")) | |
170 | return false; | |
171 | ||
172 | aarch64_override_options_internal (&global_options); | |
173 | } | |
174 | ||
175 | /* args is NULL, restore to the state described in pop_target. */ | |
176 | else | |
177 | { | |
178 | pop_target = pop_target ? pop_target : target_option_default_node; | |
179 | cl_target_option_restore (&global_options, | |
180 | TREE_TARGET_OPTION (pop_target)); | |
181 | } | |
182 | ||
183 | target_option_current_node | |
184 | = build_target_option_node (&global_options); | |
185 | ||
186 | aarch64_reset_previous_fndecl (); | |
187 | /* For the definitions, ensure all newly defined macros are considered | |
188 | as used for -Wunused-macros. There is no point warning about the | |
189 | compiler predefined macros. */ | |
190 | cpp_options *cpp_opts = cpp_get_options (parse_in); | |
191 | unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros; | |
192 | cpp_opts->warn_unused_macros = 0; | |
193 | ||
194 | aarch64_update_cpp_builtins (parse_in); | |
195 | ||
196 | cpp_opts->warn_unused_macros = saved_warn_unused_macros; | |
197 | ||
198 | /* If we're popping or reseting make sure to update the globals so that | |
199 | the optab availability predicates get recomputed. */ | |
200 | if (pop_target) | |
201 | aarch64_save_restore_target_globals (pop_target); | |
202 | ||
203 | /* Initialize SIMD builtins if we haven't already. | |
204 | Set current_target_pragma to NULL for the duration so that | |
205 | the builtin initialization code doesn't try to tag the functions | |
206 | being built with the attributes specified by any current pragma, thus | |
207 | going into an infinite recursion. */ | |
208 | if (TARGET_SIMD) | |
209 | { | |
210 | tree saved_current_target_pragma = current_target_pragma; | |
211 | current_target_pragma = NULL; | |
212 | aarch64_init_simd_builtins (); | |
213 | current_target_pragma = saved_current_target_pragma; | |
214 | } | |
215 | ||
216 | return true; | |
217 | } | |
218 | ||
219 | /* Implement REGISTER_TARGET_PRAGMAS. */ | |
220 | ||
221 | void | |
222 | aarch64_register_pragmas (void) | |
223 | { | |
224 | /* Update pragma hook to allow parsing #pragma GCC target. */ | |
225 | targetm.target_option.pragma_parse = aarch64_pragma_target_parse; | |
226 | } |