- cgraph_varpool_finalize_variable
- This function has same behaviour as the above but is used for static
+ This function has same behavior as the above but is used for static
variables.
- cgraph_finalize_compilation_unit
mark_referenced call in assemble_variable functions referenced by
static variables are noticed too.
- The intra-procedural information is produced and it's existence
+ The intra-procedural information is produced and its existence
indicated by global_info_ready. Once this flag is set it is impossible
to change function from !reachable to reachable and thus
assemble_variable no longer call mark_referenced.
??? Move this to separate file after tree-ssa merge.
We separate inlining decisions from the inliner itself and store it
- inside callgraph as so called inline plan. Reffer to cgraph.c
+ inside callgraph as so called inline plan. Refer to cgraph.c
documentation about particular representation of inline plans in the
callgraph
cgraph_decide_inlining implements heuristics taking whole callgraph
into account, while cgraph_decide_inlining_incrementally considers
only one function at a time and is used in non-unit-at-a-time mode. */
+
+
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
+#include "rtl.h"
+#include "tree-flow.h"
#include "tree-inline.h"
#include "langhooks.h"
-#include "hashtab.h"
+#include "pointer-set.h"
#include "toplev.h"
#include "flags.h"
#include "ggc.h"
#include "c-common.h"
#include "intl.h"
#include "function.h"
+#include "tree-gimple.h"
#define INSNS_PER_CALL 10
walk_tree_without_duplicates doesn't guarantee each node is visited
once because it gets a new htab upon each recursive call from
record_calls_1. */
-static htab_t visited_nodes;
+static struct pointer_set_t *visited_nodes;
+
+static FILE *cgraph_dump_file;
/* Determine if function DECL is needed. That is, visible to something
either outside this translation unit, something magic in the system
static bool
decide_is_function_needed (struct cgraph_node *node, tree decl)
{
+ tree origin;
+
/* If we decided it was needed before, but at the time we didn't have
the body of the function available, then it's still needed. We have
to go back and re-check its dependencies now. */
/* "extern inline" functions are never output locally. */
if (DECL_EXTERNAL (decl))
return false;
+ /* Nested functions of extern inline function shall not be emit unless
+ we inlined the origin. */
+ for (origin = decl_function_context (decl); origin;
+ origin = decl_function_context (origin))
+ if (DECL_EXTERNAL (origin))
+ return false;
/* We want to emit COMDAT functions only when absolutely necessary. */
if (DECL_COMDAT (decl))
return false;
return false;
}
+
+
/* When not doing unit-at-a-time, output all functions enqueued.
Return true when such a functions were found. */
cgraph_nodes_queue = cgraph_nodes_queue->next_needed;
n->next_needed = NULL;
- if (!n->origin && !n->global.inlined_to && !DECL_EXTERNAL (n->decl))
+ if (!n->global.inlined_to && !DECL_EXTERNAL (n->decl))
{
cgraph_expand_function (n);
output = true;
case can be sort-of legitimately seen with real function
redefinition errors. I would argue that the front end should
never present us with such a case, but don't enforce that for now. */
- if (node->output)
- abort ();
+ gcc_assert (!node->output);
- /* Reset our datastructures so we can analyze the function again. */
+ /* Reset our data structures so we can analyze the function again. */
memset (&node->local, 0, sizeof (node->local));
memset (&node->global, 0, sizeof (node->global));
memset (&node->rtl, 0, sizeof (node->rtl));
notice_global_symbol (decl);
node->decl = decl;
node->local.finalized = true;
+ if (node->nested)
+ lower_nested_functions (decl);
+ gcc_assert (!node->nested);
/* If not unit at a time, then we need to create the call graph
now, so that called functions can be queued and emitted now. */
if (!TREE_ASM_WRITTEN (decl))
(*debug_hooks->deferred_inline_function) (decl);
- /* We will never really output the function body, clear the STRUCT_FUNCTION array
- early then. */
- if (DECL_EXTERNAL (decl))
- DECL_STRUCT_FUNCTION (decl) = NULL;
-
/* Possibly warn about unused parameters. */
if (warn_unused_parameter)
do_warn_unused_parameter (decl);
by this function and re-examine whether the decl is actually used
after rtl has been generated. */
if (TREE_STATIC (t))
- cgraph_varpool_mark_needed_node (cgraph_varpool_node (t));
+ {
+ cgraph_varpool_mark_needed_node (cgraph_varpool_node (t));
+ if (lang_hooks.callgraph.analyze_expr)
+ return lang_hooks.callgraph.analyze_expr (tp, walk_subtrees,
+ data);
+ }
break;
case ADDR_EXPR:
default:
/* Save some cycles by not walking types and declaration as we
won't find anything useful there anyway. */
- if (DECL_P (*tp) || TYPE_P (*tp))
+ if (IS_TYPE_OR_DECL_P (*tp))
{
*walk_subtrees = 0;
break;
{
/* The nodes we're interested in are never shared, so walk
the tree ignoring duplicates. */
- visited_nodes = htab_create (37, htab_hash_pointer,
- htab_eq_pointer, NULL);
+ visited_nodes = pointer_set_create ();
walk_tree (&body, record_call_1, node, visited_nodes);
- htab_delete (visited_nodes);
+ pointer_set_destroy (visited_nodes);
visited_nodes = NULL;
}
static bool error_found;
-/* Callbrack of verify_cgraph_node. Check that all call_exprs have cgraph nodes. */
+/* Callback of verify_cgraph_node. Check that all call_exprs have
+ cgraph nodes. */
+
static tree
verify_cgraph_node_1 (tree *tp, int *walk_subtrees, void *data)
{
error_found = true;
}
}
+
/* Save some cycles by not walking types and declaration as we
won't find anything useful there anyway. */
- if (DECL_P (*tp) || TYPE_P (*tp))
- {
- *walk_subtrees = 0;
- }
+ if (IS_TYPE_OR_DECL_P (*tp))
+ *walk_subtrees = 0;
+
return NULL_TREE;
}
{
struct cgraph_node *node;
+ if (sorrycount || errorcount)
+ return;
+
for (node = cgraph_nodes; node; node = node->next)
verify_cgraph_node (node);
}
cgraph_create_edges (node, DECL_SAVED_TREE (decl));
node->local.inlinable = tree_inlinable_function_p (decl);
- if (!node->local.self_insns)
- node->local.self_insns
- = lang_hooks.tree_inlining.estimate_num_insns (decl);
+ node->local.self_insns = estimate_num_insns (DECL_SAVED_TREE (decl));
if (node->local.inlinable)
node->local.disregard_inline_limits
= lang_hooks.tree_inlining.disregard_inline_limits (decl);
if (!DECL_SAVED_TREE (decl))
continue;
- if (node->analyzed || !node->reachable || !DECL_SAVED_TREE (decl))
- abort ();
+ gcc_assert (!node->analyzed && node->reachable);
+ gcc_assert (DECL_SAVED_TREE (decl));
cgraph_analyze_function (node);
ggc_collect ();
timevar_pop (TV_CGRAPH);
}
-
/* Figure out what functions we want to assemble. */
static void
{
tree decl = node->decl;
struct cgraph_edge *e;
-
- if (node->output)
- abort ();
+
+ gcc_assert (!node->output);
for (e = node->callers; e; e = e->next_caller)
if (e->inline_failed)
&& !node->global.inlined_to
&& (node->needed
|| (e && node->reachable))
- && !TREE_ASM_WRITTEN (decl) && !node->origin
+ && !TREE_ASM_WRITTEN (decl)
&& !DECL_EXTERNAL (decl))
node->output = 1;
- /* We should've reclaimed all functions that are not needed. */
- else if (!node->global.inlined_to && DECL_SAVED_TREE (decl)
- && !node->origin && !DECL_EXTERNAL (decl))
+ else
{
- dump_cgraph_node (stderr, node);
- abort ();
+ /* We should've reclaimed all functions that are not needed. */
+#ifdef ENABLE_CHECKING
+ if (!node->global.inlined_to && DECL_SAVED_TREE (decl)
+ && !DECL_EXTERNAL (decl))
+ {
+ dump_cgraph_node (stderr, node);
+ internal_error ("failed to reclaim unneeded function");
+ }
+#endif
+ gcc_assert (node->global.inlined_to || !DECL_SAVED_TREE (decl)
+ || DECL_EXTERNAL (decl));
+
}
+
}
}
tree decl = node->decl;
/* We ought to not compile any inline clones. */
- if (node->global.inlined_to)
- abort ();
+ gcc_assert (!node->global.inlined_to);
if (flag_unit_at_a_time)
announce_function (decl);
- /* Generate RTL for the body of DECL. Nested functions are expanded
- via lang_expand_decl_stmt. */
+ /* Generate RTL for the body of DECL. */
lang_hooks.callgraph.expand_function (decl);
- if (DECL_DEFER_OUTPUT (decl))
- abort ();
- /* Make sure that BE didn't gave up on compiling. */
- if (!TREE_ASM_WRITTEN (node->decl)
- && !(sorrycount || errorcount))
- abort ();
+ /* Make sure that BE didn't give up on compiling. */
+ /* ??? Can happen with nested function of extern inline. */
+ gcc_assert (TREE_ASM_WRITTEN (node->decl));
current_function_decl = NULL;
+ if (!cgraph_preserve_function_body_p (node->decl))
+ {
+ DECL_SAVED_TREE (node->decl) = NULL;
+ DECL_STRUCT_FUNCTION (node->decl) = NULL;
+ DECL_INITIAL (node->decl) = error_mark_node;
+ /* Eliminate all call edges. This is important so the call_expr no longer
+ points to the dead function body. */
+ while (node->callees)
+ cgraph_remove_edge (node->callees);
+ }
}
/* Fill array order with all nodes with output flag set in the reverse
/* We have to deal with cycles nicely, so use a depth first traversal
output algorithm. Ignore the fact that some functions won't need
to be output and put them into order as well, so we get dependencies
- right throughout inline functions. */
+ right through intline functions. */
for (node = cgraph_nodes; node; node = node->next)
node->aux = NULL;
for (node = cgraph_nodes; node; node = node->next)
return order_pos;
}
+
/* Perform reachability analysis and reclaim all unreachable nodes.
This function also remove unneeded bodies of extern inline functions
and thus needs to be done only after inlining decisions has been made. */
fprintf (cgraph_dump_file, "\nReclaiming functions:");
#ifdef ENABLE_CHECKING
for (node = cgraph_nodes; node; node = node->next)
- if (node->aux)
- abort ();
+ gcc_assert (!node->aux);
#endif
for (node = cgraph_nodes; node; node = node->next)
- if (node->needed && (!DECL_EXTERNAL (node->decl) || !node->analyzed))
+ if (node->needed && !node->global.inlined_to
+ && (!DECL_EXTERNAL (node->decl) || !node->analyzed))
{
node->aux = first;
first = node;
}
- else if (node->aux)
- abort ();
+ else
+ gcc_assert (!node->aux);
/* Perform reachability analysis. As a special case do not consider
extern inline functions not inlined as live because we won't output
/* Remove unreachable nodes. Extern inline functions need special care;
Unreachable extern inline functions shall be removed.
Reachable extern inline functions we never inlined shall get their bodies
- eliminated
+ eliminated.
Reachable extern inline functions we sometimes inlined will be turned into
unanalyzed nodes so they look like for true extern functions to the rest
of code. Body of such functions is released via remove_node once the
int local_insns;
tree decl = node->decl;
+ node->global.inlined_to = NULL;
if (DECL_STRUCT_FUNCTION (decl))
local_insns = node->local.self_insns;
else
{
DECL_SAVED_TREE (node->decl) = NULL;
DECL_STRUCT_FUNCTION (node->decl) = NULL;
- DECL_ARGUMENTS (node->decl) = NULL;
DECL_INITIAL (node->decl) = error_mark_node;
}
while (node->callees)
/* ??? Wrong for self recursive functions or cases where we decide to not
inline for different reasons, but it is not big deal as in that case
we will keep the body around, but we will also avoid some inlining. */
- if (!node->needed && !node->origin && !DECL_EXTERNAL (node->decl))
+ if (!node->needed && !DECL_EXTERNAL (node->decl))
growth -= node->global.insns;
return growth;
/* E is expected to be an edge being inlined. Clone destination node of
the edge and redirect it to the new clone.
- DUPLICATE is used for bookeeping on whether we are actually creating new
+ DUPLICATE is used for bookkeeping on whether we are actually creating new
clones or re-using node originally representing out-of-line function call.
*/
void
{
struct cgraph_node *n;
- /* We may elliminate the need for out-of-line copy to be output. In that
+ /* We may eliminate the need for out-of-line copy to be output. In that
case just go ahead and re-use it. */
if (!e->callee->callers->next_caller
&& (!e->callee->needed || DECL_EXTERNAL (e->callee->decl))
- && !e->callee->origin
&& duplicate
&& flag_unit_at_a_time)
{
- if (e->callee->global.inlined_to)
- abort ();
+ gcc_assert (!e->callee->global.inlined_to);
if (!DECL_EXTERNAL (e->callee->decl))
overall_insns -= e->callee->global.insns, nfunctions_inlined++;
duplicate = 0;
int old_insns = 0, new_insns = 0;
struct cgraph_node *to = NULL, *what;
- if (!e->inline_failed)
- abort ();
+ gcc_assert (e->inline_failed);
e->inline_failed = NULL;
if (!e->callee->global.inlined && flag_unit_at_a_time)
- {
- void **slot;
- if (!cgraph_inline_hash)
- cgraph_inline_hash = htab_create_ggc (42, htab_hash_pointer,
- htab_eq_pointer, NULL);
- slot = htab_find_slot (cgraph_inline_hash,
- DECL_ASSEMBLER_NAME (e->callee->decl), INSERT);
- *slot = DECL_ASSEMBLER_NAME (e->callee->decl);
- }
+ DECL_POSSIBLY_INLINED (e->callee->decl) = true;
e->callee->global.inlined = true;
cgraph_clone_inlined_nodes (e, true);
what = e->callee;
- /* Now update size of caller and all functions caller is inlined into. */
+ /* Now update size of caller and all functions caller is inlined into. */
for (;e && !e->inline_failed; e = e->caller->callers)
{
old_insns = e->caller->global.insns;
new_insns = cgraph_estimate_size_after_inlining (1, e->caller,
what);
- if (new_insns < 0)
- abort ();
+ gcc_assert (new_insns >= 0);
to = e->caller;
to->global.insns = new_insns;
}
- if (what->global.inlined_to != to)
- abort ();
+ gcc_assert (what->global.inlined_to == to);
overall_insns += new_insns - old_insns;
ncalls_inlined++;
}
cgraph_mark_inline_edge (e);
if (e == edge)
edge = next;
- times ++;
+ times++;
}
}
- if (!times)
- abort ();
+ gcc_assert (times);
return edge;
}
struct cgraph_node *what,
const char **reason)
{
- struct cgraph_node *node;
-
- /* Walk TO and all functions TO is inlined in. */
- while (1)
- {
- /* We create recursive inlining either by inlining WHAT into something
- already inlined in possibly different clone of WHAT. */
- if (what->decl == to->decl)
- goto recursive;
- /* Or by inlining WHAT into something that is already inlined in WHAT. */
- for (node = cgraph_node (to->decl); node; node = node->next_clone)
- if (node->global.inlined_to == what)
- goto recursive;
- if (!to->callers || to->callers->inline_failed)
- return false;
- to = to->callers->caller;
- }
-recursive:
- if (reason)
+ bool recursive;
+ if (to->global.inlined_to)
+ recursive = what->decl == to->global.inlined_to->decl;
+ else
+ recursive = what->decl == to->decl;
+ /* Marking recursive function inline has sane semantic and thus we should
+ not warn on it. */
+ if (recursive && reason)
*reason = (what->local.disregard_inline_limits
? N_("recursive inlining") : "");
- return true;
+ return recursive;
}
/* Recompute heap nodes for each of callees. */
update_callee_keys (heap, heap_node, e->callee);
}
+/* Enqueue all recursive calls from NODE into queue linked via aux pointers
+ in between FIRST and LAST. WHERE is used for bookkeeping while looking
+ int calls inlined within NODE. */
+static void
+lookup_recursive_calls (struct cgraph_node *node, struct cgraph_node *where,
+ struct cgraph_edge **first, struct cgraph_edge **last)
+{
+ struct cgraph_edge *e;
+ for (e = where->callees; e; e = e->next_callee)
+ if (e->callee == node)
+ {
+ if (!*first)
+ *first = e;
+ else
+ (*last)->aux = e;
+ *last = e;
+ }
+ for (e = where->callees; e; e = e->next_callee)
+ if (!e->inline_failed)
+ lookup_recursive_calls (node, e->callee, first, last);
+}
+
+/* Decide on recursive inlining: in the case function has recursive calls,
+ inline until body size reaches given argument. */
+static void
+cgraph_decide_recursive_inlining (struct cgraph_node *node)
+{
+ int limit = PARAM_VALUE (PARAM_MAX_INLINE_INSNS_RECURSIVE_AUTO);
+ int max_depth = PARAM_VALUE (PARAM_MAX_INLINE_RECURSIVE_DEPTH_AUTO);
+ struct cgraph_edge *first_call = NULL, *last_call = NULL;
+ struct cgraph_edge *last_in_current_depth;
+ struct cgraph_edge *e;
+ struct cgraph_node *master_clone;
+ int depth = 0;
+ int n = 0;
+
+ if (DECL_DECLARED_INLINE_P (node->decl))
+ {
+ limit = PARAM_VALUE (PARAM_MAX_INLINE_INSNS_RECURSIVE);
+ max_depth = PARAM_VALUE (PARAM_MAX_INLINE_RECURSIVE_DEPTH);
+ }
+
+ /* Make sure that function is small enough to be considered for inlining. */
+ if (!max_depth
+ || cgraph_estimate_size_after_inlining (1, node, node) >= limit)
+ return;
+ lookup_recursive_calls (node, node, &first_call, &last_call);
+ if (!first_call)
+ return;
+
+ if (cgraph_dump_file)
+ fprintf (cgraph_dump_file,
+ "\nPerforming recursive inlining on %s\n",
+ cgraph_node_name (node));
+
+ /* We need original clone to copy around. */
+ master_clone = cgraph_clone_node (node);
+ master_clone->needed = true;
+ for (e = master_clone->callees; e; e = e->next_callee)
+ if (!e->inline_failed)
+ cgraph_clone_inlined_nodes (e, true);
+
+ /* Do the inlining and update list of recursive call during process. */
+ last_in_current_depth = last_call;
+ while (first_call
+ && cgraph_estimate_size_after_inlining (1, node, master_clone) <= limit)
+ {
+ struct cgraph_edge *curr = first_call;
+
+ first_call = first_call->aux;
+ curr->aux = NULL;
+
+ cgraph_redirect_edge_callee (curr, master_clone);
+ cgraph_mark_inline_edge (curr);
+ lookup_recursive_calls (node, curr->callee, &first_call, &last_call);
+
+ if (last_in_current_depth
+ && ++depth >= max_depth)
+ break;
+ n++;
+ }
+
+ /* Cleanup queue pointers. */
+ while (first_call)
+ {
+ struct cgraph_edge *next = first_call->aux;
+ first_call->aux = NULL;
+ first_call = next;
+ }
+ if (cgraph_dump_file)
+ fprintf (cgraph_dump_file,
+ "\n Inlined %i times, body grown from %i to %i insns\n", n,
+ master_clone->global.insns, node->global.insns);
+
+ /* Remove master clone we used for inlining. We rely that clones inlined
+ into master clone gets queued just before master clone so we don't
+ need recursion. */
+ for (node = cgraph_nodes; node != master_clone;
+ node = node->next)
+ if (node->global.inlined_to == master_clone)
+ cgraph_remove_node (node);
+ cgraph_remove_node (master_clone);
+}
+
/* Set inline_failed for all callers of given function to REASON. */
static void
}
}
+ cgraph_decide_recursive_inlining (node);
+
/* Similarly all functions called by the function we just inlined
are now called more times; update keys. */
update_callee_keys (heap, heap_node, node);
}
/* Decide on the inlining. We do so in the topological order to avoid
- expenses on updating datastructures. */
+ expenses on updating data structures. */
static void
cgraph_decide_inlining (void)
so none of our later choices will make this impossible. */
for (i = nnodes - 1; i >= 0; i--)
{
- struct cgraph_edge *e;
+ struct cgraph_edge *e, *next;
node = order[i];
- for (e = node->callees; e; e = e->next_callee)
- if (e->callee->local.disregard_inline_limits)
- break;
- if (!e)
+ if (!node->local.disregard_inline_limits)
continue;
if (cgraph_dump_file)
fprintf (cgraph_dump_file,
"\nConsidering %s %i insns (always inline)\n",
- cgraph_node_name (e->callee), e->callee->global.insns);
- for (; e; e = e->next_callee)
+ cgraph_node_name (node), node->global.insns);
+ old_insns = overall_insns;
+ for (e = node->callers; e; e = next)
{
- old_insns = overall_insns;
- if (!e->inline_failed || !e->callee->local.disregard_inline_limits)
+ next = e->next_caller;
+ if (!e->inline_failed)
continue;
- if (cgraph_recursive_inlining_p (order[i], e->callee,
+ if (cgraph_recursive_inlining_p (e->caller, e->callee,
&e->inline_failed))
continue;
- cgraph_mark_inline (e);
+ cgraph_mark_inline_edge (e);
if (cgraph_dump_file)
fprintf (cgraph_dump_file,
" Inlined into %s which now has %i insns.\n",
- cgraph_node_name (node->callees->caller),
- node->callees->caller->global.insns);
+ cgraph_node_name (e->caller),
+ e->caller->global.insns);
}
- if (cgraph_dump_file)
- fprintf (cgraph_dump_file,
- " Inlined for a net change of %+i insns.\n",
- overall_insns - old_insns);
+ if (cgraph_dump_file)
+ fprintf (cgraph_dump_file,
+ " Inlined for a net change of %+i insns.\n",
+ overall_insns - old_insns);
}
if (!flag_really_no_inline)
}
/* Decide on the inlining. We do so in the topological order to avoid
- expenses on updating datastructures. */
+ expenses on updating data structures. */
static void
cgraph_decide_inlining_incrementally (struct cgraph_node *node)
return !e->inline_failed;
}
+
+
/* Expand all functions that must be output.
Attempt to topologically sort the nodes so function is output when
int order_pos = 0, new_order_pos = 0;
int i;
- cgraph_mark_functions_to_output ();
-
order_pos = cgraph_postorder (order);
- if (order_pos != cgraph_n_nodes)
- abort ();
+ gcc_assert (order_pos == cgraph_n_nodes);
- /* Garbage collector may remove inline clones we elliminate during
+ /* Garbage collector may remove inline clones we eliminate during
optimization. So we must be sure to not reference them. */
for (i = 0; i < order_pos; i++)
if (order[i]->output)
node = order[i];
if (node->output)
{
- if (!node->reachable)
- abort ();
+ gcc_assert (node->reachable);
node->output = 0;
cgraph_expand_function (node);
}
}
/* Mark all local functions.
-
- A local function is one whose calls can occur only in the
- current compilation unit and all its calls are explicit,
- so we can change its calling convention.
- We simply mark all static functions whose address is not taken
- as local. */
+
+ A local function is one whose calls can occur only in the current
+ compilation unit and all its calls are explicit, so we can change
+ its calling convention. We simply mark all static functions whose
+ address is not taken as local. */
static void
cgraph_mark_local_functions (void)
{
struct cgraph_node *node;
- if (cgraph_dump_file)
- fprintf (cgraph_dump_file, "\nMarking local functions:");
-
/* Figure out functions we want to assemble. */
for (node = cgraph_nodes; node; node = node->next)
{
node->local.local = (!node->needed
&& DECL_SAVED_TREE (node->decl)
&& !TREE_PUBLIC (node->decl));
- if (cgraph_dump_file && node->local.local)
- fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
}
+
if (cgraph_dump_file)
- fprintf (cgraph_dump_file, "\n\n");
+ {
+ fprintf (cgraph_dump_file, "\nMarking local functions:");
+ for (node = cgraph_nodes; node; node = node->next)
+ if (node->local.local)
+ fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
+ fprintf (cgraph_dump_file, "\n\n");
+ }
}
/* Return true when function body of DECL still needs to be kept around
{
struct cgraph_node *node;
/* Keep the body; we're going to dump it. */
- if (dump_enabled_p (TDI_all))
+ if (dump_enabled_p (TDI_tree_all))
return true;
if (!cgraph_global_info_ready)
return (DECL_INLINE (decl) && !flag_really_no_inline);
#ifdef ENABLE_CHECKING
verify_cgraph ();
#endif
+
+ cgraph_mark_functions_to_output ();
+
cgraph_expand_all_functions ();
if (cgraph_dump_file)
{
}
#ifdef ENABLE_CHECKING
verify_cgraph ();
+ /* Double check that all inline clones are gone and that all
+ function bodies have been released from memory. */
+ if (flag_unit_at_a_time
+ && !dump_enabled_p (TDI_tree_all)
+ && !(sorrycount || errorcount))
+ {
+ struct cgraph_node *node;
+ bool error_found = false;
+
+ for (node = cgraph_nodes; node; node = node->next)
+ if (node->analyzed
+ && (node->global.inlined_to
+ || DECL_SAVED_TREE (node->decl)))
+ {
+ error_found = true;
+ dump_cgraph_node (stderr, node);
+ }
+ if (error_found)
+ internal_error ("Nodes with no released memory found.");
+ }
#endif
}
+
+/* Generate and emit a static constructor or destructor. WHICH must be
+ one of 'I' or 'D'. BODY should be a STATEMENT_LIST containing
+ GENERIC statements. */
+
+void
+cgraph_build_static_cdtor (char which, tree body, int priority)
+{
+ static int counter = 0;
+ char which_buf[16];
+ tree decl, name, resdecl;
+
+ sprintf (which_buf, "%c_%d", which, counter++);
+ name = get_file_function_name_long (which_buf);
+
+ decl = build_decl (FUNCTION_DECL, name,
+ build_function_type (void_type_node, void_list_node));
+ current_function_decl = decl;
+
+ resdecl = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
+ DECL_ARTIFICIAL (resdecl) = 1;
+ DECL_IGNORED_P (resdecl) = 1;
+ DECL_RESULT (decl) = resdecl;
+
+ allocate_struct_function (decl);
+
+ TREE_STATIC (decl) = 1;
+ TREE_USED (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
+ DECL_IGNORED_P (decl) = 1;
+ DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
+ DECL_SAVED_TREE (decl) = body;
+ TREE_PUBLIC (decl) = ! targetm.have_ctors_dtors;
+ DECL_UNINLINABLE (decl) = 1;
+
+ DECL_INITIAL (decl) = make_node (BLOCK);
+ TREE_USED (DECL_INITIAL (decl)) = 1;
+
+ DECL_SOURCE_LOCATION (decl) = input_location;
+ cfun->function_end_locus = input_location;
+
+ switch (which)
+ {
+ case 'I':
+ DECL_STATIC_CONSTRUCTOR (decl) = 1;
+ break;
+ case 'D':
+ DECL_STATIC_DESTRUCTOR (decl) = 1;
+ break;
+ default:
+ gcc_unreachable ();
+ }
+
+ gimplify_function_tree (decl);
+
+ /* ??? We will get called LATE in the compilation process. */
+ if (cgraph_global_info_ready)
+ tree_rest_of_compilation (decl);
+ else
+ cgraph_finalize_function (decl, 0);
+
+ if (targetm.have_ctors_dtors)
+ {
+ void (*fn) (rtx, int);
+
+ if (which == 'I')
+ fn = targetm.asm_out.constructor;
+ else
+ fn = targetm.asm_out.destructor;
+ fn (XEXP (DECL_RTL (decl), 0), priority);
+ }
+}
+
+void
+init_cgraph (void)
+{
+ cgraph_dump_file = dump_begin (TDI_cgraph, NULL);
+}