From 89576d863a879c4986867f991a6ac493106a9879 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 22 Oct 2020 06:33:34 +0200 Subject: Move nested function info out of cgraph_node this patch moves nested function information out of symbol table (to a summary). This saves memory (especially at WPA time) and also makes nested function support more contained. gcc/ChangeLog: 2020-10-22 Jan Hubicka * cgraph.c: Include tree-nested.h (cgraph_node::create): Call maybe_record_nested_function. (cgraph_node::remove): Do not remove function from nested function infos. (cgraph_node::dump): Update. (cgraph_node::unnest): Move to tree-nested.c (cgraph_node::verify_node): Update. (cgraph_c_finalize): Call nested_function_info::release. * cgraph.h (struct symtab_node): Remove nested function info. * cgraphclones.c (cgraph_node::create_clone): Do not clone nested function info. * cgraphunit.c (cgraph_node::analyze): Update. (cgraph_node::expand): Do not worry about nested functions; they are lowered. (symbol_table::finalize_compilation_unit): Call nested_function_info::release. * gimplify.c: Include tree-nested.h (unshare_body): Update. (unvisit_body): Update. * omp-offload.c (omp_discover_implicit_declare_target): Update. * tree-nested.c: Include alloc-pool.h, tree-nested.h, symbol-summary.h (nested_function_sum): New static variable. (nested_function_info::get): New member function. (nested_function_info::get_create): New member function. (unnest_function): New function. (nested_function_info::~nested_function_info): New member function. (nested_function_info::release): New function. (maybe_record_nested_function): New function. (lookup_element_for_decl): Update. (check_for_nested_with_variably_modified): Update. (create_nesting_tree): Update. (unnest_nesting_tree_1): Update. (gimplify_all_functions): Update. (lower_nested_functions): Update. * tree-nested.h (class nested_function_info): New class. (maybe_record_nested_function): Declare. (unnest_function): Declare. (first_nested_function): New inline function. (next_nested_function): New inline function. (nested_function_origin): New inline function. gcc/ada/ChangeLog: 2020-10-22 Jan Hubicka * gcc-interface/trans.c: Include tree-nested.h (walk_nesting_tree): Update for new nested function info. gcc/c-family/ChangeLog: 2020-10-22 Jan Hubicka * c-gimplify.c: Include tree-nested.h (c_genericize): Update for new nested function info. gcc/d/ChangeLog: 2020-10-22 Jan Hubicka * decl.cc: Include tree-nested.h (get_symbol_decl): Update for new nested function info. --- gcc/cgraph.c | 76 ++++++++++++++++++++---------------------------------------- 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'gcc/cgraph.c') diff --git a/gcc/cgraph.c b/gcc/cgraph.c index f018020..9480935 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -64,6 +64,7 @@ along with GCC; see the file COPYING3. If not see #include "selftest.h" #include "tree-into-ssa.h" #include "ipa-inline.h" +#include "tree-nested.h" /* FIXME: Only for PROP_loops, but cgraph shouldn't have to know about this. */ #include "tree-pass.h" @@ -517,13 +518,8 @@ cgraph_node::create (tree decl) node->ifunc_resolver = true; node->register_symbol (); + maybe_record_nested_function (node); - if (DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL) - { - node->origin = cgraph_node::get_create (DECL_CONTEXT (decl)); - node->next_nested = node->origin->nested; - node->origin->nested = node; - } return node; } @@ -1861,22 +1857,7 @@ cgraph_node::remove (void) */ force_output = false; forced_by_abi = false; - cgraph_node *next; - for (cgraph_node *n = nested; n; n = next) - { - next = n->next_nested; - n->origin = NULL; - n->next_nested = NULL; - } - nested = NULL; - if (origin) - { - cgraph_node **node2 = &origin->nested; - while (*node2 != this) - node2 = &(*node2)->next_nested; - *node2 = next_nested; - } unregister (); if (prev_sibling_clone) prev_sibling_clone->next_sibling_clone = next_sibling_clone; @@ -2139,7 +2120,7 @@ cgraph_node::dump (FILE *f) } if (tp_first_run > 0) fprintf (f, " first_run:%" PRId64, (int64_t) tp_first_run); - if (origin) + if (cgraph_node *origin = nested_function_origin (this)) fprintf (f, " nested in:%s", origin->dump_asm_name ()); if (gimple_has_body_p (decl)) fprintf (f, " body"); @@ -2348,19 +2329,6 @@ cgraph_function_possibly_inlined_p (tree decl) return DECL_POSSIBLY_INLINED (decl); } -/* cgraph_node is no longer nested function; update cgraph accordingly. */ -void -cgraph_node::unnest (void) -{ - cgraph_node **node2 = &origin->nested; - gcc_assert (origin); - - while (*node2 != this) - node2 = &(*node2)->next_nested; - *node2 = next_nested; - origin = NULL; -} - /* Return function availability. See cgraph.h for description of individual return values. */ enum availability @@ -3798,27 +3766,32 @@ cgraph_node::verify_node (void) } } - if (nested != NULL) + if (nested_function_info *info = nested_function_info::get (this)) { - for (cgraph_node *n = nested; n != NULL; n = n->next_nested) + if (info->nested != NULL) { - if (n->origin == NULL) - { - error ("missing origin for a node in a nested list"); - error_found = true; - } - else if (n->origin != this) + for (cgraph_node *n = info->nested; n != NULL; + n = next_nested_function (n)) { - error ("origin points to a different parent"); - error_found = true; - break; + nested_function_info *ninfo = nested_function_info::get (n); + if (ninfo->origin == NULL) + { + error ("missing origin for a node in a nested list"); + error_found = true; + } + else if (ninfo->origin != this) + { + error ("origin points to a different parent"); + error_found = true; + break; + } } } - } - if (next_nested != NULL && origin == NULL) - { - error ("missing origin for a node in a nested list"); - error_found = true; + if (info->next_nested != NULL && info->origin == NULL) + { + error ("missing origin for a node in a nested list"); + error_found = true; + } } if (error_found) @@ -4022,6 +3995,7 @@ cgraph_node::get_fun () const void cgraph_c_finalize (void) { + nested_function_info::release (); symtab = NULL; x_cgraph_nodes_queue = NULL; -- cgit v1.1