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