]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aix: TLS precompute register parameters (PR 94177)
authorDavid Edelsohn <dje.gcc@gmail.com>
Sun, 11 Apr 2021 23:41:26 +0000 (19:41 -0400)
committerDavid Edelsohn <dje.gcc@gmail.com>
Tue, 27 Apr 2021 16:33:41 +0000 (12:33 -0400)
AIX uses a compiler-managed TOC for global data, including TLS symbols.
The GCC TOC implementation manages the TOC entries through the constant pool.

TLS symbols sometimes require a function call to obtain the TLS base
pointer.  The arguments to the TLS call can conflict with arguments to
a normal function call if the TLS symbol is an argument in the normal call.
GCC specifically checks for this situation and precomputes the TLS
arguments, but the mechanism to check for this requirement utilizes
legitimate_constant_p().  The necessary result of legitimate_constant_p()
for correct TOC behavior and for correct TLS argument behavior is in
conflict.

This patch adds a new target hook precompute_tls_p() to decide if an
argument should be precomputed regardless of the result from
legitmate_constant_p().

gcc/ChangeLog:

PR target/94177
* calls.c (precompute_register_parameters): Additionally test
targetm.precompute_tls_p to pre-compute argument.
* config/rs6000/aix.h (TARGET_PRECOMPUTE_TLS_P): Define.
* config/rs6000/rs6000.c (rs6000_aix_precompute_tls_p): New.
* target.def (precompute_tls_p): New.
* doc/tm.texi.in (TARGET_PRECOMPUTE_TLS_P): Add hook documentation.
* doc/tm.texi: Regenerated.

gcc/calls.c
gcc/config/rs6000/aix.h
gcc/config/rs6000/rs6000.c
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/target.def

index ff606204772bd3e98064b2ccd5f90cab09ae1062..883d08ba5f280d476f1dca98bd9fcdd2ac52f0cd 100644 (file)
@@ -1002,7 +1002,8 @@ precompute_register_parameters (int num_actuals, struct arg_data *args,
        /* If the value is a non-legitimate constant, force it into a
           pseudo now.  TLS symbols sometimes need a call to resolve.  */
        if (CONSTANT_P (args[i].value)
-           && !targetm.legitimate_constant_p (args[i].mode, args[i].value))
+           && (!targetm.legitimate_constant_p (args[i].mode, args[i].value)
+               || targetm.precompute_tls_p (args[i].mode, args[i].value)))
          args[i].value = force_reg (args[i].mode, args[i].value);
 
        /* If we're going to have to load the value by parts, pull the
index 7fccb31307bbd4098d00f62f66d304800598863e..b116e1a36bb0cda3d0c1868d0dcc8c38efa34ba3 100644 (file)
 /* Use standard DWARF numbering for DWARF debugging information.  */
 #define RS6000_USE_DWARF_NUMBERING
 
+#define TARGET_PRECOMPUTE_TLS_P rs6000_aix_precompute_tls_p
index 844fee88cf3c1407fae35b833cc1f97e5898765a..60b8e3ec2e5b31974c2329313526a1aa0c8f97a6 100644 (file)
@@ -9608,7 +9608,8 @@ rs6000_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
       && SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0)) != 0)
     return true;
 
-  /* Do not place an ELF TLS symbol in the constant pool.  */
+  /* Allow AIX TOC TLS symbols in the constant pool,
+     but not ELF TLS symbols.  */
   return TARGET_ELF && tls_referenced_p (x);
 }
 
@@ -25370,6 +25371,18 @@ rs6000_legitimate_constant_p (machine_mode mode, rtx x)
   return true;
 }
 
+/* Implement TARGET_PRECOMPUTE_TLS_P.
+
+   On the AIX, TLS symbols are in the TOC, which is maintained in the
+   constant pool.  AIX TOC TLS symbols need to be pre-computed, but
+   must be considered legitimate constants.  */
+
+static bool
+rs6000_aix_precompute_tls_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
+{
+  return tls_referenced_p (x);
+}
+
 \f
 /* Return TRUE iff the sequence ending in LAST sets the static chain.  */
 
index 823f85ba9abbaf360b5964e9294801eb72ccf689..b370bc76b25192c3b2322c7902f9a4ed23b0335c 100644 (file)
@@ -5880,6 +5880,15 @@ This hook returns true if @var{x} is a legitimate constant for a
 The default definition returns true.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_PRECOMPUTE_TLS_P (machine_mode @var{mode}, rtx @var{x})
+This hook returns true if @var{x} is a TLS operand on the target
+machine that should be pre-computed when used as the argument in a call.
+You can assume that @var{x} satisfies @code{CONSTANT_P}, so you need not 
+check this.
+
+The default definition returns false.
+@end deftypefn
+
 @deftypefn {Target Hook} rtx TARGET_DELEGITIMIZE_ADDRESS (rtx @var{x})
 This hook is used to undo the possibly obfuscating effects of the
 @code{LEGITIMIZE_ADDRESS} and @code{LEGITIMIZE_RELOAD_ADDRESS} target
index 2321a5fc4e02562b6a55e6f3f1afa2e3aee3f4e8..2974dae2701799368c2c75f7820681a32c51c1ec 100644 (file)
@@ -4147,6 +4147,8 @@ address;  but often a machine-dependent strategy can generate better code.
 
 @hook TARGET_LEGITIMATE_CONSTANT_P
 
+@hook TARGET_PRECOMPUTE_TLS_P
+
 @hook TARGET_DELEGITIMIZE_ADDRESS
 
 @hook TARGET_CONST_NOT_OK_FOR_DEBUG_P
index d7b94bd8e5d7ff17dff855a63a97adef32c14792..0ebfb58fa6f49b2b05513e6095873638820014a4 100644 (file)
@@ -2715,6 +2715,18 @@ The default definition returns true.",
  bool, (machine_mode mode, rtx x),
  hook_bool_mode_rtx_true)
 
+/* True if X is a TLS operand whose value should be pre-computed.  */
+DEFHOOK
+(precompute_tls_p,
+ "This hook returns true if @var{x} is a TLS operand on the target\n\
+machine that should be pre-computed when used as the argument in a call.\n\
+You can assume that @var{x} satisfies @code{CONSTANT_P}, so you need not \n\
+check this.\n\
+\n\
+The default definition returns false.",
+ bool, (machine_mode mode, rtx x),
+ hook_bool_mode_rtx_false)
+
 /* True if the constant X cannot be placed in the constant pool.  */
 DEFHOOK
 (cannot_force_const_mem,