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