OSDN Git Service

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