Line data Source code
1 : /* Data structure definitions for a generic GCC target.
2 : Copyright (C) 2001-2026 Free Software Foundation, Inc.
3 :
4 : This program is free software; you can redistribute it and/or modify it
5 : under the terms of the GNU General Public License as published by the
6 : Free Software Foundation; either version 3, or (at your option) any
7 : later version.
8 :
9 : This program is distributed in the hope that it will be useful,
10 : but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : GNU General Public License for more details.
13 :
14 : You should have received a copy of the GNU General Public License
15 : along with this program; see the file COPYING3. If not see
16 : <http://www.gnu.org/licenses/>.
17 :
18 : In other words, you are welcome to use, share and improve this program.
19 : You are forbidden to forbid anyone else to use, share and improve
20 : what you give them. Help stamp out software-hoarding! */
21 :
22 :
23 : /* This file contains a data structure that describes a GCC target.
24 : At present it is incomplete, but in future it should grow to
25 : contain most or all target machine and target O/S specific
26 : information.
27 :
28 : This structure has its initializer declared in target-def.h in the
29 : form of large macro TARGET_INITIALIZER that expands to many smaller
30 : macros.
31 :
32 : The smaller macros each initialize one component of the structure,
33 : and each has a default. Each target should have a file that
34 : includes target.h and target-def.h, and overrides any inappropriate
35 : defaults by undefining the relevant macro and defining a suitable
36 : replacement. That file should then contain the definition of
37 : "targetm" like so:
38 :
39 : struct gcc_target targetm = TARGET_INITIALIZER;
40 :
41 : Doing things this way allows us to bring together everything that
42 : defines a GCC target. By supplying a default that is appropriate
43 : to most targets, we can easily add new items without needing to
44 : edit dozens of target configuration files. It should also allow us
45 : to gradually reduce the amount of conditional compilation that is
46 : scattered throughout GCC. */
47 :
48 : #ifndef GCC_TARGET_H
49 : #define GCC_TARGET_H
50 :
51 : #include "insn-codes.h"
52 : #include "tm.h"
53 : #include "hard-reg-set.h"
54 :
55 : #if CHECKING_P
56 :
57 : struct cumulative_args_t { void *magic; void *p; };
58 :
59 : #else /* !CHECKING_P */
60 :
61 : /* When using a GCC build compiler, we could use
62 : __attribute__((transparent_union)) to get cumulative_args_t function
63 : arguments passed like scalars where the ABI would mandate a less
64 : efficient way of argument passing otherwise. However, that would come
65 : at the cost of less type-safe !CHECKING_P compilation. */
66 :
67 : union cumulative_args_t { void *p; };
68 :
69 : #endif /* !CHECKING_P */
70 :
71 : /* Target properties of _BitInt(N) type. _BitInt(N) is to be represented
72 : as series of abi_limb_mode CEIL (N, GET_MODE_PRECISION (abi_limb_mode))
73 : limbs, ordered from least significant to most significant if !big_endian,
74 : otherwise from most significant to least significant. If extended is
75 : false, the bits above or equal to N are undefined when stored in a register
76 : or memory, otherwise they are zero or sign extended depending on if
77 : it is unsigned _BitInt(N) or _BitInt(N) / signed _BitInt(N).
78 : limb_mode is either the same as abi_limb_mode, or some narrower mode
79 : in which _BitInt lowering should actually perform operations in and
80 : what libgcc _BitInt helpers should use.
81 : E.g. abi_limb_mode could be TImode which is something some processor
82 : specific ABI would specify to use, but it would be desirable to handle
83 : it as an array of DImode instead for efficiency.
84 : Note, abi_limb_mode can be different from limb_mode only if big_endian
85 : matches WORDS_BIG_ENDIAN. */
86 :
87 : struct bitint_info {
88 : machine_mode abi_limb_mode, limb_mode;
89 : bool big_endian;
90 : bool extended;
91 : };
92 :
93 : /* Types of memory operation understood by the "by_pieces" infrastructure.
94 : Used by the TARGET_USE_BY_PIECES_INFRASTRUCTURE_P target hook and
95 : internally by the functions in expr.cc. */
96 :
97 : enum by_pieces_operation
98 : {
99 : CLEAR_BY_PIECES,
100 : MOVE_BY_PIECES,
101 : SET_BY_PIECES,
102 : STORE_BY_PIECES,
103 : COMPARE_BY_PIECES
104 : };
105 :
106 : extern unsigned HOST_WIDE_INT by_pieces_ninsns (unsigned HOST_WIDE_INT,
107 : unsigned int,
108 : unsigned int,
109 : by_pieces_operation);
110 :
111 : /* An example implementation for ELF targets. Defined in varasm.cc */
112 : extern void elf_record_gcc_switches (const char *);
113 :
114 : /* Some places still assume that all pointer or address modes are the
115 : standard Pmode and ptr_mode. These optimizations become invalid if
116 : the target actually supports multiple different modes. For now,
117 : we disable such optimizations on such targets, using this function. */
118 : extern bool target_default_pointer_address_modes_p (void);
119 :
120 : /* For hooks which use the MOVE_RATIO macro, this gives the legacy default
121 : behavior. */
122 : extern unsigned int get_move_ratio (bool);
123 :
124 : struct stdarg_info;
125 : struct spec_info_def;
126 : struct hard_reg_set_container;
127 : struct cgraph_node;
128 : struct cgraph_simd_clone;
129 :
130 : /* The struct used by the secondary_reload target hook. */
131 : struct secondary_reload_info
132 : {
133 : /* icode is actually an enum insn_code, but we don't want to force every
134 : file that includes target.h to include optabs.h . */
135 : int icode;
136 : int extra_cost; /* Cost for using (a) scratch register(s) to be taken
137 : into account by copy_cost. */
138 : /* The next two members are for the use of the backward
139 : compatibility hook. */
140 : struct secondary_reload_info *prev_sri;
141 : int t_icode; /* Actually an enum insn_code - see above. */
142 : };
143 :
144 : /* This is defined in sched-int.h . */
145 : struct _dep;
146 :
147 : /* This is defined in ddg.h . */
148 : struct ddg;
149 :
150 : /* This is defined in cfgloop.h . */
151 : class loop;
152 :
153 : /* This is defined in ifcvt.h. */
154 : struct noce_if_info;
155 :
156 : /* This is defined in tree-ssa-alias.h. */
157 : class ao_ref;
158 :
159 : /* This is defined in tree-vectorizer.h. */
160 : class _stmt_vec_info;
161 :
162 : /* This is defined in calls.h. */
163 : class function_arg_info;
164 :
165 : /* This is defined in function-abi.h. */
166 : class predefined_function_abi;
167 :
168 : /* This is defined in avoid-store-forwarding.h. */
169 : struct store_fwd_info;
170 :
171 : /* These are defined in tree-vect-stmts.cc. */
172 : extern bool stmt_in_inner_loop_p (class vec_info *, class _stmt_vec_info *);
173 :
174 : /* Assembler instructions for creating various kinds of integer object. */
175 :
176 : struct asm_int_op
177 : {
178 : const char *hi;
179 : const char *psi;
180 : const char *si;
181 : const char *pdi;
182 : const char *di;
183 : const char *pti;
184 : const char *ti;
185 : };
186 :
187 : /* Types of costs for vectorizer cost model. */
188 : enum vect_cost_for_stmt
189 : {
190 : scalar_stmt,
191 : scalar_load,
192 : scalar_store,
193 : vector_stmt,
194 : vector_load,
195 : vector_gather_load,
196 : unaligned_load,
197 : unaligned_store,
198 : vector_store,
199 : vector_scatter_store,
200 : vec_to_scalar,
201 : scalar_to_vec,
202 : cond_branch_not_taken,
203 : cond_branch_taken,
204 : vec_perm,
205 : vec_promote_demote,
206 : vec_construct
207 : };
208 :
209 : /* Separate locations for which the vectorizer cost model should
210 : track costs. */
211 : enum vect_cost_model_location {
212 : vect_prologue = 0,
213 : vect_body = 1,
214 : vect_epilogue = 2
215 : };
216 :
217 : class vec_perm_indices;
218 :
219 : /* The type to use for lists of vector sizes. */
220 : typedef vec<machine_mode> vector_modes;
221 :
222 : /* Same, but can be used to construct local lists that are
223 : automatically freed. */
224 : typedef auto_vec<machine_mode, 8> auto_vector_modes;
225 :
226 : /* First argument of targetm.omp.device_kind_arch_isa. */
227 : enum omp_device_kind_arch_isa {
228 : omp_device_kind,
229 : omp_device_arch,
230 : omp_device_isa
231 : };
232 :
233 : /* Flags returned by TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES:
234 :
235 : VECT_COMPARE_COSTS
236 : Tells the loop vectorizer to try all the provided modes and
237 : pick the one with the lowest cost. By default the vectorizer
238 : will choose the first mode that works. */
239 : const unsigned int VECT_COMPARE_COSTS = 1U << 0;
240 :
241 : /* The contexts in which the use of a type T can be checked by
242 : TARGET_VERIFY_TYPE_CONTEXT. */
243 : enum type_context_kind {
244 : /* Directly measuring the size of T. */
245 : TCTX_SIZEOF,
246 :
247 : /* Directly measuring the alignment of T. */
248 : TCTX_ALIGNOF,
249 :
250 : /* Creating objects of type T with static storage duration. */
251 : TCTX_STATIC_STORAGE,
252 :
253 : /* Creating objects of type T with thread-local storage duration. */
254 : TCTX_THREAD_STORAGE,
255 :
256 : /* Creating a field of type T. */
257 : TCTX_FIELD,
258 :
259 : /* Creating an array with elements of type T. */
260 : TCTX_ARRAY_ELEMENT,
261 :
262 : /* Adding to or subtracting from a pointer to T, or computing the
263 : difference between two pointers when one of them is a pointer to T. */
264 : TCTX_POINTER_ARITH,
265 :
266 : /* Dynamically allocating objects of type T. */
267 : TCTX_ALLOCATION,
268 :
269 : /* Dynamically deallocating objects of type T. */
270 : TCTX_DEALLOCATION,
271 :
272 : /* Throwing or catching an object of type T. */
273 : TCTX_EXCEPTIONS,
274 :
275 : /* Capturing objects of type T by value in a closure. */
276 : TCTX_CAPTURE_BY_COPY,
277 :
278 : /* Objects of type T appearing in OpenMP map clause. */
279 : TCTX_OMP_MAP,
280 :
281 : /* Objects of type T appearing in OpenMP target region
282 : without explicit map. */
283 : TCTX_OMP_MAP_IMP_REF,
284 :
285 : /* Objects of type T appearing in OpenMP private clause. */
286 : TCTX_OMP_PRIVATE,
287 :
288 : /* Objects of type T appearing in OpenMP firstprivate clause. */
289 : TCTX_OMP_FIRSTPRIVATE,
290 :
291 : /* Objects of type T appearing in OpenMP device clauses. */
292 : TCTX_OMP_DEVICE_ADDR
293 :
294 : };
295 :
296 : enum poly_value_estimate_kind
297 : {
298 : POLY_VALUE_MIN,
299 : POLY_VALUE_MAX,
300 : POLY_VALUE_LIKELY
301 : };
302 :
303 : enum class spill_cost_type
304 : {
305 : SAVE,
306 : RESTORE
307 : };
308 :
309 : enum class frame_cost_type
310 : {
311 : ALLOCATION,
312 : DEALLOCATION
313 : };
314 :
315 : typedef void (*emit_support_tinfos_callback) (tree);
316 :
317 : extern bool verify_type_context (location_t, type_context_kind, const_tree,
318 : bool = false);
319 :
320 : /* The target structure. This holds all the backend hooks. */
321 : #define DEFHOOKPOD(NAME, DOC, TYPE, INIT) TYPE NAME;
322 : #define DEFHOOK(NAME, DOC, TYPE, PARAMS, INIT) TYPE (* NAME) PARAMS;
323 : #define DEFHOOK_UNDOC DEFHOOK
324 : #define HOOKSTRUCT(FRAGMENT) FRAGMENT
325 :
326 : #include "target.def"
327 :
328 : extern struct gcc_target targetm;
329 :
330 : /* Return an estimate of the runtime value of X, for use in things
331 : like cost calculations or profiling frequencies. Note that this
332 : function should never be used in situations where the actual
333 : runtime value is needed for correctness, since the function only
334 : provides a rough guess. */
335 :
336 : inline HOST_WIDE_INT
337 27928 : estimated_poly_value (poly_int64 x,
338 : poly_value_estimate_kind kind = POLY_VALUE_LIKELY)
339 : {
340 27928 : if (NUM_POLY_INT_COEFFS == 1)
341 27928 : return x.coeffs[0];
342 : else
343 : return targetm.estimated_poly_value (x, kind);
344 : }
345 :
346 : /* Return true when MODE can be used to copy GET_MODE_BITSIZE bits
347 : unchanged. */
348 :
349 : inline bool
350 5405721 : mode_can_transfer_bits (machine_mode mode)
351 : {
352 5405721 : if (mode == BLKmode)
353 : return true;
354 9103506 : if (maybe_ne (GET_MODE_BITSIZE (mode),
355 9103506 : GET_MODE_UNIT_PRECISION (mode) * GET_MODE_NUNITS (mode)))
356 : return false;
357 4549977 : if (targetm.mode_can_transfer_bits)
358 4549977 : return targetm.mode_can_transfer_bits (mode);
359 : return true;
360 : }
361 :
362 : /* Return true if OpenMP context types. */
363 :
364 : inline bool
365 : omp_type_context (type_context_kind context)
366 : {
367 : switch (context)
368 : {
369 : case TCTX_OMP_MAP:
370 : case TCTX_OMP_MAP_IMP_REF:
371 : case TCTX_OMP_PRIVATE:
372 : case TCTX_OMP_FIRSTPRIVATE:
373 : case TCTX_OMP_DEVICE_ADDR:
374 : return true;
375 : default:
376 : return false;
377 : }
378 : }
379 :
380 : #ifdef GCC_TM_H
381 :
382 : #ifndef CUMULATIVE_ARGS_MAGIC
383 : #define CUMULATIVE_ARGS_MAGIC ((void *) &targetm.calls)
384 : #endif
385 :
386 : inline CUMULATIVE_ARGS *
387 85286954 : get_cumulative_args (cumulative_args_t arg)
388 : {
389 : #if CHECKING_P
390 85286954 : gcc_assert (arg.magic == CUMULATIVE_ARGS_MAGIC);
391 : #endif /* CHECKING_P */
392 85286954 : return (CUMULATIVE_ARGS *) arg.p;
393 : }
394 :
395 : inline cumulative_args_t
396 34893053 : pack_cumulative_args (CUMULATIVE_ARGS *arg)
397 : {
398 34893053 : cumulative_args_t ret;
399 :
400 : #if CHECKING_P
401 34893053 : ret.magic = CUMULATIVE_ARGS_MAGIC;
402 : #endif /* CHECKING_P */
403 34893053 : ret.p = (void *) arg;
404 34893053 : return ret;
405 : }
406 : #endif /* GCC_TM_H */
407 :
408 : #endif /* GCC_TARGET_H */
|