From patchwork Mon Oct 30 12:30:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 159727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2173656vqb; Mon, 30 Oct 2023 05:30:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtsnNm+nt4QxYo7Gd2p2j+STSk2eHK26mA21MoyUGVLxzX6OjADn5Ex+PLX5gslOD/RyR9 X-Received: by 2002:a05:620a:24c7:b0:775:c0fc:3c4b with SMTP id m7-20020a05620a24c700b00775c0fc3c4bmr9485103qkn.7.1698669056804; Mon, 30 Oct 2023 05:30:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698669056; cv=pass; d=google.com; s=arc-20160816; b=KgrqcFt9iHE5YNwkIA8pDLslh6+6SaPRskh8E/A8MvUxDngiv9IoCtNpsxbnheYsHz d697dziKo3WQtmrqUkxREhtApXDVvraj57S9z5UhcjXpkYBbfEJLoMNVZNeQt4JcYsD8 oXAW2PHAdgHHeNZeaA0X9IXrTdeD2sADwFf820UFjBBDIV88CW1e5WW7ck06Kgu51ox5 ULBRRcR0sQHxIQhowy32OG/IrATJirdFO76UzQx5ZnwdCj5gDJVdiA9kkie3pvEbZ1aY RR60A7HFfqLnywX3412a+X4Q63+jcO8OpQ0kZMmum0LDrapHSOurA13ZtyXA0Z9X2Jal KcsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:to:subject :from:user-agent:mime-version:date:message-id:ironport-sdr :arc-filter:dmarc-filter:delivered-to; bh=ZVHvnmO1WdyzuqHxKHiV+qj4OrkL3eHH3z2sp+ezdZI=; fh=8G0fvw9kezX2+yjwifXgHvTII1omy92vRpR1R+rFCOA=; b=L4vtzTCGLkSUHI4Ani8OhEWYGG2Ia6yZ3H3wzTUMPVl+FMpSs3KCinVOqj2lhgIzCb s2IVkDPOM01+mUl6uml+9S2RfbGuw1y7DkVG4ePK6NlPas3j2ThV74/PIT6A4xiWC9EN i3vbN+YBg6oBhmFXDoIcxQd39/eUZIoFpq6XUfraew/sYpMVabIGvvLNUmo/GZSheuH2 r+L0gk4BZcACGvMca8oRaFu4IFO4hgVtgF91f1mQ68GMNFphZZXjvkfhA0pm6f2a1ca2 kx1T2TGLseAQjyDV4S6+e+1HXHJItlVtVTuNo83xtmtUesAkNDNJCx6v6klR+ix+FZTn 7cNQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x17-20020a05620a259100b00775cab41f33si5514629qko.552.2023.10.30.05.30.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 05:30:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 84A0C385841B for ; Mon, 30 Oct 2023 12:30:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id D89CA3858D28 for ; Mon, 30 Oct 2023 12:30:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D89CA3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D89CA3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.137.180 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698669032; cv=none; b=QBSUq0H8mMm6b60lx/2xdAlcLWkPWu9ZR+2+yYch6Pwu0VWVAGBUNRKmnmTH9RV4VpUXUU2p59WxgM79f3nkLUfUU2H5/8BWTgdNy6G6A+EI+8QALPDqTSSUbcXMKOAetT/8C86M+pJ+tNDOxJc1CIgUMwuIEyJNxn3/Yesyqi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698669032; c=relaxed/simple; bh=iDecSHcd8XI5ehlaD61DN11vZB3qWPYMwDaO5/CerSM=; h=Message-ID:Date:MIME-Version:From:Subject:To; b=b2cf2vVTmiC0dtlwS98VwfXxgn6QZdR+rnQzecOtIJpjeyj97tB47B8dWmQJQw37KbGJ1mmix3h4Q730cP9YrvgbTsSa9YRInct/TYcy8F7NMGtwvDllBnpbxlUDy7oRu2dLN7y6518ylLqyzNl3uXqtdsjzcnagTxT8CJBk6Dk= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: hgqQXIDXTruaVxdRiyd2Nw== X-CSE-MsgGUID: necsLVnjRWeeK3QhgW7ikg== X-IronPort-AV: E=Sophos;i="6.03,263,1694764800"; d="diff'?scan'208,223";a="21283257" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 30 Oct 2023 04:30:23 -0800 IronPort-SDR: IAkps5hMRNwm6px/JeEgu4PNf8AgPw6ZojyaRBbYLLKKFZk3fJUPbJqFb2IwByVW729aQieW9e uD9g1Y1Ju/onqwmsONl0xOg1GIzdo+pm6TSzMFaJ5+A3rudZOMDTffuR07jUmPjozMkkcoro11 SBA7uq9H3dw9obpj2zeJ0hGCaNXK42w9RxIvzDEe+4klHO5ky0CoyCb8ze5k/cQmSI2ub6U+nh MzVbKKmFNZhDudqzClfmJyqrMA1C4KB6HHbHgjvJhA06IDo8i1NV5gMypQJ6NpHzKLkrhFW5xS CyM= Message-ID: Date: Mon, 30 Oct 2023 13:30:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Tobias Burnus Subject: [OG13] OpenMP/Fortran: Merge upstream 'omp allocators' with OG13 'omp allocate' To: gcc-patches Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLACK 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781183604770917188 X-GMAIL-MSGID: 1781183604770917188 To have it also documented via the mailing list... [OG13 = devel/omp/gcc-13] This is above merging a mainline commit to OG13, which is in principle boring. However, as OG13 already had some support for 'omp allocate' with allocatables/pointers, the merge was "interesting". Besides a revert of branch code and fixing merge differences, it also contains code which was in neither commit. That's the main reason to have it here at gcc-patches@gcc a8b1fb51ae5 OpenMP/Fortran: Merge upstream 'omp allocators' with OG13 'omp allocate' Is the attached patch; additionally fixed was a left out fix b687bc195c0 gfortran.dg/gomp/allocate-4a.f90: Update dg-error and a fixup 2cbf164c7fd OpenMP/Fortran: Ensure allocator is gimplified for 'omp allocate' (Both also attached) Plus more or less flawless mainline cherry picks (hash = OG13 hash): f0d163da425 OpenMP: Avoid ICE with LTO and 'omp allocate' 1b9ab8a0f16 OpenMP: Add C++ support for 'omp allocate' with stack variables 59175e6f088 Fortran: Support OpenMP's 'allocate' directive for stack vars 7449921f6a0 Fortran: Fix parse-dump-tree for OpenMP ALLOCATE clause Tobias ----------------- 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 2cbf164c7fd0b84bf3ed361188b8cb014f25a900 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Mon, 30 Oct 2023 10:53:29 +0100 Subject: [PATCH] OpenMP/Fortran: Ensure allocator is gimplified for 'omp allocate' Without this change, we we get an ICE in verify_gimple_call for GOMP_allocate when doing a late replacement in omp-low.cc gcc/fortran/ChangeLog: * trans-openmp.cc (gfc_trans_omp_clauses): Avoid gfc_evaluate_now for allocator with indirect ref for better diagnostic. gcc/ChangeLog: * gcc/gimplify.cc (gimplify_omp_allocate): Gimplify allocator. * omp-low.cc (lower_omp_allocate): Simplify; GOMP_free can also take a plain 0 as allocator argument (arg is unused in libgomp). libgomp/ChangeLog: * testsuite/libgomp.fortran/allocate-8a.f90: New test. --- gcc/ChangeLog.omp | 6 +++ gcc/fortran/ChangeLog.omp | 5 +++ gcc/fortran/trans-openmp.cc | 5 +-- gcc/gimplify.cc | 9 ++++ gcc/omp-low.cc | 7 +-- libgomp/ChangeLog.omp | 4 ++ .../testsuite/libgomp.fortran/allocate-8a.f90 | 44 +++++++++++++++++++ 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 libgomp/testsuite/libgomp.fortran/allocate-8a.f90 diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 570f0b009fe..fd389860a97 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,9 @@ +2023-10-30 Tobias Burnus + + * gcc/gimplify.cc (gimplify_omp_allocate): Gimplify allocator. + * omp-low.cc (lower_omp_allocate): Simplify; GOMP_free can also + take a plain 0 as allocator argument (arg is unused in libgomp). + 2023-10-27 Tobias Burnus Backported from master: diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 2b81cada326..6b30302428f 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,8 @@ +2023-10-30 Tobias Burnus + + * trans-openmp.cc (gfc_trans_omp_clauses): Avoid gfc_evaluate_now + for allocator with indirect ref for better diagnostic. + 2023-10-26 Tobias Burnus Backported from master: diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 30e43cea56c..ab45032eda3 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -4730,11 +4730,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, allocator_ = gfc_trans_omp_variable (n->u2.allocator->symtree->n.sym, false); - if (POINTER_TYPE_P (TREE_TYPE (allocator_))) - { + if (POINTER_TYPE_P (TREE_TYPE (allocator_))) allocator_ = build_fold_indirect_ref (allocator_); - allocator_ = gfc_evaluate_now (allocator_, block); - } } else if (alloc_expr != n->u2.allocator) { diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 2b6e592213f..70fda6bbf0d 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -17876,6 +17876,15 @@ gimplify_omp_allocate (tree *expr_p, gimple_seq *pre_p) kind = GF_OMP_ALLOCATE_KIND_ALLOCATE; else kind = GF_OMP_ALLOCATE_KIND_FREE; + for (tree c = OMP_ALLOCATE_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c)) + { + if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_ALLOCATE) + continue; + + gimplify_expr (&OMP_CLAUSE_ALLOCATE_ALLOCATOR (c), pre_p, NULL, + is_gimple_val, fb_rvalue); + } + gimple *stmt = gimple_build_omp_allocate (OMP_ALLOCATE_CLAUSES (expr), kind); gimplify_seq_add_stmt (pre_p, stmt); diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index 77142589f27..731271e5c96 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -9486,11 +9486,11 @@ lower_omp_allocate (gimple_stmt_iterator *gsi_p) continue; const gcall *gs = as_a (stmt); - tree allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) - ? OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) - : build_zero_cst (ptr_type_node); if (allocate) { + tree allocator = (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) + ? OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) + : build_zero_cst (ptr_type_node)); tree lhs = gimple_call_lhs (gs); if (lhs && TREE_CODE (lhs) == SSA_NAME) { @@ -9559,6 +9559,7 @@ lower_omp_allocate (gimple_stmt_iterator *gsi_p) if (arg == var) { tree repl = builtin_decl_explicit (BUILT_IN_GOMP_FREE); + tree allocator = build_zero_cst (ptr_type_node); gimple *g = gimple_build_call (repl, 2, gimple_call_arg (gs, 0), allocator); diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index d23a4be94a0..4cb8749c152 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,7 @@ +2023-10-30 Tobias Burnus + + * testsuite/libgomp.fortran/allocate-8a.f90: New test. + 2023-10-26 Tobias Burnus * libgomp.texi (OpenMP Impl. Status): Document that 'omp allocate' diff --git a/libgomp/testsuite/libgomp.fortran/allocate-8a.f90 b/libgomp/testsuite/libgomp.fortran/allocate-8a.f90 new file mode 100644 index 00000000000..28fe04fbd58 --- /dev/null +++ b/libgomp/testsuite/libgomp.fortran/allocate-8a.f90 @@ -0,0 +1,44 @@ +! { dg-additional-options "-fdump-tree-omplower" } +program main + use iso_c_binding + use omp_lib + implicit none (type, external) + integer(omp_allocator_handle_kind):: alloc_h + integer :: i, N + integer(c_intptr_t) :: intptr + integer, allocatable :: A(:) + type(omp_alloctrait):: traits(1) = [omp_alloctrait(omp_atk_alignment, 128)] + + N = 10 + alloc_h = omp_init_allocator(omp_default_mem_space, 1, traits) + + !$omp allocate(A) allocator(alloc_h) + allocate(A(N)) + a(:) = [(i, i=1,N)] + if (mod (transfer (loc(a), intptr),128) /= 0) & + stop 1 + if (any (a /= [(i, i=1,N)])) & + stop 2 + deallocate(A) + !$omp allocate(A) allocator(alloc_h) align(512) + allocate(A(N)) + block + integer, allocatable :: B(:) + !$omp allocators allocate(allocator(alloc_h), align(256) : B) + allocate(B(N)) + B(:) = [(2*i, i=1,N)] + A(:) = B + if (mod (transfer (loc(B), intptr), 256) /= 0) & + stop 1 + ! end of scope deallocation + end block + if (mod (transfer (loc(a), intptr),512) /= 0) & + stop 1 + if (any (a /= [(2*i, i=1,N)])) & + stop 2 + deallocate(A) ! Must deallocate here - before deallocator is destroyed + call omp_destroy_allocator(alloc_h) + ! No auto dealloc of A because it is SAVE +end +! { dg-final { scan-tree-dump-times "__builtin_GOMP_alloc \\(" 3 "omplower" } } +! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 3 "omplower" } } -- 2.34.1