comparison gcc/varpool.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Callgraph handling code. 1 /* Callgraph handling code.
2 Copyright (C) 2003-2018 Free Software Foundation, Inc. 2 Copyright (C) 2003-2020 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka 3 Contributed by Jan Hubicka
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
131 131
132 /* Allocate new callgraph node and insert it into basic data structures. */ 132 /* Allocate new callgraph node and insert it into basic data structures. */
133 133
134 varpool_node * 134 varpool_node *
135 varpool_node::create_empty (void) 135 varpool_node::create_empty (void)
136 { 136 {
137 varpool_node *node = ggc_cleared_alloc<varpool_node> (); 137 return new (ggc_alloc<varpool_node> ()) varpool_node ();
138 node->type = SYMTAB_VARIABLE;
139 return node;
140 } 138 }
141 139
142 /* Return varpool node assigned to DECL. Create new one when needed. */ 140 /* Return varpool node assigned to DECL. Create new one when needed. */
143 varpool_node * 141 varpool_node *
144 varpool_node::get_create (tree decl) 142 varpool_node::get_create (tree decl)
202 && !DECL_VIRTUAL_P (decl) 200 && !DECL_VIRTUAL_P (decl)
203 /* FIXME: http://gcc.gnu.org/PR55395 */ 201 /* FIXME: http://gcc.gnu.org/PR55395 */
204 && debug_info_level == DINFO_LEVEL_NONE 202 && debug_info_level == DINFO_LEVEL_NONE
205 /* When doing declaration merging we have duplicate 203 /* When doing declaration merging we have duplicate
206 entries for given decl. Do not attempt to remove 204 entries for given decl. Do not attempt to remove
207 the boides, or we will end up remiving 205 the bodies, or we will end up removing
208 wrong one. */ 206 wrong one. */
209 && symtab->state != LTO_STREAMING) 207 && symtab->state != LTO_STREAMING)
210 DECL_INITIAL (decl) = error_mark_node; 208 DECL_INITIAL (decl) = error_mark_node;
211 } 209 }
212 210
224 fprintf (f, " initialized"); 222 fprintf (f, " initialized");
225 if (output) 223 if (output)
226 fprintf (f, " output"); 224 fprintf (f, " output");
227 if (used_by_single_function) 225 if (used_by_single_function)
228 fprintf (f, " used-by-single-function"); 226 fprintf (f, " used-by-single-function");
229 if (need_bounds_init)
230 fprintf (f, " need-bounds-init");
231 if (TREE_READONLY (decl)) 227 if (TREE_READONLY (decl))
232 fprintf (f, " read-only"); 228 fprintf (f, " read-only");
233 if (ctor_useable_for_folding_p ()) 229 if (ctor_useable_for_folding_p ())
234 fprintf (f, " const-value-known"); 230 fprintf (f, " const-value-known");
235 if (writeonly) 231 if (writeonly)
299 name = lto_get_decl_name_mapping (file_data, name); 295 name = lto_get_decl_name_mapping (file_data, name);
300 struct lto_in_decl_state *decl_state 296 struct lto_in_decl_state *decl_state
301 = lto_get_function_in_decl_state (file_data, decl); 297 = lto_get_function_in_decl_state (file_data, decl);
302 298
303 data = lto_get_section_data (file_data, LTO_section_function_body, 299 data = lto_get_section_data (file_data, LTO_section_function_body,
304 name, &len, decl_state->compressed); 300 name, order - file_data->order_base,
301 &len, decl_state->compressed);
305 if (!data) 302 if (!data)
306 fatal_error (input_location, "%s: section %s is missing", 303 fatal_error (input_location, "%s: section %s.%d is missing",
307 file_data->file_name, 304 file_data->file_name,
308 name); 305 name, order - file_data->order_base);
309 306
310 if (!quiet_flag) 307 if (!quiet_flag)
311 fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); 308 fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
312 lto_input_variable_constructor (file_data, this, data); 309 lto_input_variable_constructor (file_data, this, data);
313 gcc_assert (DECL_INITIAL (decl) != error_mark_node); 310 gcc_assert (DECL_INITIAL (decl) != error_mark_node);
333 || DECL_IN_CONSTANT_POOL (decl)) 330 || DECL_IN_CONSTANT_POOL (decl))
334 return true; 331 return true;
335 if (TREE_THIS_VOLATILE (decl)) 332 if (TREE_THIS_VOLATILE (decl))
336 return false; 333 return false;
337 334
335 /* Avoid attempts to load constructors that was not streamed. */
336 if (in_lto_p && DECL_INITIAL (real_node->decl) == error_mark_node
337 && real_node->body_removed)
338 return false;
339
338 /* If we do not have a constructor, we can't use it. */ 340 /* If we do not have a constructor, we can't use it. */
339 if (DECL_INITIAL (real_node->decl) == error_mark_node 341 if (DECL_INITIAL (real_node->decl) == error_mark_node
340 && !real_node->lto_file_data) 342 && !real_node->lto_file_data)
341 return false;
342
343 /* Avoid attempts to load constructors that was not streamed. */
344 if (flag_ltrans && DECL_INITIAL (real_node->decl) == error_mark_node
345 && real_node->body_removed)
346 return false; 343 return false;
347 344
348 /* Vtables are defined by their types and must match no matter of interposition 345 /* Vtables are defined by their types and must match no matter of interposition
349 rules. */ 346 rules. */
350 if (DECL_VIRTUAL_P (decl)) 347 if (DECL_VIRTUAL_P (decl))
353 classes not defined in the current TU so that it can refer 350 classes not defined in the current TU so that it can refer
354 to them from typeinfo objects. Avoid returning NULL_TREE. */ 351 to them from typeinfo objects. Avoid returning NULL_TREE. */
355 return DECL_INITIAL (real_node->decl) != NULL; 352 return DECL_INITIAL (real_node->decl) != NULL;
356 } 353 }
357 354
358 /* Alias of readonly variable is also readonly, since the variable is stored 355 /* An alias of a read-only variable is also read-only, since the variable
359 in readonly memory. We also accept readonly aliases of non-readonly 356 is stored in read-only memory. We also accept read-only aliases of
360 locations assuming that user knows what he is asking for. */ 357 non-read-only locations assuming that the user knows what he is asking
358 for. */
361 if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl)) 359 if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl))
362 return false; 360 return false;
363 361
364 /* Variables declared 'const' without an initializer 362 /* Variables declared 'const' without an initializer
365 have zero as the initializer if they may not be 363 have zero as the initializer if they may not be
366 overridden at link or run time. 364 overridden at link or run time.
367 365
368 It is actually requirement for C++ compiler to optimize const variables 366 It is actually requirement for C++ compiler to optimize const variables
369 consistently. As a GNU extension, do not enfore this rule for user defined 367 consistently. As a GNU extension, do not enforce this rule for user defined
370 weak variables, so we support interposition on: 368 weak variables, so we support interposition on:
371 static const int dummy = 0; 369 static const int dummy = 0;
372 extern const int foo __attribute__((__weak__, __alias__("dummy"))); 370 extern const int foo __attribute__((__weak__, __alias__("dummy")));
373 */ 371 */
374 if ((!DECL_INITIAL (real_node->decl) 372 if ((!DECL_INITIAL (real_node->decl)
408 406
409 if (TREE_THIS_VOLATILE (decl)) 407 if (TREE_THIS_VOLATILE (decl))
410 return error_mark_node; 408 return error_mark_node;
411 409
412 /* Do not care about automatic variables. Those are never initialized 410 /* Do not care about automatic variables. Those are never initialized
413 anyway, because gimplifier exapnds the code. */ 411 anyway, because gimplifier expands the code. */
414 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl)) 412 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
415 { 413 {
416 gcc_assert (!TREE_PUBLIC (decl)); 414 gcc_assert (!TREE_PUBLIC (decl));
417 return error_mark_node; 415 return error_mark_node;
418 } 416 }
539 ipa_ref *ref; 537 ipa_ref *ref;
540 538
541 FOR_EACH_ALIAS (this, ref) 539 FOR_EACH_ALIAS (this, ref)
542 { 540 {
543 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring); 541 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
544 if (!alias->transparent_alias) 542 if (alias->symver)
543 do_assemble_symver (alias->decl,
544 DECL_ASSEMBLER_NAME (decl));
545 else if (!alias->transparent_alias)
545 do_assemble_alias (alias->decl, 546 do_assemble_alias (alias->decl,
546 DECL_ASSEMBLER_NAME (decl)); 547 DECL_ASSEMBLER_NAME (decl));
547 alias->assemble_aliases (); 548 alias->assemble_aliases ();
548 } 549 }
549 } 550 }
551 /* Output one variable, if necessary. Return whether we output it. */ 552 /* Output one variable, if necessary. Return whether we output it. */
552 553
553 bool 554 bool
554 varpool_node::assemble_decl (void) 555 varpool_node::assemble_decl (void)
555 { 556 {
556 /* Aliases are outout when their target is produced or by 557 /* Aliases are output when their target is produced or by
557 output_weakrefs. */ 558 output_weakrefs. */
558 if (alias) 559 if (alias)
559 return false; 560 return false;
560 561
561 /* Constant pool is output from RTL land when the reference 562 /* Constant pool is output from RTL land when the reference
637 them needed the variable. */ 638 them needed the variable. */
638 || DECL_RTL_SET_P (node->decl))) 639 || DECL_RTL_SET_P (node->decl)))
639 { 640 {
640 enqueue_node (node, &first); 641 enqueue_node (node, &first);
641 if (dump_file) 642 if (dump_file)
642 fprintf (dump_file, " %s", node->asm_name ()); 643 fprintf (dump_file, " %s", node->dump_asm_name ());
643 } 644 }
644 } 645 }
645 while (first != (varpool_node *)(void *)1) 646 while (first != (varpool_node *)(void *)1)
646 { 647 {
647 node = first; 648 node = first;
685 { 686 {
686 next = next_defined_variable (node); 687 next = next_defined_variable (node);
687 if (!node->aux && !node->no_reorder) 688 if (!node->aux && !node->no_reorder)
688 { 689 {
689 if (dump_file) 690 if (dump_file)
690 fprintf (dump_file, " %s", node->asm_name ()); 691 fprintf (dump_file, " %s", node->dump_asm_name ());
691 if (referenced.contains(node)) 692 if (referenced.contains(node))
692 node->remove_initializer (); 693 node->remove_initializer ();
693 else 694 else
694 node->remove (); 695 node->remove ();
695 } 696 }
789 return NULL; 790 return NULL;
790 791
791 alias_node = varpool_node::create_alias (alias, decl); 792 alias_node = varpool_node::create_alias (alias, decl);
792 alias_node->cpp_implicit_alias = true; 793 alias_node->cpp_implicit_alias = true;
793 794
794 /* Extra name alias mechanizm creates aliases really late 795 /* Extra name alias mechanism creates aliases really late
795 via DECL_ASSEMBLER_NAME mechanizm. 796 via DECL_ASSEMBLER_NAME mechanism.
796 This is unfortunate because they are not going through the 797 This is unfortunate because they are not going through the
797 standard channels. Ensure they get output. */ 798 standard channels. Ensure they get output. */
798 if (symtab->cpp_implicit_aliases_done) 799 if (symtab->cpp_implicit_aliases_done)
799 alias_node->resolve_alias (varpool_node::get_create (decl)); 800 alias_node->resolve_alias (varpool_node::get_create (decl));
800 return alias_node; 801 return alias_node;