]> gcc.gnu.org Git - gcc.git/blob - gcc/cgraph.h
Merge from transactional-memory branch.
[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 void cgraph_remove_node_and_inline_clones (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
517 void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
518 void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
519 bool cgraph_only_called_directly_p (struct cgraph_node *);
520
521 struct cgraph_asm_node *cgraph_add_asm_node (tree);
522
523 bool cgraph_function_possibly_inlined_p (tree);
524 void cgraph_unnest_node (struct cgraph_node *);
525
526 enum availability cgraph_function_body_availability (struct cgraph_node *);
527 void cgraph_add_new_function (tree, bool);
528 const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
529 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
530 VEC(cgraph_edge_p,heap)*,
531 VEC(ipa_replace_map_p,gc)* tree_map,
532 bitmap args_to_skip,
533 const char *clone_name);
534
535 void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
536 void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
537 void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
538 tree clone_function_name (tree decl, const char *);
539 bool cgraph_node_cannot_return (struct cgraph_node *);
540 bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
541 bool cgraph_will_be_removed_from_program_if_no_direct_calls
542 (struct cgraph_node *node);
543 bool cgraph_can_remove_if_no_direct_calls_and_refs_p
544 (struct cgraph_node *node);
545 bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
546 bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
547 bool cgraph_used_from_object_file_p (struct cgraph_node *);
548 bool varpool_used_from_object_file_p (struct varpool_node *);
549 bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
550 bool (*) (struct cgraph_node *, void *),
551 void *,
552 bool);
553 bool cgraph_for_node_and_aliases (struct cgraph_node *,
554 bool (*) (struct cgraph_node *, void *),
555 void *, bool);
556 VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
557
558
559 /* In cgraphunit.c */
560 extern FILE *cgraph_dump_file;
561 void cgraph_finalize_function (tree, bool);
562 void cgraph_mark_if_needed (tree);
563 void cgraph_analyze_function (struct cgraph_node *);
564 void cgraph_finalize_compilation_unit (void);
565 void cgraph_optimize (void);
566 void cgraph_mark_needed_node (struct cgraph_node *);
567 void cgraph_mark_address_taken_node (struct cgraph_node *);
568 void cgraph_mark_reachable_node (struct cgraph_node *);
569 bool cgraph_inline_p (struct cgraph_edge *, cgraph_inline_failed_t *reason);
570 bool cgraph_preserve_function_body_p (struct cgraph_node *);
571 void verify_cgraph (void);
572 void verify_cgraph_node (struct cgraph_node *);
573 void cgraph_build_static_cdtor (char which, tree body, int priority);
574 void cgraph_reset_static_var_maps (void);
575 void init_cgraph (void);
576 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
577 tree, VEC(cgraph_edge_p,heap)*, bitmap);
578 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
579 VEC(cgraph_edge_p,heap)*,
580 VEC(ipa_replace_map_p,gc)*,
581 bitmap, bitmap, basic_block,
582 const char *);
583 void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*, bool, bitmap,
584 bitmap, basic_block);
585 void record_references_in_initializer (tree, bool);
586 bool cgraph_process_new_functions (void);
587 void cgraph_process_same_body_aliases (void);
588
589 bool cgraph_decide_is_function_needed (struct cgraph_node *, tree);
590
591 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
592 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
593 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
594 void *);
595 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
596 void *);
597 struct cgraph_edge_hook_list;
598 struct cgraph_node_hook_list;
599 struct cgraph_2edge_hook_list;
600 struct cgraph_2node_hook_list;
601 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
602 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
603 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
604 void *);
605 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
606 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
607 void *);
608 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
609 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
610 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
611 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
612 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
613 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
614 void cgraph_materialize_all_clones (void);
615 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
616 bool cgraph_propagate_frequency (struct cgraph_node *node);
617 /* In cgraphbuild.c */
618 unsigned int rebuild_cgraph_edges (void);
619 void cgraph_rebuild_references (void);
620 void reset_inline_failed (struct cgraph_node *);
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
645 /* In predict.c */
646 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
647 bool cgraph_optimize_for_size_p (struct cgraph_node *);
648
649 /* In varpool.c */
650 extern GTY(()) struct varpool_node *varpool_nodes_queue;
651 extern GTY(()) struct varpool_node *varpool_nodes;
652
653 struct varpool_node *varpool_node (tree);
654 struct varpool_node *varpool_node_for_asm (tree asmname);
655 void varpool_mark_needed_node (struct varpool_node *);
656 void debug_varpool (void);
657 void dump_varpool (FILE *);
658 void dump_varpool_node (FILE *, struct varpool_node *);
659
660 void varpool_finalize_decl (tree);
661 bool decide_is_variable_needed (struct varpool_node *, tree);
662 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
663 void cgraph_make_decl_local (tree);
664 void cgraph_make_node_local (struct cgraph_node *);
665 bool cgraph_node_can_be_local_p (struct cgraph_node *);
666
667
668 struct varpool_node * varpool_get_node (const_tree decl);
669 void varpool_remove_node (struct varpool_node *node);
670 void varpool_finalize_named_section_flags (struct varpool_node *node);
671 bool varpool_assemble_pending_decls (void);
672 bool varpool_assemble_decl (struct varpool_node *node);
673 bool varpool_analyze_pending_decls (void);
674 void varpool_remove_unreferenced_decls (void);
675 void varpool_empty_needed_queue (void);
676 struct varpool_node * varpool_extra_name_alias (tree, tree);
677 struct varpool_node * varpool_create_variable_alias (tree, tree);
678 const char * varpool_node_name (struct varpool_node *node);
679 void varpool_reset_queue (void);
680 bool const_value_known_p (tree);
681 bool varpool_for_node_and_aliases (struct varpool_node *,
682 bool (*) (struct varpool_node *, void *),
683 void *, bool);
684
685 /* Walk all reachable static variables. */
686 #define FOR_EACH_STATIC_VARIABLE(node) \
687 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
688
689 /* Return first reachable static variable with initializer. */
690 static inline struct varpool_node *
691 varpool_first_static_initializer (void)
692 {
693 struct varpool_node *node;
694 for (node = varpool_nodes_queue; node; node = node->next_needed)
695 {
696 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
697 if (DECL_INITIAL (node->decl))
698 return node;
699 }
700 return NULL;
701 }
702
703 /* Return next reachable static variable with initializer after NODE. */
704 static inline struct varpool_node *
705 varpool_next_static_initializer (struct varpool_node *node)
706 {
707 for (node = node->next_needed; node; node = node->next_needed)
708 {
709 gcc_checking_assert (TREE_CODE (node->decl) == VAR_DECL);
710 if (DECL_INITIAL (node->decl))
711 return node;
712 }
713 return NULL;
714 }
715
716 /* Walk all static variables with initializer set. */
717 #define FOR_EACH_STATIC_INITIALIZER(node) \
718 for ((node) = varpool_first_static_initializer (); (node); \
719 (node) = varpool_next_static_initializer (node))
720
721 /* Return first function with body defined. */
722 static inline struct cgraph_node *
723 cgraph_first_defined_function (void)
724 {
725 struct cgraph_node *node;
726 for (node = cgraph_nodes; node; node = node->next)
727 {
728 if (node->analyzed)
729 return node;
730 }
731 return NULL;
732 }
733
734 /* Return next reachable static variable with initializer after NODE. */
735 static inline struct cgraph_node *
736 cgraph_next_defined_function (struct cgraph_node *node)
737 {
738 for (node = node->next; node; node = node->next)
739 {
740 if (node->analyzed)
741 return node;
742 }
743 return NULL;
744 }
745
746 /* Walk all functions with body defined. */
747 #define FOR_EACH_DEFINED_FUNCTION(node) \
748 for ((node) = cgraph_first_defined_function (); (node); \
749 (node) = cgraph_next_defined_function (node))
750
751
752 /* Return true when NODE is a function with Gimple body defined
753 in current unit. Functions can also be define externally or they
754 can be thunks with no Gimple representation.
755
756 Note that at WPA stage, the function body may not be present in memory. */
757
758 static inline bool
759 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
760 {
761 return node->analyzed && !node->thunk.thunk_p && !node->alias;
762 }
763
764 /* Return first function with body defined. */
765 static inline struct cgraph_node *
766 cgraph_first_function_with_gimple_body (void)
767 {
768 struct cgraph_node *node;
769 for (node = cgraph_nodes; node; node = node->next)
770 {
771 if (cgraph_function_with_gimple_body_p (node))
772 return node;
773 }
774 return NULL;
775 }
776
777 /* Return next reachable static variable with initializer after NODE. */
778 static inline struct cgraph_node *
779 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
780 {
781 for (node = node->next; node; node = node->next)
782 {
783 if (cgraph_function_with_gimple_body_p (node))
784 return node;
785 }
786 return NULL;
787 }
788
789 /* Walk all functions with body defined. */
790 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
791 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
792 (node) = cgraph_next_function_with_gimple_body (node))
793
794 /* Create a new static variable of type TYPE. */
795 tree add_new_static_var (tree type);
796
797 /* Return true if iterator CSI points to nothing. */
798 static inline bool
799 csi_end_p (cgraph_node_set_iterator csi)
800 {
801 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
802 }
803
804 /* Advance iterator CSI. */
805 static inline void
806 csi_next (cgraph_node_set_iterator *csi)
807 {
808 csi->index++;
809 }
810
811 /* Return the node pointed to by CSI. */
812 static inline struct cgraph_node *
813 csi_node (cgraph_node_set_iterator csi)
814 {
815 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
816 }
817
818 /* Return an iterator to the first node in SET. */
819 static inline cgraph_node_set_iterator
820 csi_start (cgraph_node_set set)
821 {
822 cgraph_node_set_iterator csi;
823
824 csi.set = set;
825 csi.index = 0;
826 return csi;
827 }
828
829 /* Return true if SET contains NODE. */
830 static inline bool
831 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
832 {
833 cgraph_node_set_iterator csi;
834 csi = cgraph_node_set_find (set, node);
835 return !csi_end_p (csi);
836 }
837
838 /* Return number of nodes in SET. */
839 static inline size_t
840 cgraph_node_set_size (cgraph_node_set set)
841 {
842 return VEC_length (cgraph_node_ptr, set->nodes);
843 }
844
845 /* Return true if iterator VSI points to nothing. */
846 static inline bool
847 vsi_end_p (varpool_node_set_iterator vsi)
848 {
849 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
850 }
851
852 /* Advance iterator VSI. */
853 static inline void
854 vsi_next (varpool_node_set_iterator *vsi)
855 {
856 vsi->index++;
857 }
858
859 /* Return the node pointed to by VSI. */
860 static inline struct varpool_node *
861 vsi_node (varpool_node_set_iterator vsi)
862 {
863 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
864 }
865
866 /* Return an iterator to the first node in SET. */
867 static inline varpool_node_set_iterator
868 vsi_start (varpool_node_set set)
869 {
870 varpool_node_set_iterator vsi;
871
872 vsi.set = set;
873 vsi.index = 0;
874 return vsi;
875 }
876
877 /* Return true if SET contains NODE. */
878 static inline bool
879 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
880 {
881 varpool_node_set_iterator vsi;
882 vsi = varpool_node_set_find (set, node);
883 return !vsi_end_p (vsi);
884 }
885
886 /* Return number of nodes in SET. */
887 static inline size_t
888 varpool_node_set_size (varpool_node_set set)
889 {
890 return VEC_length (varpool_node_ptr, set->nodes);
891 }
892
893 /* Uniquize all constants that appear in memory.
894 Each constant in memory thus far output is recorded
895 in `const_desc_table'. */
896
897 struct GTY(()) constant_descriptor_tree {
898 /* A MEM for the constant. */
899 rtx rtl;
900
901 /* The value of the constant. */
902 tree value;
903
904 /* Hash of value. Computing the hash from value each time
905 hashfn is called can't work properly, as that means recursive
906 use of the hash table during hash table expansion. */
907 hashval_t hash;
908 };
909
910 /* Return true if set is nonempty. */
911 static inline bool
912 cgraph_node_set_nonempty_p (cgraph_node_set set)
913 {
914 return !VEC_empty (cgraph_node_ptr, set->nodes);
915 }
916
917 /* Return true if set is nonempty. */
918 static inline bool
919 varpool_node_set_nonempty_p (varpool_node_set set)
920 {
921 return !VEC_empty (varpool_node_ptr, set->nodes);
922 }
923
924 /* Return true when function NODE is only called directly or it has alias.
925 i.e. it is not externally visible, address was not taken and
926 it is not used in any other non-standard way. */
927
928 static inline bool
929 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
930 {
931 gcc_assert (!node->global.inlined_to);
932 return (!node->needed && !node->address_taken
933 && !node->reachable_from_other_partition
934 && !DECL_STATIC_CONSTRUCTOR (node->decl)
935 && !DECL_STATIC_DESTRUCTOR (node->decl)
936 && !node->local.externally_visible);
937 }
938
939 /* Return true when function NODE can be removed from callgraph
940 if all direct calls are eliminated. */
941
942 static inline bool
943 varpool_can_remove_if_no_refs (struct varpool_node *node)
944 {
945 return (!node->force_output && !node->used_from_other_partition
946 && (flag_toplevel_reorder || DECL_COMDAT (node->decl)
947 || DECL_ARTIFICIAL (node->decl))
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 */
This page took 0.089674 seconds and 5 git commands to generate.