re PR bootstrap/46810 (sparc64-linux bootstrap fails with "C++ preprocessor "/lib...
[official-gcc.git] / gcc / cgraph.h
blob57a7e3bed221f08b73de7acd68e83b67c6c1276d
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[];
59 extern const char * const ld_plugin_symbol_resolution_names[];
61 /* Function inlining information. */
63 struct GTY(()) inline_summary
65 /* Estimated stack frame consumption by the function. */
66 HOST_WIDE_INT estimated_self_stack_size;
68 /* Size of the function body. */
69 int self_size;
70 /* How many instructions are likely going to disappear after inlining. */
71 int size_inlining_benefit;
72 /* Estimated time spent executing the function body. */
73 int self_time;
74 /* How much time is going to be saved by inlining. */
75 int time_inlining_benefit;
78 /* Information about thunk, used only for same body aliases. */
80 struct GTY(()) cgraph_thunk_info {
81 /* Information about the thunk. */
82 HOST_WIDE_INT fixed_offset;
83 HOST_WIDE_INT virtual_value;
84 tree alias;
85 bool this_adjusting;
86 bool virtual_offset_p;
87 /* Set to true when alias node is thunk. */
88 bool thunk_p;
91 /* Information about the function collected locally.
92 Available after function is analyzed. */
94 struct GTY(()) cgraph_local_info {
95 /* File stream where this node is being written to. */
96 struct lto_file_decl_data * lto_file_data;
98 struct inline_summary inline_summary;
100 /* Set when function function is visible in current compilation unit only
101 and its address is never taken. */
102 unsigned local : 1;
104 /* Set when function is visible by other units. */
105 unsigned externally_visible : 1;
107 /* Set once it has been finalized so we consider it to be output. */
108 unsigned finalized : 1;
110 /* False when there something makes inlining impossible (such as va_arg). */
111 unsigned inlinable : 1;
113 /* False when there something makes versioning impossible.
114 Currently computed and used only by ipa-cp. */
115 unsigned versionable : 1;
117 /* True when function should be inlined independently on its size. */
118 unsigned disregard_inline_limits : 1;
120 /* True when the function has been originally extern inline, but it is
121 redefined now. */
122 unsigned redefined_extern_inline : 1;
124 /* True if the function is going to be emitted in some other translation
125 unit, referenced from vtable. */
126 unsigned vtable_method : 1;
129 /* Information about the function that needs to be computed globally
130 once compilation is finished. Available only with -funit-at-a-time. */
132 struct GTY(()) cgraph_global_info {
133 /* Estimated stack frame consumption by the function. */
134 HOST_WIDE_INT estimated_stack_size;
135 /* Expected offset of the stack frame of inlined function. */
136 HOST_WIDE_INT stack_frame_offset;
138 /* For inline clones this points to the function they will be
139 inlined into. */
140 struct cgraph_node *inlined_to;
142 /* Estimated size of the function after inlining. */
143 int time;
144 int size;
146 /* Estimated growth after inlining. INT_MIN if not computed. */
147 int estimated_growth;
150 /* Information about the function that is propagated by the RTL backend.
151 Available only for functions that has been already assembled. */
153 struct GTY(()) cgraph_rtl_info {
154 unsigned int preferred_incoming_stack_boundary;
157 /* Represent which DECL tree (or reference to such tree)
158 will be replaced by another tree while versioning. */
159 struct GTY(()) ipa_replace_map
161 /* The tree that will be replaced. */
162 tree old_tree;
163 /* The new (replacing) tree. */
164 tree new_tree;
165 /* Parameter number to replace, when old_tree is NULL. */
166 int parm_num;
167 /* True when a substitution should be done, false otherwise. */
168 bool replace_p;
169 /* True when we replace a reference to old_tree. */
170 bool ref_p;
172 typedef struct ipa_replace_map *ipa_replace_map_p;
173 DEF_VEC_P(ipa_replace_map_p);
174 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
176 struct GTY(()) cgraph_clone_info
178 VEC(ipa_replace_map_p,gc)* tree_map;
179 bitmap args_to_skip;
180 bitmap combined_args_to_skip;
184 /* The cgraph data structure.
185 Each function decl has assigned cgraph_node listing callees and callers. */
187 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
188 tree decl;
189 struct cgraph_edge *callees;
190 struct cgraph_edge *callers;
191 struct cgraph_node *next;
192 struct cgraph_node *previous;
193 /* List of edges representing indirect calls with a yet undetermined
194 callee. */
195 struct cgraph_edge *indirect_calls;
196 /* For nested functions points to function the node is nested in. */
197 struct cgraph_node *origin;
198 /* Points to first nested function, if any. */
199 struct cgraph_node *nested;
200 /* Pointer to the next function with same origin, if any. */
201 struct cgraph_node *next_nested;
202 /* Pointer to the next function in cgraph_nodes_queue. */
203 struct cgraph_node *next_needed;
204 /* Pointer to the next clone. */
205 struct cgraph_node *next_sibling_clone;
206 struct cgraph_node *prev_sibling_clone;
207 struct cgraph_node *clones;
208 struct cgraph_node *clone_of;
209 /* For normal nodes pointer to the list of alias and thunk nodes,
210 in alias/thunk nodes pointer to the normal node. */
211 struct cgraph_node *same_body;
212 /* Circular list of nodes in the same comdat group if non-NULL. */
213 struct cgraph_node *same_comdat_group;
214 /* For functions with many calls sites it holds map from call expression
215 to the edge to speed up cgraph_edge function. */
216 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
217 /* Declaration node used to be clone of. */
218 tree former_clone_of;
220 PTR GTY ((skip)) aux;
222 /* Interprocedural passes scheduled to have their transform functions
223 applied next time we execute local pass on them. We maintain it
224 per-function in order to allow IPA passes to introduce new functions. */
225 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
227 struct ipa_ref_list ref_list;
228 struct cgraph_local_info local;
229 struct cgraph_global_info global;
230 struct cgraph_rtl_info rtl;
231 struct cgraph_clone_info clone;
232 struct cgraph_thunk_info thunk;
234 /* Expected number of executions: calculated in profile.c. */
235 gcov_type count;
236 /* How to scale counts at materialization time; used to merge
237 LTO units with different number of profile runs. */
238 int count_materialization_scale;
239 /* Unique id of the node. */
240 int uid;
241 /* Ordering of all cgraph nodes. */
242 int order;
244 /* unique id for profiling. pid is not suitable because of different
245 number of cfg nodes with -fprofile-generate and -fprofile-use */
246 int pid;
247 enum ld_plugin_symbol_resolution resolution;
249 /* Set when function must be output for some reason. The primary
250 use of this flag is to mark functions needed to be output for
251 non-standard reason. Functions that are externally visible
252 or reachable from functions needed to be output are marked
253 by specialized flags. */
254 unsigned needed : 1;
255 /* Set when function has address taken.
256 In current implementation it imply needed flag. */
257 unsigned address_taken : 1;
258 /* Set when decl is an abstract function pointed to by the
259 ABSTRACT_DECL_ORIGIN of a reachable function. */
260 unsigned abstract_and_needed : 1;
261 /* Set when function is reachable by call from other function
262 that is either reachable or needed.
263 This flag is computed at original cgraph construction and then
264 updated in cgraph_remove_unreachable_nodes. Note that after
265 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
266 nodes when they are needed for virtual clone instantiation. */
267 unsigned reachable : 1;
268 /* Set when function is reachable by call from other LTRANS partition. */
269 unsigned reachable_from_other_partition : 1;
270 /* Set once the function is lowered (i.e. its CFG is built). */
271 unsigned lowered : 1;
272 /* Set once the function has been instantiated and its callee
273 lists created. */
274 unsigned analyzed : 1;
275 /* Set when function is available in the other LTRANS partition.
276 During WPA output it is used to mark nodes that are present in
277 multiple partitions. */
278 unsigned in_other_partition : 1;
279 /* Set when function is scheduled to be processed by local passes. */
280 unsigned process : 1;
281 /* Set for aliases once they got through assemble_alias. */
282 unsigned alias : 1;
283 /* Set for nodes that was constructed and finalized by frontend. */
284 unsigned finalized_by_frontend : 1;
285 /* Set for alias and thunk nodes, same_body points to the node they are alias
286 of and they are linked through the next/previous pointers. */
287 unsigned same_body_alias : 1;
288 /* How commonly executed the node is. Initialized during branch
289 probabilities pass. */
290 ENUM_BITFIELD (node_frequency) frequency : 2;
291 /* True when function can only be called at startup (from static ctor). */
292 unsigned only_called_at_startup : 1;
293 /* True when function can only be called at startup (from static dtor). */
294 unsigned only_called_at_exit : 1;
297 typedef struct cgraph_node *cgraph_node_ptr;
299 DEF_VEC_P(cgraph_node_ptr);
300 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
301 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
303 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
304 can appear in multiple sets. */
305 struct GTY(()) cgraph_node_set_def
307 htab_t GTY((param_is (struct cgraph_node_set_element_def))) hashtab;
308 VEC(cgraph_node_ptr, gc) *nodes;
311 typedef struct varpool_node *varpool_node_ptr;
313 DEF_VEC_P(varpool_node_ptr);
314 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
315 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
317 /* A varpool node set is a collection of varpool nodes. A varpool node
318 can appear in multiple sets. */
319 struct GTY(()) varpool_node_set_def
321 htab_t GTY((param_is (struct varpool_node_set_element_def))) hashtab;
322 VEC(varpool_node_ptr, gc) *nodes;
325 typedef struct cgraph_node_set_def *cgraph_node_set;
327 DEF_VEC_P(cgraph_node_set);
328 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
329 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
331 typedef struct varpool_node_set_def *varpool_node_set;
333 DEF_VEC_P(varpool_node_set);
334 DEF_VEC_ALLOC_P(varpool_node_set,gc);
335 DEF_VEC_ALLOC_P(varpool_node_set,heap);
337 /* A cgraph node set element contains an index in the vector of nodes in
338 the set. */
339 struct GTY(()) cgraph_node_set_element_def
341 struct cgraph_node *node;
342 HOST_WIDE_INT index;
345 typedef struct cgraph_node_set_element_def *cgraph_node_set_element;
346 typedef const struct cgraph_node_set_element_def *const_cgraph_node_set_element;
348 /* Iterator structure for cgraph node sets. */
349 typedef struct
351 cgraph_node_set set;
352 unsigned index;
353 } cgraph_node_set_iterator;
355 /* A varpool node set element contains an index in the vector of nodes in
356 the set. */
357 struct GTY(()) varpool_node_set_element_def
359 struct varpool_node *node;
360 HOST_WIDE_INT index;
363 typedef struct varpool_node_set_element_def *varpool_node_set_element;
364 typedef const struct varpool_node_set_element_def *const_varpool_node_set_element;
366 /* Iterator structure for varpool node sets. */
367 typedef struct
369 varpool_node_set set;
370 unsigned index;
371 } varpool_node_set_iterator;
373 #define DEFCIFCODE(code, string) CIF_ ## code,
374 /* Reasons for inlining failures. */
375 typedef enum {
376 #include "cif-code.def"
377 CIF_N_REASONS
378 } cgraph_inline_failed_t;
380 /* Structure containing additional information about an indirect call. */
382 struct GTY(()) cgraph_indirect_call_info
384 /* Offset accumulated from ancestor jump functions of inlined call graph
385 edges. */
386 HOST_WIDE_INT anc_offset;
387 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
388 HOST_WIDE_INT otr_token;
389 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
390 tree otr_type;
391 /* Index of the parameter that is called. */
392 int param_index;
393 /* ECF flags determined from the caller. */
394 int ecf_flags;
396 /* Set when the call is a virtual call with the parameter being the
397 associated object pointer rather than a simple direct call. */
398 unsigned polymorphic : 1;
401 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
402 /* Expected number of executions: calculated in profile.c. */
403 gcov_type count;
404 struct cgraph_node *caller;
405 struct cgraph_node *callee;
406 struct cgraph_edge *prev_caller;
407 struct cgraph_edge *next_caller;
408 struct cgraph_edge *prev_callee;
409 struct cgraph_edge *next_callee;
410 gimple call_stmt;
411 /* Additional information about an indirect call. Not cleared when an edge
412 becomes direct. */
413 struct cgraph_indirect_call_info *indirect_info;
414 PTR GTY ((skip (""))) aux;
415 /* When equal to CIF_OK, inline this call. Otherwise, points to the
416 explanation why function was not inlined. */
417 cgraph_inline_failed_t inline_failed;
418 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
419 when the function is serialized in. */
420 unsigned int lto_stmt_uid;
421 /* Expected frequency of executions within the function.
422 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
423 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
424 int frequency;
425 /* Unique id of the edge. */
426 int uid;
427 /* Depth of loop nest, 1 means no loop nest. */
428 unsigned short int loop_nest;
429 /* Whether this edge was made direct by indirect inlining. */
430 unsigned int indirect_inlining_edge : 1;
431 /* Whether this edge describes an indirect call with an undetermined
432 callee. */
433 unsigned int indirect_unknown_callee : 1;
434 /* Whether this edge is still a dangling */
435 /* True if the corresponding CALL stmt cannot be inlined. */
436 unsigned int call_stmt_cannot_inline_p : 1;
437 /* Can this call throw externally? */
438 unsigned int can_throw_external : 1;
441 #define CGRAPH_FREQ_BASE 1000
442 #define CGRAPH_FREQ_MAX 100000
444 typedef struct cgraph_edge *cgraph_edge_p;
446 DEF_VEC_P(cgraph_edge_p);
447 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
449 /* The varpool data structure.
450 Each static variable decl has assigned varpool_node. */
452 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
453 tree decl;
454 /* Pointer to the next function in varpool_nodes. */
455 struct varpool_node *next, *prev;
456 /* Pointer to the next function in varpool_nodes_queue. */
457 struct varpool_node *next_needed, *prev_needed;
458 /* For normal nodes a pointer to the first extra name alias. For alias
459 nodes a pointer to the normal node. */
460 struct varpool_node *extra_name;
461 /* Circular list of nodes in the same comdat group if non-NULL. */
462 struct varpool_node *same_comdat_group;
463 struct ipa_ref_list ref_list;
464 /* File stream where this node is being written to. */
465 struct lto_file_decl_data * lto_file_data;
466 PTR GTY ((skip)) aux;
467 /* Ordering of all cgraph nodes. */
468 int order;
469 enum ld_plugin_symbol_resolution resolution;
471 /* Set when function must be output - it is externally visible
472 or its address is taken. */
473 unsigned needed : 1;
474 /* Needed variables might become dead by optimization. This flag
475 forces the variable to be output even if it appears dead otherwise. */
476 unsigned force_output : 1;
477 /* Set once the variable has been instantiated and its callee
478 lists created. */
479 unsigned analyzed : 1;
480 /* Set once it has been finalized so we consider it to be output. */
481 unsigned finalized : 1;
482 /* Set when variable is scheduled to be assembled. */
483 unsigned output : 1;
484 /* Set when function is visible by other units. */
485 unsigned externally_visible : 1;
486 /* Set for aliases once they got through assemble_alias. Also set for
487 extra name aliases in varpool_extra_name_alias. */
488 unsigned alias : 1;
489 /* Set when variable is used from other LTRANS partition. */
490 unsigned used_from_other_partition : 1;
491 /* Set when variable is available in the other LTRANS partition.
492 During WPA output it is used to mark nodes that are present in
493 multiple partitions. */
494 unsigned in_other_partition : 1;
497 /* Every top level asm statement is put into a cgraph_asm_node. */
499 struct GTY(()) cgraph_asm_node {
500 /* Next asm node. */
501 struct cgraph_asm_node *next;
502 /* String for this asm node. */
503 tree asm_str;
504 /* Ordering of all cgraph nodes. */
505 int order;
508 extern GTY(()) struct cgraph_node *cgraph_nodes;
509 extern GTY(()) int cgraph_n_nodes;
510 extern GTY(()) int cgraph_max_uid;
511 extern GTY(()) int cgraph_edge_max_uid;
512 extern GTY(()) int cgraph_max_pid;
513 extern bool cgraph_global_info_ready;
514 enum cgraph_state
516 /* Callgraph is being constructed. It is safe to add new functions. */
517 CGRAPH_STATE_CONSTRUCTION,
518 /* Callgraph is built and IPA passes are being run. */
519 CGRAPH_STATE_IPA,
520 /* Callgraph is built and all functions are transformed to SSA form. */
521 CGRAPH_STATE_IPA_SSA,
522 /* Functions are now ordered and being passed to RTL expanders. */
523 CGRAPH_STATE_EXPANSION,
524 /* All cgraph expansion is done. */
525 CGRAPH_STATE_FINISHED
527 extern enum cgraph_state cgraph_state;
528 extern bool cgraph_function_flags_ready;
529 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
530 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
532 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
533 extern GTY(()) int cgraph_order;
535 /* In cgraph.c */
536 void dump_cgraph (FILE *);
537 void debug_cgraph (void);
538 void dump_cgraph_node (FILE *, struct cgraph_node *);
539 void debug_cgraph_node (struct cgraph_node *);
540 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
541 void cgraph_remove_edge (struct cgraph_edge *);
542 void cgraph_remove_node (struct cgraph_node *);
543 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
544 void cgraph_release_function_body (struct cgraph_node *);
545 void cgraph_node_remove_callees (struct cgraph_node *node);
546 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
547 struct cgraph_node *,
548 gimple, gcov_type, int, int);
549 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple, int,
550 gcov_type, int, int);
551 struct cgraph_node * cgraph_get_node (const_tree);
552 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
553 struct cgraph_node * cgraph_node (tree);
554 struct cgraph_node * cgraph_same_body_alias (tree, tree);
555 struct cgraph_node * cgraph_add_thunk (tree, tree, bool, HOST_WIDE_INT,
556 HOST_WIDE_INT, tree, tree);
557 void cgraph_remove_same_body_alias (struct cgraph_node *);
558 struct cgraph_node *cgraph_node_for_asm (tree);
559 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
560 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
561 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
562 void cgraph_create_edge_including_clones (struct cgraph_node *,
563 struct cgraph_node *,
564 gimple, gimple, gcov_type, int, int,
565 cgraph_inline_failed_t);
566 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
567 struct cgraph_local_info *cgraph_local_info (tree);
568 struct cgraph_global_info *cgraph_global_info (tree);
569 struct cgraph_rtl_info *cgraph_rtl_info (tree);
570 const char * cgraph_node_name (struct cgraph_node *);
571 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
572 struct cgraph_node *, gimple,
573 unsigned, gcov_type, int, int, bool);
574 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type, int,
575 int, bool, VEC(cgraph_edge_p,heap) *);
577 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
578 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
580 struct cgraph_asm_node *cgraph_add_asm_node (tree);
582 bool cgraph_function_possibly_inlined_p (tree);
583 void cgraph_unnest_node (struct cgraph_node *);
585 enum availability cgraph_function_body_availability (struct cgraph_node *);
586 void cgraph_add_new_function (tree, bool);
587 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
588 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
589 VEC(cgraph_edge_p,heap)*,
590 VEC(ipa_replace_map_p,gc)* tree_map,
591 bitmap args_to_skip,
592 const char *clone_name);
594 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
595 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
596 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
597 tree clone_function_name (tree decl, const char *);
598 bool cgraph_node_cannot_return (struct cgraph_node *);
599 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
600 bool cgraph_will_be_removed_from_program_if_no_direct_calls
601 (struct cgraph_node *node);
602 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
603 (struct cgraph_node *node);
604 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution resolution);
605 bool cgraph_used_from_object_file_p (struct cgraph_node *node);
606 bool varpool_used_from_object_file_p (struct varpool_node *node);
608 /* In cgraphunit.c */
609 extern FILE *cgraph_dump_file;
610 void cgraph_finalize_function (tree, bool);
611 void cgraph_mark_if_needed (tree);
612 void cgraph_finalize_compilation_unit (void);
613 void cgraph_optimize (void);
614 void cgraph_mark_needed_node (struct cgraph_node *);
615 void cgraph_mark_address_taken_node (struct cgraph_node *);
616 void cgraph_mark_reachable_node (struct cgraph_node *);
617 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
618 bool cgraph_preserve_function_body_p (tree);
619 void verify_cgraph (void);
620 void verify_cgraph_node (struct cgraph_node *);
621 void cgraph_build_static_cdtor (char which, tree body, int priority);
622 void cgraph_reset_static_var_maps (void);
623 void init_cgraph (void);
624 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
625 VEC(cgraph_edge_p,heap)*,
626 VEC(ipa_replace_map_p,gc)*,
627 bitmap, bitmap, basic_block,
628 const char *);
629 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
630 bitmap, basic_block);
631 struct cgraph_node *save_inline_function_body (struct cgraph_node *);
632 void record_references_in_initializer (tree, bool);
633 bool cgraph_process_new_functions (void);
635 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
637 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
638 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
639 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
640 void *);
641 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
642 void *);
643 struct cgraph_edge_hook_list;
644 struct cgraph_node_hook_list;
645 struct cgraph_2edge_hook_list;
646 struct cgraph_2node_hook_list;
647 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
648 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
649 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
650 void *);
651 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
652 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
653 void *);
654 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
655 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
656 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
657 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
658 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
659 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
660 void cgraph_materialize_all_clones (void);
661 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
662 bool cgraph_propagate_frequency (struct cgraph_node *node);
663 /* In cgraphbuild.c */
664 unsigned int rebuild_cgraph_edges (void);
665 void cgraph_rebuild_references (void);
666 void reset_inline_failed (struct cgraph_node *);
667 int compute_call_stmt_bb_frequency (tree, basic_block bb);
669 /* In ipa.c */
670 bool cgraph_remove_unreachable_nodes (bool, FILE *);
671 int cgraph_postorder (struct cgraph_node **);
672 cgraph_node_set cgraph_node_set_new (void);
673 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
674 struct cgraph_node *);
675 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
676 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
677 void dump_cgraph_node_set (FILE *, cgraph_node_set);
678 void debug_cgraph_node_set (cgraph_node_set);
680 varpool_node_set varpool_node_set_new (void);
681 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
682 struct varpool_node *);
683 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
684 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
685 void dump_varpool_node_set (FILE *, varpool_node_set);
686 void debug_varpool_node_set (varpool_node_set);
687 void ipa_discover_readonly_nonaddressable_vars (void);
688 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
690 /* In predict.c */
691 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
693 /* In varpool.c */
694 extern GTY(()) struct varpool_node *varpool_nodes_queue;
695 extern GTY(()) struct varpool_node *varpool_nodes;
697 struct varpool_node *varpool_node (tree);
698 struct varpool_node *varpool_node_for_asm (tree asmname);
699 void varpool_mark_needed_node (struct varpool_node *);
700 void debug_varpool (void);
701 void dump_varpool (FILE *);
702 void dump_varpool_node (FILE *, struct varpool_node *);
704 void varpool_finalize_decl (tree);
705 bool decide_is_variable_needed (struct varpool_node *, tree);
706 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
707 void cgraph_make_decl_local (tree);
708 void cgraph_make_node_local (struct cgraph_node *);
709 bool cgraph_node_can_be_local_p (struct cgraph_node *);
712 struct varpool_node * varpool_get_node (const_tree decl);
713 void varpool_remove_node (struct varpool_node *node);
714 bool varpool_assemble_pending_decls (void);
715 bool varpool_assemble_decl (struct varpool_node *node);
716 bool varpool_analyze_pending_decls (void);
717 void varpool_remove_unreferenced_decls (void);
718 void varpool_empty_needed_queue (void);
719 struct varpool_node * varpool_extra_name_alias (tree, tree);
720 const char * varpool_node_name (struct varpool_node *node);
721 void varpool_reset_queue (void);
722 bool const_value_known_p (tree);
724 /* Walk all reachable static variables. */
725 #define FOR_EACH_STATIC_VARIABLE(node) \
726 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
728 /* Return first reachable static variable with initializer. */
729 static inline struct varpool_node *
730 varpool_first_static_initializer (void)
732 struct varpool_node *node;
733 for (node = varpool_nodes_queue; node; node = node->next_needed)
735 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
736 if (DECL_INITIAL (node->decl))
737 return node;
739 return NULL;
742 /* Return next reachable static variable with initializer after NODE. */
743 static inline struct varpool_node *
744 varpool_next_static_initializer (struct varpool_node *node)
746 for (node = node->next_needed; node; node = node->next_needed)
748 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
749 if (DECL_INITIAL (node->decl))
750 return node;
752 return NULL;
755 /* Walk all static variables with initializer set. */
756 #define FOR_EACH_STATIC_INITIALIZER(node) \
757 for ((node) = varpool_first_static_initializer (); (node); \
758 (node) = varpool_next_static_initializer (node))
760 /* In ipa-inline.c */
761 void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
762 unsigned int compute_inline_parameters (struct cgraph_node *);
765 /* Create a new static variable of type TYPE. */
766 tree add_new_static_var (tree type);
768 /* Return true if iterator CSI points to nothing. */
769 static inline bool
770 csi_end_p (cgraph_node_set_iterator csi)
772 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
775 /* Advance iterator CSI. */
776 static inline void
777 csi_next (cgraph_node_set_iterator *csi)
779 csi->index++;
782 /* Return the node pointed to by CSI. */
783 static inline struct cgraph_node *
784 csi_node (cgraph_node_set_iterator csi)
786 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
789 /* Return an iterator to the first node in SET. */
790 static inline cgraph_node_set_iterator
791 csi_start (cgraph_node_set set)
793 cgraph_node_set_iterator csi;
795 csi.set = set;
796 csi.index = 0;
797 return csi;
800 /* Return true if SET contains NODE. */
801 static inline bool
802 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
804 cgraph_node_set_iterator csi;
805 csi = cgraph_node_set_find (set, node);
806 return !csi_end_p (csi);
809 /* Return number of nodes in SET. */
810 static inline size_t
811 cgraph_node_set_size (cgraph_node_set set)
813 return htab_elements (set->hashtab);
816 /* Return true if iterator VSI points to nothing. */
817 static inline bool
818 vsi_end_p (varpool_node_set_iterator vsi)
820 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
823 /* Advance iterator VSI. */
824 static inline void
825 vsi_next (varpool_node_set_iterator *vsi)
827 vsi->index++;
830 /* Return the node pointed to by VSI. */
831 static inline struct varpool_node *
832 vsi_node (varpool_node_set_iterator vsi)
834 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
837 /* Return an iterator to the first node in SET. */
838 static inline varpool_node_set_iterator
839 vsi_start (varpool_node_set set)
841 varpool_node_set_iterator vsi;
843 vsi.set = set;
844 vsi.index = 0;
845 return vsi;
848 /* Return true if SET contains NODE. */
849 static inline bool
850 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
852 varpool_node_set_iterator vsi;
853 vsi = varpool_node_set_find (set, node);
854 return !vsi_end_p (vsi);
857 /* Return number of nodes in SET. */
858 static inline size_t
859 varpool_node_set_size (varpool_node_set set)
861 return htab_elements (set->hashtab);
864 /* Uniquize all constants that appear in memory.
865 Each constant in memory thus far output is recorded
866 in `const_desc_table'. */
868 struct GTY(()) constant_descriptor_tree {
869 /* A MEM for the constant. */
870 rtx rtl;
872 /* The value of the constant. */
873 tree value;
875 /* Hash of value. Computing the hash from value each time
876 hashfn is called can't work properly, as that means recursive
877 use of the hash table during hash table expansion. */
878 hashval_t hash;
881 /* Return true if set is nonempty. */
882 static inline bool
883 cgraph_node_set_nonempty_p (cgraph_node_set set)
885 return !VEC_empty (cgraph_node_ptr, set->nodes);
888 /* Return true if set is nonempty. */
889 static inline bool
890 varpool_node_set_nonempty_p (varpool_node_set set)
892 return !VEC_empty (varpool_node_ptr, set->nodes);
895 /* Return true when function NODE is only called directly.
896 i.e. it is not externally visible, address was not taken and
897 it is not used in any other non-standard way. */
899 static inline bool
900 cgraph_only_called_directly_p (struct cgraph_node *node)
902 gcc_assert (!node->global.inlined_to);
903 return (!node->needed && !node->address_taken
904 && !node->reachable_from_other_partition
905 && !DECL_STATIC_CONSTRUCTOR (node->decl)
906 && !DECL_STATIC_DESTRUCTOR (node->decl)
907 && !node->local.externally_visible);
910 /* Return true when function NODE can be removed from callgraph
911 if all direct calls are eliminated. */
913 static inline bool
914 cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node)
916 /* Extern inlines can always go, we will use the external definition. */
917 if (DECL_EXTERNAL (node->decl))
918 return true;
919 return !node->address_taken && cgraph_can_remove_if_no_direct_calls_and_refs_p (node);
922 /* Return true when function NODE can be removed from callgraph
923 if all direct calls are eliminated. */
925 static inline bool
926 varpool_can_remove_if_no_refs (struct varpool_node *node)
928 return (!node->force_output && !node->used_from_other_partition
929 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
930 || DECL_ARTIFICIAL (node->decl))
931 && (DECL_COMDAT (node->decl) || !node->externally_visible));
934 /* Return true when all references to VNODE must be visible in ipa_ref_list.
935 i.e. if the variable is not externally visible or not used in some magic
936 way (asm statement or such).
937 The magic uses are all sumarized in force_output flag. */
939 static inline bool
940 varpool_all_refs_explicit_p (struct varpool_node *vnode)
942 return (!vnode->externally_visible
943 && !vnode->used_from_other_partition
944 && !vnode->force_output);
947 /* Constant pool accessor function. */
948 htab_t constant_pool_htab (void);
950 /* FIXME: inappropriate dependency of cgraph on IPA. */
951 #include "ipa-ref-inline.h"
953 #endif /* GCC_CGRAPH_H */