This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [5/10] Add tree_to_shwi and tree_to_uhwi


On Sat, Nov 16, 2013 at 2:03 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> Add tree_to_shwi and tree_to_uhwi.  Initially tree_to_uhwi returns a
> HOST_WIDE_INT, so that it's a direct replacement for tree_low_cst.
> Patch 10 makes it return unsigned HOST_WIDE_INT instead.

Possibly same naming issue (though we already do have the weird
int_cst_value) - int_to_[us]hwi ()?

OTOH if somebody else is fine with using tree_ for the four functions
then call it a day.

Richard.

> Thanks,
> Richard
>
>
> gcc/
>         * tree.h (tree_to_shwi, tree_to_uhwi): Declare, with inline expansions.
>         * tree.c (tree_to_shwi, tree_to_uhwi): New functions.
>
> Index: gcc/tree.c
> ===================================================================
> --- gcc/tree.c  2013-11-15 16:46:27.420395607 +0000
> +++ gcc/tree.c  2013-11-15 16:47:15.226216885 +0000
> @@ -7027,6 +7027,28 @@ tree_low_cst (const_tree t, int pos)
>    return TREE_INT_CST_LOW (t);
>  }
>
> +/* T is an INTEGER_CST whose numerical value (extended according to
> +   TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT.  Return that
> +   HOST_WIDE_INT.  */
> +
> +HOST_WIDE_INT
> +tree_to_shwi (const_tree t)
> +{
> +  gcc_assert (tree_fits_shwi_p (t));
> +  return TREE_INT_CST_LOW (t);
> +}
> +
> +/* T is an INTEGER_CST whose numerical value (extended according to
> +   TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT.  Return that
> +   HOST_WIDE_INT.  */
> +
> +HOST_WIDE_INT
> +tree_to_uhwi (const_tree t)
> +{
> +  gcc_assert (tree_fits_uhwi_p (t));
> +  return TREE_INT_CST_LOW (t);
> +}
> +
>  /* Return the most significant (sign) bit of T.  */
>
>  int
> Index: gcc/tree.h
> ===================================================================
> --- gcc/tree.h  2013-11-15 16:46:26.263399881 +0000
> +++ gcc/tree.h  2013-11-15 16:46:56.569287095 +0000
> @@ -3662,6 +3662,8 @@ extern bool tree_fits_uhwi_p (const_tree
>  #endif
>    ;
>  extern HOST_WIDE_INT tree_low_cst (const_tree, int);
> +extern HOST_WIDE_INT tree_to_shwi (const_tree);
> +extern HOST_WIDE_INT tree_to_uhwi (const_tree);
>  #if !defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 4003)
>  extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT
>  tree_low_cst (const_tree t, int pos)
> @@ -3669,6 +3671,20 @@ tree_low_cst (const_tree t, int pos)
>    gcc_assert (host_integerp (t, pos));
>    return TREE_INT_CST_LOW (t);
>  }
> +
> +extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT
> +tree_to_shwi (const_tree t)
> +{
> +  gcc_assert (tree_fits_shwi_p (t));
> +  return TREE_INT_CST_LOW (t);
> +}
> +
> +extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT
> +tree_to_uhwi (const_tree t)
> +{
> +  gcc_assert (tree_fits_uhwi_p (t));
> +  return TREE_INT_CST_LOW (t);
> +}
>  #endif
>  extern int tree_int_cst_sgn (const_tree);
>  extern int tree_int_cst_sign_bit (const_tree);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]