Fix PR/46316
[official-gcc.git] / gcc / cgraph.h
blob2b7ed4b8985dc757e1658622b78fb3e92365f693
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
25 #include "plugin-api.h"
26 #include "vec.h"
27 #include "tree.h"
28 #include "basic-block.h"
29 #include "function.h"
30 #include "ipa-ref.h" /* FIXME: inappropriate dependency of cgraph on IPA. */
32 enum availability
34 /* Not yet set by cgraph_function_body_availability. */
35 AVAIL_UNSET,
36 /* Function body/variable initializer is unknown. */
37 AVAIL_NOT_AVAILABLE,
38 /* Function body/variable initializer is known but might be replaced
39 by a different one from other compilation unit and thus needs to
40 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
41 arbitrary side effects on escaping variables and functions, while
42 like AVAILABLE it might access static variables. */
43 AVAIL_OVERWRITABLE,
44 /* Function body/variable initializer is known and will be used in final
45 program. */
46 AVAIL_AVAILABLE,
47 /* Function body/variable initializer is known and all it's uses are explicitly
48 visible within current unit (ie it's address is never taken and it is not
49 exported to other units).
50 Currently used only for functions. */
51 AVAIL_LOCAL
54 /* This is the information that is put into the cgraph local structure
55 to recover a function. */
56 struct lto_file_decl_data;
58 extern const char * const cgraph_availability_names[];
60 /* Function inlining information. */
62 struct GTY(()) inline_summary
64 /* Estimated stack frame consumption by the function. */
65 HOST_WIDE_INT estimated_self_stack_size;
67 /* Size of the function body. */
68 int self_size;
69 /* How many instructions are likely going to disappear after inlining. */
70 int size_inlining_benefit;
71 /* Estimated time spent executing the function body. */
72 int self_time;
73 /* How much time is going to be saved by inlining. */
74 int time_inlining_benefit;
77 /* Information about thunk, used only for same body aliases. */
79 struct GTY(()) cgraph_thunk_info {
80 /* Information about the thunk. */
81 HOST_WIDE_INT fixed_offset;
82 HOST_WIDE_INT virtual_value;
83 tree alias;
84 bool this_adjusting;
85 bool virtual_offset_p;
86 /* Set to true when alias node is thunk. */
87 bool thunk_p;
90 /* Information about the function collected locally.
91 Available after function is analyzed. */
93 struct GTY(()) cgraph_local_info {
94 /* File stream where this node is being written to. */
95 struct lto_file_decl_data * lto_file_data;
97 struct inline_summary inline_summary;
99 /* Set when function function is visible in current compilation unit only
100 and its address is never taken. */
101 unsigned local : 1;
103 /* Set when function is visible by other units. */
104 unsigned externally_visible : 1;
106 /* Set once it has been finalized so we consider it to be output. */
107 unsigned finalized : 1;
109 /* False when there something makes inlining impossible (such as va_arg). */
110 unsigned inlinable : 1;
112 /* False when there something makes versioning impossible.
113 Currently computed and used only by ipa-cp. */
114 unsigned versionable : 1;
116 /* True when function should be inlined independently on its size. */
117 unsigned disregard_inline_limits : 1;
119 /* True when the function has been originally extern inline, but it is
120 redefined now. */
121 unsigned redefined_extern_inline : 1;
123 /* True if the function is going to be emitted in some other translation
124 unit, referenced from vtable. */
125 unsigned vtable_method : 1;
128 /* Information about the function that needs to be computed globally
129 once compilation is finished. Available only with -funit-at-a-time. */
131 struct GTY(()) cgraph_global_info {
132 /* Estimated stack frame consumption by the function. */
133 HOST_WIDE_INT estimated_stack_size;
134 /* Expected offset of the stack frame of inlined function. */
135 HOST_WIDE_INT stack_frame_offset;
137 /* For inline clones this points to the function they will be
138 inlined into. */
139 struct cgraph_node *inlined_to;
141 /* Estimated size of the function after inlining. */
142 int time;
143 int size;
145 /* Estimated growth after inlining. INT_MIN if not computed. */
146 int estimated_growth;
149 /* Information about the function that is propagated by the RTL backend.
150 Available only for functions that has been already assembled. */
152 struct GTY(()) cgraph_rtl_info {
153 unsigned int preferred_incoming_stack_boundary;
156 /* Represent which DECL tree (or reference to such tree)
157 will be replaced by another tree while versioning. */
158 struct GTY(()) ipa_replace_map
160 /* The tree that will be replaced. */
161 tree old_tree;
162 /* The new (replacing) tree. */
163 tree new_tree;
164 /* Parameter number to replace, when old_tree is NULL. */
165 int parm_num;
166 /* True when a substitution should be done, false otherwise. */
167 bool replace_p;
168 /* True when we replace a reference to old_tree. */
169 bool ref_p;
171 typedef struct ipa_replace_map *ipa_replace_map_p;
172 DEF_VEC_P(ipa_replace_map_p);
173 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
175 struct GTY(()) cgraph_clone_info
177 VEC(ipa_replace_map_p,gc)* tree_map;
178 bitmap args_to_skip;
179 bitmap combined_args_to_skip;
182 enum node_frequency {
183 /* This function most likely won't be executed at all.
184 (set only when profile feedback is available or via function attribute). */
185 NODE_FREQUENCY_UNLIKELY_EXECUTED,
186 /* For functions that are known to be executed once (i.e. constructors, destructors
187 and main function. */
188 NODE_FREQUENCY_EXECUTED_ONCE,
189 /* The default value. */
190 NODE_FREQUENCY_NORMAL,
191 /* Optimize this function hard
192 (set only when profile feedback is available or via function attribute). */
193 NODE_FREQUENCY_HOT
197 /* The cgraph data structure.
198 Each function decl has assigned cgraph_node listing callees and callers. */
200 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
201 tree decl;
202 struct cgraph_edge *callees;
203 struct cgraph_edge *callers;
204 struct cgraph_node *next;
205 struct cgraph_node *previous;
206 /* List of edges representing indirect calls with a yet undetermined
207 callee. */
208 struct cgraph_edge *indirect_calls;
209 /* For nested functions points to function the node is nested in. */
210 struct cgraph_node *origin;
211 /* Points to first nested function, if any. */
212 struct cgraph_node *nested;
213 /* Pointer to the next function with same origin, if any. */
214 struct cgraph_node *next_nested;
215 /* Pointer to the next function in cgraph_nodes_queue. */
216 struct cgraph_node *next_needed;
217 /* Pointer to the next clone. */
218 struct cgraph_node *next_sibling_clone;
219 struct cgraph_node *prev_sibling_clone;
220 struct cgraph_node *clones;
221 struct cgraph_node *clone_of;
222 /* For normal nodes pointer to the list of alias and thunk nodes,
223 in alias/thunk nodes pointer to the normal node. */
224 struct cgraph_node *same_body;
225 /* Circular list of nodes in the same comdat group if non-NULL. */
226 struct cgraph_node *same_comdat_group;
227 /* For functions with many calls sites it holds map from call expression
228 to the edge to speed up cgraph_edge function. */
229 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
230 /* Declaration node used to be clone of. */
231 tree former_clone_of;
233 PTR GTY ((skip)) aux;
235 /* Interprocedural passes scheduled to have their transform functions
236 applied next time we execute local pass on them. We maintain it
237 per-function in order to allow IPA passes to introduce new functions. */
238 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
240 struct ipa_ref_list ref_list;
241 struct cgraph_local_info local;
242 struct cgraph_global_info global;
243 struct cgraph_rtl_info rtl;
244 struct cgraph_clone_info clone;
245 struct cgraph_thunk_info thunk;
247 /* Expected number of executions: calculated in profile.c. */
248 gcov_type count;
249 /* Unique id of the node. */
250 int uid;
251 /* Ordering of all cgraph nodes. */
252 int order;
254 /* unique id for profiling. pid is not suitable because of different
255 number of cfg nodes with -fprofile-generate and -fprofile-use */
256 int pid;
257 enum ld_plugin_symbol_resolution resolution;
259 /* Set when function must be output for some reason. The primary
260 use of this flag is to mark functions needed to be output for
261 non-standard reason. Functions that are externally visible
262 or reachable from functions needed to be output are marked
263 by specialized flags. */
264 unsigned needed : 1;
265 /* Set when function has address taken.
266 In current implementation it imply needed flag. */
267 unsigned address_taken : 1;
268 /* Set when decl is an abstract function pointed to by the
269 ABSTRACT_DECL_ORIGIN of a reachable function. */
270 unsigned abstract_and_needed : 1;
271 /* Set when function is reachable by call from other function
272 that is either reachable or needed.
273 This flag is computed at original cgraph construction and then
274 updated in cgraph_remove_unreachable_nodes. Note that after
275 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
276 nodes when they are needed for virtual clone instantiation. */
277 unsigned reachable : 1;
278 /* Set when function is reachable by call from other LTRANS partition. */
279 unsigned reachable_from_other_partition : 1;
280 /* Set once the function is lowered (i.e. its CFG is built). */
281 unsigned lowered : 1;
282 /* Set once the function has been instantiated and its callee
283 lists created. */
284 unsigned analyzed : 1;
285 /* Set when function is available in the other LTRANS partition.
286 During WPA output it is used to mark nodes that are present in
287 multiple partitions. */
288 unsigned in_other_partition : 1;
289 /* Set when function is scheduled to be processed by local passes. */
290 unsigned process : 1;
291 /* Set for aliases once they got through assemble_alias. */
292 unsigned alias : 1;
293 /* Set for nodes that was constructed and finalized by frontend. */
294 unsigned finalized_by_frontend : 1;
295 /* Set for alias and thunk nodes, same_body points to the node they are alias
296 of and they are linked through the next/previous pointers. */
297 unsigned same_body_alias : 1;
298 /* How commonly executed the node is. Initialized during branch
299 probabilities pass. */
300 ENUM_BITFIELD (node_frequency) frequency : 2;
301 /* True when function can only be called at startup (from static ctor). */
302 unsigned only_called_at_startup : 1;
303 /* True when function can only be called at startup (from static dtor). */
304 unsigned only_called_at_exit : 1;
307 typedef struct cgraph_node *cgraph_node_ptr;
309 DEF_VEC_P(cgraph_node_ptr);
310 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
311 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
313 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
314 can appear in multiple sets. */
315 struct GTY(()) cgraph_node_set_def
317 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
318 VEC(cgraph_node_ptr, gc) *nodes;
321 typedef struct varpool_node *varpool_node_ptr;
323 DEF_VEC_P(varpool_node_ptr);
324 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
325 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
327 /* A varpool node set is a collection of varpool nodes. A varpool node
328 can appear in multiple sets. */
329 struct GTY(()) varpool_node_set_def
331 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
332 VEC(varpool_node_ptr, gc) *nodes;
335 typedef struct cgraph_node_set_def *cgraph_node_set;
337 DEF_VEC_P(cgraph_node_set);
338 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
339 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
341 typedef struct varpool_node_set_def *varpool_node_set;
343 DEF_VEC_P(varpool_node_set);
344 DEF_VEC_ALLOC_P(varpool_node_set,gc);
345 DEF_VEC_ALLOC_P(varpool_node_set,heap);
347 /* A cgraph node set element contains an index in the vector of nodes in
348 the set. */
349 struct GTY(()) cgraph_node_set_element_def
351 struct cgraph_node *node;
352 HOST_WIDE_INT index;
355 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
356 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
358 /* Iterator structure for cgraph node sets. */
359 typedef struct
361 cgraph_node_set set;
362 unsigned index;
363 } cgraph_node_set_iterator;
365 /* A varpool node set element contains an index in the vector of nodes in
366 the set. */
367 struct GTY(()) varpool_node_set_element_def
369 struct varpool_node *node;
370 HOST_WIDE_INT index;
373 typedef struct varpool_node_set_element_def *varpool_node_set_element;
374 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
376 /* Iterator structure for varpool node sets. */
377 typedef struct
379 varpool_node_set set;
380 unsigned index;
381 } varpool_node_set_iterator;
383 #define DEFCIFCODE(code, string) CIF_ ## code,
384 /* Reasons for inlining failures. */
385 typedef enum {
386 #include "cif-code.def"
387 CIF_N_REASONS
388 } cgraph_inline_failed_t;
390 /* Structure containing additional information about an indirect call. */
392 struct GTY(()) cgraph_indirect_call_info
394 /* Offset accumulated from ancestor jump functions of inlined call graph
395 edges. */
396 HOST_WIDE_INT anc_offset;
397 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
398 HOST_WIDE_INT otr_token;
399 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
400 tree otr_type;
401 /* Index of the parameter that is called. */
402 int param_index;
403 /* ECF flags determined from the caller. */
404 int ecf_flags;
406 /* Set when the call is a virtual call with the parameter being the
407 associated object pointer rather than a simple direct call. */
408 unsigned polymorphic : 1;
411 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
412 /* Expected number of executions: calculated in profile.c. */
413 gcov_type count;
414 struct cgraph_node *caller;
415 struct cgraph_node *callee;
416 struct cgraph_edge *prev_caller;
417 struct cgraph_edge *next_caller;
418 struct cgraph_edge *prev_callee;
419 struct cgraph_edge *next_callee;
420 gimple call_stmt;
421 /* Additional information about an indirect call. Not cleared when an edge
422 becomes direct. */
423 struct cgraph_indirect_call_info *indirect_info;
424 PTR GTY ((skip (""))) aux;
425 /* When equal to CIF_OK, inline this call. Otherwise, points to the
426 explanation why function was not inlined. */
427 cgraph_inline_failed_t inline_failed;
428 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
429 when the function is serialized in. */
430 unsigned int lto_stmt_uid;
431 /* Expected frequency of executions within the function.
432 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
433 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
434 int frequency;
435 /* Unique id of the edge. */
436 int uid;
437 /* Depth of loop nest, 1 means no loop nest. */
438 unsigned short int loop_nest;
439 /* Whether this edge was made direct by indirect inlining. */
440 unsigned int indirect_inlining_edge : 1;
441 /* Whether this edge describes an indirect call with an undetermined
442 callee. */
443 unsigned int indirect_unknown_callee : 1;
444 /* Whether this edge is still a dangling */
445 /* True if the corresponding CALL stmt cannot be inlined. */
446 unsigned int call_stmt_cannot_inline_p : 1;
447 /* Can this call throw externally? */
448 unsigned int can_throw_external : 1;
451 #define CGRAPH_FREQ_BASE 1000
452 #define CGRAPH_FREQ_MAX 100000
454 typedef struct cgraph_edge *cgraph_edge_p;
456 DEF_VEC_P(cgraph_edge_p);
457 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
459 /* The varpool data structure.
460 Each static variable decl has assigned varpool_node. */
462 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
463 tree decl;
464 /* Pointer to the next function in varpool_nodes. */
465 struct varpool_node *next, *prev;
466 /* Pointer to the next function in varpool_nodes_queue. */
467 struct varpool_node *next_needed, *prev_needed;
468 /* For normal nodes a pointer to the first extra name alias. For alias
469 nodes a pointer to the normal node. */
470 struct varpool_node *extra_name;
471 /* Circular list of nodes in the same comdat group if non-NULL. */
472 struct varpool_node *same_comdat_group;
473 struct ipa_ref_list ref_list;
474 /* File stream where this node is being written to. */
475 struct lto_file_decl_data * lto_file_data;
476 PTR GTY ((skip)) aux;
477 /* Ordering of all cgraph nodes. */
478 int order;
479 enum ld_plugin_symbol_resolution resolution;
481 /* Set when function must be output - it is externally visible
482 or its address is taken. */
483 unsigned needed : 1;
484 /* Needed variables might become dead by optimization. This flag
485 forces the variable to be output even if it appears dead otherwise. */
486 unsigned force_output : 1;
487 /* Set once the variable has been instantiated and its callee
488 lists created. */
489 unsigned analyzed : 1;
490 /* Set once it has been finalized so we consider it to be output. */
491 unsigned finalized : 1;
492 /* Set when variable is scheduled to be assembled. */
493 unsigned output : 1;
494 /* Set when function is visible by other units. */
495 unsigned externally_visible : 1;
496 /* Set for aliases once they got through assemble_alias. Also set for
497 extra name aliases in varpool_extra_name_alias. */
498 unsigned alias : 1;
499 /* Set when variable is used from other LTRANS partition. */
500 unsigned used_from_other_partition : 1;
501 /* Set when variable is available in the other LTRANS partition.
502 During WPA output it is used to mark nodes that are present in
503 multiple partitions. */
504 unsigned in_other_partition : 1;
507 /* Every top level asm statement is put into a cgraph_asm_node. */
509 struct GTY(()) cgraph_asm_node {
510 /* Next asm node. */
511 struct cgraph_asm_node *next;
512 /* String for this asm node. */
513 tree asm_str;
514 /* Ordering of all cgraph nodes. */
515 int order;
518 extern GTY(()) struct cgraph_node *cgraph_nodes;
519 extern GTY(()) int cgraph_n_nodes;
520 extern GTY(()) int cgraph_max_uid;
521 extern GTY(()) int cgraph_edge_max_uid;
522 extern GTY(()) int cgraph_max_pid;
523 extern bool cgraph_global_info_ready;
524 enum cgraph_state
526 /* Callgraph is being constructed. It is safe to add new functions. */
527 CGRAPH_STATE_CONSTRUCTION,
528 /* Callgraph is built and IPA passes are being run. */
529 CGRAPH_STATE_IPA,
530 /* Callgraph is built and all functions are transformed to SSA form. */
531 CGRAPH_STATE_IPA_SSA,
532 /* Functions are now ordered and being passed to RTL expanders. */
533 CGRAPH_STATE_EXPANSION,
534 /* All cgraph expansion is done. */
535 CGRAPH_STATE_FINISHED
537 extern enum cgraph_state cgraph_state;
538 extern bool cgraph_function_flags_ready;
539 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
540 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
542 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
543 extern GTY(()) int cgraph_order;
545 /* In cgraph.c */
546 void dump_cgraph (FILE *);
547 void debug_cgraph (void);
548 void dump_cgraph_node (FILE *, struct cgraph_node *);
549 void debug_cgraph_node (struct cgraph_node *);
550 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
551 void cgraph_remove_edge (struct cgraph_edge *);
552 void cgraph_remove_node (struct cgraph_node *);
553 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
554 void cgraph_release_function_body (struct cgraph_node *);
555 void cgraph_node_remove_callees (struct cgraph_node *node);
556 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
557 struct cgraph_node *,
558 gimple, gcov_type, int, int);
559 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, int,
560 gcov_type, int, int);
561 struct cgraph_node * cgraph_get_node (const_tree);
562 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
563 struct cgraph_node * cgraph_node (tree);
564 struct cgraph_node * cgraph_same_body_alias (tree, tree);
565 struct cgraph_node * cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT,
566 HOST_WIDE_INT, tree, tree);
567 void cgraph_remove_same_body_alias (struct cgraph_node *);
568 struct cgraph_node *cgraph_node_for_asm (tree);
569 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
570 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
571 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
572 void cgraph_create_edge_including_clones (struct cgraph_node *,
573 struct cgraph_node *,
574 gimple, gimple, gcov_type, int, int,
575 cgraph_inline_failed_t);
576 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
577 struct cgraph_local_info *cgraph_local_info (tree);
578 struct cgraph_global_info *cgraph_global_info (tree);
579 struct cgraph_rtl_info *cgraph_rtl_info (tree);
580 const char * cgraph_node_name (struct cgraph_node *);
581 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
582 struct cgraph_node *, gimple,
583 unsigned, gcov_type, int, int, bool);
584 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
585 int, bool, VEC(cgraph_edge_p,heap) *);
587 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
588 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
590 struct cgraph_asm_node *cgraph_add_asm_node (tree);
592 bool cgraph_function_possibly_inlined_p (tree);
593 void cgraph_unnest_node (struct cgraph_node *);
595 enum availability cgraph_function_body_availability (struct cgraph_node *);
596 void cgraph_add_new_function (tree, bool);
597 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
598 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
599 VEC(cgraph_edge_p,heap)*,
600 VEC(ipa_replace_map_p,gc)* tree_map,
601 bitmap args_to_skip,
602 const char *clone_name);
604 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
605 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
606 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
607 tree clone_function_name (tree decl, const char *);
608 bool cgraph_node_cannot_return (struct cgraph_node *);
609 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
610 bool cgraph_will_be_removed_from_program_if_no_direct_calls
611 (struct cgraph_node *node);
612 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
613 (struct cgraph_node *node);
614 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
615 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
616 bool varpool_used_from_object_file_p (struct varpool_node *node);
618 /* In cgraphunit.c */
619 extern FILE *cgraph_dump_file;
620 void cgraph_finalize_function (tree, bool);
621 void cgraph_mark_if_needed (tree);
622 void cgraph_finalize_compilation_unit (void);
623 void cgraph_optimize (void);
624 void cgraph_mark_needed_node (struct cgraph_node *);
625 void cgraph_mark_address_taken_node (struct cgraph_node *);
626 void cgraph_mark_reachable_node (struct cgraph_node *);
627 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
628 bool cgraph_preserve_function_body_p (tree);
629 void verify_cgraph (void);
630 void verify_cgraph_node (struct cgraph_node *);
631 void cgraph_build_static_cdtor (char which, tree body, int priority);
632 void cgraph_reset_static_var_maps (void);
633 void init_cgraph (void);
634 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
635 VEC(cgraph_edge_p,heap)*,
636 VEC(ipa_replace_map_p,gc)*,
637 bitmap, bitmap, basic_block,
638 const char *);
639 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
640 bitmap, basic_block);
641 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
642 void record_references_in_initializer (tree, bool);
643 bool cgraph_process_new_functions (void);
645 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
647 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
648 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
649 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
650 void *);
651 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
652 void *);
653 struct cgraph_edge_hook_list;
654 struct cgraph_node_hook_list;
655 struct cgraph_2edge_hook_list;
656 struct cgraph_2node_hook_list;
657 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
658 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
659 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
660 void *);
661 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
662 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
663 void *);
664 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
665 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
666 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
667 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
668 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
669 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
670 void cgraph_materialize_all_clones (void);
671 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
672 bool cgraph_propagate_frequency (struct cgraph_node *node);
673 /* In cgraphbuild.c */
674 unsigned int rebuild_cgraph_edges (void);
675 void cgraph_rebuild_references (void);
676 void reset_inline_failed (struct cgraph_node *);
677 int compute_call_stmt_bb_frequency (tree, basic_block bb);
679 /* In ipa.c */
680 bool cgraph_remove_unreachable_nodes (bool, FILE *);
681 int cgraph_postorder (struct cgraph_node **);
682 cgraph_node_set cgraph_node_set_new (void);
683 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
684 struct cgraph_node *);
685 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
686 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
687 void dump_cgraph_node_set (FILE *, cgraph_node_set);
688 void debug_cgraph_node_set (cgraph_node_set);
690 varpool_node_set varpool_node_set_new (void);
691 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
692 struct varpool_node *);
693 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
694 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
695 void dump_varpool_node_set (FILE *, varpool_node_set);
696 void debug_varpool_node_set (varpool_node_set);
697 void ipa_discover_readonly_nonaddressable_vars (void);
699 /* In predict.c */
700 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
702 /* In varpool.c */
703 extern GTY(()) struct varpool_node *varpool_nodes_queue;
704 extern GTY(()) struct varpool_node *varpool_nodes;
706 struct varpool_node *varpool_node (tree);
707 struct varpool_node *varpool_node_for_asm (tree asmname);
708 void varpool_mark_needed_node (struct varpool_node *);
709 void debug_varpool (void);
710 void dump_varpool (FILE *);
711 void dump_varpool_node (FILE *, struct varpool_node *);
713 void varpool_finalize_decl (tree);
714 bool decide_is_variable_needed (struct varpool_node *, tree);
715 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
716 void cgraph_make_decl_local (tree);
717 void cgraph_make_node_local (struct cgraph_node *);
718 bool cgraph_node_can_be_local_p (struct cgraph_node *);
721 struct varpool_node * varpool_get_node (const_tree decl);
722 void varpool_remove_node (struct varpool_node *node);
723 bool varpool_assemble_pending_decls (void);
724 bool varpool_assemble_decl (struct varpool_node *node);
725 bool varpool_analyze_pending_decls (void);
726 void varpool_remove_unreferenced_decls (void);
727 void varpool_empty_needed_queue (void);
728 struct varpool_node * varpool_extra_name_alias (tree, tree);
729 const char * varpool_node_name (struct varpool_node *node);
730 void varpool_reset_queue (void);
731 bool const_value_known_p (tree);
733 /* Walk all reachable static variables. */
734 #define FOR_EACH_STATIC_VARIABLE(node) \
735 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
737 /* Return first reachable static variable with initializer. */
738 static inline struct varpool_node *
739 varpool_first_static_initializer (void)
741 struct varpool_node *node;
742 for (node = varpool_nodes_queue; node; node = node->next_needed)
744 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
745 if (DECL_INITIAL (node->decl))
746 return node;
748 return NULL;
751 /* Return next reachable static variable with initializer after NODE. */
752 static inline struct varpool_node *
753 varpool_next_static_initializer (struct varpool_node *node)
755 for (node = node->next_needed; node; node = node->next_needed)
757 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
758 if (DECL_INITIAL (node->decl))
759 return node;
761 return NULL;
764 /* Walk all static variables with initializer set. */
765 #define FOR_EACH_STATIC_INITIALIZER(node) \
766 for ((node) = varpool_first_static_initializer (); (node); \
767 (node) = varpool_next_static_initializer (node))
769 /* In ipa-inline.c */
770 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
771 unsigned int compute_inline_parameters (struct cgraph_node *);
774 /* Create a new static variable of type TYPE. */
775 tree add_new_static_var (tree type);
777 /* Return true if iterator CSI points to nothing. */
778 static inline bool
779 csi_end_p (cgraph_node_set_iterator csi)
781 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
784 /* Advance iterator CSI. */
785 static inline void
786 csi_next (cgraph_node_set_iterator *csi)
788 csi->index++;
791 /* Return the node pointed to by CSI. */
792 static inline struct cgraph_node *
793 csi_node (cgraph_node_set_iterator csi)
795 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
798 /* Return an iterator to the first node in SET. */
799 static inline cgraph_node_set_iterator
800 csi_start (cgraph_node_set set)
802 cgraph_node_set_iterator csi;
804 csi.set = set;
805 csi.index = 0;
806 return csi;
809 /* Return true if SET contains NODE. */
810 static inline bool
811 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
813 cgraph_node_set_iterator csi;
814 csi = cgraph_node_set_find (set, node);
815 return !csi_end_p (csi);
818 /* Return number of nodes in SET. */
819 static inline size_t
820 cgraph_node_set_size (cgraph_node_set set)
822 return htab_elements (set->hashtab);
825 /* Return true if iterator VSI points to nothing. */
826 static inline bool
827 vsi_end_p (varpool_node_set_iterator vsi)
829 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
832 /* Advance iterator VSI. */
833 static inline void
834 vsi_next (varpool_node_set_iterator *vsi)
836 vsi->index++;
839 /* Return the node pointed to by VSI. */
840 static inline struct varpool_node *
841 vsi_node (varpool_node_set_iterator vsi)
843 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
846 /* Return an iterator to the first node in SET. */
847 static inline varpool_node_set_iterator
848 vsi_start (varpool_node_set set)
850 varpool_node_set_iterator vsi;
852 vsi.set = set;
853 vsi.index = 0;
854 return vsi;
857 /* Return true if SET contains NODE. */
858 static inline bool
859 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
861 varpool_node_set_iterator vsi;
862 vsi = varpool_node_set_find (set, node);
863 return !vsi_end_p (vsi);
866 /* Return number of nodes in SET. */
867 static inline size_t
868 varpool_node_set_size (varpool_node_set set)
870 return htab_elements (set->hashtab);
873 /* Uniquize all constants that appear in memory.
874 Each constant in memory thus far output is recorded
875 in `const_desc_table'. */
877 struct GTY(()) constant_descriptor_tree {
878 /* A MEM for the constant. */
879 rtx rtl;
881 /* The value of the constant. */
882 tree value;
884 /* Hash of value. Computing the hash from value each time
885 hashfn is called can't work properly, as that means recursive
886 use of the hash table during hash table expansion. */
887 hashval_t hash;
890 /* Return true if set is nonempty. */
891 static inline bool
892 cgraph_node_set_nonempty_p (cgraph_node_set set)
894 return !VEC_empty (cgraph_node_ptr, set->nodes);
897 /* Return true if set is nonempty. */
898 static inline bool
899 varpool_node_set_nonempty_p (varpool_node_set set)
901 return !VEC_empty (varpool_node_ptr, set->nodes);
904 /* Return true when function NODE is only called directly.
905 i.e. it is not externally visible, address was not taken and
906 it is not used in any other non-standard way. */
908 static inline bool
909 cgraph_only_called_directly_p (struct cgraph_node *node)
911 gcc_assert (!node->global.inlined_to);
912 return (!node->needed && !node->address_taken
913 && !node->reachable_from_other_partition
914 && !DECL_STATIC_CONSTRUCTOR (node->decl)
915 && !DECL_STATIC_DESTRUCTOR (node->decl)
916 && !node->local.externally_visible);
919 /* Return true when function NODE can be removed from callgraph
920 if all direct calls are eliminated. */
922 static inline bool
923 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
925 /* Extern inlines can always go, we will use the external definition. */
926 if (DECL_EXTERNAL (node->decl))
927 return true;
928 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
931 /* Return true when all references to VNODE must be visible in ipa_ref_list.
932 i.e. if the variable is not externally visible or not used in some magic
933 way (asm statement or such).
934 The magic uses are all sumarized in force_output flag. */
936 static inline bool
937 varpool_all_refs_explicit_p (struct varpool_node *vnode)
939 return (!vnode->externally_visible
940 && !vnode->used_from_other_partition
941 && !vnode->force_output);
944 /* Constant pool accessor function. */
945 htab_t constant_pool_htab (void);
947 /* FIXME: inappropriate dependency of cgraph on IPA. */
948 #include "ipa-ref-inline.h"
950 #endif /* GCC_CGRAPH_H */