diff options
author | Mark Mitchell <mark@codesourcery.com> | 2000-05-01 05:50:40 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2000-05-01 05:50:40 +0000 |
commit | 738e281059b7bd0f19aec2f0a08d00598c9a7469 (patch) | |
tree | e41de7e1f2eea4b105de1a4b38766e800772579c /gcc/cp | |
parent | e3fdc58a352cfb510340ae819be8f27b30af1206 (diff) | |
download | gcc-738e281059b7bd0f19aec2f0a08d00598c9a7469.zip gcc-738e281059b7bd0f19aec2f0a08d00598c9a7469.tar.gz gcc-738e281059b7bd0f19aec2f0a08d00598c9a7469.tar.bz2 |
expr.c (cplus_expand_expr): Preserve temporaries when expanding STMT_EXPRs.
* expr.c (cplus_expand_expr): Preserve temporaries when expanding
STMT_EXPRs.
* optimize.c (struct inline_data): Add target_exprs field.
(declare_return_variable): When a function returns an aggregate,
use the variable declared in the TARGET_EXPR as the remapped
DECL_RESULT.
(expand_call_inline): Update the pending target_exprs stack.
(optimize_function): Initialize the stack.
From-SVN: r33561
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/expr.c | 15 | ||||
-rw-r--r-- | gcc/cp/optimize.c | 48 |
3 files changed, 66 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8dc78d7..ff7b02d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2000-04-30 Mark Mitchell <mark@codesourcery.com> + * expr.c (cplus_expand_expr): Preserve temporaries when expanding + STMT_EXPRs. + * optimize.c (struct inline_data): Add target_exprs field. + (declare_return_variable): When a function returns an aggregate, + use the variable declared in the TARGET_EXPR as the remapped + DECL_RESULT. + (expand_call_inline): Update the pending target_exprs stack. + (optimize_function): Initialize the stack. + * decl2.c (finish_file): Fix typo in comment. * method.c (emit_thunk): Don't try to return a `void' value. diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c index ebf7c94..c47d390 100644 --- a/gcc/cp/expr.c +++ b/gcc/cp/expr.c @@ -143,10 +143,21 @@ cplus_expand_expr (exp, target, tmode, modifier) case STMT_EXPR: { - tree rtl_expr = expand_start_stmt_expr (); + tree rtl_expr; + rtx result; + + /* Since expand_expr_stmt calls free_temp_slots after every + expression statement, we must call push_temp_slots here. + Otherwise, any temporaries in use now would be considered + out-of-scope after the first EXPR_STMT from within the + STMT_EXPR. */ + push_temp_slots (); + rtl_expr = expand_start_stmt_expr (); expand_stmt (STMT_EXPR_STMT (exp)); expand_end_stmt_expr (rtl_expr); - return expand_expr (rtl_expr, target, tmode, modifier); + result = expand_expr (rtl_expr, target, tmode, modifier); + pop_temp_slots (); + return result; } break; diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c index e683f7e..a83b684 100644 --- a/gcc/cp/optimize.c +++ b/gcc/cp/optimize.c @@ -60,6 +60,8 @@ typedef struct inline_data /* Nonzero if we are currently within the cleanup for a TARGET_EXPR. */ int in_target_cleanup_p; + /* A stack of the TARGET_EXPRs that we are currently processing. */ + varray_type target_exprs; } inline_data; /* Prototypes. */ @@ -462,6 +464,7 @@ declare_return_variable (id, use_stmt) tree fn = VARRAY_TOP_TREE (id->fns); tree result = DECL_RESULT (fn); tree var; + int aggregate_return_p; /* We don't need to do anything for functions that don't return anything. */ @@ -472,8 +475,29 @@ declare_return_variable (id, use_stmt) return NULL_TREE; } - /* Make an appropriate copy. */ - var = copy_decl_for_inlining (result, fn, VARRAY_TREE (id->fns, 0)); + /* Figure out whether or not FN returns an aggregate. */ + aggregate_return_p = IS_AGGR_TYPE (TREE_TYPE (result)); + + /* If FN returns an aggregate then the caller will always create the + temporary (using a TARGET_EXPR) and the call will be the + initializing expression for the TARGET_EXPR. If we were just to + create a new VAR_DECL here, then the result of this function + would be copied (bitwise) into the variable initialized by the + TARGET_EXPR. That's incorrect, so we must transform any + references to the RESULT into references to the target. */ + if (aggregate_return_p) + { + my_friendly_assert (id->target_exprs->elements_used != 0, + 20000430); + var = TREE_OPERAND (VARRAY_TOP_TREE (id->target_exprs), 0); + my_friendly_assert (same_type_p (TREE_TYPE (var), + TREE_TYPE (result)), + 20000430); + } + /* Otherwise, make an appropriate copy. */ + else + var = copy_decl_for_inlining (result, fn, VARRAY_TREE (id->fns, 0)); + /* Register the VAR_DECL as the equivalent for the RESULT_DECL; that way, when the RESULT_DECL is encountered, it will be automatically replaced by the VAR_DECL. */ @@ -484,8 +508,14 @@ declare_return_variable (id, use_stmt) /* Build the USE_STMT. */ *use_stmt = build_min_nt (EXPR_STMT, var); - /* Build the declaration statement. */ - return build_min_nt (DECL_STMT, var); + /* Build the declaration statement if FN does not return an + aggregate. */ + if (!aggregate_return_p) + return build_min_nt (DECL_STMT, var); + /* If FN does return an aggregate, there's no need to declare the + return variable; we're using a variable in our caller's frame. */ + else + return NULL_TREE; } /* Returns non-zero if FN is a function that can be inlined. */ @@ -586,6 +616,9 @@ expand_call_inline (tp, walk_subtrees, data) /* We're walking our own subtrees. */ *walk_subtrees = 0; + /* Push *TP on the stack of pending TARGET_EXPRs. */ + VARRAY_PUSH_TREE (id->target_exprs, *tp); + /* Actually walk over them. This loop is the body of walk_trees, omitting the case where the TARGET_EXPR itself is handled. */ @@ -598,6 +631,9 @@ expand_call_inline (tp, walk_subtrees, data) --id->in_target_cleanup_p; } + /* We're done with this TARGET_EXPR now. */ + VARRAY_POP (id->target_exprs); + return NULL_TREE; } @@ -780,12 +816,16 @@ optimize_function (fn) prev_fn = s->function_decl; } + /* Create the stack of TARGET_EXPRs. */ + VARRAY_TREE_INIT (id.target_exprs, 32, "target_exprs"); + /* Replace all calls to inline functions with the bodies of those functions. */ expand_calls_inline (&DECL_SAVED_TREE (fn), &id); /* Clean up. */ VARRAY_FREE (id.fns); + VARRAY_FREE (id.target_exprs); } } |