]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/cgraph.h
IPA REF refactoring
[thirdparty/gcc.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 #ifndef GCC_CGRAPH_H
22 #define GCC_CGRAPH_H
23
24 #include "is-a.h"
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "basic-block.h"
28 #include "function.h"
29 #include "ipa-ref.h"
30
31 /* Symbol table consists of functions and variables.
32 TODO: add labels and CONST_DECLs. */
33 enum symtab_type
34 {
35 SYMTAB_SYMBOL,
36 SYMTAB_FUNCTION,
37 SYMTAB_VARIABLE
38 };
39
40 /* Section names are stored as reference counted strings in GGC safe hashtable
41 (to make them survive through PCH). */
42
43 struct GTY(()) section_hash_entry_d
44 {
45 int ref_count;
46 char *name; /* As long as this datastructure stays in GGC, we can not put
47 string at the tail of structure of GGC dies in horrible
48 way */
49 };
50
51 typedef struct section_hash_entry_d section_hash_entry;
52
53 /* Base of all entries in the symbol table.
54 The symtab_node is inherited by cgraph and varpol nodes. */
55 class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),
56 chain_next ("%h.next"), chain_prev ("%h.previous")))
57 symtab_node
58 {
59 public:
60 /* Return name. */
61 const char *name () const;
62
63 /* Return asm name. */
64 const char * asm_name () const;
65
66 /* Type of the symbol. */
67 ENUM_BITFIELD (symtab_type) type : 8;
68
69 /* The symbols resolution. */
70 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
71
72 /*** Flags representing the symbol type. ***/
73
74 /* True when symbol corresponds to a definition in current unit.
75 set via cgraph_finalize_function or varpool_finalize_decl */
76 unsigned definition : 1;
77 /* True when symbol is an alias.
78 Set by assemble_alias. */
79 unsigned alias : 1;
80 /* True when alias is a weakref. */
81 unsigned weakref : 1;
82 /* C++ frontend produce same body aliases and extra name aliases for
83 virtual functions and vtables that are obviously equivalent.
84 Those aliases are bit special, especially because C++ frontend
85 visibility code is so ugly it can not get them right at first time
86 and their visibility needs to be copied from their "masters" at
87 the end of parsing. */
88 unsigned cpp_implicit_alias : 1;
89 /* Set once the definition was analyzed. The list of references and
90 other properties are built during analysis. */
91 unsigned analyzed : 1;
92 /* Set for write-only variables. */
93 unsigned writeonly : 1;
94
95
96 /*** Visibility and linkage flags. ***/
97
98 /* Set when function is visible by other units. */
99 unsigned externally_visible : 1;
100 /* The symbol will be assumed to be used in an invisible way (like
101 by an toplevel asm statement). */
102 unsigned force_output : 1;
103 /* Like FORCE_OUTPUT, but in the case it is ABI requiring the symbol to be
104 exported. Unlike FORCE_OUTPUT this flag gets cleared to symbols promoted
105 to static and it does not inhibit optimization. */
106 unsigned forced_by_abi : 1;
107 /* True when the name is known to be unique and thus it does not need mangling. */
108 unsigned unique_name : 1;
109 /* Specify whether the section was set by user or by
110 compiler via -ffunction-sections. */
111 unsigned implicit_section : 1;
112 /* True when body and other characteristics have been removed by
113 symtab_remove_unreachable_nodes. */
114 unsigned body_removed : 1;
115
116 /*** WHOPR Partitioning flags.
117 These flags are used at ltrans stage when only part of the callgraph is
118 available. ***/
119
120 /* Set when variable is used from other LTRANS partition. */
121 unsigned used_from_other_partition : 1;
122 /* Set when function is available in the other LTRANS partition.
123 During WPA output it is used to mark nodes that are present in
124 multiple partitions. */
125 unsigned in_other_partition : 1;
126
127
128
129 /*** other flags. ***/
130
131 /* Set when symbol has address taken. */
132 unsigned address_taken : 1;
133 /* Set when init priority is set. */
134 unsigned in_init_priority_hash : 1;
135
136
137 /* Ordering of all symtab entries. */
138 int order;
139
140 /* Declaration representing the symbol. */
141 tree decl;
142
143 /* Linked list of symbol table entries starting with symtab_nodes. */
144 symtab_node *next;
145 symtab_node *previous;
146
147 /* Linked list of symbols with the same asm name. There may be multiple
148 entries for single symbol name during LTO, because symbols are renamed
149 only after partitioning.
150
151 Because inline clones are kept in the assembler name has, they also produce
152 duplicate entries.
153
154 There are also several long standing bugs where frontends and builtin
155 code produce duplicated decls. */
156 symtab_node *next_sharing_asm_name;
157 symtab_node *previous_sharing_asm_name;
158
159 /* Circular list of nodes in the same comdat group if non-NULL. */
160 symtab_node *same_comdat_group;
161
162 /* Return comdat group. */
163 tree get_comdat_group ()
164 {
165 return x_comdat_group;
166 }
167
168 /* Return comdat group as identifier_node. */
169 tree get_comdat_group_id ()
170 {
171 if (x_comdat_group && TREE_CODE (x_comdat_group) != IDENTIFIER_NODE)
172 x_comdat_group = DECL_ASSEMBLER_NAME (x_comdat_group);
173 return x_comdat_group;
174 }
175
176 /* Set comdat group. */
177 void set_comdat_group (tree group)
178 {
179 gcc_checking_assert (!group || TREE_CODE (group) == IDENTIFIER_NODE
180 || DECL_P (group));
181 x_comdat_group = group;
182 }
183
184 /* Return section as string. */
185 const char * get_section ()
186 {
187 if (!x_section)
188 return NULL;
189 return x_section->name;
190 }
191
192 /* Return ipa reference from this symtab_node to
193 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
194 of the use and STMT the statement (if it exists). */
195 struct ipa_ref *add_reference (symtab_node *referred_node,
196 enum ipa_ref_use use_type);
197
198 /* Return ipa reference from this symtab_node to
199 REFERED_NODE or REFERED_VARPOOL_NODE. USE_TYPE specify type
200 of the use and STMT the statement (if it exists). */
201 struct ipa_ref *add_reference (symtab_node *referred_node,
202 enum ipa_ref_use use_type, gimple stmt);
203
204 /* If VAL is a reference to a function or a variable, add a reference from
205 this symtab_node to the corresponding symbol table node. USE_TYPE specify
206 type of the use and STMT the statement (if it exists). Return the new
207 reference or NULL if none was created. */
208 struct ipa_ref *maybe_add_reference (tree val, enum ipa_ref_use use_type,
209 gimple stmt);
210
211 /* Clone all references from symtab NODE to this symtab_node. */
212 void clone_references (symtab_node *node);
213
214 /* Remove all stmt references in non-speculative references.
215 Those are not maintained during inlining & clonning.
216 The exception are speculative references that are updated along
217 with callgraph edges associated with them. */
218 void clone_referring (symtab_node *node);
219
220 /* Clone reference REF to this symtab_node and set its stmt to STMT. */
221 struct ipa_ref *clone_reference (struct ipa_ref *ref, gimple stmt);
222
223 /* Find the structure describing a reference to REFERRED_NODE
224 and associated with statement STMT. */
225 struct ipa_ref *find_reference (symtab_node *, gimple, unsigned int);
226
227 /* Remove all references that are associated with statement STMT. */
228 void remove_stmt_references (gimple stmt);
229
230 /* Remove all stmt references in non-speculative references.
231 Those are not maintained during inlining & clonning.
232 The exception are speculative references that are updated along
233 with callgraph edges associated with them. */
234 void clear_stmts_in_references (void);
235
236 /* Remove all references in ref list. */
237 void remove_all_references (void);
238
239 /* Remove all referring items in ref list. */
240 void remove_all_referring (void);
241
242 /* Dump references in ref list to FILE. */
243 void dump_references (FILE *file);
244
245 /* Dump referring in list to FILE. */
246 void dump_referring (FILE *);
247
248 /* Return true if list contains an alias. */
249 bool has_aliases_p (void);
250
251 /* Iterates I-th reference in the list, REF is also set. */
252 struct ipa_ref *iterate_reference (unsigned i, struct ipa_ref *&ref);
253
254 /* Iterates I-th referring item in the list, REF is also set. */
255 struct ipa_ref *iterate_referring (unsigned i, struct ipa_ref *&ref);
256
257 /* Vectors of referring and referenced entities. */
258 struct ipa_ref_list ref_list;
259
260 /* Alias target. May be either DECL pointer or ASSEMBLER_NAME pointer
261 depending to what was known to frontend on the creation time.
262 Once alias is resolved, this pointer become NULL. */
263 tree alias_target;
264
265 /* File stream where this node is being written to. */
266 struct lto_file_decl_data * lto_file_data;
267
268 PTR GTY ((skip)) aux;
269
270 /* Comdat group the symbol is in. Can be private if GGC allowed that. */
271 tree x_comdat_group;
272
273 /* Section name. Again can be private, if allowed. */
274 section_hash_entry *x_section;
275
276 /* Set section for symbol and its aliases. */
277 void set_section (const char *section);
278 void set_section_for_node (const char *section);
279
280 void set_init_priority (priority_type priority);
281 priority_type get_init_priority ();
282 };
283
284 enum availability
285 {
286 /* Not yet set by cgraph_function_body_availability. */
287 AVAIL_UNSET,
288 /* Function body/variable initializer is unknown. */
289 AVAIL_NOT_AVAILABLE,
290 /* Function body/variable initializer is known but might be replaced
291 by a different one from other compilation unit and thus needs to
292 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
293 arbitrary side effects on escaping variables and functions, while
294 like AVAILABLE it might access static variables. */
295 AVAIL_OVERWRITABLE,
296 /* Function body/variable initializer is known and will be used in final
297 program. */
298 AVAIL_AVAILABLE,
299 /* Function body/variable initializer is known and all it's uses are explicitly
300 visible within current unit (ie it's address is never taken and it is not
301 exported to other units).
302 Currently used only for functions. */
303 AVAIL_LOCAL
304 };
305
306 /* This is the information that is put into the cgraph local structure
307 to recover a function. */
308 struct lto_file_decl_data;
309
310 extern const char * const cgraph_availability_names[];
311 extern const char * const ld_plugin_symbol_resolution_names[];
312 extern const char * const tls_model_names[];
313
314 /* Information about thunk, used only for same body aliases. */
315
316 struct GTY(()) cgraph_thunk_info {
317 /* Information about the thunk. */
318 HOST_WIDE_INT fixed_offset;
319 HOST_WIDE_INT virtual_value;
320 tree alias;
321 bool this_adjusting;
322 bool virtual_offset_p;
323 /* Set to true when alias node is thunk. */
324 bool thunk_p;
325 };
326
327 /* Information about the function collected locally.
328 Available after function is analyzed. */
329
330 struct GTY(()) cgraph_local_info {
331 /* Set when function function is visible in current compilation unit only
332 and its address is never taken. */
333 unsigned local : 1;
334
335 /* False when there is something makes versioning impossible. */
336 unsigned versionable : 1;
337
338 /* False when function calling convention and signature can not be changed.
339 This is the case when __builtin_apply_args is used. */
340 unsigned can_change_signature : 1;
341
342 /* True when the function has been originally extern inline, but it is
343 redefined now. */
344 unsigned redefined_extern_inline : 1;
345
346 /* True if the function may enter serial irrevocable mode. */
347 unsigned tm_may_enter_irr : 1;
348 };
349
350 /* Information about the function that needs to be computed globally
351 once compilation is finished. Available only with -funit-at-a-time. */
352
353 struct GTY(()) cgraph_global_info {
354 /* For inline clones this points to the function they will be
355 inlined into. */
356 struct cgraph_node *inlined_to;
357 };
358
359 /* Information about the function that is propagated by the RTL backend.
360 Available only for functions that has been already assembled. */
361
362 struct GTY(()) cgraph_rtl_info {
363 unsigned int preferred_incoming_stack_boundary;
364
365 /* Call unsaved hard registers really used by the corresponding
366 function (including ones used by functions called by the
367 function). */
368 HARD_REG_SET function_used_regs;
369 /* Set if function_used_regs is valid. */
370 unsigned function_used_regs_valid: 1;
371 };
372
373 /* Represent which DECL tree (or reference to such tree)
374 will be replaced by another tree while versioning. */
375 struct GTY(()) ipa_replace_map
376 {
377 /* The tree that will be replaced. */
378 tree old_tree;
379 /* The new (replacing) tree. */
380 tree new_tree;
381 /* Parameter number to replace, when old_tree is NULL. */
382 int parm_num;
383 /* True when a substitution should be done, false otherwise. */
384 bool replace_p;
385 /* True when we replace a reference to old_tree. */
386 bool ref_p;
387 };
388 typedef struct ipa_replace_map *ipa_replace_map_p;
389
390 struct GTY(()) cgraph_clone_info
391 {
392 vec<ipa_replace_map_p, va_gc> *tree_map;
393 bitmap args_to_skip;
394 bitmap combined_args_to_skip;
395 };
396
397 enum cgraph_simd_clone_arg_type
398 {
399 SIMD_CLONE_ARG_TYPE_VECTOR,
400 SIMD_CLONE_ARG_TYPE_UNIFORM,
401 SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
402 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP,
403 SIMD_CLONE_ARG_TYPE_MASK
404 };
405
406 /* Function arguments in the original function of a SIMD clone.
407 Supplementary data for `struct simd_clone'. */
408
409 struct GTY(()) cgraph_simd_clone_arg {
410 /* Original function argument as it originally existed in
411 DECL_ARGUMENTS. */
412 tree orig_arg;
413
414 /* orig_arg's function (or for extern functions type from
415 TYPE_ARG_TYPES). */
416 tree orig_type;
417
418 /* If argument is a vector, this holds the vector version of
419 orig_arg that after adjusting the argument types will live in
420 DECL_ARGUMENTS. Otherwise, this is NULL.
421
422 This basically holds:
423 vector(simdlen) __typeof__(orig_arg) new_arg. */
424 tree vector_arg;
425
426 /* vector_arg's type (or for extern functions new vector type. */
427 tree vector_type;
428
429 /* If argument is a vector, this holds the array where the simd
430 argument is held while executing the simd clone function. This
431 is a local variable in the cloned function. Its content is
432 copied from vector_arg upon entry to the clone.
433
434 This basically holds:
435 __typeof__(orig_arg) simd_array[simdlen]. */
436 tree simd_array;
437
438 /* A SIMD clone's argument can be either linear (constant or
439 variable), uniform, or vector. */
440 enum cgraph_simd_clone_arg_type arg_type;
441
442 /* For arg_type SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP this is
443 the constant linear step, if arg_type is
444 SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP, this is index of
445 the uniform argument holding the step, otherwise 0. */
446 HOST_WIDE_INT linear_step;
447
448 /* Variable alignment if available, otherwise 0. */
449 unsigned int alignment;
450 };
451
452 /* Specific data for a SIMD function clone. */
453
454 struct GTY(()) cgraph_simd_clone {
455 /* Number of words in the SIMD lane associated with this clone. */
456 unsigned int simdlen;
457
458 /* Number of annotated function arguments in `args'. This is
459 usually the number of named arguments in FNDECL. */
460 unsigned int nargs;
461
462 /* Max hardware vector size in bits for integral vectors. */
463 unsigned int vecsize_int;
464
465 /* Max hardware vector size in bits for floating point vectors. */
466 unsigned int vecsize_float;
467
468 /* The mangling character for a given vector size. This is is used
469 to determine the ISA mangling bit as specified in the Intel
470 Vector ABI. */
471 unsigned char vecsize_mangle;
472
473 /* True if this is the masked, in-branch version of the clone,
474 otherwise false. */
475 unsigned int inbranch : 1;
476
477 /* True if this is a Cilk Plus variant. */
478 unsigned int cilk_elemental : 1;
479
480 /* Doubly linked list of SIMD clones. */
481 struct cgraph_node *prev_clone, *next_clone;
482
483 /* Original cgraph node the SIMD clones were created for. */
484 struct cgraph_node *origin;
485
486 /* Annotated function arguments for the original function. */
487 struct cgraph_simd_clone_arg GTY((length ("%h.nargs"))) args[1];
488 };
489
490
491 /* The cgraph data structure.
492 Each function decl has assigned cgraph_node listing callees and callers. */
493
494 struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node {
495 public:
496 struct cgraph_edge *callees;
497 struct cgraph_edge *callers;
498 /* List of edges representing indirect calls with a yet undetermined
499 callee. */
500 struct cgraph_edge *indirect_calls;
501 /* For nested functions points to function the node is nested in. */
502 struct cgraph_node *origin;
503 /* Points to first nested function, if any. */
504 struct cgraph_node *nested;
505 /* Pointer to the next function with same origin, if any. */
506 struct cgraph_node *next_nested;
507 /* Pointer to the next clone. */
508 struct cgraph_node *next_sibling_clone;
509 struct cgraph_node *prev_sibling_clone;
510 struct cgraph_node *clones;
511 struct cgraph_node *clone_of;
512 /* For functions with many calls sites it holds map from call expression
513 to the edge to speed up cgraph_edge function. */
514 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
515 /* Declaration node used to be clone of. */
516 tree former_clone_of;
517
518 /* If this is a SIMD clone, this points to the SIMD specific
519 information for it. */
520 struct cgraph_simd_clone *simdclone;
521 /* If this function has SIMD clones, this points to the first clone. */
522 struct cgraph_node *simd_clones;
523
524 /* Interprocedural passes scheduled to have their transform functions
525 applied next time we execute local pass on them. We maintain it
526 per-function in order to allow IPA passes to introduce new functions. */
527 vec<ipa_opt_pass> GTY((skip)) ipa_transforms_to_apply;
528
529 struct cgraph_local_info local;
530 struct cgraph_global_info global;
531 struct cgraph_rtl_info rtl;
532 struct cgraph_clone_info clone;
533 struct cgraph_thunk_info thunk;
534
535 /* Expected number of executions: calculated in profile.c. */
536 gcov_type count;
537 /* How to scale counts at materialization time; used to merge
538 LTO units with different number of profile runs. */
539 int count_materialization_scale;
540 /* Unique id of the node. */
541 int uid;
542 /* ID assigned by the profiling. */
543 unsigned int profile_id;
544 /* Time profiler: first run of function. */
545 int tp_first_run;
546
547 /* Set when decl is an abstract function pointed to by the
548 ABSTRACT_DECL_ORIGIN of a reachable function. */
549 unsigned used_as_abstract_origin : 1;
550 /* Set once the function is lowered (i.e. its CFG is built). */
551 unsigned lowered : 1;
552 /* Set once the function has been instantiated and its callee
553 lists created. */
554 unsigned process : 1;
555 /* How commonly executed the node is. Initialized during branch
556 probabilities pass. */
557 ENUM_BITFIELD (node_frequency) frequency : 2;
558 /* True when function can only be called at startup (from static ctor). */
559 unsigned only_called_at_startup : 1;
560 /* True when function can only be called at startup (from static dtor). */
561 unsigned only_called_at_exit : 1;
562 /* True when function is the transactional clone of a function which
563 is called only from inside transactions. */
564 /* ?? We should be able to remove this. We have enough bits in
565 cgraph to calculate it. */
566 unsigned tm_clone : 1;
567 /* True if this decl is a dispatcher for function versions. */
568 unsigned dispatcher_function : 1;
569 /* True if this decl calls a COMDAT-local function. This is set up in
570 compute_inline_parameters and inline_call. */
571 unsigned calls_comdat_local : 1;
572
573 void set_fini_priority (priority_type priority);
574 priority_type get_fini_priority ();
575 };
576
577
578 typedef struct cgraph_node *cgraph_node_ptr;
579
580
581 /* Function Multiversioning info. */
582 struct GTY(()) cgraph_function_version_info {
583 /* The cgraph_node for which the function version info is stored. */
584 struct cgraph_node *this_node;
585 /* Chains all the semantically identical function versions. The
586 first function in this chain is the version_info node of the
587 default function. */
588 struct cgraph_function_version_info *prev;
589 /* If this version node corresponds to a dispatcher for function
590 versions, this points to the version info node of the default
591 function, the first node in the chain. */
592 struct cgraph_function_version_info *next;
593 /* If this node corresponds to a function version, this points
594 to the dispatcher function decl, which is the function that must
595 be called to execute the right function version at run-time.
596
597 If this cgraph node is a dispatcher (if dispatcher_function is
598 true, in the cgraph_node struct) for function versions, this
599 points to resolver function, which holds the function body of the
600 dispatcher. The dispatcher decl is an alias to the resolver
601 function decl. */
602 tree dispatcher_resolver;
603 };
604
605 /* Get the cgraph_function_version_info node corresponding to node. */
606 struct cgraph_function_version_info *
607 get_cgraph_node_version (struct cgraph_node *node);
608
609 /* Insert a new cgraph_function_version_info node into cgraph_fnver_htab
610 corresponding to cgraph_node NODE. */
611 struct cgraph_function_version_info *
612 insert_new_cgraph_node_version (struct cgraph_node *node);
613
614 /* Record that DECL1 and DECL2 are semantically identical function
615 versions. */
616 void record_function_versions (tree decl1, tree decl2);
617
618 /* Remove the cgraph_function_version_info and cgraph_node for DECL. This
619 DECL is a duplicate declaration. */
620 void delete_function_version (tree decl);
621
622 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
623 can appear in multiple sets. */
624 struct cgraph_node_set_def
625 {
626 struct pointer_map_t *map;
627 vec<cgraph_node_ptr> nodes;
628 };
629
630 class varpool_node;
631 typedef varpool_node *varpool_node_ptr;
632
633
634 /* A varpool node set is a collection of varpool nodes. A varpool node
635 can appear in multiple sets. */
636 struct varpool_node_set_def
637 {
638 struct pointer_map_t * map;
639 vec<varpool_node_ptr> nodes;
640 };
641
642 typedef struct cgraph_node_set_def *cgraph_node_set;
643
644
645 typedef struct varpool_node_set_def *varpool_node_set;
646
647
648 /* Iterator structure for cgraph node sets. */
649 struct cgraph_node_set_iterator
650 {
651 cgraph_node_set set;
652 unsigned index;
653 };
654
655 /* Iterator structure for varpool node sets. */
656 struct varpool_node_set_iterator
657 {
658 varpool_node_set set;
659 unsigned index;
660 };
661
662 #define DEFCIFCODE(code, type, string) CIF_ ## code,
663 /* Reasons for inlining failures. */
664 enum cgraph_inline_failed_t {
665 #include "cif-code.def"
666 CIF_N_REASONS
667 };
668
669 enum cgraph_inline_failed_type_t
670 {
671 CIF_FINAL_NORMAL = 0,
672 CIF_FINAL_ERROR
673 };
674
675 /* Structure containing additional information about an indirect call. */
676
677 struct GTY(()) cgraph_indirect_call_info
678 {
679 /* When polymorphic is set, this field contains offset where the object which
680 was actually used in the polymorphic resides within a larger structure.
681 If agg_contents is set, the field contains the offset within the aggregate
682 from which the address to call was loaded. */
683 HOST_WIDE_INT offset;
684 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
685 HOST_WIDE_INT otr_token;
686 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
687 tree otr_type, outer_type;
688 /* Index of the parameter that is called. */
689 int param_index;
690 /* ECF flags determined from the caller. */
691 int ecf_flags;
692 /* Profile_id of common target obtrained from profile. */
693 int common_target_id;
694 /* Probability that call will land in function with COMMON_TARGET_ID. */
695 int common_target_probability;
696
697 /* Set when the call is a virtual call with the parameter being the
698 associated object pointer rather than a simple direct call. */
699 unsigned polymorphic : 1;
700 /* Set when the call is a call of a pointer loaded from contents of an
701 aggregate at offset. */
702 unsigned agg_contents : 1;
703 /* Set when this is a call through a member pointer. */
704 unsigned member_ptr : 1;
705 /* When the previous bit is set, this one determines whether the destination
706 is loaded from a parameter passed by reference. */
707 unsigned by_ref : 1;
708 unsigned int maybe_in_construction : 1;
709 unsigned int maybe_derived_type : 1;
710 };
711
712 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
713 /* Expected number of executions: calculated in profile.c. */
714 gcov_type count;
715 struct cgraph_node *caller;
716 struct cgraph_node *callee;
717 struct cgraph_edge *prev_caller;
718 struct cgraph_edge *next_caller;
719 struct cgraph_edge *prev_callee;
720 struct cgraph_edge *next_callee;
721 gimple call_stmt;
722 /* Additional information about an indirect call. Not cleared when an edge
723 becomes direct. */
724 struct cgraph_indirect_call_info *indirect_info;
725 PTR GTY ((skip (""))) aux;
726 /* When equal to CIF_OK, inline this call. Otherwise, points to the
727 explanation why function was not inlined. */
728 enum cgraph_inline_failed_t inline_failed;
729 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
730 when the function is serialized in. */
731 unsigned int lto_stmt_uid;
732 /* Expected frequency of executions within the function.
733 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
734 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
735 int frequency;
736 /* Unique id of the edge. */
737 int uid;
738 /* Whether this edge was made direct by indirect inlining. */
739 unsigned int indirect_inlining_edge : 1;
740 /* Whether this edge describes an indirect call with an undetermined
741 callee. */
742 unsigned int indirect_unknown_callee : 1;
743 /* Whether this edge is still a dangling */
744 /* True if the corresponding CALL stmt cannot be inlined. */
745 unsigned int call_stmt_cannot_inline_p : 1;
746 /* Can this call throw externally? */
747 unsigned int can_throw_external : 1;
748 /* Edges with SPECULATIVE flag represents indirect calls that was
749 speculatively turned into direct (i.e. by profile feedback).
750 The final code sequence will have form:
751
752 if (call_target == expected_fn)
753 expected_fn ();
754 else
755 call_target ();
756
757 Every speculative call is represented by three components attached
758 to a same call statement:
759 1) a direct call (to expected_fn)
760 2) an indirect call (to call_target)
761 3) a IPA_REF_ADDR refrence to expected_fn.
762
763 Optimizers may later redirect direct call to clone, so 1) and 3)
764 do not need to necesarily agree with destination. */
765 unsigned int speculative : 1;
766 };
767
768 #define CGRAPH_FREQ_BASE 1000
769 #define CGRAPH_FREQ_MAX 100000
770
771 typedef struct cgraph_edge *cgraph_edge_p;
772
773
774 /* The varpool data structure.
775 Each static variable decl has assigned varpool_node. */
776
777 class GTY((tag ("SYMTAB_VARIABLE"))) varpool_node : public symtab_node {
778 public:
779 /* Set when variable is scheduled to be assembled. */
780 unsigned output : 1;
781
782 /* Set if the variable is dynamically initialized, except for
783 function local statics. */
784 unsigned dynamically_initialized : 1;
785
786 ENUM_BITFIELD(tls_model) tls_model : 3;
787
788 /* Set if the variable is known to be used by single function only.
789 This is computed by ipa_signle_use pass and used by late optimizations
790 in places where optimization would be valid for local static variable
791 if we did not do any inter-procedural code movement. */
792 unsigned used_by_single_function : 1;
793 };
794
795 /* Every top level asm statement is put into a asm_node. */
796
797 struct GTY(()) asm_node {
798 /* Next asm node. */
799 struct asm_node *next;
800 /* String for this asm node. */
801 tree asm_str;
802 /* Ordering of all cgraph nodes. */
803 int order;
804 };
805
806 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
807
808 template <>
809 template <>
810 inline bool
811 is_a_helper <cgraph_node *>::test (symtab_node *p)
812 {
813 return p->type == SYMTAB_FUNCTION;
814 }
815
816 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
817
818 template <>
819 template <>
820 inline bool
821 is_a_helper <varpool_node *>::test (symtab_node *p)
822 {
823 return p->type == SYMTAB_VARIABLE;
824 }
825
826 extern GTY(()) symtab_node *symtab_nodes;
827 extern GTY(()) int cgraph_n_nodes;
828 extern GTY(()) int cgraph_max_uid;
829 extern GTY(()) int cgraph_edge_max_uid;
830 extern bool cgraph_global_info_ready;
831 enum cgraph_state
832 {
833 /* Frontend is parsing and finalizing functions. */
834 CGRAPH_STATE_PARSING,
835 /* Callgraph is being constructed. It is safe to add new functions. */
836 CGRAPH_STATE_CONSTRUCTION,
837 /* Callgraph is being at LTO time. */
838 CGRAPH_LTO_STREAMING,
839 /* Callgraph is built and IPA passes are being run. */
840 CGRAPH_STATE_IPA,
841 /* Callgraph is built and all functions are transformed to SSA form. */
842 CGRAPH_STATE_IPA_SSA,
843 /* Functions are now ordered and being passed to RTL expanders. */
844 CGRAPH_STATE_EXPANSION,
845 /* All cgraph expansion is done. */
846 CGRAPH_STATE_FINISHED
847 };
848 extern enum cgraph_state cgraph_state;
849 extern bool cgraph_function_flags_ready;
850 extern cgraph_node_set cgraph_new_nodes;
851
852 extern GTY(()) struct asm_node *asm_nodes;
853 extern GTY(()) int symtab_order;
854 extern bool cpp_implicit_aliases_done;
855
856 /* Classifcation of symbols WRT partitioning. */
857 enum symbol_partitioning_class
858 {
859 /* External declarations are ignored by partitioning algorithms and they are
860 added into the boundary later via compute_ltrans_boundary. */
861 SYMBOL_EXTERNAL,
862 /* Partitioned symbols are pur into one of partitions. */
863 SYMBOL_PARTITION,
864 /* Duplicated symbols (such as comdat or constant pool references) are
865 copied into every node needing them via add_symbol_to_partition. */
866 SYMBOL_DUPLICATE
867 };
868
869
870 /* In symtab.c */
871 void symtab_register_node (symtab_node *);
872 void symtab_unregister_node (symtab_node *);
873 void symtab_remove_from_same_comdat_group (symtab_node *);
874 void symtab_remove_node (symtab_node *);
875 symtab_node *symtab_node_for_asm (const_tree asmname);
876 void symtab_add_to_same_comdat_group (symtab_node *, symtab_node *);
877 void symtab_dissolve_same_comdat_group_list (symtab_node *node);
878 void dump_symtab (FILE *);
879 void debug_symtab (void);
880 void dump_symtab_node (FILE *, symtab_node *);
881 void debug_symtab_node (symtab_node *);
882 void dump_symtab_base (FILE *, symtab_node *);
883 void verify_symtab (void);
884 void verify_symtab_node (symtab_node *);
885 bool verify_symtab_base (symtab_node *);
886 bool symtab_used_from_object_file_p (symtab_node *);
887 void symtab_make_decl_local (tree);
888 symtab_node *symtab_alias_ultimate_target (symtab_node *,
889 enum availability *avail = NULL);
890 bool symtab_resolve_alias (symtab_node *node, symtab_node *target);
891 void fixup_same_cpp_alias_visibility (symtab_node *node, symtab_node *target);
892 bool symtab_for_node_and_aliases (symtab_node *,
893 bool (*) (symtab_node *, void *),
894 void *,
895 bool);
896 symtab_node *symtab_nonoverwritable_alias (symtab_node *);
897 enum availability symtab_node_availability (symtab_node *);
898 bool symtab_semantically_equivalent_p (symtab_node *, symtab_node *);
899 enum symbol_partitioning_class symtab_get_symbol_partitioning_class (symtab_node *);
900
901 /* In cgraph.c */
902 void dump_cgraph (FILE *);
903 void debug_cgraph (void);
904 void dump_cgraph_node (FILE *, struct cgraph_node *);
905 void debug_cgraph_node (struct cgraph_node *);
906 void cgraph_remove_edge (struct cgraph_edge *);
907 void cgraph_remove_node (struct cgraph_node *);
908 void cgraph_release_function_body (struct cgraph_node *);
909 void release_function_body (tree);
910 void cgraph_node_remove_callees (struct cgraph_node *node);
911 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
912 struct cgraph_node *,
913 gimple, gcov_type, int);
914 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
915 int, gcov_type, int);
916 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
917 struct cgraph_node * cgraph_create_node (tree);
918 struct cgraph_node * cgraph_create_empty_node (void);
919 struct cgraph_node * cgraph_get_create_node (tree);
920 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
921 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
922 HOST_WIDE_INT, tree, tree);
923 struct cgraph_node *cgraph_node_for_asm (tree);
924 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
925 void cgraph_set_call_stmt (struct cgraph_edge *, gimple, bool update_speculative = true);
926 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
927 struct cgraph_local_info *cgraph_local_info (tree);
928 struct cgraph_global_info *cgraph_global_info (tree);
929 struct cgraph_rtl_info *cgraph_rtl_info (tree);
930 struct cgraph_node *cgraph_create_function_alias (tree, tree);
931 void cgraph_call_node_duplication_hooks (struct cgraph_node *,
932 struct cgraph_node *);
933 void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
934 struct cgraph_edge *);
935
936 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
937 struct cgraph_edge *cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
938 bool cgraph_only_called_directly_p (struct cgraph_node *);
939
940 bool cgraph_function_possibly_inlined_p (tree);
941 void cgraph_unnest_node (struct cgraph_node *);
942
943 enum availability cgraph_function_body_availability (struct cgraph_node *);
944 void cgraph_add_new_function (tree, bool);
945 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
946 cgraph_inline_failed_type_t cgraph_inline_failed_type (cgraph_inline_failed_t);
947
948 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
949 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
950 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
951 bool cgraph_node_cannot_return (struct cgraph_node *);
952 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
953 bool cgraph_will_be_removed_from_program_if_no_direct_calls
954 (struct cgraph_node *node);
955 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
956 (struct cgraph_node *node);
957 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
958 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
959 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
960 bool (*) (struct cgraph_node *, void *),
961 void *,
962 bool);
963 bool cgraph_for_node_and_aliases (struct cgraph_node *,
964 bool (*) (struct cgraph_node *, void *),
965 void *, bool);
966 vec<cgraph_edge_p> collect_callers_of_node (struct cgraph_node *node);
967 void verify_cgraph (void);
968 void verify_cgraph_node (struct cgraph_node *);
969 void cgraph_mark_address_taken_node (struct cgraph_node *);
970
971 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
972 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
973 typedef void (*varpool_node_hook)(varpool_node *, void *);
974 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
975 void *);
976 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
977 void *);
978 struct cgraph_edge_hook_list;
979 struct cgraph_node_hook_list;
980 struct varpool_node_hook_list;
981 struct cgraph_2edge_hook_list;
982 struct cgraph_2node_hook_list;
983 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
984 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
985 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
986 void *);
987 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
988 struct varpool_node_hook_list *varpool_add_node_removal_hook (varpool_node_hook,
989 void *);
990 void varpool_remove_node_removal_hook (struct varpool_node_hook_list *);
991 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
992 void *);
993 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
994 struct varpool_node_hook_list *varpool_add_variable_insertion_hook (varpool_node_hook,
995 void *);
996 void varpool_remove_variable_insertion_hook (struct varpool_node_hook_list *);
997 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
998 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
999 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
1000 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
1001 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
1002 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
1003 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
1004 enum availability *avail = NULL);
1005 bool cgraph_get_body (struct cgraph_node *node);
1006 struct cgraph_edge *
1007 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
1008 struct cgraph_node *,
1009 gcov_type, int);
1010 void cgraph_speculative_call_info (struct cgraph_edge *,
1011 struct cgraph_edge *&,
1012 struct cgraph_edge *&,
1013 struct ipa_ref *&);
1014 extern bool gimple_check_call_matching_types (gimple, tree, bool);
1015
1016 /* In cgraphunit.c */
1017 struct asm_node *add_asm_node (tree);
1018 extern FILE *cgraph_dump_file;
1019 void cgraph_finalize_function (tree, bool);
1020 void finalize_compilation_unit (void);
1021 void compile (void);
1022 void init_cgraph (void);
1023 void cgraph_process_new_functions (void);
1024 void cgraph_process_same_body_aliases (void);
1025 void fixup_same_cpp_alias_visibility (symtab_node *, symtab_node *target, tree);
1026 /* Initialize datastructures so DECL is a function in lowered gimple form.
1027 IN_SSA is true if the gimple is in SSA. */
1028 basic_block init_lowered_empty_function (tree, bool);
1029 void cgraph_reset_node (struct cgraph_node *);
1030 bool expand_thunk (struct cgraph_node *, bool, bool);
1031 void cgraph_make_wrapper (struct cgraph_node *source,
1032 struct cgraph_node *target);
1033
1034 /* In cgraphclones.c */
1035
1036 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
1037 struct cgraph_node *, gimple,
1038 unsigned, gcov_type, int, bool);
1039 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
1040 int, bool, vec<cgraph_edge_p>,
1041 bool, struct cgraph_node *, bitmap);
1042 tree clone_function_name (tree decl, const char *);
1043 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
1044 vec<cgraph_edge_p>,
1045 vec<ipa_replace_map_p, va_gc> *tree_map,
1046 bitmap args_to_skip,
1047 const char *clone_name);
1048 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
1049 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
1050 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
1051 bool update_speculative = true);
1052 void cgraph_create_edge_including_clones (struct cgraph_node *,
1053 struct cgraph_node *,
1054 gimple, gimple, gcov_type, int,
1055 cgraph_inline_failed_t);
1056 void cgraph_materialize_all_clones (void);
1057 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
1058 tree, vec<cgraph_edge_p>, bitmap);
1059 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
1060 vec<cgraph_edge_p>,
1061 vec<ipa_replace_map_p, va_gc> *,
1062 bitmap, bool, bitmap,
1063 basic_block, const char *);
1064 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
1065 bool, bitmap, bool, bitmap, basic_block);
1066 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
1067
1068 /* In cgraphbuild.c */
1069 unsigned int rebuild_cgraph_edges (void);
1070 void cgraph_rebuild_references (void);
1071 int compute_call_stmt_bb_frequency (tree, basic_block bb);
1072 void record_references_in_initializer (tree, bool);
1073 void ipa_record_stmt_references (struct cgraph_node *, gimple);
1074
1075 /* In ipa.c */
1076 bool symtab_remove_unreachable_nodes (bool, FILE *);
1077 cgraph_node_set cgraph_node_set_new (void);
1078 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
1079 struct cgraph_node *);
1080 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
1081 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
1082 void dump_cgraph_node_set (FILE *, cgraph_node_set);
1083 void debug_cgraph_node_set (cgraph_node_set);
1084 void free_cgraph_node_set (cgraph_node_set);
1085 void cgraph_build_static_cdtor (char which, tree body, int priority);
1086
1087 varpool_node_set varpool_node_set_new (void);
1088 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
1089 varpool_node *);
1090 void varpool_node_set_add (varpool_node_set, varpool_node *);
1091 void varpool_node_set_remove (varpool_node_set, varpool_node *);
1092 void dump_varpool_node_set (FILE *, varpool_node_set);
1093 void debug_varpool_node_set (varpool_node_set);
1094 void free_varpool_node_set (varpool_node_set);
1095 void ipa_discover_readonly_nonaddressable_vars (void);
1096 bool varpool_externally_visible_p (varpool_node *);
1097
1098 /* In ipa-visibility.c */
1099 bool cgraph_local_node_p (struct cgraph_node *);
1100 bool address_taken_from_non_vtable_p (symtab_node *node);
1101
1102
1103 /* In predict.c */
1104 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
1105 bool cgraph_optimize_for_size_p (struct cgraph_node *);
1106
1107 /* In varpool.c */
1108 varpool_node *varpool_create_empty_node (void);
1109 varpool_node *varpool_node_for_decl (tree);
1110 varpool_node *varpool_node_for_asm (tree asmname);
1111 void varpool_mark_needed_node (varpool_node *);
1112 void debug_varpool (void);
1113 void dump_varpool (FILE *);
1114 void dump_varpool_node (FILE *, varpool_node *);
1115
1116 void varpool_finalize_decl (tree);
1117 enum availability cgraph_variable_initializer_availability (varpool_node *);
1118 void cgraph_make_node_local (struct cgraph_node *);
1119 bool cgraph_node_can_be_local_p (struct cgraph_node *);
1120
1121
1122 void varpool_remove_node (varpool_node *node);
1123 void varpool_finalize_named_section_flags (varpool_node *node);
1124 bool varpool_output_variables (void);
1125 bool varpool_assemble_decl (varpool_node *node);
1126 void varpool_analyze_node (varpool_node *);
1127 varpool_node * varpool_extra_name_alias (tree, tree);
1128 varpool_node * varpool_create_variable_alias (tree, tree);
1129 void varpool_reset_queue (void);
1130 tree ctor_for_folding (tree);
1131 bool varpool_for_node_and_aliases (varpool_node *,
1132 bool (*) (varpool_node *, void *),
1133 void *, bool);
1134 void varpool_add_new_variable (tree);
1135 void symtab_initialize_asm_name_hash (void);
1136 void symtab_prevail_in_asm_name_hash (symtab_node *node);
1137 void varpool_remove_initializer (varpool_node *);
1138
1139 /* In cgraph.c */
1140 extern void change_decl_assembler_name (tree, tree);
1141
1142 /* Return symbol table node associated with DECL, if any,
1143 and NULL otherwise. */
1144
1145 static inline symtab_node *
1146 symtab_get_node (const_tree decl)
1147 {
1148 #ifdef ENABLE_CHECKING
1149 /* Check that we are called for sane type of object - functions
1150 and static or external variables. */
1151 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL
1152 || (TREE_CODE (decl) == VAR_DECL
1153 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)
1154 || in_lto_p)));
1155 /* Check that the mapping is sane - perhaps this check can go away,
1156 but at the moment frontends tends to corrupt the mapping by calling
1157 memcpy/memset on the tree nodes. */
1158 gcc_checking_assert (!decl->decl_with_vis.symtab_node
1159 || decl->decl_with_vis.symtab_node->decl == decl);
1160 #endif
1161 return decl->decl_with_vis.symtab_node;
1162 }
1163
1164 /* Return callgraph node for given symbol and check it is a function. */
1165 static inline struct cgraph_node *
1166 cgraph (symtab_node *node)
1167 {
1168 gcc_checking_assert (!node || node->type == SYMTAB_FUNCTION);
1169 return (struct cgraph_node *)node;
1170 }
1171
1172 /* Return varpool node for given symbol and check it is a variable. */
1173 static inline varpool_node *
1174 varpool (symtab_node *node)
1175 {
1176 gcc_checking_assert (!node || node->type == SYMTAB_VARIABLE);
1177 return (varpool_node *)node;
1178 }
1179
1180 /* Return callgraph node for given symbol and check it is a function. */
1181 static inline struct cgraph_node *
1182 cgraph_get_node (const_tree decl)
1183 {
1184 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
1185 return cgraph (symtab_get_node (decl));
1186 }
1187
1188 /* Return varpool node for given symbol and check it is a function. */
1189 static inline varpool_node *
1190 varpool_get_node (const_tree decl)
1191 {
1192 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
1193 return varpool (symtab_get_node (decl));
1194 }
1195
1196 /* Walk all symbols. */
1197 #define FOR_EACH_SYMBOL(node) \
1198 for ((node) = symtab_nodes; (node); (node) = (node)->next)
1199
1200 /* Return first static symbol with definition. */
1201 static inline symtab_node *
1202 symtab_first_defined_symbol (void)
1203 {
1204 symtab_node *node;
1205
1206 for (node = symtab_nodes; node; node = node->next)
1207 if (node->definition)
1208 return node;
1209
1210 return NULL;
1211 }
1212
1213 /* Return next reachable static symbol with initializer after NODE. */
1214 static inline symtab_node *
1215 symtab_next_defined_symbol (symtab_node *node)
1216 {
1217 symtab_node *node1 = node->next;
1218
1219 for (; node1; node1 = node1->next)
1220 if (node1->definition)
1221 return node1;
1222
1223 return NULL;
1224 }
1225 /* Walk all symbols with definitions in current unit. */
1226 #define FOR_EACH_DEFINED_SYMBOL(node) \
1227 for ((node) = symtab_first_defined_symbol (); (node); \
1228 (node) = symtab_next_defined_symbol (node))
1229
1230 /* Return first variable. */
1231 static inline varpool_node *
1232 varpool_first_variable (void)
1233 {
1234 symtab_node *node;
1235 for (node = symtab_nodes; node; node = node->next)
1236 if (varpool_node *vnode = dyn_cast <varpool_node *> (node))
1237 return vnode;
1238 return NULL;
1239 }
1240
1241 /* Return next variable after NODE. */
1242 static inline varpool_node *
1243 varpool_next_variable (varpool_node *node)
1244 {
1245 symtab_node *node1 = node->next;
1246 for (; node1; node1 = node1->next)
1247 if (varpool_node *vnode1 = dyn_cast <varpool_node *> (node1))
1248 return vnode1;
1249 return NULL;
1250 }
1251 /* Walk all variables. */
1252 #define FOR_EACH_VARIABLE(node) \
1253 for ((node) = varpool_first_variable (); \
1254 (node); \
1255 (node) = varpool_next_variable ((node)))
1256
1257 /* Return first static variable with initializer. */
1258 static inline varpool_node *
1259 varpool_first_static_initializer (void)
1260 {
1261 symtab_node *node;
1262 for (node = symtab_nodes; node; node = node->next)
1263 {
1264 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1265 if (vnode && DECL_INITIAL (node->decl))
1266 return vnode;
1267 }
1268 return NULL;
1269 }
1270
1271 /* Return next static variable with initializer after NODE. */
1272 static inline varpool_node *
1273 varpool_next_static_initializer (varpool_node *node)
1274 {
1275 symtab_node *node1 = node->next;
1276 for (; node1; node1 = node1->next)
1277 {
1278 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1279 if (vnode1 && DECL_INITIAL (node1->decl))
1280 return vnode1;
1281 }
1282 return NULL;
1283 }
1284
1285 /* Walk all static variables with initializer set. */
1286 #define FOR_EACH_STATIC_INITIALIZER(node) \
1287 for ((node) = varpool_first_static_initializer (); (node); \
1288 (node) = varpool_next_static_initializer (node))
1289
1290 /* Return first static variable with definition. */
1291 static inline varpool_node *
1292 varpool_first_defined_variable (void)
1293 {
1294 symtab_node *node;
1295 for (node = symtab_nodes; node; node = node->next)
1296 {
1297 varpool_node *vnode = dyn_cast <varpool_node *> (node);
1298 if (vnode && vnode->definition)
1299 return vnode;
1300 }
1301 return NULL;
1302 }
1303
1304 /* Return next static variable with definition after NODE. */
1305 static inline varpool_node *
1306 varpool_next_defined_variable (varpool_node *node)
1307 {
1308 symtab_node *node1 = node->next;
1309 for (; node1; node1 = node1->next)
1310 {
1311 varpool_node *vnode1 = dyn_cast <varpool_node *> (node1);
1312 if (vnode1 && vnode1->definition)
1313 return vnode1;
1314 }
1315 return NULL;
1316 }
1317 /* Walk all variables with definitions in current unit. */
1318 #define FOR_EACH_DEFINED_VARIABLE(node) \
1319 for ((node) = varpool_first_defined_variable (); (node); \
1320 (node) = varpool_next_defined_variable (node))
1321
1322 /* Return first function with body defined. */
1323 static inline struct cgraph_node *
1324 cgraph_first_defined_function (void)
1325 {
1326 symtab_node *node;
1327 for (node = symtab_nodes; node; node = node->next)
1328 {
1329 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1330 if (cn && cn->definition)
1331 return cn;
1332 }
1333 return NULL;
1334 }
1335
1336 /* Return next function with body defined after NODE. */
1337 static inline struct cgraph_node *
1338 cgraph_next_defined_function (struct cgraph_node *node)
1339 {
1340 symtab_node *node1 = node->next;
1341 for (; node1; node1 = node1->next)
1342 {
1343 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1344 if (cn1 && cn1->definition)
1345 return cn1;
1346 }
1347 return NULL;
1348 }
1349
1350 /* Walk all functions with body defined. */
1351 #define FOR_EACH_DEFINED_FUNCTION(node) \
1352 for ((node) = cgraph_first_defined_function (); (node); \
1353 (node) = cgraph_next_defined_function ((node)))
1354
1355 /* Return first function. */
1356 static inline struct cgraph_node *
1357 cgraph_first_function (void)
1358 {
1359 symtab_node *node;
1360 for (node = symtab_nodes; node; node = node->next)
1361 if (cgraph_node *cn = dyn_cast <cgraph_node *> (node))
1362 return cn;
1363 return NULL;
1364 }
1365
1366 /* Return next function. */
1367 static inline struct cgraph_node *
1368 cgraph_next_function (struct cgraph_node *node)
1369 {
1370 symtab_node *node1 = node->next;
1371 for (; node1; node1 = node1->next)
1372 if (cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1))
1373 return cn1;
1374 return NULL;
1375 }
1376 /* Walk all functions. */
1377 #define FOR_EACH_FUNCTION(node) \
1378 for ((node) = cgraph_first_function (); (node); \
1379 (node) = cgraph_next_function ((node)))
1380
1381 /* Return true when NODE is a function with Gimple body defined
1382 in current unit. Functions can also be define externally or they
1383 can be thunks with no Gimple representation.
1384
1385 Note that at WPA stage, the function body may not be present in memory. */
1386
1387 static inline bool
1388 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1389 {
1390 return node->definition && !node->thunk.thunk_p && !node->alias;
1391 }
1392
1393 /* Return first function with body defined. */
1394 static inline struct cgraph_node *
1395 cgraph_first_function_with_gimple_body (void)
1396 {
1397 symtab_node *node;
1398 for (node = symtab_nodes; node; node = node->next)
1399 {
1400 cgraph_node *cn = dyn_cast <cgraph_node *> (node);
1401 if (cn && cgraph_function_with_gimple_body_p (cn))
1402 return cn;
1403 }
1404 return NULL;
1405 }
1406
1407 /* Return next reachable static variable with initializer after NODE. */
1408 static inline struct cgraph_node *
1409 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1410 {
1411 symtab_node *node1 = node->next;
1412 for (; node1; node1 = node1->next)
1413 {
1414 cgraph_node *cn1 = dyn_cast <cgraph_node *> (node1);
1415 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1416 return cn1;
1417 }
1418 return NULL;
1419 }
1420
1421 /* Walk all functions with body defined. */
1422 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1423 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1424 (node) = cgraph_next_function_with_gimple_body (node))
1425
1426 /* Create a new static variable of type TYPE. */
1427 tree add_new_static_var (tree type);
1428
1429 /* Return true if iterator CSI points to nothing. */
1430 static inline bool
1431 csi_end_p (cgraph_node_set_iterator csi)
1432 {
1433 return csi.index >= csi.set->nodes.length ();
1434 }
1435
1436 /* Advance iterator CSI. */
1437 static inline void
1438 csi_next (cgraph_node_set_iterator *csi)
1439 {
1440 csi->index++;
1441 }
1442
1443 /* Return the node pointed to by CSI. */
1444 static inline struct cgraph_node *
1445 csi_node (cgraph_node_set_iterator csi)
1446 {
1447 return csi.set->nodes[csi.index];
1448 }
1449
1450 /* Return an iterator to the first node in SET. */
1451 static inline cgraph_node_set_iterator
1452 csi_start (cgraph_node_set set)
1453 {
1454 cgraph_node_set_iterator csi;
1455
1456 csi.set = set;
1457 csi.index = 0;
1458 return csi;
1459 }
1460
1461 /* Return true if SET contains NODE. */
1462 static inline bool
1463 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1464 {
1465 cgraph_node_set_iterator csi;
1466 csi = cgraph_node_set_find (set, node);
1467 return !csi_end_p (csi);
1468 }
1469
1470 /* Return number of nodes in SET. */
1471 static inline size_t
1472 cgraph_node_set_size (cgraph_node_set set)
1473 {
1474 return set->nodes.length ();
1475 }
1476
1477 /* Return true if iterator VSI points to nothing. */
1478 static inline bool
1479 vsi_end_p (varpool_node_set_iterator vsi)
1480 {
1481 return vsi.index >= vsi.set->nodes.length ();
1482 }
1483
1484 /* Advance iterator VSI. */
1485 static inline void
1486 vsi_next (varpool_node_set_iterator *vsi)
1487 {
1488 vsi->index++;
1489 }
1490
1491 /* Return the node pointed to by VSI. */
1492 static inline varpool_node *
1493 vsi_node (varpool_node_set_iterator vsi)
1494 {
1495 return vsi.set->nodes[vsi.index];
1496 }
1497
1498 /* Return an iterator to the first node in SET. */
1499 static inline varpool_node_set_iterator
1500 vsi_start (varpool_node_set set)
1501 {
1502 varpool_node_set_iterator vsi;
1503
1504 vsi.set = set;
1505 vsi.index = 0;
1506 return vsi;
1507 }
1508
1509 /* Return true if SET contains NODE. */
1510 static inline bool
1511 varpool_node_in_set_p (varpool_node *node, varpool_node_set set)
1512 {
1513 varpool_node_set_iterator vsi;
1514 vsi = varpool_node_set_find (set, node);
1515 return !vsi_end_p (vsi);
1516 }
1517
1518 /* Return number of nodes in SET. */
1519 static inline size_t
1520 varpool_node_set_size (varpool_node_set set)
1521 {
1522 return set->nodes.length ();
1523 }
1524
1525 /* Uniquize all constants that appear in memory.
1526 Each constant in memory thus far output is recorded
1527 in `const_desc_table'. */
1528
1529 struct GTY(()) constant_descriptor_tree {
1530 /* A MEM for the constant. */
1531 rtx rtl;
1532
1533 /* The value of the constant. */
1534 tree value;
1535
1536 /* Hash of value. Computing the hash from value each time
1537 hashfn is called can't work properly, as that means recursive
1538 use of the hash table during hash table expansion. */
1539 hashval_t hash;
1540 };
1541
1542 /* Return true if set is nonempty. */
1543 static inline bool
1544 cgraph_node_set_nonempty_p (cgraph_node_set set)
1545 {
1546 return !set->nodes.is_empty ();
1547 }
1548
1549 /* Return true if set is nonempty. */
1550 static inline bool
1551 varpool_node_set_nonempty_p (varpool_node_set set)
1552 {
1553 return !set->nodes.is_empty ();
1554 }
1555
1556 /* Return true when function NODE is only called directly or it has alias.
1557 i.e. it is not externally visible, address was not taken and
1558 it is not used in any other non-standard way. */
1559
1560 static inline bool
1561 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1562 {
1563 gcc_assert (!node->global.inlined_to);
1564 return (!node->force_output && !node->address_taken
1565 && !node->used_from_other_partition
1566 && !DECL_VIRTUAL_P (node->decl)
1567 && !DECL_STATIC_CONSTRUCTOR (node->decl)
1568 && !DECL_STATIC_DESTRUCTOR (node->decl)
1569 && !node->externally_visible);
1570 }
1571
1572 /* Return true when function NODE can be removed from callgraph
1573 if all direct calls are eliminated. */
1574
1575 static inline bool
1576 varpool_can_remove_if_no_refs (varpool_node *node)
1577 {
1578 if (DECL_EXTERNAL (node->decl))
1579 return true;
1580 return (!node->force_output && !node->used_from_other_partition
1581 && ((DECL_COMDAT (node->decl)
1582 && !node->forced_by_abi
1583 && !symtab_used_from_object_file_p (node))
1584 || !node->externally_visible
1585 || DECL_HAS_VALUE_EXPR_P (node->decl)));
1586 }
1587
1588 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1589 i.e. if the variable is not externally visible or not used in some magic
1590 way (asm statement or such).
1591 The magic uses are all summarized in force_output flag. */
1592
1593 static inline bool
1594 varpool_all_refs_explicit_p (varpool_node *vnode)
1595 {
1596 return (vnode->definition
1597 && !vnode->externally_visible
1598 && !vnode->used_from_other_partition
1599 && !vnode->force_output);
1600 }
1601
1602 /* Constant pool accessor function. */
1603 htab_t constant_pool_htab (void);
1604
1605 /* Return node that alias N is aliasing. */
1606
1607 static inline symtab_node *
1608 symtab_alias_target (symtab_node *n)
1609 {
1610 struct ipa_ref *ref = NULL;
1611 n->iterate_reference (0, ref);
1612 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1613 return ref->referred;
1614 }
1615
1616 static inline struct cgraph_node *
1617 cgraph_alias_target (struct cgraph_node *n)
1618 {
1619 return dyn_cast <cgraph_node *> (symtab_alias_target (n));
1620 }
1621
1622 static inline varpool_node *
1623 varpool_alias_target (varpool_node *n)
1624 {
1625 return dyn_cast <varpool_node *> (symtab_alias_target (n));
1626 }
1627
1628 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1629 Do not walk through thunks.
1630 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1631
1632 static inline struct cgraph_node *
1633 cgraph_function_or_thunk_node (struct cgraph_node *node,
1634 enum availability *availability = NULL)
1635 {
1636 struct cgraph_node *n;
1637
1638 n = dyn_cast <cgraph_node *> (symtab_alias_ultimate_target (node,
1639 availability));
1640 if (!n && availability)
1641 *availability = AVAIL_NOT_AVAILABLE;
1642 return n;
1643 }
1644 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1645 Do not walk through thunks.
1646 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1647
1648 static inline varpool_node *
1649 varpool_variable_node (varpool_node *node,
1650 enum availability *availability = NULL)
1651 {
1652 varpool_node *n;
1653
1654 if (node)
1655 n = dyn_cast <varpool_node *> (symtab_alias_ultimate_target (node,
1656 availability));
1657 else
1658 n = NULL;
1659
1660 if (!n && availability)
1661 *availability = AVAIL_NOT_AVAILABLE;
1662 return n;
1663 }
1664
1665 /* Return true when the edge E represents a direct recursion. */
1666 static inline bool
1667 cgraph_edge_recursive_p (struct cgraph_edge *e)
1668 {
1669 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1670 if (e->caller->global.inlined_to)
1671 return e->caller->global.inlined_to->decl == callee->decl;
1672 else
1673 return e->caller->decl == callee->decl;
1674 }
1675
1676 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1677 static inline bool
1678 decl_is_tm_clone (const_tree fndecl)
1679 {
1680 struct cgraph_node *n = cgraph_get_node (fndecl);
1681 if (n)
1682 return n->tm_clone;
1683 return false;
1684 }
1685
1686 /* Likewise indicate that a node is needed, i.e. reachable via some
1687 external means. */
1688
1689 static inline void
1690 cgraph_mark_force_output_node (struct cgraph_node *node)
1691 {
1692 node->force_output = 1;
1693 gcc_checking_assert (!node->global.inlined_to);
1694 }
1695
1696 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1697 or abstract function kept for debug info purposes only. */
1698
1699 static inline bool
1700 symtab_real_symbol_p (symtab_node *node)
1701 {
1702 struct cgraph_node *cnode;
1703
1704 if (DECL_ABSTRACT (node->decl))
1705 return false;
1706 if (!is_a <cgraph_node *> (node))
1707 return true;
1708 cnode = cgraph (node);
1709 if (cnode->global.inlined_to)
1710 return false;
1711 return true;
1712 }
1713
1714 /* Return true if NODE can be discarded by linker from the binary. */
1715
1716 static inline bool
1717 symtab_can_be_discarded (symtab_node *node)
1718 {
1719 return (DECL_EXTERNAL (node->decl)
1720 || (node->get_comdat_group ()
1721 && node->resolution != LDPR_PREVAILING_DEF
1722 && node->resolution != LDPR_PREVAILING_DEF_IRONLY
1723 && node->resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1724 }
1725
1726 /* Return true if NODE is local to a particular COMDAT group, and must not
1727 be named from outside the COMDAT. This is used for C++ decloned
1728 constructors. */
1729
1730 static inline bool
1731 symtab_comdat_local_p (symtab_node *node)
1732 {
1733 return (node->same_comdat_group && !TREE_PUBLIC (node->decl));
1734 }
1735
1736 /* Return true if ONE and TWO are part of the same COMDAT group. */
1737
1738 static inline bool
1739 symtab_in_same_comdat_p (symtab_node *one, symtab_node *two)
1740 {
1741 if (cgraph_node *cn = dyn_cast <cgraph_node *> (one))
1742 {
1743 if (cn->global.inlined_to)
1744 one = cn->global.inlined_to;
1745 }
1746 if (cgraph_node *cn = dyn_cast <cgraph_node *> (two))
1747 {
1748 if (cn->global.inlined_to)
1749 two = cn->global.inlined_to;
1750 }
1751
1752 return one->get_comdat_group () == two->get_comdat_group ();
1753 }
1754 #endif /* GCC_CGRAPH_H */