From patchwork Mon Sep 5 12:28:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp153590wrt; Mon, 5 Sep 2022 05:29:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR7q5SQHiUd2tRe378EbfsrofQ+90rftNIVjXCcAtQPj87YSls2Xov1Lqo3C+SMBRl18kTmS X-Received: by 2002:aa7:cb06:0:b0:446:7668:2969 with SMTP id s6-20020aa7cb06000000b0044676682969mr43047625edt.206.1662380985485; Mon, 05 Sep 2022 05:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662380985; cv=none; d=google.com; s=arc-20160816; b=iVjLkuMV7i+rkq3KOP4+Vq4fkZTBw1k3SvxGL3B6P2V1EBRm1ecabI2GPslMSsIyT5 WRPfTuaxx3wJ1Gc3QxNwULyDgJPgwJ1AC3HrzyqtiDjZyTYTdekeBcblxbM2A43nfon1 nvTazbR/shUHH8EUim9ZmZ9Vul3GTwrgHGeoQENdHO+nffWxuXOXElVLpeliNzPoX0b2 q1p9AroeTal1Qgd/KwVD5THQJzjHJ7PlobjEaM2deFiPsgocF0ESwpIszU0rbZTgpfqT sHt4Hhj+dtHNvO1orsP5NUMfRZnejz6cjLw2IHbyXZsSg10+cOj1RMavST02c/Jj6uhv Sr4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=lziwNTelGxvcsnv4CyUh/QpioScHnX3uIcxuLkuM/L4=; b=jhxbUe4zMonFTEssGF0RYhBjoXt+I+albLeSC5d0CD3m8pSUVOHuVfD6t1LJhv2eUg +xfM03EI8Tr65+SVRULWWb2d2TRN2XcZbSo36nQDayrhk9l077tM1PvnJD7UM1ZrxcC7 JmFQ0N2bAwnL7gg4kJPRmf0BTtPMQzJ/7AkhjMFQ1kevlAeUlTmL5tLI6dkGztPaxtlR Fydb7LzFlkYj7eSXuG92RpcTh0m69dugHq7QVL1daD0O9Vz1GmHRLlmY0L/MYqU1X8w6 BsQYX/bgxq9Gz2F/mq5KwXD6u8szBs1QwpW9S6XxFNoXKTdJOm46jYDtvjIGJSlfREhZ RrlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lrBvSYkY; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k11-20020a50ce4b000000b00445fba6c607si6495148edj.140.2022.09.05.05.29.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 05:29:45 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lrBvSYkY; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5683C385702A for ; Mon, 5 Sep 2022 12:29:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5683C385702A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662380984; bh=lziwNTelGxvcsnv4CyUh/QpioScHnX3uIcxuLkuM/L4=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=lrBvSYkYAnUPDJu8JILueKT1Lx839IANlEa3GIvOZ5k3bFLocfL9KG+tKYB19kvEd S7uArM6c6KSfErdU3lWSKrGgvpjJwLf2yLDUHDXV3SEXoOEoEOWGtTz82EFP1S87i0 vilOqNSD5npGEaqKr16i0EcbFYBXxhKcrB+7sZgI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 29177385AC1B for ; Mon, 5 Sep 2022 12:29:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29177385AC1B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-3-ygkrFQofOtOw2xxHBb18tg-1; Mon, 05 Sep 2022 08:28:58 -0400 X-MC-Unique: ygkrFQofOtOw2xxHBb18tg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 341F1803301; Mon, 5 Sep 2022 12:28:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6A152166B26; Mon, 5 Sep 2022 12:28:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 285CSsHa075382 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Sep 2022 14:28:55 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 285CSrlk075381; Mon, 5 Sep 2022 14:28:53 +0200 Date: Mon, 5 Sep 2022 14:28:53 +0200 To: gcc-patches@gcc.gnu.org, Tobias Burnus Subject: [PATCH] openmp: Introduce gimple_omp_ordered_standalone_p Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743132804123341571?= X-GMAIL-MSGID: =?utf-8?q?1743132804123341571?= Hi! On Sat, Sep 03, 2022 at 10:07:27AM +0200, Jakub Jelinek via Gcc-patches wrote: > Incrementally, I'd like to change the way we differentiate between > stand-alone and block-associated ordered constructs, because the current > way of looking for presence of doacross clause doesn't work well if those > clauses are removed because they had been invalid (wrong syntax or > unknown variables in it etc.) The following, so far only lightly tested, patch implements that. Will commit if it passes full bootstrap/regtest on x86_64-linux and i686-linux overnight. 2022-09-05 Jakub Jelinek gcc/ * gimple.h (enum gf_mask): Add GF_OMP_ORDERED_STANDALONE enumerator. (gimple_omp_subcode): Use GIMPLE_OMP_ORDERED instead of GIMPLE_OMP_TEAMS as upper bound. (gimple_omp_ordered_standalone_p, gimple_omp_ordered_standalone): New inline functions. * gimplify.cc (find_standalone_omp_ordered): Look for OMP_ORDERED with NULL OMP_ORDERED_BODY rather than with OMP_DOACROSS clause. (gimplify_expr): Call gimple_omp_ordered_standalone for OMP_ORDERED with NULL OMP_ORDERED_BODY. * omp-low.cc (check_omp_nesting_restrictions): Use gimple_omp_ordered_standalone_p test instead of omp_find_clause (..., OMP_CLAUSE_DOACROSS). (lower_omp_ordered): Likewise. * omp-expand.cc (expand_omp, build_omp_regions_1, omp_make_gimple_edges): Likewise. gcc/cp/ * pt.cc (tsubst_expr) : If OMP_BODY was NULL, keep it NULL after instantiation too. gcc/testsuite/ * c-c++-common/gomp/sink-3.c: Don't expect a superfluous error during error recovery. * c-c++-common/gomp/doacross-6.c (foo): Add further tests. Jakub --- gcc/gimple.h.jj 2022-06-27 11:18:02.682058403 +0200 +++ gcc/gimple.h 2022-09-05 13:47:21.009761168 +0200 @@ -194,6 +194,7 @@ enum gf_mask { GF_OMP_RETURN_NOWAIT = 1 << 0, GF_OMP_SECTION_LAST = 1 << 0, + GF_OMP_ORDERED_STANDALONE = 1 << 0, GF_OMP_ATOMIC_MEMORY_ORDER = (1 << 6) - 1, GF_OMP_ATOMIC_NEED_VALUE = 1 << 6, GF_OMP_ATOMIC_WEAK = 1 << 7, @@ -2312,7 +2313,7 @@ static inline unsigned gimple_omp_subcode (const gimple *s) { gcc_gimple_checking_assert (gimple_code (s) >= GIMPLE_OMP_ATOMIC_LOAD - && gimple_code (s) <= GIMPLE_OMP_TEAMS); + && gimple_code (s) <= GIMPLE_OMP_ORDERED); return s->subcode; } @@ -2402,6 +2403,27 @@ gimple_omp_section_set_last (gimple *g) } +/* Return true if OMP ordered construct is stand-alone + (G has the GF_OMP_ORDERED_STANDALONE flag set). */ + +static inline bool +gimple_omp_ordered_standalone_p (const gimple *g) +{ + GIMPLE_CHECK (g, GIMPLE_OMP_ORDERED); + return (gimple_omp_subcode (g) & GF_OMP_ORDERED_STANDALONE) != 0; +} + + +/* Set the GF_OMP_ORDERED_STANDALONE flag on G. */ + +static inline void +gimple_omp_ordered_standalone (gimple *g) +{ + GIMPLE_CHECK (g, GIMPLE_OMP_ORDERED); + g->subcode |= GF_OMP_ORDERED_STANDALONE; +} + + /* Return true if OMP parallel statement G has the GF_OMP_PARALLEL_COMBINED flag set. */ --- gcc/gimplify.cc.jj 2022-09-03 09:41:34.823006434 +0200 +++ gcc/gimplify.cc 2022-09-05 13:37:00.158143869 +0200 @@ -12427,7 +12427,7 @@ gimplify_omp_taskloop_expr (tree type, t } /* Helper function of gimplify_omp_for, find OMP_ORDERED with - OMP_CLAUSE_DOACROSS clause inside of OMP_FOR's body. */ + null OMP_ORDERED_BODY inside of OMP_FOR's body. */ static tree find_standalone_omp_ordered (tree *tp, int *walk_subtrees, void *) @@ -12435,7 +12435,7 @@ find_standalone_omp_ordered (tree *tp, i switch (TREE_CODE (*tp)) { case OMP_ORDERED: - if (omp_find_clause (OMP_ORDERED_CLAUSES (*tp), OMP_CLAUSE_DOACROSS)) + if (OMP_ORDERED_BODY (*tp) == NULL_TREE) return *tp; break; case OMP_SIMD: @@ -15839,6 +15839,9 @@ gimplify_expr (tree *expr_p, gimple_seq break; case OMP_ORDERED: g = gimplify_omp_ordered (*expr_p, body); + if (OMP_BODY (*expr_p) == NULL_TREE + && gimple_code (g) == GIMPLE_OMP_ORDERED) + gimple_omp_ordered_standalone (g); break; case OMP_MASKED: gimplify_scan_omp_clauses (&OMP_MASKED_CLAUSES (*expr_p), --- gcc/omp-low.cc.jj 2022-09-03 09:41:34.827006378 +0200 +++ gcc/omp-low.cc 2022-09-05 13:24:30.796236971 +0200 @@ -3718,7 +3718,7 @@ check_omp_nesting_restrictions (gimple * "a loop region with an % clause"); return false; } - if (omp_find_clause (c, OMP_CLAUSE_DOACROSS) == NULL_TREE) + if (!gimple_omp_ordered_standalone_p (stmt)) { if (OMP_CLAUSE_ORDERED_DOACROSS (o)) { @@ -9989,8 +9989,7 @@ lower_omp_ordered (gimple_stmt_iterator bool threads = omp_find_clause (gimple_omp_ordered_clauses (ord_stmt), OMP_CLAUSE_THREADS); - if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt), - OMP_CLAUSE_DOACROSS)) + if (gimple_omp_ordered_standalone_p (ord_stmt)) { /* FIXME: This is needs to be moved to the expansion to verify various conditions only testable on cfg with dominators computed, and also --- gcc/omp-expand.cc.jj 2022-09-03 09:41:34.829006350 +0200 +++ gcc/omp-expand.cc 2022-09-05 13:25:39.328317824 +0200 @@ -10487,8 +10487,7 @@ expand_omp (struct omp_region *region) { gomp_ordered *ord_stmt = as_a (last_stmt (region->entry)); - if (omp_find_clause (gimple_omp_ordered_clauses (ord_stmt), - OMP_CLAUSE_DOACROSS)) + if (gimple_omp_ordered_standalone_p (ord_stmt)) { /* We'll expand these when expanding corresponding worksharing region with ordered(n) clause. */ @@ -10616,9 +10615,7 @@ build_omp_regions_1 (basic_block bb, str } } else if (code == GIMPLE_OMP_ORDERED - && omp_find_clause (gimple_omp_ordered_clauses - (as_a (stmt)), - OMP_CLAUSE_DOACROSS)) + && gimple_omp_ordered_standalone_p (stmt)) /* #pragma omp ordered depend is also just a stand-alone directive. */ region = NULL; @@ -10842,9 +10839,7 @@ omp_make_gimple_edges (basic_block bb, s case GIMPLE_OMP_ORDERED: cur_region = new_omp_region (bb, code, cur_region); fallthru = true; - if (omp_find_clause (gimple_omp_ordered_clauses - (as_a (last)), - OMP_CLAUSE_DOACROSS)) + if (gimple_omp_ordered_standalone_p (last)) cur_region = cur_region->outer; break; --- gcc/cp/pt.cc.jj 2022-09-03 09:41:34.866005829 +0200 +++ gcc/cp/pt.cc 2022-09-05 14:16:25.584362892 +0200 @@ -19526,9 +19526,14 @@ tsubst_expr (tree t, tree args, tsubst_f case OMP_ORDERED: tmp = tsubst_omp_clauses (OMP_ORDERED_CLAUSES (t), C_ORT_OMP, args, complain, in_decl); - stmt = push_stmt_list (); - RECUR (OMP_BODY (t)); - stmt = pop_stmt_list (stmt); + if (OMP_BODY (t)) + { + stmt = push_stmt_list (); + RECUR (OMP_BODY (t)); + stmt = pop_stmt_list (stmt); + } + else + stmt = NULL_TREE; t = copy_node (t); OMP_BODY (t) = stmt; --- gcc/testsuite/c-c++-common/gomp/sink-3.c.jj 2022-09-03 09:41:34.928004956 +0200 +++ gcc/testsuite/c-c++-common/gomp/sink-3.c 2022-09-05 14:07:04.580887813 +0200 @@ -14,7 +14,7 @@ foo () for (i=0; i < 100; ++i) { #pragma omp ordered depend(sink:poo-1,paa+1) /* { dg-error "poo.*declared.*paa.*declared" } */ - bar(&i); /* { dg-error "must not have the same binding region" "" { target *-*-* } .-1 } */ + bar(&i); #pragma omp ordered depend(source) } } --- gcc/testsuite/c-c++-common/gomp/doacross-6.c.jj 2022-09-03 09:41:34.914005153 +0200 +++ gcc/testsuite/c-c++-common/gomp/doacross-6.c 2022-09-05 13:34:20.545312759 +0200 @@ -22,6 +22,18 @@ foo (int n) { #pragma omp ordered doacross(sink) /* { dg-error "expected ':' before '\\\)' token" } */ } + #pragma omp for ordered + for (i = 0; i < 8; i += n) + { + #pragma omp ordered doacross(source) /* { dg-error "expected ':' before '\\\)' token" } */ + #pragma omp ordered doacross(sink:i-1) + } + #pragma omp for ordered + for (i = 0; i < 8; i += n) + { + #pragma omp ordered doacross(source:) + #pragma omp ordered doacross(sink) /* { dg-error "expected ':' before '\\\)' token" } */ + } } void