1 /* Driver of optimization process
2 Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This module implements main driver of compilation process.
23 The main scope of this file is to act as an interface in between
24 tree based frontends and the backend.
26 The front-end is supposed to use following functionality:
30 This function is called once front-end has parsed whole body of function
31 and it is certain that the function body nor the declaration will change.
33 (There is one exception needed for implementing GCC extern inline
36 - varpool_finalize_decl
38 This function has same behavior as the above but is used for static
43 Insert new toplevel ASM statement
45 - finalize_compilation_unit
47 This function is called once (source level) compilation unit is finalized
48 and it will no longer change.
50 The symbol table is constructed starting from the trivially needed
51 symbols finalized by the frontend. Functions are lowered into
52 GIMPLE representation and callgraph/reference lists are constructed.
53 Those are used to discover other necessary functions and variables.
55 At the end the bodies of unreachable functions are removed.
57 The function can be called multiple times when multiple source level
58 compilation units are combined.
62 This passes control to the back-end. Optimizations are performed and
63 final assembler is generated. This is done in the following way. Note
64 that with link time optimization the process is split into three
65 stages (compile time, linktime analysis and parallel linktime as
70 1) Inter-procedural optimization.
73 This part is further split into:
75 a) early optimizations. These are local passes executed in
76 the topological order on the callgraph.
78 The purpose of early optimiations is to optimize away simple
79 things that may otherwise confuse IP analysis. Very simple
80 propagation across the callgraph is done i.e. to discover
81 functions without side effects and simple inlining is performed.
83 b) early small interprocedural passes.
85 Those are interprocedural passes executed only at compilation
86 time. These include, for example, transational memory lowering,
87 unreachable code removal and other simple transformations.
89 c) IP analysis stage. All interprocedural passes do their
92 Interprocedural passes differ from small interprocedural
93 passes by their ability to operate across whole program
94 at linktime. Their analysis stage is performed early to
95 both reduce linking times and linktime memory usage by
96 not having to represent whole program in memory.
98 d) LTO sreaming. When doing LTO, everything important gets
99 streamed into the object file.
101 Compile time and or linktime analysis stage (WPA):
103 At linktime units gets streamed back and symbol table is
104 merged. Function bodies are not streamed in and not
106 e) IP propagation stage. All IP passes execute their
107 IP propagation. This is done based on the earlier analysis
108 without having function bodies at hand.
109 f) Ltrans streaming. When doing WHOPR LTO, the program
110 is partitioned and streamed into multple object files.
112 Compile time and/or parallel linktime stage (ltrans)
114 Each of the object files is streamed back and compiled
115 separately. Now the function bodies becomes available
118 2) Virtual clone materialization
119 (cgraph_materialize_clone)
121 IP passes can produce copies of existing functoins (such
122 as versioned clones or inline clones) without actually
123 manipulating their bodies by creating virtual clones in
124 the callgraph. At this time the virtual clones are
125 turned into real functions
128 All IP passes transform function bodies based on earlier
129 decision of the IP propagation.
131 4) late small IP passes
133 Simple IP passes working within single program partition.
136 (expand_all_functions)
138 At this stage functions that needs to be output into
139 assembler are identified and compiled in topological order
140 6) Output of variables and aliases
141 Now it is known what variable references was not optimized
142 out and thus all variables are output to the file.
144 Note that with -fno-toplevel-reorder passes 5 and 6
145 are combined together in cgraph_output_in_order.
147 Finally there are functions to manipulate the callgraph from
149 - cgraph_add_new_function is used to add backend produced
150 functions introduced after the unit is finalized.
151 The functions are enqueue for later processing and inserted
152 into callgraph with cgraph_process_new_functions.
154 - cgraph_function_versioning
156 produces a copy of function into new one (a version)
157 and apply simple transformations
162 #include "coretypes.h"
166 #include "stor-layout.h"
167 #include "stringpool.h"
173 #include "hash-set.h"
174 #include "machmode.h"
175 #include "hard-reg-set.h"
177 #include "function.h"
178 #include "basic-block.h"
179 #include "tree-ssa-alias.h"
180 #include "internal-fn.h"
181 #include "gimple-fold.h"
182 #include "gimple-expr.h"
185 #include "gimplify.h"
186 #include "gimple-iterator.h"
187 #include "gimplify-me.h"
188 #include "gimple-ssa.h"
189 #include "tree-cfg.h"
190 #include "tree-into-ssa.h"
191 #include "tree-ssa.h"
192 #include "tree-inline.h"
193 #include "langhooks.h"
198 #include "diagnostic.h"
201 #include "hash-map.h"
202 #include "plugin-api.h"
205 #include "alloc-pool.h"
206 #include "ipa-prop.h"
207 #include "tree-iterator.h"
208 #include "tree-pass.h"
209 #include "tree-dump.h"
210 #include "gimple-pretty-print.h"
212 #include "coverage.h"
214 #include "ipa-inline.h"
215 #include "ipa-utils.h"
216 #include "lto-streamer.h"
219 #include "regset.h" /* FIXME: For reg_obstack. */
221 #include "pass_manager.h"
222 #include "tree-nested.h"
223 #include "gimplify.h"
225 #include "tree-chkp.h"
226 #include "lto-section-names.h"
228 #include "print-tree.h"
230 /* Queue of cgraph nodes scheduled to be added into cgraph. This is a
231 secondary queue used during optimization to accommodate passes that
232 may generate new functions that need to be optimized and expanded. */
233 vec
<cgraph_node
*> cgraph_new_nodes
;
235 static void expand_all_functions (void);
236 static void mark_functions_to_output (void);
237 static void handle_alias_pairs (void);
239 /* Used for vtable lookup in thunk adjusting. */
240 static GTY (()) tree vtable_entry_type
;
242 /* Determine if symbol declaration is needed. That is, visible to something
243 either outside this translation unit, something magic in the system
246 symtab_node::needed_p (void)
248 /* Double check that no one output the function into assembly file
250 gcc_checking_assert (!DECL_ASSEMBLER_NAME_SET_P (decl
)
251 || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
)));
256 if (DECL_EXTERNAL (decl
))
259 /* If the user told us it is used, then it must be so. */
263 /* ABI forced symbols are needed when they are external. */
264 if (forced_by_abi
&& TREE_PUBLIC (decl
))
267 /* Keep constructors, destructors and virtual functions. */
268 if (TREE_CODE (decl
) == FUNCTION_DECL
269 && (DECL_STATIC_CONSTRUCTOR (decl
) || DECL_STATIC_DESTRUCTOR (decl
)))
272 /* Externally visible variables must be output. The exception is
273 COMDAT variables that must be output only when they are needed. */
274 if (TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
))
280 /* Head and terminator of the queue of nodes to be processed while building
283 static symtab_node symtab_terminator
;
284 static symtab_node
*queued_nodes
= &symtab_terminator
;
286 /* Add NODE to queue starting at QUEUED_NODES.
287 The queue is linked via AUX pointers and terminated by pointer to 1. */
290 enqueue_node (symtab_node
*node
)
294 gcc_checking_assert (queued_nodes
);
295 node
->aux
= queued_nodes
;
299 /* Process CGRAPH_NEW_FUNCTIONS and perform actions necessary to add these
300 functions into callgraph in a way so they look like ordinary reachable
301 functions inserted into callgraph already at construction time. */
304 symbol_table::process_new_functions (void)
308 if (!cgraph_new_nodes
.exists ())
311 handle_alias_pairs ();
312 /* Note that this queue may grow as its being processed, as the new
313 functions may generate new ones. */
314 for (unsigned i
= 0; i
< cgraph_new_nodes
.length (); i
++)
316 cgraph_node
*node
= cgraph_new_nodes
[i
];
321 /* At construction time we just need to finalize function and move
322 it into reachable functions list. */
324 cgraph_node::finalize_function (fndecl
, false);
325 call_cgraph_insertion_hooks (node
);
331 case IPA_SSA_AFTER_INLINING
:
332 /* When IPA optimization already started, do all essential
333 transformations that has been already performed on the whole
334 cgraph but not on this function. */
336 gimple_register_cfg_hooks ();
339 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
340 if ((state
== IPA_SSA
|| state
== IPA_SSA_AFTER_INLINING
)
341 && !gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl
)))
342 g
->get_passes ()->execute_early_local_passes ();
343 else if (inline_summary_vec
!= NULL
)
344 compute_inline_parameters (node
, true);
345 free_dominance_info (CDI_POST_DOMINATORS
);
346 free_dominance_info (CDI_DOMINATORS
);
348 call_cgraph_insertion_hooks (node
);
352 /* Functions created during expansion shall be compiled
355 call_cgraph_insertion_hooks (node
);
365 cgraph_new_nodes
.release ();
368 /* As an GCC extension we allow redefinition of the function. The
369 semantics when both copies of bodies differ is not well defined.
370 We replace the old body with new body so in unit at a time mode
371 we always use new body, while in normal mode we may end up with
372 old body inlined into some functions and new body expanded and
375 ??? It may make more sense to use one body for inlining and other
376 body for expanding the function but this is difficult to do. */
379 cgraph_node::reset (void)
381 /* If process is set, then we have already begun whole-unit analysis.
382 This is *not* testing for whether we've already emitted the function.
383 That case can be sort-of legitimately seen with real function redefinition
384 errors. I would argue that the front end should never present us with
385 such a case, but don't enforce that for now. */
386 gcc_assert (!process
);
388 /* Reset our data structures so we can analyze the function again. */
389 memset (&local
, 0, sizeof (local
));
390 memset (&global
, 0, sizeof (global
));
391 memset (&rtl
, 0, sizeof (rtl
));
396 cpp_implicit_alias
= false;
399 remove_all_references ();
402 /* Return true when there are references to the node. */
405 symtab_node::referred_to_p (void)
409 /* See if there are any references at all. */
410 if (iterate_referring (0, ref
))
412 /* For functions check also calls. */
413 cgraph_node
*cn
= dyn_cast
<cgraph_node
*> (this);
414 if (cn
&& cn
->callers
)
419 /* DECL has been parsed. Take it, queue it, compile it at the whim of the
420 logic in effect. If NO_COLLECT is true, then our caller cannot stand to have
421 the garbage collector run at the moment. We would need to either create
422 a new GC context, or just not compile right now. */
425 cgraph_node::finalize_function (tree decl
, bool no_collect
)
427 cgraph_node
*node
= cgraph_node::get_create (decl
);
429 if (node
->definition
)
431 /* Nested functions should only be defined once. */
432 gcc_assert (!DECL_CONTEXT (decl
)
433 || TREE_CODE (DECL_CONTEXT (decl
)) != FUNCTION_DECL
);
435 node
->local
.redefined_extern_inline
= true;
438 notice_global_symbol (decl
);
439 node
->definition
= true;
440 node
->lowered
= DECL_STRUCT_FUNCTION (decl
)->cfg
!= NULL
;
442 /* With -fkeep-inline-functions we are keeping all inline functions except
443 for extern inline ones. */
444 if (flag_keep_inline_functions
445 && DECL_DECLARED_INLINE_P (decl
)
446 && !DECL_EXTERNAL (decl
)
447 && !DECL_DISREGARD_INLINE_LIMITS (decl
))
448 node
->force_output
= 1;
450 /* When not optimizing, also output the static functions. (see
451 PR24561), but don't do so for always_inline functions, functions
452 declared inline and nested functions. These were optimized out
453 in the original implementation and it is unclear whether we want
454 to change the behavior here. */
455 if ((!opt_for_fn (decl
, optimize
)
456 && !node
->cpp_implicit_alias
457 && !DECL_DISREGARD_INLINE_LIMITS (decl
)
458 && !DECL_DECLARED_INLINE_P (decl
)
459 && !(DECL_CONTEXT (decl
)
460 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
))
461 && !DECL_COMDAT (decl
) && !DECL_EXTERNAL (decl
))
462 node
->force_output
= 1;
464 /* If we've not yet emitted decl, tell the debug info about it. */
465 if (!TREE_ASM_WRITTEN (decl
))
466 (*debug_hooks
->deferred_inline_function
) (decl
);
468 /* Possibly warn about unused parameters. */
469 if (warn_unused_parameter
)
470 do_warn_unused_parameter (decl
);
475 if (symtab
->state
== CONSTRUCTION
476 && (node
->needed_p () || node
->referred_to_p ()))
480 /* Add the function FNDECL to the call graph.
481 Unlike finalize_function, this function is intended to be used
482 by middle end and allows insertion of new function at arbitrary point
483 of compilation. The function can be either in high, low or SSA form
486 The function is assumed to be reachable and have address taken (so no
487 API breaking optimizations are performed on it).
489 Main work done by this function is to enqueue the function for later
490 processing to avoid need the passes to be re-entrant. */
493 cgraph_node::add_new_function (tree fndecl
, bool lowered
)
495 gcc::pass_manager
*passes
= g
->get_passes ();
497 switch (symtab
->state
)
500 cgraph_node::finalize_function (fndecl
, false);
503 /* Just enqueue function to be processed at nearest occurrence. */
504 node
= cgraph_node::get_create (fndecl
);
506 node
->lowered
= true;
507 cgraph_new_nodes
.safe_push (node
);
512 case IPA_SSA_AFTER_INLINING
:
514 /* Bring the function into finalized state and enqueue for later
515 analyzing and compilation. */
516 node
= cgraph_node::get_create (fndecl
);
517 node
->local
.local
= false;
518 node
->definition
= true;
519 node
->force_output
= true;
520 if (!lowered
&& symtab
->state
== EXPANSION
)
522 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
523 gimple_register_cfg_hooks ();
524 bitmap_obstack_initialize (NULL
);
525 execute_pass_list (cfun
, passes
->all_lowering_passes
);
526 passes
->execute_early_local_passes ();
527 bitmap_obstack_release (NULL
);
533 node
->lowered
= true;
534 cgraph_new_nodes
.safe_push (node
);
538 /* At the very end of compilation we have to do all the work up
540 node
= cgraph_node::create (fndecl
);
542 node
->lowered
= true;
543 node
->definition
= true;
545 push_cfun (DECL_STRUCT_FUNCTION (fndecl
));
546 gimple_register_cfg_hooks ();
547 bitmap_obstack_initialize (NULL
);
548 if (!gimple_in_ssa_p (DECL_STRUCT_FUNCTION (fndecl
)))
549 g
->get_passes ()->execute_early_local_passes ();
550 bitmap_obstack_release (NULL
);
559 /* Set a personality if required and we already passed EH lowering. */
561 && (function_needs_eh_personality (DECL_STRUCT_FUNCTION (fndecl
))
562 == eh_personality_lang
))
563 DECL_FUNCTION_PERSONALITY (fndecl
) = lang_hooks
.eh_personality ();
566 /* Analyze the function scheduled to be output. */
568 cgraph_node::analyze (void)
570 tree decl
= this->decl
;
571 location_t saved_loc
= input_location
;
572 input_location
= DECL_SOURCE_LOCATION (decl
);
576 create_edge (cgraph_node::get (thunk
.alias
),
577 NULL
, 0, CGRAPH_FREQ_BASE
);
578 if (!expand_thunk (false, false))
586 resolve_alias (cgraph_node::get (alias_target
));
587 else if (dispatcher_function
)
589 /* Generate the dispatcher body of multi-versioned functions. */
590 cgraph_function_version_info
*dispatcher_version_info
591 = function_version ();
592 if (dispatcher_version_info
!= NULL
593 && (dispatcher_version_info
->dispatcher_resolver
596 tree resolver
= NULL_TREE
;
597 gcc_assert (targetm
.generate_version_dispatcher_body
);
598 resolver
= targetm
.generate_version_dispatcher_body (this);
599 gcc_assert (resolver
!= NULL_TREE
);
604 push_cfun (DECL_STRUCT_FUNCTION (decl
));
606 assign_assembler_name_if_neeeded (decl
);
608 /* Make sure to gimplify bodies only once. During analyzing a
609 function we lower it, which will require gimplified nested
610 functions, so we can end up here with an already gimplified
612 if (!gimple_has_body_p (decl
))
613 gimplify_function_tree (decl
);
614 dump_function (TDI_generic
, decl
);
616 /* Lower the function. */
620 lower_nested_functions (decl
);
621 gcc_assert (!nested
);
623 gimple_register_cfg_hooks ();
624 bitmap_obstack_initialize (NULL
);
625 execute_pass_list (cfun
, g
->get_passes ()->all_lowering_passes
);
626 free_dominance_info (CDI_POST_DOMINATORS
);
627 free_dominance_info (CDI_DOMINATORS
);
629 bitmap_obstack_release (NULL
);
637 input_location
= saved_loc
;
640 /* C++ frontend produce same body aliases all over the place, even before PCH
641 gets streamed out. It relies on us linking the aliases with their function
642 in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
643 first produce aliases without links, but once C++ FE is sure he won't sream
644 PCH we build the links via this function. */
647 symbol_table::process_same_body_aliases (void)
650 FOR_EACH_SYMBOL (node
)
651 if (node
->cpp_implicit_alias
&& !node
->analyzed
)
653 (TREE_CODE (node
->alias_target
) == VAR_DECL
654 ? (symtab_node
*)varpool_node::get_create (node
->alias_target
)
655 : (symtab_node
*)cgraph_node::get_create (node
->alias_target
));
656 cpp_implicit_aliases_done
= true;
659 /* Process attributes common for vars and functions. */
662 process_common_attributes (symtab_node
*node
, tree decl
)
664 tree weakref
= lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
));
666 if (weakref
&& !lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
668 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wattributes
,
669 "%<weakref%> attribute should be accompanied with"
670 " an %<alias%> attribute");
671 DECL_WEAK (decl
) = 0;
672 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
673 DECL_ATTRIBUTES (decl
));
676 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl
)))
677 node
->no_reorder
= 1;
680 /* Look for externally_visible and used attributes and mark cgraph nodes
683 We cannot mark the nodes at the point the attributes are processed (in
684 handle_*_attribute) because the copy of the declarations available at that
685 point may not be canonical. For example, in:
688 void f() __attribute__((used));
690 the declaration we see in handle_used_attribute will be the second
691 declaration -- but the front end will subsequently merge that declaration
692 with the original declaration and discard the second declaration.
694 Furthermore, we can't mark these nodes in finalize_function because:
697 void f() __attribute__((externally_visible));
701 So, we walk the nodes at the end of the translation unit, applying the
702 attributes at that point. */
705 process_function_and_variable_attributes (cgraph_node
*first
,
706 varpool_node
*first_var
)
711 for (node
= symtab
->first_function (); node
!= first
;
712 node
= symtab
->next_function (node
))
714 tree decl
= node
->decl
;
715 if (DECL_PRESERVE_P (decl
))
716 node
->mark_force_output ();
717 else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl
)))
719 if (! TREE_PUBLIC (node
->decl
))
720 warning_at (DECL_SOURCE_LOCATION (node
->decl
), OPT_Wattributes
,
721 "%<externally_visible%>"
722 " attribute have effect only on public objects");
724 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))
725 && (node
->definition
&& !node
->alias
))
727 warning_at (DECL_SOURCE_LOCATION (node
->decl
), OPT_Wattributes
,
728 "%<weakref%> attribute ignored"
729 " because function is defined");
730 DECL_WEAK (decl
) = 0;
731 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
732 DECL_ATTRIBUTES (decl
));
735 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl
))
736 && !DECL_DECLARED_INLINE_P (decl
)
737 /* redefining extern inline function makes it DECL_UNINLINABLE. */
738 && !DECL_UNINLINABLE (decl
))
739 warning_at (DECL_SOURCE_LOCATION (decl
), OPT_Wattributes
,
740 "always_inline function might not be inlinable");
742 process_common_attributes (node
, decl
);
744 for (vnode
= symtab
->first_variable (); vnode
!= first_var
;
745 vnode
= symtab
->next_variable (vnode
))
747 tree decl
= vnode
->decl
;
748 if (DECL_EXTERNAL (decl
)
749 && DECL_INITIAL (decl
))
750 varpool_node::finalize_decl (decl
);
751 if (DECL_PRESERVE_P (decl
))
752 vnode
->force_output
= true;
753 else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl
)))
755 if (! TREE_PUBLIC (vnode
->decl
))
756 warning_at (DECL_SOURCE_LOCATION (vnode
->decl
), OPT_Wattributes
,
757 "%<externally_visible%>"
758 " attribute have effect only on public objects");
760 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
))
762 && DECL_INITIAL (decl
))
764 warning_at (DECL_SOURCE_LOCATION (vnode
->decl
), OPT_Wattributes
,
765 "%<weakref%> attribute ignored"
766 " because variable is initialized");
767 DECL_WEAK (decl
) = 0;
768 DECL_ATTRIBUTES (decl
) = remove_attribute ("weakref",
769 DECL_ATTRIBUTES (decl
));
771 process_common_attributes (vnode
, decl
);
775 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct the
776 middle end to output the variable to asm file, if needed or externally
780 varpool_node::finalize_decl (tree decl
)
782 varpool_node
*node
= varpool_node::get_create (decl
);
784 gcc_assert (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
));
786 if (node
->definition
)
788 notice_global_symbol (decl
);
789 node
->definition
= true;
790 if (TREE_THIS_VOLATILE (decl
) || DECL_PRESERVE_P (decl
)
791 /* Traditionally we do not eliminate static variables when not
792 optimizing and when not doing toplevel reoder. */
794 || ((!flag_toplevel_reorder
795 && !DECL_COMDAT (node
->decl
)
796 && !DECL_ARTIFICIAL (node
->decl
))))
797 node
->force_output
= true;
799 if (symtab
->state
== CONSTRUCTION
800 && (node
->needed_p () || node
->referred_to_p ()))
802 if (symtab
->state
>= IPA_SSA
)
804 /* Some frontends produce various interface variables after compilation
806 if (symtab
->state
== FINISHED
807 || (!flag_toplevel_reorder
808 && symtab
->state
== EXPANSION
))
809 node
->assemble_decl ();
811 if (DECL_INITIAL (decl
))
812 chkp_register_var_initializer (decl
);
815 /* EDGE is an polymorphic call. Mark all possible targets as reachable
816 and if there is only one target, perform trivial devirtualization.
817 REACHABLE_CALL_TARGETS collects target lists we already walked to
818 avoid udplicate work. */
821 walk_polymorphic_call_targets (hash_set
<void *> *reachable_call_targets
,
827 vec
<cgraph_node
*>targets
828 = possible_polymorphic_call_targets
829 (edge
, &final
, &cache_token
);
831 if (!reachable_call_targets
->add (cache_token
))
833 if (symtab
->dump_file
)
834 dump_possible_polymorphic_call_targets
835 (symtab
->dump_file
, edge
);
837 for (i
= 0; i
< targets
.length (); i
++)
839 /* Do not bother to mark virtual methods in anonymous namespace;
840 either we will find use of virtual table defining it, or it is
842 if (targets
[i
]->definition
844 (TREE_TYPE (targets
[i
]->decl
))
846 && !type_in_anonymous_namespace_p
848 (TREE_TYPE (targets
[i
]->decl
))))
849 enqueue_node (targets
[i
]);
853 /* Very trivial devirtualization; when the type is
854 final or anonymous (so we know all its derivation)
855 and there is only one possible virtual call target,
856 make the edge direct. */
859 if (targets
.length () <= 1 && dbg_cnt (devirt
))
862 if (targets
.length () == 1)
865 target
= cgraph_node::create
866 (builtin_decl_implicit (BUILT_IN_UNREACHABLE
));
868 if (symtab
->dump_file
)
870 fprintf (symtab
->dump_file
,
871 "Devirtualizing call: ");
872 print_gimple_stmt (symtab
->dump_file
,
876 if (dump_enabled_p ())
878 location_t locus
= gimple_location_safe (edge
->call_stmt
);
879 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS
, locus
,
880 "devirtualizing call in %s to %s\n",
881 edge
->caller
->name (), target
->name ());
884 edge
->make_direct (target
);
885 edge
->redirect_call_stmt_to_callee ();
887 /* Call to __builtin_unreachable shouldn't be instrumented. */
888 if (!targets
.length ())
889 gimple_call_set_with_bounds (edge
->call_stmt
, false);
891 if (symtab
->dump_file
)
893 fprintf (symtab
->dump_file
,
894 "Devirtualized as: ");
895 print_gimple_stmt (symtab
->dump_file
,
904 /* Discover all functions and variables that are trivially needed, analyze
905 them as well as all functions and variables referred by them */
906 static cgraph_node
*first_analyzed
;
907 static varpool_node
*first_analyzed_var
;
910 analyze_functions (void)
912 /* Keep track of already processed nodes when called multiple times for
913 intermodule optimization. */
914 cgraph_node
*first_handled
= first_analyzed
;
915 varpool_node
*first_handled_var
= first_analyzed_var
;
916 hash_set
<void *> reachable_call_targets
;
923 location_t saved_loc
= input_location
;
925 bitmap_obstack_initialize (NULL
);
926 symtab
->state
= CONSTRUCTION
;
927 input_location
= UNKNOWN_LOCATION
;
929 /* Ugly, but the fixup can not happen at a time same body alias is created;
930 C++ FE is confused about the COMDAT groups being right. */
931 if (symtab
->cpp_implicit_aliases_done
)
932 FOR_EACH_SYMBOL (node
)
933 if (node
->cpp_implicit_alias
)
934 node
->fixup_same_cpp_alias_visibility (node
->get_alias_target ());
935 build_type_inheritance_graph ();
937 /* Analysis adds static variables that in turn adds references to new functions.
938 So we need to iterate the process until it stabilize. */
942 process_function_and_variable_attributes (first_analyzed
,
945 /* First identify the trivially needed symbols. */
946 for (node
= symtab
->first_symbol ();
947 node
!= first_analyzed
948 && node
!= first_analyzed_var
; node
= node
->next
)
950 /* Convert COMDAT group designators to IDENTIFIER_NODEs. */
951 node
->get_comdat_group_id ();
952 if (node
->needed_p ())
955 if (!changed
&& symtab
->dump_file
)
956 fprintf (symtab
->dump_file
, "Trivially needed symbols:");
958 if (symtab
->dump_file
)
959 fprintf (symtab
->dump_file
, " %s", node
->asm_name ());
960 if (!changed
&& symtab
->dump_file
)
961 fprintf (symtab
->dump_file
, "\n");
963 if (node
== first_analyzed
964 || node
== first_analyzed_var
)
967 symtab
->process_new_functions ();
968 first_analyzed_var
= symtab
->first_variable ();
969 first_analyzed
= symtab
->first_function ();
971 if (changed
&& symtab
->dump_file
)
972 fprintf (symtab
->dump_file
, "\n");
974 /* Lower representation, build callgraph edges and references for all trivially
975 needed symbols and all symbols referred by them. */
976 while (queued_nodes
!= &symtab_terminator
)
980 queued_nodes
= (symtab_node
*)queued_nodes
->aux
;
981 cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
);
982 if (cnode
&& cnode
->definition
)
985 tree decl
= cnode
->decl
;
987 /* ??? It is possible to create extern inline function
988 and later using weak alias attribute to kill its body.
989 See gcc.c-torture/compile/20011119-1.c */
990 if (!DECL_STRUCT_FUNCTION (decl
)
992 && !cnode
->thunk
.thunk_p
993 && !cnode
->dispatcher_function
)
996 cnode
->local
.redefined_extern_inline
= true;
1000 if (!cnode
->analyzed
)
1003 for (edge
= cnode
->callees
; edge
; edge
= edge
->next_callee
)
1004 if (edge
->callee
->definition
1005 && (!DECL_EXTERNAL (edge
->callee
->decl
)
1006 /* When not optimizing, do not try to analyze extern
1007 inline functions. Doing so is pointless. */
1008 || opt_for_fn (edge
->callee
->decl
, optimize
)
1009 /* Weakrefs needs to be preserved. */
1010 || edge
->callee
->alias
1011 /* always_inline functions are inlined aven at -O0. */
1014 DECL_ATTRIBUTES (edge
->callee
->decl
))
1015 /* Multiversioned functions needs the dispatcher to
1016 be produced locally even for extern functions. */
1017 || edge
->callee
->function_version ()))
1018 enqueue_node (edge
->callee
);
1019 if (opt_for_fn (cnode
->decl
, optimize
)
1020 && opt_for_fn (cnode
->decl
, flag_devirtualize
))
1024 for (edge
= cnode
->indirect_calls
; edge
; edge
= next
)
1026 next
= edge
->next_callee
;
1027 if (edge
->indirect_info
->polymorphic
)
1028 walk_polymorphic_call_targets (&reachable_call_targets
,
1033 /* If decl is a clone of an abstract function,
1034 mark that abstract function so that we don't release its body.
1035 The DECL_INITIAL() of that abstract function declaration
1036 will be later needed to output debug info. */
1037 if (DECL_ABSTRACT_ORIGIN (decl
))
1039 cgraph_node
*origin_node
1040 = cgraph_node::get_create (DECL_ABSTRACT_ORIGIN (decl
));
1041 origin_node
->used_as_abstract_origin
= true;
1046 varpool_node
*vnode
= dyn_cast
<varpool_node
*> (node
);
1047 if (vnode
&& vnode
->definition
&& !vnode
->analyzed
)
1051 if (node
->same_comdat_group
)
1054 for (next
= node
->same_comdat_group
;
1056 next
= next
->same_comdat_group
)
1057 if (!next
->comdat_local_p ())
1058 enqueue_node (next
);
1060 for (i
= 0; node
->iterate_reference (i
, ref
); i
++)
1061 if (ref
->referred
->definition
1062 && (!DECL_EXTERNAL (ref
->referred
->decl
)
1063 || ((TREE_CODE (ref
->referred
->decl
) != FUNCTION_DECL
1065 || (TREE_CODE (ref
->referred
->decl
) == FUNCTION_DECL
1066 && opt_for_fn (ref
->referred
->decl
, optimize
))
1067 || ref
->referred
->alias
)))
1068 enqueue_node (ref
->referred
);
1069 symtab
->process_new_functions ();
1072 update_type_inheritance_graph ();
1074 /* Collect entry points to the unit. */
1075 if (symtab
->dump_file
)
1077 fprintf (symtab
->dump_file
, "\n\nInitial ");
1078 symtab_node::dump_table (symtab
->dump_file
);
1081 if (symtab
->dump_file
)
1082 fprintf (symtab
->dump_file
, "\nRemoving unused symbols:");
1084 for (node
= symtab
->first_symbol ();
1085 node
!= first_handled
1086 && node
!= first_handled_var
; node
= next
)
1089 if (!node
->aux
&& !node
->referred_to_p ())
1091 if (symtab
->dump_file
)
1092 fprintf (symtab
->dump_file
, " %s", node
->name ());
1096 if (cgraph_node
*cnode
= dyn_cast
<cgraph_node
*> (node
))
1098 tree decl
= node
->decl
;
1100 if (cnode
->definition
&& !gimple_has_body_p (decl
)
1102 && !cnode
->thunk
.thunk_p
)
1105 gcc_assert (!cnode
->definition
|| cnode
->thunk
.thunk_p
1107 || gimple_has_body_p (decl
));
1108 gcc_assert (cnode
->analyzed
== cnode
->definition
);
1112 for (;node
; node
= node
->next
)
1114 first_analyzed
= symtab
->first_function ();
1115 first_analyzed_var
= symtab
->first_variable ();
1116 if (symtab
->dump_file
)
1118 fprintf (symtab
->dump_file
, "\n\nReclaimed ");
1119 symtab_node::dump_table (symtab
->dump_file
);
1121 bitmap_obstack_release (NULL
);
1123 /* Initialize assembler name hash, in particular we want to trigger C++
1124 mangling and same body alias creation before we free DECL_ARGUMENTS
1127 symtab
->symtab_initialize_asm_name_hash ();
1129 input_location
= saved_loc
;
1132 /* Translate the ugly representation of aliases as alias pairs into nice
1133 representation in callgraph. We don't handle all cases yet,
1137 handle_alias_pairs (void)
1142 for (i
= 0; alias_pairs
&& alias_pairs
->iterate (i
, &p
);)
1144 symtab_node
*target_node
= symtab_node::get_for_asmname (p
->target
);
1146 /* Weakrefs with target not defined in current unit are easy to handle:
1147 they behave just as external variables except we need to note the
1148 alias flag to later output the weakref pseudo op into asm file. */
1150 && lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)) != NULL
)
1152 symtab_node
*node
= symtab_node::get (p
->decl
);
1155 node
->alias_target
= p
->target
;
1156 node
->weakref
= true;
1159 alias_pairs
->unordered_remove (i
);
1162 else if (!target_node
)
1164 error ("%q+D aliased to undefined symbol %qE", p
->decl
, p
->target
);
1165 symtab_node
*node
= symtab_node::get (p
->decl
);
1167 node
->alias
= false;
1168 alias_pairs
->unordered_remove (i
);
1172 if (DECL_EXTERNAL (target_node
->decl
)
1173 /* We use local aliases for C++ thunks to force the tailcall
1174 to bind locally. This is a hack - to keep it working do
1175 the following (which is not strictly correct). */
1176 && (TREE_CODE (target_node
->decl
) != FUNCTION_DECL
1177 || ! DECL_VIRTUAL_P (target_node
->decl
))
1178 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
1180 error ("%q+D aliased to external symbol %qE",
1181 p
->decl
, p
->target
);
1184 if (TREE_CODE (p
->decl
) == FUNCTION_DECL
1185 && target_node
&& is_a
<cgraph_node
*> (target_node
))
1187 cgraph_node
*src_node
= cgraph_node::get (p
->decl
);
1188 if (src_node
&& src_node
->definition
)
1190 cgraph_node::create_alias (p
->decl
, target_node
->decl
);
1191 alias_pairs
->unordered_remove (i
);
1193 else if (TREE_CODE (p
->decl
) == VAR_DECL
1194 && target_node
&& is_a
<varpool_node
*> (target_node
))
1196 varpool_node::create_alias (p
->decl
, target_node
->decl
);
1197 alias_pairs
->unordered_remove (i
);
1201 error ("%q+D alias in between function and variable is not supported",
1203 warning (0, "%q+D aliased declaration",
1205 alias_pairs
->unordered_remove (i
);
1208 vec_free (alias_pairs
);
1212 /* Figure out what functions we want to assemble. */
1215 mark_functions_to_output (void)
1218 #ifdef ENABLE_CHECKING
1219 bool check_same_comdat_groups
= false;
1221 FOR_EACH_FUNCTION (node
)
1222 gcc_assert (!node
->process
);
1225 FOR_EACH_FUNCTION (node
)
1227 tree decl
= node
->decl
;
1229 gcc_assert (!node
->process
|| node
->same_comdat_group
);
1233 /* We need to output all local functions that are used and not
1234 always inlined, as well as those that are reachable from
1235 outside the current compilation unit. */
1237 && !node
->thunk
.thunk_p
1239 && !node
->global
.inlined_to
1240 && !TREE_ASM_WRITTEN (decl
)
1241 && !DECL_EXTERNAL (decl
))
1244 if (node
->same_comdat_group
)
1247 for (next
= dyn_cast
<cgraph_node
*> (node
->same_comdat_group
);
1249 next
= dyn_cast
<cgraph_node
*> (next
->same_comdat_group
))
1250 if (!next
->thunk
.thunk_p
&& !next
->alias
1251 && !next
->comdat_local_p ())
1255 else if (node
->same_comdat_group
)
1257 #ifdef ENABLE_CHECKING
1258 check_same_comdat_groups
= true;
1263 /* We should've reclaimed all functions that are not needed. */
1264 #ifdef ENABLE_CHECKING
1265 if (!node
->global
.inlined_to
1266 && gimple_has_body_p (decl
)
1267 /* FIXME: in ltrans unit when offline copy is outside partition but inline copies
1268 are inside partition, we can end up not removing the body since we no longer
1269 have analyzed node pointing to it. */
1270 && !node
->in_other_partition
1273 && !DECL_EXTERNAL (decl
))
1276 internal_error ("failed to reclaim unneeded function");
1279 gcc_assert (node
->global
.inlined_to
1280 || !gimple_has_body_p (decl
)
1281 || node
->in_other_partition
1283 || DECL_ARTIFICIAL (decl
)
1284 || DECL_EXTERNAL (decl
));
1289 #ifdef ENABLE_CHECKING
1290 if (check_same_comdat_groups
)
1291 FOR_EACH_FUNCTION (node
)
1292 if (node
->same_comdat_group
&& !node
->process
)
1294 tree decl
= node
->decl
;
1295 if (!node
->global
.inlined_to
1296 && gimple_has_body_p (decl
)
1297 /* FIXME: in an ltrans unit when the offline copy is outside a
1298 partition but inline copies are inside a partition, we can
1299 end up not removing the body since we no longer have an
1300 analyzed node pointing to it. */
1301 && !node
->in_other_partition
1303 && !DECL_EXTERNAL (decl
))
1306 internal_error ("failed to reclaim unneeded function in same "
1313 /* DECL is FUNCTION_DECL. Initialize datastructures so DECL is a function
1314 in lowered gimple form. IN_SSA is true if the gimple is in SSA.
1316 Set current_function_decl and cfun to newly constructed empty function body.
1317 return basic block in the function body. */
1320 init_lowered_empty_function (tree decl
, bool in_ssa
)
1324 current_function_decl
= decl
;
1325 allocate_struct_function (decl
, false);
1326 gimple_register_cfg_hooks ();
1327 init_empty_tree_cfg ();
1331 init_tree_ssa (cfun
);
1332 init_ssa_operands (cfun
);
1333 cfun
->gimple_df
->in_ssa_p
= true;
1334 cfun
->curr_properties
|= PROP_ssa
;
1337 DECL_INITIAL (decl
) = make_node (BLOCK
);
1339 DECL_SAVED_TREE (decl
) = error_mark_node
;
1340 cfun
->curr_properties
|= (PROP_gimple_lcf
| PROP_gimple_leh
| PROP_gimple_any
1341 | PROP_cfg
| PROP_loops
);
1343 set_loops_for_fn (cfun
, ggc_cleared_alloc
<loops
> ());
1344 init_loops_structure (cfun
, loops_for_fn (cfun
), 1);
1345 loops_for_fn (cfun
)->state
|= LOOPS_MAY_HAVE_MULTIPLE_LATCHES
;
1347 /* Create BB for body of the function and connect it properly. */
1348 bb
= create_basic_block (NULL
, (void *) 0, ENTRY_BLOCK_PTR_FOR_FN (cfun
));
1349 make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
), bb
, EDGE_FALLTHRU
);
1350 make_edge (bb
, EXIT_BLOCK_PTR_FOR_FN (cfun
), 0);
1351 add_bb_to_loop (bb
, ENTRY_BLOCK_PTR_FOR_FN (cfun
)->loop_father
);
1356 /* Adjust PTR by the constant FIXED_OFFSET, and by the vtable
1357 offset indicated by VIRTUAL_OFFSET, if that is
1358 non-null. THIS_ADJUSTING is nonzero for a this adjusting thunk and
1359 zero for a result adjusting thunk. */
1362 thunk_adjust (gimple_stmt_iterator
* bsi
,
1363 tree ptr
, bool this_adjusting
,
1364 HOST_WIDE_INT fixed_offset
, tree virtual_offset
)
1370 && fixed_offset
!= 0)
1372 stmt
= gimple_build_assign
1373 (ptr
, fold_build_pointer_plus_hwi_loc (input_location
,
1376 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1379 /* If there's a virtual offset, look up that value in the vtable and
1380 adjust the pointer again. */
1387 if (!vtable_entry_type
)
1389 tree vfunc_type
= make_node (FUNCTION_TYPE
);
1390 TREE_TYPE (vfunc_type
) = integer_type_node
;
1391 TYPE_ARG_TYPES (vfunc_type
) = NULL_TREE
;
1392 layout_type (vfunc_type
);
1394 vtable_entry_type
= build_pointer_type (vfunc_type
);
1398 create_tmp_reg (build_pointer_type
1399 (build_pointer_type (vtable_entry_type
)), "vptr");
1401 /* The vptr is always at offset zero in the object. */
1402 stmt
= gimple_build_assign (vtabletmp
,
1403 build1 (NOP_EXPR
, TREE_TYPE (vtabletmp
),
1405 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1407 /* Form the vtable address. */
1408 vtabletmp2
= create_tmp_reg (TREE_TYPE (TREE_TYPE (vtabletmp
)),
1410 stmt
= gimple_build_assign (vtabletmp2
,
1411 build_simple_mem_ref (vtabletmp
));
1412 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1414 /* Find the entry with the vcall offset. */
1415 stmt
= gimple_build_assign (vtabletmp2
,
1416 fold_build_pointer_plus_loc (input_location
,
1419 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1421 /* Get the offset itself. */
1422 vtabletmp3
= create_tmp_reg (TREE_TYPE (TREE_TYPE (vtabletmp2
)),
1424 stmt
= gimple_build_assign (vtabletmp3
,
1425 build_simple_mem_ref (vtabletmp2
));
1426 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1428 /* Adjust the `this' pointer. */
1429 ptr
= fold_build_pointer_plus_loc (input_location
, ptr
, vtabletmp3
);
1430 ptr
= force_gimple_operand_gsi (bsi
, ptr
, true, NULL_TREE
, false,
1431 GSI_CONTINUE_LINKING
);
1435 && fixed_offset
!= 0)
1436 /* Adjust the pointer by the constant. */
1440 if (TREE_CODE (ptr
) == VAR_DECL
)
1444 ptrtmp
= create_tmp_reg (TREE_TYPE (ptr
), "ptr");
1445 stmt
= gimple_build_assign (ptrtmp
, ptr
);
1446 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1448 ptr
= fold_build_pointer_plus_hwi_loc (input_location
,
1449 ptrtmp
, fixed_offset
);
1452 /* Emit the statement and gimplify the adjustment expression. */
1453 ret
= create_tmp_reg (TREE_TYPE (ptr
), "adjusted_this");
1454 stmt
= gimple_build_assign (ret
, ptr
);
1455 gsi_insert_after (bsi
, stmt
, GSI_NEW_STMT
);
1460 /* Expand thunk NODE to gimple if possible.
1461 When FORCE_GIMPLE_THUNK is true, gimple thunk is created and
1462 no assembler is produced.
1463 When OUTPUT_ASM_THUNK is true, also produce assembler for
1464 thunks that are not lowered. */
1467 cgraph_node::expand_thunk (bool output_asm_thunks
, bool force_gimple_thunk
)
1469 bool this_adjusting
= thunk
.this_adjusting
;
1470 HOST_WIDE_INT fixed_offset
= thunk
.fixed_offset
;
1471 HOST_WIDE_INT virtual_value
= thunk
.virtual_value
;
1472 tree virtual_offset
= NULL
;
1473 tree alias
= callees
->callee
->decl
;
1474 tree thunk_fndecl
= decl
;
1478 if (!force_gimple_thunk
&& this_adjusting
1479 && targetm
.asm_out
.can_output_mi_thunk (thunk_fndecl
, fixed_offset
,
1480 virtual_value
, alias
))
1484 tree restype
= TREE_TYPE (TREE_TYPE (thunk_fndecl
));
1486 if (!output_asm_thunks
)
1493 get_untransformed_body ();
1494 a
= DECL_ARGUMENTS (thunk_fndecl
);
1496 current_function_decl
= thunk_fndecl
;
1498 /* Ensure thunks are emitted in their correct sections. */
1499 resolve_unique_section (thunk_fndecl
, 0, flag_function_sections
);
1501 DECL_RESULT (thunk_fndecl
)
1502 = build_decl (DECL_SOURCE_LOCATION (thunk_fndecl
),
1503 RESULT_DECL
, 0, restype
);
1504 DECL_CONTEXT (DECL_RESULT (thunk_fndecl
)) = thunk_fndecl
;
1505 fnname
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl
));
1507 /* The back end expects DECL_INITIAL to contain a BLOCK, so we
1509 fn_block
= make_node (BLOCK
);
1510 BLOCK_VARS (fn_block
) = a
;
1511 DECL_INITIAL (thunk_fndecl
) = fn_block
;
1512 init_function_start (thunk_fndecl
);
1514 insn_locations_init ();
1515 set_curr_insn_location (DECL_SOURCE_LOCATION (thunk_fndecl
));
1516 prologue_location
= curr_insn_location ();
1517 assemble_start_function (thunk_fndecl
, fnname
);
1519 targetm
.asm_out
.output_mi_thunk (asm_out_file
, thunk_fndecl
,
1520 fixed_offset
, virtual_value
, alias
);
1522 assemble_end_function (thunk_fndecl
, fnname
);
1523 insn_locations_finalize ();
1524 init_insn_lengths ();
1525 free_after_compilation (cfun
);
1527 TREE_ASM_WRITTEN (thunk_fndecl
) = 1;
1528 thunk
.thunk_p
= false;
1534 basic_block bb
, then_bb
, else_bb
, return_bb
;
1535 gimple_stmt_iterator bsi
;
1546 get_untransformed_body ();
1547 a
= DECL_ARGUMENTS (thunk_fndecl
);
1549 current_function_decl
= thunk_fndecl
;
1551 /* Ensure thunks are emitted in their correct sections. */
1552 resolve_unique_section (thunk_fndecl
, 0, flag_function_sections
);
1554 DECL_IGNORED_P (thunk_fndecl
) = 1;
1555 bitmap_obstack_initialize (NULL
);
1557 if (thunk
.virtual_offset_p
)
1558 virtual_offset
= size_int (virtual_value
);
1560 /* Build the return declaration for the function. */
1561 restype
= TREE_TYPE (TREE_TYPE (thunk_fndecl
));
1562 if (DECL_RESULT (thunk_fndecl
) == NULL_TREE
)
1564 resdecl
= build_decl (input_location
, RESULT_DECL
, 0, restype
);
1565 DECL_ARTIFICIAL (resdecl
) = 1;
1566 DECL_IGNORED_P (resdecl
) = 1;
1567 DECL_RESULT (thunk_fndecl
) = resdecl
;
1568 DECL_CONTEXT (DECL_RESULT (thunk_fndecl
)) = thunk_fndecl
;
1571 resdecl
= DECL_RESULT (thunk_fndecl
);
1573 bb
= then_bb
= else_bb
= return_bb
= init_lowered_empty_function (thunk_fndecl
, true);
1575 bsi
= gsi_start_bb (bb
);
1577 /* Build call to the function being thunked. */
1578 if (!VOID_TYPE_P (restype
))
1580 if (DECL_BY_REFERENCE (resdecl
))
1582 restmp
= gimple_fold_indirect_ref (resdecl
);
1584 restmp
= build2 (MEM_REF
,
1585 TREE_TYPE (TREE_TYPE (DECL_RESULT (alias
))),
1587 build_int_cst (TREE_TYPE
1588 (DECL_RESULT (alias
)), 0));
1590 else if (!is_gimple_reg_type (restype
))
1594 if (TREE_CODE (restmp
) == VAR_DECL
)
1595 add_local_decl (cfun
, restmp
);
1596 BLOCK_VARS (DECL_INITIAL (current_function_decl
)) = restmp
;
1599 restmp
= create_tmp_reg (restype
, "retval");
1602 for (arg
= a
; arg
; arg
= DECL_CHAIN (arg
))
1604 auto_vec
<tree
> vargs (nargs
);
1606 vargs
.quick_push (thunk_adjust (&bsi
, a
, 1, fixed_offset
,
1609 vargs
.quick_push (a
);
1612 for (i
= 1, arg
= DECL_CHAIN (a
); i
< nargs
; i
++, arg
= DECL_CHAIN (arg
))
1615 if (!is_gimple_val (arg
))
1617 tmp
= create_tmp_reg (TYPE_MAIN_VARIANT
1618 (TREE_TYPE (arg
)), "arg");
1619 gimple stmt
= gimple_build_assign (tmp
, arg
);
1620 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
1622 vargs
.quick_push (tmp
);
1624 call
= gimple_build_call_vec (build_fold_addr_expr_loc (0, alias
), vargs
);
1625 callees
->call_stmt
= call
;
1626 gimple_call_set_from_thunk (call
, true);
1627 gimple_call_set_with_bounds (call
, instrumentation_clone
);
1630 gimple_call_set_lhs (call
, restmp
);
1631 gcc_assert (useless_type_conversion_p (TREE_TYPE (restmp
),
1632 TREE_TYPE (TREE_TYPE (alias
))));
1634 gsi_insert_after (&bsi
, call
, GSI_NEW_STMT
);
1635 if (!(gimple_call_flags (call
) & ECF_NORETURN
))
1637 if (restmp
&& !this_adjusting
1638 && (fixed_offset
|| virtual_offset
))
1640 tree true_label
= NULL_TREE
;
1642 if (TREE_CODE (TREE_TYPE (restmp
)) == POINTER_TYPE
)
1645 /* If the return type is a pointer, we need to
1646 protect against NULL. We know there will be an
1647 adjustment, because that's why we're emitting a
1649 then_bb
= create_basic_block (NULL
, (void *) 0, bb
);
1650 return_bb
= create_basic_block (NULL
, (void *) 0, then_bb
);
1651 else_bb
= create_basic_block (NULL
, (void *) 0, else_bb
);
1652 add_bb_to_loop (then_bb
, bb
->loop_father
);
1653 add_bb_to_loop (return_bb
, bb
->loop_father
);
1654 add_bb_to_loop (else_bb
, bb
->loop_father
);
1655 remove_edge (single_succ_edge (bb
));
1656 true_label
= gimple_block_label (then_bb
);
1657 stmt
= gimple_build_cond (NE_EXPR
, restmp
,
1658 build_zero_cst (TREE_TYPE (restmp
)),
1659 NULL_TREE
, NULL_TREE
);
1660 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
1661 make_edge (bb
, then_bb
, EDGE_TRUE_VALUE
);
1662 make_edge (bb
, else_bb
, EDGE_FALSE_VALUE
);
1663 make_edge (return_bb
, EXIT_BLOCK_PTR_FOR_FN (cfun
), 0);
1664 make_edge (then_bb
, return_bb
, EDGE_FALLTHRU
);
1665 make_edge (else_bb
, return_bb
, EDGE_FALLTHRU
);
1666 bsi
= gsi_last_bb (then_bb
);
1669 restmp
= thunk_adjust (&bsi
, restmp
, /*this_adjusting=*/0,
1670 fixed_offset
, virtual_offset
);
1674 bsi
= gsi_last_bb (else_bb
);
1675 stmt
= gimple_build_assign (restmp
,
1676 build_zero_cst (TREE_TYPE (restmp
)));
1677 gsi_insert_after (&bsi
, stmt
, GSI_NEW_STMT
);
1678 bsi
= gsi_last_bb (return_bb
);
1682 gimple_call_set_tail (call
, true);
1684 /* Build return value. */
1685 if (!DECL_BY_REFERENCE (resdecl
))
1686 ret
= gimple_build_return (restmp
);
1688 ret
= gimple_build_return (resdecl
);
1690 gsi_insert_after (&bsi
, ret
, GSI_NEW_STMT
);
1694 gimple_call_set_tail (call
, true);
1695 remove_edge (single_succ_edge (bb
));
1698 cfun
->gimple_df
->in_ssa_p
= true;
1699 /* FIXME: C++ FE should stop setting TREE_ASM_WRITTEN on thunks. */
1700 TREE_ASM_WRITTEN (thunk_fndecl
) = false;
1701 delete_unreachable_blocks ();
1702 update_ssa (TODO_update_ssa
);
1703 #ifdef ENABLE_CHECKING
1704 verify_flow_info ();
1706 free_dominance_info (CDI_DOMINATORS
);
1708 /* Since we want to emit the thunk, we explicitly mark its name as
1710 thunk
.thunk_p
= false;
1712 bitmap_obstack_release (NULL
);
1714 current_function_decl
= NULL
;
1719 /* Assemble thunks and aliases associated to node. */
1722 cgraph_node::assemble_thunks_and_aliases (void)
1727 for (e
= callers
; e
;)
1728 if (e
->caller
->thunk
.thunk_p
1729 && !e
->caller
->thunk
.add_pointer_bounds_args
)
1731 cgraph_node
*thunk
= e
->caller
;
1734 thunk
->expand_thunk (true, false);
1735 thunk
->assemble_thunks_and_aliases ();
1740 FOR_EACH_ALIAS (this, ref
)
1742 cgraph_node
*alias
= dyn_cast
<cgraph_node
*> (ref
->referring
);
1743 bool saved_written
= TREE_ASM_WRITTEN (decl
);
1745 /* Force assemble_alias to really output the alias this time instead
1746 of buffering it in same alias pairs. */
1747 TREE_ASM_WRITTEN (decl
) = 1;
1748 do_assemble_alias (alias
->decl
,
1749 DECL_ASSEMBLER_NAME (decl
));
1750 alias
->assemble_thunks_and_aliases ();
1751 TREE_ASM_WRITTEN (decl
) = saved_written
;
1755 /* Expand function specified by node. */
1758 cgraph_node::expand (void)
1760 location_t saved_loc
;
1762 /* We ought to not compile any inline clones. */
1763 gcc_assert (!global
.inlined_to
);
1765 announce_function (decl
);
1767 gcc_assert (lowered
);
1768 get_untransformed_body ();
1770 /* Generate RTL for the body of DECL. */
1772 timevar_push (TV_REST_OF_COMPILATION
);
1774 gcc_assert (symtab
->global_info_ready
);
1776 /* Initialize the default bitmap obstack. */
1777 bitmap_obstack_initialize (NULL
);
1779 /* Initialize the RTL code for the function. */
1780 current_function_decl
= decl
;
1781 saved_loc
= input_location
;
1782 input_location
= DECL_SOURCE_LOCATION (decl
);
1783 init_function_start (decl
);
1785 gimple_register_cfg_hooks ();
1787 bitmap_obstack_initialize (®_obstack
); /* FIXME, only at RTL generation*/
1789 execute_all_ipa_transforms ();
1791 /* Perform all tree transforms and optimizations. */
1793 /* Signal the start of passes. */
1794 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_START
, NULL
);
1796 execute_pass_list (cfun
, g
->get_passes ()->all_passes
);
1798 /* Signal the end of passes. */
1799 invoke_plugin_callbacks (PLUGIN_ALL_PASSES_END
, NULL
);
1801 bitmap_obstack_release (®_obstack
);
1803 /* Release the default bitmap obstack. */
1804 bitmap_obstack_release (NULL
);
1806 /* If requested, warn about function definitions where the function will
1807 return a value (usually of some struct or union type) which itself will
1808 take up a lot of stack space. */
1809 if (warn_larger_than
&& !DECL_EXTERNAL (decl
) && TREE_TYPE (decl
))
1811 tree ret_type
= TREE_TYPE (TREE_TYPE (decl
));
1813 if (ret_type
&& TYPE_SIZE_UNIT (ret_type
)
1814 && TREE_CODE (TYPE_SIZE_UNIT (ret_type
)) == INTEGER_CST
1815 && 0 < compare_tree_int (TYPE_SIZE_UNIT (ret_type
),
1818 unsigned int size_as_int
1819 = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (ret_type
));
1821 if (compare_tree_int (TYPE_SIZE_UNIT (ret_type
), size_as_int
) == 0)
1822 warning (OPT_Wlarger_than_
, "size of return value of %q+D is %u bytes",
1825 warning (OPT_Wlarger_than_
, "size of return value of %q+D is larger than %wd bytes",
1826 decl
, larger_than_size
);
1830 gimple_set_body (decl
, NULL
);
1831 if (DECL_STRUCT_FUNCTION (decl
) == 0
1832 && !cgraph_node::get (decl
)->origin
)
1834 /* Stop pointing to the local nodes about to be freed.
1835 But DECL_INITIAL must remain nonzero so we know this
1836 was an actual function definition.
1837 For a nested function, this is done in c_pop_function_context.
1838 If rest_of_compilation set this to 0, leave it 0. */
1839 if (DECL_INITIAL (decl
) != 0)
1840 DECL_INITIAL (decl
) = error_mark_node
;
1843 input_location
= saved_loc
;
1846 timevar_pop (TV_REST_OF_COMPILATION
);
1848 /* Make sure that BE didn't give up on compiling. */
1849 gcc_assert (TREE_ASM_WRITTEN (decl
));
1851 current_function_decl
= NULL
;
1853 /* It would make a lot more sense to output thunks before function body to get more
1854 forward and lest backwarding jumps. This however would need solving problem
1855 with comdats. See PR48668. Also aliases must come after function itself to
1856 make one pass assemblers, like one on AIX, happy. See PR 50689.
1857 FIXME: Perhaps thunks should be move before function IFF they are not in comdat
1859 assemble_thunks_and_aliases ();
1861 /* Eliminate all call edges. This is important so the GIMPLE_CALL no longer
1862 points to the dead function body. */
1864 remove_all_references ();
1867 /* Node comparer that is responsible for the order that corresponds
1868 to time when a function was launched for the first time. */
1871 node_cmp (const void *pa
, const void *pb
)
1873 const cgraph_node
*a
= *(const cgraph_node
* const *) pa
;
1874 const cgraph_node
*b
= *(const cgraph_node
* const *) pb
;
1876 /* Functions with time profile must be before these without profile. */
1877 if (!a
->tp_first_run
|| !b
->tp_first_run
)
1878 return a
->tp_first_run
- b
->tp_first_run
;
1880 return a
->tp_first_run
!= b
->tp_first_run
1881 ? b
->tp_first_run
- a
->tp_first_run
1882 : b
->order
- a
->order
;
1885 /* Expand all functions that must be output.
1887 Attempt to topologically sort the nodes so function is output when
1888 all called functions are already assembled to allow data to be
1889 propagated across the callgraph. Use a stack to get smaller distance
1890 between a function and its callees (later we may choose to use a more
1891 sophisticated algorithm for function reordering; we will likely want
1892 to use subsections to make the output functions appear in top-down
1896 expand_all_functions (void)
1899 cgraph_node
**order
= XCNEWVEC (cgraph_node
*,
1900 symtab
->cgraph_count
);
1901 unsigned int expanded_func_count
= 0, profiled_func_count
= 0;
1902 int order_pos
, new_order_pos
= 0;
1905 order_pos
= ipa_reverse_postorder (order
);
1906 gcc_assert (order_pos
== symtab
->cgraph_count
);
1908 /* Garbage collector may remove inline clones we eliminate during
1909 optimization. So we must be sure to not reference them. */
1910 for (i
= 0; i
< order_pos
; i
++)
1911 if (order
[i
]->process
)
1912 order
[new_order_pos
++] = order
[i
];
1914 if (flag_profile_reorder_functions
)
1915 qsort (order
, new_order_pos
, sizeof (cgraph_node
*), node_cmp
);
1917 for (i
= new_order_pos
- 1; i
>= 0; i
--)
1923 expanded_func_count
++;
1924 if(node
->tp_first_run
)
1925 profiled_func_count
++;
1927 if (symtab
->dump_file
)
1928 fprintf (symtab
->dump_file
,
1929 "Time profile order in expand_all_functions:%s:%d\n",
1930 node
->asm_name (), node
->tp_first_run
);
1937 fprintf (dump_file
, "Expanded functions with time profile (%s):%u/%u\n",
1938 main_input_filename
, profiled_func_count
, expanded_func_count
);
1940 if (symtab
->dump_file
&& flag_profile_reorder_functions
)
1941 fprintf (symtab
->dump_file
, "Expanded functions with time profile:%u/%u\n",
1942 profiled_func_count
, expanded_func_count
);
1944 symtab
->process_new_functions ();
1945 free_gimplify_stack ();
1950 /* This is used to sort the node types by the cgraph order number. */
1952 enum cgraph_order_sort_kind
1954 ORDER_UNDEFINED
= 0,
1960 struct cgraph_order_sort
1962 enum cgraph_order_sort_kind kind
;
1971 /* Output all functions, variables, and asm statements in the order
1972 according to their order fields, which is the order in which they
1973 appeared in the file. This implements -fno-toplevel-reorder. In
1974 this mode we may output functions and variables which don't really
1976 When NO_REORDER is true only do this for symbols marked no reorder. */
1979 output_in_order (bool no_reorder
)
1982 cgraph_order_sort
*nodes
;
1987 max
= symtab
->order
;
1988 nodes
= XCNEWVEC (cgraph_order_sort
, max
);
1990 FOR_EACH_DEFINED_FUNCTION (pf
)
1992 if (pf
->process
&& !pf
->thunk
.thunk_p
&& !pf
->alias
)
1994 if (no_reorder
&& !pf
->no_reorder
)
1997 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
1998 nodes
[i
].kind
= ORDER_FUNCTION
;
2003 FOR_EACH_DEFINED_VARIABLE (pv
)
2004 if (!DECL_EXTERNAL (pv
->decl
))
2006 if (no_reorder
&& !pv
->no_reorder
)
2009 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
2010 nodes
[i
].kind
= ORDER_VAR
;
2014 for (pa
= symtab
->first_asm_symbol (); pa
; pa
= pa
->next
)
2017 gcc_assert (nodes
[i
].kind
== ORDER_UNDEFINED
);
2018 nodes
[i
].kind
= ORDER_ASM
;
2022 /* In toplevel reorder mode we output all statics; mark them as needed. */
2024 for (i
= 0; i
< max
; ++i
)
2025 if (nodes
[i
].kind
== ORDER_VAR
)
2026 nodes
[i
].u
.v
->finalize_named_section_flags ();
2028 for (i
= 0; i
< max
; ++i
)
2030 switch (nodes
[i
].kind
)
2032 case ORDER_FUNCTION
:
2033 nodes
[i
].u
.f
->process
= 0;
2034 nodes
[i
].u
.f
->expand ();
2038 nodes
[i
].u
.v
->assemble_decl ();
2042 assemble_asm (nodes
[i
].u
.a
->asm_str
);
2045 case ORDER_UNDEFINED
:
2053 symtab
->clear_asm_symbols ();
2061 gcc::pass_manager
*passes
= g
->get_passes ();
2064 current_function_decl
= NULL
;
2065 gimple_register_cfg_hooks ();
2066 bitmap_obstack_initialize (NULL
);
2068 invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_START
, NULL
);
2072 execute_ipa_pass_list (passes
->all_small_ipa_passes
);
2077 /* This extra symtab_remove_unreachable_nodes pass tends to catch some
2078 devirtualization and other changes where removal iterate. */
2079 symtab
->remove_unreachable_nodes (symtab
->dump_file
);
2081 /* If pass_all_early_optimizations was not scheduled, the state of
2082 the cgraph will not be properly updated. Update it now. */
2083 if (symtab
->state
< IPA_SSA
)
2084 symtab
->state
= IPA_SSA
;
2088 /* Generate coverage variables and constructors. */
2091 /* Process new functions added. */
2093 current_function_decl
= NULL
;
2094 symtab
->process_new_functions ();
2096 execute_ipa_summary_passes
2097 ((ipa_opt_pass_d
*) passes
->all_regular_ipa_passes
);
2100 /* Some targets need to handle LTO assembler output specially. */
2101 if (flag_generate_lto
|| flag_generate_offload
)
2102 targetm
.asm_out
.lto_start ();
2106 if (g
->have_offload
)
2108 section_name_prefix
= OFFLOAD_SECTION_NAME_PREFIX
;
2109 ipa_write_summaries (true);
2113 section_name_prefix
= LTO_SECTION_NAME_PREFIX
;
2114 ipa_write_summaries (false);
2118 if (flag_generate_lto
|| flag_generate_offload
)
2119 targetm
.asm_out
.lto_end ();
2121 if (!flag_ltrans
&& (in_lto_p
|| !flag_lto
|| flag_fat_lto_objects
))
2122 execute_ipa_pass_list (passes
->all_regular_ipa_passes
);
2123 invoke_plugin_callbacks (PLUGIN_ALL_IPA_PASSES_END
, NULL
);
2125 bitmap_obstack_release (NULL
);
2129 /* Return string alias is alias of. */
2132 get_alias_symbol (tree decl
)
2134 tree alias
= lookup_attribute ("alias", DECL_ATTRIBUTES (decl
));
2135 return get_identifier (TREE_STRING_POINTER
2136 (TREE_VALUE (TREE_VALUE (alias
))));
2140 /* Weakrefs may be associated to external decls and thus not output
2141 at expansion time. Emit all necessary aliases. */
2144 symbol_table::output_weakrefs (void)
2148 FOR_EACH_SYMBOL (node
)
2150 && !TREE_ASM_WRITTEN (node
->decl
)
2151 && (!(cnode
= dyn_cast
<cgraph_node
*> (node
))
2152 || !cnode
->instrumented_version
2153 || !TREE_ASM_WRITTEN (cnode
->instrumented_version
->decl
))
2158 /* Weakrefs are special by not requiring target definition in current
2159 compilation unit. It is thus bit hard to work out what we want to
2161 When alias target is defined, we need to fetch it from symtab reference,
2162 otherwise it is pointed to by alias_target. */
2163 if (node
->alias_target
)
2164 target
= (DECL_P (node
->alias_target
)
2165 ? DECL_ASSEMBLER_NAME (node
->alias_target
)
2166 : node
->alias_target
);
2167 else if (node
->analyzed
)
2168 target
= DECL_ASSEMBLER_NAME (node
->get_alias_target ()->decl
);
2172 target
= get_alias_symbol (node
->decl
);
2174 do_assemble_alias (node
->decl
, target
);
2178 /* Perform simple optimizations based on callgraph. */
2181 symbol_table::compile (void)
2186 #ifdef ENABLE_CHECKING
2187 symtab_node::verify_symtab_nodes ();
2190 timevar_push (TV_CGRAPHOPT
);
2191 if (pre_ipa_mem_report
)
2193 fprintf (stderr
, "Memory consumption before IPA\n");
2194 dump_memory_report (false);
2197 fprintf (stderr
, "Performing interprocedural optimizations\n");
2200 /* Offloading requires LTO infrastructure. */
2201 if (!in_lto_p
&& g
->have_offload
)
2202 flag_generate_offload
= 1;
2204 /* If LTO is enabled, initialize the streamer hooks needed by GIMPLE. */
2205 if (flag_generate_lto
|| flag_generate_offload
)
2206 lto_streamer_hooks_init ();
2208 /* Don't run the IPA passes if there was any error or sorry messages. */
2212 /* Do nothing else if any IPA pass found errors or if we are just streaming LTO. */
2214 || (!in_lto_p
&& flag_lto
&& !flag_fat_lto_objects
))
2216 timevar_pop (TV_CGRAPHOPT
);
2220 global_info_ready
= true;
2223 fprintf (dump_file
, "Optimized ");
2224 symtab_node:: dump_table (dump_file
);
2226 if (post_ipa_mem_report
)
2228 fprintf (stderr
, "Memory consumption after IPA\n");
2229 dump_memory_report (false);
2231 timevar_pop (TV_CGRAPHOPT
);
2233 /* Output everything. */
2234 (*debug_hooks
->assembly_start
) ();
2236 fprintf (stderr
, "Assembling functions:\n");
2237 #ifdef ENABLE_CHECKING
2238 symtab_node::verify_symtab_nodes ();
2241 materialize_all_clones ();
2242 bitmap_obstack_initialize (NULL
);
2243 execute_ipa_pass_list (g
->get_passes ()->all_late_ipa_passes
);
2244 bitmap_obstack_release (NULL
);
2245 mark_functions_to_output ();
2247 /* When weakref support is missing, we autmatically translate all
2248 references to NODE to references to its ultimate alias target.
2249 The renaming mechanizm uses flag IDENTIFIER_TRANSPARENT_ALIAS and
2252 Set up this mapping before we output any assembler but once we are sure
2253 that all symbol renaming is done.
2255 FIXME: All this uglyness can go away if we just do renaming at gimple
2256 level by physically rewritting the IL. At the moment we can only redirect
2257 calls, so we need infrastructure for renaming references as well. */
2258 #ifndef ASM_OUTPUT_WEAKREF
2261 FOR_EACH_SYMBOL (node
)
2263 && lookup_attribute ("weakref", DECL_ATTRIBUTES (node
->decl
)))
2265 IDENTIFIER_TRANSPARENT_ALIAS
2266 (DECL_ASSEMBLER_NAME (node
->decl
)) = 1;
2267 TREE_CHAIN (DECL_ASSEMBLER_NAME (node
->decl
))
2268 = (node
->alias_target
? node
->alias_target
2269 : DECL_ASSEMBLER_NAME (node
->get_alias_target ()->decl
));
2275 if (!flag_toplevel_reorder
)
2276 output_in_order (false);
2279 /* Output first asm statements and anything ordered. The process
2280 flag is cleared for these nodes, so we skip them later. */
2281 output_in_order (true);
2282 expand_all_functions ();
2283 output_variables ();
2286 process_new_functions ();
2292 fprintf (dump_file
, "\nFinal ");
2293 symtab_node::dump_table (dump_file
);
2295 #ifdef ENABLE_CHECKING
2296 symtab_node::verify_symtab_nodes ();
2297 /* Double check that all inline clones are gone and that all
2298 function bodies have been released from memory. */
2302 bool error_found
= false;
2304 FOR_EACH_DEFINED_FUNCTION (node
)
2305 if (node
->global
.inlined_to
2306 || gimple_has_body_p (node
->decl
))
2312 internal_error ("nodes with unreleased memory found");
2318 /* Analyze the whole compilation unit once it is parsed completely. */
2321 symbol_table::finalize_compilation_unit (void)
2323 timevar_push (TV_CGRAPH
);
2325 /* If we're here there's no current function anymore. Some frontends
2326 are lazy in clearing these. */
2327 current_function_decl
= NULL
;
2330 /* Do not skip analyzing the functions if there were errors, we
2331 miss diagnostics for following functions otherwise. */
2333 /* Emit size functions we didn't inline. */
2334 finalize_size_functions ();
2336 /* Mark alias targets necessary and emit diagnostics. */
2337 handle_alias_pairs ();
2341 fprintf (stderr
, "\nAnalyzing compilation unit\n");
2345 if (flag_dump_passes
)
2348 /* Gimplify and lower all functions, compute reachability and
2349 remove unreachable nodes. */
2350 analyze_functions ();
2352 /* Mark alias targets necessary and emit diagnostics. */
2353 handle_alias_pairs ();
2355 /* Gimplify and lower thunks. */
2356 analyze_functions ();
2358 /* Finally drive the pass manager. */
2361 timevar_pop (TV_CGRAPH
);
2364 /* Reset all state within cgraphunit.c so that we can rerun the compiler
2365 within the same process. For use by toplev::finalize. */
2368 cgraphunit_c_finalize (void)
2370 gcc_assert (cgraph_new_nodes
.length () == 0);
2371 cgraph_new_nodes
.truncate (0);
2373 vtable_entry_type
= NULL
;
2374 queued_nodes
= &symtab_terminator
;
2376 first_analyzed
= NULL
;
2377 first_analyzed_var
= NULL
;
2380 /* Creates a wrapper from cgraph_node to TARGET node. Thunk is used for this
2381 kind of wrapper method. */
2384 cgraph_node::create_wrapper (cgraph_node
*target
)
2386 /* Preserve DECL_RESULT so we get right by reference flag. */
2387 tree decl_result
= DECL_RESULT (decl
);
2389 /* Remove the function's body but keep arguments to be reused
2391 release_body (true);
2394 DECL_RESULT (decl
) = decl_result
;
2395 DECL_INITIAL (decl
) = NULL
;
2396 allocate_struct_function (decl
, false);
2399 /* Turn alias into thunk and expand it into GIMPLE representation. */
2401 thunk
.thunk_p
= true;
2402 thunk
.this_adjusting
= false;
2404 cgraph_edge
*e
= create_edge (target
, NULL
, 0, CGRAPH_FREQ_BASE
);
2406 tree arguments
= DECL_ARGUMENTS (decl
);
2410 TREE_ADDRESSABLE (arguments
) = false;
2411 arguments
= TREE_CHAIN (arguments
);
2414 expand_thunk (false, true);
2415 e
->call_stmt_cannot_inline_p
= true;
2417 /* Inline summary set-up. */
2419 inline_analyze_function (this);
2422 #include "gt-cgraphunit.h"