This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, gimple] Add create_tmp_reg helper function
- From: Richard Guenther <rguenther at suse dot de>
- To: Martin Jambor <mjambor at suse dot cz>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 16 Apr 2010 17:29:54 +0200 (CEST)
- Subject: Re: [PATCH, gimple] Add create_tmp_reg helper function
- References: <20100416151428.GA4366@virgil.suse.cz>
On Fri, 16 Apr 2010, Martin Jambor wrote:
> Hi,
>
> as discussed in an earlier thread
> (http://gcc.gnu.org/ml/gcc/2010-04/msg00325.html), this patch adds a
> new helper to avoid having stuff like the following all over gcc.
>
> tmp = create_tmp_var (TREE_TYPE (adj->base), "blah");
> if (TREE_CODE (TREE_TYPE (tmp)) == COMPLEX_TYPE
> || TREE_CODE (TREE_TYPE (tmp)) == VECTOR_TYPE)
> DECL_GIMPLE_REG_P (tmp) = 1;
>
> I have briefly glanced at all callers of create_tmp_var and changed
> those which clearly exhibited this pattern. I hope I haven't missed
> any but it is certainly possible. The PRE hunks are perhaps the only
> slightly non-obvious ones but I believe got those right too.
>
> I briefly experimented with setting DECL_GIMPLE_REG_P unconditionally
> after asserting gimple_reg_type (type) but that has failed bootstrap
> (because at least of a call in gimplify_return_expr). I have then
> quickly abandoned this path because I don't think it was that
> important.
>
> Bootstrapped and regression tested on x86_64-linux without any
> problems. OK for trunk?
>
> Thanks,
>
> Martin
>
>
> 2010-04-16 Martin Jambor <mjambor@suse.cz>
>
> * gimple.h (create_tmp_reg): Declare.
> * gimplify.c (create_tmp_reg): New function.
> (gimplify_return_expr): Use create_tmp_reg.
> (gimplify_omp_atomic): Likewise.
> (gimple_regimplify_operands): Likewise.
> * tree-dfa.c (make_rename_temp): Likewise.
> * tree-predcom.c (predcom_tmp_var): Likewise.
> (reassociate_to_the_same_stmt): Likewise.
> * tree-sra.c (replace_uses_with_default_def_ssa_name): Likewise.
> (get_replaced_param_substitute): Likewise.
> * tree-ssa-phiprop.c (phiprop_insert_phi): Likewise.
> * tree-ssa-phiopt.c (cond_store_replacement): Likewise.
> * tree-ssa-pre.c (get_representative_for): Likewise.
> (create_expression_by_pieces): Likewise.
> * tree-tailcall.c (adjust_return_value_with_ops): Likewise.
> (create_tailcall_accumulator): Likewise.
>
>
> Index: mine/gcc/gimple.h
> ===================================================================
> --- mine.orig/gcc/gimple.h
> +++ mine/gcc/gimple.h
> @@ -942,6 +942,7 @@ extern bool gimple_ior_addresses_taken (
> extern tree create_tmp_var_raw (tree, const char *);
> extern tree create_tmp_var_name (const char *);
> extern tree create_tmp_var (tree, const char *);
> +extern tree create_tmp_reg (tree, const char *);
> extern tree get_initialized_tmp_var (tree, gimple_seq *, gimple_seq *);
> extern tree get_formal_tmp_var (tree, gimple_seq *);
> extern void declare_vars (tree, gimple, bool);
> Index: mine/gcc/gimplify.c
> ===================================================================
> --- mine.orig/gcc/gimplify.c
> +++ mine/gcc/gimplify.c
> @@ -508,6 +508,22 @@ create_tmp_var (tree type, const char *p
> return tmp_var;
> }
>
> +/* Create a new temporary variable declaration of type TYPE by calling
> + create_tmp_var and if TYPE is a vector or a complex number, mark the new
> + temporary as gimple register. */
> +
> +tree create_tmp_reg (tree type, const char *prefix)
newline after tree
> +{
> + tree tmp;
> +
> + tmp = create_tmp_var (type, prefix);
> + if (TREE_CODE (type) == COMPLEX_TYPE
> + || TREE_CODE (type) == VECTOR_TYPE)
> + DECL_GIMPLE_REG_P (tmp) = 1;
> +
> + return tmp;
> +}
> +
> /* Create a temporary with a name derived from VAL. Subroutine of
> lookup_tmp_var; nobody else should call this function. */
>
> @@ -1219,10 +1235,7 @@ gimplify_return_expr (tree stmt, gimple_
> result = gimplify_ctxp->return_temp;
> else
> {
> - result = create_tmp_var (TREE_TYPE (result_decl), NULL);
> - if (TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (result) = 1;
> + result = create_tmp_reg (TREE_TYPE (result_decl), NULL);
>
> /* ??? With complex control flow (usually involving abnormal edges),
> we can wind up warning about an uninitialized value for this. Due
> @@ -6351,7 +6364,7 @@ gimplify_omp_atomic (tree *expr_p, gimpl
> tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr)));
> tree tmp_load;
>
> - tmp_load = create_tmp_var (type, NULL);
> + tmp_load = create_tmp_reg (type, NULL);
> if (TREE_CODE (type) == COMPLEX_TYPE || TREE_CODE (type) == VECTOR_TYPE)
> DECL_GIMPLE_REG_P (tmp_load) = 1;
delete the DECL_GIMPLE_REG_P setting
Otherwise ok.
Thanks,
Richard.
> if (goa_stabilize_expr (&rhs, pre_p, addr, tmp_load) < 0)
> @@ -7828,11 +7841,8 @@ gimple_regimplify_operands (gimple stmt,
> }
> if (need_temp)
> {
> - tree temp = create_tmp_var (TREE_TYPE (lhs), NULL);
> + tree temp = create_tmp_reg (TREE_TYPE (lhs), NULL);
>
> - if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (temp) = 1;
> if (TREE_CODE (orig_lhs) == SSA_NAME)
> orig_lhs = SSA_NAME_VAR (orig_lhs);
>
> Index: mine/gcc/tree-dfa.c
> ===================================================================
> --- mine.orig/gcc/tree-dfa.c
> +++ mine/gcc/tree-dfa.c
> @@ -193,11 +193,7 @@ renumber_gimple_stmt_uids_in_blocks (bas
> tree
> make_rename_temp (tree type, const char *prefix)
> {
> - tree t = create_tmp_var (type, prefix);
> -
> - if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (t) = 1;
> + tree t = create_tmp_reg (type, prefix);
>
> if (gimple_referenced_vars (cfun))
> {
> Index: mine/gcc/tree-predcom.c
> ===================================================================
> --- mine.orig/gcc/tree-predcom.c
> +++ mine/gcc/tree-predcom.c
> @@ -1460,13 +1460,9 @@ static tree
> predcom_tmp_var (tree ref, unsigned i, bitmap tmp_vars)
> {
> tree type = TREE_TYPE (ref);
> - tree var = create_tmp_var (type, get_lsm_tmp_name (ref, i));
> -
> /* We never access the components of the temporary variable in predictive
> commoning. */
> - if (TREE_CODE (type) == COMPLEX_TYPE
> - || TREE_CODE (type) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (var) = 1;
> + tree var = create_tmp_reg (type, get_lsm_tmp_name (ref, i));
>
> add_referenced_var (var);
> bitmap_set_bit (tmp_vars, DECL_UID (var));
> @@ -2209,18 +2205,12 @@ reassociate_to_the_same_stmt (tree name1
>
> /* Insert the new statement combining NAME1 and NAME2 before S1, and
> combine it with the rhs of S1. */
> - var = create_tmp_var (type, "predreastmp");
> - if (TREE_CODE (type) == COMPLEX_TYPE
> - || TREE_CODE (type) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (var) = 1;
> + var = create_tmp_reg (type, "predreastmp");
> add_referenced_var (var);
> new_name = make_ssa_name (var, NULL);
> new_stmt = gimple_build_assign_with_ops (code, new_name, name1, name2);
>
> - var = create_tmp_var (type, "predreastmp");
> - if (TREE_CODE (type) == COMPLEX_TYPE
> - || TREE_CODE (type) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (var) = 1;
> + var = create_tmp_reg (type, "predreastmp");
> add_referenced_var (var);
> tmp_name = make_ssa_name (var, NULL);
>
> Index: mine/gcc/tree-sra.c
> ===================================================================
> --- mine.orig/gcc/tree-sra.c
> +++ mine/gcc/tree-sra.c
> @@ -2537,10 +2537,7 @@ replace_uses_with_default_def_ssa_name (
> tree repl, decl = SSA_NAME_VAR (ssa);
> if (TREE_CODE (decl) == PARM_DECL)
> {
> - tree tmp = create_tmp_var (TREE_TYPE (decl), "SR");
> - if (TREE_CODE (TREE_TYPE (tmp)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (tmp)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (tmp) = 1;
> + tree tmp = create_tmp_reg (TREE_TYPE (decl), "SR");
>
> get_var_ann (tmp);
> add_referenced_var (tmp);
> @@ -3733,10 +3730,7 @@ get_replaced_param_substitute (struct ip
> {
> char *pretty_name = make_fancy_name (adj->base);
>
> - repl = create_tmp_var (TREE_TYPE (adj->base), "ISR");
> - if (TREE_CODE (TREE_TYPE (repl)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (repl)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (repl) = 1;
> + repl = create_tmp_reg (TREE_TYPE (adj->base), "ISR");
> DECL_NAME (repl) = get_identifier (pretty_name);
> obstack_free (&name_obstack, pretty_name);
>
> Index: mine/gcc/tree-ssa-phiopt.c
> ===================================================================
> --- mine.orig/gcc/tree-ssa-phiopt.c
> +++ mine/gcc/tree-ssa-phiopt.c
> @@ -1226,11 +1226,8 @@ cond_store_replacement (basic_block midd
> of the memory touched by the store, if we need to. */
> if (!condstoretemp || TREE_TYPE (lhs) != TREE_TYPE (condstoretemp))
> {
> - condstoretemp = create_tmp_var (TREE_TYPE (lhs), "cstore");
> + condstoretemp = create_tmp_reg (TREE_TYPE (lhs), "cstore");
> get_var_ann (condstoretemp);
> - if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (condstoretemp) = 1;
> }
> add_referenced_var (condstoretemp);
>
> Index: mine/gcc/tree-ssa-phiprop.c
> ===================================================================
> --- mine.orig/gcc/tree-ssa-phiprop.c
> +++ mine/gcc/tree-ssa-phiprop.c
> @@ -190,11 +190,8 @@ phiprop_insert_phi (basic_block bb, gimp
> {
> gcc_assert (TREE_CODE (old_arg) == ADDR_EXPR);
> old_arg = TREE_OPERAND (old_arg, 0);
> - new_var = create_tmp_var (TREE_TYPE (old_arg), NULL);
> + new_var = create_tmp_reg (TREE_TYPE (old_arg), NULL);
> tmp = gimple_build_assign (new_var, unshare_expr (old_arg));
> - if (TREE_CODE (TREE_TYPE (old_arg)) == COMPLEX_TYPE
> - || TREE_CODE (TREE_TYPE (old_arg)) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (new_var) = 1;
> gcc_assert (is_gimple_reg (new_var));
> add_referenced_var (new_var);
> new_var = make_ssa_name (new_var, tmp);
> Index: mine/gcc/tree-ssa-pre.c
> ===================================================================
> --- mine.orig/gcc/tree-ssa-pre.c
> +++ mine/gcc/tree-ssa-pre.c
> @@ -1407,7 +1407,7 @@ get_representative_for (const pre_expr e
> that we will return. */
> if (!pretemp || exprtype != TREE_TYPE (pretemp))
> {
> - pretemp = create_tmp_var (exprtype, "pretmp");
> + pretemp = create_tmp_reg (exprtype, "pretmp");
> get_var_ann (pretemp);
> }
>
> @@ -3073,17 +3073,13 @@ create_expression_by_pieces (basic_block
> that we will return. */
> if (!pretemp || exprtype != TREE_TYPE (pretemp))
> {
> - pretemp = create_tmp_var (exprtype, "pretmp");
> + pretemp = create_tmp_reg (exprtype, "pretmp");
> get_var_ann (pretemp);
> }
>
> temp = pretemp;
> add_referenced_var (temp);
>
> - if (TREE_CODE (exprtype) == COMPLEX_TYPE
> - || TREE_CODE (exprtype) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (temp) = 1;
> -
> newstmt = gimple_build_assign (temp, folded);
> name = make_ssa_name (temp, newstmt);
> gimple_assign_set_lhs (newstmt, name);
> Index: mine/gcc/tree-tailcall.c
> ===================================================================
> --- mine.orig/gcc/tree-tailcall.c
> +++ mine/gcc/tree-tailcall.c
> @@ -574,13 +574,10 @@ adjust_return_value_with_ops (enum tree_
> {
>
> tree ret_type = TREE_TYPE (DECL_RESULT (current_function_decl));
> - tree tmp = create_tmp_var (ret_type, label);
> + tree tmp = create_tmp_reg (ret_type, label);
> gimple stmt;
> tree result;
>
> - if (TREE_CODE (ret_type) == COMPLEX_TYPE
> - || TREE_CODE (ret_type) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (tmp) = 1;
> add_referenced_var (tmp);
>
> if (types_compatible_p (TREE_TYPE (acc), TREE_TYPE (op1)))
> @@ -907,12 +904,9 @@ static tree
> create_tailcall_accumulator (const char *label, basic_block bb, tree init)
> {
> tree ret_type = TREE_TYPE (DECL_RESULT (current_function_decl));
> - tree tmp = create_tmp_var (ret_type, label);
> + tree tmp = create_tmp_reg (ret_type, label);
> gimple phi;
>
> - if (TREE_CODE (ret_type) == COMPLEX_TYPE
> - || TREE_CODE (ret_type) == VECTOR_TYPE)
> - DECL_GIMPLE_REG_P (tmp) = 1;
> add_referenced_var (tmp);
> phi = create_phi_node (tmp, bb);
> /* RET_TYPE can be a float when -ffast-maths is enabled. */
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex