public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls
@ 2017-07-17  7:22 Yuri Gribov
  2017-07-17  9:27 ` Jan Hubicka
  0 siblings, 1 reply; 15+ messages in thread
From: Yuri Gribov @ 2017-07-17  7:22 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

Hi all,

This is a new version of previous patch
(https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00020.html), fixed
after Rainer's remarks.

-Y

[-- Attachment #2: pr56727-2.patch --]
[-- Type: application/octet-stream, Size: 3158 bytes --]

diff -rupN gcc/gcc/ipa-visibility.c gcc-56727/gcc/ipa-visibility.c
--- gcc/gcc/ipa-visibility.c	2017-06-29 21:14:57.000000000 +0200
+++ gcc-56727/gcc/ipa-visibility.c	2017-07-01 22:03:34.000000000 +0200
@@ -83,6 +83,7 @@ along with GCC; see the file COPYING3.  
 #include "cgraph.h"
 #include "calls.h"
 #include "varasm.h"
+#include "ipa-utils.h"
 
 /* Return true when NODE can not be local. Worker for cgraph_local_node_p.  */
 
@@ -617,6 +618,36 @@ function_and_variable_visibility (bool w
   /* All aliases should be procssed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
+  FOR_EACH_DEFINED_FUNCTION (node)
+    {
+      if (node->get_availability () != AVAIL_INTERPOSABLE
+          || node->can_be_discarded_p ()
+          || node->has_aliases_p ())
+        continue;
+
+      cgraph_node *alias = 0;
+      for (cgraph_edge *e = node->callees; e; e = e->next_callee)
+        {
+          /* Recursive function calls usually can't be interposed.  */
+
+          if (!e->recursive_p ())
+            continue;
+
+          if (!alias)
+            { 
+              alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
+              gcc_assert (alias && alias != node);
+            }
+
+          e->redirect_callee (alias);
+          if (gimple_has_body_p (e->caller->decl))
+            { 
+              push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
+              e->redirect_call_stmt_to_callee ();
+              pop_cfun (); 
+            }
+        }
+    }
   FOR_EACH_FUNCTION (node)
     {
       int flags = flags_from_decl_or_type (node->decl);
diff -rupN gcc/gcc/testsuite/gcc.dg/pr56727-1.c gcc-56727/gcc/testsuite/gcc.dg/pr56727-1.c
--- gcc/gcc/testsuite/gcc.dg/pr56727-1.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc-56727/gcc/testsuite/gcc.dg/pr56727-1.c	2017-07-02 08:35:27.000000000 +0200
@@ -0,0 +1,23 @@
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-final { scan-assembler-not "@(PLT|plt)" { target i?86-*-* x86_64-*-* powerpc*-*-* } } } */
+
+#define define_func(type) \
+  void f_ ## type (type b) { f_ ## type (0); } \
+  void __attribute__((noinline, noclone)) f_noinline_ ## type (type b) \
+  { f_noinline_ ## type (0); }
+
+define_func(char)
+define_func(short)
+define_func(int)
+define_func(long)
+
+int foo(int n)
+{
+  return (n == 1 || n == 2) ? 1 : foo(n-1) * foo(n-2);
+}
+
+int __attribute__((noinline, noclone)) foo_noinline(int n)
+{
+  return (n == 1 || n == 2) ? 1 : foo_noinline(n-1) * foo_noinline(n-2);
+}
diff -rupN gcc/gcc/testsuite/gcc.dg/pr56727-2.c gcc-56727/gcc/testsuite/gcc.dg/pr56727-2.c
--- gcc/gcc/testsuite/gcc.dg/pr56727-2.c	1970-01-01 01:00:00.000000000 +0100
+++ gcc-56727/gcc/testsuite/gcc.dg/pr56727-2.c	2017-07-02 08:35:18.000000000 +0200
@@ -0,0 +1,16 @@
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-final { scan-assembler "@(PLT|plt)" { target i?86-*-* x86_64-*-* powerpc*-*-* } } } */
+
+__attribute__((noinline, noclone))
+void f (short b)
+{
+  f (0);
+}
+
+static void g (short) __attribute__ ((alias ("f")));
+
+void h ()
+{
+  g (0);
+}

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls
  2017-07-17  7:22 [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Yuri Gribov
@ 2017-07-17  9:27 ` Jan Hubicka
  2017-07-18  8:27   ` Yuri Gribov
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Hubicka @ 2017-07-17  9:27 UTC (permalink / raw)
  To: Yuri Gribov; +Cc: GCC Patches

> Hi all,
> 
> This is a new version of previous patch
> (https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00020.html), fixed
> after Rainer's remarks.
Hi,
the patch looks OK, but I wonder why you included can_be_discarded check?
If function is in comdat I believe the optimization still can happen.
Perhaps you only want to check DECL_EXTERNAL?

Honza

> 
> -Y

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls
  2017-07-17  9:27 ` Jan Hubicka
@ 2017-07-18  8:27   ` Yuri Gribov
  2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
  2017-08-02  9:47     ` [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Jan Hubicka
  0 siblings, 2 replies; 15+ messages in thread
From: Yuri Gribov @ 2017-07-18  8:27 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches

On Mon, Jul 17, 2017 at 10:27 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>> Hi all,
>>
>> This is a new version of previous patch
>> (https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00020.html), fixed
>> after Rainer's remarks.
> Hi,
> the patch looks OK, but I wonder why you included can_be_discarded check?
> If function is in comdat I believe the optimization still can happen.
> Perhaps you only want to check DECL_EXTERNAL?

TBH I was inspired by can_replace_by_local_alias which prohibits local
alias for discardable functions.  But I agree that situation here is
different and it's indeed not needed (if function is discarded, it
does not matter whether we optimized recursive calls).

Could you elaborate why we still need DECL_EXTERNAL though?

-Y

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520).
  2017-07-18  8:27   ` Yuri Gribov
@ 2017-07-24 12:52     ` Martin Liška
  2017-07-24 14:06       ` Jan Hubicka
  2017-07-25  4:20       ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Yuri Gribov
  2017-08-02  9:47     ` [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Jan Hubicka
  1 sibling, 2 replies; 15+ messages in thread
From: Martin Liška @ 2017-07-24 12:52 UTC (permalink / raw)
  To: Yuri Gribov, Jan Hubicka; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 446 bytes --]

Hi.

The patch fixed PR mentioned in subject of this email. We should not call the transformation
on targets that do not support aliases.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Apart from that, can you Yuri please take a look at failing test-case on ppc64le: 

FAIL: gcc.dg/pr56727-2.c scan-assembler @(PLT|plt)

in: https://gcc.gnu.org/ml/gcc-testresults/2017-07/msg02164.html

Ready to be installed?
Martin

