OSDN Git Service

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