OSDN Git Service

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