From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id CB7BD3858D35 for ; Mon, 4 Sep 2023 21:05:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB7BD3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.02,227,1688457600"; d="s'?scan'208,223";a="16075504" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 04 Sep 2023 13:05:18 -0800 IronPort-SDR: /5i+YKnepiONjT7kLv+Gp1X2bttTmABgS6MTkV9Q/qoqb5BAsRkUqBL6KfCM7azK97FlJ7BBJQ xEGJivxcPDwtp0i3pw66tppG470xH+LhzQOL1WXHSTwP6Ei7TRWoS+qCSdjqtERrUCQ9h6ewox 4Bo25RdH2GNC7vIHMAmaxvZyIwAwdjMw3c5VzkGrpGwOR2f21syabGt5keEs2gdtR5S58DEZER Dn2AGTxUZQ2YRUMtFtqSXqu7iQDRopuc5VJGPOg3RJMsKBB5IuD6C6AhH0WvQnKvrZETYkyg+r sig= From: Thomas Schwinge To: Richard Sandiford , CC: Tom de Vries , Roger Sayle Subject: [WIP] testsuite: Port 'check-function-bodies' to nvptx (was: Add dg test for matching function bodies) In-Reply-To: References: User-Agent: Notmuch/0.29.3+94~g74c3f1b (https://notmuchmail.org) Emacs/28.2 (x86_64-pc-linux-gnu) Date: Mon, 4 Sep 2023 23:05:05 +0200 Message-ID: <874jk9wsxq.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955 --=-=-= Content-Type: text/plain Content-Disposition: inline; filename="abort.s" // 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; --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename="0001-WIP-testsuite-Port-check-function-bodies-to-nvptx.patch" >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 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 --=-=-=--