public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] testsuite: Add tail_call effective target
@ 2023-03-06 18:45 Hans-Peter Nilsson
  2023-03-06 18:47 ` [PATCH 2/3] doc: Document testsuite check_effective_target_tail_call Hans-Peter Nilsson
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Hans-Peter Nilsson @ 2023-03-06 18:45 UTC (permalink / raw)
  To: gcc-patches

Ok to commit?
-- >8 --
The RTL "expand" dump is the first RTL dump, and it also appears to be
the earliest trace of the target having implemented sibcalls.
Including the "," in the pattern searched for, to try and avoid
possible false matches, but there doesn't appear to be any identifiers
or target names nearby so this is just belts and suspenders.  Using
"tail_call" as a shorter and more commonly used term than a derivative
of "sibling calls", and expecting only gcc folks to have heard of
"sibcalls".

	* lib/target-supports.exp (check_effective_target_tail_call): New.
---
 gcc/testsuite/lib/target-supports.exp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 0ca7a9680bb4..958537b3b7c0 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -11684,6 +11684,15 @@ proc check_effective_target_frame_pointer_for_non_leaf { } {
   return 0
 }
 
+# Return 1 if the target can perform tail-call optimizations of the
+# most trivial type.
+proc check_effective_target_tail_call { } {
+    return [check_no_messages_and_pattern tail_call ",SIBCALL" rtl-expand {
+	__attribute__((__noipa__)) void foo (void) { }
+	__attribute__((__noipa__)) void bar (void) { foo(); }
+    } {-O2 -fdump-rtl-expand-all}] ;# The "SIBCALL" note requires a detailed dump.
+}
+
 # Return 1 if the target's calling sequence or its ABI
 # create implicit stack probes at or prior to function entry.
 proc check_effective_target_caller_implicit_probes { } {
-- 
2.30.2


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

* [PATCH 2/3] doc: Document testsuite check_effective_target_tail_call
  2023-03-06 18:45 [PATCH 1/3] testsuite: Add tail_call effective target Hans-Peter Nilsson
@ 2023-03-06 18:47 ` Hans-Peter Nilsson
  2023-03-06 18:50 ` [PATCH 3/3] testsuite: Gate gcc.dg/plugin/must-tail-call-1.c and -2.c on tail_call Hans-Peter Nilsson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Hans-Peter Nilsson @ 2023-03-06 18:47 UTC (permalink / raw)
  To: gcc-patches

Will commit as obvious, when the 1/3 tail_call is applied.
-- >8 --
Spot-checked the PDF output for sanity.

	* doc/sourcebuild.texi: Document check_effective_target_tail_call.
---
 gcc/doc/sourcebuild.texi | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index c348a1e47cc3..80bef7f0a0e2 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2844,6 +2844,9 @@ Target supports named sections.
 Target uses natural alignment (aligned to type size) for types of
 32 bits or less.
 
+@item tail_call
+Target supports tail-call optimizations.
+
 @item target_natural_alignment_64
 Target uses natural alignment (aligned to type size) for types of
 64 bits or less.
-- 
2.30.2


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

* [PATCH 3/3] testsuite: Gate gcc.dg/plugin/must-tail-call-1.c and -2.c on tail_call
  2023-03-06 18:45 [PATCH 1/3] testsuite: Add tail_call effective target Hans-Peter Nilsson
  2023-03-06 18:47 ` [PATCH 2/3] doc: Document testsuite check_effective_target_tail_call Hans-Peter Nilsson
@ 2023-03-06 18:50 ` Hans-Peter Nilsson
  2023-03-06 18:52 ` [PATCH] testsuite: Support scanning tree-dumps Hans-Peter Nilsson
  2023-03-06 21:14 ` [PATCH 1/3] testsuite: Add tail_call effective target Mike Stump
  3 siblings, 0 replies; 6+ messages in thread
From: Hans-Peter Nilsson @ 2023-03-06 18:50 UTC (permalink / raw)
  To: gcc-patches

Borderline obvious when tail_call is available, so I'll then apply.
-- >8 --
While gcc.dg/plugin/must-tail-call-2.c passes for all targets even
without this, the error message is, for a target like cris-elf that
doesn't implement sibling calls: "error: cannot tail-call: machine
description does not have a sibcall_epilogue instruction pattern"
rather than "error: cannot tail-call: callee returns a structure".
Also, it'd be confusing to exclude must-tail-call-1.c but not
must-tail-call-2.c

	* gcc.dg/plugin/must-tail-call-1.c, gcc.dg/plugin/must-tail-call-2.c:
	Gate on effective target tail_call.
---
 gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c | 1 +
 gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
index 1495a48232a6..3a6d4cceaba7 100644
--- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-1.c
@@ -1,3 +1,4 @@
+/* { dg-do compile { target tail_call } } */
 /* { dg-options "-fdelayed-branch" { target sparc*-*-* } } */
 
 extern void abort (void);
diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c
index c6dfecd32458..d51d15cc0879 100644
--- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c
+++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c
@@ -1,3 +1,4 @@
+/* { dg-do compile { target tail_call } } */
 /* Allow nested functions.  */
 /* { dg-options "-Wno-pedantic" } */
 
-- 
2.30.2


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

* [PATCH] testsuite: Support scanning tree-dumps
  2023-03-06 18:45 [PATCH 1/3] testsuite: Add tail_call effective target Hans-Peter Nilsson
  2023-03-06 18:47 ` [PATCH 2/3] doc: Document testsuite check_effective_target_tail_call Hans-Peter Nilsson
  2023-03-06 18:50 ` [PATCH 3/3] testsuite: Gate gcc.dg/plugin/must-tail-call-1.c and -2.c on tail_call Hans-Peter Nilsson
@ 2023-03-06 18:52 ` Hans-Peter Nilsson
  2023-03-06 21:17   ` Mike Stump
  2023-03-06 21:14 ` [PATCH 1/3] testsuite: Add tail_call effective target Mike Stump
  3 siblings, 1 reply; 6+ messages in thread
