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