On Wed, 24 Jun 2026, Andrea Pinski wrote:

> On Wed, Jun 24, 2026 at 6:19 AM Richard Biener <[email protected]> wrote:
> >
> > The following changes the reassociation_width target hook to take
> > a tree_code after recognizing the x86 hook compares against rtx_code PLUS.
> > Like rtx_code we can now forward declare tree_code to achieve that.
> >
> > Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> >
> > OK if that succeeds?
> 
> Yes. Though note this is not an enum class though. It is just an enum
> with the underlying type specified. Enum class is a different thing;
> the named constants in an enum class are only part of the enum class
> scope rather than in the namespace scope of where the enum is defined.

I see.  The following is what I applied - I needed adjustments in two
places that do x ? tree_code : 0 which we otherwise diagnose.  Also
tm.texi regeneration was missing.

Richard.

[PATCH] Forward declare tree_code in coretypes.h

The following changes the reassociation_width target hook to take
a tree_code after recognizing the x86 hook compares against rtx_code PLUS.
Like rtx_code we can now forward declare tree_code to achieve that.

gcc/
        * coretypes.h (enum tree_code): Declare.
        * tree-core.h (enum tree_code): Adjust.
        * target.def (reassociation_width): Get a tree_code instead
        of unsigned int.
        * doc/tm.texi: Regenerate.
        * genmatch.cc (enum tree_code): Adjust.
        * gimple-loop-versioning.cc (address_info_hasher::hash): Likewise.
        * config/aarch64/aarch64.cc (aarch64_reassociation_width):
        Likewise.
        * config/loongarch/loongarch.cc
        (loongarch_cpu_sched_reassociation_width): Likewise.
        * config/mips/mips.cc (mips_sched_reassociation_width): Likewise.
        * config/rs6000/rs6000.cc (rs6000_reassociation_width): Likewise.
        * config/i386/i386.cc (ix86_reassociation_width): Likewise
        and fix bogus compares.

gcc/cp/
        * module.cc (trees_out::decl_value): Adjust for enum class
        tree_code.
---
 gcc/config/aarch64/aarch64.cc     | 2 +-
 gcc/config/i386/i386.cc           | 6 +++---
 gcc/config/loongarch/loongarch.cc | 5 +----
 gcc/config/mips/mips.cc           | 2 +-
 gcc/config/rs6000/rs6000.cc       | 2 +-
 gcc/coretypes.h                   | 3 +++
 gcc/cp/module.cc                  | 4 ++--
 gcc/doc/tm.texi                   | 2 +-
 gcc/genmatch.cc                   | 2 +-
 gcc/gimple-loop-versioning.cc     | 2 +-
 gcc/target.def                    | 2 +-
 gcc/tree-core.h                   | 2 +-
 12 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 9dd19d81d7b..8dc3c43c812 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -1528,7 +1528,7 @@ aarch64_min_divisions_for_recip_mul (machine_mode mode)
 
 /* Return the reassociation width of treeop OPC with mode MODE.  */
 static int
-aarch64_reassociation_width (unsigned opc, machine_mode mode)
+aarch64_reassociation_width (tree_code opc, machine_mode mode)
 {
   if (VECTOR_MODE_P (mode))
     return aarch64_tune_params.vec_reassoc_width;
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 33b4c13d0fa..e66958db7ac 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -25842,7 +25842,7 @@ ix86_enum_va_list (int idx, const char **pname, tree 
*ptree)
    is passed in MODE.  */
 
 static int
-ix86_reassociation_width (unsigned int op, machine_mode mode)
+ix86_reassociation_width (tree_code op, machine_mode mode)
 {
   int width = 1;
   /* Vector part.  */
@@ -25865,12 +25865,12 @@ ix86_reassociation_width (unsigned int op, 
machine_mode mode)
           || ix86_tune == PROCESSOR_C86_4G_M6
           || ix86_tune == PROCESSOR_C86_4G_M7
           || ix86_tune == PROCESSOR_C86_4G_M8)
-         && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
+         && INTEGRAL_MODE_P (mode) && op != PLUS_EXPR && op != MINUS_EXPR)
        return 1;
       /* Znver5 can do 2 integer multiplications per cycle with latency
         of 3.  */
       if ((ix86_tune == PROCESSOR_ZNVER5 || ix86_tune == PROCESSOR_ZNVER6)
-         && INTEGRAL_MODE_P (mode) && op != PLUS && op != MINUS)
+         && INTEGRAL_MODE_P (mode) && op != PLUS_EXPR && op != MINUS_EXPR)
        width = 6;
 
       /* Account for targets that splits wide vectors into multiple parts.  */
diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 131f7b3f57b..1192c85e0f1 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -9999,11 +9999,8 @@ loongarch_vectorize_vec_perm_const (machine_mode vmode, 
machine_mode op_mode,
 
 static int
 loongarch_cpu_sched_reassociation_width (struct loongarch_target *target,
-                                        unsigned int opc, machine_mode mode)
+                                        tree_code opc, machine_mode mode)
 {
-  /* unreferenced argument */
-  (void) opc;
-
   switch (target->cpu_tune)
     {
     case TUNE_GENERIC:
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 303766db522..277ec419826 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -22328,7 +22328,7 @@ mips_expand_msa_reduc (rtx (*fn) (rtx, rtx, rtx), rtx 
dest, rtx in)
 /* Implement TARGET_SCHED_REASSOCIATION_WIDTH.  */
 
 static int
-mips_sched_reassociation_width (unsigned int opc ATTRIBUTE_UNUSED,
+mips_sched_reassociation_width (tree_code opc ATTRIBUTE_UNUSED,
                                machine_mode mode)
 {
   if (MSA_SUPPORTED_MODE_P (mode))
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index afe5d45c125..86d06cfdaa6 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -10157,7 +10157,7 @@ rs6000_offsettable_memref_p (rtx op, machine_mode 
reg_mode, bool strict)
 */
 
 static int
-rs6000_reassociation_width (unsigned int opc ATTRIBUTE_UNUSED,
+rs6000_reassociation_width (tree_code opc ATTRIBUTE_UNUSED,
                             machine_mode mode)
 {
   switch (rs6000_tune)
diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 61f91cd2745..5cc602ed7e5 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -105,6 +105,9 @@ enum tree_index : unsigned;
 /* Forward declare rtx_code, so that we can use it in target hooks without
    needing to pull in rtl.h.  */
 enum rtx_code : unsigned;
+/* Forward declare tree_code, so that we can use it in target hooks without
+   needing to pull in tree-core.h.  */
+enum tree_code : unsigned;
 
 /* Forward decls for leaf gimple subclasses (for individual gimple codes).
    Keep this in the same order as the corresponding codes in gimple.def.  */
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 060d2ba344c..f250dc3e9df 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -8442,7 +8442,7 @@ trees_out::decl_value (tree decl, depset *dep)
                       && TYPE_NAME (type) == inner);
 
       if (streaming_p ())
-       u (has_type ? TREE_CODE (type) : 0);
+       u (has_type ? (unsigned) TREE_CODE (type) : 0);
 
       if (has_type)
        {
@@ -8459,7 +8459,7 @@ trees_out::decl_value (tree decl, depset *dep)
          stub_decl = TYPE_STUB_DECL (type);
          bool has_stub = inner != stub_decl;
          if (streaming_p ())
-           u (has_stub ? TREE_CODE (stub_decl) : 0);
+           u (has_stub ? (unsigned) TREE_CODE (stub_decl) : 0);
          if (has_stub)
            {
              stub_tag = insert (stub_decl);
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index e726745a8e1..94a5f265c14 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -7878,7 +7878,7 @@ the order of instructions is important for correctness 
when scheduling, but
 also the latencies of operations.
 @end deftypevr
 
-@deftypefn {Target Hook} int TARGET_SCHED_REASSOCIATION_WIDTH (unsigned int 
@var{opc}, machine_mode @var{mode})
+@deftypefn {Target Hook} int TARGET_SCHED_REASSOCIATION_WIDTH (tree_code 
@var{opc}, machine_mode @var{mode})
 This hook is called by tree reassociator to determine a level of
 parallelism required in output calculations chain.
 @end deftypefn
diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index 8ee7ae66e46..920cf27877d 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -999,7 +999,7 @@ choose_output (const vec<FILE *> &parts)
    definition files.  */
 
 #define DEFTREECODE(SYM, STRING, TYPE, NARGS)   SYM,
-enum tree_code {
+enum tree_code : unsigned {
 #include "tree.def"
 MAX_TREE_CODES
 };
diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc
index 71bf1b2f256..fa014f47b8e 100644
--- a/gcc/gimple-loop-versioning.cc
+++ b/gcc/gimple-loop-versioning.cc
@@ -449,7 +449,7 @@ hashval_t
 address_info_hasher::hash (const address_info *info)
 {
   inchash::hash hash;
-  hash.add_int (info->base ? TREE_CODE (info->base) : 0);
+  hash.add_int (info->base ? (unsigned) TREE_CODE (info->base) : 0);
   hash.add_int (info->terms.length ());
   for (unsigned int i = 0; i < info->terms.length (); ++i)
     {
diff --git a/gcc/target.def b/gcc/target.def
index 89788a26986..3f28768fdf0 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -1535,7 +1535,7 @@ DEFHOOK
 (reassociation_width,
 "This hook is called by tree reassociator to determine a level of\n\
 parallelism required in output calculations chain.",
-int, (unsigned int opc, machine_mode mode),
+int, (tree_code opc, machine_mode mode),
 hook_int_uint_mode_1)
 
 /* The following member value is a function that returns priority for
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 09c07c5c129..6992a5acf81 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -151,7 +151,7 @@ struct die_struct;
 #define DEFTREECODE(SYM, STRING, TYPE, NARGS)   SYM,
 #define END_OF_BASE_TREE_CODES LAST_AND_UNUSED_TREE_CODE,
 
-enum tree_code {
+enum tree_code : unsigned {
 #include "all-tree.def"
 MAX_TREE_CODES
 };
-- 
2.51.0

Reply via email to