From: Hans-Peter Nilsson @ 2023-03-06 18:52 UTC (permalink / raw)
  To: gcc-patches

This is sort-of a spin-off from effective_target_tail_call: I thought
that'd best be implemented by scanning a tree-dump, specifically
-fdump-tree-optimized, but the "tail call" found there is emitted for
*all* targets.  Debugged and ready to apply, putting it out for
consideration as someone will need it (or should use it) sooner rather
than later...  Best committed rather than sitting in mail-archives so:
Ok to apply?
-- >8 --
No planned usage.

	* lib/target-supports.exp (check_compile): Support scanning tree-dumps.
---
 gcc/testsuite/lib/target-supports.exp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 4236c920baeb..0ca7a9680bb4 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -87,6 +87,7 @@ proc check_compile {basename type contents args} {
 	assembly { set output ${basename}[pid].s }
 	object { set output ${basename}[pid].o }
 	executable { set output ${basename}[pid].exe }
+	"tree-*" -
 	"rtl-*" {
 	    set output ${basename}[pid].s
 	    lappend options "additional_flags=-fdump-$type"
@@ -108,6 +109,9 @@ proc check_compile {basename type contents args} {
     if [regexp "rtl-(.*)" $type dummy rtl_type] {
 	set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]r.$rtl_type]"
 	file delete $output
+    } elseif [regexp "tree-(.*)" $type dummy tree_type] {
+	set scan_output "[glob $src.\[0-9\]\[0-9\]\[0-9\]t.$tree_type]"
+	file delete $output
     }
 
     # Restore additional_sources.
-- 
2.30.2


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

* Re: [PATCH 1/3] testsuite: Add tail_call effective target
  2023-03-06 18:45 [PATCH 1/3] testsuite: Add tail_call effective target Hans-Peter Nilsson
                   ` (2 preceding siblings ...)
  2023-03-06 18:52 ` [PATCH] testsuite: Support scanning tree-dumps Hans-Peter Nilsson
@ 2023-03-06 21:14 ` Mike Stump
  3 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 2023-03-06 21:14 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: gcc-patches

On Mar 6, 2023, at 10:45 AM, Hans-Peter Nilsson via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> Ok to commit?

Ok.

> -- >8 --
> The RTL "expand" dump is the first RTL dump, and it also appears to be
> the earliest trace of the target having implemented sibcalls.
> Including the "," in the pattern searched for, to try and avoid
> possible false matches, but there doesn't appear to be any identifiers
> or target names nearby so this is just belts and suspenders.  Using
> "tail_call" as a shorter and more commonly used term than a derivative
> of "sibling calls", and expecting only gcc folks to have heard of
> "sibcalls".
> 
> 	* lib/target-supports.exp (check_effective_target_tail_call): New.


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

* Re: [PATCH] testsuite: Support scanning tree-dumps
  2023-03-06 18:52 ` [PATCH] testsuite: Support scanning tree-dumps Hans-Peter Nilsson
@ 2023-03-06 21:17   ` Mike Stump
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 2023-03-06 21:17 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: gcc-patches

On Mar 6, 2023, at 10:52 AM, Hans-Peter Nilsson via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> Ok to apply?

Ok.

> 	* lib/target-supports.exp (check_compile): Support scanning tree-dumps.


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

end of thread, other threads:[~2023-03-06 21:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 18:45 [PATCH 1/3] testsuite: Add tail_call effective target Hans-Peter Nilsson
2023-03-06 18:47 ` [PATCH 2/3] doc: Document testsuite check_effective_target_tail_call Hans-Peter Nilsson
2023-03-06 18:50 ` [PATCH 3/3] testsuite: Gate gcc.dg/plugin/must-tail-call-1.c and -2.c on tail_call Hans-Peter Nilsson
2023-03-06 18:52 ` [PATCH] testsuite: Support scanning tree-dumps Hans-Peter Nilsson
2023-03-06 21:17   ` Mike Stump
2023-03-06 21:14 ` [PATCH 1/3] testsuite: Add tail_call effective target Mike Stump

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).