OSDN Git Service

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