1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 /* This file contains basic routines manipulating call graph
26 The call-graph is data structure designed for intra-procedural optimization
27 but it is also used in non-unit-at-a-time compilation to allow easier code
30 The call-graph consist of nodes and edges represented via linked lists.
31 Each function (external or not) corresponds to the unique node (in
32 contrast to tree DECL nodes where we can have multiple nodes for each
35 The mapping from declarations to call-graph nodes is done using hash table
36 based on DECL_ASSEMBLER_NAME, so it is essential for assembler name to
37 not change once the declaration is inserted into the call-graph.
38 The call-graph nodes are created lazily using cgraph_node function when
39 called for unknown declaration.
41 When built, there is one edge for each direct call. It is possible that
42 the reference will be later optimized out. The call-graph is built
43 conservatively in order to make conservative data flow analysis possible.
45 The callgraph at the moment does not represent indirect calls or calls
46 from other compilation unit. Flag NEEDED is set for each node that may
47 be accessed in such an invisible way and it shall be considered an
48 entry point to the callgraph.
50 Interprocedural information:
52 Callgraph is place to store data needed for interprocedural optimization.
53 All data structures are divided into three components: local_info that
54 is produced while analyzing the function, global_info that is result
55 of global walking of the callgraph on the end of compilation and
56 rtl_info used by RTL backend to propagate data from already compiled
57 functions to their callers.
61 The function inlining information is decided in advance and maintained
62 in the callgraph as so called inline plan.
63 For each inlined call, the callee's node is cloned to represent the
64 new function copy produced by inliner.
65 Each inlined call gets a unique corresponding clone node of the callee
66 and the data structure is updated while inlining is performed, so
67 the clones are eliminated and their callee edges redirected to the
70 Each edge has "inline_failed" field. When the field is set to NULL,
71 the call will be inlined. When it is non-NULL it contains a reason
72 why inlining wasn't performed. */
76 #include "coretypes.h"
79 #include "tree-inline.h"
80 #include "langhooks.h"
87 #include "basic-block.h"
92 #include "tree-gimple.h"
93 #include "tree-dump.h"
95 static void cgraph_node_remove_callers (struct cgraph_node
*node
);
96 static inline void cgraph_edge_remove_caller (struct cgraph_edge
*e
);
97 static inline void cgraph_edge_remove_callee (struct cgraph_edge
*e
);
99 /* Hash table used to convert declarations into nodes. */
100 static GTY((param_is (struct cgraph_node
))) htab_t cgraph_hash
;
102 /* The linked list of cgraph nodes. */
103 struct cgraph_node
*cgraph_nodes
;
105 /* Queue of cgraph nodes scheduled to be lowered. */
106 struct cgraph_node
*cgraph_nodes_queue
;
108 /* Queue of cgraph nodes scheduled to be expanded. This is a
109 secondary queue used during optimization to accommodate passes that
110 may generate new functions that need to be optimized and expanded. */
111 struct cgraph_node
*cgraph_expand_queue
;
113 /* Number of nodes in existence. */
116 /* Maximal uid used in cgraph nodes. */
119 /* Set when whole unit has been analyzed so we can access global info. */
120 bool cgraph_global_info_ready
= false;
122 /* Set when the cgraph is fully build and the basic flags are computed. */
123 bool cgraph_function_flags_ready
= false;
125 /* Linked list of cgraph asm nodes. */
126 struct cgraph_asm_node
*cgraph_asm_nodes
;
128 /* Last node in cgraph_asm_nodes. */
129 static GTY(()) struct cgraph_asm_node
*cgraph_asm_last_node
;
131 /* The order index of the next cgraph node to be created. This is
132 used so that we can sort the cgraph nodes in order by when we saw
133 them, to support -fno-toplevel-reorder. */
136 static hashval_t
hash_node (const void *);
137 static int eq_node (const void *, const void *);
139 /* Returns a hash code for P. */
142 hash_node (const void *p
)
144 const struct cgraph_node
*n
= (const struct cgraph_node
*) p
;
145 return (hashval_t
) DECL_UID (n
->decl
);
148 /* Returns nonzero if P1 and P2 are equal. */
151 eq_node (const void *p1
, const void *p2
)
153 const struct cgraph_node
*n1
= (const struct cgraph_node
*) p1
;
154 const struct cgraph_node
*n2
= (const struct cgraph_node
*) p2
;
155 return DECL_UID (n1
->decl
) == DECL_UID (n2
->decl
);
158 /* Allocate new callgraph node and insert it into basic data structures. */
159 static struct cgraph_node
*
160 cgraph_create_node (void)
162 struct cgraph_node
*node
;
164 node
= GGC_CNEW (struct cgraph_node
);
165 node
->next
= cgraph_nodes
;
166 node
->uid
= cgraph_max_uid
++;
167 node
->order
= cgraph_order
++;
169 cgraph_nodes
->previous
= node
;
170 node
->previous
= NULL
;
171 node
->global
.estimated_growth
= INT_MIN
;
174 COPY_HARD_REG_SET (node
->function_used_regs
, call_used_reg_set
);
178 /* Return cgraph node assigned to DECL. Create new one when needed. */
180 cgraph_node (tree decl
)
182 struct cgraph_node key
, *node
, **slot
;
184 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
187 cgraph_hash
= htab_create_ggc (10, hash_node
, eq_node
, NULL
);
191 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, &key
, INSERT
);
196 if (!node
->master_clone
)
197 node
->master_clone
= node
;
201 node
= cgraph_create_node ();
204 if (DECL_CONTEXT (decl
) && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
206 node
->origin
= cgraph_node (DECL_CONTEXT (decl
));
207 node
->next_nested
= node
->origin
->nested
;
208 node
->origin
->nested
= node
;
209 node
->master_clone
= node
;
214 /* Insert already constructed node into hashtable. */
217 cgraph_insert_node_to_hashtable (struct cgraph_node
*node
)
219 struct cgraph_node
**slot
;
221 slot
= (struct cgraph_node
**) htab_find_slot (cgraph_hash
, node
, INSERT
);
228 /* Return the cgraph node that has ASMNAME for its DECL_ASSEMBLER_NAME.
229 Return NULL if there's no such node. */
232 cgraph_node_for_asm (tree asmname
)
234 struct cgraph_node
*node
;
236 for (node
= cgraph_nodes
; node
; node
= node
->next
)
237 if (decl_assembler_name_equal (node
->decl
, asmname
))
243 /* Returns a hash value for X (which really is a die_struct). */
246 edge_hash (const void *x
)
248 return htab_hash_pointer (((struct cgraph_edge
*) x
)->call_stmt
);
251 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
254 edge_eq (const void *x
, const void *y
)
256 return ((struct cgraph_edge
*) x
)->call_stmt
== y
;
259 /* Return callgraph edge representing CALL_EXPR statement. */
261 cgraph_edge (struct cgraph_node
*node
, tree call_stmt
)
263 struct cgraph_edge
*e
, *e2
;
266 if (node
->call_site_hash
)
267 return htab_find_with_hash (node
->call_site_hash
, call_stmt
,
268 htab_hash_pointer (call_stmt
));
270 /* This loop may turn out to be performance problem. In such case adding
271 hashtables into call nodes with very many edges is probably best
272 solution. It is not good idea to add pointer into CALL_EXPR itself
273 because we want to make possible having multiple cgraph nodes representing
274 different clones of the same body before the body is actually cloned. */
275 for (e
= node
->callees
; e
; e
= e
->next_callee
)
277 if (e
->call_stmt
== call_stmt
)
283 node
->call_site_hash
= htab_create_ggc (120, edge_hash
, edge_eq
, NULL
);
284 for (e2
= node
->callees
; e2
; e2
= e2
->next_callee
)
287 slot
= htab_find_slot_with_hash (node
->call_site_hash
,
289 htab_hash_pointer (e2
->call_stmt
),
298 /* Change call_smtt of edge E to NEW_STMT. */
300 cgraph_set_call_stmt (struct cgraph_edge
*e
, tree new_stmt
)
302 if (e
->caller
->call_site_hash
)
304 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
306 htab_hash_pointer (e
->call_stmt
));
308 e
->call_stmt
= new_stmt
;
309 if (e
->caller
->call_site_hash
)
312 slot
= htab_find_slot_with_hash (e
->caller
->call_site_hash
,
315 (e
->call_stmt
), INSERT
);
321 /* Create edge from CALLER to CALLEE in the cgraph. */
324 cgraph_create_edge (struct cgraph_node
*caller
, struct cgraph_node
*callee
,
325 tree call_stmt
, gcov_type count
, int nest
)
327 struct cgraph_edge
*edge
= GGC_NEW (struct cgraph_edge
);
328 #ifdef ENABLE_CHECKING
329 struct cgraph_edge
*e
;
331 for (e
= caller
->callees
; e
; e
= e
->next_callee
)
332 gcc_assert (e
->call_stmt
!= call_stmt
);
335 gcc_assert (get_call_expr_in (call_stmt
));
337 if (!DECL_SAVED_TREE (callee
->decl
))
338 edge
->inline_failed
= N_("function body not available");
339 else if (callee
->local
.redefined_extern_inline
)
340 edge
->inline_failed
= N_("redefined extern inline functions are not "
341 "considered for inlining");
342 else if (callee
->local
.inlinable
)
343 edge
->inline_failed
= N_("function not considered for inlining");
345 edge
->inline_failed
= N_("function not inlinable");
349 edge
->caller
= caller
;
350 edge
->callee
= callee
;
351 edge
->call_stmt
= call_stmt
;
352 edge
->prev_caller
= NULL
;
353 edge
->next_caller
= callee
->callers
;
355 callee
->callers
->prev_caller
= edge
;
356 edge
->prev_callee
= NULL
;
357 edge
->next_callee
= caller
->callees
;
359 caller
->callees
->prev_callee
= edge
;
360 caller
->callees
= edge
;
361 callee
->callers
= edge
;
363 edge
->loop_nest
= nest
;
364 if (caller
->call_site_hash
)
367 slot
= htab_find_slot_with_hash (caller
->call_site_hash
,
378 /* Remove the edge E from the list of the callers of the callee. */
381 cgraph_edge_remove_callee (struct cgraph_edge
*e
)
384 e
->prev_caller
->next_caller
= e
->next_caller
;
386 e
->next_caller
->prev_caller
= e
->prev_caller
;
388 e
->callee
->callers
= e
->next_caller
;
391 /* Remove the edge E from the list of the callees of the caller. */
394 cgraph_edge_remove_caller (struct cgraph_edge
*e
)
397 e
->prev_callee
->next_callee
= e
->next_callee
;
399 e
->next_callee
->prev_callee
= e
->prev_callee
;
401 e
->caller
->callees
= e
->next_callee
;
402 if (e
->caller
->call_site_hash
)
403 htab_remove_elt_with_hash (e
->caller
->call_site_hash
,
405 htab_hash_pointer (e
->call_stmt
));
408 /* Remove the edge E in the cgraph. */
411 cgraph_remove_edge (struct cgraph_edge
*e
)
413 /* Remove from callers list of the callee. */
414 cgraph_edge_remove_callee (e
);
416 /* Remove from callees list of the callers. */
417 cgraph_edge_remove_caller (e
);
420 /* Redirect callee of E to N. The function does not update underlying
424 cgraph_redirect_edge_callee (struct cgraph_edge
*e
, struct cgraph_node
*n
)
426 /* Remove from callers list of the current callee. */
427 cgraph_edge_remove_callee (e
);
429 /* Insert to callers list of the new callee. */
430 e
->prev_caller
= NULL
;
432 n
->callers
->prev_caller
= e
;
433 e
->next_caller
= n
->callers
;
438 /* Remove all callees from the node. */
441 cgraph_node_remove_callees (struct cgraph_node
*node
)
443 struct cgraph_edge
*e
;
445 /* It is sufficient to remove the edges from the lists of callers of
446 the callees. The callee list of the node can be zapped with one
448 for (e
= node
->callees
; e
; e
= e
->next_callee
)
449 cgraph_edge_remove_callee (e
);
450 node
->callees
= NULL
;
451 if (node
->call_site_hash
)
453 htab_delete (node
->call_site_hash
);
454 node
->call_site_hash
= NULL
;
458 /* Remove all callers from the node. */
461 cgraph_node_remove_callers (struct cgraph_node
*node
)
463 struct cgraph_edge
*e
;
465 /* It is sufficient to remove the edges from the lists of callees of
466 the callers. The caller list of the node can be zapped with one
468 for (e
= node
->callers
; e
; e
= e
->next_caller
)
469 cgraph_edge_remove_caller (e
);
470 node
->callers
= NULL
;
473 /* Remove the node from cgraph. */
476 cgraph_remove_node (struct cgraph_node
*node
)
479 bool kill_body
= false;
481 cgraph_node_remove_callers (node
);
482 cgraph_node_remove_callees (node
);
483 /* Incremental inlining access removed nodes stored in the postorder list.
485 node
->needed
= node
->reachable
= false;
487 cgraph_remove_node (node
->nested
);
490 struct cgraph_node
**node2
= &node
->origin
->nested
;
492 while (*node2
!= node
)
493 node2
= &(*node2
)->next_nested
;
494 *node2
= node
->next_nested
;
497 node
->previous
->next
= node
->next
;
499 cgraph_nodes
= node
->next
;
501 node
->next
->previous
= node
->previous
;
503 node
->previous
= NULL
;
504 slot
= htab_find_slot (cgraph_hash
, node
, NO_INSERT
);
507 if (node
->next_clone
)
509 struct cgraph_node
*new_node
= node
->next_clone
;
510 struct cgraph_node
*n
;
512 /* Make the next clone be the master clone */
513 for (n
= new_node
; n
; n
= n
->next_clone
)
514 n
->master_clone
= new_node
;
517 node
->next_clone
->prev_clone
= NULL
;
521 htab_clear_slot (cgraph_hash
, slot
);
527 node
->prev_clone
->next_clone
= node
->next_clone
;
528 if (node
->next_clone
)
529 node
->next_clone
->prev_clone
= node
->prev_clone
;
532 /* While all the clones are removed after being proceeded, the function
533 itself is kept in the cgraph even after it is compiled. Check whether
534 we are done with this body and reclaim it proactively if this is the case.
536 if (!kill_body
&& *slot
)
538 struct cgraph_node
*n
= (struct cgraph_node
*) *slot
;
539 if (!n
->next_clone
&& !n
->global
.inlined_to
540 && (cgraph_global_info_ready
541 && (TREE_ASM_WRITTEN (n
->decl
) || DECL_EXTERNAL (n
->decl
))))
545 if (kill_body
&& flag_unit_at_a_time
)
547 DECL_SAVED_TREE (node
->decl
) = NULL
;
548 DECL_STRUCT_FUNCTION (node
->decl
) = NULL
;
549 DECL_INITIAL (node
->decl
) = error_mark_node
;
552 if (node
->call_site_hash
)
554 htab_delete (node
->call_site_hash
);
555 node
->call_site_hash
= NULL
;
558 /* Do not free the structure itself so the walk over chain can continue. */
561 /* Notify finalize_compilation_unit that given node is reachable. */
564 cgraph_mark_reachable_node (struct cgraph_node
*node
)
566 if (!node
->reachable
&& node
->local
.finalized
)
568 notice_global_symbol (node
->decl
);
570 gcc_assert (!cgraph_global_info_ready
);
572 node
->next_needed
= cgraph_nodes_queue
;
573 cgraph_nodes_queue
= node
;
577 /* Likewise indicate that a node is needed, i.e. reachable via some
581 cgraph_mark_needed_node (struct cgraph_node
*node
)
584 cgraph_mark_reachable_node (node
);
587 /* Return local info for the compiled function. */
589 struct cgraph_local_info
*
590 cgraph_local_info (tree decl
)
592 struct cgraph_node
*node
;
594 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
595 node
= cgraph_node (decl
);
599 /* Return local info for the compiled function. */
601 struct cgraph_global_info
*
602 cgraph_global_info (tree decl
)
604 struct cgraph_node
*node
;
606 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
&& cgraph_global_info_ready
);
607 node
= cgraph_node (decl
);
608 return &node
->global
;
611 /* Return local info for the compiled function. */
613 struct cgraph_rtl_info
*
614 cgraph_rtl_info (tree decl
)
616 struct cgraph_node
*node
;
618 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
619 node
= cgraph_node (decl
);
620 if (decl
!= current_function_decl
621 && !TREE_ASM_WRITTEN (node
->decl
))
626 /* Return name of the node used in debug output. */
628 cgraph_node_name (struct cgraph_node
*node
)
630 return lang_hooks
.decl_printable_name (node
->decl
, 2);
633 /* Names used to print out the availability enum. */
634 const char * const cgraph_availability_names
[] =
635 {"unset", "not_available", "overwrittable", "available", "local"};
637 /* Dump given cgraph node. */
639 dump_cgraph_node (FILE *f
, struct cgraph_node
*node
)
641 struct cgraph_edge
*edge
;
642 fprintf (f
, "%s/%i:", cgraph_node_name (node
), node
->uid
);
643 if (node
->global
.inlined_to
)
644 fprintf (f
, " (inline copy in %s/%i)",
645 cgraph_node_name (node
->global
.inlined_to
),
646 node
->global
.inlined_to
->uid
);
647 if (cgraph_function_flags_ready
)
648 fprintf (f
, " availability:%s",
649 cgraph_availability_names
[cgraph_function_body_availability (node
)]);
650 if (node
->master_clone
&& node
->master_clone
->uid
!= node
->uid
)
651 fprintf (f
, "(%i)", node
->master_clone
->uid
);
653 fprintf (f
, " executed "HOST_WIDEST_INT_PRINT_DEC
"x",
654 (HOST_WIDEST_INT
)node
->count
);
655 if (node
->local
.self_insns
)
656 fprintf (f
, " %i insns", node
->local
.self_insns
);
657 if (node
->global
.insns
&& node
->global
.insns
!= node
->local
.self_insns
)
658 fprintf (f
, " (%i after inlining)", node
->global
.insns
);
659 if (node
->local
.estimated_self_stack_size
)
660 fprintf (f
, " %i bytes stack usage", (int)node
->local
.estimated_self_stack_size
);
661 if (node
->global
.estimated_stack_size
!= node
->local
.estimated_self_stack_size
)
662 fprintf (f
, " %i bytes after inlining", (int)node
->global
.estimated_stack_size
);
664 fprintf (f
, " nested in: %s", cgraph_node_name (node
->origin
));
666 fprintf (f
, " needed");
667 else if (node
->reachable
)
668 fprintf (f
, " reachable");
669 if (DECL_SAVED_TREE (node
->decl
))
670 fprintf (f
, " tree");
672 fprintf (f
, " output");
673 if (node
->local
.local
)
674 fprintf (f
, " local");
675 if (node
->local
.externally_visible
)
676 fprintf (f
, " externally_visible");
677 if (node
->local
.finalized
)
678 fprintf (f
, " finalized");
679 if (node
->local
.disregard_inline_limits
)
680 fprintf (f
, " always_inline");
681 else if (node
->local
.inlinable
)
682 fprintf (f
, " inlinable");
683 if (node
->local
.redefined_extern_inline
)
684 fprintf (f
, " redefined_extern_inline");
685 if (TREE_ASM_WRITTEN (node
->decl
))
686 fprintf (f
, " asm_written");
688 fprintf (f
, "\n called by: ");
689 for (edge
= node
->callers
; edge
; edge
= edge
->next_caller
)
691 fprintf (f
, "%s/%i ", cgraph_node_name (edge
->caller
),
694 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
695 (HOST_WIDEST_INT
)edge
->count
);
696 if (!edge
->inline_failed
)
697 fprintf(f
, "(inlined) ");
700 fprintf (f
, "\n calls: ");
701 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
703 fprintf (f
, "%s/%i ", cgraph_node_name (edge
->callee
),
705 if (!edge
->inline_failed
)
706 fprintf(f
, "(inlined) ");
708 fprintf (f
, "("HOST_WIDEST_INT_PRINT_DEC
"x) ",
709 (HOST_WIDEST_INT
)edge
->count
);
711 fprintf (f
, "(nested in %i loops) ", edge
->loop_nest
);
716 /* Dump the callgraph. */
719 dump_cgraph (FILE *f
)
721 struct cgraph_node
*node
;
723 fprintf (f
, "callgraph:\n\n");
724 for (node
= cgraph_nodes
; node
; node
= node
->next
)
725 dump_cgraph_node (f
, node
);
728 /* Set the DECL_ASSEMBLER_NAME and update cgraph hashtables. */
730 change_decl_assembler_name (tree decl
, tree name
)
732 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
734 SET_DECL_ASSEMBLER_NAME (decl
, name
);
737 if (name
== DECL_ASSEMBLER_NAME (decl
))
740 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
741 && DECL_RTL_SET_P (decl
))
742 warning (0, "%D renamed after being referenced in assembly", decl
);
744 SET_DECL_ASSEMBLER_NAME (decl
, name
);
747 /* Add a top-level asm statement to the list. */
749 struct cgraph_asm_node
*
750 cgraph_add_asm_node (tree asm_str
)
752 struct cgraph_asm_node
*node
;
754 node
= GGC_CNEW (struct cgraph_asm_node
);
755 node
->asm_str
= asm_str
;
756 node
->order
= cgraph_order
++;
758 if (cgraph_asm_nodes
== NULL
)
759 cgraph_asm_nodes
= node
;
761 cgraph_asm_last_node
->next
= node
;
762 cgraph_asm_last_node
= node
;
766 /* Return true when the DECL can possibly be inlined. */
768 cgraph_function_possibly_inlined_p (tree decl
)
770 if (!cgraph_global_info_ready
)
771 return (DECL_INLINE (decl
) && !flag_really_no_inline
);
772 return DECL_POSSIBLY_INLINED (decl
);
775 /* Create clone of E in the node N represented by CALL_EXPR the callgraph. */
777 cgraph_clone_edge (struct cgraph_edge
*e
, struct cgraph_node
*n
,
778 tree call_stmt
, gcov_type count_scale
, int loop_nest
,
779 bool update_original
)
781 struct cgraph_edge
*new;
783 new = cgraph_create_edge (n
, e
->callee
, call_stmt
,
784 e
->count
* count_scale
/ REG_BR_PROB_BASE
,
785 e
->loop_nest
+ loop_nest
);
787 new->inline_failed
= e
->inline_failed
;
790 e
->count
-= new->count
;
797 /* Create node representing clone of N executed COUNT times. Decrease
798 the execution counts from original node too.
800 When UPDATE_ORIGINAL is true, the counts are subtracted from the original
801 function's profile to reflect the fact that part of execution is handled
804 cgraph_clone_node (struct cgraph_node
*n
, gcov_type count
, int loop_nest
,
805 bool update_original
)
807 struct cgraph_node
*new = cgraph_create_node ();
808 struct cgraph_edge
*e
;
809 gcov_type count_scale
;
812 new->origin
= n
->origin
;
815 new->next_nested
= new->origin
->nested
;
816 new->origin
->nested
= new;
818 new->analyzed
= n
->analyzed
;
819 new->local
= n
->local
;
820 new->global
= n
->global
;
822 new->master_clone
= n
->master_clone
;
825 count_scale
= new->count
* REG_BR_PROB_BASE
/ n
->count
;
835 for (e
= n
->callees
;e
; e
=e
->next_callee
)
836 cgraph_clone_edge (e
, new, e
->call_stmt
, count_scale
, loop_nest
,
839 new->next_clone
= n
->next_clone
;
843 new->next_clone
->prev_clone
= new;
848 /* Return true if N is an master_clone, (see cgraph_master_clone). */
851 cgraph_is_master_clone (struct cgraph_node
*n
)
853 return (n
== cgraph_master_clone (n
));
857 cgraph_master_clone (struct cgraph_node
*n
)
859 enum availability avail
= cgraph_function_body_availability (n
);
861 if (avail
== AVAIL_NOT_AVAILABLE
|| avail
== AVAIL_OVERWRITABLE
)
864 if (!n
->master_clone
)
865 n
->master_clone
= cgraph_node (n
->decl
);
867 return n
->master_clone
;
870 /* NODE is no longer nested function; update cgraph accordingly. */
872 cgraph_unnest_node (struct cgraph_node
*node
)
874 struct cgraph_node
**node2
= &node
->origin
->nested
;
875 gcc_assert (node
->origin
);
877 while (*node2
!= node
)
878 node2
= &(*node2
)->next_nested
;
879 *node2
= node
->next_nested
;
883 /* Return function availability. See cgraph.h for description of individual
886 cgraph_function_body_availability (struct cgraph_node
*node
)
888 enum availability avail
;
889 gcc_assert (cgraph_function_flags_ready
);
891 avail
= AVAIL_NOT_AVAILABLE
;
892 else if (node
->local
.local
)
894 else if (node
->local
.externally_visible
)
895 avail
= AVAIL_AVAILABLE
;
897 /* If the function can be overwritten, return OVERWRITABLE. Take
898 care at least of two notable extensions - the COMDAT functions
899 used to share template instantiations in C++ (this is symmetric
900 to code cp_cannot_inline_tree_fn and probably shall be shared and
901 the inlinability hooks completely eliminated).
903 ??? Does the C++ one definition rule allow us to always return
904 AVAIL_AVAILABLE here? That would be good reason to preserve this
905 hook Similarly deal with extern inline functions - this is again
906 necessary to get C++ shared functions having keyed templates
907 right and in the C extension documentation we probably should
908 document the requirement of both versions of function (extern
909 inline and offline) having same side effect characteristics as
910 good optimization is what this optimization is about. */
912 else if (!(*targetm
.binds_local_p
) (node
->decl
)
913 && !DECL_COMDAT (node
->decl
) && !DECL_EXTERNAL (node
->decl
))
914 avail
= AVAIL_OVERWRITABLE
;
915 else avail
= AVAIL_AVAILABLE
;
920 /* Add the function FNDECL to the call graph. FNDECL is assumed to be
921 in low GIMPLE form and ready to be processed by cgraph_finalize_function.
923 When operating in unit-at-a-time, a new callgraph node is added to
924 CGRAPH_EXPAND_QUEUE, which is processed after all the original
925 functions in the call graph .
927 When not in unit-at-a-time, the new callgraph node is added to
928 CGRAPH_NODES_QUEUE for cgraph_assemble_pending_functions to
932 cgraph_add_new_function (tree fndecl
)
934 struct cgraph_node
*n
= cgraph_node (fndecl
);
935 n
->next_needed
= cgraph_expand_queue
;
936 cgraph_expand_queue
= n
;
939 #include "gt-cgraph.h"