[-- Attachment #2: 0001-Fix-wrong-condition-in-ipa-visibility.c-PR-ipa-81520.patch --]
[-- Type: text/x-patch, Size: 2364 bytes --]

From 046931ec490d20a6c003094367f7f0bfae64647f Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 24 Jul 2017 11:21:18 +0200
Subject: [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520).

gcc/ChangeLog:

2017-07-24  Martin Liska  <mliska@suse.cz>

	PR ipa/81520
	* ipa-visibility.c (function_and_variable_visibility): Make the redirection
	just on target that do supporting aliasing.  Fix GNU coding style.

gcc/testsuite/ChangeLog:

2017-07-24  Martin Liska  <mliska@suse.cz>

	PR ipa/81520
	* gcc.dg/ipa/pr81520.c: New test.
---
 gcc/ipa-visibility.c               | 11 +++++++----
 gcc/testsuite/gcc.dg/ipa/pr81520.c | 11 +++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr81520.c

diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index 21321703dbb..13cf2a3a1cf 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -615,9 +615,10 @@ function_and_variable_visibility (bool whole_program)
   struct cgraph_node *node;
   varpool_node *vnode;
 
-  /* All aliases should be procssed at this point.  */
+  /* All aliases should be processed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
+#ifdef ASM_OUTPUT_DEF
   FOR_EACH_DEFINED_FUNCTION (node)
     {
       if (node->get_availability () != AVAIL_INTERPOSABLE
@@ -634,20 +635,22 @@ function_and_variable_visibility (bool whole_program)
 	    continue;
 
 	  if (!alias)
-	    { 
+	    {
 	      alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
 	      gcc_assert (alias && alias != node);
 	    }
 
 	  e->redirect_callee (alias);
 	  if (gimple_has_body_p (e->caller->decl))
-	    { 
+	    {
 	      push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
 	      e->redirect_call_stmt_to_callee ();
-	      pop_cfun (); 
+	      pop_cfun ();
 	    }
 	}
     }
+#endif
+
   FOR_EACH_FUNCTION (node)
     {
       int flags = flags_from_decl_or_type (node->decl);
diff --git a/gcc/testsuite/gcc.dg/ipa/pr81520.c b/gcc/testsuite/gcc.dg/ipa/pr81520.c
new file mode 100644
index 00000000000..b5d33d2dc96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr81520.c
@@ -0,0 +1,11 @@
+/* PR ipa/81520 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fPIC" } */
+/* { dg-require-effective-target fpic } */
+
+char
+a (int b)
+{
+  a (b);
+  return 0;
+}
-- 
2.13.3


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520).
  2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
@ 2017-07-24 14:06       ` Jan Hubicka
  2017-07-31  8:04         ` [PATCH] Introduce TARGET_SUPPORTS_ALIASES Martin Liška
  2017-07-25  4:20       ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Yuri Gribov
  1 sibling, 1 reply; 15+ messages in thread
From: Jan Hubicka @ 2017-07-24 14:06 UTC (permalink / raw)
  To: Martin Liška; +Cc: Yuri Gribov, GCC Patches

> >From 046931ec490d20a6c003094367f7f0bfae64647f Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Mon, 24 Jul 2017 11:21:18 +0200
> Subject: [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520).
> 
> gcc/ChangeLog:
> 
> 2017-07-24  Martin Liska  <mliska@suse.cz>
> 
> 	PR ipa/81520
> 	* ipa-visibility.c (function_and_variable_visibility): Make the redirection
> 	just on target that do supporting aliasing.  Fix GNU coding style.
> 
> gcc/testsuite/ChangeLog:
> 
> 2017-07-24  Martin Liska  <mliska@suse.cz>
> 
> 	PR ipa/81520
> 	* gcc.dg/ipa/pr81520.c: New test.

OK, we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
incrementally.

