]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/aarch64/aarch64-c.c
[AArch64] ARMv8.2 command line and feature macros support
[thirdparty/gcc.git] / gcc / config / aarch64 / aarch64-c.c
1 /* Target-specific code for C family languages.
2 Copyright (C) 2015-2016 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 "tm_p.h"
26 #include "flags.h"
27 #include "c-family/c-common.h"
28 #include "cpplib.h"
29 #include "c-family/c-pragma.h"
30 #include "langhooks.h"
31 #include "target.h"
32
33
34 #define builtin_define(TXT) cpp_define (pfile, TXT)
35 #define builtin_assert(TXT) cpp_assert (pfile, TXT)
36
37
38 static void
39 aarch64_def_or_undef (bool def_p, const char *macro, cpp_reader *pfile)
40 {
41 if (def_p)
42 cpp_define (pfile, macro);
43 else
44 cpp_undef (pfile, macro);
45 }
46
47 /* Define the macros that we always expect to have on AArch64. */
48
49 static void
50 aarch64_define_unconditional_macros (cpp_reader *pfile)
51 {
52 builtin_define ("__aarch64__");
53 builtin_define ("__ARM_64BIT_STATE");
54
55 builtin_define ("__ARM_ARCH_ISA_A64");
56 builtin_define_with_int_value ("__ARM_ALIGN_MAX_PWR", 28);
57 builtin_define_with_int_value ("__ARM_ALIGN_MAX_STACK_PWR", 16);
58
59 /* __ARM_ARCH_8A is not mandated by ACLE but we define it unconditionally
60 as interoperability with the same arm macro. */
61 builtin_define ("__ARM_ARCH_8A");
62
63 builtin_define_with_int_value ("__ARM_ARCH_PROFILE", 'A');
64 builtin_define ("__ARM_FEATURE_CLZ");
65 builtin_define ("__ARM_FEATURE_IDIV");
66 builtin_define ("__ARM_FEATURE_UNALIGNED");
67 builtin_define ("__ARM_PCS_AAPCS64");
68 builtin_define_with_int_value ("__ARM_SIZEOF_WCHAR_T", WCHAR_TYPE_SIZE / 8);
69 }
70
71 /* Undefine/redefine macros that depend on the current backend state and may
72 need to change when a target pragma modifies the backend state. */
73
74 static void
75 aarch64_update_cpp_builtins (cpp_reader *pfile)
76 {
77 aarch64_def_or_undef (flag_unsafe_math_optimizations, "__ARM_FP_FAST", pfile);
78
79 builtin_define_with_int_value ("__ARM_ARCH", aarch64_architecture_version);
80
81 builtin_define_with_int_value ("__ARM_SIZEOF_MINIMAL_ENUM",
82 flag_short_enums ? 1 : 4);
83 aarch64_def_or_undef (TARGET_BIG_END, "__AARCH64EB__", pfile);
84 aarch64_def_or_undef (TARGET_BIG_END, "__ARM_BIG_ENDIAN", pfile);
85 aarch64_def_or_undef (!TARGET_BIG_END, "__AARCH64EL__", pfile);
86
87 aarch64_def_or_undef (TARGET_FLOAT, "__ARM_FEATURE_FMA", pfile);
88
89 if (TARGET_FLOAT || TARGET_SIMD)
90 {
91 builtin_define_with_int_value ("__ARM_FP", 0x0E);
92 builtin_define ("__ARM_FP16_FORMAT_IEEE");
93 builtin_define ("__ARM_FP16_ARGS");
94 }
95 else
96 cpp_undef (pfile, "__ARM_FP");
97
98 aarch64_def_or_undef (TARGET_FP_F16INST,
99 "__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", pfile);
100 aarch64_def_or_undef (TARGET_SIMD_F16INST,
101 "__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", pfile);
102
103 aarch64_def_or_undef (TARGET_SIMD, "__ARM_FEATURE_NUMERIC_MAXMIN", pfile);
104 aarch64_def_or_undef (TARGET_SIMD, "__ARM_NEON", pfile);
105
106
107 aarch64_def_or_undef (TARGET_CRC32, "__ARM_FEATURE_CRC32", pfile);
108
109 cpp_undef (pfile, "__AARCH64_CMODEL_TINY__");
110 cpp_undef (pfile, "__AARCH64_CMODEL_SMALL__");
111 cpp_undef (pfile, "__AARCH64_CMODEL_LARGE__");
112
113 switch (aarch64_cmodel)
114 {
115 case AARCH64_CMODEL_TINY:
116 case AARCH64_CMODEL_TINY_PIC:
117 builtin_define ("__AARCH64_CMODEL_TINY__");
118 break;
119 case AARCH64_CMODEL_SMALL:
120 case AARCH64_CMODEL_SMALL_PIC:
121 builtin_define ("__AARCH64_CMODEL_SMALL__");
122 break;
123 case AARCH64_CMODEL_LARGE:
124 builtin_define ("__AARCH64_CMODEL_LARGE__");
125 break;
126 default:
127 break;
128 }
129
130 aarch64_def_or_undef (TARGET_ILP32, "_ILP32", pfile);
131 aarch64_def_or_undef (TARGET_ILP32, "__ILP32__", pfile);
132
133 aarch64_def_or_undef (TARGET_CRYPTO, "__ARM_FEATURE_CRYPTO", pfile);
134 aarch64_def_or_undef (TARGET_SIMD_RDMA, "__ARM_FEATURE_QRDMX", pfile);
135 }
136
137 /* Implement TARGET_CPU_CPP_BUILTINS. */
138
139 void
140 aarch64_cpu_cpp_builtins (cpp_reader *pfile)
141 {
142 aarch64_define_unconditional_macros (pfile);
143 aarch64_update_cpp_builtins (pfile);
144 }
145
146 /* Hook to validate the current #pragma GCC target and set the state, and
147 update the macros based on what was changed. If ARGS is NULL, then
148 POP_TARGET is used to reset the options. */
149
150 static bool
151 aarch64_pragma_target_parse (tree args, tree pop_target)
152 {
153 /* If args is not NULL then process it and setup the target-specific
154 information that it specifies. */
155 if (args)
156 {
157 if (!aarch64_process_target_attr (args, "pragma"))
158 return false;
159
160 aarch64_override_options_internal (&global_options);
161 }
162
163 /* args is NULL, restore to the state described in pop_target. */
164 else
165 {
166 pop_target = pop_target ? pop_target : target_option_default_node;
167 cl_target_option_restore (&global_options,
168 TREE_TARGET_OPTION (pop_target));
169 }
170
171 target_option_current_node
172 = build_target_option_node (&global_options);
173
174 aarch64_reset_previous_fndecl ();
175 /* For the definitions, ensure all newly defined macros are considered
176 as used for -Wunused-macros. There is no point warning about the
177 compiler predefined macros. */
178 cpp_options *cpp_opts = cpp_get_options (parse_in);
179 unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
180 cpp_opts->warn_unused_macros = 0;
181
182 aarch64_update_cpp_builtins (parse_in);
183
184 cpp_opts->warn_unused_macros = saved_warn_unused_macros;
185
186 /* If we're popping or reseting make sure to update the globals so that
187 the optab availability predicates get recomputed. */
188 if (pop_target)
189 aarch64_save_restore_target_globals (pop_target);
190
191 /* Initialize SIMD builtins if we haven't already.
192 Set current_target_pragma to NULL for the duration so that
193 the builtin initialization code doesn't try to tag the functions
194 being built with the attributes specified by any current pragma, thus
195 going into an infinite recursion. */
196 if (TARGET_SIMD)
197 {
198 tree saved_current_target_pragma = current_target_pragma;
199 current_target_pragma = NULL;
200 aarch64_init_simd_builtins ();
201 current_target_pragma = saved_current_target_pragma;
202 }
203
204 return true;
205 }
206
207 /* Implement REGISTER_TARGET_PRAGMAS. */
208
209 void
210 aarch64_register_pragmas (void)
211 {
212 /* Update pragma hook to allow parsing #pragma GCC target. */
213 targetm.target_option.pragma_parse = aarch64_pragma_target_parse;
214 }