diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-27 12:45:13 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-04-27 12:45:13 +0000 |
commit | 268b9e9e95f56a59a8817b28ad59b53f40fc668d (patch) | |
tree | 5e9529982daf11d5b3ab800d4c58bc3fbee99d28 /gcc/tree-nested.c | |
parent | e1910362719612f58bd1ea5050fa7a5175036abc (diff) | |
download | gcc-268b9e9e95f56a59a8817b28ad59b53f40fc668d.tar.gz |
2009-04-27 Basile Starynkevitch <basile@starynkevitch.net>
MERGED WITH TRUNK r146824::
* gcc/basilys.h: all GTY goes before the identifiers.
* gcc/basilys.c: removed errors.h include.
* gcc/run-basilys.h: ditto.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@146839 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-nested.c')
-rw-r--r-- | gcc/tree-nested.c | 282 |
1 files changed, 279 insertions, 3 deletions
diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 8f9fec58cf6..e45f8de2532 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -770,6 +770,7 @@ get_frame_field (struct nesting_info *info, tree target_context, return x; } +static void note_nonlocal_vla_type (struct nesting_info *info, tree type); /* A subroutine of convert_nonlocal_reference_op. Create a local variable in the nested function with DECL_VALUE_EXPR set to reference the true @@ -827,6 +828,11 @@ get_nonlocal_debug_decl (struct nesting_info *info, tree decl) TREE_READONLY (new_decl) = TREE_READONLY (decl); TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl); DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1; + if ((TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL + || TREE_CODE (decl) == VAR_DECL) + && DECL_BY_REFERENCE (decl)) + DECL_BY_REFERENCE (new_decl) = 1; SET_DECL_VALUE_EXPR (new_decl, x); DECL_HAS_VALUE_EXPR_P (new_decl) = 1; @@ -835,6 +841,11 @@ get_nonlocal_debug_decl (struct nesting_info *info, tree decl) TREE_CHAIN (new_decl) = info->debug_var_chain; info->debug_var_chain = new_decl; + if (!optimize + && info->context != target_context + && variably_modified_type_p (TREE_TYPE (decl), NULL)) + note_nonlocal_vla_type (info, TREE_TYPE (decl)); + return new_decl; } @@ -1106,6 +1117,60 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) return need_chain; } +/* Create nonlocal debug decls for nonlocal VLA array bounds. */ + +static void +note_nonlocal_vla_type (struct nesting_info *info, tree type) +{ + while (POINTER_TYPE_P (type) && !TYPE_NAME (type)) + type = TREE_TYPE (type); + + if (TYPE_NAME (type) + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) + type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); + + while (POINTER_TYPE_P (type) + || TREE_CODE (type) == VECTOR_TYPE + || TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + type = TREE_TYPE (type); + + if (TREE_CODE (type) == ARRAY_TYPE) + { + tree domain, t; + + note_nonlocal_vla_type (info, TREE_TYPE (type)); + domain = TYPE_DOMAIN (type); + if (domain) + { + t = TYPE_MIN_VALUE (domain); + if (t && (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == PARM_DECL) + && decl_function_context (t) != info->context) + get_nonlocal_debug_decl (info, t); + t = TYPE_MAX_VALUE (domain); + if (t && (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == PARM_DECL) + && decl_function_context (t) != info->context) + get_nonlocal_debug_decl (info, t); + } + } +} + +/* Create nonlocal debug decls for nonlocal VLA array bounds for VLAs + in BLOCK. */ + +static void +note_nonlocal_block_vlas (struct nesting_info *info, tree block) +{ + tree var; + + for (var = BLOCK_VARS (block); var; var = TREE_CHAIN (var)) + if (TREE_CODE (var) == VAR_DECL + && variably_modified_type_p (TREE_TYPE (var), NULL) + && DECL_HAS_VALUE_EXPR_P (var) + && decl_function_context (var) != info->context) + note_nonlocal_vla_type (info, TREE_TYPE (var)); +} /* Callback for walk_gimple_stmt. Rewrite all references to VAR and PARM_DECLs that belong to outer functions. This handles statements @@ -1197,6 +1262,13 @@ convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p, info, gimple_omp_body (stmt)); break; + case GIMPLE_BIND: + if (!optimize && gimple_bind_block (stmt)) + note_nonlocal_block_vlas (info, gimple_bind_block (stmt)); + + *handled_ops_p = false; + return NULL_TREE; + default: /* For every other statement that we are not interested in handling here, let the walker traverse the operands. */ @@ -1240,6 +1312,11 @@ get_local_debug_decl (struct nesting_info *info, tree decl, tree field) TREE_READONLY (new_decl) = TREE_READONLY (decl); TREE_ADDRESSABLE (new_decl) = TREE_ADDRESSABLE (decl); DECL_SEEN_IN_BIND_EXPR_P (new_decl) = 1; + if ((TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL + || TREE_CODE (decl) == VAR_DECL) + && DECL_BY_REFERENCE (decl)) + DECL_BY_REFERENCE (new_decl) = 1; SET_DECL_VALUE_EXPR (new_decl, x); DECL_HAS_VALUE_EXPR_P (new_decl) = 1; @@ -1944,6 +2021,142 @@ convert_all_function_calls (struct nesting_info *root) while (root); } +struct nesting_copy_body_data +{ + copy_body_data cb; + struct nesting_info *root; +}; + +/* A helper subroutine for debug_var_chain type remapping. */ + +static tree +nesting_copy_decl (tree decl, copy_body_data *id) +{ + struct nesting_copy_body_data *nid = (struct nesting_copy_body_data *) id; + void **slot = pointer_map_contains (nid->root->var_map, decl); + + if (slot) + return (tree) *slot; + + if (TREE_CODE (decl) == TYPE_DECL && DECL_ORIGINAL_TYPE (decl)) + { + tree new_decl = copy_decl_no_change (decl, id); + DECL_ORIGINAL_TYPE (new_decl) + = remap_type (DECL_ORIGINAL_TYPE (decl), id); + return new_decl; + } + + if (TREE_CODE (decl) == VAR_DECL + || TREE_CODE (decl) == PARM_DECL + || TREE_CODE (decl) == RESULT_DECL) + return decl; + + return copy_decl_no_change (decl, id); +} + +/* A helper function for remap_vla_decls. See if *TP contains + some remapped variables. */ + +static tree +contains_remapped_vars (tree *tp, int *walk_subtrees, void *data) +{ + struct nesting_info *root = (struct nesting_info *) data; + tree t = *tp; + void **slot; + + if (DECL_P (t)) + { + *walk_subtrees = 0; + slot = pointer_map_contains (root->var_map, t); + + if (slot) + return (tree) *slot; + } + return NULL; +} + +/* Remap VLA decls in BLOCK and subblocks if remapped variables are + involved. */ + +static void +remap_vla_decls (tree block, struct nesting_info *root) +{ + tree var, subblock, val, type; + struct nesting_copy_body_data id; + + for (subblock = BLOCK_SUBBLOCKS (block); + subblock; + subblock = BLOCK_CHAIN (subblock)) + remap_vla_decls (subblock, root); + + for (var = BLOCK_VARS (block); var; var = TREE_CHAIN (var)) + { + if (TREE_CODE (var) == VAR_DECL + && variably_modified_type_p (TREE_TYPE (var), NULL) + && DECL_HAS_VALUE_EXPR_P (var)) + { + type = TREE_TYPE (var); + val = DECL_VALUE_EXPR (var); + if (walk_tree (&type, contains_remapped_vars, root, NULL) != NULL + || walk_tree (&val, contains_remapped_vars, root, NULL) != NULL) + break; + } + } + if (var == NULL_TREE) + return; + + memset (&id, 0, sizeof (id)); + id.cb.copy_decl = nesting_copy_decl; + id.cb.decl_map = pointer_map_create (); + id.root = root; + + for (; var; var = TREE_CHAIN (var)) + if (TREE_CODE (var) == VAR_DECL + && variably_modified_type_p (TREE_TYPE (var), NULL) + && DECL_HAS_VALUE_EXPR_P (var)) + { + struct nesting_info *i; + tree newt, t, context; + + t = type = TREE_TYPE (var); + val = DECL_VALUE_EXPR (var); + if (walk_tree (&type, contains_remapped_vars, root, NULL) == NULL + && walk_tree (&val, contains_remapped_vars, root, NULL) == NULL) + continue; + + context = decl_function_context (var); + for (i = root; i; i = i->outer) + if (i->context == context) + break; + + if (i == NULL) + continue; + + id.cb.src_fn = i->context; + id.cb.dst_fn = i->context; + id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context); + + TREE_TYPE (var) = newt = remap_type (type, &id.cb); + while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt)) + { + newt = TREE_TYPE (newt); + t = TREE_TYPE (t); + } + if (TYPE_NAME (newt) + && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL + && DECL_ORIGINAL_TYPE (TYPE_NAME (newt)) + && newt != t + && TYPE_NAME (newt) == TYPE_NAME (t)) + TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb); + + walk_tree (&val, copy_tree_body_r, &id.cb, NULL); + if (val != DECL_VALUE_EXPR (var)) + SET_DECL_VALUE_EXPR (var, val); + } + + pointer_map_destroy (id.cb.decl_map); +} + /* Do "everything else" to clean up or complete state collected by the various walking passes -- lay out the types and decls, generate code to initialize the frame decl, store critical expressions in the @@ -2076,10 +2289,73 @@ finalize_nesting_tree_1 (struct nesting_info *root) declare_vars (root->new_local_var_chain, gimple_seq_first_stmt (gimple_body (root->context)), false); + if (root->debug_var_chain) - declare_vars (root->debug_var_chain, - gimple_seq_first_stmt (gimple_body (root->context)), - true); + { + tree debug_var; + gimple scope; + + remap_vla_decls (DECL_INITIAL (root->context), root); + + for (debug_var = root->debug_var_chain; debug_var; + debug_var = TREE_CHAIN (debug_var)) + if (variably_modified_type_p (TREE_TYPE (debug_var), NULL)) + break; + + /* If there are any debug decls with variable length types, + remap those types using other debug_var_chain variables. */ + if (debug_var) + { + struct nesting_copy_body_data id; + + memset (&id, 0, sizeof (id)); + id.cb.copy_decl = nesting_copy_decl; + id.cb.decl_map = pointer_map_create (); + id.root = root; + + for (; debug_var; debug_var = TREE_CHAIN (debug_var)) + if (variably_modified_type_p (TREE_TYPE (debug_var), NULL)) + { + tree type = TREE_TYPE (debug_var); + tree newt, t = type; + struct nesting_info *i; + + for (i = root; i; i = i->outer) + if (variably_modified_type_p (type, i->context)) + break; + + if (i == NULL) + continue; + + id.cb.src_fn = i->context; + id.cb.dst_fn = i->context; + id.cb.src_cfun = DECL_STRUCT_FUNCTION (root->context); + + TREE_TYPE (debug_var) = newt = remap_type (type, &id.cb); + while (POINTER_TYPE_P (newt) && !TYPE_NAME (newt)) + { + newt = TREE_TYPE (newt); + t = TREE_TYPE (t); + } + if (TYPE_NAME (newt) + && TREE_CODE (TYPE_NAME (newt)) == TYPE_DECL + && DECL_ORIGINAL_TYPE (TYPE_NAME (newt)) + && newt != t + && TYPE_NAME (newt) == TYPE_NAME (t)) + TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb); + } + + pointer_map_destroy (id.cb.decl_map); + } + + scope = gimple_seq_first_stmt (gimple_body (root->context)); + if (gimple_bind_block (scope)) + declare_vars (root->debug_var_chain, scope, true); + else + BLOCK_VARS (DECL_INITIAL (root->context)) + = chainon (BLOCK_VARS (DECL_INITIAL (root->context)), + root->debug_var_chain); + } /* Dump the translated tree function. */ dump_function (TDI_nested, root->context); |