Thanks,
Honza
> ---
>  gcc/ipa-visibility.c               | 11 +++++++----
>  gcc/testsuite/gcc.dg/ipa/pr81520.c | 11 +++++++++++
>  2 files changed, 18 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/pr81520.c
> 
> diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
> index 21321703dbb..13cf2a3a1cf 100644
> --- a/gcc/ipa-visibility.c
> +++ b/gcc/ipa-visibility.c
> @@ -615,9 +615,10 @@ function_and_variable_visibility (bool whole_program)
>    struct cgraph_node *node;
>    varpool_node *vnode;
>  
> -  /* All aliases should be procssed at this point.  */
> +  /* All aliases should be processed at this point.  */
>    gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
>  
> +#ifdef ASM_OUTPUT_DEF
>    FOR_EACH_DEFINED_FUNCTION (node)
>      {
>        if (node->get_availability () != AVAIL_INTERPOSABLE
> @@ -634,20 +635,22 @@ function_and_variable_visibility (bool whole_program)
>  	    continue;
>  
>  	  if (!alias)
> -	    { 
> +	    {
>  	      alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
>  	      gcc_assert (alias && alias != node);
>  	    }
>  
>  	  e->redirect_callee (alias);
>  	  if (gimple_has_body_p (e->caller->decl))
> -	    { 
> +	    {
>  	      push_cfun (DECL_STRUCT_FUNCTION (e->caller->decl));
>  	      e->redirect_call_stmt_to_callee ();
> -	      pop_cfun (); 
> +	      pop_cfun ();
>  	    }
>  	}
>      }
> +#endif
> +
>    FOR_EACH_FUNCTION (node)
>      {
>        int flags = flags_from_decl_or_type (node->decl);
> diff --git a/gcc/testsuite/gcc.dg/ipa/pr81520.c b/gcc/testsuite/gcc.dg/ipa/pr81520.c
> new file mode 100644
> index 00000000000..b5d33d2dc96
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ipa/pr81520.c
> @@ -0,0 +1,11 @@
> +/* PR ipa/81520 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fPIC" } */
> +/* { dg-require-effective-target fpic } */
> +
> +char
> +a (int b)
> +{
> +  a (b);
> +  return 0;
> +}
> -- 
> 2.13.3
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520).
  2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
  2017-07-24 14:06       ` Jan Hubicka
@ 2017-07-25  4:20       ` Yuri Gribov
  1 sibling, 0 replies; 15+ messages in thread
From: Yuri Gribov @ 2017-07-25  4:20 UTC (permalink / raw)
  To: Martin Liška; +Cc: Jan Hubicka, GCC Patches

On Mon, Jul 24, 2017 at 1:52 PM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> The patch fixed PR mentioned in subject of this email. We should not call the transformation
> on targets that do not support aliases.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> Apart from that, can you Yuri please take a look at failing test-case on ppc64le:
>
> FAIL: gcc.dg/pr56727-2.c scan-assembler @(PLT|plt)
>
> in: https://gcc.gnu.org/ml/gcc-testresults/2017-07/msg02164.html

Thanks Martin, this has been reported in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81535 (the test gets
tailcall optimized).  I'll be back on Thursday to fix it.

-Y

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] Introduce TARGET_SUPPORTS_ALIASES
  2017-07-24 14:06       ` Jan Hubicka
@ 2017-07-31  8:04         ` Martin Liška
  2017-07-31  9:58           ` Yuri Gribov
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2017-07-31  8:04 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: Yuri Gribov, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 265 bytes --]

Hi.

Doing the transformation suggested by Honza.

Patch can bootstrap on ppc64le-redhat-linux and x86_64-linux-gnu and survives regression tests.
And I also verified that works on hppa2.0w-hp-hpux11.11 (target w/o aliasing support).

Ready to be installed?
Martin

[-- Attachment #2: 0001-Introduce-TARGET_SUPPORTS_ALIASES.patch --]
[-- Type: text/x-patch, Size: 9023 bytes --]

From f8584bcb678dba92241c20b3e81895a52fc865f3 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 25 Jul 2017 13:11:28 +0200
Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES

gcc/c-family/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* c-opts.c (c_common_post_options): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.

gcc/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* asan.c (asan_protect_global): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.
	* cgraph.c (cgraph_node::create_same_body_alias): Likewise.
	* ipa-visibility.c (can_replace_by_local_alias): Likewise.
	(optimize_weakref): Likewise.
	* symtab.c (symtab_node::noninterposable_alias): Likewise.
	* varpool.c (varpool_node::create_extra_name_alias): Likewise.
	* defaults.h: Introduce TARGET_SUPPORTS_ALIASES.

gcc/cp/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* decl2.c (get_tls_init_fn): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.
	(handle_tls_init): Likewise.
	(note_mangling_alias): Likewise.
	* optimize.c (can_alias_cdtor): Likewise.
---
 gcc/asan.c            |  4 +---
 gcc/c-family/c-opts.c | 22 ++++++++++++----------
 gcc/cgraph.c          |  7 ++++---
 gcc/cp/decl2.c        | 23 ++++++++++-------------
 gcc/cp/optimize.c     |  6 +++---
 gcc/defaults.h        |  9 +++++++++
 gcc/ipa-visibility.c  | 15 +++++----------
 gcc/symtab.c          |  6 +++---
 gcc/varpool.c         |  6 +++---
 9 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/gcc/asan.c b/gcc/asan.c
index 5f9275f6425..d8cb2b52c8b 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1663,10 +1663,8 @@ asan_protect_global (tree decl)
   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
     return false;
 
-#ifndef ASM_OUTPUT_DEF
-  if (asan_needs_local_alias (decl))
+  if (!TARGET_SUPPORTS_ALIASES && asan_needs_local_alias (decl))
     return false;
-#endif
 
   return true;
 }
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 1657e7a4390..0b13a188c1b 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -957,16 +957,18 @@ c_common_post_options (const char **pfilename)
 
   if (flag_extern_tls_init)
     {
-#if !defined (ASM_OUTPUT_DEF) || !SUPPORTS_WEAK
-      /* Lazy TLS initialization for a variable in another TU requires
-	 alias and weak reference support. */
-      if (flag_extern_tls_init > 0)
-	sorry ("external TLS initialization functions not supported "
-	       "on this target");
-      flag_extern_tls_init = 0;
-#else
-      flag_extern_tls_init = 1;
-#endif
+      if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
+	{
+	  /* Lazy TLS initialization for a variable in another TU requires
+	     alias and weak reference support.  */
+	  if (flag_extern_tls_init > 0)
+	    sorry ("external TLS initialization functions not supported "
+		   "on this target");
+
+	  flag_extern_tls_init = 0;
+	}
+      else
+	flag_extern_tls_init = 1;
     }
 
   if (num_in_fnames > 1)
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 2f820f1bb67..356bcd311e1 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -582,10 +582,11 @@ cgraph_node *
 cgraph_node::create_same_body_alias (tree alias, tree decl)
 {
   cgraph_node *n;
-#ifndef ASM_OUTPUT_DEF
+
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
+
   /* Langhooks can create same body aliases of symbols not defined.
      Those are useless. Drop them on the floor.  */
   if (symtab->global_info_ready)
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 2a52f8ca3e2..5119d4e62cc 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3156,11 +3156,9 @@ get_tls_init_fn (tree var)
   if (!flag_extern_tls_init && DECL_EXTERNAL (var))
     return NULL_TREE;
 
-#ifdef ASM_OUTPUT_DEF
   /* If the variable is internal, or if we can't generate aliases,
      call the local init function directly.  */
-  if (!TREE_PUBLIC (var))
-#endif
+  if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
     return get_local_tls_init_fn ();
 
   tree sname = mangle_tls_init_fn (var);
@@ -4241,9 +4239,8 @@ handle_tls_init (void)
       tree init = TREE_PURPOSE (vars);
       one_static_initialization_or_destruction (var, init, true);
 
-#ifdef ASM_OUTPUT_DEF
       /* Output init aliases even with -fno-extern-tls-init.  */
-      if (TREE_PUBLIC (var))
+      if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var))
 	{
           tree single_init_fn = get_tls_init_fn (var);
 	  if (single_init_fn == NULL_TREE)
@@ -4253,7 +4250,6 @@ handle_tls_init (void)
 		(single_init_fn, fn);
 	  gcc_assert (alias != NULL);
 	}
-#endif
     }
 
   finish_then_clause (if_stmt);
@@ -4300,15 +4296,16 @@ generate_mangling_alias (tree decl, tree id2)
 void
 note_mangling_alias (tree decl ATTRIBUTE_UNUSED, tree id2 ATTRIBUTE_UNUSED)
 {
-#ifdef ASM_OUTPUT_DEF
-  if (!defer_mangling_aliases)
-    generate_mangling_alias (decl, id2);
-  else
+  if (TARGET_SUPPORTS_ALIASES)
     {
-      vec_safe_push (mangling_aliases, decl);
-      vec_safe_push (mangling_aliases, id2);
+      if (!defer_mangling_aliases)
+	generate_mangling_alias (decl, id2);
+      else
+	{
+	  vec_safe_push (mangling_aliases, decl);
+	  vec_safe_push (mangling_aliases, id2);
+	}
     }
-#endif
 }
 
 /* Emit all mangling aliases that were deferred up to this point.  */
diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c
index a1c387092d4..09ffbda7ca8 100644
--- a/gcc/cp/optimize.c
+++ b/gcc/cp/optimize.c
@@ -184,10 +184,10 @@ cdtor_comdat_group (tree complete, tree base)
 static bool
 can_alias_cdtor (tree fn)
 {
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported by the assembler, fail.  */
-  return false;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return false;
+
   /* We can't use an alias if there are virtual bases.  */
   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     return false;
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 7ad92d920f8..072ef6b6d17 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -863,6 +863,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #endif
 #endif
 
+/* Decide whether target supports aliases.  */
+#ifndef TARGET_SUPPORTS_ALIASES
+#ifdef ASM_OUTPUT_DEF
+#define TARGET_SUPPORTS_ALIASES 1
+#else
+#define TARGET_SUPPORTS_ALIASES 0
+#endif
+#endif
+
 /* Select a format to encode pointers in exception handling data.  We
    prefer those that result in fewer dynamic relocations.  Assume no
    special support here and encode direct references.  */
diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index 21321703dbb..b78e66e622a 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -334,10 +334,10 @@ varpool_node::externally_visible_p (void)
 static bool
 can_replace_by_local_alias (symtab_node *node)
 {
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported, we can't do replacement.  */
-  return false;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return false;
+
   /* Weakrefs have a reason to be non-local.  Be sure we do not replace
      them.  */
   while (node->transparent_alias && node->definition && !node->weakref)
@@ -458,11 +458,6 @@ update_visibility_by_resolution_info (symtab_node * node)
 static void
 optimize_weakref (symtab_node *node)
 {
-#ifdef ASM_OUTPUT_DEF
-  bool aliases_supported = true;
-#else
-  bool aliases_supported = false;
-#endif
   bool strip_weakref = false;
   bool static_alias = false;
 
@@ -481,8 +476,8 @@ optimize_weakref (symtab_node *node)
 
   /* If we have definition of weakref's target and we know it binds locally,
      we can turn weakref to static alias.  */
-  if (target->definition && decl_binds_to_current_def_p (target->decl)
-      && aliases_supported)
+  if (TARGET_SUPPORTS_ALIASES
+      && target->definition && decl_binds_to_current_def_p (target->decl))
     strip_weakref = static_alias = true;
   /* Otherwise we can turn weakref into transparent alias.  This transformation
      may break asm statements which directly refers to symbol name and expect
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 0145910023f..1affc1dce1d 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1763,10 +1763,10 @@ symtab_node::noninterposable_alias (void)
 				   (void *)&new_node, true);
   if (new_node)
     return new_node;
-#ifndef ASM_OUTPUT_DEF
+
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
 
   /* Otherwise create a new one.  */
   new_decl = copy_node (node->decl);
diff --git a/gcc/varpool.c b/gcc/varpool.c
index ab59c80406b..db3dcee1af8 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -786,10 +786,10 @@ varpool_node::create_extra_name_alias (tree alias, tree decl)
 {
   varpool_node *alias_node;
 
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
+
   alias_node = varpool_node::create_alias (alias, decl);
   alias_node->cpp_implicit_alias = true;
 
-- 
2.13.3


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Introduce TARGET_SUPPORTS_ALIASES
  2017-07-31  8:04         ` [PATCH] Introduce TARGET_SUPPORTS_ALIASES Martin Liška
@ 2017-07-31  9:58           ` Yuri Gribov
  2017-07-31 11:22             ` [PATCH][v2] " Martin Liška
  0 siblings, 1 reply; 15+ messages in thread
From: Yuri Gribov @ 2017-07-31  9:58 UTC (permalink / raw)
  To: Martin Liška; +Cc: Jan Hubicka, GCC Patches

On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> Doing the transformation suggested by Honza.
>
> Patch can bootstrap on ppc64le-redhat-linux and x86_64-linux-gnu and survives regression tests.
> And I also verified that works on hppa2.0w-hp-hpux11.11 (target w/o aliasing support).
>
> Ready to be installed?

A nit - you can probly get rid of ATTRIBUTE_UNUSED in note_mangling_alias now.

-Y

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES
  2017-07-31  9:58           ` Yuri Gribov
@ 2017-07-31 11:22             ` Martin Liška
  2017-08-10 13:49               ` Jan Hubicka
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2017-07-31 11:22 UTC (permalink / raw)
  To: Yuri Gribov; +Cc: Jan Hubicka, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

On 07/31/2017 11:57 AM, Yuri Gribov wrote:
> On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
>> Hi.
>>
>> Doing the transformation suggested by Honza.
>>
>> Patch can bootstrap on ppc64le-redhat-linux and x86_64-linux-gnu and survives regression tests.
>> And I also verified that works on hppa2.0w-hp-hpux11.11 (target w/o aliasing support).
>>
>> Ready to be installed?
> 
> A nit - you can probly get rid of ATTRIBUTE_UNUSED in note_mangling_alias now.
> 
> -Y
> 

Sure.

Done in v2.

Martin

[-- Attachment #2: 0001-Introduce-TARGET_SUPPORTS_ALIASES-v2.patch --]
[-- Type: text/x-patch, Size: 9140 bytes --]

From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 25 Jul 2017 13:11:28 +0200
Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES

gcc/c-family/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* c-opts.c (c_common_post_options): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.

gcc/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* asan.c (asan_protect_global): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.
	* cgraph.c (cgraph_node::create_same_body_alias): Likewise.
	* ipa-visibility.c (can_replace_by_local_alias): Likewise.
	(optimize_weakref): Likewise.
	* symtab.c (symtab_node::noninterposable_alias): Likewise.
	* varpool.c (varpool_node::create_extra_name_alias): Likewise.
	* defaults.h: Introduce TARGET_SUPPORTS_ALIASES.

gcc/cp/ChangeLog:

2017-07-25  Martin Liska  <mliska@suse.cz>

	* decl2.c (get_tls_init_fn): Replace ASM_OUTPUT_DEF with
	TARGET_SUPPORTS_ALIASES.
	(handle_tls_init): Likewise.
	(note_mangling_alias): Likewise.  Remove ATTRIBUTE_UNUSED for
	both arguments.
	* optimize.c (can_alias_cdtor): Likewise.
---
 gcc/asan.c            |  4 +---
 gcc/c-family/c-opts.c | 22 ++++++++++++----------
 gcc/cgraph.c          |  7 ++++---
 gcc/cp/decl2.c        | 25 +++++++++++--------------
 gcc/cp/optimize.c     |  6 +++---
 gcc/defaults.h        |  9 +++++++++
 gcc/ipa-visibility.c  | 15 +++++----------
 gcc/symtab.c          |  6 +++---
 gcc/varpool.c         |  6 +++---
 9 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/gcc/asan.c b/gcc/asan.c
index 5f9275f6425..d8cb2b52c8b 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1663,10 +1663,8 @@ asan_protect_global (tree decl)
   if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
     return false;
 
-#ifndef ASM_OUTPUT_DEF
-  if (asan_needs_local_alias (decl))
+  if (!TARGET_SUPPORTS_ALIASES && asan_needs_local_alias (decl))
     return false;
-#endif
 
   return true;
 }
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 1657e7a4390..0b13a188c1b 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -957,16 +957,18 @@ c_common_post_options (const char **pfilename)
 
   if (flag_extern_tls_init)
     {
-#if !defined (ASM_OUTPUT_DEF) || !SUPPORTS_WEAK
-      /* Lazy TLS initialization for a variable in another TU requires
-	 alias and weak reference support. */
-      if (flag_extern_tls_init > 0)
-	sorry ("external TLS initialization functions not supported "
-	       "on this target");
-      flag_extern_tls_init = 0;
-#else
-      flag_extern_tls_init = 1;
-#endif
+      if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK)
+	{
+	  /* Lazy TLS initialization for a variable in another TU requires
+	     alias and weak reference support.  */
+	  if (flag_extern_tls_init > 0)
+	    sorry ("external TLS initialization functions not supported "
+		   "on this target");
+
+	  flag_extern_tls_init = 0;
+	}
+      else
+	flag_extern_tls_init = 1;
     }
 
   if (num_in_fnames > 1)
diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index d7c9ba61795..849989443b1 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -582,10 +582,11 @@ cgraph_node *
 cgraph_node::create_same_body_alias (tree alias, tree decl)
 {
   cgraph_node *n;
-#ifndef ASM_OUTPUT_DEF
+
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
+
   /* Langhooks can create same body aliases of symbols not defined.
      Those are useless. Drop them on the floor.  */
   if (symtab->global_info_ready)
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 2a52f8ca3e2..29a2e3cf02d 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3156,11 +3156,9 @@ get_tls_init_fn (tree var)
   if (!flag_extern_tls_init && DECL_EXTERNAL (var))
     return NULL_TREE;
 
-#ifdef ASM_OUTPUT_DEF
   /* If the variable is internal, or if we can't generate aliases,
      call the local init function directly.  */
-  if (!TREE_PUBLIC (var))
-#endif
+  if (!TREE_PUBLIC (var) || !TARGET_SUPPORTS_ALIASES)
     return get_local_tls_init_fn ();
 
   tree sname = mangle_tls_init_fn (var);
@@ -4241,9 +4239,8 @@ handle_tls_init (void)
       tree init = TREE_PURPOSE (vars);
       one_static_initialization_or_destruction (var, init, true);
 
-#ifdef ASM_OUTPUT_DEF
       /* Output init aliases even with -fno-extern-tls-init.  */
-      if (TREE_PUBLIC (var))
+      if (TARGET_SUPPORTS_ALIASES && TREE_PUBLIC (var))
 	{
           tree single_init_fn = get_tls_init_fn (var);
 	  if (single_init_fn == NULL_TREE)
@@ -4253,7 +4250,6 @@ handle_tls_init (void)
 		(single_init_fn, fn);
 	  gcc_assert (alias != NULL);
 	}
-#endif
     }
 
   finish_then_clause (if_stmt);
@@ -4298,17 +4294,18 @@ generate_mangling_alias (tree decl, tree id2)
    implementation.  */
 
 void
-note_mangling_alias (tree decl ATTRIBUTE_UNUSED, tree id2 ATTRIBUTE_UNUSED)
+note_mangling_alias (tree decl, tree id2)
 {
-#ifdef ASM_OUTPUT_DEF
-  if (!defer_mangling_aliases)
-    generate_mangling_alias (decl, id2);
-  else
+  if (TARGET_SUPPORTS_ALIASES)
     {
-      vec_safe_push (mangling_aliases, decl);
-      vec_safe_push (mangling_aliases, id2);
+      if (!defer_mangling_aliases)
+	generate_mangling_alias (decl, id2);
+      else
+	{
+	  vec_safe_push (mangling_aliases, decl);
+	  vec_safe_push (mangling_aliases, id2);
+	}
     }
-#endif
 }
 
 /* Emit all mangling aliases that were deferred up to this point.  */
diff --git a/gcc/cp/optimize.c b/gcc/cp/optimize.c
index a1c387092d4..09ffbda7ca8 100644
--- a/gcc/cp/optimize.c
+++ b/gcc/cp/optimize.c
@@ -184,10 +184,10 @@ cdtor_comdat_group (tree complete, tree base)
 static bool
 can_alias_cdtor (tree fn)
 {
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported by the assembler, fail.  */
-  return false;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return false;
+
   /* We can't use an alias if there are virtual bases.  */
   if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
     return false;
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 7ad92d920f8..072ef6b6d17 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -863,6 +863,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #endif
 #endif
 
+/* Decide whether target supports aliases.  */
+#ifndef TARGET_SUPPORTS_ALIASES
+#ifdef ASM_OUTPUT_DEF
+#define TARGET_SUPPORTS_ALIASES 1
+#else
+#define TARGET_SUPPORTS_ALIASES 0
+#endif
+#endif
+
 /* Select a format to encode pointers in exception handling data.  We
    prefer those that result in fewer dynamic relocations.  Assume no
    special support here and encode direct references.  */
diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index 3033f20e3f1..825b3fc36e9 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -337,10 +337,10 @@ varpool_node::externally_visible_p (void)
 static bool
 can_replace_by_local_alias (symtab_node *node)
 {
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported, we can't do replacement.  */
-  return false;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return false;
+
   /* Weakrefs have a reason to be non-local.  Be sure we do not replace
      them.  */
   while (node->transparent_alias && node->definition && !node->weakref)
@@ -461,11 +461,6 @@ update_visibility_by_resolution_info (symtab_node * node)
 static void
 optimize_weakref (symtab_node *node)
 {
-#ifdef ASM_OUTPUT_DEF
-  bool aliases_supported = true;
-#else
-  bool aliases_supported = false;
-#endif
   bool strip_weakref = false;
   bool static_alias = false;
 
@@ -484,8 +479,8 @@ optimize_weakref (symtab_node *node)
 
   /* If we have definition of weakref's target and we know it binds locally,
      we can turn weakref to static alias.  */
-  if (target->definition && decl_binds_to_current_def_p (target->decl)
-      && aliases_supported)
+  if (TARGET_SUPPORTS_ALIASES
+      && target->definition && decl_binds_to_current_def_p (target->decl))
     strip_weakref = static_alias = true;
   /* Otherwise we can turn weakref into transparent alias.  This transformation
      may break asm statements which directly refers to symbol name and expect
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 0145910023f..1affc1dce1d 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1763,10 +1763,10 @@ symtab_node::noninterposable_alias (void)
 				   (void *)&new_node, true);
   if (new_node)
     return new_node;
-#ifndef ASM_OUTPUT_DEF
+
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
 
   /* Otherwise create a new one.  */
   new_decl = copy_node (node->decl);
diff --git a/gcc/varpool.c b/gcc/varpool.c
index ab59c80406b..db3dcee1af8 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -786,10 +786,10 @@ varpool_node::create_extra_name_alias (tree alias, tree decl)
 {
   varpool_node *alias_node;
 
-#ifndef ASM_OUTPUT_DEF
   /* If aliases aren't supported by the assembler, fail.  */
-  return NULL;
-#endif
+  if (!TARGET_SUPPORTS_ALIASES)
+    return NULL;
+
   alias_node = varpool_node::create_alias (alias, decl);
   alias_node->cpp_implicit_alias = true;
 
-- 
2.13.3


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls
  2017-07-18  8:27   ` Yuri Gribov
  2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
@ 2017-08-02  9:47     ` Jan Hubicka
  1 sibling, 0 replies; 15+ messages in thread
From: Jan Hubicka @ 2017-08-02  9:47 UTC (permalink / raw)
  To: Yuri Gribov; +Cc: GCC Patches

Hi,
> On Mon, Jul 17, 2017 at 10:27 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
> >> Hi all,
> >>
> >> This is a new version of previous patch
> >> (https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00020.html), fixed
> >> after Rainer's remarks.
> > Hi,
> > the patch looks OK, but I wonder why you included can_be_discarded check?
> > If function is in comdat I believe the optimization still can happen.
> > Perhaps you only want to check DECL_EXTERNAL?
> 
> TBH I was inspired by can_replace_by_local_alias which prohibits local
> alias for discardable functions.  But I agree that situation here is
> different and it's indeed not needed (if function is discarded, it
> does not matter whether we optimized recursive calls).
> 
> Could you elaborate why we still need DECL_EXTERNAL though?

I you have DECL_EXTERNAl function, its definition lives only until inlining
and then all offline copies are  replaced by external calls.  So if you create
alias for recusive call you will probably end up with an ICE.

Honza

> 
> -Y

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES
  2017-07-31 11:22             ` [PATCH][v2] " Martin Liška
@ 2017-08-10 13:49               ` Jan Hubicka
  2023-09-08 12:02                 ` More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES) Thomas Schwinge
  0 siblings, 1 reply; 15+ messages in thread
