150974Swpaul/* Callgraph handling code.
250974Swpaul   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
350974Swpaul   Contributed by Jan Hubicka
450974Swpaul
550974SwpaulThis file is part of GCC.
650974Swpaul
750974SwpaulGCC is free software; you can redistribute it and/or modify it under
850974Swpaulthe terms of the GNU General Public License as published by the Free
950974SwpaulSoftware Foundation; either version 2, or (at your option) any later
1050974Swpaulversion.
1150974Swpaul
1250974SwpaulGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1350974SwpaulWARRANTY; without even the implied warranty of MERCHANTABILITY or
1450974SwpaulFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1550974Swpaulfor more details.
1650974Swpaul
1750974SwpaulYou should have received a copy of the GNU General Public License
1850974Swpaulalong with GCC; see the file COPYING.  If not, write to the Free
1950974SwpaulSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2050974Swpaul02110-1301, USA.  */
2150974Swpaul
2250974Swpaul#ifndef GCC_CGRAPH_H
2350974Swpaul#define GCC_CGRAPH_H
2450974Swpaul#include "tree.h"
2550974Swpaul#include "basic-block.h"
2650974Swpaul
2750974Swpaulenum availability
2850974Swpaul{
2950974Swpaul  /* Not yet set by cgraph_function_body_availability.  */
3050974Swpaul  AVAIL_UNSET,
3150974Swpaul  /* Function body/variable initializer is unknown.  */
3250974Swpaul  AVAIL_NOT_AVAILABLE,
33122678Sobrien  /* Function body/variable initializer is known but might be replaced
34122678Sobrien     by a different one from other compilation unit and thus needs to
35122678Sobrien     be dealt with a care.  Like AVAIL_NOT_AVAILABLE it can have
3650974Swpaul     arbitrary side effects on escaping variables and functions, while
3750974Swpaul     like AVAILABLE it might access static variables.  */
3850974Swpaul  AVAIL_OVERWRITABLE,
3950974Swpaul  /* Function body/variable initializer is known and will be used in final
4064963Swpaul     program.  */
4164963Swpaul  AVAIL_AVAILABLE,
4264963Swpaul  /* Function body/variable initializer is known and all it's uses are explicitly
4350974Swpaul     visible within current unit (ie it's address is never taken and it is not
4450974Swpaul     exported to other units).
4550974Swpaul     Currently used only for functions.  */
4650974Swpaul  AVAIL_LOCAL
4750974Swpaul};
4850974Swpaul
4950974Swpaul/* Information about the function collected locally.
5050974Swpaul   Available after function is analyzed.  */
5150974Swpaul
5250974Swpaulstruct cgraph_local_info GTY(())
5350974Swpaul{
5450974Swpaul  /* Size of the function before inlining.  */
5550974Swpaul  int self_insns;
5650974Swpaul
5750974Swpaul  /* Set when function function is visible in current compilation unit only
5850974Swpaul     and its address is never taken.  */
5950974Swpaul  bool local;
6050974Swpaul
6150974Swpaul  /* Set when function is visible by other units.  */
6250974Swpaul  bool externally_visible;
6350974Swpaul
6450974Swpaul  /* Set once it has been finalized so we consider it to be output.  */
6550974Swpaul  bool finalized;
66129876Sphk
6750974Swpaul  /* False when there something makes inlining impossible (such as va_arg).  */
6887059Sluigi  bool inlinable;
6950974Swpaul
7050974Swpaul  /* True when function should be inlined independently on its size.  */
7150974Swpaul  bool disregard_inline_limits;
7250974Swpaul
7350974Swpaul  /* True when the function has been originally extern inline, but it is
7450974Swpaul     redefined now.  */
7587390Sjhay  bool redefined_extern_inline;
7687390Sjhay
7750974Swpaul  /* True if statics_read_for_function and
7850974Swpaul     statics_written_for_function contain valid data.  */
7950974Swpaul  bool for_functions_valid;
8050974Swpaul
8150974Swpaul  /* True if the function is going to be emitted in some other translation
8250974Swpaul     unit, referenced from vtable.  */
8350974Swpaul  bool vtable_method;
8450974Swpaul};
8550974Swpaul
8650974Swpaul/* Information about the function that needs to be computed globally
8750974Swpaul   once compilation is finished.  Available only with -funit-at-time.  */
8850974Swpaul
8950974Swpaulstruct cgraph_global_info GTY(())
90119288Simp{
91119288Simp  /* For inline clones this points to the function they will be inlined into.  */
9250974Swpaul  struct cgraph_node *inlined_to;
9350974Swpaul
9450974Swpaul  /* Estimated size of the function after inlining.  */
9550974Swpaul  int insns;
9650974Swpaul
97113506Smdodd  /* Estimated growth after inlining.  INT_MIN if not computed.  */
98113506Smdodd  int estimated_growth;
9959758Speter
10059758Speter  /* Set iff the function has been inlined at least once.  */
10151089Speter  bool inlined;
10250974Swpaul};
10350974Swpaul
10450974Swpaul/* Information about the function that is propagated by the RTL backend.
10550974Swpaul   Available only for functions that has been already assembled.  */
10650974Swpaul
10750974Swpaulstruct cgraph_rtl_info GTY(())
10850974Swpaul{
10950974Swpaul   int preferred_incoming_stack_boundary;
110119712Sphk};
11150974Swpaul
11250974Swpaul/* The cgraph data structure.
11350974Swpaul   Each function decl has assigned cgraph_node listing callees and callers.  */
11492739Salfred
11592739Salfredstruct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
11692739Salfred{
11750974Swpaul  tree decl;
11892739Salfred  struct cgraph_edge *callees;
11992739Salfred  struct cgraph_edge *callers;
12092739Salfred  struct cgraph_node *next;
121121262Ssilby  struct cgraph_node *previous;
12292739Salfred  /* For nested functions points to function the node is nested in.  */
12392739Salfred  struct cgraph_node *origin;
12492739Salfred  /* Points to first nested function, if any.  */
12592739Salfred  struct cgraph_node *nested;
12692739Salfred  /* Pointer to the next function with same origin, if any.  */
12792739Salfred  struct cgraph_node *next_nested;
12892739Salfred  /* Pointer to the next function in cgraph_nodes_queue.  */
12992739Salfred  struct cgraph_node *next_needed;
13092739Salfred  /* Pointer to the next clone.  */
13192739Salfred  struct cgraph_node *next_clone;
13292739Salfred  struct cgraph_node *prev_clone;
13392739Salfred  /* Pointer to a single unique cgraph node for this function.  If the
13492739Salfred     function is to be output, this is the copy that will survive.  */
13550974Swpaul  struct cgraph_node *master_clone;
13692739Salfred
13792739Salfred  PTR GTY ((skip)) aux;
13892739Salfred
13992739Salfred  struct cgraph_local_info local;
14092739Salfred  struct cgraph_global_info global;
14192739Salfred  struct cgraph_rtl_info rtl;
14272197Swpaul
14392739Salfred  /* Expected number of executions: calculated in profile.c.  */
14492739Salfred  gcov_type count;
14592739Salfred  /* Unique id of the node.  */
14692739Salfred  int uid;
14772197Swpaul  /* Set when function must be output - it is externally visible
14872197Swpaul     or its address is taken.  */
149109060Smbr  bool needed;
150109060Smbr  /* Set when function is reachable by call from other function
151109060Smbr     that is either reachable or needed.  */
152109060Smbr  bool reachable;
15392739Salfred  /* Set once the function is lowered (ie it's CFG is built).  */
15492739Salfred  bool lowered;
15592739Salfred  /* Set once the function has been instantiated and its callee
15650974Swpaul     lists created.  */
15792739Salfred  bool analyzed;
15892739Salfred  /* Set when function is scheduled to be assembled.  */
159123289Sobrien  bool output;
16092739Salfred  /* Set when function is visible by other units.  */
16192739Salfred  bool externally_visible;
16292739Salfred  /* Set for aliases once they got through assemble_alias.  */
16350974Swpaul  bool alias;
16492739Salfred};
16592739Salfred
16692739Salfredstruct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
16750974Swpaul{
16850974Swpaul  struct cgraph_node *caller;
16950974Swpaul  struct cgraph_node *callee;
17050974Swpaul  struct cgraph_edge *prev_caller;
17151030Swpaul  struct cgraph_edge *next_caller;
17251030Swpaul  struct cgraph_edge *prev_callee;
17350974Swpaul  struct cgraph_edge *next_callee;
17450974Swpaul  tree call_stmt;
17550974Swpaul  PTR GTY ((skip (""))) aux;
17650974Swpaul  /* When NULL, inline this call.  When non-NULL, points to the explanation
17750974Swpaul     why function was not inlined.  */
17850974Swpaul  const char *inline_failed;
17950974Swpaul  /* Expected number of executions: calculated in profile.c.  */
18050974Swpaul  gcov_type count;
18150974Swpaul  /* Depth of loop nest, 1 means no loop nest.  */
18250974Swpaul  int loop_nest;
18350974Swpaul};
18450974Swpaul
18550974Swpaul/* The cgraph_varpool data structure.
18650974Swpaul   Each static variable decl has assigned cgraph_varpool_node.  */
18750974Swpaul
18850974Swpaulstruct cgraph_varpool_node GTY(())
18950974Swpaul{
19050974Swpaul  tree decl;
19150974Swpaul  /* Pointer to the next function in cgraph_varpool_nodes.  */
19250974Swpaul  struct cgraph_varpool_node *next;
19350974Swpaul  /* Pointer to the next function in cgraph_varpool_nodes_queue.  */
19450974Swpaul  struct cgraph_varpool_node *next_needed;
19551455Swpaul
19650974Swpaul  /* Set when function must be output - it is externally visible
19750974Swpaul     or its address is taken.  */
19850974Swpaul  bool needed;
19950974Swpaul  /* Needed variables might become dead by optimization.  This flag
20050974Swpaul     forces the variable to be output even if it appears dead otherwise.  */
20150974Swpaul  bool force_output;
202113506Smdodd  /* Set once the variable has been instantiated and its callee
20351473Swpaul     lists created.  */
20450974Swpaul  bool analyzed;
20550974Swpaul  /* Set once it has been finalized so we consider it to be output.  */
20650974Swpaul  bool finalized;
20750974Swpaul  /* Set when variable is scheduled to be assembled.  */
20850974Swpaul  bool output;
20950974Swpaul  /* Set when function is visible by other units.  */
21050974Swpaul  bool externally_visible;
21150974Swpaul  /* Set for aliases once they got through assemble_alias.  */
21250974Swpaul  bool alias;
21350974Swpaul};
21450974Swpaul
21550974Swpaulextern GTY(()) struct cgraph_node *cgraph_nodes;
21650974Swpaulextern GTY(()) int cgraph_n_nodes;
21750974Swpaulextern GTY(()) int cgraph_max_uid;
21850974Swpaulextern bool cgraph_global_info_ready;
21981713Swpaulextern bool cgraph_function_flags_ready;
22081713Swpaulextern GTY(()) struct cgraph_node *cgraph_nodes_queue;
22181713Swpaul
22281713Swpaulextern GTY(()) struct cgraph_varpool_node *cgraph_varpool_first_unanalyzed_node;
22381713Swpaulextern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes_queue;
22481713Swpaulextern GTY(()) struct cgraph_varpool_node *cgraph_varpool_nodes;
22581713Swpaul
22681713Swpaul/* In cgraph.c  */
22781713Swpaulvoid dump_cgraph (FILE *);
22881713Swpaulvoid dump_cgraph_node (FILE *, struct cgraph_node *);
22981713Swpaulvoid dump_varpool (FILE *);
23081713Swpaulvoid dump_cgraph_varpool_node (FILE *, struct cgraph_varpool_node *);
23181713Swpaulvoid cgraph_remove_edge (struct cgraph_edge *);
23281713Swpaulvoid cgraph_remove_node (struct cgraph_node *);
23381713Swpaulvoid cgraph_node_remove_callees (struct cgraph_node *node);
23481713Swpaulstruct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
23581713Swpaul					struct cgraph_node *,
23681713Swpaul				        tree, gcov_type, int);
23781713Swpaulstruct cgraph_node *cgraph_node (tree);
23881713Swpaulstruct cgraph_node *cgraph_node_for_asm (tree asmname);
23981713Swpaulstruct cgraph_edge *cgraph_edge (struct cgraph_node *, tree);
24081713Swpaulstruct cgraph_local_info *cgraph_local_info (tree);
24181713Swpaulstruct cgraph_global_info *cgraph_global_info (tree);
24281713Swpaulstruct cgraph_rtl_info *cgraph_rtl_info (tree);
24381713Swpaulconst char * cgraph_node_name (struct cgraph_node *);
24481713Swpaulstruct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
24581713Swpaul				        struct cgraph_node *,
24681713Swpaul				        tree, gcov_type, int, bool);
24781713Swpaulstruct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type,
24881713Swpaul					int, bool);
24981713Swpaul
25081713Swpaulstruct cgraph_varpool_node *cgraph_varpool_node (tree);
25181713Swpaulstruct cgraph_varpool_node *cgraph_varpool_node_for_asm (tree asmname);
25281713Swpaulvoid cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *);
25381713Swpaulvoid cgraph_varpool_finalize_decl (tree);
25481713Swpaulvoid cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
25581713Swpaul
25681713Swpaulbool cgraph_function_possibly_inlined_p (tree);
25781713Swpaulvoid cgraph_unnest_node (struct cgraph_node *);
25881713Swpaulvoid cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node *);
25981713Swpaulvoid cgraph_varpool_reset_queue (void);
26081713Swpaulbool decide_is_variable_needed (struct cgraph_varpool_node *, tree);
26162672Swpaul
26262672Swpaulenum availability cgraph_function_body_availability (struct cgraph_node *);
26362672Swpaulenum availability cgraph_variable_initializer_availability (struct cgraph_varpool_node *);
26462672Swpaulbool cgraph_is_master_clone (struct cgraph_node *);
265102334Salfredstruct cgraph_node *cgraph_master_clone (struct cgraph_node *);
266102334Salfred
26762672Swpaul/* In cgraphunit.c  */
26862672Swpaulbool cgraph_assemble_pending_functions (void);
26962672Swpaulbool cgraph_varpool_assemble_pending_decls (void);
27062672Swpaulvoid cgraph_finalize_function (tree, bool);
27162672Swpaulvoid cgraph_lower_function (struct cgraph_node *);
27262672Swpaulvoid cgraph_finalize_compilation_unit (void);
27362672Swpaulvoid cgraph_optimize (void);
27462672Swpaulvoid cgraph_mark_needed_node (struct cgraph_node *);
27562672Swpaulvoid cgraph_mark_reachable_node (struct cgraph_node *);
27662672Swpaulbool cgraph_inline_p (struct cgraph_edge *, const char **reason);
277102334Salfredbool cgraph_preserve_function_body_p (tree);
278102334Salfredvoid verify_cgraph (void);
27950974Swpaulvoid verify_cgraph_node (struct cgraph_node *);
28050974Swpaulvoid cgraph_build_static_cdtor (char which, tree body, int priority);
28150974Swpaulvoid cgraph_reset_static_var_maps (void);
28250974Swpaulvoid init_cgraph (void);
28350974Swpaulstruct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
28450974Swpaul                                                varray_type, varray_type);
28550974Swpaul
28650974Swpaul/* In ipa.c  */
28750974Swpaulbool cgraph_remove_unreachable_nodes (bool, FILE *);
28850974Swpaulint cgraph_postorder (struct cgraph_node **);
289102334Salfred
290102334Salfred/* In ipa-inline.c  */
29150974Swpaulbool cgraph_decide_inlining_incrementally (struct cgraph_node *, bool);
29250974Swpaulvoid cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
29350974Swpaulvoid cgraph_mark_inline_edge (struct cgraph_edge *, bool);
29450974Swpaulbool cgraph_default_inline_p (struct cgraph_node *, const char **);
29550974Swpaul#endif  /* GCC_CGRAPH_H  */
29650974Swpaul