aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-inline.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/tree-inline.c')
-rw-r--r--gcc/tree-inline.c204
1 files changed, 158 insertions, 46 deletions
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index fd4443c74f9..37d9098034f 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1,5 +1,5 @@
/* Tree inlining.
- Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
Contributed by Alexandre Oliva <aoliva@redhat.com>
@@ -122,7 +122,6 @@ eni_weights eni_time_weights;
static tree declare_return_variable (copy_body_data *, tree, tree, tree *);
static bool inlinable_function_p (tree);
static void remap_block (tree *, copy_body_data *);
-static tree remap_decls (tree, copy_body_data *);
static void copy_bind_expr (tree *, int *, copy_body_data *);
static tree mark_local_for_remap_r (tree *, int *, void *);
static void unsave_expr_1 (tree);
@@ -427,8 +426,65 @@ remap_type (tree type, copy_body_data *id)
return tmp;
}
+/* Return previously remapped type of TYPE in ID. Return NULL if TYPE
+ is NULL or TYPE has not been remapped before. */
+
static tree
-remap_decls (tree decls, copy_body_data *id)
+remapped_type (tree type, copy_body_data *id)
+{
+ tree *node;
+
+ if (type == NULL)
+ return type;
+
+ /* See if we have remapped this type. */
+ node = (tree *) pointer_map_contains (id->decl_map, type);
+ if (node)
+ return *node;
+ else
+ return NULL;
+}
+
+ /* The type only needs remapping if it's variably modified. */
+/* Decide if DECL can be put into BLOCK_NONLOCAL_VARs. */
+
+static bool
+can_be_nonlocal (tree decl, copy_body_data *id)
+{
+ /* We can not duplicate function decls. */
+ if (TREE_CODE (decl) == FUNCTION_DECL)
+ return true;
+
+ /* Local static vars must be non-local or we get multiple declaration
+ problems. */
+ if (TREE_CODE (decl) == VAR_DECL
+ && !auto_var_in_fn_p (decl, id->src_fn))
+ return true;
+
+ /* At the moment dwarf2out can handle only these types of nodes. We
+ can support more later. */
+ if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
+ return false;
+
+ /* We must use global type. We call remapped_type instead of
+ remap_type since we don't want to remap this type here if it
+ hasn't been remapped before. */
+ if (TREE_TYPE (decl) != remapped_type (TREE_TYPE (decl), id))
+ return false;
+
+ /* Wihtout SSA we can't tell if variable is used. */
+ if (!gimple_in_ssa_p (cfun))
+ return false;
+
+ /* Live variables must be copied so we can attach DECL_RTL. */
+ if (var_ann (decl))
+ return false;
+
+ return true;
+}
+
+static tree
+remap_decls (tree decls, VEC(tree,gc) **nonlocalized_list, copy_body_data *id)
{
tree old_var;
tree new_decls = NULL_TREE;
@@ -437,16 +493,18 @@ remap_decls (tree decls, copy_body_data *id)
for (old_var = decls; old_var; old_var = TREE_CHAIN (old_var))
{
tree new_var;
+ tree origin_var = DECL_ORIGIN (old_var);
- /* We cannot chain the local static declarations into the local_decls
- as we can't duplicate them or break one decl rule. Go ahead
- and link them into local_decls. */
-
- if (!auto_var_in_fn_p (old_var, id->src_fn)
- && !DECL_EXTERNAL (old_var))
+ if (can_be_nonlocal (old_var, id))
{
- cfun->local_decls = tree_cons (NULL_TREE, old_var,
- cfun->local_decls);
+ if (TREE_CODE (old_var) == VAR_DECL
+ && (var_ann (old_var) || !gimple_in_ssa_p (cfun)))
+ cfun->local_decls = tree_cons (NULL_TREE, old_var,
+ cfun->local_decls);
+ if (debug_info_level > DINFO_LEVEL_TERSE
+ && !DECL_IGNORED_P (old_var)
+ && nonlocalized_list)
+ VEC_safe_push (tree, gc, *nonlocalized_list, origin_var);
continue;
}
@@ -456,8 +514,16 @@ remap_decls (tree decls, copy_body_data *id)
/* If we didn't remap this variable, we can't mess with its
TREE_CHAIN. If we remapped this variable to the return slot, it's
already declared somewhere else, so don't declare it here. */
- if (!new_var || new_var == id->retvar)
+
+ if (new_var == id->retvar)
;
+ else if (!new_var)
+ {
+ if (debug_info_level > DINFO_LEVEL_TERSE
+ && !DECL_IGNORED_P (old_var)
+ && nonlocalized_list)
+ VEC_safe_push (tree, gc, *nonlocalized_list, origin_var);
+ }
else
{
gcc_assert (DECL_P (new_var));
@@ -485,10 +551,14 @@ remap_block (tree *block, copy_body_data *id)
TREE_USED (new_block) = TREE_USED (old_block);
BLOCK_ABSTRACT_ORIGIN (new_block) = old_block;
BLOCK_SOURCE_LOCATION (new_block) = BLOCK_SOURCE_LOCATION (old_block);
+ BLOCK_NONLOCALIZED_VARS (new_block)
+ = VEC_copy (tree, gc, BLOCK_NONLOCALIZED_VARS (old_block));
*block = new_block;
/* Remap its variables. */
- BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block), id);
+ BLOCK_VARS (new_block) = remap_decls (BLOCK_VARS (old_block),
+ &BLOCK_NONLOCALIZED_VARS (new_block),
+ id);
fn = id->dst_fn;
@@ -549,7 +619,7 @@ copy_bind_expr (tree *tp, int *walk_subtrees, copy_body_data *id)
if (BIND_EXPR_VARS (*tp))
/* This will remap a lot of the same decls again, but this should be
harmless. */
- BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), id);
+ BIND_EXPR_VARS (*tp) = remap_decls (BIND_EXPR_VARS (*tp), NULL, id);
}
@@ -595,7 +665,7 @@ copy_gimple_bind (gimple stmt, copy_body_data *id)
harmless. */
new_vars = gimple_bind_vars (stmt);
if (new_vars)
- new_vars = remap_decls (new_vars, id);
+ new_vars = remap_decls (new_vars, NULL, id);
new_bind = gimple_build_bind (new_vars, new_body, new_block);
@@ -2040,6 +2110,10 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
We need to construct map for the variable anyway as it might be used
in different SSA names when parameter is set in function.
+ Do replacement at -O0 for const arguments replaced by constant.
+ This is important for builtin_constant_p and other construct requiring
+ constant argument to be visible in inlined function body.
+
FIXME: This usually kills the last connection in between inlined
function parameter and the actual value in debug info. Can we do
better here? If we just inserted the statement, copy propagation
@@ -2048,6 +2122,9 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
We might want to introduce a notion that single SSA_NAME might
represent multiple variables for purposes of debugging. */
if (gimple_in_ssa_p (cfun) && rhs && def && is_gimple_reg (p)
+ && (optimize
+ || (TREE_READONLY (p)
+ && is_gimple_min_invariant (rhs)))
&& (TREE_CODE (rhs) == SSA_NAME
|| is_gimple_min_invariant (rhs))
&& !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
@@ -2058,7 +2135,7 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
/* If the value of argument is never used, don't care about initializing
it. */
- if (gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p))
+ if (optimize && gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p))
{
gcc_assert (!value || !TREE_SIDE_EFFECTS (value));
return NULL;
@@ -3076,7 +3153,7 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
tree modify_dest;
location_t saved_location;
struct cgraph_edge *cg_edge;
- const char *reason;
+ cgraph_inline_failed_t reason;
basic_block return_block;
edge e;
gimple_stmt_iterator gsi, stmt_gsi;
@@ -3141,7 +3218,7 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
cgraph_create_edge (id->dst_node, dest, stmt,
bb->count, CGRAPH_FREQ_BASE,
bb->loop_depth)->inline_failed
- = N_("originally indirect function call not considered for inlining");
+ = CIF_ORIGINALLY_INDIRECT_CALL;
if (dump_file)
{
fprintf (dump_file, "Created new direct edge to %s",
@@ -3164,18 +3241,19 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
/* Avoid warnings during early inline pass. */
&& cgraph_global_info_ready)
{
- sorry ("inlining failed in call to %q+F: %s", fn, reason);
+ sorry ("inlining failed in call to %q+F: %s", fn,
+ cgraph_inline_failed_string (reason));
sorry ("called from here");
}
else if (warn_inline && DECL_DECLARED_INLINE_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn)
- && strlen (reason)
+ && reason != CIF_UNSPECIFIED
&& !lookup_attribute ("noinline", DECL_ATTRIBUTES (fn))
/* Avoid warnings during early inline pass. */
&& cgraph_global_info_ready)
{
warning (OPT_Winline, "inlining failed in call to %q+F: %s",
- fn, reason);
+ fn, cgraph_inline_failed_string (reason));
warning (OPT_Winline, "called from here");
}
goto egress;
@@ -3305,26 +3383,29 @@ expand_call_inline (basic_block bb, gimple stmt, copy_body_data *id)
DECL_NO_TBAA_P (retvar) = 1;
}
- /* This is it. Duplicate the callee body. Assume callee is
- pre-gimplified. Note that we must not alter the caller
- function in any way before this point, as this CALL_EXPR may be
- a self-referential call; if we're calling ourselves, we need to
- duplicate our body before altering anything. */
- copy_body (id, bb->count, bb->frequency, bb, return_block);
-
/* Add local vars in this inlined callee to caller. */
t_step = id->src_cfun->local_decls;
for (; t_step; t_step = TREE_CHAIN (t_step))
{
var = TREE_VALUE (t_step);
if (TREE_STATIC (var) && !TREE_ASM_WRITTEN (var))
- cfun->local_decls = tree_cons (NULL_TREE, var,
- cfun->local_decls);
- else
+ {
+ if (var_ann (var) && add_referenced_var (var))
+ cfun->local_decls = tree_cons (NULL_TREE, var,
+ cfun->local_decls);
+ }
+ else if (!can_be_nonlocal (var, id))
cfun->local_decls = tree_cons (NULL_TREE, remap_decl (var, id),
- cfun->local_decls);
+ cfun->local_decls);
}
+ /* This is it. Duplicate the callee body. Assume callee is
+ pre-gimplified. Note that we must not alter the caller
+ function in any way before this point, as this CALL_EXPR may be
+ a self-referential call; if we're calling ourselves, we need to
+ duplicate our body before altering anything. */
+ copy_body (id, bb->count, bb->frequency, bb, return_block);
+
/* Clean up. */
pointer_map_destroy (id->decl_map);
id->decl_map = st;
@@ -3905,7 +3986,7 @@ replace_locals_stmt (gimple_stmt_iterator *gsip,
/* This will remap a lot of the same decls again, but this should be
harmless. */
if (gimple_bind_vars (stmt))
- gimple_bind_set_vars (stmt, remap_decls (gimple_bind_vars (stmt), id));
+ gimple_bind_set_vars (stmt, remap_decls (gimple_bind_vars (stmt), NULL, id));
}
/* Keep iterating. */
@@ -4140,7 +4221,7 @@ copy_arguments_for_versioning (tree orig_parm, copy_body_data * id,
*parg = new_tree;
parg = &TREE_CHAIN (new_tree);
}
- else
+ else if (!pointer_map_contains (id->decl_map, arg))
{
/* Make an equivalent VAR_DECL. If the argument was used
as temporary variable later in function, the uses will be
@@ -4188,6 +4269,29 @@ tree_versionable_function_p (tree fndecl)
return true;
}
+/* Create a new name for omp child function. Returns an identifier. */
+
+static GTY(()) unsigned int clone_fn_id_num;
+
+static tree
+clone_function_name (tree decl)
+{
+ tree name = DECL_ASSEMBLER_NAME (decl);
+ size_t len = IDENTIFIER_LENGTH (name);
+ char *tmp_name, *prefix;
+
+ prefix = XALLOCAVEC (char, len + strlen ("_clone") + 1);
+ memcpy (prefix, IDENTIFIER_POINTER (name), len);
+ strcpy (prefix + len, "_clone");
+#ifndef NO_DOT_IN_LABEL
+ prefix[len] = '.';
+#elif !defined NO_DOLLAR_IN_LABEL
+ prefix[len] = '$';
+#endif
+ ASM_FORMAT_PRIVATE_NAME (tmp_name, prefix, clone_fn_id_num++);
+ return get_identifier (tmp_name);
+}
+
/* Create a copy of a function's tree.
OLD_DECL and NEW_DECL are FUNCTION_DECL tree nodes
of the original function and the new copied function
@@ -4220,6 +4324,12 @@ tree_function_versioning (tree old_decl, tree new_decl, varray_type tree_map,
old_version_node = cgraph_node (old_decl);
new_version_node = cgraph_node (new_decl);
+ /* Output the inlining info for this abstract function, since it has been
+ inlined. If we don't do this now, we can lose the information about the
+ variables in the function when the blocks get blown away as soon as we
+ remove the cgraph node. */
+ (*debug_hooks->outlining_inline_function) (old_decl);
+
DECL_ARTIFICIAL (new_decl) = 1;
DECL_ABSTRACT_ORIGIN (new_decl) = DECL_ORIGIN (old_decl);
@@ -4229,7 +4339,7 @@ tree_function_versioning (tree old_decl, tree new_decl, varray_type tree_map,
/* Generate a new name for the new version. */
if (!update_clones)
{
- DECL_NAME (new_decl) = create_tmp_var_name (NULL);
+ DECL_NAME (new_decl) = clone_function_name (old_decl);
SET_DECL_ASSEMBLER_NAME (new_decl, DECL_NAME (new_decl));
SET_DECL_RTL (new_decl, NULL_RTX);
id.statements_to_fold = pointer_set_create ();
@@ -4263,16 +4373,6 @@ tree_function_versioning (tree old_decl, tree new_decl, varray_type tree_map,
DECL_STRUCT_FUNCTION (new_decl)->static_chain_decl =
copy_static_chain (DECL_STRUCT_FUNCTION (old_decl)->static_chain_decl,
&id);
- /* Copy the function's arguments. */
- if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
- DECL_ARGUMENTS (new_decl) =
- copy_arguments_for_versioning (DECL_ARGUMENTS (old_decl), &id,
- args_to_skip, &vars);
-
- DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
-
- /* Renumber the lexical scoping (non-code) blocks consecutively. */
- number_blocks (id.dst_fn);
/* If there's a tree_map, prepare for substitution. */
if (tree_map)
@@ -4307,6 +4407,16 @@ tree_function_versioning (tree old_decl, tree new_decl, varray_type tree_map,
VEC_safe_push (gimple, heap, init_stmts, init);
}
}
+ /* Copy the function's arguments. */
+ if (DECL_ARGUMENTS (old_decl) != NULL_TREE)
+ DECL_ARGUMENTS (new_decl) =
+ copy_arguments_for_versioning (DECL_ARGUMENTS (old_decl), &id,
+ args_to_skip, &vars);
+
+ DECL_INITIAL (new_decl) = remap_blocks (DECL_INITIAL (id.src_fn), &id);
+
+ /* Renumber the lexical scoping (non-code) blocks consecutively. */
+ number_blocks (id.dst_fn);
declare_inline_vars (DECL_INITIAL (new_decl), vars);
if (DECL_STRUCT_FUNCTION (old_decl)->local_decls != NULL_TREE)
@@ -4317,7 +4427,7 @@ tree_function_versioning (tree old_decl, tree new_decl, varray_type tree_map,
tree var = TREE_VALUE (t_step);
if (TREE_STATIC (var) && !TREE_ASM_WRITTEN (var))
cfun->local_decls = tree_cons (NULL_TREE, var, cfun->local_decls);
- else
+ else if (!can_be_nonlocal (var, &id))
cfun->local_decls =
tree_cons (NULL_TREE, remap_decl (var, &id),
cfun->local_decls);
@@ -4434,3 +4544,5 @@ tree_can_inline_p (tree caller, tree callee)
/* Allow the backend to decide if inlining is ok. */
return targetm.target_option.can_inline_p (caller, callee);
}
+
+#include "gt-tree-inline.h"