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