From: Jan Hubicka @ 2017-08-10 13:49 UTC (permalink / raw)
  To: Martin Liška; +Cc: Yuri Gribov, GCC Patches

> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
> > On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
> >> Hi.
> >>
> >> Doing the transformation suggested by Honza.
> >>
> >> Patch can bootstrap on ppc64le-redhat-linux and x86_64-linux-gnu and survives regression tests.
> >> And I also verified that works on hppa2.0w-hp-hpux11.11 (target w/o aliasing support).
> >>
> >> Ready to be installed?
> > 
> > A nit - you can probly get rid of ATTRIBUTE_UNUSED in note_mangling_alias now.
> > 
> > -Y
> > 
> 
> Sure.
> 
> Done in v2.
> 
> Martin

> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Tue, 25 Jul 2017 13:11:28 +0200
> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES
> 
> gcc/c-family/ChangeLog:
> 
> 2017-07-25  Martin Liska  <mliska@suse.cz>
> 
> 	* c-opts.c (c_common_post_options): Replace ASM_OUTPUT_DEF with
> 	TARGET_SUPPORTS_ALIASES.
> 
> gcc/ChangeLog:
> 
> 2017-07-25  Martin Liska  <mliska@suse.cz>
> 
> 	* asan.c (asan_protect_global): Replace ASM_OUTPUT_DEF with
> 	TARGET_SUPPORTS_ALIASES.
> 	* cgraph.c (cgraph_node::create_same_body_alias): Likewise.
> 	* ipa-visibility.c (can_replace_by_local_alias): Likewise.
> 	(optimize_weakref): Likewise.
> 	* symtab.c (symtab_node::noninterposable_alias): Likewise.
> 	* varpool.c (varpool_node::create_extra_name_alias): Likewise.
> 	* defaults.h: Introduce TARGET_SUPPORTS_ALIASES.
> 
> gcc/cp/ChangeLog:
> 
> 2017-07-25  Martin Liska  <mliska@suse.cz>
> 
> 	* decl2.c (get_tls_init_fn): Replace ASM_OUTPUT_DEF with
> 	TARGET_SUPPORTS_ALIASES.
> 	(handle_tls_init): Likewise.
> 	(note_mangling_alias): Likewise.  Remove ATTRIBUTE_UNUSED for
> 	both arguments.
> 	* optimize.c (can_alias_cdtor): Likewise.

