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