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