OK,
thanks!

Honza

^ permalink raw reply	[flat|nested] 15+ messages in thread

* More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES)
  2017-08-10 13:49               ` Jan Hubicka
@ 2023-09-08 12:02                 ` Thomas Schwinge
  2023-09-19  8:47                   ` [PING] " Thomas Schwinge
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schwinge @ 2023-09-08 12:02 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches; +Cc: Tom de Vries

[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]

Hi!

On 2017-08-10T15:42:13+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
>> > On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
>> >> Doing the transformation suggested by Honza.

... which was:

| On 2017-07-24T16:06:22+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
| > we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
| > incrementally.

>> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
>> From: marxin <mliska@suse.cz>
>> Date: Tue, 25 Jul 2017 13:11:28 +0200
>> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES

..., and got pushed as commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6
(Subversion r251048) "Introduce TARGET_SUPPORTS_ALIASES".

I don't know if that was actually intentional here, or just an
"accident", but such changes actually allow that a back end may or may
not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES')
independent of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not
just on static but instead on dynamic (run-time) configuration.  This is
relevant for the nvptx back end's '-malias' flag.

There did remain a few instances where we currently still assume that
from '#ifdef ASM_OUTPUT_DEF' follows 'TARGET_SUPPORTS_ALIASES', which I'm
adjusting in the attached (with '--ignore-space-change', for easy review)
"More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.".
OK to push?

These changes are necessary to cure nvptx regressions raised in
<https://inbox.sourceware.org/87iliurqt1.fsf@euler.schwinge.homeip.net>
"[nvptx] Use .alias directive for mptx >= 6.3", addressing the comment:
"[...] remains to be analyzed".


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-More-ifdef-ASM_OUTPUT_DEF-if-TARGET_SUPPORTS_ALIASES.patch --]
[-- Type: text/x-diff, Size: 4737 bytes --]

From 4c725226c3657adb775af274876de5077b8fbf45 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 7 Sep 2023 22:15:08 +0200
Subject: [PATCH] More '#ifdef ASM_OUTPUT_DEF' -> 'if
 (TARGET_SUPPORTS_ALIASES)' etc.

Per commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6 (Subversion r251048)
"Introduce TARGET_SUPPORTS_ALIASES", there is the idea that a back end may or
may not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES') independent
of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not just on static but
instead on dynamic (run-time) configuration.  There did remain a few instances
where we currently still assume that from '#ifdef ASM_OUTPUT_DEF' follows
'TARGET_SUPPORTS_ALIASES'.  Change these to 'if (TARGET_SUPPORTS_ALIASES)',
similarly, or 'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.

	gcc/
	* ipa-icf.cc (sem_item::target_supports_symbol_aliases_p):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);' before
	'return true;'.
	* ipa-visibility.cc (function_and_variable_visibility): Change
	'#ifdef ASM_OUTPUT_DEF' to 'if (TARGET_SUPPORTS_ALIASES)'.
	* varasm.cc (output_constant_pool_contents)
	[#ifdef ASM_OUTPUT_DEF]:
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
	(do_assemble_alias) [#ifdef ASM_OUTPUT_DEF]:
	'if (!TARGET_SUPPORTS_ALIASES)',
	'gcc_checking_assert (seen_error ());'.
	(assemble_alias): Change '#if !defined (ASM_OUTPUT_DEF)' to
	'if (!TARGET_SUPPORTS_ALIASES)'.
	(default_asm_output_anchor):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
---
 gcc/ipa-icf.cc        |  1 +
 gcc/ipa-visibility.cc |  8 +++++---
 gcc/varasm.cc         | 13 ++++++++++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 836d0914ded..bbdfd445397 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -218,6 +218,7 @@ sem_item::target_supports_symbol_aliases_p (void)
 #if !defined (ASM_OUTPUT_DEF) || (!defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL))
   return false;
 #else
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
   return true;
 #endif
 }
diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc
index 8ec82bb333e..8ce56114ee3 100644
--- a/gcc/ipa-visibility.cc
+++ b/gcc/ipa-visibility.cc
@@ -622,7 +622,8 @@ function_and_variable_visibility (bool whole_program)
   /* All aliases should be processed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
-#ifdef ASM_OUTPUT_DEF
+  if (TARGET_SUPPORTS_ALIASES)
+    {
       FOR_EACH_DEFINED_FUNCTION (node)
 	{
 	  if (node->get_availability () != AVAIL_INTERPOSABLE
@@ -643,7 +644,8 @@ function_and_variable_visibility (bool whole_program)
 
 	      if (!alias)
 		{
-	      alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
+		  alias
+		    = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
 		  gcc_assert (alias && alias != node);
 		}
 
@@ -656,7 +658,7 @@ function_and_variable_visibility (bool whole_program)
 		}
 	    }
 	}
-#endif
+    }
 
   FOR_EACH_FUNCTION (node)
     {
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 53f0cc61922..40d6081a3fa 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -4300,6 +4300,8 @@ output_constant_pool_contents (struct rtx_constant_pool *pool)
     if (desc->mark < 0)
       {
 #ifdef ASM_OUTPUT_DEF
+	gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
 	const char *name = XSTR (desc->sym, 0);
 	char label[256];
 	char buffer[256 + 32];
@@ -6225,6 +6227,10 @@ do_assemble_alias (tree decl, tree target)
 		  IDENTIFIER_POINTER (id),
 		  IDENTIFIER_POINTER (target));
 # endif
+  /* If symbol aliases aren't actually supported...  */
+  if (!TARGET_SUPPORTS_ALIASES)
+    /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error.  */
+    gcc_checking_assert (seen_error ());
 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
   {
     const char *name;
@@ -6294,9 +6300,8 @@ assemble_alias (tree decl, tree target)
       if (TREE_PUBLIC (decl))
 	error ("%qs symbol %q+D must have static linkage", "weakref", decl);
     }
-  else
+  else if (!TARGET_SUPPORTS_ALIASES)
     {
-#if !defined (ASM_OUTPUT_DEF)
 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
       error_at (DECL_SOURCE_LOCATION (decl),
 		"alias definitions not supported in this configuration");
@@ -6317,7 +6322,7 @@ assemble_alias (tree decl, tree target)
 	  return;
 	}
 # endif
-#endif
+      gcc_unreachable ();
     }
   TREE_USED (decl) = 1;
 
@@ -7406,6 +7411,8 @@ default_strip_name_encoding (const char *str)
 void
 default_asm_output_anchor (rtx symbol)
 {
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
   char buffer[100];
 
   sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PING] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES)
  2023-09-08 12:02                 ` More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES) Thomas Schwinge
