static tree unsave_r (tree *, int *, void *);
static void declare_inline_vars (tree, tree);
static void remap_save_expr (tree *, void *, int *);
-static void add_lexical_block (tree current_block, tree new_block);
+static void prepend_lexical_block (tree current_block, tree new_block);
static tree copy_decl_to_var (tree, copy_body_data *);
static tree copy_result_decl_to_var (tree, copy_body_data *);
static tree copy_decl_maybe_to_var (tree, copy_body_data *);
remap_block (&new_tree, id);
gcc_assert (new_tree != block);
for (t = BLOCK_SUBBLOCKS (block); t ; t = BLOCK_CHAIN (t))
- add_lexical_block (new_tree, remap_blocks (t, id));
+ prepend_lexical_block (new_tree, remap_blocks (t, id));
+ /* Blocks are in arbitrary order, but make things slightly prettier and do
+ not swap order when producing a copy. */
+ BLOCK_SUBBLOCKS (new_tree) = blocks_nreverse (BLOCK_SUBBLOCKS (new_tree));
return new_tree;
}
gimple copy = NULL;
struct walk_stmt_info wi;
tree new_block;
+ bool skip_first = false;
/* Begin by recognizing trees that we'll completely rewrite for the
inlining context. Our output for these trees is completely
already been set (e.g. a recent "foo (&result_decl, ...)");
just toss the entire GIMPLE_RETURN. */
if (retval && TREE_CODE (retval) != RESULT_DECL)
- copy = gimple_build_assign (id->retvar, retval);
+ {
+ copy = gimple_build_assign (id->retvar, retval);
+ /* id->retvar is already substituted. Skip it on later remapping. */
+ skip_first = true;
+ }
else
return gimple_build_nop ();
}
/* Remap all the operands in COPY. */
memset (&wi, 0, sizeof (wi));
wi.info = id;
- walk_gimple_op (copy, remap_gimple_op_r, &wi);
+ if (skip_first)
+ walk_tree (gimple_op_ptr (copy, 1), remap_gimple_op_r, &wi, NULL);
+ else
+ walk_gimple_op (copy, remap_gimple_op_r, &wi);
/* We have to handle EH region remapping of GIMPLE_RESX specially because
the region number is not an operand. */
copy_bb (copy_body_data *id, basic_block bb, int frequency_scale,
gcov_type count_scale)
{
- gimple_stmt_iterator gsi, copy_gsi;
+ gimple_stmt_iterator gsi, copy_gsi, seq_gsi;
basic_block copy_basic_block;
tree decl;
continue;
gimple_duplicate_stmt_histograms (cfun, stmt, id->src_cfun, orig_stmt);
+ seq_gsi = copy_gsi;
/* With return slot optimization we can end up with
non-gimple (foo *)&this->m, fix that here. */
&& !is_gimple_val (gimple_assign_rhs1 (stmt)))
{
tree new_rhs;
- new_rhs = force_gimple_operand_gsi (©_gsi,
+ new_rhs = force_gimple_operand_gsi (&seq_gsi,
gimple_assign_rhs1 (stmt),
true, NULL, true, GSI_SAME_STMT);
gimple_assign_set_rhs1 (stmt, new_rhs);
+ id->regimplify = false;
}
- else if (id->regimplify)
- gimple_regimplify_operands (stmt, ©_gsi);
- gsi_insert_after (©_gsi, stmt, GSI_NEW_STMT);
+ gsi_insert_after (&seq_gsi, stmt, GSI_NEW_STMT);
+
+ if (id->regimplify)
+ gimple_regimplify_operands (stmt, &seq_gsi);
+
+ /* If copy_basic_block has been empty at the start of this iteration,
+ call gsi_start_bb again to get at the newly added statements. */
+ if (gsi_end_p (copy_gsi))
+ copy_gsi = gsi_start_bb (copy_basic_block);
+ else
+ gsi_next (©_gsi);
/* Process the new statement. The call to gimple_regimplify_operands
possibly turned the statement into multiple statements, we
need to process all of them. */
- while (!gsi_end_p (copy_gsi))
+ do
{
+ stmt = gsi_stmt (copy_gsi);
if (is_gimple_call (stmt)
&& gimple_call_va_arg_pack_p (stmt)
&& id->gimple_call)
gimple_call_set_lhs (new_call, gimple_call_lhs (stmt));
gsi_replace (©_gsi, new_call, false);
+ gimple_set_bb (stmt, NULL);
stmt = new_call;
}
else if (is_gimple_call (stmt)
gsi_next (©_gsi);
}
+ while (!gsi_end_p (copy_gsi));
copy_gsi = gsi_last_bb (copy_basic_block);
}
static void
insert_init_stmt (basic_block bb, gimple init_stmt)
{
- gimple_stmt_iterator si = gsi_last_bb (bb);
- gimple_stmt_iterator i;
- gimple_seq seq = gimple_seq_alloc ();
- struct gimplify_ctx gctx;
-
- push_gimplify_context (&gctx);
-
- i = gsi_start (seq);
- gimple_regimplify_operands (init_stmt, &i);
-
- if (init_stmt
- && !gimple_seq_empty_p (seq))
- {
- /* The replacement can expose previously unreferenced
- variables. */
- if (gimple_in_ssa_p (cfun))
- for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
- find_new_referenced_vars (gsi_stmt (i));
-
- /* Insert the gimplified sequence needed for INIT_STMT
- after SI. INIT_STMT will be inserted after SEQ. */
- gsi_insert_seq_after (&si, seq, GSI_NEW_STMT);
- }
-
- pop_gimplify_context (NULL);
-
/* If VAR represents a zero-sized variable, it's possible that the
assignment statement may result in no gimple statements. */
if (init_stmt)
- gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
+ {
+ gimple_stmt_iterator si = gsi_last_bb (bb);
- if (gimple_in_ssa_p (cfun))
- for (;!gsi_end_p (si); gsi_next (&si))
- mark_symbols_for_renaming (gsi_stmt (si));
+ /* We can end up with init statements that store to a non-register
+ from a rhs with a conversion. Handle that here by forcing the
+ rhs into a temporary. gimple_regimplify_operands is not
+ prepared to do this for us. */
+ if (!is_gimple_reg (gimple_assign_lhs (init_stmt))
+ && is_gimple_reg_type (TREE_TYPE (gimple_assign_lhs (init_stmt)))
+ && gimple_assign_rhs_class (init_stmt) == GIMPLE_UNARY_RHS)
+ {
+ tree rhs = build1 (gimple_assign_rhs_code (init_stmt),
+ gimple_expr_type (init_stmt),
+ gimple_assign_rhs1 (init_stmt));
+ rhs = force_gimple_operand_gsi (&si, rhs, true, NULL_TREE, false,
+ GSI_NEW_STMT);
+ gimple_assign_set_rhs_code (init_stmt, TREE_CODE (rhs));
+ gimple_assign_set_rhs1 (init_stmt, rhs);
+ }
+ gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
+ gimple_regimplify_operands (init_stmt, &si);
+ mark_symbols_for_renaming (init_stmt);
+ }
}
/* Initialize parameter P with VALUE. If needed, produce init statement
/* We only warn for functions declared `inline' by the user. */
do_warning = (warn_inline
&& DECL_DECLARED_INLINE_P (fn)
+ && !DECL_NO_INLINE_WARNING_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn));
always_inline = lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn));
/* Install new lexical TREE_BLOCK underneath 'current_block'. */
static void
-add_lexical_block (tree current_block, tree new_block)
+prepend_lexical_block (tree current_block, tree new_block)
{
- tree *blk_p;
-
- /* Walk to the last sub-block. */
- for (blk_p = &BLOCK_SUBBLOCKS (current_block);
- *blk_p;
- blk_p = &BLOCK_CHAIN (*blk_p))
- ;
- *blk_p = new_block;
+ BLOCK_CHAIN (new_block) = BLOCK_SUBBLOCKS (current_block);
+ BLOCK_SUBBLOCKS (current_block) = new_block;
BLOCK_SUPERCONTEXT (new_block) = current_block;
}
id->block = make_node (BLOCK);
BLOCK_ABSTRACT_ORIGIN (id->block) = fn;
BLOCK_SOURCE_LOCATION (id->block) = input_location;
- add_lexical_block (gimple_block (stmt), id->block);
+ prepend_lexical_block (gimple_block (stmt), id->block);
/* Local declarations will be replaced by their equivalents in this
map. */
initialize_inlined_parameters (id, stmt, fn, bb);
if (DECL_INITIAL (fn))
- add_lexical_block (id->block, remap_blocks (DECL_INITIAL (fn), id));
+ prepend_lexical_block (id->block, remap_blocks (DECL_INITIAL (fn), id));
/* Return statements in the function body will be replaced by jumps
to the RET_LABEL. */