1 /* Callgraph based interprocedural optimizations.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This module implements main driver of compilation process as well as
23 few basic interprocedural optimizers.
25 The main scope of this file is to act as an interface in between
26 tree based frontends and the backend (and middle end)
28 The front-end is supposed to use following functionality:
30 - cgraph_finalize_function
32 This function is called once front-end has parsed whole body of function
33 and it is certain that the function body nor the declaration will change.
35 (There is one exception needed for implementing GCC extern inline
38 - varpool_finalize_variable
40 This function has same behavior as the above but is used for static
43 - cgraph_finalize_compilation_unit
45 This function is called once (source level) compilation unit is finalized
46 and it will no longer change.
48 In the the call-graph construction and local function
49 analysis takes place here. Bodies of unreachable functions are released
50 to conserve memory usage.
52 The function can be called multiple times when multiple source level
53 compilation units are combined (such as in C frontend)
57 In this unit-at-a-time compilation the intra procedural analysis takes
58 place here. In particular the static functions whose address is never
59 taken are marked as local. Backend can then use this information to
60 modify calling conventions, do better inlining or similar optimizations.
62 - cgraph_mark_needed_node
63 - varpool_mark_needed_node
65 When function or variable is referenced by some hidden way the call-graph
66 data structure must be updated accordingly by this function.
67 There should be little need to call this function and all the references
68 should be made explicit to cgraph code. At present these functions are
69 used by C++ frontend to explicitly mark the keyed methods.
71 - analyze_expr callback
73 This function is responsible for lowering tree nodes not understood by
74 generic code into understandable ones or alternatively marking
75 callgraph and varpool nodes referenced by the as needed.
77 ??? On the tree-ssa genericizing should take place here and we will avoid
78 need for these hooks (replacing them by genericizing hook)
80 Analyzing of all functions is deferred
81 to cgraph_finalize_compilation_unit and expansion into cgraph_optimize.
83 In cgraph_finalize_compilation_unit the reachable functions are
84 analyzed. During analysis the call-graph edges from reachable
85 functions are constructed and their destinations are marked as
86 reachable. References to functions and variables are discovered too
87 and variables found to be needed output to the assembly file. Via
88 mark_referenced call in assemble_variable functions referenced by
89 static variables are noticed too.
91 The intra-procedural information is produced and its existence
92 indicated by global_info_ready. Once this flag is set it is impossible
93 to change function from !reachable to reachable and thus
94 assemble_variable no longer call mark_referenced.
96 Finally the call-graph is topologically sorted and all reachable functions
97 that has not been completely inlined or are not external are output.
99 ??? It is possible that reference to function or variable is optimized
100 out. We can not deal with this nicely because topological order is not
101 suitable for it. For tree-ssa we may consider another pass doing
102 optimization and re-discovering reachable functions.
104 ??? Reorganize code so variables are output very last and only if they
105 really has been referenced by produced code, so we catch more cases
106 where reference has been optimized out. */
111 #include "coretypes.h"
115 #include "tree-flow.h"
116 #include "tree-inline.h"
117 #include "langhooks.h"
118 #include "pointer-set.h"
125 #include "diagnostic.h"
130 #include "function.h"
131 #include "ipa-prop.h"
133 #include "tree-iterator.h"
134 #include "tree-pass.h"
136 #include "coverage.h"
138 static void cgraph_expand_all_functions (void);
139 static void cgraph_mark_functions_to_output (void);
140 static void cgraph_expand_function (struct cgraph_node *);
141 static void cgraph_output_pending_asms (void);
143 static FILE *cgraph_dump_file;
145 /* A vector of FUNCTION_DECLs declared as static constructors. */
146 static GTY (()) VEC(tree, gc) *static_ctors;
147 /* A vector of FUNCTION_DECLs declared as static destructors. */
148 static GTY (()) VEC(tree, gc) *static_dtors;
150 /* When target does not have ctors and dtors, we call all constructor
151 and destructor by special initialization/destruction function
152 recognized by collect2.
154 When we are going to build this function, collect all constructors and
155 destructors and turn them into normal functions. */
158 record_cdtor_fn (tree fndecl)
160 struct cgraph_node *node;
161 if (targetm.have_ctors_dtors
162 || (!DECL_STATIC_CONSTRUCTOR (fndecl)
163 && !DECL_STATIC_DESTRUCTOR (fndecl)))
166 if (DECL_STATIC_CONSTRUCTOR (fndecl))
168 VEC_safe_push (tree, gc, static_ctors, fndecl);
169 DECL_STATIC_CONSTRUCTOR (fndecl) = 0;
171 if (DECL_STATIC_DESTRUCTOR (fndecl))
173 VEC_safe_push (tree, gc, static_dtors, fndecl);
174 DECL_STATIC_DESTRUCTOR (fndecl) = 0;
176 node = cgraph_node (fndecl);
177 node->local.disregard_inline_limits = 1;
178 cgraph_mark_reachable_node (node);
181 /* Define global constructors/destructor functions for the CDTORS, of
182 which they are LEN. The CDTORS are sorted by initialization
183 priority. If CTOR_P is true, these are constructors; otherwise,
184 they are destructors. */
187 build_cdtor (bool ctor_p, tree *cdtors, size_t len)
196 priority_type priority;
200 /* Find the next batch of constructors/destructors with the same
201 initialization priority. */
206 p = ctor_p ? DECL_INIT_PRIORITY (fn) : DECL_FINI_PRIORITY (fn);
209 else if (p != priority)
211 append_to_statement_list (build_function_call_expr (UNKNOWN_LOCATION,
217 gcc_assert (body != NULL_TREE);
218 /* Generate a function to call all the function of like
220 cgraph_build_static_cdtor (ctor_p ? 'I' : 'D', body, priority);
224 /* Comparison function for qsort. P1 and P2 are actually of type
225 "tree *" and point to static constructors. DECL_INIT_PRIORITY is
226 used to determine the sort order. */
229 compare_ctor (const void *p1, const void *p2)
236 f1 = *(const tree *)p1;
237 f2 = *(const tree *)p2;
238 priority1 = DECL_INIT_PRIORITY (f1);
239 priority2 = DECL_INIT_PRIORITY (f2);
241 if (priority1 < priority2)
243 else if (priority1 > priority2)
246 /* Ensure a stable sort. */
247 return (const tree *)p1 - (const tree *)p2;
250 /* Comparison function for qsort. P1 and P2 are actually of type
251 "tree *" and point to static destructors. DECL_FINI_PRIORITY is
252 used to determine the sort order. */
255 compare_dtor (const void *p1, const void *p2)
262 f1 = *(const tree *)p1;
263 f2 = *(const tree *)p2;
264 priority1 = DECL_FINI_PRIORITY (f1);
265 priority2 = DECL_FINI_PRIORITY (f2);
267 if (priority1 < priority2)
269 else if (priority1 > priority2)
272 /* Ensure a stable sort. */
273 return (const tree *)p1 - (const tree *)p2;
276 /* Generate functions to call static constructors and destructors
277 for targets that do not support .ctors/.dtors sections. These
278 functions have magic names which are detected by collect2. */
281 cgraph_build_cdtor_fns (void)
283 if (!VEC_empty (tree, static_ctors))
285 gcc_assert (!targetm.have_ctors_dtors);
286 qsort (VEC_address (tree, static_ctors),
287 VEC_length (tree, static_ctors),
290 build_cdtor (/*ctor_p=*/true,
291 VEC_address (tree, static_ctors),
292 VEC_length (tree, static_ctors));
293 VEC_truncate (tree, static_ctors, 0);
296 if (!VEC_empty (tree, static_dtors))
298 gcc_assert (!targetm.have_ctors_dtors);
299 qsort (VEC_address (tree, static_dtors),
300 VEC_length (tree, static_dtors),
303 build_cdtor (/*ctor_p=*/false,
304 VEC_address (tree, static_dtors),
305 VEC_length (tree, static_dtors));
306 VEC_truncate (tree, static_dtors, 0);
310 /* Determine if function DECL is needed. That is, visible to something
311 either outside this translation unit, something magic in the system
315 decide_is_function_needed (struct cgraph_node *node, tree decl)
317 if (MAIN_NAME_P (DECL_NAME (decl))
318 && TREE_PUBLIC (decl))
320 node->local.externally_visible = true;
324 /* If the user told us it is used, then it must be so. */
325 if (node->local.externally_visible)
328 /* ??? If the assembler name is set by hand, it is possible to assemble
329 the name later after finalizing the function and the fact is noticed
330 in assemble_name then. This is arguably a bug. */
331 if (DECL_ASSEMBLER_NAME_SET_P (decl)
332 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
335 /* With -fkeep-inline-functions we are keeping all inline functions except
336 for extern inline ones. */
337 if (flag_keep_inline_functions
338 && DECL_DECLARED_INLINE_P (decl)
339 && !DECL_EXTERNAL (decl)
340 && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl)))
343 /* If we decided it was needed before, but at the time we didn't have
344 the body of the function available, then it's still needed. We have
345 to go back and re-check its dependencies now. */
349 /* Externally visible functions must be output. The exception is
350 COMDAT functions that must be output only when they are needed.
352 When not optimizing, also output the static functions. (see
353 PR24561), but don't do so for always_inline functions, functions
354 declared inline and nested functions. These was optimized out
355 in the original implementation and it is unclear whether we want
356 to change the behavior here. */
357 if (((TREE_PUBLIC (decl)
358 || (!optimize && !node->local.disregard_inline_limits
359 && !DECL_DECLARED_INLINE_P (decl)
361 && !flag_whole_program)
362 && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
365 /* Constructors and destructors are reachable from the runtime by
367 if (DECL_STATIC_CONSTRUCTOR (decl) || DECL_STATIC_DESTRUCTOR (decl))
373 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
374 functions into callgraph in a way so they look like ordinary reachable
375 functions inserted into callgraph already at construction time. */
378 cgraph_process_new_functions (void)
382 struct cgraph_node *node;
384 /* Note that this queue may grow as its being processed, as the new
385 functions may generate new ones. */
386 while (cgraph_new_nodes)
388 node = cgraph_new_nodes;
390 cgraph_new_nodes = cgraph_new_nodes->next_needed;
391 switch (cgraph_state)
393 case CGRAPH_STATE_CONSTRUCTION:
394 /* At construction time we just need to finalize function and move
395 it into reachable functions list. */
397 node->next_needed = NULL;
398 cgraph_finalize_function (fndecl, false);
399 cgraph_mark_reachable_node (node);
403 case CGRAPH_STATE_IPA:
404 case CGRAPH_STATE_IPA_SSA:
405 /* When IPA optimization already started, do all essential
406 transformations that has been already performed on the whole
407 cgraph but not on this function. */
409 gimple_register_cfg_hooks ();
411 cgraph_analyze_function (node);
412 push_cfun (DECL_STRUCT_FUNCTION (fndecl));
413 current_function_decl = fndecl;
414 compute_inline_parameters (node);
415 if ((cgraph_state == CGRAPH_STATE_IPA_SSA
416 && !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl)))
417 /* When not optimizing, be sure we run early local passes anyway
420 execute_pass_list (pass_early_local_passes.pass.sub);
421 free_dominance_info (CDI_POST_DOMINATORS);
422 free_dominance_info (CDI_DOMINATORS);
424 current_function_decl = NULL;
427 case CGRAPH_STATE_EXPANSION:
428 /* Functions created during expansion shall be compiled
431 cgraph_expand_function (node);
438 cgraph_call_function_insertion_hooks (node);
443 /* As an GCC extension we allow redefinition of the function. The
444 semantics when both copies of bodies differ is not well defined.
445 We replace the old body with new body so in unit at a time mode
446 we always use new body, while in normal mode we may end up with
447 old body inlined into some functions and new body expanded and
450 ??? It may make more sense to use one body for inlining and other
451 body for expanding the function but this is difficult to do. */
454 cgraph_reset_node (struct cgraph_node *node)
456 /* If node->process is set, then we have already begun whole-unit analysis.
457 This is *not* testing for whether we've already emitted the function.
458 That case can be sort-of legitimately seen with real function redefinition
459 errors. I would argue that the front end should never present us with
460 such a case, but don't enforce that for now. */
461 gcc_assert (!node->process);
463 /* Reset our data structures so we can analyze the function again. */
464 memset (&node->local, 0, sizeof (node->local));
465 memset (&node->global, 0, sizeof (node->global));
466 memset (&node->rtl, 0, sizeof (node->rtl));
467 node->analyzed = false;
468 node->local.redefined_extern_inline = true;
469 node->local.finalized = false;
471 cgraph_node_remove_callees (node);
473 /* We may need to re-queue the node for assembling in case
474 we already proceeded it and ignored as not needed or got
475 a re-declaration in IMA mode. */
478 struct cgraph_node *n;
480 for (n = cgraph_nodes_queue; n; n = n->next_needed)
489 cgraph_lower_function (struct cgraph_node *node)
493 tree_lowering_passes (node->decl);
494 node->lowered = true;
497 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
498 logic in effect. If NESTED is true, then our caller cannot stand to have
499 the garbage collector run at the moment. We would need to either create
500 a new GC context, or just not compile right now. */
503 cgraph_finalize_function (tree decl, bool nested)
505 struct cgraph_node *node = cgraph_node (decl);
507 if (node->local.finalized)
508 cgraph_reset_node (node);
510 node->pid = cgraph_max_pid ++;
511 notice_global_symbol (decl);
512 node->local.finalized = true;
513 node->lowered = DECL_STRUCT_FUNCTION (decl)->cfg != NULL;
514 node->finalized_by_frontend = true;
515 record_cdtor_fn (node->decl);
517 lower_nested_functions (decl);
518 gcc_assert (!node->nested);
520 if (decide_is_function_needed (node, decl))
521 cgraph_mark_needed_node (node);
523 /* Since we reclaim unreachable nodes at the end of every language
524 level unit, we need to be conservative about possible entry points
526 if ((TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl)))
527 cgraph_mark_reachable_node (node);
529 /* If we've not yet emitted decl, tell the debug info about it. */
530 if (!TREE_ASM_WRITTEN (decl))
531 (*debug_hooks->deferred_inline_function) (decl);
533 /* Possibly warn about unused parameters. */
534 if (warn_unused_parameter)
535 do_warn_unused_parameter (decl);
541 /* C99 extern inline keywords allow changing of declaration after function
542 has been finalized. We need to re-decide if we want to mark the function as
546 cgraph_mark_if_needed (tree decl)
548 struct cgraph_node *node = cgraph_node (decl);
549 if (node->local.finalized && decide_is_function_needed (node, decl))
550 cgraph_mark_needed_node (node);
553 /* Return TRUE if NODE2 is equivalent to NODE or its clone. */
555 clone_of_p (struct cgraph_node *node, struct cgraph_node *node2)
557 while (node != node2 && node2)
558 node2 = node2->clone_of;
559 return node2 != NULL;
562 /* Verify cgraph nodes of given cgraph node. */
564 verify_cgraph_node (struct cgraph_node *node)
566 struct cgraph_edge *e;
567 struct function *this_cfun = DECL_STRUCT_FUNCTION (node->decl);
568 struct function *saved_cfun = cfun;
569 basic_block this_block;
570 gimple_stmt_iterator gsi;
571 bool error_found = false;
573 if (errorcount || sorrycount)
576 timevar_push (TV_CGRAPH_VERIFY);
577 /* debug_generic_stmt needs correct cfun */
578 set_cfun (this_cfun);
579 for (e = node->callees; e; e = e->next_callee)
582 error ("aux field set for edge %s->%s",
583 identifier_to_locale (cgraph_node_name (e->caller)),
584 identifier_to_locale (cgraph_node_name (e->callee)));
589 error ("Execution count is negative");
592 for (e = node->callers; e; e = e->next_caller)
596 error ("caller edge count is negative");
599 if (e->frequency < 0)
601 error ("caller edge frequency is negative");
604 if (e->frequency > CGRAPH_FREQ_MAX)
606 error ("caller edge frequency is too large");
609 if (!e->inline_failed)
611 if (node->global.inlined_to
612 != (e->caller->global.inlined_to
613 ? e->caller->global.inlined_to : e->caller))
615 error ("inlined_to pointer is wrong");
618 if (node->callers->next_caller)
620 error ("multiple inline callers");
625 if (node->global.inlined_to)
627 error ("inlined_to pointer set for noninline callers");
631 if (!node->callers && node->global.inlined_to)
633 error ("inlined_to pointer is set but no predecessors found");
636 if (node->global.inlined_to == node)
638 error ("inlined_to pointer refers to itself");
642 if (!cgraph_node (node->decl))
644 error ("node not found in cgraph_hash");
650 struct cgraph_node *n;
651 for (n = node->clone_of->clones; n; n = n->next_sibling_clone)
656 error ("node has wrong clone_of");
662 struct cgraph_node *n;
663 for (n = node->clones; n; n = n->next_sibling_clone)
664 if (n->clone_of != node)
668 error ("node has wrong clone list");
672 if ((node->prev_sibling_clone || node->next_sibling_clone) && !node->clone_of)
674 error ("node is in clone list but it is not clone");
677 if (!node->prev_sibling_clone && node->clone_of && node->clone_of->clones != node)
679 error ("node has wrong prev_clone pointer");
682 if (node->prev_sibling_clone && node->prev_sibling_clone->next_sibling_clone != node)
684 error ("double linked list of clones corrupted");
688 if (node->analyzed && gimple_has_body_p (node->decl)
689 && !TREE_ASM_WRITTEN (node->decl)
690 && (!DECL_EXTERNAL (node->decl) || node->global.inlined_to))
694 /* The nodes we're interested in are never shared, so walk
695 the tree ignoring duplicates. */
696 struct pointer_set_t *visited_nodes = pointer_set_create ();
697 /* Reach the trees by walking over the CFG, and note the
698 enclosing basic-blocks in the call edges. */
699 FOR_EACH_BB_FN (this_block, this_cfun)
700 for (gsi = gsi_start_bb (this_block);
704 gimple stmt = gsi_stmt (gsi);
706 if (is_gimple_call (stmt) && (decl = gimple_call_fndecl (stmt)))
708 struct cgraph_edge *e = cgraph_edge (node, stmt);
713 error ("shared call_stmt:");
714 debug_gimple_stmt (stmt);
717 if (!clone_of_p (cgraph_node (decl), e->callee)
718 && !e->callee->global.inlined_to)
720 error ("edge points to wrong declaration:");
721 debug_tree (e->callee->decl);
722 fprintf (stderr," Instead of:");
729 error ("missing callgraph edge for call stmt:");
730 debug_gimple_stmt (stmt);
735 pointer_set_destroy (visited_nodes);
738 /* No CFG available?! */
741 for (e = node->callees; e; e = e->next_callee)
743 if (!e->aux && !e->indirect_call)
745 error ("edge %s->%s has no corresponding call_stmt",
746 identifier_to_locale (cgraph_node_name (e->caller)),
747 identifier_to_locale (cgraph_node_name (e->callee)));
748 debug_gimple_stmt (e->call_stmt);
756 dump_cgraph_node (stderr, node);
757 internal_error ("verify_cgraph_node failed");
759 set_cfun (saved_cfun);
760 timevar_pop (TV_CGRAPH_VERIFY);
763 /* Verify whole cgraph structure. */
767 struct cgraph_node *node;
769 if (sorrycount || errorcount)
772 for (node = cgraph_nodes; node; node = node->next)
773 verify_cgraph_node (node);
776 /* Output all asm statements we have stored up to be output. */
779 cgraph_output_pending_asms (void)
781 struct cgraph_asm_node *can;
783 if (errorcount || sorrycount)
786 for (can = cgraph_asm_nodes; can; can = can->next)
787 assemble_asm (can->asm_str);
788 cgraph_asm_nodes = NULL;
791 /* Analyze the function scheduled to be output. */
793 cgraph_analyze_function (struct cgraph_node *node)
795 tree decl = node->decl;
797 current_function_decl = decl;
798 push_cfun (DECL_STRUCT_FUNCTION (decl));
799 cgraph_lower_function (node);
800 node->analyzed = true;
803 current_function_decl = NULL;
806 /* Look for externally_visible and used attributes and mark cgraph nodes
809 We cannot mark the nodes at the point the attributes are processed (in
810 handle_*_attribute) because the copy of the declarations available at that
811 point may not be canonical. For example, in:
814 void f() __attribute__((used));
816 the declaration we see in handle_used_attribute will be the second
817 declaration -- but the front end will subsequently merge that declaration
818 with the original declaration and discard the second declaration.
820 Furthermore, we can't mark these nodes in cgraph_finalize_function because:
823 void f() __attribute__((externally_visible));
827 So, we walk the nodes at the end of the translation unit, applying the
828 attributes at that point. */
831 process_function_and_variable_attributes (struct cgraph_node *first,
832 struct varpool_node *first_var)
834 struct cgraph_node *node;
835 struct varpool_node *vnode;
837 for (node = cgraph_nodes; node != first; node = node->next)
839 tree decl = node->decl;
840 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
842 mark_decl_referenced (decl);
843 if (node->local.finalized)
844 cgraph_mark_needed_node (node);
846 if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
848 if (! TREE_PUBLIC (node->decl))
849 warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
850 "%<externally_visible%>"
851 " attribute have effect only on public objects");
854 if (node->local.finalized)
855 cgraph_mark_needed_node (node);
856 node->local.externally_visible = true;
860 for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next)
862 tree decl = vnode->decl;
863 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
865 mark_decl_referenced (decl);
866 if (vnode->finalized)
867 varpool_mark_needed_node (vnode);
869 if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
871 if (! TREE_PUBLIC (vnode->decl))
872 warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
873 "%<externally_visible%>"
874 " attribute have effect only on public objects");
877 if (vnode->finalized)
878 varpool_mark_needed_node (vnode);
879 vnode->externally_visible = true;
885 /* Process CGRAPH_NODES_NEEDED queue, analyze each function (and transitively
886 each reachable functions) and build cgraph.
887 The function can be called multiple times after inserting new nodes
888 into beginning of queue. Just the new part of queue is re-scanned then. */
891 cgraph_analyze_functions (void)
893 /* Keep track of already processed nodes when called multiple times for
894 intermodule optimization. */
895 static struct cgraph_node *first_analyzed;
896 struct cgraph_node *first_processed = first_analyzed;
897 static struct varpool_node *first_analyzed_var;
898 struct cgraph_node *node, *next;
900 process_function_and_variable_attributes (first_processed,
902 first_processed = cgraph_nodes;
903 first_analyzed_var = varpool_nodes;
904 varpool_analyze_pending_decls ();
905 if (cgraph_dump_file)
907 fprintf (cgraph_dump_file, "Initial entry points:");
908 for (node = cgraph_nodes; node != first_analyzed; node = node->next)
910 fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
911 fprintf (cgraph_dump_file, "\n");
913 cgraph_process_new_functions ();
915 /* Propagate reachability flag and lower representation of all reachable
916 functions. In the future, lowering will introduce new functions and
917 new entry points on the way (by template instantiation and virtual
918 method table generation for instance). */
919 while (cgraph_nodes_queue)
921 struct cgraph_edge *edge;
922 tree decl = cgraph_nodes_queue->decl;
924 node = cgraph_nodes_queue;
925 cgraph_nodes_queue = cgraph_nodes_queue->next_needed;
926 node->next_needed = NULL;
928 /* ??? It is possible to create extern inline function and later using
929 weak alias attribute to kill its body. See
930 gcc.c-torture/compile/20011119-1.c */
931 if (!DECL_STRUCT_FUNCTION (decl))
933 cgraph_reset_node (node);
937 gcc_assert (!node->analyzed && node->reachable);
938 gcc_assert (gimple_body (decl));
940 cgraph_analyze_function (node);
942 for (edge = node->callees; edge; edge = edge->next_callee)
943 if (!edge->callee->reachable)
944 cgraph_mark_reachable_node (edge->callee);
946 /* If decl is a clone of an abstract function, mark that abstract
947 function so that we don't release its body. The DECL_INITIAL() of that
948 abstract function declaration will be later needed to output debug info. */
949 if (DECL_ABSTRACT_ORIGIN (decl))
951 struct cgraph_node *origin_node = cgraph_node (DECL_ABSTRACT_ORIGIN (decl));
952 origin_node->abstract_and_needed = true;
955 /* We finalize local static variables during constructing callgraph
956 edges. Process their attributes too. */
957 process_function_and_variable_attributes (first_processed,
959 first_processed = cgraph_nodes;
960 first_analyzed_var = varpool_nodes;
961 varpool_analyze_pending_decls ();
962 cgraph_process_new_functions ();
965 /* Collect entry points to the unit. */
966 if (cgraph_dump_file)
968 fprintf (cgraph_dump_file, "Unit entry points:");
969 for (node = cgraph_nodes; node != first_analyzed; node = node->next)
971 fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
972 fprintf (cgraph_dump_file, "\n\nInitial ");
973 dump_cgraph (cgraph_dump_file);
976 if (cgraph_dump_file)
977 fprintf (cgraph_dump_file, "\nReclaiming functions:");
979 for (node = cgraph_nodes; node != first_analyzed; node = next)
981 tree decl = node->decl;
984 if (node->local.finalized && !gimple_has_body_p (decl))
985 cgraph_reset_node (node);
987 if (!node->reachable && gimple_has_body_p (decl))
989 if (cgraph_dump_file)
990 fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
991 cgraph_remove_node (node);
995 node->next_needed = NULL;
996 gcc_assert (!node->local.finalized || gimple_has_body_p (decl));
997 gcc_assert (node->analyzed == node->local.finalized);
999 if (cgraph_dump_file)
1001 fprintf (cgraph_dump_file, "\n\nReclaimed ");
1002 dump_cgraph (cgraph_dump_file);
1004 first_analyzed = cgraph_nodes;
1008 /* Analyze the whole compilation unit once it is parsed completely. */
1011 cgraph_finalize_compilation_unit (void)
1013 if (errorcount || sorrycount)
1016 finalize_size_functions ();
1017 finish_aliases_1 ();
1021 fprintf (stderr, "\nAnalyzing compilation unit\n");
1025 timevar_push (TV_CGRAPH);
1026 cgraph_analyze_functions ();
1027 timevar_pop (TV_CGRAPH);
1031 /* Figure out what functions we want to assemble. */
1034 cgraph_mark_functions_to_output (void)
1036 struct cgraph_node *node;
1038 for (node = cgraph_nodes; node; node = node->next)
1040 tree decl = node->decl;
1041 struct cgraph_edge *e;
1043 gcc_assert (!node->process);
1045 for (e = node->callers; e; e = e->next_caller)
1046 if (e->inline_failed)
1049 /* We need to output all local functions that are used and not
1050 always inlined, as well as those that are reachable from
1051 outside the current compilation unit. */
1053 && !node->global.inlined_to
1055 || (e && node->reachable))
1056 && !TREE_ASM_WRITTEN (decl)
1057 && !DECL_EXTERNAL (decl))
1061 /* We should've reclaimed all functions that are not needed. */
1062 #ifdef ENABLE_CHECKING
1063 if (!node->global.inlined_to
1064 && gimple_has_body_p (decl)
1065 && !DECL_EXTERNAL (decl))
1067 dump_cgraph_node (stderr, node);
1068 internal_error ("failed to reclaim unneeded function");
1071 gcc_assert (node->global.inlined_to
1072 || !gimple_has_body_p (decl)
1073 || DECL_EXTERNAL (decl));
1080 /* Expand function specified by NODE. */
1083 cgraph_expand_function (struct cgraph_node *node)
1085 tree decl = node->decl;
1087 /* We ought to not compile any inline clones. */
1088 gcc_assert (!node->global.inlined_to);
1090 announce_function (decl);
1093 gcc_assert (node->lowered);
1095 /* Generate RTL for the body of DECL. */
1096 if (lang_hooks.callgraph.emit_associated_thunks
1097 && node->finalized_by_frontend)
1098 lang_hooks.callgraph.emit_associated_thunks (decl);
1099 tree_rest_of_compilation (decl);
1101 /* Make sure that BE didn't give up on compiling. */
1102 gcc_assert (TREE_ASM_WRITTEN (decl));
1103 current_function_decl = NULL;
1104 gcc_assert (!cgraph_preserve_function_body_p (decl));
1105 cgraph_release_function_body (node);
1106 /* Eliminate all call edges. This is important so the GIMPLE_CALL no longer
1107 points to the dead function body. */
1108 cgraph_node_remove_callees (node);
1110 cgraph_function_flags_ready = true;
1113 /* Return true when CALLER_DECL should be inlined into CALLEE_DECL. */
1116 cgraph_inline_p (struct cgraph_edge *e, cgraph_inline_failed_t *reason)
1118 *reason = e->inline_failed;
1119 return !e->inline_failed;
1124 /* Expand all functions that must be output.
1126 Attempt to topologically sort the nodes so function is output when
1127 all called functions are already assembled to allow data to be
1128 propagated across the callgraph. Use a stack to get smaller distance
1129 between a function and its callees (later we may choose to use a more
1130 sophisticated algorithm for function reordering; we will likely want
1131 to use subsections to make the output functions appear in top-down
1135 cgraph_expand_all_functions (void)
1137 struct cgraph_node *node;
1138 struct cgraph_node **order = XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
1139 int order_pos, new_order_pos = 0;
1142 order_pos = cgraph_postorder (order);
1143 gcc_assert (order_pos == cgraph_n_nodes);
1145 /* Garbage collector may remove inline clones we eliminate during
1146 optimization. So we must be sure to not reference them. */
1147 for (i = 0; i < order_pos; i++)
1148 if (order[i]->process)
1149 order[new_order_pos++] = order[i];
1151 for (i = new_order_pos - 1; i >= 0; i--)
1156 gcc_assert (node->reachable);
1158 cgraph_expand_function (node);
1161 cgraph_process_new_functions ();
1167 /* This is used to sort the node types by the cgraph order number. */
1169 enum cgraph_order_sort_kind
1171 ORDER_UNDEFINED = 0,
1177 struct cgraph_order_sort
1179 enum cgraph_order_sort_kind kind;
1182 struct cgraph_node *f;
1183 struct varpool_node *v;
1184 struct cgraph_asm_node *a;
1188 /* Output all functions, variables, and asm statements in the order
1189 according to their order fields, which is the order in which they
1190 appeared in the file. This implements -fno-toplevel-reorder. In
1191 this mode we may output functions and variables which don't really
1192 need to be output. */
1195 cgraph_output_in_order (void)
1199 struct cgraph_order_sort *nodes;
1201 struct cgraph_node *pf;
1202 struct varpool_node *pv;
1203 struct cgraph_asm_node *pa;
1206 size = max * sizeof (struct cgraph_order_sort);
1207 nodes = (struct cgraph_order_sort *) alloca (size);
1208 memset (nodes, 0, size);
1210 varpool_analyze_pending_decls ();
1212 for (pf = cgraph_nodes; pf; pf = pf->next)
1217 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
1218 nodes[i].kind = ORDER_FUNCTION;
1223 for (pv = varpool_nodes_queue; pv; pv = pv->next_needed)
1226 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
1227 nodes[i].kind = ORDER_VAR;
1231 for (pa = cgraph_asm_nodes; pa; pa = pa->next)
1234 gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
1235 nodes[i].kind = ORDER_ASM;
1239 /* In toplevel reorder mode we output all statics; mark them as needed. */
1240 for (i = 0; i < max; ++i)
1242 if (nodes[i].kind == ORDER_VAR)
1244 varpool_mark_needed_node (nodes[i].u.v);
1247 varpool_empty_needed_queue ();
1249 for (i = 0; i < max; ++i)
1251 switch (nodes[i].kind)
1253 case ORDER_FUNCTION:
1254 nodes[i].u.f->process = 0;
1255 cgraph_expand_function (nodes[i].u.f);
1259 varpool_assemble_decl (nodes[i].u.v);
1263 assemble_asm (nodes[i].u.a->asm_str);
1266 case ORDER_UNDEFINED:
1274 cgraph_asm_nodes = NULL;
1277 /* Return true when function body of DECL still needs to be kept around
1278 for later re-use. */
1280 cgraph_preserve_function_body_p (tree decl)
1282 struct cgraph_node *node;
1284 gcc_assert (cgraph_global_info_ready);
1285 /* Look if there is any clone around. */
1286 node = cgraph_node (decl);
1296 current_function_decl = NULL;
1297 gimple_register_cfg_hooks ();
1298 bitmap_obstack_initialize (NULL);
1299 execute_ipa_pass_list (all_ipa_passes);
1301 /* Generate coverage variables and constructors. */
1304 /* Process new functions added. */
1306 current_function_decl = NULL;
1307 cgraph_process_new_functions ();
1309 bitmap_obstack_release (NULL);
1312 /* Perform simple optimizations based on callgraph. */
1315 cgraph_optimize (void)
1317 if (errorcount || sorrycount)
1320 #ifdef ENABLE_CHECKING
1324 /* Call functions declared with the "constructor" or "destructor"
1326 cgraph_build_cdtor_fns ();
1328 /* Frontend may output common variables after the unit has been finalized.
1329 It is safe to deal with them here as they are always zero initialized. */
1330 varpool_analyze_pending_decls ();
1331 cgraph_analyze_functions ();
1333 timevar_push (TV_CGRAPHOPT);
1334 if (pre_ipa_mem_report)
1336 fprintf (stderr, "Memory consumption before IPA\n");
1337 dump_memory_report (false);
1340 fprintf (stderr, "Performing interprocedural optimizations\n");
1341 cgraph_state = CGRAPH_STATE_IPA;
1343 /* Don't run the IPA passes if there was any error or sorry messages. */
1344 if (errorcount == 0 && sorrycount == 0)
1347 /* This pass remove bodies of extern inline functions we never inlined.
1348 Do this later so other IPA passes see what is really going on. */
1349 cgraph_remove_unreachable_nodes (false, dump_file);
1350 cgraph_global_info_ready = true;
1351 if (cgraph_dump_file)
1353 fprintf (cgraph_dump_file, "Optimized ");
1354 dump_cgraph (cgraph_dump_file);
1355 dump_varpool (cgraph_dump_file);
1357 if (post_ipa_mem_report)
1359 fprintf (stderr, "Memory consumption after IPA\n");
1360 dump_memory_report (false);
1362 timevar_pop (TV_CGRAPHOPT);
1364 /* Output everything. */
1366 fprintf (stderr, "Assembling functions:\n");
1367 #ifdef ENABLE_CHECKING
1371 cgraph_materialize_all_clones ();
1372 cgraph_mark_functions_to_output ();
1374 cgraph_state = CGRAPH_STATE_EXPANSION;
1375 if (!flag_toplevel_reorder)
1376 cgraph_output_in_order ();
1379 cgraph_output_pending_asms ();
1381 cgraph_expand_all_functions ();
1382 varpool_remove_unreferenced_decls ();
1384 varpool_assemble_pending_decls ();
1386 cgraph_process_new_functions ();
1387 cgraph_state = CGRAPH_STATE_FINISHED;
1389 if (cgraph_dump_file)
1391 fprintf (cgraph_dump_file, "\nFinal ");
1392 dump_cgraph (cgraph_dump_file);
1394 #ifdef ENABLE_CHECKING
1396 /* Double check that all inline clones are gone and that all
1397 function bodies have been released from memory. */
1398 if (!(sorrycount || errorcount))
1400 struct cgraph_node *node;
1401 bool error_found = false;
1403 for (node = cgraph_nodes; node; node = node->next)
1405 && (node->global.inlined_to
1406 || gimple_has_body_p (node->decl)))
1409 dump_cgraph_node (stderr, node);
1412 internal_error ("nodes with unreleased memory found");
1416 /* Generate and emit a static constructor or destructor. WHICH must
1417 be one of 'I' (for a constructor) or 'D' (for a destructor). BODY
1418 is a STATEMENT_LIST containing GENERIC statements. PRIORITY is the
1419 initialization priority for this constructor or destructor. */
1422 cgraph_build_static_cdtor (char which, tree body, int priority)
1424 static int counter = 0;
1426 tree decl, name, resdecl;
1428 /* The priority is encoded in the constructor or destructor name.
1429 collect2 will sort the names and arrange that they are called at
1431 sprintf (which_buf, "%c_%.5d_%d", which, priority, counter++);
1432 name = get_file_function_name (which_buf);
1434 decl = build_decl (input_location, FUNCTION_DECL, name,
1435 build_function_type (void_type_node, void_list_node));
1436 current_function_decl = decl;
1438 resdecl = build_decl (input_location,
1439 RESULT_DECL, NULL_TREE, void_type_node);
1440 DECL_ARTIFICIAL (resdecl) = 1;
1441 DECL_RESULT (decl) = resdecl;
1442 DECL_CONTEXT (resdecl) = decl;
1444 allocate_struct_function (decl, false);
1446 TREE_STATIC (decl) = 1;
1447 TREE_USED (decl) = 1;
1448 DECL_ARTIFICIAL (decl) = 1;
1449 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1450 DECL_SAVED_TREE (decl) = body;
1451 TREE_PUBLIC (decl) = ! targetm.have_ctors_dtors;
1452 DECL_UNINLINABLE (decl) = 1;
1454 DECL_INITIAL (decl) = make_node (BLOCK);
1455 TREE_USED (DECL_INITIAL (decl)) = 1;
1457 DECL_SOURCE_LOCATION (decl) = input_location;
1458 cfun->function_end_locus = input_location;
1463 DECL_STATIC_CONSTRUCTOR (decl) = 1;
1464 decl_init_priority_insert (decl, priority);
1467 DECL_STATIC_DESTRUCTOR (decl) = 1;
1468 decl_fini_priority_insert (decl, priority);
1474 gimplify_function_tree (decl);
1476 cgraph_add_new_function (decl, false);
1477 cgraph_mark_needed_node (cgraph_node (decl));
1484 cgraph_dump_file = dump_begin (TDI_cgraph, NULL);
1487 /* The edges representing the callers of the NEW_VERSION node were
1488 fixed by cgraph_function_versioning (), now the call_expr in their
1489 respective tree code should be updated to call the NEW_VERSION. */
1492 update_call_expr (struct cgraph_node *new_version)
1494 struct cgraph_edge *e;
1496 gcc_assert (new_version);
1498 /* Update the call expr on the edges to call the new version. */
1499 for (e = new_version->callers; e; e = e->next_caller)
1501 struct function *inner_function = DECL_STRUCT_FUNCTION (e->caller->decl);
1502 gimple_call_set_fndecl (e->call_stmt, new_version->decl);
1503 /* Update EH information too, just in case. */
1504 if (!stmt_could_throw_p (e->call_stmt)
1505 && lookup_stmt_eh_region_fn (inner_function, e->call_stmt))
1506 remove_stmt_from_eh_region_fn (inner_function, e->call_stmt);
1511 /* Create a new cgraph node which is the new version of
1512 OLD_VERSION node. REDIRECT_CALLERS holds the callers
1513 edges which should be redirected to point to
1514 NEW_VERSION. ALL the callees edges of OLD_VERSION
1515 are cloned to the new version node. Return the new
1518 static struct cgraph_node *
1519 cgraph_copy_node_for_versioning (struct cgraph_node *old_version,
1521 VEC(cgraph_edge_p,heap) *redirect_callers)
1523 struct cgraph_node *new_version;
1524 struct cgraph_edge *e, *new_e;
1525 struct cgraph_edge *next_callee;
1528 gcc_assert (old_version);
1530 new_version = cgraph_node (new_decl);
1532 new_version->analyzed = true;
1533 new_version->local = old_version->local;
1534 new_version->global = old_version->global;
1535 new_version->rtl = new_version->rtl;
1536 new_version->reachable = true;
1537 new_version->count = old_version->count;
1539 /* Clone the old node callees. Recursive calls are
1541 for (e = old_version->callees;e; e=e->next_callee)
1543 new_e = cgraph_clone_edge (e, new_version, e->call_stmt, 0, e->frequency,
1544 e->loop_nest, true);
1545 new_e->count = e->count;
1547 /* Fix recursive calls.
1548 If OLD_VERSION has a recursive call after the
1549 previous edge cloning, the new version will have an edge
1550 pointing to the old version, which is wrong;
1551 Redirect it to point to the new version. */
1552 for (e = new_version->callees ; e; e = next_callee)
1554 next_callee = e->next_callee;
1555 if (e->callee == old_version)
1556 cgraph_redirect_edge_callee (e, new_version);
1561 for (i = 0; VEC_iterate (cgraph_edge_p, redirect_callers, i, e); i++)
1563 /* Redirect calls to the old version node to point to its new
1565 cgraph_redirect_edge_callee (e, new_version);
1571 /* Perform function versioning.
1572 Function versioning includes copying of the tree and
1573 a callgraph update (creating a new cgraph node and updating
1574 its callees and callers).
1576 REDIRECT_CALLERS varray includes the edges to be redirected
1579 TREE_MAP is a mapping of tree nodes we want to replace with
1580 new ones (according to results of prior analysis).
1581 OLD_VERSION_NODE is the node that is versioned.
1582 It returns the new version's cgraph node.
1583 ARGS_TO_SKIP lists arguments to be omitted from functions
1586 struct cgraph_node *
1587 cgraph_function_versioning (struct cgraph_node *old_version_node,
1588 VEC(cgraph_edge_p,heap) *redirect_callers,
1589 VEC (ipa_replace_map_p,gc)* tree_map,
1590 bitmap args_to_skip)
1592 tree old_decl = old_version_node->decl;
1593 struct cgraph_node *new_version_node = NULL;
1596 if (!tree_versionable_function_p (old_decl))
1599 /* Make a new FUNCTION_DECL tree node for the
1602 new_decl = copy_node (old_decl);
1604 new_decl = build_function_decl_skip_args (old_decl, args_to_skip);
1606 /* Create the new version's call-graph node.
1607 and update the edges of the new node. */
1609 cgraph_copy_node_for_versioning (old_version_node, new_decl,
1612 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1613 tree_function_versioning (old_decl, new_decl, tree_map, false, args_to_skip);
1615 /* Update the new version's properties.
1616 Make The new version visible only within this translation unit. Make sure
1617 that is not weak also.
1618 ??? We cannot use COMDAT linkage because there is no
1619 ABI support for this. */
1620 DECL_EXTERNAL (new_version_node->decl) = 0;
1621 DECL_COMDAT_GROUP (new_version_node->decl) = NULL_TREE;
1622 TREE_PUBLIC (new_version_node->decl) = 0;
1623 DECL_COMDAT (new_version_node->decl) = 0;
1624 DECL_WEAK (new_version_node->decl) = 0;
1625 DECL_VIRTUAL_P (new_version_node->decl) = 0;
1626 new_version_node->local.externally_visible = 0;
1627 new_version_node->local.local = 1;
1628 new_version_node->lowered = true;
1630 /* Update the call_expr on the edges to call the new version node. */
1631 update_call_expr (new_version_node);
1633 cgraph_call_function_insertion_hooks (new_version_node);
1634 return new_version_node;
1637 /* Produce separate function body for inline clones so the offline copy can be
1638 modified without affecting them. */
1639 struct cgraph_node *
1640 save_inline_function_body (struct cgraph_node *node)
1642 struct cgraph_node *first_clone, *n;
1644 gcc_assert (node == cgraph_node (node->decl));
1646 cgraph_lower_function (node);
1648 first_clone = node->clones;
1650 first_clone->decl = copy_node (node->decl);
1651 cgraph_insert_node_to_hashtable (first_clone);
1652 gcc_assert (first_clone == cgraph_node (first_clone->decl));
1653 if (first_clone->next_sibling_clone)
1655 for (n = first_clone->next_sibling_clone; n->next_sibling_clone; n = n->next_sibling_clone)
1656 n->clone_of = first_clone;
1657 n->clone_of = first_clone;
1658 n->next_sibling_clone = first_clone->clones;
1659 if (first_clone->clones)
1660 first_clone->clones->prev_sibling_clone = n;
1661 first_clone->clones = first_clone->next_sibling_clone;
1662 first_clone->next_sibling_clone->prev_sibling_clone = NULL;
1663 first_clone->next_sibling_clone = NULL;
1664 gcc_assert (!first_clone->prev_sibling_clone);
1666 first_clone->clone_of = NULL;
1667 node->clones = NULL;
1669 if (first_clone->clones)
1670 for (n = first_clone->clones; n != first_clone;)
1672 gcc_assert (n->decl == node->decl);
1673 n->decl = first_clone->decl;
1676 else if (n->next_sibling_clone)
1677 n = n->next_sibling_clone;
1680 while (n != first_clone && !n->next_sibling_clone)
1682 if (n != first_clone)
1683 n = n->next_sibling_clone;
1687 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1688 tree_function_versioning (node->decl, first_clone->decl, NULL, true, NULL);
1690 DECL_EXTERNAL (first_clone->decl) = 0;
1691 DECL_COMDAT_GROUP (first_clone->decl) = NULL_TREE;
1692 TREE_PUBLIC (first_clone->decl) = 0;
1693 DECL_COMDAT (first_clone->decl) = 0;
1694 VEC_free (ipa_opt_pass, heap,
1695 DECL_STRUCT_FUNCTION (first_clone->decl)->ipa_transforms_to_apply);
1696 DECL_STRUCT_FUNCTION (first_clone->decl)->ipa_transforms_to_apply = NULL;
1698 #ifdef ENABLE_CHECKING
1699 verify_cgraph_node (first_clone);
1704 /* Given virtual clone, turn it into actual clone. */
1706 cgraph_materialize_clone (struct cgraph_node *node)
1708 bitmap_obstack_initialize (NULL);
1709 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1710 tree_function_versioning (node->clone_of->decl, node->decl,
1711 node->clone.tree_map, true,
1712 node->clone.args_to_skip);
1714 /* Function is no longer clone. */
1715 if (node->next_sibling_clone)
1716 node->next_sibling_clone->prev_sibling_clone = node->prev_sibling_clone;
1717 if (node->prev_sibling_clone)
1718 node->prev_sibling_clone->next_sibling_clone = node->next_sibling_clone;
1720 node->clone_of->clones = node->next_sibling_clone;
1721 node->next_sibling_clone = NULL;
1722 node->prev_sibling_clone = NULL;
1723 node->clone_of = NULL;
1724 bitmap_obstack_release (NULL);
1727 /* Once all functions from compilation unit are in memory, produce all clones
1728 and update all calls.
1729 We might also do this on demand if we don't want to bring all functions to
1730 memory prior compilation, but current WHOPR implementation does that and it is
1731 is bit easier to keep everything right in this order. */
1733 cgraph_materialize_all_clones (void)
1735 struct cgraph_node *node;
1736 bool stabilized = false;
1738 if (cgraph_dump_file)
1739 fprintf (cgraph_dump_file, "Materializing clones\n");
1740 #ifdef ENABLE_CHECKING
1744 /* We can also do topological order, but number of iterations should be
1745 bounded by number of IPA passes since single IPA pass is probably not
1746 going to create clones of clones it created itself. */
1750 for (node = cgraph_nodes; node; node = node->next)
1752 if (node->clone_of && node->decl != node->clone_of->decl
1753 && !gimple_has_body_p (node->decl))
1755 if (gimple_has_body_p (node->clone_of->decl))
1757 if (cgraph_dump_file)
1758 fprintf (cgraph_dump_file, " clonning %s to %s",
1759 cgraph_node_name (node->clone_of),
1760 cgraph_node_name (node));
1761 cgraph_materialize_clone (node);
1768 if (cgraph_dump_file)
1769 fprintf (cgraph_dump_file, "Updating call sites\n");
1770 for (node = cgraph_nodes; node; node = node->next)
1771 if (node->analyzed && gimple_has_body_p (node->decl)
1772 && (!node->clone_of || node->clone_of->decl != node->decl))
1774 struct cgraph_edge *e;
1776 current_function_decl = node->decl;
1777 push_cfun (DECL_STRUCT_FUNCTION (node->decl));
1778 for (e = node->callees; e; e = e->next_callee)
1780 tree decl = gimple_call_fndecl (e->call_stmt);
1781 /* When function gets inlined, indirect inlining might've invented
1782 new edge for orginally indirect stmt. Since we are not
1783 preserving clones in the original form, we must not update here
1784 since other inline clones don't need to contain call to the same
1785 call. Inliner will do the substitution for us later. */
1786 if (decl && decl != e->callee->decl)
1789 gimple_stmt_iterator gsi;
1791 if (cgraph_dump_file)
1793 fprintf (cgraph_dump_file, "updating call of %s in %s:",
1794 cgraph_node_name (node),
1795 cgraph_node_name (e->callee));
1796 print_gimple_stmt (cgraph_dump_file, e->call_stmt, 0, dump_flags);
1799 if (e->callee->clone.args_to_skip)
1800 new_stmt = gimple_call_copy_skip_args (e->call_stmt,
1801 e->callee->clone.args_to_skip);
1803 new_stmt = e->call_stmt;
1804 if (gimple_vdef (new_stmt)
1805 && TREE_CODE (gimple_vdef (new_stmt)) == SSA_NAME)
1806 SSA_NAME_DEF_STMT (gimple_vdef (new_stmt)) = new_stmt;
1807 gimple_call_set_fndecl (new_stmt, e->callee->decl);
1809 gsi = gsi_for_stmt (e->call_stmt);
1810 gsi_replace (&gsi, new_stmt, true);
1812 /* Update EH information too, just in case. */
1813 if (!stmt_could_throw_p (new_stmt)
1814 && lookup_stmt_eh_region (new_stmt))
1815 remove_stmt_from_eh_region (new_stmt);
1817 cgraph_set_call_stmt_including_clones (node, e->call_stmt, new_stmt);
1819 if (cgraph_dump_file)
1821 fprintf (cgraph_dump_file, " updated to:");
1822 print_gimple_stmt (cgraph_dump_file, e->call_stmt, 0, dump_flags);
1827 current_function_decl = NULL;
1828 #ifdef ENABLE_CHECKING
1829 verify_cgraph_node (node);
1832 #ifdef ENABLE_CHECKING
1835 cgraph_remove_unreachable_nodes (false, cgraph_dump_file);
1838 #include "gt-cgraphunit.h"