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