cgraph.c (cgraph_for_node_thunks_and_aliases, [...]): Fix thinko in recursive walking.
[gcc.git] / gcc / cgraph.h
1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
5
6 This file is part of GCC.
7
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.
12
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.
17
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/>. */
21
22 #ifndef GCC_CGRAPH_H
23 #define GCC_CGRAPH_H
24
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. */
31
32 enum availability
33 {
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
52 };
53
54 /* This is the information that is put into the cgraph local structure
55 to recover a function. */
56 struct lto_file_decl_data;
57
58 extern const char * const cgraph_availability_names[];
59 extern const char * const ld_plugin_symbol_resolution_names[];
60
61 /* Information about thunk, used only for same body aliases. */
62
63 struct GTY(()) cgraph_thunk_info {
64 /* Information about the thunk. */
65 HOST_WIDE_INT fixed_offset;
66 HOST_WIDE_INT virtual_value;
67 tree alias;
68 bool this_adjusting;
69 bool virtual_offset_p;
70 /* Set to true when alias node is thunk. */
71 bool thunk_p;
72 };
73
74 /* Information about the function collected locally.
75 Available after function is analyzed. */
76
77 struct GTY(()) cgraph_local_info {
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data * lto_file_data;
80
81 /* Set when function function is visible in current compilation unit only
82 and its address is never taken. */
83 unsigned local : 1;
84
85 /* Set when function is visible by other units. */
86 unsigned externally_visible : 1;
87
88 /* Set once it has been finalized so we consider it to be output. */
89 unsigned finalized : 1;
90
91 /* False when function calling convention and signature can not be changed.
92 This is the case when __builtin_apply_args is used. */
93 unsigned can_change_signature : 1;
94
95 /* True when the function has been originally extern inline, but it is
96 redefined now. */
97 unsigned redefined_extern_inline : 1;
98 };
99
100 /* Information about the function that needs to be computed globally
101 once compilation is finished. Available only with -funit-at-a-time. */
102
103 struct GTY(()) cgraph_global_info {
104 /* For inline clones this points to the function they will be
105 inlined into. */
106 struct cgraph_node *inlined_to;
107 };
108
109 /* Information about the function that is propagated by the RTL backend.
110 Available only for functions that has been already assembled. */
111
112 struct GTY(()) cgraph_rtl_info {
113 unsigned int preferred_incoming_stack_boundary;
114 };
115
116 /* Represent which DECL tree (or reference to such tree)
117 will be replaced by another tree while versioning. */
118 struct GTY(()) ipa_replace_map
119 {
120 /* The tree that will be replaced. */
121 tree old_tree;
122 /* The new (replacing) tree. */
123 tree new_tree;
124 /* Parameter number to replace, when old_tree is NULL. */
125 int parm_num;
126 /* True when a substitution should be done, false otherwise. */
127 bool replace_p;
128 /* True when we replace a reference to old_tree. */
129 bool ref_p;
130 };
131 typedef struct ipa_replace_map *ipa_replace_map_p;
132 DEF_VEC_P(ipa_replace_map_p);
133 DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
134
135 struct GTY(()) cgraph_clone_info
136 {
137 VEC(ipa_replace_map_p,gc)* tree_map;
138 bitmap args_to_skip;
139 bitmap combined_args_to_skip;
140 };
141
142
143 /* The cgraph data structure.
144 Each function decl has assigned cgraph_node listing callees and callers. */
145
146 struct GTY((chain_next ("%h.next"), chain_prev ("%h.previous"))) cgraph_node {
147 tree decl;
148 struct cgraph_edge *callees;
149 struct cgraph_edge *callers;
150 struct cgraph_node *next;
151 struct cgraph_node *previous;
152 /* List of edges representing indirect calls with a yet undetermined
153 callee. */
154 struct cgraph_edge *indirect_calls;
155 /* For nested functions points to function the node is nested in. */
156 struct cgraph_node *origin;
157 /* Points to first nested function, if any. */
158 struct cgraph_node *nested;
159 /* Pointer to the next function with same origin, if any. */
160 struct cgraph_node *next_nested;
161 /* Pointer to the next function in cgraph_nodes_queue. */
162 struct cgraph_node *next_needed;
163 /* Pointer to the next clone. */
164 struct cgraph_node *next_sibling_clone;
165 struct cgraph_node *prev_sibling_clone;
166 struct cgraph_node *clones;
167 struct cgraph_node *clone_of;
168 /* Circular list of nodes in the same comdat group if non-NULL. */
169 struct cgraph_node *same_comdat_group;
170 /* For functions with many calls sites it holds map from call expression
171 to the edge to speed up cgraph_edge function. */
172 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
173 /* Declaration node used to be clone of. */
174 tree former_clone_of;
175
176 PTR GTY ((skip)) aux;
177
178 /* Interprocedural passes scheduled to have their transform functions
179 applied next time we execute local pass on them. We maintain it
180 per-function in order to allow IPA passes to introduce new functions. */
181 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
182
183 struct ipa_ref_list ref_list;
184 struct cgraph_local_info local;
185 struct cgraph_global_info global;
186 struct cgraph_rtl_info rtl;
187 struct cgraph_clone_info clone;
188 struct cgraph_thunk_info thunk;
189
190 /* Expected number of executions: calculated in profile.c. */
191 gcov_type count;
192 /* How to scale counts at materialization time; used to merge
193 LTO units with different number of profile runs. */
194 int count_materialization_scale;
195 /* Unique id of the node. */
196 int uid;
197 /* Ordering of all cgraph nodes. */
198 int order;
199
200 enum ld_plugin_symbol_resolution resolution;
201
202 /* Set when function must be output for some reason. The primary
203 use of this flag is to mark functions needed to be output for
204 non-standard reason. Functions that are externally visible
205 or reachable from functions needed to be output are marked
206 by specialized flags. */
207 unsigned needed : 1;
208 /* Set when function has address taken.
209 In current implementation it imply needed flag. */
210 unsigned address_taken : 1;
211 /* Set when decl is an abstract function pointed to by the
212 ABSTRACT_DECL_ORIGIN of a reachable function. */
213 unsigned abstract_and_needed : 1;
214 /* Set when function is reachable by call from other function
215 that is either reachable or needed.
216 This flag is computed at original cgraph construction and then
217 updated in cgraph_remove_unreachable_nodes. Note that after
218 cgraph_remove_unreachable_nodes cgraph still can contain unreachable
219 nodes when they are needed for virtual clone instantiation. */
220 unsigned reachable : 1;
221 /* Set when function is reachable by call from other LTRANS partition. */
222 unsigned reachable_from_other_partition : 1;
223 /* Set once the function is lowered (i.e. its CFG is built). */
224 unsigned lowered : 1;
225 /* Set once the function has been instantiated and its callee
226 lists created. */
227 unsigned analyzed : 1;
228 /* Set when function is available in the other LTRANS partition.
229 During WPA output it is used to mark nodes that are present in
230 multiple partitions. */
231 unsigned in_other_partition : 1;
232 /* Set when function is scheduled to be processed by local passes. */
233 unsigned process : 1;
234 /* Set for aliases once they got through assemble_alias. */
235 unsigned alias : 1;
236 /* Set for aliases created as C++ same body aliases. */
237 unsigned same_body_alias : 1;
238 /* How commonly executed the node is. Initialized during branch
239 probabilities pass. */
240 ENUM_BITFIELD (node_frequency) frequency : 2;
241 /* True when function can only be called at startup (from static ctor). */
242 unsigned only_called_at_startup : 1;
243 /* True when function can only be called at startup (from static dtor). */
244 unsigned only_called_at_exit : 1;
245 };
246
247 typedef struct cgraph_node *cgraph_node_ptr;
248
249 DEF_VEC_P(cgraph_node_ptr);
250 DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
251 DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
252
253 /* A cgraph node set is a collection of cgraph nodes. A cgraph node
254 can appear in multiple sets. */
255 struct cgraph_node_set_def
256 {
257 struct pointer_map_t *map;
258 VEC(cgraph_node_ptr, heap) *nodes;
259 };
260
261 typedef struct varpool_node *varpool_node_ptr;
262
263 DEF_VEC_P(varpool_node_ptr);
264 DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
265 DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
266
267 /* A varpool node set is a collection of varpool nodes. A varpool node
268 can appear in multiple sets. */
269 struct varpool_node_set_def
270 {
271 struct pointer_map_t * map;
272 VEC(varpool_node_ptr, heap) *nodes;
273 };
274
275 typedef struct cgraph_node_set_def *cgraph_node_set;
276
277 DEF_VEC_P(cgraph_node_set);
278 DEF_VEC_ALLOC_P(cgraph_node_set,gc);
279 DEF_VEC_ALLOC_P(cgraph_node_set,heap);
280
281 typedef struct varpool_node_set_def *varpool_node_set;
282
283 DEF_VEC_P(varpool_node_set);
284 DEF_VEC_ALLOC_P(varpool_node_set,gc);
285 DEF_VEC_ALLOC_P(varpool_node_set,heap);
286
287 /* Iterator structure for cgraph node sets. */
288 typedef struct
289 {
290 cgraph_node_set set;
291 unsigned index;
292 } cgraph_node_set_iterator;
293
294 /* Iterator structure for varpool node sets. */
295 typedef struct
296 {
297 varpool_node_set set;
298 unsigned index;
299 } varpool_node_set_iterator;
300
301 #define DEFCIFCODE(code, string) CIF_ ## code,
302 /* Reasons for inlining failures. */
303 typedef enum cgraph_inline_failed_enum {
304 #include "cif-code.def"
305 CIF_N_REASONS
306 } cgraph_inline_failed_t;
307
308 /* Structure containing additional information about an indirect call. */
309
310 struct GTY(()) cgraph_indirect_call_info
311 {
312 /* Offset accumulated from ancestor jump functions of inlined call graph
313 edges. */
314 HOST_WIDE_INT anc_offset;
315 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
316 HOST_WIDE_INT otr_token;
317 /* Delta by which must be added to this parameter to compensate for a skipped
318 this adjusting thunk. */
319 HOST_WIDE_INT thunk_delta;
320 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
321 tree otr_type;
322 /* Index of the parameter that is called. */
323 int param_index;
324 /* ECF flags determined from the caller. */
325 int ecf_flags;
326
327 /* Set when the call is a virtual call with the parameter being the
328 associated object pointer rather than a simple direct call. */
329 unsigned polymorphic : 1;
330 };
331
332 struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
333 /* Expected number of executions: calculated in profile.c. */
334 gcov_type count;
335 struct cgraph_node *caller;
336 struct cgraph_node *callee;
337 struct cgraph_edge *prev_caller;
338 struct cgraph_edge *next_caller;
339 struct cgraph_edge *prev_callee;
340 struct cgraph_edge *next_callee;
341 gimple call_stmt;
342 /* Additional information about an indirect call. Not cleared when an edge
343 becomes direct. */
344 struct cgraph_indirect_call_info *indirect_info;
345 PTR GTY ((skip (""))) aux;
346 /* When equal to CIF_OK, inline this call. Otherwise, points to the
347 explanation why function was not inlined. */
348 cgraph_inline_failed_t inline_failed;
349 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
350 when the function is serialized in. */
351 unsigned int lto_stmt_uid;
352 /* Expected frequency of executions within the function.
353 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
354 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
355 int frequency;
356 /* Unique id of the edge. */
357 int uid;
358 /* Whether this edge was made direct by indirect inlining. */
359 unsigned int indirect_inlining_edge : 1;
360 /* Whether this edge describes an indirect call with an undetermined
361 callee. */
362 unsigned int indirect_unknown_callee : 1;
363 /* Whether this edge is still a dangling */
364 /* True if the corresponding CALL stmt cannot be inlined. */
365 unsigned int call_stmt_cannot_inline_p : 1;
366 /* Can this call throw externally? */
367 unsigned int can_throw_external : 1;
368 };
369
370 #define CGRAPH_FREQ_BASE 1000
371 #define CGRAPH_FREQ_MAX 100000
372
373 typedef struct cgraph_edge *cgraph_edge_p;
374
375 DEF_VEC_P(cgraph_edge_p);
376 DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
377
378 /* The varpool data structure.
379 Each static variable decl has assigned varpool_node. */
380
381 struct GTY((chain_next ("%h.next"), chain_prev ("%h.prev"))) varpool_node {
382 tree decl;
383 /* Pointer to the next function in varpool_nodes. */
384 struct varpool_node *next, *prev;
385 /* Pointer to the next function in varpool_nodes_queue. */
386 struct varpool_node *next_needed, *prev_needed;
387 /* For normal nodes a pointer to the first extra name alias. For alias
388 nodes a pointer to the normal node. */
389 struct varpool_node *extra_name;
390 /* Circular list of nodes in the same comdat group if non-NULL. */
391 struct varpool_node *same_comdat_group;
392 struct ipa_ref_list ref_list;
393 /* File stream where this node is being written to. */
394 struct lto_file_decl_data * lto_file_data;
395 PTR GTY ((skip)) aux;
396 /* Ordering of all cgraph nodes. */
397 int order;
398 enum ld_plugin_symbol_resolution resolution;
399
400 /* Set when function must be output - it is externally visible
401 or its address is taken. */
402 unsigned needed : 1;
403 /* Needed variables might become dead by optimization. This flag
404 forces the variable to be output even if it appears dead otherwise. */
405 unsigned force_output : 1;
406 /* Set once the variable has been instantiated and its callee
407 lists created. */
408 unsigned analyzed : 1;
409 /* Set once it has been finalized so we consider it to be output. */
410 unsigned finalized : 1;
411 /* Set when variable is scheduled to be assembled. */
412 unsigned output : 1;
413 /* Set when function is visible by other units. */
414 unsigned externally_visible : 1;
415 /* Set for aliases once they got through assemble_alias. Also set for
416 extra name aliases in varpool_extra_name_alias. */
417 unsigned alias : 1;
418 /* Set when variable is used from other LTRANS partition. */
419 unsigned used_from_other_partition : 1;
420 /* Set when variable is available in the other LTRANS partition.
421 During WPA output it is used to mark nodes that are present in
422 multiple partitions. */
423 unsigned in_other_partition : 1;
424 };
425
426 /* Every top level asm statement is put into a cgraph_asm_node. */
427
428 struct GTY(()) cgraph_asm_node {
429 /* Next asm node. */
430 struct cgraph_asm_node *next;
431 /* String for this asm node. */
432 tree asm_str;
433 /* Ordering of all cgraph nodes. */
434 int order;
435 };
436
437 extern GTY(()) struct cgraph_node *cgraph_nodes;
438 extern GTY(()) int cgraph_n_nodes;
439 extern GTY(()) int cgraph_max_uid;
440 extern GTY(()) int cgraph_edge_max_uid;
441 extern bool cgraph_global_info_ready;
442 enum cgraph_state
443 {
444 /* Callgraph is being constructed. It is safe to add new functions. */
445 CGRAPH_STATE_CONSTRUCTION,
446 /* Callgraph is built and IPA passes are being run. */
447 CGRAPH_STATE_IPA,
448 /* Callgraph is built and all functions are transformed to SSA form. */
449 CGRAPH_STATE_IPA_SSA,
450 /* Functions are now ordered and being passed to RTL expanders. */
451 CGRAPH_STATE_EXPANSION,
452 /* All cgraph expansion is done. */
453 CGRAPH_STATE_FINISHED
454 };
455 extern enum cgraph_state cgraph_state;
456 extern bool cgraph_function_flags_ready;
457 extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
458 extern GTY(()) struct cgraph_node *cgraph_new_nodes;
459
460 extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
461 extern GTY(()) int cgraph_order;
462 extern bool same_body_aliases_done;
463
464 /* In cgraph.c */
465 void dump_cgraph (FILE *);
466 void debug_cgraph (void);
467 void dump_cgraph_node (FILE *, struct cgraph_node *);
468 void debug_cgraph_node (struct cgraph_node *);
469 void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
470 void cgraph_remove_edge (struct cgraph_edge *);
471 void cgraph_remove_node (struct cgraph_node *);
472 void cgraph_remove_node_and_inline_clones (struct cgraph_node *);
473 void cgraph_release_function_body (struct cgraph_node *);
474 void cgraph_node_remove_callees (struct cgraph_node *node);
475 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
476 struct cgraph_node *,
477 gimple, gcov_type, int);
478 struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
479 int, gcov_type, int);
480 struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
481 struct cgraph_node * cgraph_get_node (const_tree);
482 struct cgraph_node * cgraph_get_node_or_alias (const_tree);
483 struct cgraph_node * cgraph_create_node (tree);
484 struct cgraph_node * cgraph_get_create_node (tree);
485 struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
486 struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
487 HOST_WIDE_INT, tree, tree);
488 struct cgraph_node *cgraph_node_for_asm (tree);
489 struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
490 void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
491 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
492 void cgraph_create_edge_including_clones (struct cgraph_node *,
493 struct cgraph_node *,
494 gimple, gimple, gcov_type, int,
495 cgraph_inline_failed_t);
496 void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
497 struct cgraph_local_info *cgraph_local_info (tree);
498 struct cgraph_global_info *cgraph_global_info (tree);
499 struct cgraph_rtl_info *cgraph_rtl_info (tree);
500 const char * cgraph_node_name (struct cgraph_node *);
501 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
502 struct cgraph_node *, gimple,
503 unsigned, gcov_type, int, bool);
504 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
505 int, bool, VEC(cgraph_edge_p,heap) *,
506 bool);
507 struct cgraph_node *cgraph_create_function_alias (tree, tree);
508
509 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
510 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *,
511 HOST_WIDE_INT);
512 bool cgraph_only_called_directly_p (struct cgraph_node *);
513
514 struct cgraph_asm_node *cgraph_add_asm_node (tree);
515
516 bool cgraph_function_possibly_inlined_p (tree);
517 void cgraph_unnest_node (struct cgraph_node *);
518
519 enum availability cgraph_function_body_availability (struct cgraph_node *);
520 void cgraph_add_new_function (tree, bool);
521 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
522 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
523 VEC(cgraph_edge_p,heap)*,
524 VEC(ipa_replace_map_p,gc)* tree_map,
525 bitmap args_to_skip,
526 const char *clone_name);
527
528 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
529 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
530 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
531 tree clone_function_name (tree decl, const char *);
532 bool cgraph_node_cannot_return (struct cgraph_node *);
533 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
534 bool cgraph_will_be_removed_from_program_if_no_direct_calls
535 (struct cgraph_node *node);
536 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
537 (struct cgraph_node *node);
538 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
539 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
540 bool cgraph_used_from_object_file_p (struct cgraph_node *);
541 bool varpool_used_from_object_file_p (struct varpool_node *);
542 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
543 bool (*) (struct cgraph_node *, void *),
544 void *,
545 bool);
546 bool cgraph_for_node_and_aliases (struct cgraph_node *,
547 bool (*) (struct cgraph_node *, void *),
548 void *, bool);
549 VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
550
551
552 /* In cgraphunit.c */
553 extern FILE *cgraph_dump_file;
554 void cgraph_finalize_function (tree, bool);
555 void cgraph_mark_if_needed (tree);
556 void cgraph_analyze_function (struct cgraph_node *);
557 void cgraph_finalize_compilation_unit (void);
558 void cgraph_optimize (void);
559 void cgraph_mark_needed_node (struct cgraph_node *);
560 void cgraph_mark_address_taken_node (struct cgraph_node *);
561 void cgraph_mark_reachable_node (struct cgraph_node *);
562 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
563 bool cgraph_preserve_function_body_p (struct cgraph_node *);
564 void verify_cgraph (void);
565 void verify_cgraph_node (struct cgraph_node *);
566 void cgraph_build_static_cdtor (char which, tree body, int priority);
567 void cgraph_reset_static_var_maps (void);
568 void init_cgraph (void);
569 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
570 VEC(cgraph_edge_p,heap)*,
571 VEC(ipa_replace_map_p,gc)*,
572 bitmap, bitmap, basic_block,
573 const char *);
574 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
575 bitmap, basic_block);
576 void record_references_in_initializer (tree, bool);
577 bool cgraph_process_new_functions (void);
578 void cgraph_process_same_body_aliases (void);
579
580 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
581
582 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
583 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
584 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
585 void *);
586 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
587 void *);
588 struct cgraph_edge_hook_list;
589 struct cgraph_node_hook_list;
590 struct cgraph_2edge_hook_list;
591 struct cgraph_2node_hook_list;
592 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
593 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
594 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
595 void *);
596 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
597 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
598 void *);
599 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
600 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
601 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
602 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
603 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
604 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
605 void cgraph_materialize_all_clones (void);
606 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
607 bool cgraph_propagate_frequency (struct cgraph_node *node);
608 /* In cgraphbuild.c */
609 unsigned int rebuild_cgraph_edges (void);
610 void cgraph_rebuild_references (void);
611 void reset_inline_failed (struct cgraph_node *);
612 int compute_call_stmt_bb_frequency (tree, basic_block bb);
613
614 /* In ipa.c */
615 bool cgraph_remove_unreachable_nodes (bool, FILE *);
616 cgraph_node_set cgraph_node_set_new (void);
617 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
618 struct cgraph_node *);
619 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
620 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
621 void dump_cgraph_node_set (FILE *, cgraph_node_set);
622 void debug_cgraph_node_set (cgraph_node_set);
623 void free_cgraph_node_set (cgraph_node_set);
624
625 varpool_node_set varpool_node_set_new (void);
626 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
627 struct varpool_node *);
628 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
629 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
630 void dump_varpool_node_set (FILE *, varpool_node_set);
631 void debug_varpool_node_set (varpool_node_set);
632 void free_varpool_node_set (varpool_node_set);
633 void ipa_discover_readonly_nonaddressable_vars (void);
634 bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
635
636 /* In predict.c */
637 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
638 bool cgraph_optimize_for_size_p (struct cgraph_node *);
639
640 /* In varpool.c */
641 extern GTY(()) struct varpool_node *varpool_nodes_queue;
642 extern GTY(()) struct varpool_node *varpool_nodes;
643
644 struct varpool_node *varpool_node (tree);
645 struct varpool_node *varpool_node_for_asm (tree asmname);
646 void varpool_mark_needed_node (struct varpool_node *);
647 void debug_varpool (void);
648 void dump_varpool (FILE *);
649 void dump_varpool_node (FILE *, struct varpool_node *);
650
651 void varpool_finalize_decl (tree);
652 bool decide_is_variable_needed (struct varpool_node *, tree);
653 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
654 void cgraph_make_decl_local (tree);
655 void cgraph_make_node_local (struct cgraph_node *);
656 bool cgraph_node_can_be_local_p (struct cgraph_node *);
657
658
659 struct varpool_node * varpool_get_node (const_tree decl);
660 void varpool_remove_node (struct varpool_node *node);
661 void varpool_finalize_named_section_flags (struct varpool_node *node);
662 bool varpool_assemble_pending_decls (void);
663 bool varpool_assemble_decl (struct varpool_node *node);
664 bool varpool_analyze_pending_decls (void);
665 void varpool_remove_unreferenced_decls (void);
666 void varpool_empty_needed_queue (void);
667 struct varpool_node * varpool_extra_name_alias (tree, tree);
668 const char * varpool_node_name (struct varpool_node *node);
669 void varpool_reset_queue (void);
670 bool const_value_known_p (tree);
671
672 /* Walk all reachable static variables. */
673 #define FOR_EACH_STATIC_VARIABLE(node) \
674 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
675
676 /* Return first reachable static variable with initializer. */
677 static inline struct varpool_node *
678 varpool_first_static_initializer (void)
679 {
680 struct varpool_node *node;
681 for (node = varpool_nodes_queue; node; node = node->next_needed)
682 {
683 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
684 if (DECL_INITIAL (node->decl))
685 return node;
686 }
687 return NULL;
688 }
689
690 /* Return next reachable static variable with initializer after NODE. */
691 static inline struct varpool_node *
692 varpool_next_static_initializer (struct varpool_node *node)
693 {
694 for (node = node->next_needed; node; node = node->next_needed)
695 {
696 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
697 if (DECL_INITIAL (node->decl))
698 return node;
699 }
700 return NULL;
701 }
702
703 /* Walk all static variables with initializer set. */
704 #define FOR_EACH_STATIC_INITIALIZER(node) \
705 for ((node) = varpool_first_static_initializer (); (node); \
706 (node) = varpool_next_static_initializer (node))
707
708 /* Return first function with body defined. */
709 static inline struct cgraph_node *
710 cgraph_first_defined_function (void)
711 {
712 struct cgraph_node *node;
713 for (node = cgraph_nodes; node; node = node->next)
714 {
715 if (node->analyzed)
716 return node;
717 }
718 return NULL;
719 }
720
721 /* Return next reachable static variable with initializer after NODE. */
722 static inline struct cgraph_node *
723 cgraph_next_defined_function (struct cgraph_node *node)
724 {
725 for (node = node->next; node; node = node->next)
726 {
727 if (node->analyzed)
728 return node;
729 }
730 return NULL;
731 }
732
733 /* Walk all functions with body defined. */
734 #define FOR_EACH_DEFINED_FUNCTION(node) \
735 for ((node) = cgraph_first_defined_function (); (node); \
736 (node) = cgraph_next_defined_function (node))
737
738
739 /* Return true when NODE is a function with Gimple body defined
740 in current unit. Functions can also be define externally or they
741 can be thunks with no Gimple representation.
742
743 Note that at WPA stage, the function body may not be present in memory. */
744
745 static inline bool
746 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
747 {
748 return node->analyzed && !node->thunk.thunk_p && !node->alias;
749 }
750
751 /* Return first function with body defined. */
752 static inline struct cgraph_node *
753 cgraph_first_function_with_gimple_body (void)
754 {
755 struct cgraph_node *node;
756 for (node = cgraph_nodes; node; node = node->next)
757 {
758 if (cgraph_function_with_gimple_body_p (node))
759 return node;
760 }
761 return NULL;
762 }
763
764 /* Return next reachable static variable with initializer after NODE. */
765 static inline struct cgraph_node *
766 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
767 {
768 for (node = node->next; node; node = node->next)
769 {
770 if (cgraph_function_with_gimple_body_p (node))
771 return node;
772 }
773 return NULL;
774 }
775
776 /* Walk all functions with body defined. */
777 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
778 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
779 (node) = cgraph_next_function_with_gimple_body (node))
780
781 /* Create a new static variable of type TYPE. */
782 tree add_new_static_var (tree type);
783
784 /* Return true if iterator CSI points to nothing. */
785 static inline bool
786 csi_end_p (cgraph_node_set_iterator csi)
787 {
788 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
789 }
790
791 /* Advance iterator CSI. */
792 static inline void
793 csi_next (cgraph_node_set_iterator *csi)
794 {
795 csi->index++;
796 }
797
798 /* Return the node pointed to by CSI. */
799 static inline struct cgraph_node *
800 csi_node (cgraph_node_set_iterator csi)
801 {
802 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
803 }
804
805 /* Return an iterator to the first node in SET. */
806 static inline cgraph_node_set_iterator
807 csi_start (cgraph_node_set set)
808 {
809 cgraph_node_set_iterator csi;
810
811 csi.set = set;
812 csi.index = 0;
813 return csi;
814 }
815
816 /* Return true if SET contains NODE. */
817 static inline bool
818 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
819 {
820 cgraph_node_set_iterator csi;
821 csi = cgraph_node_set_find (set, node);
822 return !csi_end_p (csi);
823 }
824
825 /* Return number of nodes in SET. */
826 static inline size_t
827 cgraph_node_set_size (cgraph_node_set set)
828 {
829 return VEC_length (cgraph_node_ptr, set->nodes);
830 }
831
832 /* Return true if iterator VSI points to nothing. */
833 static inline bool
834 vsi_end_p (varpool_node_set_iterator vsi)
835 {
836 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
837 }
838
839 /* Advance iterator VSI. */
840 static inline void
841 vsi_next (varpool_node_set_iterator *vsi)
842 {
843 vsi->index++;
844 }
845
846 /* Return the node pointed to by VSI. */
847 static inline struct varpool_node *
848 vsi_node (varpool_node_set_iterator vsi)
849 {
850 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
851 }
852
853 /* Return an iterator to the first node in SET. */
854 static inline varpool_node_set_iterator
855 vsi_start (varpool_node_set set)
856 {
857 varpool_node_set_iterator vsi;
858
859 vsi.set = set;
860 vsi.index = 0;
861 return vsi;
862 }
863
864 /* Return true if SET contains NODE. */
865 static inline bool
866 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
867 {
868 varpool_node_set_iterator vsi;
869 vsi = varpool_node_set_find (set, node);
870 return !vsi_end_p (vsi);
871 }
872
873 /* Return number of nodes in SET. */
874 static inline size_t
875 varpool_node_set_size (varpool_node_set set)
876 {
877 return VEC_length (varpool_node_ptr, set->nodes);
878 }
879
880 /* Uniquize all constants that appear in memory.
881 Each constant in memory thus far output is recorded
882 in `const_desc_table'. */
883
884 struct GTY(()) constant_descriptor_tree {
885 /* A MEM for the constant. */
886 rtx rtl;
887
888 /* The value of the constant. */
889 tree value;
890
891 /* Hash of value. Computing the hash from value each time
892 hashfn is called can't work properly, as that means recursive
893 use of the hash table during hash table expansion. */
894 hashval_t hash;
895 };
896
897 /* Return true if set is nonempty. */
898 static inline bool
899 cgraph_node_set_nonempty_p (cgraph_node_set set)
900 {
901 return !VEC_empty (cgraph_node_ptr, set->nodes);
902 }
903
904 /* Return true if set is nonempty. */
905 static inline bool
906 varpool_node_set_nonempty_p (varpool_node_set set)
907 {
908 return !VEC_empty (varpool_node_ptr, set->nodes);
909 }
910
911 /* Return true when function NODE is only called directly or it has alias.
912 i.e. it is not externally visible, address was not taken and
913 it is not used in any other non-standard way. */
914
915 static inline bool
916 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
917 {
918 gcc_assert (!node->global.inlined_to);
919 return (!node->needed && !node->address_taken
920 && !node->reachable_from_other_partition
921 && !DECL_STATIC_CONSTRUCTOR (node->decl)
922 && !DECL_STATIC_DESTRUCTOR (node->decl)
923 && !node->local.externally_visible);
924 }
925
926 /* Return true when function NODE can be removed from callgraph
927 if all direct calls are eliminated. */
928
929 static inline bool
930 varpool_can_remove_if_no_refs (struct varpool_node *node)
931 {
932 return (!node->force_output && !node->used_from_other_partition
933 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
934 || DECL_ARTIFICIAL (node->decl))
935 && (DECL_COMDAT (node->decl) || !node->externally_visible));
936 }
937
938 /* Return true when all references to VNODE must be visible in ipa_ref_list.
939 i.e. if the variable is not externally visible or not used in some magic
940 way (asm statement or such).
941 The magic uses are all summarized in force_output flag. */
942
943 static inline bool
944 varpool_all_refs_explicit_p (struct varpool_node *vnode)
945 {
946 return (!vnode->externally_visible
947 && !vnode->used_from_other_partition
948 && !vnode->force_output);
949 }
950
951 /* Constant pool accessor function. */
952 htab_t constant_pool_htab (void);
953
954 /* FIXME: inappropriate dependency of cgraph on IPA. */
955 #include "ipa-ref-inline.h"
956
957 /* Return node that alias N is aliasing. */
958
959 static inline struct cgraph_node *
960 cgraph_alias_aliased_node (struct cgraph_node *n)
961 {
962 struct ipa_ref *ref;
963
964 ipa_ref_list_reference_iterate (&n->ref_list, 0, ref);
965 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
966 if (ref->refered_type == IPA_REF_CGRAPH)
967 return ipa_ref_node (ref);
968 return NULL;
969 }
970
971 /* Given NODE, walk the alias chain to return the function NODE is alias of.
972 Walk through thunk, too.
973 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
974
975 static inline struct cgraph_node *
976 cgraph_function_node (struct cgraph_node *node, enum availability *availability)
977 {
978 if (availability)
979 *availability = cgraph_function_body_availability (node);
980 while (node)
981 {
982 if (node->alias && node->analyzed)
983 node = cgraph_alias_aliased_node (node);
984 else if (node->thunk.thunk_p)
985 node = node->callees->callee;
986 else
987 return node;
988 if (node && availability)
989 {
990 enum availability a;
991 a = cgraph_function_body_availability (node);
992 if (a < *availability)
993 *availability = a;
994 }
995 }
996 if (*availability)
997 *availability = AVAIL_NOT_AVAILABLE;
998 return NULL;
999 }
1000
1001 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1002 Do not walk through thunks.
1003 When AVAILABILITY is non-NULL, get minimal availablity in the chain. */
1004
1005 static inline struct cgraph_node *
1006 cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1007 {
1008 if (availability)
1009 *availability = cgraph_function_body_availability (node);
1010 while (node)
1011 {
1012 if (node->alias && node->analyzed)
1013 node = cgraph_alias_aliased_node (node);
1014 else
1015 return node;
1016 if (node && availability)
1017 {
1018 enum availability a;
1019 a = cgraph_function_body_availability (node);
1020 if (a < *availability)
1021 *availability = a;
1022 }
1023 }
1024 if (*availability)
1025 *availability = AVAIL_NOT_AVAILABLE;
1026 return NULL;
1027 }
1028
1029 /* Return true when the edge E represents a direct recursion. */
1030 static inline bool
1031 cgraph_edge_recursive_p (struct cgraph_edge *e)
1032 {
1033 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1034 if (e->caller->global.inlined_to)
1035 return e->caller->global.inlined_to->decl == callee->decl;
1036 else
1037 return e->caller->decl == callee->decl;
1038 }
1039 #endif /* GCC_CGRAPH_H */