The INSN_BASE_REG_CLASS macro is useful for getting full context on real insns,
but isn't very helpful for targets that have multiple address spaces and
therefore no single default when the insn context is not available.  This
patch allows multiple macros to exist simultaneously: INSN_BASE_REG_CLASS
is used as first preference, and another macro is selected when INSN is
null.

The only existing user of INSN_BASE_REG_CLASS (x86) returns BASE_REG_CLASS
when INSN is null, so this change should be safe.

Additionally, there were a few cases where base_reg_class was called without an
insn, even though it was known. These bypassed the preferred macro, so the
patch fixes them up.

gcc/ChangeLog:

        * addresses.h (base_reg_class): Don't call INSN_BASE_REG_CLASS with
        null insn.
        * doc/tm.texi: Document new INSN_BASE_REG_CLASS behaviour.
        * doc/tm.texi.in: Likewise.
        * regcprop.cc (replace_oldest_value_mem): Pass insn to base_reg_class.
        * regrename.cc (base_reg_class_for_rename): Likewise.
---

OK for mainline?

Andrew

 gcc/addresses.h    | 8 +++++---
 gcc/doc/tm.texi    | 4 ++--
 gcc/doc/tm.texi.in | 4 ++--
 gcc/regcprop.cc    | 2 +-
 gcc/regrename.cc   | 2 +-
 5 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/gcc/addresses.h b/gcc/addresses.h
index 6a9ffcd7cb3..6a316825f6d 100644
--- a/gcc/addresses.h
+++ b/gcc/addresses.h
@@ -32,8 +32,11 @@ base_reg_class (machine_mode mode ATTRIBUTE_UNUSED,
                rtx_insn *insn ATTRIBUTE_UNUSED = NULL)
 {
 #ifdef INSN_BASE_REG_CLASS
-  return INSN_BASE_REG_CLASS (insn);
-#else
+  if (insn)
+    return INSN_BASE_REG_CLASS (insn);
+  /* Else fall back to another macro, if available.  */
+#endif
+
 #ifdef MODE_CODE_BASE_REG_CLASS
   return MODE_CODE_BASE_REG_CLASS (MACRO_MODE (mode), as, outer_code,
                                   index_code);
@@ -48,7 +51,6 @@ base_reg_class (machine_mode mode ATTRIBUTE_UNUSED,
   return BASE_REG_CLASS;
 #endif
 #endif
-#endif
 }
 
 inline enum reg_class
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index d62f2932473..8b8e141a41b 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -2596,8 +2596,8 @@ A C expression whose value is the register class to which 
a valid
 base register for a specified @var{insn} must belong. This macro is
 used when some backend insns may have limited usage of base register
 compared with other insns. If you define this macro, the compiler will
-use it instead of all other defined macros that relate to
-BASE_REG_CLASS.
+use it when an insn is known, and otherwise fall back to one of the other
+defined macros that relate to @code{BASE_REG_CLASS}.
 @end defmac
 
 @defmac INDEX_REG_CLASS
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 2aa58133d66..54c8ae9fd2a 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -2181,8 +2181,8 @@ A C expression whose value is the register class to which 
a valid
 base register for a specified @var{insn} must belong. This macro is
 used when some backend insns may have limited usage of base register
 compared with other insns. If you define this macro, the compiler will
-use it instead of all other defined macros that relate to
-BASE_REG_CLASS.
+use it when an insn is known, and otherwise fall back to one of the other
+defined macros that relate to @code{BASE_REG_CLASS}.
 @end defmac
 
 @defmac INDEX_REG_CLASS
diff --git a/gcc/regcprop.cc b/gcc/regcprop.cc
index 2a9956353cc..bbc02688702 100644
--- a/gcc/regcprop.cc
+++ b/gcc/regcprop.cc
@@ -744,7 +744,7 @@ replace_oldest_value_mem (rtx x, rtx_insn *insn, struct 
value_data *vd)
   if (DEBUG_INSN_P (insn))
     cl = ALL_REGS;
   else
-    cl = base_reg_class (GET_MODE (x), MEM_ADDR_SPACE (x), MEM, SCRATCH);
+    cl = base_reg_class (GET_MODE (x), MEM_ADDR_SPACE (x), MEM, SCRATCH, insn);
 
   return replace_oldest_value_addr (&XEXP (x, 0), cl,
                                    GET_MODE (x), MEM_ADDR_SPACE (x),
diff --git a/gcc/regrename.cc b/gcc/regrename.cc
index 5b625cd27df..1d36b90bdc5 100644
--- a/gcc/regrename.cc
+++ b/gcc/regrename.cc
@@ -1308,7 +1308,7 @@ base_reg_class_for_rename (rtx_insn *insn, machine_mode 
mode, addr_space_t as,
 {
   if (DEBUG_INSN_P (insn))
     return ALL_REGS;
-  return base_reg_class (mode, as, code, index_code);
+  return base_reg_class (mode, as, code, index_code, insn);
 }
 
 /* Adapted from find_reloads_address_1.  CL is INDEX_REG_CLASS or
-- 
2.54.0

Reply via email to