testsuite: Port 'check-function-bodies' to nvptx (was: Add dg test for matching function bodies)
Hi! On 2023-09-04T23:05:05+0200, I wrote: > On 2019-07-16T15:04:49+0100, Richard Sandiford > wrote: >> This patch therefore adds a new check-function-bodies dg-final test >> 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. [...] > 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! Indeed that works fine. > 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 changed my mind about that: instead of '\t', use '\t*' for nvptx, which means that both instructions emitted with additional whitespace prefixed and labels in column zero work nicely. > --- a/gcc/testsuite/lib/scanasm.exp > +++ b/gcc/testsuite/lib/scanasm.exp > @@ -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+)$} There's actually no reason that the expected output syntax (this one) has to match the assembly -- so I restored that, to use the same syntax for nvptx here, too. Any comments before I push the attached "testsuite: Port 'check-function-bodies' to nvptx"? 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 >From bdaf7572d9d4c1988274405840de4071ded3733f Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Mon, 4 Sep 2023 22:28:12 +0200 Subject: [PATCH] testsuite: Port 'check-function-bodies' to nvptx This extends commit 4d706ff86ea86868615558e92407674a4f4b4af9 "Add dg test for matching function bodies" for nvptx. gcc/testsuite/ * lib/scanasm.exp (configure_check-function-bodies): New proc. (parse_function_bodies, check-function-bodies): Use it. * gcc.target/nvptx/abort.c: Use 'check-function-bodies'. gcc/ * doc/sourcebuild.texi (check-function-bodies): Update. --- gcc/doc/sourcebuild.texi | 9 ++- gcc/testsuite/gcc.target/nvptx/abort.c | 19 ++- gcc/testsuite/lib/scanasm.exp | 76 -- 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 1a78b3c1abb..8aec6b6592c 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -3327,9 +3327,12 @@ 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. -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 +Depending on the configuration (see +@code{gcc/testsuite/lib/scanasm.exp:configure_check-function-bodies}), +the test may discard from the compiler's assembly output +directives such as @code{.cfi_startproc}, +local label definitions such as @code{.LFB0}, and more. +It then matches the result against the expected output for a function as a single regular expression. This means that later lines can use backslashes to refer back to @samp{(@dots{})} captures on earlier lines. For example: diff --git a/gcc/testsuite/gcc.target/nvptx/abort.c b/gcc/testsuite/gcc.target/nvptx/abort.c index d3220687400..ae9dbf45a9b 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;" } } */ +/* +** main: +** ... +** \.reg\.pred (%r[0-9]+); +** ... +** @\1 bra (\$L[0-9]+); +** { +** call abort; +** trap; // \(noreturn\) +** exit; // \(noreturn\) +** } +** \2: +** \tmov\.u32 %r[0-9]+, 0; +** ... +*/ diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 0685de1d641..5df80325dff 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -777,33 +777,73 @@ proc scan-lto-assembler { args } { dg-scan
[WIP] testsuite: Port 'check-function-bodies' to nvptx (was: Add dg test for matching function bodies)
Hi! On 2019-07-16T15:04:49+0100, Richard Sandiford 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 // BEGIN PREAMBLE .version6.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; >From 1a15a9dbd8cfc3c2f5df72653614c5c70a0c6018 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge 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