OSDN Git Service

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