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