]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cgraph.h
* recog.c (extract_insn): Enabled alternative defaults to 1.
[thirdparty/gcc.git] / gcc / cgraph.h
CommitLineData
1c4a429a 1/* Callgraph handling code.
960bfb69
JH
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
3 2012 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
7a8cba34 24
5d59b5e1 25#include "is-a.h"
051f8cc6 26#include "plugin-api.h"
7a8cba34 27#include "vec.h"
6674a6ce 28#include "tree.h"
e42922b1 29#include "basic-block.h"
7a8cba34 30#include "function.h"
1f00098b
JH
31#include "ipa-ref.h"
32
33/* Symbol table consists of functions and variables.
34 TODO: add labels, constant pool and aliases. */
35enum symtab_type
36{
960bfb69 37 SYMTAB_SYMBOL,
1f00098b
JH
38 SYMTAB_FUNCTION,
39 SYMTAB_VARIABLE
40};
41
42/* Base of all entries in the symbol table.
43 The symtab_node is inherited by cgraph and varpol nodes. */
960bfb69 44struct GTY(()) symtab_node_base
1f00098b
JH
45{
46 /* Type of the symbol. */
b8dbdb12
RG
47 ENUM_BITFIELD (symtab_type) type : 8;
48
49 /* The symbols resolution. */
50 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
51
52 /* Set when function has address taken.
53 In current implementation it imply needed flag. */
54 unsigned address_taken : 1;
55 /* Set when variable is used from other LTRANS partition. */
56 unsigned used_from_other_partition : 1;
57 /* Set when function is available in the other LTRANS partition.
58 During WPA output it is used to mark nodes that are present in
59 multiple partitions. */
60 unsigned in_other_partition : 1;
61 /* Set when function is visible by other units. */
62 unsigned externally_visible : 1;
63 /* Needed variables might become dead by optimization. This flag
64 forces the variable to be output even if it appears dead otherwise. */
65 unsigned force_output : 1;
66
67 /* Ordering of all symtab entries. */
68 int order;
69
960bfb69 70 tree decl;
b8dbdb12
RG
71
72 /* Vectors of referring and referenced entities. */
960bfb69 73 struct ipa_ref_list ref_list;
b8dbdb12 74
960bfb69
JH
75 /* Circular list of nodes in the same comdat group if non-NULL. */
76 symtab_node same_comdat_group;
b8dbdb12 77
960bfb69
JH
78 /* File stream where this node is being written to. */
79 struct lto_file_decl_data * lto_file_data;
80
2aae7680
JH
81 /* Linked list of symbol table entries starting with symtab_nodes. */
82 symtab_node next;
83 symtab_node previous;
1ab24192
JH
84 /* Linked list of symbols with the same asm name. There may be multiple
85 entries for single symbol name in the case of LTO resolutions,
86 existence of inline clones, or duplicated declaration. The last case
87 is a long standing bug frontends and builtin handling. */
88 symtab_node next_sharing_asm_name;
89 symtab_node previous_sharing_asm_name;
2aae7680 90
960bfb69 91 PTR GTY ((skip)) aux;
1f00098b 92};
1c4a429a 93
6b02a499
JH
94enum availability
95{
96 /* Not yet set by cgraph_function_body_availability. */
97 AVAIL_UNSET,
98 /* Function body/variable initializer is unknown. */
99 AVAIL_NOT_AVAILABLE,
100 /* Function body/variable initializer is known but might be replaced
101 by a different one from other compilation unit and thus needs to
102 be dealt with a care. Like AVAIL_NOT_AVAILABLE it can have
103 arbitrary side effects on escaping variables and functions, while
104 like AVAILABLE it might access static variables. */
105 AVAIL_OVERWRITABLE,
106 /* Function body/variable initializer is known and will be used in final
107 program. */
108 AVAIL_AVAILABLE,
109 /* Function body/variable initializer is known and all it's uses are explicitly
110 visible within current unit (ie it's address is never taken and it is not
111 exported to other units).
112 Currently used only for functions. */
113 AVAIL_LOCAL
114};
115
d7f09764
DN
116/* This is the information that is put into the cgraph local structure
117 to recover a function. */
118struct lto_file_decl_data;
119
8a4a83ed 120extern const char * const cgraph_availability_names[];
430c6ceb 121extern const char * const ld_plugin_symbol_resolution_names[];
8a4a83ed 122
6744a6ab
JH
123/* Information about thunk, used only for same body aliases. */
124
125struct GTY(()) cgraph_thunk_info {
126 /* Information about the thunk. */
127 HOST_WIDE_INT fixed_offset;
128 HOST_WIDE_INT virtual_value;
129 tree alias;
130 bool this_adjusting;
131 bool virtual_offset_p;
132 /* Set to true when alias node is thunk. */
133 bool thunk_p;
134};
135
dafc5b82 136/* Information about the function collected locally.
25c84396 137 Available after function is analyzed. */
dafc5b82 138
d1b38208 139struct GTY(()) cgraph_local_info {
e0bb17a8 140 /* Set when function function is visible in current compilation unit only
e2209b03 141 and its address is never taken. */
b4e19405 142 unsigned local : 1;
6674a6ce 143
f6981e16 144 /* Set once it has been finalized so we consider it to be output. */
b4e19405 145 unsigned finalized : 1;
b58b1157 146
124f1be6
MJ
147 /* False when there is something makes versioning impossible. */
148 unsigned versionable : 1;
149
61e03ffc
JH
150 /* False when function calling convention and signature can not be changed.
151 This is the case when __builtin_apply_args is used. */
152 unsigned can_change_signature : 1;
153
95c755e9
JH
154 /* True when the function has been originally extern inline, but it is
155 redefined now. */
b4e19405 156 unsigned redefined_extern_inline : 1;
0a35513e
AH
157
158 /* True if the function may enter serial irrevocable mode. */
159 unsigned tm_may_enter_irr : 1;
dafc5b82
JH
160};
161
162/* Information about the function that needs to be computed globally
726a989a 163 once compilation is finished. Available only with -funit-at-a-time. */
dafc5b82 164
d1b38208 165struct GTY(()) cgraph_global_info {
726a989a
RB
166 /* For inline clones this points to the function they will be
167 inlined into. */
18c6ada9 168 struct cgraph_node *inlined_to;
dafc5b82
JH
169};
170
b255a036
JH
171/* Information about the function that is propagated by the RTL backend.
172 Available only for functions that has been already assembled. */
173
d1b38208 174struct GTY(()) cgraph_rtl_info {
17b29c0a 175 unsigned int preferred_incoming_stack_boundary;
b255a036
JH
176};
177
9187e02d
JH
178/* Represent which DECL tree (or reference to such tree)
179 will be replaced by another tree while versioning. */
180struct GTY(()) ipa_replace_map
181{
182 /* The tree that will be replaced. */
183 tree old_tree;
184 /* The new (replacing) tree. */
185 tree new_tree;
922f15c2
JH
186 /* Parameter number to replace, when old_tree is NULL. */
187 int parm_num;
9187e02d
JH
188 /* True when a substitution should be done, false otherwise. */
189 bool replace_p;
190 /* True when we replace a reference to old_tree. */
191 bool ref_p;
192};
193typedef struct ipa_replace_map *ipa_replace_map_p;
194DEF_VEC_P(ipa_replace_map_p);
195DEF_VEC_ALLOC_P(ipa_replace_map_p,gc);
196
197struct GTY(()) cgraph_clone_info
198{
199 VEC(ipa_replace_map_p,gc)* tree_map;
200 bitmap args_to_skip;
08ad1d6d 201 bitmap combined_args_to_skip;
9187e02d
JH
202};
203
5fefcf92 204
ba228239 205/* The cgraph data structure.
e0bb17a8 206 Each function decl has assigned cgraph_node listing callees and callers. */
1c4a429a 207
960bfb69
JH
208struct GTY(()) cgraph_node {
209 struct symtab_node_base symbol;
1c4a429a
JH
210 struct cgraph_edge *callees;
211 struct cgraph_edge *callers;
e33c6cd6
MJ
212 /* List of edges representing indirect calls with a yet undetermined
213 callee. */
214 struct cgraph_edge *indirect_calls;
1c4a429a 215 /* For nested functions points to function the node is nested in. */
960bfb69
JH
216 struct cgraph_node *
217 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
218 origin;
1c4a429a 219 /* Points to first nested function, if any. */
960bfb69
JH
220 struct cgraph_node *
221 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
222 nested;
1c4a429a 223 /* Pointer to the next function with same origin, if any. */
960bfb69
JH
224 struct cgraph_node *
225 GTY ((nested_ptr (union symtab_node_def, "(struct cgraph_node *)(%h)", "(symtab_node)%h")))
226 next_nested;
18c6ada9 227 /* Pointer to the next clone. */
9187e02d
JH
228 struct cgraph_node *next_sibling_clone;
229 struct cgraph_node *prev_sibling_clone;
230 struct cgraph_node *clones;
231 struct cgraph_node *clone_of;
70d539ce
JH
232 /* For functions with many calls sites it holds map from call expression
233 to the edge to speed up cgraph_edge function. */
234 htab_t GTY((param_is (struct cgraph_edge))) call_site_hash;
97ba0040
JH
235 /* Declaration node used to be clone of. */
236 tree former_clone_of;
c22cacf3 237
0e3776db
JH
238 /* Interprocedural passes scheduled to have their transform functions
239 applied next time we execute local pass on them. We maintain it
240 per-function in order to allow IPA passes to introduce new functions. */
241 VEC(ipa_opt_pass,heap) * GTY((skip)) ipa_transforms_to_apply;
242
95c755e9
JH
243 struct cgraph_local_info local;
244 struct cgraph_global_info global;
245 struct cgraph_rtl_info rtl;
9187e02d 246 struct cgraph_clone_info clone;
6744a6ab 247 struct cgraph_thunk_info thunk;
c22cacf3 248
e42922b1
JH
249 /* Expected number of executions: calculated in profile.c. */
250 gcov_type count;
db0bf14f
JH
251 /* How to scale counts at materialization time; used to merge
252 LTO units with different number of profile runs. */
253 int count_materialization_scale;
95c755e9
JH
254 /* Unique id of the node. */
255 int uid;
3691626c 256
6b20f353
DS
257 /* Set when decl is an abstract function pointed to by the
258 ABSTRACT_DECL_ORIGIN of a reachable function. */
259 unsigned abstract_and_needed : 1;
50674e96 260 /* Set once the function is lowered (i.e. its CFG is built). */
b4e19405 261 unsigned lowered : 1;
25c84396
RH
262 /* Set once the function has been instantiated and its callee
263 lists created. */
b4e19405 264 unsigned analyzed : 1;
257eb6e3
JH
265 /* Set when function is scheduled to be processed by local passes. */
266 unsigned process : 1;
12527dce 267 /* Set for aliases once they got through assemble_alias. */
b4e19405 268 unsigned alias : 1;
39e2db00 269 /* Set for aliases created as C++ same body aliases. */
b2583345 270 unsigned same_body_alias : 1;
5fefcf92
JH
271 /* How commonly executed the node is. Initialized during branch
272 probabilities pass. */
273 ENUM_BITFIELD (node_frequency) frequency : 2;
844db5d0
JH
274 /* True when function can only be called at startup (from static ctor). */
275 unsigned only_called_at_startup : 1;
276 /* True when function can only be called at startup (from static dtor). */
277 unsigned only_called_at_exit : 1;
0a35513e
AH
278 /* True when function is the transactional clone of a function which
279 is called only from inside transactions. */
280 /* ?? We should be able to remove this. We have enough bits in
281 cgraph to calculate it. */
282 unsigned tm_clone : 1;
1c4a429a
JH
283};
284
7380e6ef
JH
285DEF_VEC_P(symtab_node);
286DEF_VEC_ALLOC_P(symtab_node,heap);
287DEF_VEC_ALLOC_P(symtab_node,gc);
288
fed5ae11
DK
289typedef struct cgraph_node *cgraph_node_ptr;
290
291DEF_VEC_P(cgraph_node_ptr);
292DEF_VEC_ALLOC_P(cgraph_node_ptr,heap);
293DEF_VEC_ALLOC_P(cgraph_node_ptr,gc);
294
295/* A cgraph node set is a collection of cgraph nodes. A cgraph node
296 can appear in multiple sets. */
1cb1a99f 297struct cgraph_node_set_def
fed5ae11 298{
1cb1a99f
JH
299 struct pointer_map_t *map;
300 VEC(cgraph_node_ptr, heap) *nodes;
fed5ae11
DK
301};
302
2942c502
JH
303typedef struct varpool_node *varpool_node_ptr;
304
305DEF_VEC_P(varpool_node_ptr);
306DEF_VEC_ALLOC_P(varpool_node_ptr,heap);
307DEF_VEC_ALLOC_P(varpool_node_ptr,gc);
308
309/* A varpool node set is a collection of varpool nodes. A varpool node
310 can appear in multiple sets. */
1cb1a99f 311struct varpool_node_set_def
2942c502 312{
1cb1a99f
JH
313 struct pointer_map_t * map;
314 VEC(varpool_node_ptr, heap) *nodes;
2942c502
JH
315};
316
fed5ae11
DK
317typedef struct cgraph_node_set_def *cgraph_node_set;
318
319DEF_VEC_P(cgraph_node_set);
320DEF_VEC_ALLOC_P(cgraph_node_set,gc);
321DEF_VEC_ALLOC_P(cgraph_node_set,heap);
322
2942c502
JH
323typedef struct varpool_node_set_def *varpool_node_set;
324
325DEF_VEC_P(varpool_node_set);
326DEF_VEC_ALLOC_P(varpool_node_set,gc);
327DEF_VEC_ALLOC_P(varpool_node_set,heap);
328
fed5ae11
DK
329/* Iterator structure for cgraph node sets. */
330typedef struct
331{
332 cgraph_node_set set;
333 unsigned index;
334} cgraph_node_set_iterator;
335
2942c502
JH
336/* Iterator structure for varpool node sets. */
337typedef struct
338{
339 varpool_node_set set;
340 unsigned index;
341} varpool_node_set_iterator;
342
61a05df1
JH
343#define DEFCIFCODE(code, string) CIF_ ## code,
344/* Reasons for inlining failures. */
533c07c5 345typedef enum cgraph_inline_failed_enum {
61a05df1
JH
346#include "cif-code.def"
347 CIF_N_REASONS
348} cgraph_inline_failed_t;
349
e33c6cd6
MJ
350/* Structure containing additional information about an indirect call. */
351
352struct GTY(()) cgraph_indirect_call_info
353{
8b7773a4
MJ
354 /* When polymorphic is set, this field contains offset where the object which
355 was actually used in the polymorphic resides within a larger structure.
356 If agg_contents is set, the field contains the offset within the aggregate
357 from which the address to call was loaded. */
358 HOST_WIDE_INT offset;
b258210c
MJ
359 /* OBJ_TYPE_REF_TOKEN of a polymorphic call (if polymorphic is set). */
360 HOST_WIDE_INT otr_token;
361 /* Type of the object from OBJ_TYPE_REF_OBJECT. */
362 tree otr_type;
e33c6cd6
MJ
363 /* Index of the parameter that is called. */
364 int param_index;
5f902d76
JH
365 /* ECF flags determined from the caller. */
366 int ecf_flags;
b258210c
MJ
367
368 /* Set when the call is a virtual call with the parameter being the
369 associated object pointer rather than a simple direct call. */
370 unsigned polymorphic : 1;
8b7773a4
MJ
371 /* Set when the call is a call of a pointer loaded from contents of an
372 aggregate at offset. */
373 unsigned agg_contents : 1;
374 /* When the previous bit is set, this one determines whether the destination
375 is loaded from a parameter passed by reference. */
376 unsigned by_ref : 1;
e33c6cd6
MJ
377};
378
d1b38208 379struct GTY((chain_next ("%h.next_caller"), chain_prev ("%h.prev_caller"))) cgraph_edge {
6009ee7b
MJ
380 /* Expected number of executions: calculated in profile.c. */
381 gcov_type count;
ed2df68b
JH
382 struct cgraph_node *caller;
383 struct cgraph_node *callee;
2563c224 384 struct cgraph_edge *prev_caller;
1c4a429a 385 struct cgraph_edge *next_caller;
2563c224 386 struct cgraph_edge *prev_callee;
1c4a429a 387 struct cgraph_edge *next_callee;
726a989a 388 gimple call_stmt;
e33c6cd6
MJ
389 /* Additional information about an indirect call. Not cleared when an edge
390 becomes direct. */
391 struct cgraph_indirect_call_info *indirect_info;
18c6ada9 392 PTR GTY ((skip (""))) aux;
61a05df1
JH
393 /* When equal to CIF_OK, inline this call. Otherwise, points to the
394 explanation why function was not inlined. */
395 cgraph_inline_failed_t inline_failed;
6009ee7b
MJ
396 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
397 when the function is serialized in. */
398 unsigned int lto_stmt_uid;
b8698a0f 399 /* Expected frequency of executions within the function.
45a80bb9
JH
400 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
401 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
402 int frequency;
6009ee7b
MJ
403 /* Unique id of the edge. */
404 int uid;
e33c6cd6
MJ
405 /* Whether this edge was made direct by indirect inlining. */
406 unsigned int indirect_inlining_edge : 1;
407 /* Whether this edge describes an indirect call with an undetermined
408 callee. */
409 unsigned int indirect_unknown_callee : 1;
410 /* Whether this edge is still a dangling */
d7f09764
DN
411 /* True if the corresponding CALL stmt cannot be inlined. */
412 unsigned int call_stmt_cannot_inline_p : 1;
2505c5ed
JH
413 /* Can this call throw externally? */
414 unsigned int can_throw_external : 1;
1c4a429a
JH
415};
416
45a80bb9
JH
417#define CGRAPH_FREQ_BASE 1000
418#define CGRAPH_FREQ_MAX 100000
419
b2c0ad40
KH
420typedef struct cgraph_edge *cgraph_edge_p;
421
422DEF_VEC_P(cgraph_edge_p);
423DEF_VEC_ALLOC_P(cgraph_edge_p,heap);
424
8a4a83ed
JH
425/* The varpool data structure.
426 Each static variable decl has assigned varpool_node. */
e69529cd 427
2aae7680 428struct GTY(()) varpool_node {
960bfb69 429 struct symtab_node_base symbol;
cd35bcf7
JH
430 /* For aliases points to declaration DECL is alias of. */
431 tree alias_of;
e69529cd 432
cd9c7bd2
JH
433 /* Set once the variable has been instantiated and its callee
434 lists created. */
b4e19405 435 unsigned analyzed : 1;
e69529cd 436 /* Set once it has been finalized so we consider it to be output. */
b4e19405 437 unsigned finalized : 1;
6b02a499 438 /* Set when variable is scheduled to be assembled. */
b4e19405 439 unsigned output : 1;
2c71ac78
JM
440 /* Set for aliases once they got through assemble_alias. Also set for
441 extra name aliases in varpool_extra_name_alias. */
b4e19405 442 unsigned alias : 1;
cd35bcf7 443 unsigned extra_name_alias : 1;
e69529cd
JH
444};
445
65d630d4 446/* Every top level asm statement is put into a asm_node. */
474eccc6 447
65d630d4 448struct GTY(()) asm_node {
474eccc6 449 /* Next asm node. */
65d630d4 450 struct asm_node *next;
474eccc6
ILT
451 /* String for this asm node. */
452 tree asm_str;
453 /* Ordering of all cgraph nodes. */
454 int order;
455};
456
960bfb69 457/* Symbol table entry. */
2aae7680
JH
458union GTY((desc ("%h.symbol.type"), chain_next ("%h.symbol.next"),
459 chain_prev ("%h.symbol.previous"))) symtab_node_def {
960bfb69 460 struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
5d59b5e1
LC
461 /* To access the following fields,
462 use the use dyn_cast or as_a to obtain the concrete type. */
960bfb69 463 struct cgraph_node GTY ((tag ("SYMTAB_FUNCTION"))) x_function;
960bfb69
JH
464 struct varpool_node GTY ((tag ("SYMTAB_VARIABLE"))) x_variable;
465};
466
5d59b5e1
LC
467/* Report whether or not THIS symtab node is a function, aka cgraph_node. */
468
469template <>
470template <>
471inline bool
472is_a_helper <cgraph_node>::test (symtab_node_def *p)
473{
474 return p->symbol.type == SYMTAB_FUNCTION;
475}
476
477/* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
478
479template <>
480template <>
481inline bool
482is_a_helper <varpool_node>::test (symtab_node_def *p)
483{
484 return p->symbol.type == SYMTAB_VARIABLE;
485}
486
2aae7680 487extern GTY(()) symtab_node symtab_nodes;
ed2df68b 488extern GTY(()) int cgraph_n_nodes;
b58b1157 489extern GTY(()) int cgraph_max_uid;
9088c1cc 490extern GTY(()) int cgraph_edge_max_uid;
dafc5b82 491extern bool cgraph_global_info_ready;
f45e0ad1
JH
492enum cgraph_state
493{
66058468
JH
494 /* Frontend is parsing and finalizing functions. */
495 CGRAPH_STATE_PARSING,
f45e0ad1
JH
496 /* Callgraph is being constructed. It is safe to add new functions. */
497 CGRAPH_STATE_CONSTRUCTION,
498 /* Callgraph is built and IPA passes are being run. */
499 CGRAPH_STATE_IPA,
7a388ee4
JH
500 /* Callgraph is built and all functions are transformed to SSA form. */
501 CGRAPH_STATE_IPA_SSA,
f45e0ad1
JH
502 /* Functions are now ordered and being passed to RTL expanders. */
503 CGRAPH_STATE_EXPANSION,
504 /* All cgraph expansion is done. */
505 CGRAPH_STATE_FINISHED
506};
507extern enum cgraph_state cgraph_state;
e7d6beb0 508extern bool cgraph_function_flags_ready;
66058468 509extern cgraph_node_set cgraph_new_nodes;
1c4a429a 510
65d630d4 511extern GTY(()) struct asm_node *asm_nodes;
2aae7680 512extern GTY(()) int symtab_order;
39e2db00 513extern bool same_body_aliases_done;
e69529cd 514
2aae7680
JH
515/* In symtab.c */
516void symtab_register_node (symtab_node);
517void symtab_unregister_node (symtab_node);
518void symtab_remove_node (symtab_node);
1ab24192
JH
519symtab_node symtab_get_node (const_tree);
520symtab_node symtab_node_for_asm (const_tree asmname);
8f940ee6
JH
521const char * symtab_node_asm_name (symtab_node);
522const char * symtab_node_name (symtab_node);
1ab24192 523void symtab_insert_node_to_hashtable (symtab_node);
65d630d4
JH
524void symtab_add_to_same_comdat_group (symtab_node, symtab_node);
525void symtab_dissolve_same_comdat_group_list (symtab_node node);
8f940ee6
JH
526void dump_symtab (FILE *);
527void debug_symtab (void);
528void dump_symtab_node (FILE *, symtab_node);
529void debug_symtab_node (symtab_node);
530void dump_symtab_base (FILE *, symtab_node);
474ffc72
JH
531void verify_symtab (void);
532void verify_symtab_node (symtab_node);
533bool verify_symtab_base (symtab_node);
65d630d4
JH
534bool symtab_used_from_object_file_p (symtab_node);
535void symtab_make_decl_local (tree);
2aae7680 536
1c4a429a 537/* In cgraph.c */
439f7bc3 538void dump_cgraph (FILE *);
c4e622b6 539void debug_cgraph (void);
18c6ada9 540void dump_cgraph_node (FILE *, struct cgraph_node *);
c4e622b6 541void debug_cgraph_node (struct cgraph_node *);
18c6ada9 542void cgraph_remove_edge (struct cgraph_edge *);
439f7bc3 543void cgraph_remove_node (struct cgraph_node *);
3a40c18a 544void cgraph_release_function_body (struct cgraph_node *);
2563c224 545void cgraph_node_remove_callees (struct cgraph_node *node);
18c6ada9
JH
546struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
547 struct cgraph_node *,
898b8927 548 gimple, gcov_type, int);
ce47fda3 549struct cgraph_edge *cgraph_create_indirect_edge (struct cgraph_node *, gimple,
898b8927 550 int, gcov_type, int);
ce47fda3 551struct cgraph_indirect_call_info *cgraph_allocate_init_indirect_info (void);
a358e188 552struct cgraph_node * cgraph_create_node (tree);
66a20fc2 553struct cgraph_node * cgraph_create_empty_node (void);
a358e188 554struct cgraph_node * cgraph_get_create_node (tree);
87e7b310
JH
555struct cgraph_node * cgraph_same_body_alias (struct cgraph_node *, tree, tree);
556struct cgraph_node * cgraph_add_thunk (struct cgraph_node *, tree, tree, bool, HOST_WIDE_INT,
051f8cc6 557 HOST_WIDE_INT, tree, tree);
4537ec0c 558struct cgraph_node *cgraph_node_for_asm (tree);
726a989a
RB
559struct cgraph_edge *cgraph_edge (struct cgraph_node *, gimple);
560void cgraph_set_call_stmt (struct cgraph_edge *, gimple);
4b685e14 561void cgraph_update_edges_for_call_stmt (gimple, tree, gimple);
439f7bc3
AJ
562struct cgraph_local_info *cgraph_local_info (tree);
563struct cgraph_global_info *cgraph_global_info (tree);
564struct cgraph_rtl_info *cgraph_rtl_info (tree);
39e2db00 565struct cgraph_node *cgraph_create_function_alias (tree, tree);
66a20fc2
JH
566void cgraph_call_node_duplication_hooks (struct cgraph_node *,
567 struct cgraph_node *);
568void cgraph_call_edge_duplication_hooks (struct cgraph_edge *,
569 struct cgraph_edge *);
1c4a429a 570
18c6ada9 571void cgraph_redirect_edge_callee (struct cgraph_edge *, struct cgraph_node *);
81fa35bd 572void cgraph_make_edge_direct (struct cgraph_edge *, struct cgraph_node *);
be330ed4 573bool cgraph_only_called_directly_p (struct cgraph_node *);
e69529cd 574
1bb17c21 575bool cgraph_function_possibly_inlined_p (tree);
e42922b1 576void cgraph_unnest_node (struct cgraph_node *);
1bb17c21 577
6b02a499 578enum availability cgraph_function_body_availability (struct cgraph_node *);
f45e0ad1 579void cgraph_add_new_function (tree, bool);
61a05df1 580const char* cgraph_inline_failed_string (cgraph_inline_failed_t);
6b02a499 581
20cdc2be 582void cgraph_set_nothrow_flag (struct cgraph_node *, bool);
530f3a1b
JH
583void cgraph_set_const_flag (struct cgraph_node *, bool, bool);
584void cgraph_set_pure_flag (struct cgraph_node *, bool, bool);
d56026c2
JH
585bool cgraph_node_cannot_return (struct cgraph_node *);
586bool cgraph_edge_cannot_lead_to_return (struct cgraph_edge *);
508e4757
JH
587bool cgraph_will_be_removed_from_program_if_no_direct_calls
588 (struct cgraph_node *node);
589bool cgraph_can_remove_if_no_direct_calls_and_refs_p
590 (struct cgraph_node *node);
9aa3f5c5 591bool cgraph_can_remove_if_no_direct_calls_p (struct cgraph_node *node);
be330ed4 592bool resolution_used_from_other_file_p (enum ld_plugin_symbol_resolution);
be330ed4
JH
593bool cgraph_for_node_thunks_and_aliases (struct cgraph_node *,
594 bool (*) (struct cgraph_node *, void *),
595 void *,
596 bool);
597bool cgraph_for_node_and_aliases (struct cgraph_node *,
598 bool (*) (struct cgraph_node *, void *),
599 void *, bool);
600VEC (cgraph_edge_p, heap) * collect_callers_of_node (struct cgraph_node *node);
18c6ada9
JH
601void verify_cgraph (void);
602void verify_cgraph_node (struct cgraph_node *);
9c8305f8 603void cgraph_mark_address_taken_node (struct cgraph_node *);
d7f09764 604
9088c1cc
MJ
605typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
606typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
607typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
608 void *);
609typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
610 void *);
611struct cgraph_edge_hook_list;
612struct cgraph_node_hook_list;
613struct cgraph_2edge_hook_list;
614struct cgraph_2node_hook_list;
615struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
616void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
617struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
618 void *);
619void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
129a37fc
JH
620struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
621 void *);
622void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
623void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
9088c1cc
MJ
624struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
625void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
626struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
627void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
8132a837 628gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
fa5f5e27 629bool cgraph_propagate_frequency (struct cgraph_node *node);
9c8305f8
JH
630
631/* In cgraphunit.c */
65d630d4 632struct asm_node *add_asm_node (tree);
9c8305f8
JH
633extern FILE *cgraph_dump_file;
634void cgraph_finalize_function (tree, bool);
65d630d4
JH
635void finalize_compilation_unit (void);
636void compile (void);
9c8305f8 637void init_cgraph (void);
66a20fc2
JH
638bool cgraph_process_new_functions (void);
639void cgraph_process_same_body_aliases (void);
640void fixup_same_cpp_alias_visibility (symtab_node node, symtab_node target, tree alias);
641
642/* In cgraphclones.c */
643
644struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
645 struct cgraph_node *, gimple,
646 unsigned, gcov_type, int, bool);
647struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
648 int, bool, VEC(cgraph_edge_p,heap) *,
649 bool);
650tree clone_function_name (tree decl, const char *);
651struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
652 VEC(cgraph_edge_p,heap)*,
653 VEC(ipa_replace_map_p,gc)* tree_map,
654 bitmap args_to_skip,
655 const char *clone_name);
656struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
657bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
658void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple);
659void cgraph_create_edge_including_clones (struct cgraph_node *,
660 struct cgraph_node *,
661 gimple, gimple, gcov_type, int,
662 cgraph_inline_failed_t);
663void cgraph_materialize_all_clones (void);
9c8305f8
JH
664struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
665 tree, VEC(cgraph_edge_p,heap)*, bitmap);
666struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
667 VEC(cgraph_edge_p,heap)*,
668 VEC(ipa_replace_map_p,gc)*,
669 bitmap, bool, bitmap,
670 basic_block, const char *);
671void tree_function_versioning (tree, tree, VEC (ipa_replace_map_p,gc)*,
672 bool, bitmap, bool, bitmap, basic_block);
9c8305f8 673
917948d3
ZD
674/* In cgraphbuild.c */
675unsigned int rebuild_cgraph_edges (void);
99b766fc 676void cgraph_rebuild_references (void);
9187e02d 677int compute_call_stmt_bb_frequency (tree, basic_block bb);
9c8305f8 678void record_references_in_initializer (tree, bool);
917948d3 679
ca31b95f 680/* In ipa.c */
04142cc3 681bool symtab_remove_unreachable_nodes (bool, FILE *);
fed5ae11
DK
682cgraph_node_set cgraph_node_set_new (void);
683cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
684 struct cgraph_node *);
685void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
686void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
687void dump_cgraph_node_set (FILE *, cgraph_node_set);
688void debug_cgraph_node_set (cgraph_node_set);
1cb1a99f 689void free_cgraph_node_set (cgraph_node_set);
9c8305f8 690void cgraph_build_static_cdtor (char which, tree body, int priority);
fed5ae11 691
2942c502
JH
692varpool_node_set varpool_node_set_new (void);
693varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
694 struct varpool_node *);
695void varpool_node_set_add (varpool_node_set, struct varpool_node *);
696void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
697void dump_varpool_node_set (FILE *, varpool_node_set);
698void debug_varpool_node_set (varpool_node_set);
1cb1a99f 699void free_varpool_node_set (varpool_node_set);
4a444e58 700void ipa_discover_readonly_nonaddressable_vars (void);
430c6ceb 701bool cgraph_comdat_can_be_unshared_p (struct cgraph_node *);
38877e98 702bool varpool_externally_visible_p (struct varpool_node *, bool);
ca31b95f 703
fed5ae11 704/* In predict.c */
ca30a539 705bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
e6416b30 706bool cgraph_optimize_for_size_p (struct cgraph_node *);
ca30a539 707
8a4a83ed 708/* In varpool.c */
5d59b5e1 709struct varpool_node *varpool_node_for_decl (tree);
8a4a83ed
JH
710struct varpool_node *varpool_node_for_asm (tree asmname);
711void varpool_mark_needed_node (struct varpool_node *);
d85478c2 712void debug_varpool (void);
8a4a83ed
JH
713void dump_varpool (FILE *);
714void dump_varpool_node (FILE *, struct varpool_node *);
715
716void varpool_finalize_decl (tree);
717bool decide_is_variable_needed (struct varpool_node *, tree);
718enum availability cgraph_variable_initializer_availability (struct varpool_node *);
a550d677
MJ
719void cgraph_make_node_local (struct cgraph_node *);
720bool cgraph_node_can_be_local_p (struct cgraph_node *);
8a4a83ed 721
2942c502 722
2942c502 723void varpool_remove_node (struct varpool_node *node);
7fece979 724void varpool_finalize_named_section_flags (struct varpool_node *node);
65d630d4 725bool varpool_output_variables (void);
8a4a83ed 726bool varpool_assemble_decl (struct varpool_node *node);
66058468 727void varpool_analyze_node (struct varpool_node *);
051f8cc6 728struct varpool_node * varpool_extra_name_alias (tree, tree);
cd35bcf7 729struct varpool_node * varpool_create_variable_alias (tree, tree);
b34fd25c 730void varpool_reset_queue (void);
64e0f5ff 731bool const_value_known_p (tree);
cd35bcf7
JH
732bool varpool_for_node_and_aliases (struct varpool_node *,
733 bool (*) (struct varpool_node *, void *),
734 void *, bool);
38877e98 735void varpool_add_new_variable (tree);
b5493fb2
JH
736void symtab_initialize_asm_name_hash (void);
737void symtab_prevail_in_asm_name_hash (symtab_node node);
8a4a83ed 738
68e56cc4 739
1f00098b
JH
740/* Return callgraph node for given symbol and check it is a function. */
741static inline struct cgraph_node *
960bfb69 742cgraph (symtab_node node)
1f00098b 743{
960bfb69 744 gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION);
1ab24192 745 return (struct cgraph_node *)node;
1f00098b
JH
746}
747
748/* Return varpool node for given symbol and check it is a variable. */
749static inline struct varpool_node *
960bfb69 750varpool (symtab_node node)
1f00098b 751{
960bfb69 752 gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE);
1ab24192 753 return (struct varpool_node *)node;
1f00098b
JH
754}
755
1ab24192
JH
756/* Return callgraph node for given symbol and check it is a function. */
757static inline struct cgraph_node *
758cgraph_get_node (const_tree decl)
759{
760 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
761 return cgraph (symtab_get_node (decl));
762}
763
764/* Return varpool node for given symbol and check it is a function. */
765static inline struct varpool_node *
766varpool_get_node (const_tree decl)
767{
768 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
769 return varpool (symtab_get_node (decl));
770}
771
8f940ee6
JH
772/* Return asm name of cgraph node. */
773static inline const char *
774cgraph_node_asm_name(struct cgraph_node *node)
775{
776 return symtab_node_asm_name ((symtab_node)node);
777}
778
779/* Return asm name of varpool node. */
780static inline const char *
781varpool_node_asm_name(struct varpool_node *node)
782{
783 return symtab_node_asm_name ((symtab_node)node);
784}
785
786/* Return name of cgraph node. */
787static inline const char *
788cgraph_node_name(struct cgraph_node *node)
789{
790 return symtab_node_name ((symtab_node)node);
791}
792
793/* Return name of varpool node. */
794static inline const char *
795varpool_node_name(struct varpool_node *node)
796{
797 return symtab_node_name ((symtab_node)node);
798}
799
1ab24192
JH
800/* Walk all symbols. */
801#define FOR_EACH_SYMBOL(node) \
802 for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next)
1f00098b 803
66058468
JH
804
805/* Return first variable. */
806static inline struct varpool_node *
807varpool_first_variable (void)
808{
809 symtab_node node;
810 for (node = symtab_nodes; node; node = node->symbol.next)
5d59b5e1
LC
811 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
812 return vnode;
66058468
JH
813 return NULL;
814}
815
816/* Return next variable after NODE. */
817static inline struct varpool_node *
818varpool_next_variable (struct varpool_node *node)
819{
820 symtab_node node1 = (symtab_node) node->symbol.next;
821 for (; node1; node1 = node1->symbol.next)
5d59b5e1
LC
822 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
823 return vnode1;
66058468
JH
824 return NULL;
825}
826/* Walk all variables. */
827#define FOR_EACH_VARIABLE(node) \
828 for ((node) = varpool_first_variable (); \
829 (node); \
830 (node) = varpool_next_variable ((node)))
831
68e56cc4
JH
832/* Return first reachable static variable with initializer. */
833static inline struct varpool_node *
834varpool_first_static_initializer (void)
835{
66058468
JH
836 symtab_node node;
837 for (node = symtab_nodes; node; node = node->symbol.next)
68e56cc4 838 {
5d59b5e1
LC
839 varpool_node *vnode = dyn_cast <varpool_node> (node);
840 if (vnode && DECL_INITIAL (node->symbol.decl))
841 return vnode;
68e56cc4
JH
842 }
843 return NULL;
844}
845
846/* Return next reachable static variable with initializer after NODE. */
847static inline struct varpool_node *
848varpool_next_static_initializer (struct varpool_node *node)
849{
66058468
JH
850 symtab_node node1 = (symtab_node) node->symbol.next;
851 for (; node1; node1 = node1->symbol.next)
68e56cc4 852 {
5d59b5e1
LC
853 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
854 if (vnode1 && DECL_INITIAL (node1->symbol.decl))
855 return vnode1;
68e56cc4
JH
856 }
857 return NULL;
858}
859
860/* Walk all static variables with initializer set. */
861#define FOR_EACH_STATIC_INITIALIZER(node) \
862 for ((node) = varpool_first_static_initializer (); (node); \
863 (node) = varpool_next_static_initializer (node))
2aae7680 864
66058468 865/* Return first reachable static variable with initializer. */
2aae7680 866static inline struct varpool_node *
66058468 867varpool_first_defined_variable (void)
2aae7680
JH
868{
869 symtab_node node;
870 for (node = symtab_nodes; node; node = node->symbol.next)
871 {
5d59b5e1
LC
872 varpool_node *vnode = dyn_cast <varpool_node> (node);
873 if (vnode && vnode->analyzed)
874 return vnode;
2aae7680
JH
875 }
876 return NULL;
877}
878
66058468 879/* Return next reachable static variable with initializer after NODE. */
2aae7680 880static inline struct varpool_node *
66058468 881varpool_next_defined_variable (struct varpool_node *node)
2aae7680
JH
882{
883 symtab_node node1 = (symtab_node) node->symbol.next;
884 for (; node1; node1 = node1->symbol.next)
885 {
5d59b5e1
LC
886 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
887 if (vnode1 && vnode1->analyzed)
888 return vnode1;
2aae7680
JH
889 }
890 return NULL;
891}
65c70e6b
JH
892/* Walk all variables with definitions in current unit. */
893#define FOR_EACH_DEFINED_VARIABLE(node) \
66058468
JH
894 for ((node) = varpool_first_defined_variable (); (node); \
895 (node) = varpool_next_defined_variable (node))
68e56cc4 896
c47d0034
JH
897/* Return first function with body defined. */
898static inline struct cgraph_node *
899cgraph_first_defined_function (void)
900{
2aae7680
JH
901 symtab_node node;
902 for (node = symtab_nodes; node; node = node->symbol.next)
c47d0034 903 {
5d59b5e1
LC
904 cgraph_node *cn = dyn_cast <cgraph_node> (node);
905 if (cn && cn->analyzed)
906 return cn;
c47d0034
JH
907 }
908 return NULL;
909}
910
45896127 911/* Return next function with body defined after NODE. */
c47d0034
JH
912static inline struct cgraph_node *
913cgraph_next_defined_function (struct cgraph_node *node)
914{
2aae7680
JH
915 symtab_node node1 = (symtab_node) node->symbol.next;
916 for (; node1; node1 = node1->symbol.next)
c47d0034 917 {
5d59b5e1
LC
918 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
919 if (cn1 && cn1->analyzed)
920 return cn1;
c47d0034
JH
921 }
922 return NULL;
923}
924
925/* Walk all functions with body defined. */
926#define FOR_EACH_DEFINED_FUNCTION(node) \
927 for ((node) = cgraph_first_defined_function (); (node); \
2aae7680
JH
928 (node) = cgraph_next_defined_function ((node)))
929
930/* Return first function. */
931static inline struct cgraph_node *
932cgraph_first_function (void)
933{
934 symtab_node node;
935 for (node = symtab_nodes; node; node = node->symbol.next)
5d59b5e1
LC
936 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
937 return cn;
2aae7680
JH
938 return NULL;
939}
940
941/* Return next function. */
942static inline struct cgraph_node *
943cgraph_next_function (struct cgraph_node *node)
944{
945 symtab_node node1 = (symtab_node) node->symbol.next;
946 for (; node1; node1 = node1->symbol.next)
5d59b5e1
LC
947 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
948 return cn1;
2aae7680
JH
949 return NULL;
950}
65c70e6b
JH
951/* Walk all functions. */
952#define FOR_EACH_FUNCTION(node) \
2aae7680
JH
953 for ((node) = cgraph_first_function (); (node); \
954 (node) = cgraph_next_function ((node)))
c47d0034
JH
955
956/* Return true when NODE is a function with Gimple body defined
957 in current unit. Functions can also be define externally or they
958 can be thunks with no Gimple representation.
959
960 Note that at WPA stage, the function body may not be present in memory. */
961
962static inline bool
963cgraph_function_with_gimple_body_p (struct cgraph_node *node)
964{
39e2db00 965 return node->analyzed && !node->thunk.thunk_p && !node->alias;
c47d0034
JH
966}
967
968/* Return first function with body defined. */
969static inline struct cgraph_node *
970cgraph_first_function_with_gimple_body (void)
971{
2aae7680
JH
972 symtab_node node;
973 for (node = symtab_nodes; node; node = node->symbol.next)
c47d0034 974 {
5d59b5e1
LC
975 cgraph_node *cn = dyn_cast <cgraph_node> (node);
976 if (cn && cgraph_function_with_gimple_body_p (cn))
977 return cn;
c47d0034
JH
978 }
979 return NULL;
980}
981
982/* Return next reachable static variable with initializer after NODE. */
983static inline struct cgraph_node *
984cgraph_next_function_with_gimple_body (struct cgraph_node *node)
985{
2aae7680
JH
986 symtab_node node1 = node->symbol.next;
987 for (; node1; node1 = node1->symbol.next)
c47d0034 988 {
5d59b5e1
LC
989 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
990 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
991 return cn1;
c47d0034
JH
992 }
993 return NULL;
994}
995
996/* Walk all functions with body defined. */
997#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
998 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
999 (node) = cgraph_next_function_with_gimple_body (node))
1000
43d861a5
RL
1001/* Create a new static variable of type TYPE. */
1002tree add_new_static_var (tree type);
1003
fed5ae11
DK
1004/* Return true if iterator CSI points to nothing. */
1005static inline bool
1006csi_end_p (cgraph_node_set_iterator csi)
1007{
1008 return csi.index >= VEC_length (cgraph_node_ptr, csi.set->nodes);
1009}
1010
1011/* Advance iterator CSI. */
1012static inline void
1013csi_next (cgraph_node_set_iterator *csi)
1014{
1015 csi->index++;
1016}
1017
1018/* Return the node pointed to by CSI. */
1019static inline struct cgraph_node *
1020csi_node (cgraph_node_set_iterator csi)
1021{
1022 return VEC_index (cgraph_node_ptr, csi.set->nodes, csi.index);
1023}
1024
1025/* Return an iterator to the first node in SET. */
1026static inline cgraph_node_set_iterator
1027csi_start (cgraph_node_set set)
1028{
1029 cgraph_node_set_iterator csi;
1030
1031 csi.set = set;
1032 csi.index = 0;
1033 return csi;
1034}
1035
1036/* Return true if SET contains NODE. */
1037static inline bool
1038cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1039{
1040 cgraph_node_set_iterator csi;
1041 csi = cgraph_node_set_find (set, node);
1042 return !csi_end_p (csi);
1043}
1044
1045/* Return number of nodes in SET. */
1046static inline size_t
1047cgraph_node_set_size (cgraph_node_set set)
1048{
1cb1a99f 1049 return VEC_length (cgraph_node_ptr, set->nodes);
fed5ae11
DK
1050}
1051
2942c502
JH
1052/* Return true if iterator VSI points to nothing. */
1053static inline bool
1054vsi_end_p (varpool_node_set_iterator vsi)
1055{
1056 return vsi.index >= VEC_length (varpool_node_ptr, vsi.set->nodes);
1057}
1058
1059/* Advance iterator VSI. */
1060static inline void
1061vsi_next (varpool_node_set_iterator *vsi)
1062{
1063 vsi->index++;
1064}
1065
1066/* Return the node pointed to by VSI. */
1067static inline struct varpool_node *
1068vsi_node (varpool_node_set_iterator vsi)
1069{
1070 return VEC_index (varpool_node_ptr, vsi.set->nodes, vsi.index);
1071}
1072
1073/* Return an iterator to the first node in SET. */
1074static inline varpool_node_set_iterator
1075vsi_start (varpool_node_set set)
1076{
1077 varpool_node_set_iterator vsi;
1078
1079 vsi.set = set;
1080 vsi.index = 0;
1081 return vsi;
1082}
1083
1084/* Return true if SET contains NODE. */
1085static inline bool
1086varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1087{
1088 varpool_node_set_iterator vsi;
1089 vsi = varpool_node_set_find (set, node);
1090 return !vsi_end_p (vsi);
1091}
1092
1093/* Return number of nodes in SET. */
1094static inline size_t
1095varpool_node_set_size (varpool_node_set set)
1096{
1cb1a99f 1097 return VEC_length (varpool_node_ptr, set->nodes);
2942c502
JH
1098}
1099
d48e9cea
OR
1100/* Uniquize all constants that appear in memory.
1101 Each constant in memory thus far output is recorded
1102 in `const_desc_table'. */
1103
1104struct GTY(()) constant_descriptor_tree {
1105 /* A MEM for the constant. */
1106 rtx rtl;
b8698a0f 1107
d48e9cea
OR
1108 /* The value of the constant. */
1109 tree value;
1110
1111 /* Hash of value. Computing the hash from value each time
1112 hashfn is called can't work properly, as that means recursive
1113 use of the hash table during hash table expansion. */
1114 hashval_t hash;
1115};
1116
ace72c88
JH
1117/* Return true if set is nonempty. */
1118static inline bool
1119cgraph_node_set_nonempty_p (cgraph_node_set set)
1120{
9eec9488 1121 return !VEC_empty (cgraph_node_ptr, set->nodes);
ace72c88
JH
1122}
1123
1124/* Return true if set is nonempty. */
1125static inline bool
1126varpool_node_set_nonempty_p (varpool_node_set set)
1127{
9eec9488 1128 return !VEC_empty (varpool_node_ptr, set->nodes);
ace72c88
JH
1129}
1130
be330ed4 1131/* Return true when function NODE is only called directly or it has alias.
b20996ff
JH
1132 i.e. it is not externally visible, address was not taken and
1133 it is not used in any other non-standard way. */
1134
1135static inline bool
be330ed4 1136cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
b20996ff 1137{
530f3a1b 1138 gcc_assert (!node->global.inlined_to);
ead84f73 1139 return (!node->symbol.force_output && !node->symbol.address_taken
960bfb69
JH
1140 && !node->symbol.used_from_other_partition
1141 && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
1142 && !DECL_STATIC_DESTRUCTOR (node->symbol.decl)
1143 && !node->symbol.externally_visible);
b20996ff
JH
1144}
1145
df7705b1
JH
1146/* Return true when function NODE can be removed from callgraph
1147 if all direct calls are eliminated. */
1148
1149static inline bool
1150varpool_can_remove_if_no_refs (struct varpool_node *node)
1151{
6649df51
JH
1152 if (DECL_EXTERNAL (node->symbol.decl))
1153 return true;
ead84f73 1154 return (!node->symbol.force_output && !node->symbol.used_from_other_partition
3d2e04fd
JH
1155 && ((DECL_COMDAT (node->symbol.decl)
1156 && !symtab_used_from_object_file_p ((symtab_node) node))
6649df51
JH
1157 || !node->symbol.externally_visible
1158 || DECL_HAS_VALUE_EXPR_P (node->symbol.decl)));
df7705b1
JH
1159}
1160
4a444e58
JH
1161/* Return true when all references to VNODE must be visible in ipa_ref_list.
1162 i.e. if the variable is not externally visible or not used in some magic
1163 way (asm statement or such).
61502ca8 1164 The magic uses are all summarized in force_output flag. */
4a444e58
JH
1165
1166static inline bool
1167varpool_all_refs_explicit_p (struct varpool_node *vnode)
1168{
e8fdf1cd 1169 return (vnode->analyzed
960bfb69
JH
1170 && !vnode->symbol.externally_visible
1171 && !vnode->symbol.used_from_other_partition
ead84f73 1172 && !vnode->symbol.force_output);
4a444e58
JH
1173}
1174
d48e9cea
OR
1175/* Constant pool accessor function. */
1176htab_t constant_pool_htab (void);
fed5ae11 1177
be330ed4
JH
1178/* FIXME: inappropriate dependency of cgraph on IPA. */
1179#include "ipa-ref-inline.h"
1180
39e2db00
JH
1181/* Return node that alias N is aliasing. */
1182
1183static inline struct cgraph_node *
1184cgraph_alias_aliased_node (struct cgraph_node *n)
1185{
1186 struct ipa_ref *ref;
1187
960bfb69 1188 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
39e2db00 1189 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
5d59b5e1 1190 if (is_a <cgraph_node> (ref->referred))
39e2db00
JH
1191 return ipa_ref_node (ref);
1192 return NULL;
1193}
1194
cd35bcf7
JH
1195/* Return node that alias N is aliasing. */
1196
1197static inline struct varpool_node *
1198varpool_alias_aliased_node (struct varpool_node *n)
1199{
1200 struct ipa_ref *ref;
1201
960bfb69 1202 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
cd35bcf7 1203 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
5d59b5e1 1204 if (is_a <varpool_node> (ref->referred))
cd35bcf7
JH
1205 return ipa_ref_varpool_node (ref);
1206 return NULL;
1207}
1208
be330ed4
JH
1209/* Given NODE, walk the alias chain to return the function NODE is alias of.
1210 Walk through thunk, too.
073a8998 1211 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
be330ed4
JH
1212
1213static inline struct cgraph_node *
1214cgraph_function_node (struct cgraph_node *node, enum availability *availability)
1215{
1216 if (availability)
1217 *availability = cgraph_function_body_availability (node);
1218 while (node)
1219 {
39e2db00
JH
1220 if (node->alias && node->analyzed)
1221 node = cgraph_alias_aliased_node (node);
1222 else if (node->thunk.thunk_p)
be330ed4
JH
1223 node = node->callees->callee;
1224 else
1225 return node;
39e2db00 1226 if (node && availability)
be330ed4
JH
1227 {
1228 enum availability a;
1229 a = cgraph_function_body_availability (node);
1230 if (a < *availability)
1231 *availability = a;
1232 }
1233 }
9c7c9f10 1234 if (availability)
39e2db00 1235 *availability = AVAIL_NOT_AVAILABLE;
be330ed4
JH
1236 return NULL;
1237}
1238
1239/* Given NODE, walk the alias chain to return the function NODE is alias of.
1240 Do not walk through thunks.
073a8998 1241 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
be330ed4
JH
1242
1243static inline struct cgraph_node *
1244cgraph_function_or_thunk_node (struct cgraph_node *node, enum availability *availability)
1245{
1246 if (availability)
1247 *availability = cgraph_function_body_availability (node);
39e2db00
JH
1248 while (node)
1249 {
1250 if (node->alias && node->analyzed)
1251 node = cgraph_alias_aliased_node (node);
1252 else
1253 return node;
1254 if (node && availability)
1255 {
1256 enum availability a;
1257 a = cgraph_function_body_availability (node);
1258 if (a < *availability)
1259 *availability = a;
1260 }
1261 }
9c7c9f10 1262 if (availability)
39e2db00 1263 *availability = AVAIL_NOT_AVAILABLE;
be330ed4
JH
1264 return NULL;
1265}
1266
cd35bcf7
JH
1267/* Given NODE, walk the alias chain to return the function NODE is alias of.
1268 Do not walk through thunks.
073a8998 1269 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
cd35bcf7
JH
1270
1271static inline struct varpool_node *
1272varpool_variable_node (struct varpool_node *node, enum availability *availability)
1273{
1274 if (availability)
1275 *availability = cgraph_variable_initializer_availability (node);
1276 while (node)
1277 {
1278 if (node->alias && node->analyzed)
1279 node = varpool_alias_aliased_node (node);
1280 else
1281 return node;
1282 if (node && availability)
1283 {
1284 enum availability a;
1285 a = cgraph_variable_initializer_availability (node);
1286 if (a < *availability)
1287 *availability = a;
1288 }
1289 }
9c7c9f10 1290 if (availability)
cd35bcf7
JH
1291 *availability = AVAIL_NOT_AVAILABLE;
1292 return NULL;
1293}
1294
d7d1d041
RG
1295/* Return true when the edge E represents a direct recursion. */
1296static inline bool
1297cgraph_edge_recursive_p (struct cgraph_edge *e)
1298{
be330ed4 1299 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
d7d1d041 1300 if (e->caller->global.inlined_to)
960bfb69 1301 return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl;
d7d1d041 1302 else
960bfb69 1303 return e->caller->symbol.decl == callee->symbol.decl;
d7d1d041 1304}
0a35513e
AH
1305
1306/* Return true if the TM_CLONE bit is set for a given FNDECL. */
1307static inline bool
1308decl_is_tm_clone (const_tree fndecl)
1309{
1310 struct cgraph_node *n = cgraph_get_node (fndecl);
1311 if (n)
1312 return n->tm_clone;
1313 return false;
1314}
9c8305f8
JH
1315
1316/* Likewise indicate that a node is needed, i.e. reachable via some
1317 external means. */
1318
1319static inline void
1320cgraph_mark_force_output_node (struct cgraph_node *node)
1321{
1322 node->symbol.force_output = 1;
1323 gcc_checking_assert (!node->global.inlined_to);
1324}
65d630d4 1325
b5493fb2
JH
1326/* Return true when the symbol is real symbol, i.e. it is not inline clone
1327 or extern function kept around just for inlining. */
1328
1329static inline bool
1330symtab_real_symbol_p (symtab_node node)
1331{
1332 struct cgraph_node *cnode;
1333 struct ipa_ref *ref;
1334
5d59b5e1 1335 if (!is_a <cgraph_node> (node))
b5493fb2
JH
1336 return true;
1337 cnode = cgraph (node);
1338 if (cnode->global.inlined_to)
1339 return false;
1340 if (cnode->abstract_and_needed)
1341 return false;
1342 /* We keep virtual clones in symtab. */
1343 if (!cnode->analyzed
1344 || DECL_EXTERNAL (cnode->symbol.decl))
1345 return (cnode->callers
1346 || ipa_ref_list_referring_iterate (&cnode->symbol.ref_list, 0, ref));
1347 return true;
1348}
1c4a429a 1349#endif /* GCC_CGRAPH_H */