@ 2023-09-19  8:47                   ` Thomas Schwinge
  2023-10-25  8:38                     ` [PING^2] " Thomas Schwinge
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schwinge @ 2023-09-19  8:47 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2179 bytes --]

Hi!

Ping.


Grüße
 Thomas


On 2023-09-08T14:02:50+0200, I wrote:
> Hi!
>
> On 2017-08-10T15:42:13+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>>> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
>>> > On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
>>> >> Doing the transformation suggested by Honza.
>
> ... which was:
>
> | On 2017-07-24T16:06:22+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
> | > we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
> | > incrementally.
>
>>> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
>>> From: marxin <mliska@suse.cz>
>>> Date: Tue, 25 Jul 2017 13:11:28 +0200
>>> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES
>
> ..., and got pushed as commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6
> (Subversion r251048) "Introduce TARGET_SUPPORTS_ALIASES".
>
> I don't know if that was actually intentional here, or just an
> "accident", but such changes actually allow that a back end may or may
> not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES')
> independent of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not
> just on static but instead on dynamic (run-time) configuration.  This is
> relevant for the nvptx back end's '-malias' flag.
>
> There did remain a few instances where we currently still assume that
> from '#ifdef ASM_OUTPUT_DEF' follows 'TARGET_SUPPORTS_ALIASES', which I'm
> adjusting in the attached (with '--ignore-space-change', for easy review)
> "More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.".
> OK to push?
>
> These changes are necessary to cure nvptx regressions raised in
> <https://inbox.sourceware.org/87iliurqt1.fsf@euler.schwinge.homeip.net>
> "[nvptx] Use .alias directive for mptx >= 6.3", addressing the comment:
> "[...] remains to be analyzed".
>
>
> Grüße
>  Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-More-ifdef-ASM_OUTPUT_DEF-if-TARGET_SUPPORTS_ALIASES.patch --]
[-- Type: text/x-diff, Size: 4737 bytes --]

From 4c725226c3657adb775af274876de5077b8fbf45 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 7 Sep 2023 22:15:08 +0200
Subject: [PATCH] More '#ifdef ASM_OUTPUT_DEF' -> 'if
 (TARGET_SUPPORTS_ALIASES)' etc.

