1 /* Callgraph based interprocedural optimizations.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
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 unit-at-a-time 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 We implement two compilation modes.
82 - unit-at-a-time: In this mode analyzing of all functions is deferred
83 to cgraph_finalize_compilation_unit and expansion into cgraph_optimize.
85 In cgraph_finalize_compilation_unit the reachable functions are
86 analyzed. During analysis the call-graph edges from reachable
87 functions are constructed and their destinations are marked as
88 reachable. References to functions and variables are discovered too
89 and variables found to be needed output to the assembly file. Via
90 mark_referenced call in assemble_variable functions referenced by
91 static variables are noticed too.
93 The intra-procedural information is produced and its existence
94 indicated by global_info_ready. Once this flag is set it is impossible
95 to change function from !reachable to reachable and thus
96 assemble_variable no longer call mark_referenced.
98 Finally the call-graph is topologically sorted and all reachable functions
99 that has not been completely inlined or are not external are output.
101 ??? It is possible that reference to function or variable is optimized
102 out. We can not deal with this nicely because topological order is not
103 suitable for it. For tree-ssa we may consider another pass doing
104 optimization and re-discovering reachable functions.
106 ??? Reorganize code so variables are output very last and only if they
107 really has been referenced by produced code, so we catch more cases
108 where reference has been optimized out.
112 All functions are variables are output as early as possible to conserve
113 memory consumption. This may or may not result in less memory used but
114 it is still needed for some legacy code that rely on particular ordering
115 of things output from the compiler.
117 Varpool data structures are not used and variables are output directly.
119 Functions are output early using call of
120 cgraph_assemble_pending_function from cgraph_finalize_function. The
121 decision on whether function is needed is made more conservative so
122 uninlininable static functions are needed too. During the call-graph
123 construction the edge destinations are not marked as reachable and it
124 is completely relied upn assemble_variable to mark them. */
129 #include "coretypes.h"
133 #include "tree-flow.h"
134 #include "tree-inline.h"
135 #include "langhooks.h"
136 #include "pointer-set.h"
143 #include "diagnostic.h"
147 #include "c-common.h"
149 #include "function.h"
150 #include "ipa-prop.h"
151 #include "tree-gimple.h"
152 #include "tree-pass.h"
155 static void cgraph_expand_all_functions (void);
156 static void cgraph_mark_functions_to_output (void);
157 static void cgraph_expand_function (struct cgraph_node
*);
158 static void cgraph_output_pending_asms (void);
160 static FILE *cgraph_dump_file
;
162 /* A vector of FUNCTION_DECLs declared as static constructors. */
163 static GTY (()) VEC(tree
, gc
) *static_ctors
;
164 /* A vector of FUNCTION_DECLs declared as static destructors. */
165 static GTY (()) VEC(tree
, gc
) *static_dtors
;
167 /* When target does not have ctors and dtors, we call all constructor
168 and destructor by special initialization/destruction function
169 recognized by collect2.
171 When we are going to build this function, collect all constructors and
172 destructors and turn them into normal functions. */
175 record_cdtor_fn (tree fndecl
)
177 struct cgraph_node
*node
;
178 if (targetm
.have_ctors_dtors
179 || (!DECL_STATIC_CONSTRUCTOR (fndecl
)
180 && !DECL_STATIC_DESTRUCTOR (fndecl
)))
183 if (DECL_STATIC_CONSTRUCTOR (fndecl
))
185 VEC_safe_push (tree
, gc
, static_ctors
, fndecl
);
186 DECL_STATIC_CONSTRUCTOR (fndecl
) = 0;
188 if (DECL_STATIC_DESTRUCTOR (fndecl
))
190 VEC_safe_push (tree
, gc
, static_dtors
, fndecl
);
191 DECL_STATIC_DESTRUCTOR (fndecl
) = 0;
193 DECL_INLINE (fndecl
) = 1;
194 node
= cgraph_node (fndecl
);
195 node
->local
.disregard_inline_limits
= 1;
196 cgraph_mark_reachable_node (node
);
199 /* Define global constructors/destructor functions for the CDTORS, of
200 which they are LEN. The CDTORS are sorted by initialization
201 priority. If CTOR_P is true, these are constructors; otherwise,
202 they are destructors. */
205 build_cdtor (bool ctor_p
, tree
*cdtors
, size_t len
)
214 priority_type priority
;
218 /* Find the next batch of constructors/destructors with the same
219 initialization priority. */
224 p
= ctor_p
? DECL_INIT_PRIORITY (fn
) : DECL_FINI_PRIORITY (fn
);
227 else if (p
!= priority
)
229 append_to_statement_list (build_function_call_expr (fn
, 0),
234 gcc_assert (body
!= NULL_TREE
);
235 /* Generate a function to call all the function of like
237 cgraph_build_static_cdtor (ctor_p
? 'I' : 'D', body
, priority
);
241 /* Comparison function for qsort. P1 and P2 are actually of type
242 "tree *" and point to static constructors. DECL_INIT_PRIORITY is
243 used to determine the sort order. */
246 compare_ctor (const void *p1
, const void *p2
)
253 f1
= *(const tree
*)p1
;
254 f2
= *(const tree
*)p2
;
255 priority1
= DECL_INIT_PRIORITY (f1
);
256 priority2
= DECL_INIT_PRIORITY (f2
);
258 if (priority1
< priority2
)
260 else if (priority1
> priority2
)
263 /* Ensure a stable sort. */
264 return (const tree
*)p1
- (const tree
*)p2
;
267 /* Comparison function for qsort. P1 and P2 are actually of type
268 "tree *" and point to static destructors. DECL_FINI_PRIORITY is
269 used to determine the sort order. */
272 compare_dtor (const void *p1
, const void *p2
)
279 f1
= *(const tree
*)p1
;
280 f2
= *(const tree
*)p2
;
281 priority1
= DECL_FINI_PRIORITY (f1
);
282 priority2
= DECL_FINI_PRIORITY (f2
);
284 if (priority1
< priority2
)
286 else if (priority1
> priority2
)
289 /* Ensure a stable sort. */
290 return (const tree
*)p1
- (const tree
*)p2
;
293 /* Generate functions to call static constructors and destructors
294 for targets that do not support .ctors/.dtors sections. These
295 functions have magic names which are detected by collect2. */
298 cgraph_build_cdtor_fns (void)
300 if (!VEC_empty (tree
, static_ctors
))
302 gcc_assert (!targetm
.have_ctors_dtors
);
303 qsort (VEC_address (tree
, static_ctors
),
304 VEC_length (tree
, static_ctors
),
307 build_cdtor (/*ctor_p=*/true,
308 VEC_address (tree
, static_ctors
),
309 VEC_length (tree
, static_ctors
));
310 VEC_truncate (tree
, static_ctors
, 0);
313 if (!VEC_empty (tree
, static_dtors
))
315 gcc_assert (!targetm
.have_ctors_dtors
);
316 qsort (VEC_address (tree
, static_dtors
),
317 VEC_length (tree
, static_dtors
),
320 build_cdtor (/*ctor_p=*/false,
321 VEC_address (tree
, static_dtors
),
322 VEC_length (tree
, static_dtors
));
323 VEC_truncate (tree
, static_dtors
, 0);
327 /* Determine if function DECL is needed. That is, visible to something
328 either outside this translation unit, something magic in the system
329 configury, or (if not doing unit-at-a-time) to something we havn't
333 decide_is_function_needed (struct cgraph_node
*node
, tree decl
)
336 if (MAIN_NAME_P (DECL_NAME (decl
))
337 && TREE_PUBLIC (decl
))
339 node
->local
.externally_visible
= true;
343 /* If the user told us it is used, then it must be so. */
344 if (node
->local
.externally_visible
)
347 if (!flag_unit_at_a_time
&& lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
350 /* ??? If the assembler name is set by hand, it is possible to assemble
351 the name later after finalizing the function and the fact is noticed
352 in assemble_name then. This is arguably a bug. */
353 if (DECL_ASSEMBLER_NAME_SET_P (decl
)
354 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)))
357 /* With -fkeep-inline-functions we are keeping all inline functions except
358 for extern inline ones. */
359 if (flag_keep_inline_functions
360 && DECL_DECLARED_INLINE_P (decl
)
361 && !DECL_EXTERNAL (decl
)
362 && !lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl
)))
365 /* If we decided it was needed before, but at the time we didn't have
366 the body of the function available, then it's still needed. We have
367 to go back and re-check its dependencies now. */
371 /* Externally visible functions must be output. The exception is
372 COMDAT functions that must be output only when they are needed.
374 When not optimizing, also output the static functions. (see
375 PR24561), but don't do so for always_inline functions, functions
376 declared inline and nested functions. These was optimized out
377 in the original implementation and it is unclear whether we want
378 to change the behavior here. */
379 if (((TREE_PUBLIC (decl
)
380 || (!optimize
&& !node
->local
.disregard_inline_limits
381 && !DECL_DECLARED_INLINE_P (decl
)
383 && !flag_whole_program
)
384 && !DECL_COMDAT (decl
) && !DECL_EXTERNAL (decl
))
387 /* Constructors and destructors are reachable from the runtime by
389 if (DECL_STATIC_CONSTRUCTOR (decl
) || DECL_STATIC_DESTRUCTOR (decl
))
392 if (flag_unit_at_a_time
)
395 /* If not doing unit at a time, then we'll only defer this function
396 if its marked for inlining. Otherwise we want to emit it now. */
398 /* "extern inline" functions are never output locally. */
399 if (DECL_EXTERNAL (decl
))
401 /* Nested functions of extern inline function shall not be emit unless
402 we inlined the origin. */
403 for (origin
= decl_function_context (decl
); origin
;
404 origin
= decl_function_context (origin
))
405 if (DECL_EXTERNAL (origin
))
407 /* We want to emit COMDAT functions only when absolutely necessary. */
408 if (DECL_COMDAT (decl
))
410 if (!DECL_INLINE (decl
)
411 || (!node
->local
.disregard_inline_limits
412 /* When declared inline, defer even the uninlinable functions.
413 This allows them to be eliminated when unused. */
414 && !DECL_DECLARED_INLINE_P (decl
)
415 && (!node
->local
.inlinable
|| !cgraph_default_inline_p (node
, NULL
))))
421 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
422 functions into callgraph in a way so they look like ordinary reachable
423 functions inserted into callgraph already at construction time. */
426 cgraph_process_new_functions (void)
430 struct cgraph_node
*node
;
432 /* Note that this queue may grow as its being processed, as the new
433 functions may generate new ones. */
434 while (cgraph_new_nodes
)
436 node
= cgraph_new_nodes
;
438 cgraph_new_nodes
= cgraph_new_nodes
->next_needed
;
439 switch (cgraph_state
)
441 case CGRAPH_STATE_CONSTRUCTION
:
442 /* At construction time we just need to finalize function and move
443 it into reachable functions list. */
445 node
->next_needed
= NULL
;
446 node
->needed
= node
->reachable
= false;
447 cgraph_finalize_function (fndecl
, false);
448 cgraph_mark_reachable_node (node
);
452 case CGRAPH_STATE_IPA
:
453 case CGRAPH_STATE_IPA_SSA
:
454 /* When IPA optimization already started, do all essential
455 transformations that has been already performed on the whole
456 cgraph but not on this function. */
458 tree_register_cfg_hooks ();
460 cgraph_analyze_function (node
);
461 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
462 current_function_decl
= fndecl
;
463 node
->local
.inlinable
= tree_inlinable_function_p (fndecl
);
464 node
->local
.self_insns
= estimate_num_insns (fndecl
,
465 &eni_inlining_weights
);
466 node
->local
.disregard_inline_limits
467 |= DECL_DISREGARD_INLINE_LIMITS (fndecl
);
468 /* Inlining characteristics are maintained by the
469 cgraph_mark_inline. */
470 node
->global
.insns
= node
->local
.self_insns
;
471 if (flag_really_no_inline
&& !node
->local
.disregard_inline_limits
)
472 node
->local
.inlinable
= 0;
473 if ((cgraph_state
== CGRAPH_STATE_IPA_SSA
474 && !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl
)))
475 /* When not optimizing, be sure we run early local passes anyway
478 execute_pass_list (pass_early_local_passes
.sub
);
479 free_dominance_info (CDI_POST_DOMINATORS
);
480 free_dominance_info (CDI_DOMINATORS
);
482 current_function_decl
= NULL
;
485 case CGRAPH_STATE_EXPANSION
:
486 /* Functions created during expansion shall be compiled
489 cgraph_expand_function (node
);
500 /* When not doing unit-at-a-time, output all functions enqueued.
501 Return true when such a functions were found. */
504 cgraph_assemble_pending_functions (void)
508 if (flag_unit_at_a_time
)
511 cgraph_output_pending_asms ();
513 while (cgraph_nodes_queue
)
515 struct cgraph_node
*n
= cgraph_nodes_queue
;
517 cgraph_nodes_queue
= cgraph_nodes_queue
->next_needed
;
518 n
->next_needed
= NULL
;
519 if (!n
->global
.inlined_to
521 && !DECL_EXTERNAL (n
->decl
))
523 cgraph_expand_function (n
);
526 output
|= cgraph_process_new_functions ();
533 /* As an GCC extension we allow redefinition of the function. The
534 semantics when both copies of bodies differ is not well defined.
535 We replace the old body with new body so in unit at a time mode
536 we always use new body, while in normal mode we may end up with
537 old body inlined into some functions and new body expanded and
540 ??? It may make more sense to use one body for inlining and other
541 body for expanding the function but this is difficult to do. */
544 cgraph_reset_node (struct cgraph_node
*node
)
546 /* If node->output is set, then this is a unit-at-a-time compilation
547 and we have already begun whole-unit analysis. This is *not*
548 testing for whether we've already emitted the function. That
549 case can be sort-of legitimately seen with real function
550 redefinition errors. I would argue that the front end should
551 never present us with such a case, but don't enforce that for now. */
552 gcc_assert (!node
->output
);
554 /* Reset our data structures so we can analyze the function again. */
555 memset (&node
->local
, 0, sizeof (node
->local
));
556 memset (&node
->global
, 0, sizeof (node
->global
));
557 memset (&node
->rtl
, 0, sizeof (node
->rtl
));
558 node
->analyzed
= false;
559 node
->local
.redefined_extern_inline
= true;
560 node
->local
.finalized
= false;
562 if (!flag_unit_at_a_time
)
564 struct cgraph_node
*n
, *next
;
566 for (n
= cgraph_nodes
; n
; n
= next
)
569 if (n
->global
.inlined_to
== node
)
570 cgraph_remove_node (n
);
574 cgraph_node_remove_callees (node
);
576 /* We may need to re-queue the node for assembling in case
577 we already proceeded it and ignored as not needed or got
578 a re-declaration in IMA mode. */
581 struct cgraph_node
*n
;
583 for (n
= cgraph_nodes_queue
; n
; n
= n
->next_needed
)
592 cgraph_lower_function (struct cgraph_node
*node
)
596 tree_lowering_passes (node
->decl
);
597 node
->lowered
= true;
600 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
601 logic in effect. If NESTED is true, then our caller cannot stand to have
602 the garbage collector run at the moment. We would need to either create
603 a new GC context, or just not compile right now. */
606 cgraph_finalize_function (tree decl
, bool nested
)
608 struct cgraph_node
*node
= cgraph_node (decl
);
610 if (node
->local
.finalized
)
611 cgraph_reset_node (node
);
613 node
->pid
= cgraph_max_pid
++;
614 notice_global_symbol (decl
);
616 node
->local
.finalized
= true;
617 node
->lowered
= DECL_STRUCT_FUNCTION (decl
)->cfg
!= NULL
;
618 record_cdtor_fn (node
->decl
);
620 lower_nested_functions (decl
);
621 gcc_assert (!node
->nested
);
623 /* If not unit at a time, then we need to create the call graph
624 now, so that called functions can be queued and emitted now. */
625 if (!flag_unit_at_a_time
)
626 cgraph_analyze_function (node
);
628 if (decide_is_function_needed (node
, decl
))
629 cgraph_mark_needed_node (node
);
631 /* Since we reclaim unreachable nodes at the end of every language
632 level unit, we need to be conservative about possible entry points
634 if ((TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
) && !DECL_EXTERNAL (decl
)))
635 cgraph_mark_reachable_node (node
);
637 /* If not unit at a time, go ahead and emit everything we've found
638 to be reachable at this time. */
641 if (!cgraph_assemble_pending_functions ())
645 /* If we've not yet emitted decl, tell the debug info about it. */
646 if (!TREE_ASM_WRITTEN (decl
))
647 (*debug_hooks
->deferred_inline_function
) (decl
);
649 /* Possibly warn about unused parameters. */
650 if (warn_unused_parameter
)
651 do_warn_unused_parameter (decl
);
654 /* Verify cgraph nodes of given cgraph node. */
656 verify_cgraph_node (struct cgraph_node
*node
)
658 struct cgraph_edge
*e
;
659 struct cgraph_node
*main_clone
;
660 struct function
*this_cfun
= DECL_STRUCT_FUNCTION (node
->decl
);
661 struct function
*saved_cfun
= cfun
;
662 basic_block this_block
;
663 block_stmt_iterator bsi
;
664 bool error_found
= false;
666 if (errorcount
|| sorrycount
)
669 timevar_push (TV_CGRAPH_VERIFY
);
670 /* debug_generic_stmt needs correct cfun */
671 set_cfun (this_cfun
);
672 for (e
= node
->callees
; e
; e
= e
->next_callee
)
675 error ("aux field set for edge %s->%s",
676 cgraph_node_name (e
->caller
), cgraph_node_name (e
->callee
));
681 error ("Execution count is negative");
684 for (e
= node
->callers
; e
; e
= e
->next_caller
)
688 error ("caller edge count is negative");
691 if (e
->frequency
< 0)
693 error ("caller edge frequency is negative");
696 if (e
->frequency
> CGRAPH_FREQ_MAX
)
698 error ("caller edge frequency is too large");
701 if (!e
->inline_failed
)
703 if (node
->global
.inlined_to
704 != (e
->caller
->global
.inlined_to
705 ? e
->caller
->global
.inlined_to
: e
->caller
))
707 error ("inlined_to pointer is wrong");
710 if (node
->callers
->next_caller
)
712 error ("multiple inline callers");
717 if (node
->global
.inlined_to
)
719 error ("inlined_to pointer set for noninline callers");
723 if (!node
->callers
&& node
->global
.inlined_to
)
725 error ("inlined_to pointer is set but no predecessors found");
728 if (node
->global
.inlined_to
== node
)
730 error ("inlined_to pointer refers to itself");
734 for (main_clone
= cgraph_node (node
->decl
); main_clone
;
735 main_clone
= main_clone
->next_clone
)
736 if (main_clone
== node
)
738 if (!cgraph_node (node
->decl
))
740 error ("node not found in cgraph_hash");
745 && DECL_SAVED_TREE (node
->decl
) && !TREE_ASM_WRITTEN (node
->decl
)
746 && (!DECL_EXTERNAL (node
->decl
) || node
->global
.inlined_to
))
750 /* The nodes we're interested in are never shared, so walk
751 the tree ignoring duplicates. */
752 struct pointer_set_t
*visited_nodes
= pointer_set_create ();
753 /* Reach the trees by walking over the CFG, and note the
754 enclosing basic-blocks in the call edges. */
755 FOR_EACH_BB_FN (this_block
, this_cfun
)
756 for (bsi
= bsi_start (this_block
); !bsi_end_p (bsi
); bsi_next (&bsi
))
758 tree stmt
= bsi_stmt (bsi
);
759 tree call
= get_call_expr_in (stmt
);
761 if (call
&& (decl
= get_callee_fndecl (call
)))
763 struct cgraph_edge
*e
= cgraph_edge (node
, stmt
);
768 error ("shared call_stmt:");
769 debug_generic_stmt (stmt
);
772 if (e
->callee
->decl
!= cgraph_node (decl
)->decl
775 error ("edge points to wrong declaration:");
776 debug_tree (e
->callee
->decl
);
777 fprintf (stderr
," Instead of:");
784 error ("missing callgraph edge for call stmt:");
785 debug_generic_stmt (stmt
);
790 pointer_set_destroy (visited_nodes
);
793 /* No CFG available?! */
796 for (e
= node
->callees
; e
; e
= e
->next_callee
)
800 error ("edge %s->%s has no corresponding call_stmt",
801 cgraph_node_name (e
->caller
),
802 cgraph_node_name (e
->callee
));
803 debug_generic_stmt (e
->call_stmt
);
811 dump_cgraph_node (stderr
, node
);
812 internal_error ("verify_cgraph_node failed");
814 set_cfun (saved_cfun
);
815 timevar_pop (TV_CGRAPH_VERIFY
);
818 /* Verify whole cgraph structure. */
822 struct cgraph_node
*node
;
824 if (sorrycount
|| errorcount
)
827 for (node
= cgraph_nodes
; node
; node
= node
->next
)
828 verify_cgraph_node (node
);
831 /* Output all asm statements we have stored up to be output. */
834 cgraph_output_pending_asms (void)
836 struct cgraph_asm_node
*can
;
838 if (errorcount
|| sorrycount
)
841 for (can
= cgraph_asm_nodes
; can
; can
= can
->next
)
842 assemble_asm (can
->asm_str
);
843 cgraph_asm_nodes
= NULL
;
846 /* Analyze the function scheduled to be output. */
848 cgraph_analyze_function (struct cgraph_node
*node
)
850 tree decl
= node
->decl
;
852 current_function_decl
= decl
;
853 push_cfun (DECL_STRUCT_FUNCTION (decl
));
854 cgraph_lower_function (node
);
855 node
->analyzed
= true;
857 if (!flag_unit_at_a_time
)
859 bitmap_obstack_initialize (NULL
);
860 tree_register_cfg_hooks ();
861 execute_pass_list (pass_early_local_passes
.sub
);
862 free_dominance_info (CDI_POST_DOMINATORS
);
863 free_dominance_info (CDI_DOMINATORS
);
864 bitmap_obstack_release (NULL
);
868 current_function_decl
= NULL
;
871 /* Look for externally_visible and used attributes and mark cgraph nodes
874 We cannot mark the nodes at the point the attributes are processed (in
875 handle_*_attribute) because the copy of the declarations available at that
876 point may not be canonical. For example, in:
879 void f() __attribute__((used));
881 the declaration we see in handle_used_attribute will be the second
882 declaration -- but the front end will subsequently merge that declaration
883 with the original declaration and discard the second declaration.
885 Furthermore, we can't mark these nodes in cgraph_finalize_function because:
888 void f() __attribute__((externally_visible));
892 So, we walk the nodes at the end of the translation unit, applying the
893 attributes at that point. */
896 process_function_and_variable_attributes (struct cgraph_node
*first
,
897 struct varpool_node
*first_var
)
899 struct cgraph_node
*node
;
900 struct varpool_node
*vnode
;
902 for (node
= cgraph_nodes
; node
!= first
; node
= node
->next
)
904 tree decl
= node
->decl
;
905 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
907 mark_decl_referenced (decl
);
908 if (node
->local
.finalized
)
909 cgraph_mark_needed_node (node
);
911 if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl
)))
913 if (! TREE_PUBLIC (node
->decl
))
914 warning (OPT_Wattributes
,
915 "%J%<externally_visible%> attribute have effect only on public objects",
919 if (node
->local
.finalized
)
920 cgraph_mark_needed_node (node
);
921 node
->local
.externally_visible
= true;
925 for (vnode
= varpool_nodes
; vnode
!= first_var
; vnode
= vnode
->next
)
927 tree decl
= vnode
->decl
;
928 if (lookup_attribute ("used", DECL_ATTRIBUTES (decl
)))
930 mark_decl_referenced (decl
);
931 if (vnode
->finalized
)
932 varpool_mark_needed_node (vnode
);
934 if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl
)))
936 if (! TREE_PUBLIC (vnode
->decl
))
937 warning (OPT_Wattributes
,
938 "%J%<externally_visible%> attribute have effect only on public objects",
942 if (vnode
->finalized
)
943 varpool_mark_needed_node (vnode
);
944 vnode
->externally_visible
= true;
950 /* Process CGRAPH_NODES_NEEDED queue, analyze each function (and transitively
951 each reachable functions) and build cgraph.
952 The function can be called multiple times after inserting new nodes
953 into beginning of queue. Just the new part of queue is re-scanned then. */
956 cgraph_analyze_functions (void)
958 /* Keep track of already processed nodes when called multiple times for
959 intermodule optimization. */
960 static struct cgraph_node
*first_analyzed
;
961 struct cgraph_node
*first_processed
= first_analyzed
;
962 static struct varpool_node
*first_analyzed_var
;
963 struct cgraph_node
*node
, *next
;
965 process_function_and_variable_attributes (first_processed
,
967 first_processed
= cgraph_nodes
;
968 first_analyzed_var
= varpool_nodes
;
969 varpool_analyze_pending_decls ();
970 if (cgraph_dump_file
)
972 fprintf (cgraph_dump_file
, "Initial entry points:");
973 for (node
= cgraph_nodes
; node
!= first_analyzed
; node
= node
->next
)
974 if (node
->needed
&& DECL_SAVED_TREE (node
->decl
))
975 fprintf (cgraph_dump_file
, " %s", cgraph_node_name (node
));
976 fprintf (cgraph_dump_file
, "\n");
978 cgraph_process_new_functions ();
980 /* Propagate reachability flag and lower representation of all reachable
981 functions. In the future, lowering will introduce new functions and
982 new entry points on the way (by template instantiation and virtual
983 method table generation for instance). */
984 while (cgraph_nodes_queue
)
986 struct cgraph_edge
*edge
;
987 tree decl
= cgraph_nodes_queue
->decl
;
989 node
= cgraph_nodes_queue
;
990 cgraph_nodes_queue
= cgraph_nodes_queue
->next_needed
;
991 node
->next_needed
= NULL
;
993 /* ??? It is possible to create extern inline function and later using
994 weak alias attribute to kill its body. See
995 gcc.c-torture/compile/20011119-1.c */
996 if (!DECL_SAVED_TREE (decl
))
998 cgraph_reset_node (node
);
1002 gcc_assert (!node
->analyzed
&& node
->reachable
);
1003 gcc_assert (DECL_SAVED_TREE (decl
));
1005 cgraph_analyze_function (node
);
1007 for (edge
= node
->callees
; edge
; edge
= edge
->next_callee
)
1008 if (!edge
->callee
->reachable
)
1009 cgraph_mark_reachable_node (edge
->callee
);
1011 /* We finalize local static variables during constructing callgraph
1012 edges. Process their attributes too. */
1013 process_function_and_variable_attributes (first_processed
,
1014 first_analyzed_var
);
1015 first_processed
= cgraph_nodes
;
1016 first_analyzed_var
= varpool_nodes
;
1017 varpool_analyze_pending_decls ();
1018 cgraph_process_new_functions ();
1021 /* Collect entry points to the unit. */
1022 if (cgraph_dump_file
)
1024 fprintf (cgraph_dump_file
, "Unit entry points:");
1025 for (node
= cgraph_nodes
; node
!= first_analyzed
; node
= node
->next
)
1026 if (node
->needed
&& DECL_SAVED_TREE (node
->decl
))
1027 fprintf (cgraph_dump_file
, " %s", cgraph_node_name (node
));
1028 fprintf (cgraph_dump_file
, "\n\nInitial ");
1029 dump_cgraph (cgraph_dump_file
);
1032 if (cgraph_dump_file
)
1033 fprintf (cgraph_dump_file
, "\nReclaiming functions:");
1035 for (node
= cgraph_nodes
; node
!= first_analyzed
; node
= next
)
1037 tree decl
= node
->decl
;
1040 if (node
->local
.finalized
&& !DECL_SAVED_TREE (decl
))
1041 cgraph_reset_node (node
);
1043 if (!node
->reachable
&& DECL_SAVED_TREE (decl
))
1045 if (cgraph_dump_file
)
1046 fprintf (cgraph_dump_file
, " %s", cgraph_node_name (node
));
1047 cgraph_remove_node (node
);
1051 node
->next_needed
= NULL
;
1052 gcc_assert (!node
->local
.finalized
|| DECL_SAVED_TREE (decl
));
1053 gcc_assert (node
->analyzed
== node
->local
.finalized
);
1055 if (cgraph_dump_file
)
1057 fprintf (cgraph_dump_file
, "\n\nReclaimed ");
1058 dump_cgraph (cgraph_dump_file
);
1060 first_analyzed
= cgraph_nodes
;
1064 /* Analyze the whole compilation unit once it is parsed completely. */
1067 cgraph_finalize_compilation_unit (void)
1069 if (errorcount
|| sorrycount
)
1072 finish_aliases_1 ();
1074 if (!flag_unit_at_a_time
)
1076 cgraph_output_pending_asms ();
1077 cgraph_assemble_pending_functions ();
1078 varpool_output_debug_info ();
1084 fprintf (stderr
, "\nAnalyzing compilation unit\n");
1088 timevar_push (TV_CGRAPH
);
1089 cgraph_analyze_functions ();
1090 timevar_pop (TV_CGRAPH
);
1092 /* Figure out what functions we want to assemble. */
1095 cgraph_mark_functions_to_output (void)
1097 struct cgraph_node
*node
;
1099 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1101 tree decl
= node
->decl
;
1102 struct cgraph_edge
*e
;
1104 gcc_assert (!node
->output
);
1106 for (e
= node
->callers
; e
; e
= e
->next_caller
)
1107 if (e
->inline_failed
)
1110 /* We need to output all local functions that are used and not
1111 always inlined, as well as those that are reachable from
1112 outside the current compilation unit. */
1113 if (DECL_SAVED_TREE (decl
)
1114 && !node
->global
.inlined_to
1116 || (e
&& node
->reachable
))
1117 && !TREE_ASM_WRITTEN (decl
)
1118 && !DECL_EXTERNAL (decl
))
1122 /* We should've reclaimed all functions that are not needed. */
1123 #ifdef ENABLE_CHECKING
1124 if (!node
->global
.inlined_to
&& DECL_SAVED_TREE (decl
)
1125 && !DECL_EXTERNAL (decl
))
1127 dump_cgraph_node (stderr
, node
);
1128 internal_error ("failed to reclaim unneeded function");
1131 gcc_assert (node
->global
.inlined_to
|| !DECL_SAVED_TREE (decl
)
1132 || DECL_EXTERNAL (decl
));
1139 /* Expand function specified by NODE. */
1142 cgraph_expand_function (struct cgraph_node
*node
)
1144 tree decl
= node
->decl
;
1146 /* We ought to not compile any inline clones. */
1147 gcc_assert (!node
->global
.inlined_to
);
1149 if (flag_unit_at_a_time
)
1150 announce_function (decl
);
1152 gcc_assert (node
->lowered
);
1154 /* Generate RTL for the body of DECL. */
1155 if (lang_hooks
.callgraph
.emit_associated_thunks
)
1156 lang_hooks
.callgraph
.emit_associated_thunks (decl
);
1157 tree_rest_of_compilation (decl
);
1159 /* Make sure that BE didn't give up on compiling. */
1160 /* ??? Can happen with nested function of extern inline. */
1161 gcc_assert (TREE_ASM_WRITTEN (node
->decl
));
1163 current_function_decl
= NULL
;
1164 if (!cgraph_preserve_function_body_p (node
->decl
))
1166 cgraph_release_function_body (node
);
1167 /* Eliminate all call edges. This is important so the call_expr no longer
1168 points to the dead function body. */
1169 cgraph_node_remove_callees (node
);
1172 cgraph_function_flags_ready
= true;
1175 /* Return true when CALLER_DECL should be inlined into CALLEE_DECL. */
1178 cgraph_inline_p (struct cgraph_edge
*e
, const char **reason
)
1180 *reason
= e
->inline_failed
;
1181 return !e
->inline_failed
;
1186 /* Expand all functions that must be output.
1188 Attempt to topologically sort the nodes so function is output when
1189 all called functions are already assembled to allow data to be
1190 propagated across the callgraph. Use a stack to get smaller distance
1191 between a function and its callees (later we may choose to use a more
1192 sophisticated algorithm for function reordering; we will likely want
1193 to use subsections to make the output functions appear in top-down
1197 cgraph_expand_all_functions (void)
1199 struct cgraph_node
*node
;
1200 struct cgraph_node
**order
= XCNEWVEC (struct cgraph_node
*, cgraph_n_nodes
);
1201 int order_pos
= 0, new_order_pos
= 0;
1204 order_pos
= cgraph_postorder (order
);
1205 gcc_assert (order_pos
== cgraph_n_nodes
);
1207 /* Garbage collector may remove inline clones we eliminate during
1208 optimization. So we must be sure to not reference them. */
1209 for (i
= 0; i
< order_pos
; i
++)
1210 if (order
[i
]->output
)
1211 order
[new_order_pos
++] = order
[i
];
1213 for (i
= new_order_pos
- 1; i
>= 0; i
--)
1218 gcc_assert (node
->reachable
);
1220 cgraph_expand_function (node
);
1223 cgraph_process_new_functions ();
1229 /* This is used to sort the node types by the cgraph order number. */
1231 struct cgraph_order_sort
1233 enum { ORDER_UNDEFINED
= 0, ORDER_FUNCTION
, ORDER_VAR
, ORDER_ASM
} kind
;
1236 struct cgraph_node
*f
;
1237 struct varpool_node
*v
;
1238 struct cgraph_asm_node
*a
;
1242 /* Output all functions, variables, and asm statements in the order
1243 according to their order fields, which is the order in which they
1244 appeared in the file. This implements -fno-toplevel-reorder. In
1245 this mode we may output functions and variables which don't really
1246 need to be output. */
1249 cgraph_output_in_order (void)
1253 struct cgraph_order_sort
*nodes
;
1255 struct cgraph_node
*pf
;
1256 struct varpool_node
*pv
;
1257 struct cgraph_asm_node
*pa
;
1260 size
= max
* sizeof (struct cgraph_order_sort
);
1261 nodes
= (struct cgraph_order_sort
*) alloca (size
);
1262 memset (nodes
, 0, size
);
1264 varpool_analyze_pending_decls ();
1266 for (pf
= cgraph_nodes
; pf
; pf
= pf
->next
)
1271 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
1272 nodes
[i
].kind
= ORDER_FUNCTION
;
1277 for (pv
= varpool_nodes_queue
; pv
; pv
= pv
->next_needed
)
1280 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
1281 nodes
[i
].kind
= ORDER_VAR
;
1285 for (pa
= cgraph_asm_nodes
; pa
; pa
= pa
->next
)
1288 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
1289 nodes
[i
].kind
= ORDER_ASM
;
1293 for (i
= 0; i
< max
; ++i
)
1295 switch (nodes
[i
].kind
)
1297 case ORDER_FUNCTION
:
1298 nodes
[i
].u
.f
->output
= 0;
1299 cgraph_expand_function (nodes
[i
].u
.f
);
1303 varpool_assemble_decl (nodes
[i
].u
.v
);
1307 assemble_asm (nodes
[i
].u
.a
->asm_str
);
1310 case ORDER_UNDEFINED
:
1318 cgraph_asm_nodes
= NULL
;
1321 /* Return true when function body of DECL still needs to be kept around
1322 for later re-use. */
1324 cgraph_preserve_function_body_p (tree decl
)
1326 struct cgraph_node
*node
;
1327 if (!cgraph_global_info_ready
)
1328 return (flag_really_no_inline
1329 ? DECL_DISREGARD_INLINE_LIMITS (decl
)
1330 : DECL_INLINE (decl
));
1331 /* Look if there is any clone around. */
1332 for (node
= cgraph_node (decl
); node
; node
= node
->next_clone
)
1333 if (node
->global
.inlined_to
)
1342 current_function_decl
= NULL
;
1343 tree_register_cfg_hooks ();
1344 bitmap_obstack_initialize (NULL
);
1345 execute_ipa_pass_list (all_ipa_passes
);
1346 bitmap_obstack_release (NULL
);
1349 /* Perform simple optimizations based on callgraph. */
1352 cgraph_optimize (void)
1354 if (errorcount
|| sorrycount
)
1357 #ifdef ENABLE_CHECKING
1361 /* Call functions declared with the "constructor" or "destructor"
1363 cgraph_build_cdtor_fns ();
1364 if (!flag_unit_at_a_time
)
1366 cgraph_assemble_pending_functions ();
1367 cgraph_process_new_functions ();
1368 cgraph_state
= CGRAPH_STATE_FINISHED
;
1369 cgraph_output_pending_asms ();
1370 varpool_assemble_pending_decls ();
1371 varpool_output_debug_info ();
1375 /* Frontend may output common variables after the unit has been finalized.
1376 It is safe to deal with them here as they are always zero initialized. */
1377 varpool_analyze_pending_decls ();
1378 cgraph_analyze_functions ();
1380 timevar_push (TV_CGRAPHOPT
);
1381 if (pre_ipa_mem_report
)
1383 fprintf (stderr
, "Memory consumption before IPA\n");
1384 dump_memory_report (false);
1387 fprintf (stderr
, "Performing interprocedural optimizations\n");
1388 cgraph_state
= CGRAPH_STATE_IPA
;
1390 /* Don't run the IPA passes if there was any error or sorry messages. */
1391 if (errorcount
== 0 && sorrycount
== 0)
1394 /* This pass remove bodies of extern inline functions we never inlined.
1395 Do this later so other IPA passes see what is really going on. */
1396 cgraph_remove_unreachable_nodes (false, dump_file
);
1397 cgraph_global_info_ready
= true;
1398 if (cgraph_dump_file
)
1400 fprintf (cgraph_dump_file
, "Optimized ");
1401 dump_cgraph (cgraph_dump_file
);
1402 dump_varpool (cgraph_dump_file
);
1404 if (post_ipa_mem_report
)
1406 fprintf (stderr
, "Memory consumption after IPA\n");
1407 dump_memory_report (false);
1409 timevar_pop (TV_CGRAPHOPT
);
1411 /* Output everything. */
1413 fprintf (stderr
, "Assembling functions:\n");
1414 #ifdef ENABLE_CHECKING
1418 cgraph_mark_functions_to_output ();
1420 cgraph_state
= CGRAPH_STATE_EXPANSION
;
1421 if (!flag_toplevel_reorder
)
1422 cgraph_output_in_order ();
1425 cgraph_output_pending_asms ();
1427 cgraph_expand_all_functions ();
1428 varpool_remove_unreferenced_decls ();
1430 varpool_assemble_pending_decls ();
1431 varpool_output_debug_info ();
1433 cgraph_process_new_functions ();
1434 cgraph_state
= CGRAPH_STATE_FINISHED
;
1436 if (cgraph_dump_file
)
1438 fprintf (cgraph_dump_file
, "\nFinal ");
1439 dump_cgraph (cgraph_dump_file
);
1441 #ifdef ENABLE_CHECKING
1443 /* Double check that all inline clones are gone and that all
1444 function bodies have been released from memory. */
1445 if (flag_unit_at_a_time
1446 && !(sorrycount
|| errorcount
))
1448 struct cgraph_node
*node
;
1449 bool error_found
= false;
1451 for (node
= cgraph_nodes
; node
; node
= node
->next
)
1453 && (node
->global
.inlined_to
1454 || DECL_SAVED_TREE (node
->decl
)))
1457 dump_cgraph_node (stderr
, node
);
1460 internal_error ("nodes with no released memory found");
1464 /* Generate and emit a static constructor or destructor. WHICH must
1465 be one of 'I' (for a constructor) or 'D' (for a destructor). BODY
1466 is a STATEMENT_LIST containing GENERIC statements. PRIORITY is the
1467 initialization priority fot this constructor or destructor. */
1470 cgraph_build_static_cdtor (char which
, tree body
, int priority
)
1472 static int counter
= 0;
1474 tree decl
, name
, resdecl
;
1476 /* The priority is encoded in the constructor or destructor name.
1477 collect2 will sort the names and arrange that they are called at
1479 sprintf (which_buf
, "%c_%.5d_%d", which
, priority
, counter
++);
1480 name
= get_file_function_name (which_buf
);
1482 decl
= build_decl (FUNCTION_DECL
, name
,
1483 build_function_type (void_type_node
, void_list_node
));
1484 current_function_decl
= decl
;
1486 resdecl
= build_decl (RESULT_DECL
, NULL_TREE
, void_type_node
);
1487 DECL_ARTIFICIAL (resdecl
) = 1;
1488 DECL_RESULT (decl
) = resdecl
;
1490 allocate_struct_function (decl
, false);
1492 TREE_STATIC (decl
) = 1;
1493 TREE_USED (decl
) = 1;
1494 DECL_ARTIFICIAL (decl
) = 1;
1495 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
1496 DECL_SAVED_TREE (decl
) = body
;
1497 TREE_PUBLIC (decl
) = ! targetm
.have_ctors_dtors
;
1498 DECL_UNINLINABLE (decl
) = 1;
1500 DECL_INITIAL (decl
) = make_node (BLOCK
);
1501 TREE_USED (DECL_INITIAL (decl
)) = 1;
1503 DECL_SOURCE_LOCATION (decl
) = input_location
;
1504 cfun
->function_end_locus
= input_location
;
1509 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
1510 decl_init_priority_insert (decl
, priority
);
1513 DECL_STATIC_DESTRUCTOR (decl
) = 1;
1514 decl_fini_priority_insert (decl
, priority
);
1520 gimplify_function_tree (decl
);
1522 cgraph_add_new_function (decl
, false);
1523 cgraph_mark_needed_node (cgraph_node (decl
));
1530 cgraph_dump_file
= dump_begin (TDI_cgraph
, NULL
);
1533 /* The edges representing the callers of the NEW_VERSION node were
1534 fixed by cgraph_function_versioning (), now the call_expr in their
1535 respective tree code should be updated to call the NEW_VERSION. */
1538 update_call_expr (struct cgraph_node
*new_version
)
1540 struct cgraph_edge
*e
;
1542 gcc_assert (new_version
);
1543 for (e
= new_version
->callers
; e
; e
= e
->next_caller
)
1544 /* Update the call expr on the edges
1545 to call the new version. */
1546 TREE_OPERAND (CALL_EXPR_FN (get_call_expr_in (e
->call_stmt
)), 0) = new_version
->decl
;
1550 /* Create a new cgraph node which is the new version of
1551 OLD_VERSION node. REDIRECT_CALLERS holds the callers
1552 edges which should be redirected to point to
1553 NEW_VERSION. ALL the callees edges of OLD_VERSION
1554 are cloned to the new version node. Return the new
1557 static struct cgraph_node
*
1558 cgraph_copy_node_for_versioning (struct cgraph_node
*old_version
,
1560 VEC(cgraph_edge_p
,heap
) *redirect_callers
)
1562 struct cgraph_node
*new_version
;
1563 struct cgraph_edge
*e
, *new_e
;
1564 struct cgraph_edge
*next_callee
;
1567 gcc_assert (old_version
);
1569 new_version
= cgraph_node (new_decl
);
1571 new_version
->analyzed
= true;
1572 new_version
->local
= old_version
->local
;
1573 new_version
->global
= old_version
->global
;
1574 new_version
->rtl
= new_version
->rtl
;
1575 new_version
->reachable
= true;
1576 new_version
->count
= old_version
->count
;
1578 /* Clone the old node callees. Recursive calls are
1580 for (e
= old_version
->callees
;e
; e
=e
->next_callee
)
1582 new_e
= cgraph_clone_edge (e
, new_version
, e
->call_stmt
, 0, e
->frequency
,
1583 e
->loop_nest
, true);
1584 new_e
->count
= e
->count
;
1586 /* Fix recursive calls.
1587 If OLD_VERSION has a recursive call after the
1588 previous edge cloning, the new version will have an edge
1589 pointing to the old version, which is wrong;
1590 Redirect it to point to the new version. */
1591 for (e
= new_version
->callees
; e
; e
= next_callee
)
1593 next_callee
= e
->next_callee
;
1594 if (e
->callee
== old_version
)
1595 cgraph_redirect_edge_callee (e
, new_version
);
1600 for (i
= 0; VEC_iterate (cgraph_edge_p
, redirect_callers
, i
, e
); i
++)
1602 /* Redirect calls to the old version node to point to its new
1604 cgraph_redirect_edge_callee (e
, new_version
);
1610 /* Perform function versioning.
1611 Function versioning includes copying of the tree and
1612 a callgraph update (creating a new cgraph node and updating
1613 its callees and callers).
1615 REDIRECT_CALLERS varray includes the edges to be redirected
1618 TREE_MAP is a mapping of tree nodes we want to replace with
1619 new ones (according to results of prior analysis).
1620 OLD_VERSION_NODE is the node that is versioned.
1621 It returns the new version's cgraph node. */
1623 struct cgraph_node
*
1624 cgraph_function_versioning (struct cgraph_node
*old_version_node
,
1625 VEC(cgraph_edge_p
,heap
) *redirect_callers
,
1626 varray_type tree_map
)
1628 tree old_decl
= old_version_node
->decl
;
1629 struct cgraph_node
*new_version_node
= NULL
;
1632 if (!tree_versionable_function_p (old_decl
))
1635 /* Make a new FUNCTION_DECL tree node for the
1637 new_decl
= copy_node (old_decl
);
1639 /* Create the new version's call-graph node.
1640 and update the edges of the new node. */
1642 cgraph_copy_node_for_versioning (old_version_node
, new_decl
,
1645 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1646 tree_function_versioning (old_decl
, new_decl
, tree_map
, false);
1647 /* Update the call_expr on the edges to call the new version node. */
1648 update_call_expr (new_version_node
);
1650 /* Update the new version's properties.
1651 Make The new version visible only within this translation unit.
1652 ??? We cannot use COMDAT linkage because there is no
1653 ABI support for this. */
1654 DECL_EXTERNAL (new_version_node
->decl
) = 0;
1655 DECL_ONE_ONLY (new_version_node
->decl
) = 0;
1656 TREE_PUBLIC (new_version_node
->decl
) = 0;
1657 DECL_COMDAT (new_version_node
->decl
) = 0;
1658 new_version_node
->local
.externally_visible
= 0;
1659 new_version_node
->local
.local
= 1;
1660 new_version_node
->lowered
= true;
1661 return new_version_node
;
1664 /* Produce separate function body for inline clones so the offline copy can be
1665 modified without affecting them. */
1666 struct cgraph_node
*
1667 save_inline_function_body (struct cgraph_node
*node
)
1669 struct cgraph_node
*first_clone
;
1671 gcc_assert (node
== cgraph_node (node
->decl
));
1673 cgraph_lower_function (node
);
1675 /* In non-unit-at-a-time we construct full fledged clone we never output to
1676 assembly file. This clone is pointed out by inline_decl of original function
1677 and inlining infrastructure knows how to deal with this. */
1678 if (!flag_unit_at_a_time
)
1680 struct cgraph_edge
*e
;
1682 first_clone
= cgraph_clone_node (node
, node
->count
, 0, CGRAPH_FREQ_BASE
,
1684 first_clone
->needed
= 0;
1685 first_clone
->reachable
= 1;
1686 /* Recursively clone all bodies. */
1687 for (e
= first_clone
->callees
; e
; e
= e
->next_callee
)
1688 if (!e
->inline_failed
)
1689 cgraph_clone_inlined_nodes (e
, true, false);
1692 first_clone
= node
->next_clone
;
1694 first_clone
->decl
= copy_node (node
->decl
);
1695 node
->next_clone
= NULL
;
1696 if (!flag_unit_at_a_time
)
1697 node
->inline_decl
= first_clone
->decl
;
1698 first_clone
->prev_clone
= NULL
;
1699 cgraph_insert_node_to_hashtable (first_clone
);
1700 gcc_assert (first_clone
== cgraph_node (first_clone
->decl
));
1702 /* Copy the OLD_VERSION_NODE function tree to the new version. */
1703 tree_function_versioning (node
->decl
, first_clone
->decl
, NULL
, true);
1705 DECL_EXTERNAL (first_clone
->decl
) = 0;
1706 DECL_ONE_ONLY (first_clone
->decl
) = 0;
1707 TREE_PUBLIC (first_clone
->decl
) = 0;
1708 DECL_COMDAT (first_clone
->decl
) = 0;
1710 for (node
= first_clone
->next_clone
; node
; node
= node
->next_clone
)
1711 node
->decl
= first_clone
->decl
;
1712 #ifdef ENABLE_CHECKING
1713 verify_cgraph_node (first_clone
);
1718 #include "gt-cgraphunit.h"