]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
re PR target/37170 (gcc.dg/weak/weak-1.c)
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
1c4a429a 1/* Callgraph handling code.
2bafad93
JJ
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
1c4a429a
JH
4 Contributed by Jan Hubicka
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
9dcd6f09 10Software Foundation; either version 3, or (at your option) any later
1c4a429a
JH
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
9dcd6f09
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
1c4a429a
JH
21
22#ifndef GCC_CGRAPH_H
23#define GCC_CGRAPH_H
6674a6ce 24#include "tree.h"
e42922b1 25#include "basic-block.h"
1c4a429a 26
6b02a499
JH
27enum availability
28{
29 /* Not yet set by cgraph_function_body_availability. */
30 AVAIL_UNSET,
31 /* Function body/variable initializer is unknown. */
32 AVAIL_NOT_AVAILABLE,
33 /* Function body/variable initializer is known but might be replaced
34 by a different one from other compilation unit and thus needs to
35 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
36 arbitrary side effects on escaping variables and functions, while
37 like AVAILABLE it might access static variables. */
38 AVAIL_OVERWRITABLE,
39 /* Function body/variable initializer is known and will be used in final
40 program. */
41 AVAIL_AVAILABLE,
42 /* Function body/variable initializer is known and all it's uses are explicitly
43 visible within current unit (ie it's address is never taken and it is not
44 exported to other units).
45 Currently used only for functions. */
46 AVAIL_LOCAL
47};
48
8a4a83ed
JH
49extern const char * const cgraph_availability_names[];
50
dafc5b82 51/* Information about the function collected locally.
25c84396 52 Available after function is analyzed. */
dafc5b82 53
ed2df68b 54struct cgraph_local_info GTY(())
dafc5b82 55{
95622280
JH
56 struct inline_summary {
57 /* Estimated stack frame consumption by the function. */
58 HOST_WIDE_INT estimated_self_stack_size;
ff28a94d 59
95622280
JH
60 /* Size of the function before inlining. */
61 int self_insns;
62 } inline_summary;
6674a6ce 63
e0bb17a8 64 /* Set when function function is visible in current compilation unit only
e2209b03 65 and its address is never taken. */
b4e19405 66 unsigned local : 1;
6674a6ce 67
e7d6beb0 68 /* Set when function is visible by other units. */
b4e19405 69 unsigned externally_visible : 1;
e7d6beb0 70
f6981e16 71 /* Set once it has been finalized so we consider it to be output. */
b4e19405 72 unsigned finalized : 1;
b58b1157 73
b3c3af2f 74 /* False when there something makes inlining impossible (such as va_arg). */
b4e19405 75 unsigned inlinable : 1;
6674a6ce 76
e2209b03 77 /* True when function should be inlined independently on its size. */
b4e19405 78 unsigned disregard_inline_limits : 1;
6674a6ce 79
95c755e9
JH
80 /* True when the function has been originally extern inline, but it is
81 redefined now. */
b4e19405 82 unsigned redefined_extern_inline : 1;
6674a6ce
KZ
83
84 /* True if statics_read_for_function and
85 statics_written_for_function contain valid data. */
b4e19405 86 unsigned for_functions_valid : 1;
8634c649
JJ
87
88 /* True if the function is going to be emitted in some other translation
89 unit, referenced from vtable. */
b4e19405 90 unsigned vtable_method : 1;
dafc5b82
JH
91};
92
93/* Information about the function that needs to be computed globally
726a989a 94 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 95
ed2df68b 96struct cgraph_global_info GTY(())
dafc5b82 97{
ff28a94d
JH
98 /* Estimated stack frame consumption by the function. */
99 HOST_WIDE_INT estimated_stack_size;
100 /* Expected offset of the stack frame of inlined function. */
101 HOST_WIDE_INT stack_frame_offset;
102
726a989a
RB
103 /* For inline clones this points to the function they will be
104 inlined into. */
18c6ada9
JH
105 struct cgraph_node *inlined_to;
106
b58b1157
JH
107 /* Estimated size of the function after inlining. */
108 int insns;
109
670cd5c5
JH
110 /* Estimated growth after inlining. INT_MIN if not computed. */
111 int estimated_growth;
112
18c6ada9 113 /* Set iff the function has been inlined at least once. */
1bb17c21 114 bool inlined;
dafc5b82
JH
115};
116
b255a036
JH
117/* Information about the function that is propagated by the RTL backend.
118 Available only for functions that has been already assembled. */
119
ed2df68b 120struct cgraph_rtl_info GTY(())
b255a036 121{
17b29c0a 122 unsigned int preferred_incoming_stack_boundary;
b255a036
JH
123};
124
ba228239 125/* The cgraph data structure.
e0bb17a8 126 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 127
d1bd0ded 128struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
1c4a429a
JH
129{
130 tree decl;
131 struct cgraph_edge *callees;
132 struct cgraph_edge *callers;
ed2df68b
JH
133 struct cgraph_node *next;
134 struct cgraph_node *previous;
1c4a429a
JH
135 /* For nested functions points to function the node is nested in. */
136 struct cgraph_node *origin;
137 /* Points to first nested function, if any. */
138 struct cgraph_node *nested;
139 /* Pointer to the next function with same origin, if any. */
140 struct cgraph_node *next_nested;
8bd87c4e
JH
141 /* Pointer to the next function in cgraph_nodes_queue. */
142 struct cgraph_node *next_needed;
18c6ada9
JH
143 /* Pointer to the next clone. */
144 struct cgraph_node *next_clone;
1655dc9d 145 struct cgraph_node *prev_clone;
6b02a499
JH
146 /* Pointer to a single unique cgraph node for this function. If the
147 function is to be output, this is the copy that will survive. */
148 struct cgraph_node *master_clone;
70d539ce
JH
149 /* For functions with many calls sites it holds map from call expression
150 to the edge to speed up cgraph_edge function. */
151 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
c22cacf3 152
1431042e 153 PTR GTY ((skip)) aux;
1c4a429a 154
95c755e9
JH
155 struct cgraph_local_info local;
156 struct cgraph_global_info global;
157 struct cgraph_rtl_info rtl;
c22cacf3 158
e42922b1
JH
159 /* Expected number of executions: calculated in profile.c. */
160 gcov_type count;
95c755e9
JH
161 /* Unique id of the node. */
162 int uid;
474eccc6
ILT
163 /* Ordering of all cgraph nodes. */
164 int order;
b4e19405 165
1c4a429a 166 /* Set when function must be output - it is externally visible
e2209b03 167 or its address is taken. */
b4e19405 168 unsigned needed : 1;
6b20f353
DS
169 /* Set when decl is an abstract function pointed to by the
170 ABSTRACT_DECL_ORIGIN of a reachable function. */
171 unsigned abstract_and_needed : 1;
1c4a429a 172 /* Set when function is reachable by call from other function
e0bb17a8 173 that is either reachable or needed. */
b4e19405 174 unsigned reachable : 1;
50674e96 175 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 176 unsigned lowered : 1;
25c84396
RH
177 /* Set once the function has been instantiated and its callee
178 lists created. */
b4e19405 179 unsigned analyzed : 1;
1c4a429a 180 /* Set when function is scheduled to be assembled. */
b4e19405 181 unsigned output : 1;
12527dce 182 /* Set for aliases once they got through assemble_alias. */
b4e19405 183 unsigned alias : 1;
ea99e0be
JH
184
185 /* In non-unit-at-a-time mode the function body of inline candidates is saved
186 into clone before compiling so the function in original form can be
187 inlined later. This pointer points to the clone. */
188 tree inline_decl;
6bad2617
TB
189
190 /* unique id for profiling. pid is not suitable because of different
191 number of cfg nodes with -fprofile-generate and -fprofile-use */
192 int pid;
1c4a429a
JH
193};
194
2563c224 195struct cgraph_edge GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller")))
1c4a429a 196{
ed2df68b
JH
197 struct cgraph_node *caller;
198 struct cgraph_node *callee;
2563c224 199 struct cgraph_edge *prev_caller;
1c4a429a 200 struct cgraph_edge *next_caller;
2563c224 201 struct cgraph_edge *prev_callee;
1c4a429a 202 struct cgraph_edge *next_callee;
726a989a 203 gimple call_stmt;
18c6ada9 204 PTR GTY ((skip (""))) aux;
dc0bfe6a
JH
205 /* When NULL, inline this call. When non-NULL, points to the explanation
206 why function was not inlined. */
207 const char *inline_failed;
e42922b1
JH
208 /* Expected number of executions: calculated in profile.c. */
209 gcov_type count;
45a80bb9
JH
210 /* Expected frequency of executions within the function.
211 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
212 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
213 int frequency;
e42922b1 214 /* Depth of loop nest, 1 means no loop nest. */
3e293154
MJ
215 unsigned int loop_nest : 31;
216 /* Whether this edge describes a call that was originally indirect. */
217 unsigned int indirect_call : 1;
9088c1cc
MJ
218 /* Unique id of the edge. */
219 int uid;
1c4a429a
JH
220};
221
45a80bb9
JH
222#define CGRAPH_FREQ_BASE 1000
223#define CGRAPH_FREQ_MAX 100000
224
b2c0ad40
KH
225typedef struct cgraph_edge *cgraph_edge_p;
226
227DEF_VEC_P(cgraph_edge_p);
228DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
229
8a4a83ed
JH
230/* The varpool data structure.
231 Each static variable decl has assigned varpool_node. */
e69529cd 232
266ad5c8 233struct varpool_node GTY((chain_next ("%h.next")))
e69529cd
JH
234{
235 tree decl;
8a4a83ed
JH
236 /* Pointer to the next function in varpool_nodes. */
237 struct varpool_node *next;
238 /* Pointer to the next function in varpool_nodes_queue. */
239 struct varpool_node *next_needed;
474eccc6
ILT
240 /* Ordering of all cgraph nodes. */
241 int order;
e69529cd
JH
242
243 /* Set when function must be output - it is externally visible
e2209b03 244 or its address is taken. */
b4e19405 245 unsigned needed : 1;
cd9c7bd2
JH
246 /* Needed variables might become dead by optimization. This flag
247 forces the variable to be output even if it appears dead otherwise. */
b4e19405 248 unsigned force_output : 1;
cd9c7bd2
JH
249 /* Set once the variable has been instantiated and its callee
250 lists created. */
b4e19405 251 unsigned analyzed : 1;
e69529cd 252 /* Set once it has been finalized so we consider it to be output. */
b4e19405 253 unsigned finalized : 1;
6b02a499 254 /* Set when variable is scheduled to be assembled. */
b4e19405 255 unsigned output : 1;
e7d6beb0 256 /* Set when function is visible by other units. */
b4e19405 257 unsigned externally_visible : 1;
1a612e0a 258 /* Set for aliases once they got through assemble_alias. */
b4e19405 259 unsigned alias : 1;
e69529cd
JH
260};
261
474eccc6
ILT
262/* Every top level asm statement is put into a cgraph_asm_node. */
263
264struct cgraph_asm_node GTY(())
265{
266 /* Next asm node. */
267 struct cgraph_asm_node *next;
268 /* String for this asm node. */
269 tree asm_str;
270 /* Ordering of all cgraph nodes. */
271 int order;
272};
273
ed2df68b
JH
274extern GTY(()) struct cgraph_node *cgraph_nodes;
275extern GTY(()) int cgraph_n_nodes;
b58b1157 276extern GTY(()) int cgraph_max_uid;
9088c1cc 277extern GTY(()) int cgraph_edge_max_uid;
6bad2617 278extern GTY(()) int cgraph_max_pid;
dafc5b82 279extern bool cgraph_global_info_ready;
f45e0ad1
JH
280enum cgraph_state
281{
282 /* Callgraph is being constructed. It is safe to add new functions. */
283 CGRAPH_STATE_CONSTRUCTION,
284 /* Callgraph is built and IPA passes are being run. */
285 CGRAPH_STATE_IPA,
7a388ee4
JH
286 /* Callgraph is built and all functions are transformed to SSA form. */
287 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
288 /* Functions are now ordered and being passed to RTL expanders. */
289 CGRAPH_STATE_EXPANSION,
290 /* All cgraph expansion is done. */
291 CGRAPH_STATE_FINISHED
292};
293extern enum cgraph_state cgraph_state;
e7d6beb0 294extern bool cgraph_function_flags_ready;
ed2df68b 295extern GTY(()) struct cgraph_node *cgraph_nodes_queue;
f45e0ad1 296extern GTY(()) struct cgraph_node *cgraph_new_nodes;
1c4a429a 297
474eccc6
ILT
298extern GTY(()) struct cgraph_asm_node *cgraph_asm_nodes;
299extern GTY(()) int cgraph_order;
e69529cd 300
1c4a429a 301/* In cgraph.c */
439f7bc3 302void dump_cgraph (FILE *);
c4e622b6 303void debug_cgraph (void);
18c6ada9 304void dump_cgraph_node (FILE *, struct cgraph_node *);
c4e622b6 305void debug_cgraph_node (struct cgraph_node *);
ea99e0be 306void cgraph_insert_node_to_hashtable (struct cgraph_node *node);
18c6ada9 307void cgraph_remove_edge (struct cgraph_edge *);
439f7bc3 308void cgraph_remove_node (struct cgraph_node *);
3a40c18a 309void cgraph_release_function_body (struct cgraph_node *);
2563c224 310void cgraph_node_remove_callees (struct cgraph_node *node);
18c6ada9
JH
311struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
312 struct cgraph_node *,
726a989a 313 gimple, gcov_type, int, int);
e42922b1 314struct cgraph_node *cgraph_node (tree);
bedb9fc0 315struct cgraph_node *cgraph_node_for_asm (tree asmname);
726a989a
RB
316struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
317void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
318void cgraph_update_edges_for_call_stmt (gimple, gimple);
439f7bc3
AJ
319struct cgraph_local_info *cgraph_local_info (tree);
320struct cgraph_global_info *cgraph_global_info (tree);
321struct cgraph_rtl_info *cgraph_rtl_info (tree);
322const char * cgraph_node_name (struct cgraph_node *);
c5a4444c 323struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
c22cacf3 324 struct cgraph_node *,
726a989a 325 gimple, gcov_type, int, int, bool);
45a80bb9 326struct cgraph_node * cgraph_clone_node (struct cgraph_node *, gcov_type, int,
c5a4444c 327 int, bool);
1c4a429a 328
18c6ada9 329void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
e69529cd 330
474eccc6
ILT
331struct cgraph_asm_node *cgraph_add_asm_node (tree);
332
1bb17c21 333bool cgraph_function_possibly_inlined_p (tree);
e42922b1 334void cgraph_unnest_node (struct cgraph_node *);
1bb17c21 335
6b02a499 336enum availability cgraph_function_body_availability (struct cgraph_node *);
6b02a499
JH
337bool cgraph_is_master_clone (struct cgraph_node *);
338struct cgraph_node *cgraph_master_clone (struct cgraph_node *);
f45e0ad1 339void cgraph_add_new_function (tree, bool);
6b02a499 340
1c4a429a 341/* In cgraphunit.c */
6b00c969 342void cgraph_finalize_function (tree, bool);
f0c882ab 343void cgraph_mark_if_needed (tree);
439f7bc3 344void cgraph_finalize_compilation_unit (void);
439f7bc3 345void cgraph_optimize (void);
8dafba3c
RH
346void cgraph_mark_needed_node (struct cgraph_node *);
347void cgraph_mark_reachable_node (struct cgraph_node *);
18c6ada9
JH
348bool cgraph_inline_p (struct cgraph_edge *, const char **reason);
349bool cgraph_preserve_function_body_p (tree);
350void verify_cgraph (void);
351void verify_cgraph_node (struct cgraph_node *);
35b6fdcf 352void cgraph_build_static_cdtor (char which, tree body, int priority);
6674a6ce 353void cgraph_reset_static_var_maps (void);
9b3e897d 354void init_cgraph (void);
57fb5341 355struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
c22cacf3 356 VEC(cgraph_edge_p,heap)*,
c6f7cfc1
JH
357 varray_type,
358 bitmap);
953ff289 359void cgraph_analyze_function (struct cgraph_node *);
ea99e0be 360struct cgraph_node *save_inline_function_body (struct cgraph_node *);
8a4a83ed 361void record_references_in_initializer (tree);
f45e0ad1 362bool cgraph_process_new_functions (void);
1c4a429a 363
9088c1cc
MJ
364typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
365typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
366typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
367 void *);
368typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
369 void *);
370struct cgraph_edge_hook_list;
371struct cgraph_node_hook_list;
372struct cgraph_2edge_hook_list;
373struct cgraph_2node_hook_list;
374struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
375void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
376struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
377 void *);
378void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
129a37fc
JH
379struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
380 void *);
381void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
382void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
9088c1cc
MJ
383struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
384void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
385struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
386void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
387
917948d3
ZD
388/* In cgraphbuild.c */
389unsigned int rebuild_cgraph_edges (void);
3e293154 390int compute_call_stmt_bb_frequency (basic_block bb);
917948d3 391
ca31b95f
JH
392/* In ipa.c */
393bool cgraph_remove_unreachable_nodes (bool, FILE *);
394int cgraph_postorder (struct cgraph_node **);
395
ca30a539
JH
396bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
397
8a4a83ed
JH
398/* In varpool.c */
399
400extern GTY(()) struct varpool_node *varpool_nodes_queue;
401extern GTY(()) struct varpool_node *varpool_nodes;
402
403struct varpool_node *varpool_node (tree);
404struct varpool_node *varpool_node_for_asm (tree asmname);
405void varpool_mark_needed_node (struct varpool_node *);
406void dump_varpool (FILE *);
407void dump_varpool_node (FILE *, struct varpool_node *);
408
409void varpool_finalize_decl (tree);
410bool decide_is_variable_needed (struct varpool_node *, tree);
411enum availability cgraph_variable_initializer_availability (struct varpool_node *);
412
413bool varpool_assemble_pending_decls (void);
414bool varpool_assemble_decl (struct varpool_node *node);
415bool varpool_analyze_pending_decls (void);
416void varpool_output_debug_info (void);
417void varpool_remove_unreferenced_decls (void);
7386e3ee 418void varpool_empty_needed_queue (void);
8a4a83ed 419
68e56cc4
JH
420/* Walk all reachable static variables. */
421#define FOR_EACH_STATIC_VARIABLE(node) \
422 for ((node) = varpool_nodes_queue; (node); (node) = (node)->next_needed)
423
424/* Return first reachable static variable with initializer. */
425static inline struct varpool_node *
426varpool_first_static_initializer (void)
427{
428 struct varpool_node *node;
429 for (node = varpool_nodes_queue; node; node = node->next_needed)
430 {
431 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
432 if (DECL_INITIAL (node->decl))
433 return node;
434 }
435 return NULL;
436}
437
438/* Return next reachable static variable with initializer after NODE. */
439static inline struct varpool_node *
440varpool_next_static_initializer (struct varpool_node *node)
441{
442 for (node = node->next_needed; node; node = node->next_needed)
443 {
444 gcc_assert (TREE_CODE (node->decl) == VAR_DECL);
445 if (DECL_INITIAL (node->decl))
446 return node;
447 }
448 return NULL;
449}
450
451/* Walk all static variables with initializer set. */
452#define FOR_EACH_STATIC_INITIALIZER(node) \
453 for ((node) = varpool_first_static_initializer (); (node); \
454 (node) = varpool_next_static_initializer (node))
455
ca31b95f 456/* In ipa-inline.c */
06191a23 457void cgraph_clone_inlined_nodes (struct cgraph_edge *, bool, bool);
9de21a23 458bool cgraph_default_inline_p (struct cgraph_node *, const char **);
1920df6c 459unsigned int compute_inline_parameters (struct cgraph_node *);
43d861a5
RL
460
461
462/* Create a new static variable of type TYPE. */
463tree add_new_static_var (tree type);
464
1c4a429a 465#endif /* GCC_CGRAPH_H */