annotate gcc/config/aarch64/aarch64-c.c @ 131:84e7813d76e9

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