OSDN Git Service

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