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