OSDN Git Service

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