> Am 28.07.2024 um 06:41 schrieb Andrew Pinski <quic_apin...@quicinc.com>:
> 
> While doing some other cleanups with the properties I noticed that 
> debug_properties
> was not updated for some of the new properties. So instead of just updating 
> the function,
> this moves the properties over to its own .def file so we don't need to 
> update this nor will
> have a conflict in the bit ordering either.
> 
> For now I just used an `enum class` for the enum that holds the bit number of 
> each property.
> Later on this might be changed to a normal enum and only use that instead. 
> But that won't be
> until we require C++17 since `folding expressions` make this code much 
> simplier.
> 
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Ok for both.  Can you check the internals manual if there’s any updates needed?

Thanks,
Richard 

> gcc/ChangeLog:
> 
>    PR middle-end/116118
>    * function.h (PROP_bitnum): New enum class.
>    (function_prop_type): New typedef.
>    (PROP_gimple_any): Remove.
>    (PROP_gimple_lcf): Remove.
>    (PROP_gimple_leh): Remove.
>    (PROP_cfg): Remove.
>    (PROP_objsz): Remove.
>    (PROP_ssa): Remove.
>    (PROP_rtl): Remove.
>    (PROP_gimple_lomp): Remove.
>    (PROP_cfglayout): Remove.
>    (PROP_gimple_lcx): Remove.
>    (PROP_loops): Remove.
>    (PROP_gimple_lvec): Remove.
>    (PROP_gimple_eomp): Remove.
>    (PROP_gimple_lva): Remove.
>    (PROP_gimple_opt_math): Remove.
>    (PROP_gimple_lomp_dev): Remove.
>    (PROP_rtl_split_insns): Remove.
>    (PROP_loop_opts_done): Remove.
>    (PROP_assumptions_done): Remove.
>    (PROP_gimple_lbitint): Remove.
>    (enum PROP_bit): New.
>    (struct function): Use function_prop_type instead of `unsigned int`
>    for the properties.
>    * passes.cc (debug_properties): Update to use function_prop_type.
>    (dump_properties): Likewise. Also don't directly print the properties,
>    use an array.
>    * ir-prop.def: New file.
> 
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
> gcc/function.h  | 47 ++++++++++++++++++++---------------------------
> gcc/ir-prop.def | 45 +++++++++++++++++++++++++++++++++++++++++++++
> gcc/passes.cc   | 45 +++++++++++++++++++--------------------------
> 3 files changed, 84 insertions(+), 53 deletions(-)
> create mode 100644 gcc/ir-prop.def
> 
> diff --git a/gcc/function.h b/gcc/function.h
> index f0f48648504..9a678741f6c 100644
> --- a/gcc/function.h
> +++ b/gcc/function.h
> @@ -243,34 +243,27 @@ public:
>   (current_function_dynamic_stack_size != 0               \
>    || current_function_has_unbounded_dynamic_stack_size)
> 
> +/* Pass properties set on function::curr_properties.  */
> +enum class PROP_bitnum
> +{
> +#define PROP(a) PROP_BIT_##a ,
> +#include "ir-prop.def"
> +PROP_BIT_end
> +};
> +
> +typedef unsigned int function_prop_type;
> +/* Make sure current_properties has enough bits for the properties. */
> +static_assert ((size_t)PROP_bitnum::PROP_BIT_end
> +        <= (sizeof(function_prop_type) * CHAR_BIT),
> +           "too many properties for prop type");
> 
> /* Pass properties set on function::curr_properties.  */
> -#define PROP_gimple_any        (1 << 0)    /* entire gimple grammar */
> -#define PROP_gimple_lcf        (1 << 1)    /* lowered control flow */
> -#define PROP_gimple_leh        (1 << 2)    /* lowered eh */
> -#define PROP_cfg        (1 << 3)
> -#define PROP_objsz        (1 << 4)    /* object sizes computed */
> -#define PROP_ssa        (1 << 5)
> -/* UNUSED            (1 << 6) */
> -#define PROP_rtl        (1 << 7)
> -#define PROP_gimple_lomp    (1 << 8)    /* lowered OpenMP directives */
> -#define PROP_cfglayout        (1 << 9)    /* cfglayout mode on RTL */
> -#define PROP_gimple_lcx        (1 << 10)       /* lowered complex */
> -#define PROP_loops        (1 << 11)    /* preserve loop structures */
> -#define PROP_gimple_lvec    (1 << 12)       /* lowered vector */
> -#define PROP_gimple_eomp    (1 << 13)       /* no OpenMP directives */
> -#define PROP_gimple_lva        (1 << 14)       /* No va_arg internal 
> function.  */
> -#define PROP_gimple_opt_math    (1 << 15)    /* Disable canonicalization
> -                           of math functions; the
> -                           current choices have
> -                           been optimized.  */
> -#define PROP_gimple_lomp_dev    (1 << 16)    /* done omp_device_lower */
> -#define PROP_rtl_split_insns    (1 << 17)    /* RTL has insns split.  */
> -#define PROP_loop_opts_done    (1 << 18)    /* SSA loop optimizations
> -                           have completed.  */
> -#define PROP_assumptions_done    (1 << 19)    /* Assume function kept
> -                           around.  */
> -#define PROP_gimple_lbitint    (1 << 20)       /* lowered large _BitInt */
> +enum PROP_bit : function_prop_type
> +{
> +#define PROP(a) PROP_##a = \
> +    ((function_prop_type)1) << (function_prop_type)PROP_bitnum::PROP_BIT_##a,
> +#include "ir-prop.def"
> +};
> 
> #define PROP_gimple \
>   (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
> @@ -364,7 +357,7 @@ struct GTY(()) function {
>   location_t function_end_locus;
> 
>   /* Properties used by the pass manager.  */
> -  unsigned int curr_properties;
> +  function_prop_type curr_properties;
>   unsigned int last_verified;
> 
>   /* Different from normal TODO_flags which are handled right at the
> diff --git a/gcc/ir-prop.def b/gcc/ir-prop.def
> new file mode 100644
> index 00000000000..7ec6d135a4e
> --- /dev/null
> +++ b/gcc/ir-prop.def
> @@ -0,0 +1,45 @@
> +/* Pass properties set on function::curr_properties.
> +   Copyright (C) 1989-2024 Free Software Foundation, Inc.
> +   Copyright The GNU Toolchain Authors.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* PROP (name) defines the property that can be set on
> +   function::curr_properties. */
> +PROP (gimple_any)    /* entire gimple grammar */
> +PROP (gimple_lcf)    /* lowered control flow */
> +PROP (gimple_leh)    /* lowered eh */
> +PROP (cfg)
> +PROP (objsz)        /* object sizes computed */
> +PROP (ssa)
> +PROP (rtl)
> +PROP (gimple_lomp)    /* lowered OpenMP directives */
> +PROP (cfglayout)    /* cfglayout mode on RTL */
> +PROP (gimple_lcx)    /* lowered complex */
> +PROP (loops)        /* preserve loop structures */
> +PROP (gimple_lvec)    /* lowered vector */
> +PROP (gimple_eomp)    /* no OpenMP directives */
> +PROP (gimple_lva)    /* No va_arg internal function.  */
> +PROP (gimple_opt_math)    /* Disable canonicalization of math functions; the
> +               current choices have been optimized.  */
> +PROP (gimple_lomp_dev)    /* done omp_device_lower */
> +PROP (rtl_split_insns)    /* RTL has insns split.  */
> +PROP (loop_opts_done)    /* SSA loop optimizations have completed.  */
> +PROP (assumptions_done)    /* Assume function kept  around.  */
> +PROP (gimple_lbitint)    /* lowered large _BitInt */
> +
> +#undef PROP
> diff --git a/gcc/passes.cc b/gcc/passes.cc
> index c494c76808b..1cfc505a24f 100644
> --- a/gcc/passes.cc
> +++ b/gcc/passes.cc
> @@ -3161,39 +3161,32 @@ execute_all_ipa_stmt_fixups (struct cgraph_node 
> *node, gimple **stmts)
> }
> 
> 
> -extern void debug_properties (unsigned int);
> -extern void dump_properties (FILE *, unsigned int);
> +extern void debug_properties (function_prop_type);
> +extern void dump_properties (FILE *, function_prop_type);
> 
> DEBUG_FUNCTION void
> -dump_properties (FILE *dump, unsigned int props)
> +dump_properties (FILE *dump, function_prop_type props)
> {
>   fprintf (dump, "Properties:\n");
> -  if (props & PROP_gimple_any)
> -    fprintf (dump, "PROP_gimple_any\n");
> -  if (props & PROP_gimple_lcf)
> -    fprintf (dump, "PROP_gimple_lcf\n");
> -  if (props & PROP_gimple_leh)
> -    fprintf (dump, "PROP_gimple_leh\n");
> -  if (props & PROP_cfg)
> -    fprintf (dump, "PROP_cfg\n");
> -  if (props & PROP_ssa)
> -    fprintf (dump, "PROP_ssa\n");
> -  if (props & PROP_rtl)
> -    fprintf (dump, "PROP_rtl\n");
> -  if (props & PROP_gimple_lomp)
> -    fprintf (dump, "PROP_gimple_lomp\n");
> -  if (props & PROP_gimple_lomp_dev)
> -    fprintf (dump, "PROP_gimple_lomp_dev\n");
> -  if (props & PROP_gimple_lcx)
> -    fprintf (dump, "PROP_gimple_lcx\n");
> -  if (props & PROP_gimple_lvec)
> -    fprintf (dump, "PROP_gimple_lvec\n");
> -  if (props & PROP_cfglayout)
> -    fprintf (dump, "PROP_cfglayout\n");
> +  static const char *prop_name[] = {
> +#define PROP(a) "PROP_" #a ,
> +#include "ir-prop.def"
> +  };
> +  for (unsigned i = 0; i < (sizeof(function_prop_type) * CHAR_BIT); i++)
> +    {
> +      if ((props & (((function_prop_type)1) << i)) == 0)
> +    continue;
> +      if (i >= ARRAY_SIZE (prop_name))
> +    {
> +      fprintf(dump, "unkown_prop: %d\n", i);
> +      continue;
> +    }
> +      fprintf(dump, "%s\n", prop_name[i]);
> +    }
> }
> 
> DEBUG_FUNCTION void
> -debug_properties (unsigned int props)
> +debug_properties (function_prop_type props)
> {
>   dump_properties (stderr, props);
> }
> --
> 2.43.0
> 

Reply via email to