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 : 72458 : lhd_do_nothing (void)
47 : : {
48 : 72458 : }
49 : :
50 : : /* Do nothing (tree). */
51 : :
52 : : void
53 : 12119915 : lhd_do_nothing_t (tree ARG_UNUSED (t))
54 : : {
55 : 12119915 : }
56 : :
57 : : /* Pass through (tree). */
58 : : tree
59 : 421 : lhd_pass_through_t (tree t)
60 : : {
61 : 421 : 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 : 9084 : lhd_return_null_const_tree (const_tree ARG_UNUSED (t))
93 : : {
94 : 9084 : 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 : 6533591 : lhd_set_decl_assembler_name (tree decl)
138 : : {
139 : 6533591 : 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 : 6533591 : 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 : 6429919 : 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 : 6429919 : if (TREE_PUBLIC (decl) || DECL_FILE_SCOPE_P (decl))
169 : 6205295 : id = targetm.mangle_decl_assembler_name (decl, DECL_NAME (decl));
170 : : else
171 : : {
172 : 224624 : const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
173 : 224624 : static unsigned long num;
174 : 224624 : char *label;
175 : :
176 : 224624 : ASM_FORMAT_PRIVATE_NAME (label, name, num++);
177 : 224624 : id = get_identifier (label);
178 : : }
179 : :
180 : 6429919 : SET_DECL_ASSEMBLER_NAME (decl, id);
181 : : }
182 : :
183 : : /* Forcibly overwrite the DECL_ASSEMBLER_NAME for DECL to NAME. */
184 : : void
185 : 162543411 : lhd_overwrite_decl_assembler_name (tree decl, tree name)
186 : : {
187 : 162543411 : DECL_ASSEMBLER_NAME_RAW (decl) = name;
188 : 162543411 : }
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 : 128200 : lhd_register_builtin_type (tree ARG_UNUSED (type),
200 : : const char * ARG_UNUSED (name))
201 : : {
202 : 128200 : }
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 : 1000503957 : lhd_get_alias_set (tree ARG_UNUSED (t))
218 : : {
219 : 1000503957 : return -1;
220 : : }
221 : :
222 : : /* This is the default decl_printable_name function. */
223 : :
224 : : const char *
225 : 7836799 : lhd_decl_printable_name (tree decl, int ARG_UNUSED (verbosity))
226 : : {
227 : 7836799 : gcc_assert (decl && DECL_NAME (decl));
228 : 7836799 : return IDENTIFIER_POINTER (DECL_NAME (decl));
229 : : }
230 : :
231 : : /* This is the default dwarf_name function. */
232 : :
233 : : const char *
234 : 7491264 : lhd_dwarf_name (tree t, int verbosity)
235 : : {
236 : 7491264 : gcc_assert (DECL_P (t));
237 : :
238 : 7491264 : 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 : 80036147 : lhd_gimplify_expr (tree *expr_p ATTRIBUTE_UNUSED,
274 : : gimple_seq *pre_p ATTRIBUTE_UNUSED,
275 : : gimple_seq *post_p ATTRIBUTE_UNUSED)
276 : : {
277 : 80036147 : 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 : 118849 : lhd_decl_ok_for_sibcall (const_tree decl ATTRIBUTE_UNUSED)
294 : : {
295 : 118849 : 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 : 30790 : global_decl_processing (void)
304 : : {
305 : 30790 : tree globals, decl, *vec;
306 : 30790 : int len, i;
307 : :
308 : 30790 : timevar_stop (TV_PHASE_PARSING);
309 : 30790 : 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 : 30790 : globals = lang_hooks.decls.getdecls ();
315 : 30790 : len = list_length (globals);
316 : 30790 : 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 : 142630595 : for (i = 0, decl = globals; i < len; i++, decl = DECL_CHAIN (decl))
322 : 142569015 : vec[len - i - 1] = decl;
323 : :
324 : 30790 : wrapup_global_declarations (vec, len);
325 : 30790 : timevar_stop (TV_PHASE_DEFERRED);
326 : :
327 : 30790 : timevar_start (TV_PHASE_PARSING);
328 : 30790 : free (vec);
329 : 30790 : }
330 : :
331 : : /* Called to perform language-specific initialization of CTX. */
332 : : void
333 : 78650 : lhd_initialize_diagnostics (diagnostic_context *ctx ATTRIBUTE_UNUSED)
334 : : {
335 : 78650 : }
336 : :
337 : : /* Called to register dumps. */
338 : : void
339 : 167943 : lhd_register_dumps (gcc::dump_manager *)
340 : : {
341 : 167943 : }
342 : :
343 : : /* Called to perform language-specific options initialization. */
344 : : void
345 : 32237 : lhd_init_options (unsigned int decoded_options_count ATTRIBUTE_UNUSED,
346 : : struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
347 : : {
348 : 32237 : }
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 : 105418 : lhd_print_error_function (diagnostic_text_output_format &text_output,
373 : : const char *file,
374 : : const diagnostic_info *diagnostic)
375 : : {
376 : 105418 : diagnostic_context *const context = &text_output.get_context ();
377 : 105418 : if (diagnostic_last_function_changed (context, diagnostic))
378 : : {
379 : 15492 : pretty_printer *const pp = text_output.get_printer ();
380 : 15492 : char *old_prefix = pp_take_prefix (pp);
381 : 15492 : tree abstract_origin = diagnostic_abstract_origin (diagnostic);
382 : 15492 : char *new_prefix = (file && abstract_origin == NULL)
383 : 15492 : ? text_output.file_name_as_prefix (file) : NULL;
384 : :
385 : 15492 : pp_set_prefix (pp, new_prefix);
386 : :
387 : 15492 : if (current_function_decl == NULL)
388 : 592 : pp_printf (pp, _("At top level:"));
389 : : else
390 : : {
391 : 14900 : tree fndecl, ao;
392 : :
393 : 14900 : if (abstract_origin)
394 : : {
395 : 185 : ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
396 : 185 : gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
397 : : fndecl = ao;
398 : : }
399 : : else
400 : : fndecl = current_function_decl;
401 : :
402 : 14900 : 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 : 14894 : pp_printf
408 : 14894 : (pp, _("In function %qs"),
409 : 14894 : identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
410 : :
411 : 15147 : while (abstract_origin)
412 : : {
413 : 247 : location_t *locus;
414 : 247 : tree block = abstract_origin;
415 : :
416 : 247 : locus = &BLOCK_SOURCE_LOCATION (block);
417 : 247 : fndecl = NULL;
418 : 247 : block = BLOCK_SUPERCONTEXT (block);
419 : 518 : while (block && TREE_CODE (block) == BLOCK
420 : 542 : && BLOCK_ABSTRACT_ORIGIN (block))
421 : : {
422 : 86 : ao = BLOCK_ABSTRACT_ORIGIN (block);
423 : 86 : if (TREE_CODE (ao) == FUNCTION_DECL)
424 : : {
425 : : fndecl = ao;
426 : : break;
427 : : }
428 : 24 : else if (TREE_CODE (ao) != BLOCK)
429 : : break;
430 : :
431 : 24 : block = BLOCK_SUPERCONTEXT (block);
432 : : }
433 : 247 : if (fndecl)
434 : : abstract_origin = block;
435 : : else
436 : : {
437 : 431 : while (block && TREE_CODE (block) == BLOCK)
438 : 246 : block = BLOCK_SUPERCONTEXT (block);
439 : :
440 : 185 : if (block && TREE_CODE (block) == FUNCTION_DECL)
441 : : fndecl = block;
442 : : abstract_origin = NULL;
443 : : }
444 : : if (fndecl)
445 : : {
446 : 247 : expanded_location s = expand_location (*locus);
447 : 247 : pp_comma (pp);
448 : 247 : pp_newline (pp);
449 : 247 : if (s.file != NULL)
450 : : {
451 : 247 : if (context->m_show_column)
452 : 247 : pp_printf (pp,
453 : 247 : _(" inlined from %qs at %r%s:%d:%d%R"),
454 : 247 : 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 : 14900 : pp_colon (pp);
469 : : }
470 : :
471 : 15492 : diagnostic_set_last_function (context, diagnostic);
472 : 15492 : pp_newline_and_flush (pp);
473 : 15492 : pp->set_prefix (old_prefix);
474 : : }
475 : 105418 : }
476 : :
477 : : tree
478 : 224140 : lhd_make_node (enum tree_code code)
479 : : {
480 : 224140 : 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 : 114265 : lhd_type_for_size (unsigned precision, int unsignedp)
547 : : {
548 : 114265 : int i;
549 : :
550 : 114265 : if (precision == TYPE_PRECISION (integer_type_node))
551 : 22871 : return unsignedp ? unsigned_type_node : integer_type_node;
552 : :
553 : 91394 : if (precision == TYPE_PRECISION (signed_char_type_node))
554 : 22844 : return unsignedp ? unsigned_char_type_node : signed_char_type_node;
555 : :
556 : 68550 : if (precision == TYPE_PRECISION (short_integer_type_node))
557 : 22844 : return unsignedp ? short_unsigned_type_node : short_integer_type_node;
558 : :
559 : 45706 : if (precision == TYPE_PRECISION (long_integer_type_node))
560 : 22862 : return unsignedp ? long_unsigned_type_node : long_integer_type_node;
561 : :
562 : 22844 : 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 : 22844 : for (i = 0; i < NUM_INT_N_ENTS; i ++)
568 : 22844 : if (int_n_enabled_p[i]
569 : 22844 : && precision == int_n_data[i].bitsize)
570 : 22844 : return (unsignedp ? int_n_trees[i].unsigned_type
571 : 22844 : : 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 : 4414693 : lhd_to_target_charset (HOST_WIDE_INT c)
593 : : {
594 : 4414693 : return c;
595 : : }
596 : :
597 : : tree
598 : 998379082 : lhd_expr_to_decl (tree expr, bool *tc ATTRIBUTE_UNUSED, bool *se ATTRIBUTE_UNUSED)
599 : : {
600 : 998379082 : 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 : 49612 : lhd_omp_finish_clause (tree, gimple_seq *, bool)
637 : : {
638 : 49612 : }
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 : 77469 : lhd_omp_deep_mapping_p (const gimple *, tree)
652 : : {
653 : 77469 : return false;
654 : : }
655 : :
656 : : /* Returns number of additional mappings for a decl. */
657 : :
658 : : tree
659 : 84106 : lhd_omp_deep_mapping_cnt (const gimple *, tree, gimple_seq *)
660 : : {
661 : 84106 : 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 : : /* Return true if DECL is a scalar variable (for the purpose of
673 : : implicit firstprivatization & mapping). Only if alloc_ptr_ok
674 : : are allocatables and pointers accepted. */
675 : :
676 : : bool
677 : 11837 : lhd_omp_scalar_p (tree decl, bool ptr_ok)
678 : : {
679 : 11837 : tree type = TREE_TYPE (decl);
680 : 11837 : if (TREE_CODE (type) == REFERENCE_TYPE)
681 : 97 : type = TREE_TYPE (type);
682 : 11837 : if (TREE_CODE (type) == COMPLEX_TYPE)
683 : 0 : type = TREE_TYPE (type);
684 : 11837 : if (INTEGRAL_TYPE_P (type)
685 : 11837 : || SCALAR_FLOAT_TYPE_P (type)
686 : 1145 : || (ptr_ok && TREE_CODE (type) == POINTER_TYPE))
687 : 10712 : return true;
688 : : return false;
689 : : }
690 : :
691 : : /* Return static initializer for DECL. */
692 : :
693 : : tree *
694 : 4310 : lhd_omp_get_decl_init (tree decl)
695 : : {
696 : 4310 : return &DECL_INITIAL (decl);
697 : : }
698 : :
699 : : /* Free any extra memory used to hold initializer information for
700 : : variable declarations. */
701 : :
702 : : void
703 : 5008 : lhd_omp_finish_decl_inits (void)
704 : : {
705 : 5008 : }
706 : :
707 : : /* Register language specific type size variables as potentially OpenMP
708 : : firstprivate variables. */
709 : :
710 : : void
711 : 9251 : lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *c ATTRIBUTE_UNUSED,
712 : : tree t ATTRIBUTE_UNUSED)
713 : : {
714 : 9251 : }
715 : :
716 : : /* Common function for add_builtin_function, add_builtin_function_ext_scope
717 : : and simulate_builtin_function_decl. */
718 : :
719 : : static tree
720 : 802166619 : build_builtin_function (location_t location, const char *name, tree type,
721 : : int function_code, enum built_in_class cl,
722 : : const char *library_name, tree attrs)
723 : : {
724 : 802166619 : tree id = get_identifier (name);
725 : 802166619 : tree decl = build_decl (location, FUNCTION_DECL, id, type);
726 : :
727 : 802166619 : TREE_PUBLIC (decl) = 1;
728 : 802166619 : DECL_EXTERNAL (decl) = 1;
729 : :
730 : 802166619 : set_decl_built_in_function (decl, cl, function_code);
731 : :
732 : 802166619 : if (library_name)
733 : : {
734 : 245154785 : tree libname = get_identifier (library_name);
735 : :
736 : 245154785 : libname = targetm.mangle_decl_assembler_name (decl, libname);
737 : 245154785 : SET_DECL_ASSEMBLER_NAME (decl, libname);
738 : : }
739 : :
740 : : /* Possibly apply some default attributes to this built-in function. */
741 : 802166619 : if (attrs)
742 : 451197514 : decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
743 : : else
744 : 350969105 : decl_attributes (&decl, NULL_TREE, 0);
745 : :
746 : 802166619 : return decl;
747 : : }
748 : :
749 : : /* Create a builtin function. */
750 : :
751 : : tree
752 : 790402610 : add_builtin_function (const char *name,
753 : : tree type,
754 : : int function_code,
755 : : enum built_in_class cl,
756 : : const char *library_name,
757 : : tree attrs)
758 : : {
759 : 790402610 : tree decl = build_builtin_function (BUILTINS_LOCATION, name, type,
760 : : function_code, cl, library_name, attrs);
761 : 790402610 : return lang_hooks.builtin_function (decl);
762 : : }
763 : :
764 : : /* Like add_builtin_function, but make sure the scope is the external scope.
765 : : This is used to delay putting in back end builtin functions until the ISA
766 : : that defines the builtin is declared via function specific target options,
767 : : which can save memory for machines like the x86_64 that have multiple ISAs.
768 : : If this points to the same function as builtin_function, the backend must
769 : : add all of the builtins at program initialization time. */
770 : :
771 : : tree
772 : 11764009 : add_builtin_function_ext_scope (const char *name,
773 : : tree type,
774 : : int function_code,
775 : : enum built_in_class cl,
776 : : const char *library_name,
777 : : tree attrs)
778 : : {
779 : 11764009 : tree decl = build_builtin_function (BUILTINS_LOCATION, name, type,
780 : : function_code, cl, library_name, attrs);
781 : 11764009 : return lang_hooks.builtin_function_ext_scope (decl);
782 : : }
783 : :
784 : : /* Simulate a declaration of a target-specific built-in function at
785 : : location LOCATION, as though it had been declared directly in the
786 : : source language. NAME is the name of the function, TYPE is its function
787 : : type, FUNCTION_CODE is the target-specific function code, LIBRARY_NAME
788 : : is the name of the underlying library function (NULL if none) and
789 : : ATTRS is a list of function attributes.
790 : :
791 : : Return the decl of the declared function. */
792 : :
793 : : tree
794 : 0 : simulate_builtin_function_decl (location_t location, const char *name,
795 : : tree type, int function_code,
796 : : const char *library_name, tree attrs)
797 : : {
798 : 0 : tree decl = build_builtin_function (location, name, type,
799 : : function_code, BUILT_IN_MD,
800 : : library_name, attrs);
801 : 0 : tree new_decl = lang_hooks.simulate_builtin_function_decl (decl);
802 : :
803 : : /* Give the front end a chance to create a new decl if necessary,
804 : : but if the front end discards the decl in favour of a conflicting
805 : : (erroneous) previous definition, return the decl that we tried but
806 : : failed to add. This allows the caller to process the returned decl
807 : : normally, even though the source code won't be able to use it. */
808 : 0 : if (TREE_CODE (new_decl) == FUNCTION_DECL
809 : 0 : && fndecl_built_in_p (new_decl, function_code, BUILT_IN_MD))
810 : 0 : return new_decl;
811 : :
812 : : return decl;
813 : : }
814 : :
815 : : tree
816 : 0 : lhd_builtin_function (tree decl)
817 : : {
818 : 0 : lang_hooks.decls.pushdecl (decl);
819 : 0 : return decl;
820 : : }
821 : :
822 : : /* Create a builtin type. */
823 : :
824 : : tree
825 : 0 : add_builtin_type (const char *name, tree type)
826 : : {
827 : 0 : tree id = get_identifier (name);
828 : 0 : tree decl = build_decl (BUILTINS_LOCATION, TYPE_DECL, id, type);
829 : 0 : return lang_hooks.decls.pushdecl (decl);
830 : : }
831 : :
832 : : /* LTO hooks. */
833 : :
834 : : /* Used to save and restore any previously active section. */
835 : : static section *saved_section;
836 : :
837 : :
838 : : /* Begin a new LTO output section named NAME. This default implementation
839 : : saves the old section and emits assembly code to switch to the new
840 : : section. */
841 : :
842 : : void
843 : 425664 : lhd_begin_section (const char *name)
844 : : {
845 : 425664 : section *section;
846 : :
847 : : /* Save the old section so we can restore it in lto_end_asm_section. */
848 : 425664 : gcc_assert (!saved_section);
849 : 425664 : saved_section = in_section;
850 : 425664 : if (!saved_section)
851 : 22448 : saved_section = text_section;
852 : :
853 : : /* Create a new section and switch to it. */
854 : 425664 : section = get_section (name, SECTION_DEBUG | SECTION_EXCLUDE, NULL, true);
855 : 425664 : switch_to_section (section);
856 : 425664 : }
857 : :
858 : :
859 : : /* Write DATA of length LEN to the current LTO output section. This default
860 : : implementation just calls assemble_string. */
861 : :
862 : : void
863 : 4718999 : lhd_append_data (const void *data, size_t len, void *)
864 : : {
865 : 4718999 : if (data)
866 : : {
867 : 4718999 : timevar_push (TV_IPA_LTO_OUTPUT);
868 : 4718999 : assemble_string ((const char *)data, len);
869 : 4718999 : timevar_pop (TV_IPA_LTO_OUTPUT);
870 : : }
871 : 4718999 : }
872 : :
873 : :
874 : : /* Finish the current LTO output section. This default implementation emits
875 : : assembly code to switch to any section previously saved by
876 : : lhd_begin_section. */
877 : :
878 : : void
879 : 425664 : lhd_end_section (void)
880 : : {
881 : 425664 : if (saved_section)
882 : : {
883 : 425664 : switch_to_section (saved_section);
884 : 425664 : saved_section = NULL;
885 : : }
886 : 425664 : }
887 : :
888 : : /* Default implementation of enum_underlying_base_type using type_for_size. */
889 : :
890 : : tree
891 : 85895 : lhd_enum_underlying_base_type (const_tree enum_type)
892 : : {
893 : 85895 : return lang_hooks.types.type_for_size (TYPE_PRECISION (enum_type),
894 : 85895 : TYPE_UNSIGNED (enum_type));
895 : : }
896 : :
897 : : /* Default implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION. */
898 : :
899 : : const char *
900 : 530 : lhd_get_substring_location (const substring_loc &, location_t *)
901 : : {
902 : 530 : return "unimplemented";
903 : : }
904 : :
905 : : /* Default implementation of LANG_HOOKS_DECL_DWARF_ATTRIBUTE. Don't add
906 : : any attributes. */
907 : :
908 : : int
909 : 6022950 : lhd_decl_dwarf_attribute (const_tree, int)
910 : : {
911 : 6022950 : return -1;
912 : : }
913 : :
914 : : /* Default implementation of LANG_HOOKS_TYPE_DWARF_ATTRIBUTE. Don't add
915 : : any attributes. */
916 : :
917 : : int
918 : 113958 : lhd_type_dwarf_attribute (const_tree, int)
919 : : {
920 : 113958 : return -1;
921 : : }
922 : :
923 : : /* Default implementation of LANG_HOOKS_UNIT_SIZE_WITHOUT_REUSABLE_PADDING.
924 : : Just return TYPE_SIZE_UNIT unadjusted. */
925 : :
926 : : tree
927 : 7516 : lhd_unit_size_without_reusable_padding (tree t)
928 : : {
929 : 7516 : return TYPE_SIZE_UNIT (t);
930 : : }
931 : :
932 : : /* Default implementation for the finalize_early_debug hook. */
933 : :
934 : : void
935 : 51969 : lhd_finalize_early_debug (void)
936 : : {
937 : : /* Emit early debug for reachable functions, and by consequence,
938 : : locally scoped symbols. */
939 : 51969 : struct cgraph_node *cnode;
940 : 562274 : FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
941 : 510305 : (*debug_hooks->early_global_decl) (cnode->decl);
942 : 51969 : }
943 : :
944 : : /* Default implementation of LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE. */
945 : :
946 : : const char *
947 : 0 : lhd_get_sarif_source_language (const char *)
948 : : {
949 : 0 : return NULL;
950 : : }
951 : :
952 : : /* Returns true if the current lang_hooks represents the GNU C frontend. */
953 : :
954 : : bool
955 : 515107 : lang_GNU_C (void)
956 : : {
957 : 515107 : return (startswith (lang_hooks.name, "GNU C")
958 : 515107 : && (lang_hooks.name[5] == '\0' || ISDIGIT (lang_hooks.name[5])));
959 : : }
960 : :
961 : : /* Returns true if the current lang_hooks represents the GNU C++ frontend. */
962 : :
963 : : bool
964 : 17115 : lang_GNU_CXX (void)
965 : : {
966 : 17115 : return startswith (lang_hooks.name, "GNU C++");
967 : : }
968 : :
969 : : /* Returns true if the current lang_hooks represents the GNU Fortran frontend. */
970 : :
971 : : bool
972 : 204134 : lang_GNU_Fortran (void)
973 : : {
974 : 204134 : return startswith (lang_hooks.name, "GNU Fortran");
975 : : }
976 : :
977 : : /* Returns true if the current lang_hooks represents the GNU Objective-C
978 : : frontend. */
979 : :
980 : : bool
981 : 116411 : lang_GNU_OBJC (void)
982 : : {
983 : 116411 : return startswith (lang_hooks.name, "GNU Objective-C");
984 : : }
|