From patchwork Mon Sep 4 21:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 137470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1310057vqo; Mon, 4 Sep 2023 14:05:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0VTMUmeG0Ri0pKaY5MndHBlKnPqkk+6LsL3O74Fr41ZdQPdtoR2JpXPapal4l6YHdDoDA X-Received: by 2002:a05:6402:3202:b0:52e:585a:e95 with SMTP id g2-20020a056402320200b0052e585a0e95mr892871eda.2.1693861550358; Mon, 04 Sep 2023 14:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693861550; cv=none; d=google.com; s=arc-20160816; b=uB/8cHSkgNFJPRvcA+fQV7M8OOjeKs6fYf7wVBhsq4GeJxR9h7mS/+INMiP10UAggf lTWuYP+fZSRLV9MfG2W2MRhplf3h/UE/4pWLCBYJRktWYpCUj9S2JRbX77BM3LTsgmHy uTi3MHBTbm7E0+s0O8hbDfmmsSGqNY8Ll2RDx/IEpJW0rl95DZuoHQ7e/5zs2IP6xhQQ bGxAg8cWMHmBBbX4hzvjOA3VQ85k9OZJcLJ6zY7HjXuMa511ywYCAnOKk8BfkMF0Ou1f dW0Y5kXK3aMo0uzZ10xf8gP7jtPm+74AlB9f0kshcBPIkQ20cQFhjjQJB0QVxDzVyZh8 2Q9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:references:in-reply-to:subject:to:from:ironport-sdr :dmarc-filter:delivered-to; bh=SycVG9rD5WJOYkpTK4cegFAyQhftJPchzd8hIL+1jzM=; fh=4eO9hOLmPWazUIDVd2E9Hv9lLwW1Ojw4D+vc/4IYaqs=; b=vKUeQB2uvkY3UqbuMnOXSM+yArh2CBfBQE3T2rAtN9NUn2VDKggjEwxMOz+Va8hHVL TwPWuPxNDBcWnwgRG9e4K7RyRfNms1rcq3eVprLuUXcU0L7RGVBBPDCDQw9BZCssKF9x Xse078apOdc5lx6vJSVC4wpCP326XpndJrcv6YQcD8q0sOsQNIQMbGN/HRaEJbXxx334 gNvZPy5oclKHPZnFJpoLfFjIsjpghS5ibyokODmVMWyj1oDx2KrCo9tBX5Il5Lj4W9gC WtcuKefmv7SgKsyhYXTmtZzaYD0LC2JsJHTO1DTjIdVK4k79Fe0iNpEyA/W9tRtFXLOC lmZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f18-20020a056402161200b005236885749csi6898108edv.431.2023.09.04.14.05.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Sep 2023 14:05:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF9003858C1F for ; Mon, 4 Sep 2023 21:05:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 , 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roger Sayle Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776142568787923188 X-GMAIL-MSGID: 1776142568787923188 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 .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; 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