Branch data Line data Source code
1 : : /* Default language-specific hooks.
2 : : Copyright (C) 2001-2025 Free Software Foundation, Inc.
3 : : Contributed by Alexandre Oliva <aoliva@redhat.com>
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify
8 : : it under the terms of the GNU General Public License as published by
9 : : the Free Software Foundation; either version 3, or (at your option)
10 : : any later version.
11 : :
12 : : GCC is distributed in the hope that it will be useful,
13 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : GNU General Public License for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "target.h"
25 : : #include "rtl.h"
26 : : #include "tree.h"
27 : : #include "timevar.h"
28 : : #include "stringpool.h"
29 : : #include "diagnostic.h"
30 : : #include "intl.h"
31 : : #include "toplev.h"
32 : : #include "attribs.h"
33 : : #include "gimplify.h"
34 : : #include "langhooks.h"
35 : : #include "tree-diagnostic.h"
36 : : #include "output.h"
37 : : #include "timevar.h"
38 : : #include "stor-layout.h"
39 : : #include "cgraph.h"
40 : : #include "debug.h"
41 : : #include "diagnostic-format-text.h"
42 : :
43 : : /* Do nothing; in many cases the default hook. */
44 : :
45 : : void
46 : 72999 : lhd_do_nothing (void)
47 : : {
48 : 72999 : }
49 : :
50 : : /* Do nothing (tree). */
51 : :
52 : : void
53 : 12289802 : lhd_do_nothing_t (tree ARG_UNUSED (t))
54 : : {
55 : 12289802 : }
56 : :
57 : : /* Pass through (tree). */
58 : : tree
59 : 424 : lhd_pass_through_t (tree t)
60 : : {
61 : 424 : return t;
62 : : }
63 : :
64 : : /* Do nothing (int, int, int). Return NULL_TREE. */
65 : :
66 : : tree
67 : 0 : lhd_do_nothing_iii_return_null_tree (int ARG_UNUSED (i),
68 : : int ARG_UNUSED (j),
69 : : int ARG_UNUSED (k))
70 : : {
71 : 0 : return NULL_TREE;
72 : : }
73 : :
74 : : /* Do nothing (function). */
75 : :
76 : : void
77 : 0 : lhd_do_nothing_f (struct function * ARG_UNUSED (f))
78 : : {
79 : 0 : }
80 : :
81 : : /* Do nothing (return NULL_TREE). */
82 : :
83 : : tree
84 : 0 : lhd_return_null_tree (tree ARG_UNUSED (t))
85 : : {
86 : 0 : return NULL_TREE;
87 : : }
88 : :
89 : : /* Do nothing (return NULL_TREE). */
90 : :
91 : : tree
92 : 9093 : lhd_return_null_const_tree (const_tree ARG_UNUSED (t))
93 : : {
94 : 9093 : return NULL_TREE;
95 : : }
96 : :
97 : : /* The default post options hook. */
98 : :
99 : : bool
100 : 1254 : lhd_post_options (const char ** ARG_UNUSED (pfilename))
101 : : {
102 : : /* Excess precision other than "fast" requires front-end
103 : : support. */
104 : 1254 : flag_excess_precision = EXCESS_PRECISION_FAST;
105 : 1254 : return false;
106 : : }
107 : :
108 : : /* Called from by print-tree.cc. */
109 : :
110 : : void
111 : 71 : lhd_print_tree_nothing (FILE * ARG_UNUSED (file),
112 : : tree ARG_UNUSED (node),
113 : : int ARG_UNUSED (indent))
114 : : {
115 : 71 : }
116 : :
117 : : /* Called from check_global_declaration. */
118 : :
119 : : bool
120 : 6 : lhd_warn_unused_global_decl (const_tree decl)
121 : : {
122 : : /* This is what used to exist in check_global_declaration. Probably
123 : : not many of these actually apply to non-C languages. */
124 : :
125 : 6 : if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
126 : : return false;
127 : 6 : if (VAR_P (decl) && TREE_READONLY (decl))
128 : : return false;
129 : 6 : if (DECL_IN_SYSTEM_HEADER (decl))
130 : : return false;
131 : :
132 : : return true;
133 : : }
134 : :
135 : : /* Set the DECL_ASSEMBLER_NAME for DECL. */
136 : : void
137 : 6523979 : lhd_set_decl_assembler_name (tree decl)
138 : : {
139 : 6523979 : tree id;
140 : :
141 : : /* set_decl_assembler_name may be called on TYPE_DECL to record ODR
142 : : name for C++ types. By default types have no ODR names. */
143 : 6523979 : if (TREE_CODE (decl) == TYPE_DECL)
144 : : return;
145 : :
146 : : /* The language-independent code should never use the
147 : : DECL_ASSEMBLER_NAME for lots of DECLs. Only FUNCTION_DECLs and
148 : : VAR_DECLs for variables with static storage duration need a real
149 : : DECL_ASSEMBLER_NAME. */
150 : 6419882 : gcc_assert (TREE_CODE (decl) == FUNCTION_DECL
151 : : || (VAR_P (decl)
152 : : && (TREE_STATIC (decl)
153 : : || DECL_EXTERNAL (decl)
154 : : || TREE_PUBLIC (decl))));
155 : :
156 : : /* By default, assume the name to use in assembly code is the same
157 : : as that used in the source language. (That's correct for C, and
158 : : GCC used to set DECL_ASSEMBLER_NAME to the same value as
159 : : DECL_NAME in build_decl, so this choice provides backwards
160 : : compatibility with existing front-ends. This assumption is wrapped
161 : : in a target hook, to allow for target-specific modification of the
162 : : identifier.
163 : :
164 : : Can't use just the variable's own name for a variable whose scope
165 : : is less than the whole compilation. Concatenate a distinguishing
166 : : number. */
167 : :
168 : 6419882 : if (TREE_PUBLIC (decl) || DECL_FILE_SCOPE_P (decl))
169 : 6194595 : id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
170 : : else
171 : : {
172 : 225287 : const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
173 : 225287 : static unsigned long num;
174 : 225287 : char *label;
175 : :
176 : 225287 : ASM_FORMAT_PRIVATE_NAME (label, name, num++);
177 : 225287 : id = get_identifier (label);
178 : : }
179 : :
180 : 6419882 : SET_DECL_ASSEMBLER_NAME (decl, id);
181 : : }
182 : :
183 : : /* Forcibly overwrite the DECL_ASSEMBLER_NAME for DECL to NAME. */
184 : : void
185 : 171856524 : lhd_overwrite_decl_assembler_name (tree decl, tree name)
186 : : {
187 : 171856524 : DECL_ASSEMBLER_NAME_RAW (decl) = name;
188 : 171856524 : }
189 : :
190 : : /* Type promotion for variable arguments. */
191 : : tree
192 : 0 : lhd_type_promotes_to (tree ARG_UNUSED (type))
193 : : {
194 : 0 : gcc_unreachable ();
195 : : }
196 : :
197 : : /* Registration of machine- or os-specific builtin types. */
198 : : void
199 : 127296 : lhd_register_builtin_type (tree ARG_UNUSED (type),
200 : : const char * ARG_UNUSED (name))
201 : : {
202 : 127296 : }
203 : :
204 : : /* Invalid use of an incomplete type. */
205 : : void
206 : 0 : lhd_incomplete_type_error (location_t ARG_UNUSED (loc),
207 : : const_tree ARG_UNUSED (value), const_tree type)
208 : : {
209 : 0 : gcc_assert (TREE_CODE (type) == ERROR_MARK);
210 : 0 : return;
211 : : }
212 : :
213 : : /* Provide a default routine for alias sets that always returns -1. This
214 : : is used by languages that don't need to do anything special. */
215 : :
216 : : alias_set_type
217 : 1043778327 : lhd_get_alias_set (tree ARG_UNUSED (t))
218 : : {
219 : 1043778327 : return -1;
220 : : }
221 : :
222 : : /* This is the default decl_printable_name function. */
223 : :
224 : : const char *
225 : 7856998 : lhd_decl_printable_name (tree decl, int ARG_UNUSED (verbosity))
226 : : {
227 : 7856998 : gcc_assert (decl && DECL_NAME (decl));
228 : 7856998 : return IDENTIFIER_POINTER (DECL_NAME (decl));
229 : : }
230 : :
231 : : /* This is the default dwarf_name function. */
232 : :
233 : : const char *
234 : 7512151 : lhd_dwarf_name (tree t, int verbosity)
235 : : {
236 : 7512151 : gcc_assert (DECL_P (t));
237 : :
238 : 7512151 : return lang_hooks.decl_printable_name (t, verbosity);
239 : : }
240 : :
241 : : /* This compares two types for equivalence ("compatible" in C-based languages).
242 : : This routine should only return 1 if it is sure. It should not be used
243 : : in contexts where erroneously returning 0 causes problems. */
244 : :
245 : : int
246 : 0 : lhd_types_compatible_p (tree x, tree y)
247 : : {
248 : 0 : return TYPE_MAIN_VARIANT (x) == TYPE_MAIN_VARIANT (y);
249 : : }
250 : :
251 : : /* lang_hooks.tree_dump.dump_tree: Dump language-specific parts of tree
252 : : nodes. Returns nonzero if it does not want the usual dumping of the
253 : : second argument. */
254 : :
255 : : bool
256 : 0 : lhd_tree_dump_dump_tree (void *di ATTRIBUTE_UNUSED, tree t ATTRIBUTE_UNUSED)
257 : : {
258 : 0 : return false;
259 : : }
260 : :
261 : : /* lang_hooks.tree_dump.type_qual: Determine type qualifiers in a
262 : : language-specific way. */
263 : :
264 : : int
265 : 4 : lhd_tree_dump_type_quals (const_tree t)
266 : : {
267 : 4 : return TYPE_QUALS (t);
268 : : }
269 : :
270 : : /* lang_hooks.gimplify_expr re-writes *EXPR_P into GIMPLE form. */
271 : :
272 : : int
273 : 82123347 : lhd_gimplify_expr (tree *expr_p ATTRIBUTE_UNUSED,
274 : : gimple_seq *pre_p ATTRIBUTE_UNUSED,
275 : : gimple_seq *post_p ATTRIBUTE_UNUSED)
276 : : {
277 : 82123347 : return GS_UNHANDLED;
278 : : }
279 : :
280 : : /* lang_hooks.tree_size: Determine the size of a tree with code C,
281 : : which is a language-specific tree code in category tcc_constant,
282 : : tcc_exceptional or tcc_type. The default expects never to be called. */
283 : : size_t
284 : 0 : lhd_tree_size (enum tree_code c ATTRIBUTE_UNUSED)
285 : : {
286 : 0 : gcc_unreachable ();
287 : : }
288 : :
289 : : /* Return true if decl, which is a function decl, may be called by a
290 : : sibcall. */
291 : :
292 : : bool
293 : 124659 : lhd_decl_ok_for_sibcall (const_tree decl ATTRIBUTE_UNUSED)
294 : : {
295 : 124659 : return true;
296 : : }
297 : :
298 : : /* Generic global declaration processing. This is meant to be called
299 : : by the front-ends at the end of parsing. C/C++ do their own thing,
300 : : but other front-ends may call this. */
301 : :
302 : : void
303 : 30564 : global_decl_processing (void)
304 : : {
305 : 30564 : tree globals, decl, *vec;
306 : 30564 : int len, i;
307 : :
308 : 30564 : timevar_stop (TV_PHASE_PARSING);
309 : 30564 : timevar_start (TV_PHASE_DEFERRED);
310 : : /* Really define vars that have had only a tentative definition.
311 : : Really output inline functions that must actually be callable
312 : : and have not been output so far. */
313 : :
314 : 30564 : globals = lang_hooks.decls.getdecls ();
315 : 30564 : len = list_length (globals);
316 : 30564 : vec = XNEWVEC (tree, len);
317 : :
318 : : /* Process the decls in reverse order--earliest first.
319 : : Put them into VEC from back to front, then take out from front. */
320 : :
321 : 136886787 : for (i = 0, decl = globals; i < len; i++, decl = DECL_CHAIN (decl))
322 : 136825659 : vec[len - i - 1] = decl;
323 : :
324 : 30564 : wrapup_global_declarations (vec, len);
325 : 30564 : timevar_stop (TV_PHASE_DEFERRED);
326 : :
327 : 30564 : timevar_start (TV_PHASE_PARSING);
328 : 30564 : free (vec);
329 : 30564 : }
330 : :
331 : : /* Called to perform language-specific initialization of CTX. */
332 : : void
333 : 78766 : lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED)
334 : : {
335 : 78766 : }
336 : :
337 : : /* Called to register dumps. */
338 : : void
339 : 168070 : lhd_register_dumps (gcc::dump_manager *)
340 : : {
341 : 168070 : }
342 : :
343 : : /* Called to perform language-specific options initialization. */
344 : : void
345 : 32914 : lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
346 : : struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
347 : : {
348 : 32914 : }
349 : :
350 : : /* By default, always complain about options for the wrong language. */
351 : : bool
352 : 6 : lhd_complain_wrong_lang_p (const struct cl_option *option ATTRIBUTE_UNUSED)
353 : : {
354 : 6 : return true;
355 : : }
356 : :
357 : : /* By default, no language-specific options are valid. */
358 : : bool
359 : 0 : lhd_handle_option (size_t code ATTRIBUTE_UNUSED,
360 : : const char *arg ATTRIBUTE_UNUSED,
361 : : HOST_WIDE_INT value ATTRIBUTE_UNUSED,
362 : : int kind ATTRIBUTE_UNUSED,
363 : : location_t loc ATTRIBUTE_UNUSED,
364 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
365 : : {
366 : 0 : return false;
367 : : }
368 : :
369 : : /* The default function to print out name of current function that caused
370 : : an error. */
371 : : void
372 : 105407 : lhd_print_error_function (diagnostic_text_output_format &text_output,
373 : : const char *file,
374 : : const diagnostic_info *diagnostic)
375 : : {
376 : 105407 : diagnostic_context *const context = &text_output.get_context ();
377 : 105407 : if (diagnostic_last_function_changed (context, diagnostic))
378 : : {
379 : 15406 : pretty_printer *const pp = text_output.get_printer ();
380 : 15406 : char *old_prefix = pp_take_prefix (pp);
381 : 15406 : tree abstract_origin = diagnostic_abstract_origin (diagnostic);
382 : 15406 : char *new_prefix = (file && abstract_origin == NULL)
383 : 15406 : ? text_output.file_name_as_prefix (file) : NULL;
384 : :
385 : 15406 : pp_set_prefix (pp, new_prefix);
386 : :
387 : 15406 : if (current_function_decl == NULL)
388 : 588 : pp_printf (pp, _("At top level:"));
389 : : else
390 : : {
391 : 14818 : tree fndecl, ao;
392 : :
393 : 14818 : if (abstract_origin)
394 : : {
395 : 187 : ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
396 : 187 : gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
397 : : fndecl = ao;
398 : : }
399 : : else
400 : : fndecl = current_function_decl;
401 : :
402 : 14818 : if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
403 : 6 : pp_printf
404 : 6 : (pp, _("In member function %qs"),
405 : 6 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
406 : : else
407 : 14812 : pp_printf
408 : 14812 : (pp, _("In function %qs"),
409 : 14812 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
410 : :
411 : 15069 : while (abstract_origin)
412 : : {
413 : 251 : location_t *locus;
414 : 251 : tree block = abstract_origin;
415 : :
416 : 251 : locus = &BLOCK_SOURCE_LOCATION (block);
417 : 251 : fndecl = NULL;
418 : 251 : block = BLOCK_SUPERCONTEXT (block);
419 : 528 : while (block && TREE_CODE (block) == BLOCK
420 : 554 : && BLOCK_ABSTRACT_ORIGIN (block))
421 : : {
422 : 90 : ao = BLOCK_ABSTRACT_ORIGIN (block);
423 : 90 : if (TREE_CODE (ao) == FUNCTION_DECL)
424 : : {
425 : : fndecl = ao;
426 : : break;
427 : : }
428 : 26 : else if (TREE_CODE (ao) != BLOCK)
429 : : break;
430 : :
431 : 26 : block = BLOCK_SUPERCONTEXT (block);
432 : : }
433 : 251 : if (fndecl)
434 : : abstract_origin = block;
435 : : else
436 : : {
437 : 435 : while (block && TREE_CODE (block) == BLOCK)
438 : 248 : block = BLOCK_SUPERCONTEXT (block);
439 : :
440 : 187 : if (block && TREE_CODE (block) == FUNCTION_DECL)
441 : : fndecl = block;
442 : : abstract_origin = NULL;
443 : : }
444 : : if (fndecl)
445 : : {
446 : 251 : expanded_location s = expand_location (*locus);
447 : 251 : pp_comma (pp);
448 : 251 : pp_newline (pp);
449 : 251 : if (s.file != NULL)
450 : : {
451 : 251 : if (context->m_show_column)
452 : 251 : pp_printf (pp,
453 : 251 : _(" inlined from %qs at %r%s:%d:%d%R"),
454 : 251 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
455 : : "locus", s.file, s.line, s.column);
456 : : else
457 : 0 : pp_printf (pp,
458 : 0 : _(" inlined from %qs at %r%s:%d%R"),
459 : 0 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
460 : : "locus", s.file, s.line);
461 : :
462 : : }
463 : : else
464 : 0 : pp_printf (pp, _(" inlined from %qs"),
465 : 0 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
466 : : }
467 : : }
468 : 14818 : pp_colon (pp);
469 : : }
470 : :
471 : 15406 : diagnostic_set_last_function (context, diagnostic);
472 : 15406 : pp_newline_and_flush (pp);
473 : 15406 : pp->set_prefix (old_prefix);
474 : : }
475 : 105407 : }
476 : :
477 : : tree
478 : 224752 : lhd_make_node (enum tree_code code)
479 : : {
480 : 224752 : return make_node (code);
481 : : }
482 : :
483 : : /* Default implementation of LANG_HOOKS_SIMULATE_ENUM_DECL. Assume a
484 : : simple int-based enumerator (which is all the hook can be used for
485 : : at present) and push each decl individually without any decoration.
486 : :
487 : : This definition is suitable for LTO and is generic enough that it
488 : : might be reusable elsewhere. */
489 : : tree
490 : 0 : lhd_simulate_enum_decl (location_t loc, const char *name,
491 : : vec<string_int_pair> *values_ptr)
492 : : {
493 : 0 : tree enumtype = lang_hooks.types.make_type (ENUMERAL_TYPE);
494 : 0 : tree enumdecl = build_decl (loc, TYPE_DECL, get_identifier (name), enumtype);
495 : 0 : TYPE_STUB_DECL (enumtype) = enumdecl;
496 : :
497 : 0 : tree value_chain = NULL_TREE;
498 : 0 : string_int_pair *value;
499 : 0 : vec<string_int_pair> values = *values_ptr;
500 : 0 : unsigned int i;
501 : 0 : FOR_EACH_VEC_ELT (values, i, value)
502 : : {
503 : 0 : tree value_decl = build_decl (loc, CONST_DECL,
504 : : get_identifier (value->first), enumtype);
505 : 0 : DECL_INITIAL (value_decl) = build_int_cst (integer_type_node,
506 : 0 : value->second);
507 : 0 : lang_hooks.decls.pushdecl (value_decl);
508 : 0 : value_chain = tree_cons (value_decl, DECL_INITIAL (value_decl),
509 : : value_chain);
510 : : }
511 : :
512 : 0 : TYPE_MIN_VALUE (enumtype) = TYPE_MIN_VALUE (integer_type_node);
513 : 0 : TYPE_MAX_VALUE (enumtype) = TYPE_MAX_VALUE (integer_type_node);
514 : 0 : SET_TYPE_ALIGN (enumtype, TYPE_ALIGN (integer_type_node));
515 : 0 : TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
516 : 0 : layout_type (enumtype);
517 : 0 : lang_hooks.decls.pushdecl (enumdecl);
518 : :
519 : 0 : return enumtype;
520 : : }
521 : :
522 : : /* Default implementation of LANG_HOOKS_SIMULATE_RECORD_DECL.
523 : : Just create a normal RECORD_TYPE and a TYPE_DECL for it. */
524 : : tree
525 : 0 : lhd_simulate_record_decl (location_t loc, const char *name,
526 : : array_slice<const tree> fields)
527 : : {
528 : 0 : for (unsigned int i = 1; i < fields.size (); ++i)
529 : : /* Reversed by finish_builtin_struct. */
530 : 0 : DECL_CHAIN (fields[i]) = fields[i - 1];
531 : :
532 : 0 : tree type = lang_hooks.types.make_type (RECORD_TYPE);
533 : 0 : finish_builtin_struct (type, name, fields.back (), NULL_TREE);
534 : :
535 : 0 : tree decl = build_decl (loc, TYPE_DECL, get_identifier (name), type);
536 : 0 : lang_hooks.decls.pushdecl (decl);
537 : :
538 : 0 : return type;
539 : : }
540 : :
541 : : /* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE.
542 : : Return an integer type with PRECISION bits of precision,
543 : : that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
544 : :
545 : : tree
546 : 115625 : lhd_type_for_size (unsigned precision, int unsignedp)
547 : : {
548 : 115625 : int i;
549 : :
550 : 115625 : if (precision == TYPE_PRECISION (integer_type_node))
551 : 23143 : return unsignedp ? unsigned_type_node : integer_type_node;
552 : :
553 : 92482 : if (precision == TYPE_PRECISION (signed_char_type_node))
554 : 23116 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
555 : :
556 : 69366 : if (precision == TYPE_PRECISION (short_integer_type_node))
557 : 23116 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
558 : :
559 : 46250 : if (precision == TYPE_PRECISION (long_integer_type_node))
560 : 23134 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
561 : :
562 : 23116 : if (precision == TYPE_PRECISION (long_long_integer_type_node))
563 : 0 : return unsignedp
564 : 0 : ? long_long_unsigned_type_node
565 : 0 : : long_long_integer_type_node;
566 : :
567 : 23116 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
568 : 23116 : if (int_n_enabled_p[i]
569 : 23116 : && precision == int_n_data[i].bitsize)
570 : 23116 : return (unsignedp ? int_n_trees[i].unsigned_type
571 : 23116 : : int_n_trees[i].signed_type);
572 : :
573 : 0 : if (precision <= TYPE_PRECISION (intQI_type_node))
574 : 0 : return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
575 : :
576 : 0 : if (precision <= TYPE_PRECISION (intHI_type_node))
577 : 0 : return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
578 : :
579 : 0 : if (precision <= TYPE_PRECISION (intSI_type_node))
580 : 0 : return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
581 : :
582 : 0 : if (precision <= TYPE_PRECISION (intDI_type_node))
583 : 0 : return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
584 : :
585 : 0 : if (precision <= TYPE_PRECISION (intTI_type_node))
586 : 0 : return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
587 : :
588 : : return NULL_TREE;
589 : : }
590 : :
591 : : HOST_WIDE_INT
592 : 4410573 : lhd_to_target_charset (HOST_WIDE_INT c)
593 : : {
594 : 4410573 : return c;
595 : : }
596 : :
597 : : tree
598 : 1123061939 : lhd_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se ATTRIBUTE_UNUSED)
599 : : {
600 : 1123061939 : return expr;
601 : : }
602 : :
603 : : /* Return sharing kind if OpenMP sharing attribute of DECL is
604 : : predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise. */
605 : :
606 : : enum omp_clause_default_kind
607 : 0 : lhd_omp_predetermined_sharing (tree decl)
608 : : {
609 : 0 : if (DECL_ARTIFICIAL (decl))
610 : 0 : return OMP_CLAUSE_DEFAULT_SHARED;
611 : : return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
612 : : }
613 : :
614 : : /* Return sharing kind if OpenMP mapping attribute of DECL is
615 : : predetermined, OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED otherwise. */
616 : :
617 : : enum omp_clause_defaultmap_kind
618 : 0 : lhd_omp_predetermined_mapping (tree decl)
619 : : {
620 : 0 : if (DECL_ARTIFICIAL (decl))
621 : 0 : return OMP_CLAUSE_DEFAULTMAP_TO;
622 : : return OMP_CLAUSE_DEFAULTMAP_CATEGORY_UNSPECIFIED;
623 : : }
624 : :
625 : : /* Generate code to copy SRC to DST. */
626 : :
627 : : tree
628 : 0 : lhd_omp_assignment (tree clause ATTRIBUTE_UNUSED, tree dst, tree src)
629 : : {
630 : 0 : return build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
631 : : }
632 : :
633 : : /* Finalize clause C. */
634 : :
635 : : void
636 : 49643 : lhd_omp_finish_clause (tree, gimple_seq *, bool)
637 : : {
638 : 49643 : }
639 : :
640 : : /* Return array size; cf. omp_array_data. */
641 : :
642 : : tree
643 : 0 : lhd_omp_array_size (tree, gimple_seq *)
644 : : {
645 : 0 : return NULL_TREE;
646 : : }
647 : :
648 : : /* Returns true when additional mappings for a decl are needed. */
649 : :
650 : : bool
651 : 36514 : lhd_omp_deep_mapping_p (const gimple *, tree)
652 : : {
653 : 36514 : return false;
654 : : }
655 : :
656 : : /* Returns number of additional mappings for a decl. */
657 : :
658 : : tree
659 : 40855 : lhd_omp_deep_mapping_cnt (const gimple *, tree, gimple_seq *)
660 : : {
661 : 40855 : return NULL_TREE;
662 : : }
663 : :
664 : : /* Do the additional mappings. */
665 : :
666 : : void
667 : 0 : lhd_omp_deep_mapping (const gimple *, tree, unsigned HOST_WIDE_INT, tree, tree,
668 : : tree, tree, tree, gimple_seq *)
669 : : {
670 : 0 : }
671 : :
672 : : /* Look up an OpenMP "declare mapper" mapper. */
673 : :
674 : : tree
675 : 0 : lhd_omp_mapper_lookup (tree, tree)
676 : : {
677 : 0 : return NULL_TREE;
678 : : }
679 : :
680 : : /* Given the representation used by the front-end to contain a mapper
681 : : directive, return the statement for the directive itself. */
682 : :
683 : : tree
684 : 0 : lhd_omp_extract_mapper_directive (tree)
685 : : {
686 : 0 : return error_mark_node;
687 : : }
688 : :
689 : : /* Return a simplified form for OMP_ARRAY_SECTION argument, or
690 : : error_mark_node if impossible. */
691 : :
692 : : tree
693 : 0 : lhd_omp_map_array_section (location_t, tree)
694 : : {
695 : 0 : return error_mark_node;
696 : : }
697 : :
698 : : /* Return true if DECL is a scalar variable (for the purpose of
699 : : implicit firstprivatization & mapping). Only if alloc_ptr_ok
700 : : are allocatables and pointers accepted. */
701 : :
702 : : bool
703 : 23402 : lhd_omp_scalar_p (tree decl, bool ptr_ok)
704 : : {
705 : 23402 : tree type = TREE_TYPE (decl);
706 : 23402 : if (TREE_CODE (type) == REFERENCE_TYPE)
707 : 3891 : type = TREE_TYPE (type);
708 : 23402 : if (TREE_CODE (type) == COMPLEX_TYPE)
709 : 36 : type = TREE_TYPE (type);
710 : 23402 : if (INTEGRAL_TYPE_P (type)
711 : 23402 : || SCALAR_FLOAT_TYPE_P (type)
712 : 10581 : || (ptr_ok && TREE_CODE (type) == POINTER_TYPE))
713 : 12841 : return true;
714 : : return false;
715 : : }
716 : :
717 : : /* Return static initializer for DECL. */
718 : :
719 : : tree *
720 : 4293 : lhd_omp_get_decl_init (tree decl)
721 : : {
722 : 4293 : return &DECL_INITIAL (decl);
723 : : }
724 : :
725 : : /* Free any extra memory used to hold initializer information for
726 : : variable declarations. */
727 : :
728 : : void
729 : 5108 : lhd_omp_finish_decl_inits (void)
730 : : {
731 : 5108 : }
732 : :
733 : : /* Register language specific type size variables as potentially OpenMP
734 : : firstprivate variables. */
735 : :
736 : : void
737 : 9251 : lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *c ATTRIBUTE_UNUSED,
738 : : tree t ATTRIBUTE_UNUSED)
739 : : {
740 : 9251 : }
741 : :
742 : : /* Common function for add_builtin_function, add_builtin_function_ext_scope
743 : : and simulate_builtin_function_decl. */
744 : :
745 : : static tree
746 : 818798979 : build_builtin_function (location_t location, const char *name, tree type,
747 : : int function_code, enum built_in_class cl,
748 : : const char *library_name, tree attrs)
749 : : {
750 : 818798979 : tree id = get_identifier (name);
751 : 818798979 : tree decl = build_decl (location, FUNCTION_DECL, id, type);
752 : :
753 : 818798979 : TREE_PUBLIC (decl) = 1;
754 : 818798979 : DECL_EXTERNAL (decl) = 1;
755 : :
756 : 818798979 : set_decl_built_in_function (decl, cl, function_code);
757 : :
758 : 818798979 : if (library_name)
759 : : {
760 : 262125611 : tree libname = get_identifier (library_name);
761 : :
762 : 262125611 : libname = targetm.mangle_decl_assembler_name (decl, libname);
763 : 262125611 : SET_DECL_ASSEMBLER_NAME (decl, libname);
764 : : }
765 : :
766 : : /* Possibly apply some default attributes to this built-in function. */
767 : 818798979 : if (attrs)
768 : 477328855 : decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
769 : : else
770 : 341470124 : decl_attributes (&decl, NULL_TREE, 0);
771 : :
772 : 818798979 : return decl;
773 : : }
774 : :
775 : : /* Create a builtin function. */
776 : :
777 : : tree
778 : 807792063 : add_builtin_function (const char *name,
779 : : tree type,
780 : : int function_code,
781 : : enum built_in_class cl,
782 : : const char *library_name,
783 : : tree attrs)
784 : : {
785 : 807792063 : tree decl = build_builtin_function (BUILTINS_LOCATION, name, type,
786 : : function_code, cl, library_name, attrs);
787 : 807792063 : return lang_hooks.builtin_function (decl);
788 : : }
789 : :
790 : : /* Like add_builtin_function, but make sure the scope is the external scope.
791 : : This is used to delay putting in back end builtin functions until the ISA
792 : : that defines the builtin is declared via function specific target options,
793 : : which can save memory for machines like the x86_64 that have multiple ISAs.
794 : : If this points to the same function as builtin_function, the backend must
795 : : add all of the builtins at program initialization time. */
796 : :
797 : : tree
798 : 11006916 : add_builtin_function_ext_scope (const char *name,
799 : : tree type,
800 : : int function_code,
801 : : enum built_in_class cl,
802 : : const char *library_name,
803 : : tree attrs)
804 : : {
805 : 11006916 : tree decl = build_builtin_function (BUILTINS_LOCATION, name, type,
806 : : function_code, cl, library_name, attrs);
807 : 11006916 : return lang_hooks.builtin_function_ext_scope (decl);
808 : : }
809 : :
810 : : /* Simulate a declaration of a target-specific built-in function at
811 : : location LOCATION, as though it had been declared directly in the
812 : : source language. NAME is the name of the function, TYPE is its function
813 : : type, FUNCTION_CODE is the target-specific function code, LIBRARY_NAME
814 : : is the name of the underlying library function (NULL if none) and
815 : : ATTRS is a list of function attributes.
816 : :
817 : : Return the decl of the declared function. */
818 : :
819 : : tree
820 : 0 : simulate_builtin_function_decl (location_t location, const char *name,
821 : : tree type, int function_code,
822 : : const char *library_name, tree attrs)
823 : : {
824 : 0 : tree decl = build_builtin_function (location, name, type,
825 : : function_code, BUILT_IN_MD,
826 : : library_name, attrs);
827 : 0 : tree new_decl = lang_hooks.simulate_builtin_function_decl (decl);
828 : :
829 : : /* Give the front end a chance to create a new decl if necessary,
830 : : but if the front end discards the decl in favour of a conflicting
831 : : (erroneous) previous definition, return the decl that we tried but
832 : : failed to add. This allows the caller to process the returned decl
833 : : normally, even though the source code won't be able to use it. */
834 : 0 : if (TREE_CODE (new_decl) == FUNCTION_DECL
835 : 0 : && fndecl_built_in_p (new_decl, function_code, BUILT_IN_MD))
836 : 0 : return new_decl;
837 : :
838 : : return decl;
839 : : }
840 : :
841 : : tree
842 : 0 : lhd_builtin_function (tree decl)
843 : : {
844 : 0 : lang_hooks.decls.pushdecl (decl);
845 : 0 : return decl;
846 : : }
847 : :
848 : : /* Create a builtin type. */
849 : :
850 : : tree
851 : 0 : add_builtin_type (const char *name, tree type)
852 : : {
853 : 0 : tree id = get_identifier (name);
854 : 0 : tree decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, id, type);
855 : 0 : return lang_hooks.decls.pushdecl (decl);
856 : : }
857 : :
858 : : /* LTO hooks. */
859 : :
860 : : /* Used to save and restore any previously active section. */
861 : : static section *saved_section;
862 : :
863 : :
864 : : /* Begin a new LTO output section named NAME. This default implementation
865 : : saves the old section and emits assembly code to switch to the new
866 : : section. */
867 : :
868 : : void
869 : 427418 : lhd_begin_section (const char *name)
870 : : {
871 : 427418 : section *section;
872 : :
873 : : /* Save the old section so we can restore it in lto_end_asm_section. */
874 : 427418 : gcc_assert (!saved_section);
875 : 427418 : saved_section = in_section;
876 : 427418 : if (!saved_section)
877 : 22529 : saved_section = text_section;
878 : :
879 : : /* Create a new section and switch to it. */
880 : 427418 : section = get_section (name, SECTION_DEBUG | SECTION_EXCLUDE, NULL, true);
881 : 427418 : switch_to_section (section);
882 : 427418 : }
883 : :
884 : :
885 : : /* Write DATA of length LEN to the current LTO output section. This default
886 : : implementation just calls assemble_string. */
887 : :
888 : : void
889 : 4726712 : lhd_append_data (const void *data, size_t len, void *)
890 : : {
891 : 4726712 : if (data)
892 : : {
893 : 4726712 : timevar_push (TV_IPA_LTO_OUTPUT);
894 : 4726712 : assemble_string ((const char *)data, len);
895 : 4726712 : timevar_pop (TV_IPA_LTO_OUTPUT);
896 : : }
897 : 4726712 : }
898 : :
899 : :
900 : : /* Finish the current LTO output section. This default implementation emits
901 : : assembly code to switch to any section previously saved by
902 : : lhd_begin_section. */
903 : :
904 : : void
905 : 427418 : lhd_end_section (void)
906 : : {
907 : 427418 : if (saved_section)
908 : : {
909 : 427418 : switch_to_section (saved_section);
910 : 427418 : saved_section = NULL;
911 : : }
912 : 427418 : }
913 : :
914 : : /* Default implementation of enum_underlying_base_type using type_for_size. */
915 : :
916 : : tree
917 : 88953 : lhd_enum_underlying_base_type (const_tree enum_type)
918 : : {
919 : 88953 : return lang_hooks.types.type_for_size (TYPE_PRECISION (enum_type),
920 : 88953 : TYPE_UNSIGNED (enum_type));
921 : : }
922 : :
923 : : /* Default implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
924 : :
925 : : const char *
926 : 530 : lhd_get_substring_location (const substring_loc &, location_t *)
927 : : {
928 : 530 : return "unimplemented";
929 : : }
930 : :
931 : : /* Default implementation of LANG_HOOKS_DECL_DWARF_ATTRIBUTE. Don't add
932 : : any attributes. */
933 : :
934 : : int
935 : 6034479 : lhd_decl_dwarf_attribute (const_tree, int)
936 : : {
937 : 6034479 : return -1;
938 : : }
939 : :
940 : : /* Default implementation of LANG_HOOKS_TYPE_DWARF_ATTRIBUTE. Don't add
941 : : any attributes. */
942 : :
943 : : int
944 : 113964 : lhd_type_dwarf_attribute (const_tree, int)
945 : : {
946 : 113964 : return -1;
947 : : }
948 : :
949 : : /* Default implementation of LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING.
950 : : Just return TYPE_SIZE_UNIT unadjusted. */
951 : :
952 : : tree
953 : 7569 : lhd_unit_size_without_reusable_padding (tree t)
954 : : {
955 : 7569 : return TYPE_SIZE_UNIT (t);
956 : : }
957 : :
958 : : /* Default implementation for the finalize_early_debug hook. */
959 : :
960 : : void
961 : 51854 : lhd_finalize_early_debug (void)
962 : : {
963 : : /* Emit early debug for reachable functions, and by consequence,
964 : : locally scoped symbols. */
965 : 51854 : struct cgraph_node *cnode;
966 : 562866 : FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
967 : 511012 : (*debug_hooks->early_global_decl) (cnode->decl);
968 : 51854 : }
969 : :
970 : : /* Default implementation of LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE. */
971 : :
972 : : const char *
973 : 0 : lhd_get_sarif_source_language (const char *)
974 : : {
975 : 0 : return NULL;
976 : : }
977 : :
978 : : /* Returns true if the current lang_hooks represents the GNU C frontend. */
979 : :
980 : : bool
981 : 519086 : lang_GNU_C (void)
982 : : {
983 : 519086 : return (startswith (lang_hooks.name, "GNU C")
984 : 519086 : && (lang_hooks.name[5] == '\0' || ISDIGIT (lang_hooks.name[5])));
985 : : }
986 : :
987 : : /* Returns true if the current lang_hooks represents the GNU C++ frontend. */
988 : :
989 : : bool
990 : 17199 : lang_GNU_CXX (void)
991 : : {
992 : 17199 : return startswith (lang_hooks.name, "GNU C++");
993 : : }
994 : :
995 : : /* Returns true if the current lang_hooks represents the GNU Fortran frontend. */
996 : :
997 : : bool
998 : 209092 : lang_GNU_Fortran (void)
999 : : {
1000 : 209092 : return startswith (lang_hooks.name, "GNU Fortran");
1001 : : }
1002 : :
1003 : : /* Returns true if the current lang_hooks represents the GNU Objective-C
1004 : : frontend. */
1005 : :
1006 : : bool
1007 : 118345 : lang_GNU_OBJC (void)
1008 : : {
1009 : 118345 : return startswith (lang_hooks.name, "GNU Objective-C");
1010 : : }
|