[2/5] Add function tree_code_in_cst.

Message ID 2f168b86-8c73-11b4-a172-ee14e715d097@theobroma-systems.com
State New
Headers show
Series
  • ipa-initcall-cp
Related show

Commit Message

Erick Ochoa May 29, 2020, 5:31 p.m.
---
  gcc/tree.h | 11 +++++++++++
  1 file changed, 11 insertions(+)

-- 
2.18.1

Comments

Jan Hubicka May 29, 2020, 9:03 p.m. | #1
> 

> ---

>  gcc/tree.h | 11 +++++++++++

>  1 file changed, 11 insertions(+)

> 

> diff --git a/gcc/tree.h b/gcc/tree.h

> index bd0c51b2a18..86a4542f58b 100644

> --- a/gcc/tree.h

> +++ b/gcc/tree.h

> @@ -6156,6 +6156,17 @@ int_bit_position (const_tree field)

>  	  + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();

>  }

> 

> +/* Determine if tree code is a constant */

> +inline bool

> +tree_code_is_cst (tree op)

> +{

> +  int code = TREE_CODE (op);

> +  if (code == INTEGER_CST || code == REAL_CST || code == COMPLEX_CST

> +      || code == VECTOR_CST)

> +    return true;

> +  return false;


We have is_gimple_ip_invariant which I think should suit your purpose -
it return true if tree is a constant, it also accepts things like
addresses of (global) variables, functions and labels.
> +}

> +

>  /* Return true if it makes sense to consider alias set for a type T.  */

> 

>  inline bool

> -- 

> 2.18.1

>
Kees Cook via Gcc-patches June 2, 2020, 12:29 p.m. | #2
On Sat, May 30, 2020 at 12:18 AM Jan Hubicka <hubicka@ucw.cz> wrote:
>

> >

> > ---

> >  gcc/tree.h | 11 +++++++++++

> >  1 file changed, 11 insertions(+)

> >

> > diff --git a/gcc/tree.h b/gcc/tree.h

> > index bd0c51b2a18..86a4542f58b 100644

> > --- a/gcc/tree.h

> > +++ b/gcc/tree.h

> > @@ -6156,6 +6156,17 @@ int_bit_position (const_tree field)

> >         + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();

> >  }

> >

> > +/* Determine if tree code is a constant */

> > +inline bool

> > +tree_code_is_cst (tree op)

> > +{

> > +  int code = TREE_CODE (op);

> > +  if (code == INTEGER_CST || code == REAL_CST || code == COMPLEX_CST

> > +      || code == VECTOR_CST)

> > +    return true;

> > +  return false;

>

> We have is_gimple_ip_invariant which I think should suit your purpose -

> it return true if tree is a constant, it also accepts things like

> addresses of (global) variables, functions and labels.


And otherwise there's CONSTANT_CLASS_P ().

Richard.

> > +}

> > +

> >  /* Return true if it makes sense to consider alias set for a type T.  */

> >

> >  inline bool

> > --

> > 2.18.1

> >
Erick Ochoa June 2, 2020, 12:30 p.m. | #3
On 02/06/2020 14:29, Richard Biener wrote:
> On Sat, May 30, 2020 at 12:18 AM Jan Hubicka <hubicka@ucw.cz> wrote:

>>

>>>

>>> ---

>>>   gcc/tree.h | 11 +++++++++++

>>>   1 file changed, 11 insertions(+)

>>>

>>> diff --git a/gcc/tree.h b/gcc/tree.h

>>> index bd0c51b2a18..86a4542f58b 100644

>>> --- a/gcc/tree.h

>>> +++ b/gcc/tree.h

>>> @@ -6156,6 +6156,17 @@ int_bit_position (const_tree field)

>>>          + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();

>>>   }

>>>

>>> +/* Determine if tree code is a constant */

>>> +inline bool

>>> +tree_code_is_cst (tree op)

>>> +{

>>> +  int code = TREE_CODE (op);

>>> +  if (code == INTEGER_CST || code == REAL_CST || code == COMPLEX_CST

>>> +      || code == VECTOR_CST)

>>> +    return true;

>>> +  return false;

>>

>> We have is_gimple_ip_invariant which I think should suit your purpose -

>> it return true if tree is a constant, it also accepts things like

>> addresses of (global) variables, functions and labels.

> 

> And otherwise there's CONSTANT_CLASS_P ().

> 

> Richard.


Thanks, I'll check these suggestions and remove unnecessary code!

> 

>>> +}

>>> +

>>>   /* Return true if it makes sense to consider alias set for a type T.  */

>>>

>>>   inline bool

>>> --

>>> 2.18.1

>>>

Patch

diff --git a/gcc/tree.h b/gcc/tree.h
index bd0c51b2a18..86a4542f58b 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -6156,6 +6156,17 @@  int_bit_position (const_tree field)
  	  + wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();
  }

+/* Determine if tree code is a constant */
+inline bool
+tree_code_is_cst (tree op)
+{
+  int code = TREE_CODE (op);
+  if (code == INTEGER_CST || code == REAL_CST || code == COMPLEX_CST
+      || code == VECTOR_CST)
+    return true;
+  return false;
+}
+
  /* Return true if it makes sense to consider alias set for a type T.  */

  inline bool