OSDN Git Service

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