25 #include "plugin-api.h"
49 ENUM_BITFIELD (ld_plugin_symbol_resolution) resolution : 8;
55 unsigned definition : 1;
67 unsigned cpp_implicit_alias : 1;
70 unsigned analyzed : 1;
76 unsigned externally_visible : 1;
79 unsigned force_output : 1;
83 unsigned forced_by_abi : 1;
85 unsigned unique_name : 1;
93 unsigned used_from_other_partition : 1;
97 unsigned in_other_partition : 1;
104 unsigned address_taken : 1;
197 unsigned versionable : 1;
201 unsigned can_change_signature : 1;
205 unsigned redefined_extern_inline : 1;
208 unsigned tm_may_enter_irr : 1;
264 GTY ((nested_ptr (
union symtab_node_def,
"(struct cgraph_node *)(%h)",
"(symtab_node)%h")))
341 struct cgraph_function_version_info *
prev;
345 struct cgraph_function_version_info *
next;
414 #define DEFCIFCODE(code, string) CIF_ ## code,
417 #include "cif-code.def"
445 unsigned polymorphic : 1;
448 unsigned agg_contents : 1;
450 unsigned member_ptr : 1;
456 struct GTY((chain_next ("%h.next_caller
"), chain_prev ("%h.prev_caller
"))) cgraph_edge {
457 /* Expected number of executions: calculated in profile.c. */
459 struct cgraph_node *caller;
460 struct cgraph_node *callee;
461 struct cgraph_edge *prev_caller;
462 struct cgraph_edge *next_caller;
463 struct cgraph_edge *prev_callee;
464 struct cgraph_edge *next_callee;
466 /* Additional information about an indirect call. Not cleared when an edge
468 struct cgraph_indirect_call_info *indirect_info;
469 PTR GTY ((skip (""))) aux;
470 /* When equal to CIF_OK, inline this call. Otherwise, points to the
471 explanation why function was not inlined. */
472 cgraph_inline_failed_t inline_failed;
473 /* The stmt_uid of call_stmt. This is used by LTO to recover the call_stmt
474 when the function is serialized in. */
475 unsigned int lto_stmt_uid;
476 /* Expected frequency of executions within the function.
477 When set to CGRAPH_FREQ_BASE, the edge is expected to be called once
478 per function call. The range is 0 to CGRAPH_FREQ_MAX. */
480 /* Unique id of the edge. */
482 /* Whether this edge was made direct by indirect inlining. */
483 unsigned int indirect_inlining_edge : 1;
484 /* Whether this edge describes an indirect call with an undetermined
486 unsigned int indirect_unknown_callee : 1;
487 /* Whether this edge is still a dangling */
488 /* True if the corresponding CALL stmt cannot be inlined. */
489 unsigned int call_stmt_cannot_inline_p : 1;
490 /* Can this call throw externally? */
491 unsigned int can_throw_external : 1;
492 /* Edges with SPECULATIVE flag represents indirect calls that was
493 speculatively turned into direct (i.e. by profile feedback).
494 The final code sequence will have form:
496 if (call_target == expected_fn)
501 Every speculative call is represented by three components attached
502 to a same call statement:
503 1) a direct call (to expected_fn)
504 2) an indirect call (to call_target)
505 3) a IPA_REF_ADDR refrence to expected_fn.
507 Optimizers may later redirect direct call to clone, so 1) and 3)
508 do not need to necesarily agree with destination. */
509 unsigned int speculative : 1;
512 #define CGRAPH_FREQ_BASE 1000
513 #define CGRAPH_FREQ_MAX 100000
515 typedef struct cgraph_edge *cgraph_edge_p;
518 /* The varpool data structure.
519 Each static variable decl has assigned varpool_node. */
521 struct GTY(()) varpool_node {
522 struct symtab_node_base symbol;
524 /* Set when variable is scheduled to be assembled. */
528 /* Every top level asm statement is put into a asm_node. */
530 struct GTY(()) asm_node {
532 struct asm_node *next;
533 /* String for this asm node. */
535 /* Ordering of all cgraph nodes. */
539 /* Symbol table entry. */
540 union GTY((desc ("%h.symbol.type
"), chain_next ("%h.symbol.next
"),
541 chain_prev ("%h.symbol.previous
"))) symtab_node_def {
542 struct symtab_node_base GTY ((tag ("SYMTAB_SYMBOL"))) symbol;
543 /* To access the following fields,
544 use the use dyn_cast or as_a to obtain the concrete type. */
549 /* Report whether or not THIS symtab node is a function, aka cgraph_node. */
554 is_a_helper <cgraph_node>::test (symtab_node_def *p)
556 return p->symbol.type == SYMTAB_FUNCTION;
559 /* Report whether or not THIS symtab node is a vriable, aka varpool_node. */
564 is_a_helper <varpool_node>::test (symtab_node_def *p)
566 return p->symbol.type == SYMTAB_VARIABLE;
569 extern GTY(()) symtab_node symtab_nodes;
570 extern GTY(()) int cgraph_n_nodes;
571 extern GTY(()) int cgraph_max_uid;
572 extern GTY(()) int cgraph_edge_max_uid;
573 extern bool cgraph_global_info_ready;
576 /* Frontend is parsing and finalizing functions. */
577 CGRAPH_STATE_PARSING,
578 /* Callgraph is being constructed. It is safe to add new functions. */
579 CGRAPH_STATE_CONSTRUCTION,
580 /* Callgraph is being at LTO time. */
581 CGRAPH_LTO_STREAMING,
582 /* Callgraph is built and IPA passes are being run. */
584 /* Callgraph is built and all functions are transformed to SSA form. */
585 CGRAPH_STATE_IPA_SSA,
586 /* Functions are now ordered and being passed to RTL expanders. */
587 CGRAPH_STATE_EXPANSION,
588 /* All cgraph expansion is done. */
589 CGRAPH_STATE_FINISHED
591 extern enum cgraph_state cgraph_state;
592 extern bool cgraph_function_flags_ready;
593 extern cgraph_node_set cgraph_new_nodes;
595 extern GTY(()) struct asm_node *asm_nodes;
596 extern GTY(()) int symtab_order;
597 extern bool cpp_implicit_aliases_done;
600 void symtab_register_node (symtab_node);
601 void symtab_unregister_node (symtab_node);
602 void symtab_remove_node (symtab_node);
603 symtab_node symtab_get_node (const_tree);
604 symtab_node symtab_node_for_asm (const_tree asmname);
605 const char * symtab_node_asm_name (symtab_node);
606 const char * symtab_node_name (symtab_node);
607 void symtab_insert_node_to_hashtable (symtab_node);
608 void symtab_add_to_same_comdat_group (symtab_node, symtab_node);
609 void symtab_dissolve_same_comdat_group_list (symtab_node node);
610 void dump_symtab (FILE *);
611 void debug_symtab (void);
612 void dump_symtab_node (FILE *, symtab_node);
613 void debug_symtab_node (symtab_node);
614 void dump_symtab_base (FILE *, symtab_node);
615 void verify_symtab (void);
616 void verify_symtab_node (symtab_node);
617 bool verify_symtab_base (symtab_node);
618 bool symtab_used_from_object_file_p (symtab_node);
619 void symtab_make_decl_local (tree);
620 symtab_node symtab_alias_ultimate_target (symtab_node,
621 enum availability *avail = NULL);
622 bool symtab_resolve_alias (symtab_node node, symtab_node target);
623 void fixup_same_cpp_alias_visibility (symtab_node node, symtab_node target);
624 bool symtab_for_node_and_aliases (symtab_node,
625 bool (*) (symtab_node, void *),
628 symtab_node symtab_nonoverwritable_alias (symtab_node);
629 enum availability symtab_node_availability (symtab_node);
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 *);
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 *);
671 bool cgraph_function_possibly_inlined_p (tree);
672 void cgraph_unnest_node (struct cgraph_node *);
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);
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 *),
693 bool cgraph_for_node_and_aliases (struct cgraph_node *,
694 bool (*) (struct cgraph_node *, void *),
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 *);
701 typedef void (*cgraph_edge_hook)(struct cgraph_edge *, void *);
702 typedef void (*cgraph_node_hook)(struct cgraph_node *, void *);
703 typedef void (*cgraph_2edge_hook)(struct cgraph_edge *, struct cgraph_edge *,
705 typedef void (*cgraph_2node_hook)(struct cgraph_node *, struct cgraph_node *,
707 struct cgraph_edge_hook_list;
708 struct cgraph_node_hook_list;
709 struct cgraph_2edge_hook_list;
710 struct cgraph_2node_hook_list;
711 struct cgraph_edge_hook_list *cgraph_add_edge_removal_hook (cgraph_edge_hook, void *);
712 void cgraph_remove_edge_removal_hook (struct cgraph_edge_hook_list *);
713 struct cgraph_node_hook_list *cgraph_add_node_removal_hook (cgraph_node_hook,
715 void cgraph_remove_node_removal_hook (struct cgraph_node_hook_list *);
716 struct cgraph_node_hook_list *cgraph_add_function_insertion_hook (cgraph_node_hook,
718 void cgraph_remove_function_insertion_hook (struct cgraph_node_hook_list *);
719 void cgraph_call_function_insertion_hooks (struct cgraph_node *node);
720 struct cgraph_2edge_hook_list *cgraph_add_edge_duplication_hook (cgraph_2edge_hook, void *);
721 void cgraph_remove_edge_duplication_hook (struct cgraph_2edge_hook_list *);
722 struct cgraph_2node_hook_list *cgraph_add_node_duplication_hook (cgraph_2node_hook, void *);
723 void cgraph_remove_node_duplication_hook (struct cgraph_2node_hook_list *);
724 gimple cgraph_redirect_edge_call_stmt_to_callee (struct cgraph_edge *);
725 bool cgraph_propagate_frequency (struct cgraph_node *node);
726 struct cgraph_node * cgraph_function_node (struct cgraph_node *,
727 enum availability *avail = NULL);
728 bool cgraph_get_body (struct cgraph_node *node);
730 cgraph_turn_edge_to_speculative (struct cgraph_edge *,
731 struct cgraph_node *,
733 void cgraph_speculative_call_info (struct cgraph_edge *,
734 struct cgraph_edge *&,
735 struct cgraph_edge *&,
738 /* In cgraphunit.c */
739 struct asm_node *add_asm_node (tree);
740 extern FILE *cgraph_dump_file;
741 void cgraph_finalize_function (tree, bool);
742 void finalize_compilation_unit (void);
744 void init_cgraph (void);
745 bool cgraph_process_new_functions (void);
746 void cgraph_process_same_body_aliases (void);
747 void fixup_same_cpp_alias_visibility (symtab_node, symtab_node target, tree);
748 /* Initialize datastructures so DECL is a function in lowered gimple form.
749 IN_SSA is true if the gimple is in SSA. */
750 basic_block init_lowered_empty_function (tree, bool);
751 void cgraph_reset_node (struct cgraph_node *);
752 void expand_thunk (struct cgraph_node *);
754 /* In cgraphclones.c */
756 struct cgraph_edge * cgraph_clone_edge (struct cgraph_edge *,
757 struct cgraph_node *, gimple,
758 unsigned, gcov_type, int, bool);
759 struct cgraph_node * cgraph_clone_node (struct cgraph_node *, tree, gcov_type,
760 int, bool, vec<cgraph_edge_p>,
761 bool, struct cgraph_node *);
762 tree clone_function_name (tree decl, const char *);
763 struct cgraph_node * cgraph_create_virtual_clone (struct cgraph_node *old_node,
765 vec<ipa_replace_map_p, va_gc> *tree_map,
767 const char *clone_name);
768 struct cgraph_node *cgraph_find_replacement_node (struct cgraph_node *);
769 bool cgraph_remove_node_and_inline_clones (struct cgraph_node *, struct cgraph_node *);
770 void cgraph_set_call_stmt_including_clones (struct cgraph_node *, gimple, gimple,
771 bool update_speculative = true);
772 void cgraph_create_edge_including_clones (struct cgraph_node *,
773 struct cgraph_node *,
774 gimple, gimple, gcov_type, int,
775 cgraph_inline_failed_t);
776 void cgraph_materialize_all_clones (void);
777 struct cgraph_node * cgraph_copy_node_for_versioning (struct cgraph_node *,
778 tree, vec<cgraph_edge_p>, bitmap);
779 struct cgraph_node *cgraph_function_versioning (struct cgraph_node *,
781 vec<ipa_replace_map_p, va_gc> *,
782 bitmap, bool, bitmap,
783 basic_block, const char *);
784 void tree_function_versioning (tree, tree, vec<ipa_replace_map_p, va_gc> *,
785 bool, bitmap, bool, bitmap, basic_block);
786 struct cgraph_edge *cgraph_resolve_speculation (struct cgraph_edge *, tree);
788 /* In cgraphbuild.c */
789 unsigned int rebuild_cgraph_edges (void);
790 void cgraph_rebuild_references (void);
791 int compute_call_stmt_bb_frequency (tree, basic_block bb);
792 void record_references_in_initializer (tree, bool);
793 void ipa_record_stmt_references (struct cgraph_node *, gimple);
796 bool symtab_remove_unreachable_nodes (bool, FILE *);
797 cgraph_node_set cgraph_node_set_new (void);
798 cgraph_node_set_iterator cgraph_node_set_find (cgraph_node_set,
799 struct cgraph_node *);
800 void cgraph_node_set_add (cgraph_node_set, struct cgraph_node *);
801 void cgraph_node_set_remove (cgraph_node_set, struct cgraph_node *);
802 void dump_cgraph_node_set (FILE *, cgraph_node_set);
803 void debug_cgraph_node_set (cgraph_node_set);
804 void free_cgraph_node_set (cgraph_node_set);
805 void cgraph_build_static_cdtor (char which, tree body, int priority);
807 varpool_node_set varpool_node_set_new (void);
808 varpool_node_set_iterator varpool_node_set_find (varpool_node_set,
809 struct varpool_node *);
810 void varpool_node_set_add (varpool_node_set, struct varpool_node *);
811 void varpool_node_set_remove (varpool_node_set, struct varpool_node *);
812 void dump_varpool_node_set (FILE *, varpool_node_set);
813 void debug_varpool_node_set (varpool_node_set);
814 void free_varpool_node_set (varpool_node_set);
815 void ipa_discover_readonly_nonaddressable_vars (void);
816 bool varpool_externally_visible_p (struct varpool_node *);
819 bool cgraph_maybe_hot_edge_p (struct cgraph_edge *e);
820 bool cgraph_optimize_for_size_p (struct cgraph_node *);
823 struct varpool_node *varpool_create_empty_node (void);
824 struct varpool_node *varpool_node_for_decl (tree);
825 struct varpool_node *varpool_node_for_asm (tree asmname);
826 void varpool_mark_needed_node (struct varpool_node *);
827 void debug_varpool (void);
828 void dump_varpool (FILE *);
829 void dump_varpool_node (FILE *, struct varpool_node *);
831 void varpool_finalize_decl (tree);
832 enum availability cgraph_variable_initializer_availability (struct varpool_node *);
833 void cgraph_make_node_local (struct cgraph_node *);
834 bool cgraph_node_can_be_local_p (struct cgraph_node *);
837 void varpool_remove_node (struct varpool_node *node);
838 void varpool_finalize_named_section_flags (struct varpool_node *node);
839 bool varpool_output_variables (void);
840 bool varpool_assemble_decl (struct varpool_node *node);
841 void varpool_analyze_node (struct varpool_node *);
842 struct varpool_node * varpool_extra_name_alias (tree, tree);
843 struct varpool_node * varpool_create_variable_alias (tree, tree);
844 void varpool_reset_queue (void);
845 tree ctor_for_folding (tree);
846 bool varpool_for_node_and_aliases (struct varpool_node *,
847 bool (*) (struct varpool_node *, void *),
849 void varpool_add_new_variable (tree);
850 void symtab_initialize_asm_name_hash (void);
851 void symtab_prevail_in_asm_name_hash (symtab_node node);
852 void varpool_remove_initializer (struct varpool_node *);
855 /* Return callgraph node for given symbol and check it is a function. */
856 static inline struct cgraph_node *
857 cgraph (symtab_node node)
859 gcc_checking_assert (!node || node->symbol.type == SYMTAB_FUNCTION);
860 return (struct cgraph_node *)node;
863 /* Return varpool node for given symbol and check it is a variable. */
864 static inline struct varpool_node *
865 varpool (symtab_node node)
867 gcc_checking_assert (!node || node->symbol.type == SYMTAB_VARIABLE);
868 return (struct varpool_node *)node;
871 /* Return callgraph node for given symbol and check it is a function. */
872 static inline struct cgraph_node *
873 cgraph_get_node (const_tree decl)
875 gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
876 return cgraph (symtab_get_node (decl));
879 /* Return varpool node for given symbol and check it is a function. */
880 static inline struct varpool_node *
881 varpool_get_node (const_tree decl)
883 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
884 return varpool (symtab_get_node (decl));
887 /* Return asm name of cgraph node. */
888 static inline const char *
889 cgraph_node_asm_name (struct cgraph_node *node)
891 return symtab_node_asm_name ((symtab_node)node);
894 /* Return asm name of varpool node. */
895 static inline const char *
896 varpool_node_asm_name(struct varpool_node *node)
898 return symtab_node_asm_name ((symtab_node)node);
901 /* Return name of cgraph node. */
902 static inline const char *
903 cgraph_node_name(struct cgraph_node *node)
905 return symtab_node_name ((symtab_node)node);
908 /* Return name of varpool node. */
909 static inline const char *
910 varpool_node_name(struct varpool_node *node)
912 return symtab_node_name ((symtab_node)node);
915 /* Walk all symbols. */
916 #define FOR_EACH_SYMBOL(node) \
917 for ((node) = symtab_nodes; (node); (node) = (node)->symbol.next)
920 /* Return first variable. */
921 static inline struct varpool_node *
922 varpool_first_variable (void)
925 for (node = symtab_nodes; node; node = node->symbol.next)
926 if (varpool_node *vnode = dyn_cast <varpool_node> (node))
931 /* Return next variable after NODE. */
932 static inline struct varpool_node *
933 varpool_next_variable (struct varpool_node *node)
935 symtab_node node1 = (symtab_node) node->symbol.next;
936 for (; node1; node1 = node1->symbol.next)
937 if (varpool_node *vnode1 = dyn_cast <varpool_node> (node1))
941 /* Walk all variables. */
942 #define FOR_EACH_VARIABLE(node) \
943 for ((node) = varpool_first_variable (); \
945 (node) = varpool_next_variable ((node)))
947 /* Return first reachable static variable with initializer. */
948 static inline struct varpool_node *
949 varpool_first_static_initializer (void)
952 for (node = symtab_nodes; node; node = node->symbol.next)
954 varpool_node *vnode = dyn_cast <varpool_node> (node);
955 if (vnode && DECL_INITIAL (node->symbol.decl))
961 /* Return next reachable static variable with initializer after NODE. */
962 static inline struct varpool_node *
963 varpool_next_static_initializer (struct varpool_node *node)
965 symtab_node node1 = (symtab_node) node->symbol.next;
966 for (; node1; node1 = node1->symbol.next)
968 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
969 if (vnode1 && DECL_INITIAL (node1->symbol.decl))
975 /* Walk all static variables with initializer set. */
976 #define FOR_EACH_STATIC_INITIALIZER(node) \
977 for ((node) = varpool_first_static_initializer (); (node); \
978 (node) = varpool_next_static_initializer (node))
980 /* Return first reachable static variable with initializer. */
981 static inline struct varpool_node *
982 varpool_first_defined_variable (void)
985 for (node = symtab_nodes; node; node = node->symbol.next)
987 varpool_node *vnode = dyn_cast <varpool_node> (node);
988 if (vnode && vnode->symbol.definition)
994 /* Return next reachable static variable with initializer after NODE. */
995 static inline struct varpool_node *
996 varpool_next_defined_variable (struct varpool_node *node)
998 symtab_node node1 = (symtab_node) node->symbol.next;
999 for (; node1; node1 = node1->symbol.next)
1001 varpool_node *vnode1 = dyn_cast <varpool_node> (node1);
1002 if (vnode1 && vnode1->symbol.definition)
1007 /* Walk all variables with definitions in current unit. */
1008 #define FOR_EACH_DEFINED_VARIABLE(node) \
1009 for ((node) = varpool_first_defined_variable (); (node); \
1010 (node) = varpool_next_defined_variable (node))
1012 /* Return first function with body defined. */
1013 static inline struct cgraph_node *
1014 cgraph_first_defined_function (void)
1017 for (node = symtab_nodes; node; node = node->symbol.next)
1019 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1020 if (cn && cn->symbol.definition)
1026 /* Return next function with body defined after NODE. */
1027 static inline struct cgraph_node *
1028 cgraph_next_defined_function (struct cgraph_node *node)
1030 symtab_node node1 = (symtab_node) node->symbol.next;
1031 for (; node1; node1 = node1->symbol.next)
1033 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1034 if (cn1 && cn1->symbol.definition)
1040 /* Walk all functions with body defined. */
1041 #define FOR_EACH_DEFINED_FUNCTION(node) \
1042 for ((node) = cgraph_first_defined_function (); (node); \
1043 (node) = cgraph_next_defined_function ((node)))
1045 /* Return first function. */
1046 static inline struct cgraph_node *
1047 cgraph_first_function (void)
1050 for (node = symtab_nodes; node; node = node->symbol.next)
1051 if (cgraph_node *cn = dyn_cast <cgraph_node> (node))
1056 /* Return next function. */
1057 static inline struct cgraph_node *
1058 cgraph_next_function (struct cgraph_node *node)
1060 symtab_node node1 = (symtab_node) node->symbol.next;
1061 for (; node1; node1 = node1->symbol.next)
1062 if (cgraph_node *cn1 = dyn_cast <cgraph_node> (node1))
1066 /* Walk all functions. */
1067 #define FOR_EACH_FUNCTION(node) \
1068 for ((node) = cgraph_first_function (); (node); \
1069 (node) = cgraph_next_function ((node)))
1071 /* Return true when NODE is a function with Gimple body defined
1072 in current unit. Functions can also be define externally or they
1073 can be thunks with no Gimple representation.
1075 Note that at WPA stage, the function body may not be present in memory. */
1078 cgraph_function_with_gimple_body_p (struct cgraph_node *node)
1080 return node->symbol.definition && !node->thunk.thunk_p && !node->symbol.alias;
1083 /* Return first function with body defined. */
1084 static inline struct cgraph_node *
1085 cgraph_first_function_with_gimple_body (void)
1088 for (node = symtab_nodes; node; node = node->symbol.next)
1090 cgraph_node *cn = dyn_cast <cgraph_node> (node);
1091 if (cn && cgraph_function_with_gimple_body_p (cn))
1097 /* Return next reachable static variable with initializer after NODE. */
1098 static inline struct cgraph_node *
1099 cgraph_next_function_with_gimple_body (struct cgraph_node *node)
1101 symtab_node node1 = node->symbol.next;
1102 for (; node1; node1 = node1->symbol.next)
1104 cgraph_node *cn1 = dyn_cast <cgraph_node> (node1);
1105 if (cn1 && cgraph_function_with_gimple_body_p (cn1))
1111 /* Walk all functions with body defined. */
1112 #define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
1113 for ((node) = cgraph_first_function_with_gimple_body (); (node); \
1114 (node) = cgraph_next_function_with_gimple_body (node))
1116 /* Create a new static variable of type TYPE. */
1117 tree add_new_static_var (tree type);
1119 /* Return true if iterator CSI points to nothing. */
1121 csi_end_p (cgraph_node_set_iterator csi)
1123 return csi.index >= csi.set->nodes.length ();
1126 /* Advance iterator CSI. */
1128 csi_next (cgraph_node_set_iterator *csi)
1133 /* Return the node pointed to by CSI. */
1134 static inline struct cgraph_node *
1135 csi_node (cgraph_node_set_iterator csi)
1137 return csi.set->nodes[csi.index];
1140 /* Return an iterator to the first node in SET. */
1141 static inline cgraph_node_set_iterator
1142 csi_start (cgraph_node_set set)
1144 cgraph_node_set_iterator csi;
1151 /* Return true if SET contains NODE. */
1153 cgraph_node_in_set_p (struct cgraph_node *node, cgraph_node_set set)
1155 cgraph_node_set_iterator csi;
1156 csi = cgraph_node_set_find (set, node);
1157 return !csi_end_p (csi);
1160 /* Return number of nodes in SET. */
1161 static inline size_t
1162 cgraph_node_set_size (cgraph_node_set set)
1164 return set->nodes.length ();
1167 /* Return true if iterator VSI points to nothing. */
1169 vsi_end_p (varpool_node_set_iterator vsi)
1171 return vsi.index >= vsi.set->nodes.length ();
1174 /* Advance iterator VSI. */
1176 vsi_next (varpool_node_set_iterator *vsi)
1181 /* Return the node pointed to by VSI. */
1182 static inline struct varpool_node *
1183 vsi_node (varpool_node_set_iterator vsi)
1185 return vsi.set->nodes[vsi.index];
1188 /* Return an iterator to the first node in SET. */
1189 static inline varpool_node_set_iterator
1190 vsi_start (varpool_node_set set)
1192 varpool_node_set_iterator vsi;
1199 /* Return true if SET contains NODE. */
1201 varpool_node_in_set_p (struct varpool_node *node, varpool_node_set set)
1203 varpool_node_set_iterator vsi;
1204 vsi = varpool_node_set_find (set, node);
1205 return !vsi_end_p (vsi);
1208 /* Return number of nodes in SET. */
1209 static inline size_t
1210 varpool_node_set_size (varpool_node_set set)
1212 return set->nodes.length ();
1215 /* Uniquize all constants that appear in memory.
1216 Each constant in memory thus far output is recorded
1217 in `const_desc_table'. */
1219 struct GTY(()) constant_descriptor_tree {
1220 /* A MEM for the constant. */
1223 /* The value of the constant. */
1226 /* Hash of value. Computing the hash from value each time
1227 hashfn is called can't work properly, as that means recursive
1228 use of the hash table during hash table expansion. */
1232 /* Return true if set is nonempty. */
1234 cgraph_node_set_nonempty_p (cgraph_node_set set)
1236 return !set->nodes.is_empty ();
1239 /* Return true if set is nonempty. */
1241 varpool_node_set_nonempty_p (varpool_node_set set)
1243 return !set->nodes.is_empty ();
1246 /* Return true when function NODE is only called directly or it has alias.
1247 i.e. it is not externally visible, address was not taken and
1248 it is not used in any other non-standard way. */
1251 cgraph_only_called_directly_or_aliased_p (struct cgraph_node *node)
1253 gcc_assert (!node->global.inlined_to);
1254 return (!node->symbol.force_output && !node->symbol.address_taken
1255 && !node->symbol.used_from_other_partition
1256 && !DECL_VIRTUAL_P (node->symbol.decl)
1257 && !DECL_STATIC_CONSTRUCTOR (node->symbol.decl)
1258 && !DECL_STATIC_DESTRUCTOR (node->symbol.decl)
1259 && !node->symbol.externally_visible);
1262 /* Return true when function NODE can be removed from callgraph
1263 if all direct calls are eliminated. */
1266 varpool_can_remove_if_no_refs (struct varpool_node *node)
1268 if (DECL_EXTERNAL (node->symbol.decl))
1270 return (!node->symbol.force_output && !node->symbol.used_from_other_partition
1271 && ((DECL_COMDAT (node->symbol.decl)
1272 && !node->symbol.forced_by_abi
1273 && !symtab_used_from_object_file_p ((symtab_node) node))
1274 || !node->symbol.externally_visible
1275 || DECL_HAS_VALUE_EXPR_P (node->symbol.decl)));
1278 /* Return true when all references to VNODE must be visible in ipa_ref_list.
1279 i.e. if the variable is not externally visible or not used in some magic
1280 way (asm statement or such).
1281 The magic uses are all summarized in force_output flag. */
1284 varpool_all_refs_explicit_p (struct varpool_node *vnode)
1286 return (vnode->symbol.definition
1287 && !vnode->symbol.externally_visible
1288 && !vnode->symbol.used_from_other_partition
1289 && !vnode->symbol.force_output);
1292 /* Constant pool accessor function. */
1293 htab_t constant_pool_htab (void);
1295 /* FIXME: inappropriate dependency of cgraph on IPA. */
1296 #include "ipa-ref-
inline.h
"
1298 /* Return node that alias N is aliasing. */
1300 static inline symtab_node
1301 symtab_alias_target (symtab_node n)
1303 struct ipa_ref *ref;
1304 ipa_ref_list_reference_iterate (&n->symbol.ref_list, 0, ref);
1305 gcc_checking_assert (ref->use == IPA_REF_ALIAS);
1306 return ref->referred;
1309 static inline struct cgraph_node *
1310 cgraph_alias_target (struct cgraph_node *n)
1312 return dyn_cast <cgraph_node> (symtab_alias_target ((symtab_node) n));
1315 static inline struct varpool_node *
1316 varpool_alias_target (struct varpool_node *n)
1318 return dyn_cast <varpool_node> (symtab_alias_target ((symtab_node) n));
1321 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1322 Do not walk through thunks.
1323 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1325 static inline struct cgraph_node *
1326 cgraph_function_or_thunk_node (struct cgraph_node *node,
1327 enum availability *availability = NULL)
1329 struct cgraph_node *n;
1331 n = dyn_cast <cgraph_node> (symtab_alias_ultimate_target ((symtab_node)node,
1333 if (!n && availability)
1334 *availability = AVAIL_NOT_AVAILABLE;
1337 /* Given NODE, walk the alias chain to return the function NODE is alias of.
1338 Do not walk through thunks.
1339 When AVAILABILITY is non-NULL, get minimal availability in the chain. */
1341 static inline struct varpool_node *
1342 varpool_variable_node (struct varpool_node *node,
1343 enum availability *availability = NULL)
1345 struct varpool_node *n;
1347 n = dyn_cast <varpool_node> (symtab_alias_ultimate_target ((symtab_node)node,
1349 if (!n && availability)
1350 *availability = AVAIL_NOT_AVAILABLE;
1354 /* Return true when the edge E represents a direct recursion. */
1356 cgraph_edge_recursive_p (struct cgraph_edge *e)
1358 struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
1359 if (e->caller->global.inlined_to)
1360 return e->caller->global.inlined_to->symbol.decl == callee->symbol.decl;
1362 return e->caller->symbol.decl == callee->symbol.decl;
1365 /* Return true if the TM_CLONE bit is set for a given FNDECL. */
1367 decl_is_tm_clone (const_tree fndecl)
1369 struct cgraph_node *n = cgraph_get_node (fndecl);
1375 /* Likewise indicate that a node is needed, i.e. reachable via some
1379 cgraph_mark_force_output_node (struct cgraph_node *node)
1381 node->symbol.force_output = 1;
1382 gcc_checking_assert (!node->global.inlined_to);
1385 /* Return true when the symbol is real symbol, i.e. it is not inline clone
1386 or abstract function kept for debug info purposes only. */
1389 symtab_real_symbol_p (symtab_node node)
1391 struct cgraph_node *cnode;
1393 if (DECL_ABSTRACT (node->symbol.decl))
1395 if (!is_a <cgraph_node> (node))
1397 cnode = cgraph (node);
1398 if (cnode->global.inlined_to)
1403 /* Return true if NODE can be discarded by linker from the binary. */
1406 symtab_can_be_discarded (symtab_node node)
1408 return (DECL_EXTERNAL (node->symbol.decl)
1409 || (DECL_ONE_ONLY (node->symbol.decl)
1410 && node->symbol.resolution != LDPR_PREVAILING_DEF
1411 && node->symbol.resolution != LDPR_PREVAILING_DEF_IRONLY
1412 && node->symbol.resolution != LDPR_PREVAILING_DEF_IRONLY_EXP));
1414 #endif /* GCC_CGRAPH_H */