Per commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6 (Subversion r251048)
"Introduce TARGET_SUPPORTS_ALIASES", there is the idea that a back end may or
may not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES') independent
of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not just on static but
instead on dynamic (run-time) configuration.  There did remain a few instances
where we currently still assume that from '#ifdef ASM_OUTPUT_DEF' follows
'TARGET_SUPPORTS_ALIASES'.  Change these to 'if (TARGET_SUPPORTS_ALIASES)',
similarly, or 'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.

	gcc/
	* ipa-icf.cc (sem_item::target_supports_symbol_aliases_p):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);' before
	'return true;'.
	* ipa-visibility.cc (function_and_variable_visibility): Change
	'#ifdef ASM_OUTPUT_DEF' to 'if (TARGET_SUPPORTS_ALIASES)'.
	* varasm.cc (output_constant_pool_contents)
	[#ifdef ASM_OUTPUT_DEF]:
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
	(do_assemble_alias) [#ifdef ASM_OUTPUT_DEF]:
	'if (!TARGET_SUPPORTS_ALIASES)',
	'gcc_checking_assert (seen_error ());'.
	(assemble_alias): Change '#if !defined (ASM_OUTPUT_DEF)' to
	'if (!TARGET_SUPPORTS_ALIASES)'.
	(default_asm_output_anchor):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
---
 gcc/ipa-icf.cc        |  1 +
 gcc/ipa-visibility.cc |  8 +++++---
 gcc/varasm.cc         | 13 ++++++++++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 836d0914ded..bbdfd445397 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -218,6 +218,7 @@ sem_item::target_supports_symbol_aliases_p (void)
 #if !defined (ASM_OUTPUT_DEF) || (!defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL))
   return false;
 #else
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
   return true;
 #endif
 }
diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc
index 8ec82bb333e..8ce56114ee3 100644
--- a/gcc/ipa-visibility.cc
+++ b/gcc/ipa-visibility.cc
@@ -622,7 +622,8 @@ function_and_variable_visibility (bool whole_program)
   /* All aliases should be processed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
-#ifdef ASM_OUTPUT_DEF
+  if (TARGET_SUPPORTS_ALIASES)
+    {
       FOR_EACH_DEFINED_FUNCTION (node)
 	{
 	  if (node->get_availability () != AVAIL_INTERPOSABLE
@@ -643,7 +644,8 @@ function_and_variable_visibility (bool whole_program)
 
 	      if (!alias)
 		{
-	      alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
+		  alias
+		    = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
 		  gcc_assert (alias && alias != node);
 		}
 
@@ -656,7 +658,7 @@ function_and_variable_visibility (bool whole_program)
 		}
 	    }
 	}
-#endif
+    }
 
   FOR_EACH_FUNCTION (node)
     {
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 53f0cc61922..40d6081a3fa 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -4300,6 +4300,8 @@ output_constant_pool_contents (struct rtx_constant_pool *pool)
     if (desc->mark < 0)
       {
 #ifdef ASM_OUTPUT_DEF
+	gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
 	const char *name = XSTR (desc->sym, 0);
 	char label[256];
 	char buffer[256 + 32];
@@ -6225,6 +6227,10 @@ do_assemble_alias (tree decl, tree target)
 		  IDENTIFIER_POINTER (id),
 		  IDENTIFIER_POINTER (target));
 # endif
+  /* If symbol aliases aren't actually supported...  */
+  if (!TARGET_SUPPORTS_ALIASES)
+    /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error.  */
+    gcc_checking_assert (seen_error ());
 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
   {
     const char *name;
@@ -6294,9 +6300,8 @@ assemble_alias (tree decl, tree target)
       if (TREE_PUBLIC (decl))
 	error ("%qs symbol %q+D must have static linkage", "weakref", decl);
     }
-  else
+  else if (!TARGET_SUPPORTS_ALIASES)
     {
-#if !defined (ASM_OUTPUT_DEF)
 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
       error_at (DECL_SOURCE_LOCATION (decl),
 		"alias definitions not supported in this configuration");
@@ -6317,7 +6322,7 @@ assemble_alias (tree decl, tree target)
 	  return;
 	}
 # endif
-#endif
+      gcc_unreachable ();
     }
   TREE_USED (decl) = 1;
 
@@ -7406,6 +7411,8 @@ default_strip_name_encoding (const char *str)
 void
 default_asm_output_anchor (rtx symbol)
 {
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
   char buffer[100];
 
   sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PING^2] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES)
  2023-09-19  8:47                   ` [PING] " Thomas Schwinge
@ 2023-10-25  8:38                     ` Thomas Schwinge
  2023-10-25 16:19                       ` [PING^2] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc Jeff Law
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schwinge @ 2023-10-25  8:38 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2315 bytes --]

Hi!

Ping.


Grüße
 Thomas


On 2023-09-19T10:47:56+0200, I wrote:
> Hi!
>
> Ping.
>
>
> Grüße
>  Thomas
>
>
> On 2023-09-08T14:02:50+0200, I wrote:
>> Hi!
>>
>> On 2017-08-10T15:42:13+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>>>> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
>>>> > On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
>>>> >> Doing the transformation suggested by Honza.
>>
>> ... which was:
>>
>> | On 2017-07-24T16:06:22+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>> | > we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
>> | > incrementally.
>>
>>>> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
>>>> From: marxin <mliska@suse.cz>
>>>> Date: Tue, 25 Jul 2017 13:11:28 +0200
>>>> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES
>>
>> ..., and got pushed as commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6
>> (Subversion r251048) "Introduce TARGET_SUPPORTS_ALIASES".
>>
>> I don't know if that was actually intentional here, or just an
>> "accident", but such changes actually allow that a back end may or may
>> not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES')
>> independent of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not
>> just on static but instead on dynamic (run-time) configuration.  This is
>> relevant for the nvptx back end's '-malias' flag.
>>
>> There did remain a few instances where we currently still assume that
>> from '#ifdef ASM_OUTPUT_DEF' follows 'TARGET_SUPPORTS_ALIASES', which I'm
>> adjusting in the attached (with '--ignore-space-change', for easy review)
>> "More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.".
>> OK to push?
>>
>> These changes are necessary to cure nvptx regressions raised in
>> <https://inbox.sourceware.org/87iliurqt1.fsf@euler.schwinge.homeip.net>
>> "[nvptx] Use .alias directive for mptx >= 6.3", addressing the comment:
>> "[...] remains to be analyzed".
>>
>>
>> Grüße
>>  Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-More-ifdef-ASM_OUTPUT_DEF-if-TARGET_SUPPORTS_ALIASES.patch --]
[-- Type: text/x-diff, Size: 4737 bytes --]

From 4c725226c3657adb775af274876de5077b8fbf45 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 7 Sep 2023 22:15:08 +0200
Subject: [PATCH] More '#ifdef ASM_OUTPUT_DEF' -> 'if
 (TARGET_SUPPORTS_ALIASES)' etc.

Per commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6 (Subversion r251048)
"Introduce TARGET_SUPPORTS_ALIASES", there is the idea that a back end may or
may not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES') independent
of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not just on static but
instead on dynamic (run-time) configuration.  There did remain a few instances
where we currently still assume that from '#ifdef ASM_OUTPUT_DEF' follows
'TARGET_SUPPORTS_ALIASES'.  Change these to 'if (TARGET_SUPPORTS_ALIASES)',
similarly, or 'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.

	gcc/
	* ipa-icf.cc (sem_item::target_supports_symbol_aliases_p):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);' before
	'return true;'.
	* ipa-visibility.cc (function_and_variable_visibility): Change
	'#ifdef ASM_OUTPUT_DEF' to 'if (TARGET_SUPPORTS_ALIASES)'.
	* varasm.cc (output_constant_pool_contents)
	[#ifdef ASM_OUTPUT_DEF]:
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
	(do_assemble_alias) [#ifdef ASM_OUTPUT_DEF]:
	'if (!TARGET_SUPPORTS_ALIASES)',
	'gcc_checking_assert (seen_error ());'.
	(assemble_alias): Change '#if !defined (ASM_OUTPUT_DEF)' to
	'if (!TARGET_SUPPORTS_ALIASES)'.
	(default_asm_output_anchor):
	'gcc_checking_assert (TARGET_SUPPORTS_ALIASES);'.
---
 gcc/ipa-icf.cc        |  1 +
 gcc/ipa-visibility.cc |  8 +++++---
 gcc/varasm.cc         | 13 ++++++++++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-icf.cc b/gcc/ipa-icf.cc
index 836d0914ded..bbdfd445397 100644
--- a/gcc/ipa-icf.cc
+++ b/gcc/ipa-icf.cc
@@ -218,6 +218,7 @@ sem_item::target_supports_symbol_aliases_p (void)
 #if !defined (ASM_OUTPUT_DEF) || (!defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL))
   return false;
 #else
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
   return true;
 #endif
 }
diff --git a/gcc/ipa-visibility.cc b/gcc/ipa-visibility.cc
index 8ec82bb333e..8ce56114ee3 100644
--- a/gcc/ipa-visibility.cc
+++ b/gcc/ipa-visibility.cc
@@ -622,7 +622,8 @@ function_and_variable_visibility (bool whole_program)
   /* All aliases should be processed at this point.  */
   gcc_checking_assert (!alias_pairs || !alias_pairs->length ());
 
-#ifdef ASM_OUTPUT_DEF
+  if (TARGET_SUPPORTS_ALIASES)
+    {
       FOR_EACH_DEFINED_FUNCTION (node)
 	{
 	  if (node->get_availability () != AVAIL_INTERPOSABLE
@@ -643,7 +644,8 @@ function_and_variable_visibility (bool whole_program)
 
 	      if (!alias)
 		{
-	      alias = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
+		  alias
+		    = dyn_cast<cgraph_node *> (node->noninterposable_alias ());
 		  gcc_assert (alias && alias != node);
 		}
 
@@ -656,7 +658,7 @@ function_and_variable_visibility (bool whole_program)
 		}
 	    }
 	}
-#endif
+    }
 
   FOR_EACH_FUNCTION (node)
     {
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index 53f0cc61922..40d6081a3fa 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -4300,6 +4300,8 @@ output_constant_pool_contents (struct rtx_constant_pool *pool)
     if (desc->mark < 0)
       {
 #ifdef ASM_OUTPUT_DEF
+	gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
 	const char *name = XSTR (desc->sym, 0);
 	char label[256];
 	char buffer[256 + 32];
@@ -6225,6 +6227,10 @@ do_assemble_alias (tree decl, tree target)
 		  IDENTIFIER_POINTER (id),
 		  IDENTIFIER_POINTER (target));
 # endif
+  /* If symbol aliases aren't actually supported...  */
+  if (!TARGET_SUPPORTS_ALIASES)
+    /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error.  */
+    gcc_checking_assert (seen_error ());
 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
   {
     const char *name;
@@ -6294,9 +6300,8 @@ assemble_alias (tree decl, tree target)
       if (TREE_PUBLIC (decl))
 	error ("%qs symbol %q+D must have static linkage", "weakref", decl);
     }
-  else
+  else if (!TARGET_SUPPORTS_ALIASES)
     {
-#if !defined (ASM_OUTPUT_DEF)
 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
       error_at (DECL_SOURCE_LOCATION (decl),
 		"alias definitions not supported in this configuration");
@@ -6317,7 +6322,7 @@ assemble_alias (tree decl, tree target)
 	  return;
 	}
 # endif
-#endif
+      gcc_unreachable ();
     }
   TREE_USED (decl) = 1;
 
@@ -7406,6 +7411,8 @@ default_strip_name_encoding (const char *str)
 void
 default_asm_output_anchor (rtx symbol)
 {
+  gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
+
   char buffer[100];
 
   sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PING^2] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.
  2023-10-25  8:38                     ` [PING^2] " Thomas Schwinge
