public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: Richard Sandiford <richard.sandiford@arm.com>, <gcc-patches@gcc.gnu.org>
Cc: Tom de Vries <tdevries@suse.de>,
	Roger Sayle <roger@nextmovesoftware.com>
Subject: [WIP] testsuite: Port 'check-function-bodies' to nvptx (was: Add dg test for matching function bodies)
Date: Mon, 4 Sep 2023 23:05:05 +0200	[thread overview]
Message-ID: <874jk9wsxq.fsf@euler.schwinge.homeip.net> (raw)
In-Reply-To: <mpt4l3m848u.fsf@arm.com>

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

Hi!

On 2019-07-16T15:04:49+0100, Richard Sandiford <richard.sandiford@arm.com> wrote:
> There isn't a 1:1 mapping from SVE intrinsics to SVE instructions,
> but the intrinsics are still close enough to the instructions for
> there to be a specific preferred sequence (or sometimes choice of
> preferred sequences) for a given combination of operands.  Sometimes
> these sequences will be one instruction, sometimes they'll be several.
>
> I therefore wanted a convenient way of matching the exact assembly
> implementation of a given function.  It's possible to do that using
> single scan-assembler lines, but:
>
> (a) they become hard to read for multiline matches
> (b) the PASS/FAIL lines tend to be long
> (c) it's useful to have a single place that skips over uninteresting
>     lines, such as entry block labels and .cfi_* directives, without
>     being overly broad
>
> This patch therefore adds a new check-function-bodies dg-final test
> that looks for specially-formatted comments.  As a demo, the patch
> converts the SVE vec_init tests to use the new harness instead of
> scan-assembler.

Great, thanks, belatedly!

> The regexps in parse_function_bodies are fairly general, but might
> still need to be extended in future for targets like Darwin or AIX.

..., or nvptx.  As an example, I'm attaching the 'abort.s' generated for
'gcc.target/nvptx/abort.c'.

I'm further attaching a crude ;-) (obviously, not intending to push in
this form) "[WIP] testsuite: Port 'check-function-bodies' to nvptx" to
illustrate that (a) it can be made work for nvptx, but (b) there are a
number of TODO items.

In particular how to parameterize regular expressions for the different
syntax used by nvptx: for example, parameterize via global variables,
initialized accordingly (where?)?  Thinking about it, maybe simply
conditionalizing the current local initializations by
'if { [istarget nvptx-*-*] } { [...] } else { [...] }' will do, simple
enough!

Regarding whitespace prefixed, I think I'll go with the current
'append function_regexp "\t" $line "\n"', that is, prefix expected output
lines with '\t' (as done in 'gcc.target/nvptx/abort.c'), and also for
nvptx handle labels as "fluff" (until we solve that issue generally).

(I'll look into all that later, but wanted to post this now, in case
anyone has different ideas.)


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

[-- Attachment #2: abort.s --]
[-- Type: text/plain, Size: 733 bytes --]

// BEGIN PREAMBLE
	.version	6.0
	.target	sm_30
	.address_size 64
// END PREAMBLE


// BEGIN GLOBAL FUNCTION DECL: main
.visible .func (.param.u32 %value_out) main (.param.u32 %in_ar0, .param.u64 %in_ar1);

// BEGIN GLOBAL FUNCTION DEF: main
.visible .func (.param.u32 %value_out) main (.param.u32 %in_ar0, .param.u64 %in_ar1)
{
	.reg.u32 %value;
	.reg.u32 %ar0;
	ld.param.u32 %ar0, [%in_ar0];
	.reg.u64 %ar1;
	ld.param.u64 %ar1, [%in_ar1];
	.reg.u32 %r23;
	.reg.pred %r25;
		mov.u32	%r23, %ar0;
		setp.le.s32	%r25, %r23, 2;
	@%r25	bra	$L2;
	{
		call abort;
		trap; // (noreturn)
		exit; // (noreturn)
	}
$L2:
		mov.u32	%value, 0;
	st.param.u32	[%value_out], %value;
	ret;
}

// BEGIN GLOBAL FUNCTION DECL: abort
.extern .func abort;

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-WIP-testsuite-Port-check-function-bodies-to-nvptx.patch --]
[-- Type: text/x-diff, Size: 4647 bytes --]

From 1a15a9dbd8cfc3c2f5df72653614c5c70a0c6018 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Mon, 4 Sep 2023 22:28:12 +0200
Subject: [PATCH] [WIP] testsuite: Port 'check-function-bodies' to nvptx

This extends commit 4d706ff86ea86868615558e92407674a4f4b4af9
"Add dg test for matching function bodies" for nvptx.
---
 gcc/doc/sourcebuild.texi               |  2 ++
 gcc/testsuite/gcc.target/nvptx/abort.c | 19 +++++++++++++++++--
 gcc/testsuite/lib/scanasm.exp          | 21 +++++++++++++++++----
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 60a708e88c0..d83da89f9ba 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -3319,6 +3319,7 @@ function body for unoptimized code.
 
 The first line of the expected output for a function @var{fn} has the form:
 