@ 2023-10-25 16:19                       ` Jeff Law
  0 siblings, 0 replies; 15+ messages in thread
From: Jeff Law @ 2023-10-25 16:19 UTC (permalink / raw)
  To: Thomas Schwinge, Jan Hubicka, gcc-patches



On 10/25/23 02:38, Thomas Schwinge wrote:
> Hi!
> 
> Ping.
> 
> 
> Grüße
>   Thomas
> 
> 
> On 2023-09-19T10:47:56+0200, I wrote:
>> Hi!
>>
>> Ping.
>>
>>
>> Grüße
>>   Thomas
>>
>>
>> On 2023-09-08T14:02:50+0200, I wrote:
>>> Hi!
>>>
>>> On 2017-08-10T15:42:13+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>>>>> On 07/31/2017 11:57 AM, Yuri Gribov wrote:
>>>>>> On Mon, Jul 31, 2017 at 9:04 AM, Martin Liška <mliska@suse.cz> wrote:
>>>>>>> Doing the transformation suggested by Honza.
>>>
>>> ... which was:
>>>
>>> | On 2017-07-24T16:06:22+0200, Jan Hubicka <hubicka@ucw.cz> wrote:
>>> | > we probably should turn ASM_OUTPUT_DEF ifdefs into a conditional compilation
>>> | > incrementally.
>>>
>>>>> >From 78ee08b25d22125cb1fa248bac98ef1e84504761 Mon Sep 17 00:00:00 2001
>>>>> From: marxin <mliska@suse.cz>
>>>>> Date: Tue, 25 Jul 2017 13:11:28 +0200
>>>>> Subject: [PATCH] Introduce TARGET_SUPPORTS_ALIASES
>>>
>>> ..., and got pushed as commit a8b522b483ebb8c972ecfde8779a7a6ec16aecd6
>>> (Subversion r251048) "Introduce TARGET_SUPPORTS_ALIASES".
>>>
>>> I don't know if that was actually intentional here, or just an
>>> "accident", but such changes actually allow that a back end may or may
>>> not provide symbol aliasing support ('TARGET_SUPPORTS_ALIASES')
>>> independent of '#ifdef ASM_OUTPUT_DEF', and in particular, depending not
>>> just on static but instead on dynamic (run-time) configuration.  This is
>>> relevant for the nvptx back end's '-malias' flag.
>>>
>>> There did remain a few instances where we currently still assume that
>>> from '#ifdef ASM_OUTPUT_DEF' follows 'TARGET_SUPPORTS_ALIASES', which I'm
>>> adjusting in the attached (with '--ignore-space-change', for easy review)
>>> "More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc.".
>>> OK to push?
>>>
>>> These changes are necessary to cure nvptx regressions raised in
>>> <https://inbox.sourceware.org/87iliurqt1.fsf@euler.schwinge.homeip.net>
>>> "[nvptx] Use .alias directive for mptx >= 6.3", addressing the comment:
>>> "[...] remains to be analyzed".
OK
jeff

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-10-25 16:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-17  7:22 [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Yuri Gribov
2017-07-17  9:27 ` Jan Hubicka
2017-07-18  8:27   ` Yuri Gribov
2017-07-24 12:52     ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Martin Liška
2017-07-24 14:06       ` Jan Hubicka
2017-07-31  8:04         ` [PATCH] Introduce TARGET_SUPPORTS_ALIASES Martin Liška
2017-07-31  9:58           ` Yuri Gribov
2017-07-31 11:22             ` [PATCH][v2] " Martin Liška
2017-08-10 13:49               ` Jan Hubicka
2023-09-08 12:02                 ` More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc. (was: [PATCH][v2] Introduce TARGET_SUPPORTS_ALIASES) Thomas Schwinge
2023-09-19  8:47                   ` [PING] " Thomas Schwinge
2023-10-25  8:38                     ` [PING^2] " Thomas Schwinge
2023-10-25 16:19                       ` [PING^2] More '#ifdef ASM_OUTPUT_DEF' -> 'if (TARGET_SUPPORTS_ALIASES)' etc Jeff Law
2017-07-25  4:20       ` [PATCH] Fix wrong condition in ipa-visibility.c (PR ipa/81520) Yuri Gribov
2017-08-02  9:47     ` [PATCHv2][PING^2][PR 56727] Bypass PLT for recursive calls Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).