+@c TODO
 @smallexample
 @var{prefix} @var{fn}:  [@{ target/xfail @var{selector} @}]
 @end smallexample
@@ -3326,6 +3327,7 @@ The first line of the expected output for a function @var{fn} has the form:
 Subsequent lines of the expected output also start with @var{prefix}.
 In both cases, whitespace after @var{prefix} is not significant.
 
+@c TODO
 The test discards assembly directives such as @code{.cfi_startproc}
 and local label definitions such as @code{.LFB0} from the compiler's
 assembly output.  It then matches the result against the expected
diff --git a/gcc/testsuite/gcc.target/nvptx/abort.c b/gcc/testsuite/gcc.target/nvptx/abort.c
index d3220687400..aae90e38872 100644
--- a/gcc/testsuite/gcc.target/nvptx/abort.c
+++ b/gcc/testsuite/gcc.target/nvptx/abort.c
@@ -1,4 +1,6 @@
 /* { dg-do compile} */
+/* { dg-final { check-function-bodies {**} {} } } */
+
 /* Annotate no return functions with a trailing 'trap'.  */
 
 extern void abort ();
@@ -9,5 +11,18 @@ int main (int argc, char **argv)
     abort ();
   return 0;
 }
-
-/* { dg-final { scan-assembler "call abort;\[\r\n\t \]+trap;" } } */
+/*
+** // BEGIN GLOBAL FUNCTION DEF: main
+**     ...
+**     \.reg\.pred (%r[0-9]+);
+**     ...
+**     @\1	bra	(\$L[0-9]+);
+**     {
+**     \tcall abort;
+**     \ttrap; // \(noreturn\)
+**     \texit; // \(noreturn\)
+**     }
+TODO**     \2:
+TODO This label currently cannot be matched.
+**     ...
+*/
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index 0685de1d641..7cc9f7cae7d 100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -785,13 +785,16 @@ proc parse_function_bodies { filename result } {
     upvar $result up_result
 
     # Regexp for the start of a function definition (name in \1).
-    set label {^([a-zA-Z_]\S+):$}
+    #TODO
+    set label {^// BEGIN GLOBAL FUNCTION DEF: ([a-zA-Z_]\S+)$}
 
     # Regexp for the end of a function definition.
-    set terminator {^\s*\.size}
+    #TODO
+    set terminator {^\}$}
 
     # Regexp for lines that aren't interesting.
-    set fluff {^\s*(?:\.|//|@|$)}
+    #TODO n/a -- or still TODO
+    set fluff {^\s*$}
 
     set fd [open $filename r]
     set in_function 0
@@ -801,6 +804,7 @@ proc parse_function_bodies { filename result } {
 	    set function_body ""
 	} elseif { $in_function } {
 	    if { [regexp $terminator $line] } {
+		#verbose -log "parse_function_bodies: $function_name\n$function_body"
 		set up_result($function_name) $function_body
 		set in_function 0
 	    } elseif { ![regexp $fluff $line] } {
@@ -907,7 +911,8 @@ proc check-function-bodies { args } {
 
     set count 0
     set function_regexp ""
-    set label {^(\S+):$}
+    #TODO
+    set label {^// BEGIN GLOBAL FUNCTION DEF: ([a-zA-Z_]\S+)$}
 
     set lineno 1
     set fd [open $input_filename r]
@@ -937,7 +942,15 @@ proc check-function-bodies { args } {
 	    } elseif { [string equal $line "..."] } {
 		append function_regexp ".*"
 	    } else {
+		#TODO
+		# Certain (predicable) nvptx instructions are emitted with additional whitespace prefixed.
+		# Prune that here, or include in expected output lines?
+		# On the other hand, labels are emitted in column zero (for no particular reason as far as I can tell; could be changed).
+		# (Whitespace is not significant there.)
+		# But: labels are also in column zero for x86_64 assembly, for example, so that's a pre-existing issue, to be solved generally.
+		# Actually, they're filtered out as "fluff", so that's generally a non-issue vs. TODO item.
 		append function_regexp "\t" $line "\n"
+		#append function_regexp {\s*} $line {\n}
 	    }
 	} elseif { [string equal -length $terminator_len $line $terminator] } {
 	    if { ![string equal $selector "N"] } {
-- 
2.34.1


  parent reply	other threads:[~2023-09-04 21:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-16 14:14 Add dg test for matching function bodies Richard Sandiford
2019-07-21 20:16 ` Jeff Law
2023-09-04 21:05 ` Thomas Schwinge [this message]
2023-09-05 12:20   ` testsuite: Port 'check-function-bodies' to nvptx (was: Add dg test for matching function bodies) Thomas Schwinge
2023-09-05 14:28     ` testsuite: Port 'check-function-bodies' to nvptx Richard Sandiford
2023-09-12  8:45       ` Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jk9wsxq.fsf@euler.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.com \
    --cc=roger@nextmovesoftware.com \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).