From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR06-DB8-obe.outbound.protection.outlook.com (mail-db8eur06olkn2082.outbound.protection.outlook.com [40.92.51.82]) by sourceware.org (Postfix) with ESMTPS id DD1163860C37; Mon, 17 May 2021 12:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DD1163860C37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bernd.edlinger@hotmail.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CVgdc9vNjNc+EQcbrIKW0yW6/r+cXr5QYMcbDpZL5Y5xpyMXyTwckpJ+/beIh3WyiNvSdBlqVigfqpkOewmUS55Ckvba8ctxjzNKkhSnOFdkLJ5KhnmUbOqJntk/VQ32yFufU5CfjUxHy3q+Ei6lD7Iaht2QeAATfwanbRHkXlDdwxbmMMp0/s0sGMGGMQ6HwyY2sMXWQfPLgSzUz/oEWJxkIGJXrQpkXw1uM8KOmsRJ0W2WZsyJnzqtNULGdRbabmW8216z6nmpcYDyWNV2IYMcxyOoLseRZyxNYgBz1SUcbZaNjlnFyhztAyU505AyxZkEWK6QOW2PPa9EFkJLRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oR7IJZr+MBmZYoN1jcbox2gg7A+Ql3ZpvqVL30mp3co=; b=N3Tb3B52uqrgVuZdbTX2bV0RntgU185J78LQHq695gT1ZTOE40wvHxUUXs1rYGEQKnUy2l+eFncM/3ix44hzt+c1SftgNnmyQVk1sbsHe1XRx8x+KtFM/uIY2yOMvNBrfuke1OfQFm/zbSDVSjDXxsNB/W7hcEqon5pF5LPa643UUiuAZZoHLjx4Thl1oOBPZyk1fZL+iw2OowJrKBf+btpcC8ST7AErj3EnNu8nWEwTXgEBhA2ozLH01vvwViRqAjnxw9G0ytARFqfHcUAkyACDtg8le9O4kILd29iF7HsiUF3DiROlvhCPdZXLzG6iU/pG0559ujoGB9J8PtWPAQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DB8EUR06FT007.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::46) by DB8EUR06HT152.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::288) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Mon, 17 May 2021 12:12:03 +0000 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:fc35::48) by DB8EUR06FT007.mail.protection.outlook.com (2a01:111:e400:fc35::171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25 via Frontend Transport; Mon, 17 May 2021 12:12:03 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:C45F3C65CFB0CDE3166887A45B15C166FFA7349F0039111E103212F31950C2EF; UpperCasedChecksum:895FE22AFF8BCF89730939AF16CB3D82F5E5DCED1E610521A419F3FD3B4B716A; SizeAsReceived:8157; Count:48 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::e41b:107f:af82:150a]) by AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::e41b:107f:af82:150a%7]) with mapi id 15.20.4129.031; Mon, 17 May 2021 12:12:03 +0000 Subject: Re: [PATCH 4/5] Rework indirect struct handling for OpenACC/OpenMP in gimplify.c To: Julian Brown , gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , Tobias Burnus , Chung-Lin Tang , Thomas Schwinge , fortran@gcc.gnu.org References: From: Bernd Edlinger Message-ID: Date: Mon, 17 May 2021 14:12:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TMN: [JvhUSZg6pB7GBlceRkpUtndkidzMlP2Q] X-ClientProxiedBy: PR0P264CA0164.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1b::32) To AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:364::23) X-Microsoft-Original-Message-ID: <95d38f8b-6b70-d67b-431d-55b0f17c790c@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (84.57.61.94) by PR0P264CA0164.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1b::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 17 May 2021 12:12:02 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5ef1836c-fcb1-4bf3-4845-08d9192cfaed X-MS-TrafficTypeDiagnostic: DB8EUR06HT152: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ofRoaRz89NNAUelD0PcTN+5Lmm+g5dZguQ4PgHJIjv+ODzcLVr2t7XlH99GH4kBPijGD37lPz/VSewwkk0+FfgQ7OX24+AChyxTHgB2OiSfb+xCjmhA0BKFN02u/xJpyx+eG90/zQDAy5y39feShx7FnqVVX/Odn4jTl0b9zKQz6Z6Wb2jj1dlfZ4pjOce6POmNv/C04jdCqiRLeRNHoCqGgmb8dFLeg2mtRi5KNOdKMQ2FHC9SsMyeYqJfBgykVbUA5Jhycd50DgXu9nvN8h1Tu3vUmYEyLC06EcWB9wq+EMEQEc1VjsdlZ2EGdAuaBSomVWqkmhYFWUs+s2RZsLcljX+B5bnb88wE9c0JP+/TWC2qiiGI7m6bkBg5PIIkkt7G3RE4g6cxHdJjLlHZPMA== X-MS-Exchange-AntiSpam-MessageData: lAGblh9We0G7LE/2FZQT5v94Eju/wMrwAZcdY+6EcjwIBwQYVIaw+vU+k1fJilDlh4ISTxQmE4uOqQ6ynel8Wn1wv32ezXmfV/ow/kTUsGbfwR34H9RaAgNs2hRYVb/QWx1HQtr4hT4uX2jjmWM0WA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ef1836c-fcb1-4bf3-4845-08d9192cfaed X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2021 12:12:03.3992 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR06FT007.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR06HT152 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, FORGED_MUA_MOZILLA, FREEMAIL_FROM, GIT_PATCH_0, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 17 May 2021 12:12:08 -0000 On 5/14/21 11:26 PM, Julian Brown wrote: > This patch reworks indirect struct handling in gimplify.c (i.e. for struct > components mapped with "mystruct->a[0:n]", "mystruct->b", etc.), for > both OpenACC and OpenMP. The key observation leading to these changes > was that component mappings of references-to-structures is already > implemented and working, and indirect struct component handling via a > pointer can work quite similarly. That lets us remove some earlier, > special-case handling for mapping indirect struct component accesses > for OpenACC, which required the pointed-to struct to be manually mapped > before the indirect component mapping. > > With this patch, you can map struct components directly (e.g. an array > slice "mystruct->a[0:n]") just like you can map a non-indirect struct > component slice ("mystruct.a[0:n]"). Both references-to-pointers (with > the former syntax) and references to structs (with the latter syntax) > work now. > > For Fortran class pointers, we no longer re-use GOMP_MAP_TO_PSET for the > class metadata (the structure that points to the class data and vptr) > -- it is instead treated as any other struct. > > For C++, the struct handling also works for class members ("this->foo"), > without having to explicitly map "this[:1]" first. > > For OpenACC, we permit chained indirect component references > ("mystruct->a->b[0:n]"), though only the last part of such mappings will > trigger an attach/detach operation. To properly use such a construct > on the target, you must still manually map "mystruct->a[:1]" first -- > but there's no need to map "mystruct[:1]" explicitly before that. > > This patch incorporates parts of Chung-Lin's patch "Recommit "Enable > gimplify GOMP_MAP_STRUCT handling of (COMPONENT_REF (INDIRECT_REF > ...)) map clauses"." from the og10 branch. > > OK for trunk? > > Thanks, > > Julian > > 2021-05-14 Julian Brown > Chung-Lin Tang > > gcc/fortran/ > * trans-openmp.c (gfc_trans_omp_clauses): Don't create GOMP_MAP_TO_PSET > mappings for class metadata, nor GOMP_MAP_POINTER mappings for > POINTER_TYPE_P decls. > > gcc/ > * gimplify.c (tree-hash-traits.h): Include. > (extract_base_bit_offset): Add BASE_IND parameter. Handle > pointer-typed indirect references alongside reference-typed ones. > (strip_components_and_deref, aggregate_base_p): New functions. > (build_struct_group): Update struct_map_to_clause type. Add pointer > type indirect ref handling, including chained references. Handle > pointers and references to structs in OpenACC regions as well as > OpenMP ones. > (gimplify_scan_omp_clauses): Remove struct_deref_set handling. Rework > pointer-type indirect structure access handling to work more like > the reference-typed handling. > * omp-low.c (scan_sharing_clauses): Handle pointer-type indirect struct > references, and references to pointers to structs also. > > gcc/testsuite/ > * g++.dg/goacc/member-array-acc.C: New test (XFAILed for now). > * g++.dg/gomp/member-array-omp.C: New test (XFAILed for now). > > libgomp/ > * testsuite/libgomp.oacc-c-c++-common/deep-copy-15.c: New test. > * testsuite/libgomp.oacc-c-c++-common/deep-copy-16.c: New test. > * testsuite/libgomp.oacc-c++/deep-copy-17.C: New test. > --- > gcc/fortran/trans-openmp.c | 20 +- > gcc/gimplify.c | 285 ++++++++++-------- > gcc/omp-low.c | 16 +- > gcc/testsuite/g++.dg/goacc/member-array-acc.C | 14 + > gcc/testsuite/g++.dg/gomp/member-array-omp.C | 14 + > .../testsuite/libgomp.oacc-c++/deep-copy-17.C | 101 +++++++ > .../libgomp.oacc-c-c++-common/deep-copy-15.c | 71 +++++ > .../libgomp.oacc-c-c++-common/deep-copy-16.c | 231 ++++++++++++++ > 8 files changed, 612 insertions(+), 140 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/goacc/member-array-acc.C > create mode 100644 gcc/testsuite/g++.dg/gomp/member-array-omp.C > create mode 100644 libgomp/testsuite/libgomp.oacc-c++/deep-copy-17.C > create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-15.c > create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/deep-copy-16.c > > diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c > index 5666cd68c7e..ff614ffe744 100644 > --- a/gcc/fortran/trans-openmp.c > +++ b/gcc/fortran/trans-openmp.c > @@ -2721,30 +2721,16 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, > tree present = gfc_omp_check_optional_argument (decl, true); > if (openacc && n->sym->ts.type == BT_CLASS) > { > - tree type = TREE_TYPE (decl); > if (n->sym->attr.optional) > sorry ("optional class parameter"); > - if (POINTER_TYPE_P (type)) > - { > - node4 = build_omp_clause (input_location, > - OMP_CLAUSE_MAP); > - OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER); > - OMP_CLAUSE_DECL (node4) = decl; > - OMP_CLAUSE_SIZE (node4) = size_int (0); > - decl = build_fold_indirect_ref (decl); > - } > tree ptr = gfc_class_data_get (decl); > ptr = build_fold_indirect_ref (ptr); > OMP_CLAUSE_DECL (node) = ptr; > OMP_CLAUSE_SIZE (node) = gfc_class_vtab_size_get (decl); > node2 = build_omp_clause (input_location, OMP_CLAUSE_MAP); > - OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_TO_PSET); > - OMP_CLAUSE_DECL (node2) = decl; > - OMP_CLAUSE_SIZE (node2) = TYPE_SIZE_UNIT (type); > - node3 = build_omp_clause (input_location, OMP_CLAUSE_MAP); > - OMP_CLAUSE_SET_MAP_KIND (node3, GOMP_MAP_ATTACH_DETACH); > - OMP_CLAUSE_DECL (node3) = gfc_class_data_get (decl); > - OMP_CLAUSE_SIZE (node3) = size_int (0); > + OMP_CLAUSE_SET_MAP_KIND (node2, GOMP_MAP_ATTACH_DETACH); > + OMP_CLAUSE_DECL (node2) = gfc_class_data_get (decl); > + OMP_CLAUSE_SIZE (node2) = size_int (0); > goto finalize_map_clause; > } > else if (POINTER_TYPE_P (TREE_TYPE (decl)) > diff --git a/gcc/gimplify.c b/gcc/gimplify.c > index 69ab637367c..c0f068a725d 100644 > --- a/gcc/gimplify.c > +++ b/gcc/gimplify.c > @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3. If not see > #include "langhooks.h" > #include "tree-cfg.h" > #include "tree-ssa.h" > +#include "tree-hash-traits.h" > #include "omp-general.h" > #include "omp-low.h" > #include "gimple-low.h" > @@ -8351,8 +8352,8 @@ build_struct_comp_nodes (enum tree_code code, tree grp_start, tree grp_end, > has array type, else return NULL. */ > > static tree > -extract_base_bit_offset (tree base, tree *base_ref, poly_int64 *bitposp, > - poly_offset_int *poffsetp) > +extract_base_bit_offset (tree base, tree *base_ind, tree *base_ref, > + poly_int64 *bitposp, poly_offset_int *poffsetp) > { > tree offset; > poly_int64 bitsize, bitpos; > @@ -8360,6 +8361,9 @@ extract_base_bit_offset (tree base, tree *base_ref, poly_int64 *bitposp, > int unsignedp, reversep, volatilep = 0; > poly_offset_int poffset; > > + if (base_ind) > + *base_ind = NULL_TREE; > + > if (base_ref) > *base_ref = NULL_TREE; > > @@ -8380,14 +8384,27 @@ extract_base_bit_offset (tree base, tree *base_ref, poly_int64 *bitposp, > base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode, > &unsignedp, &reversep, &volatilep); > > - tree orig_base = base; > - > + if ((TREE_CODE (base) == INDIRECT_REF > + || (TREE_CODE (base) == MEM_REF > + && integer_zerop (TREE_OPERAND (base, 1)))) > + && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == POINTER_TYPE) > + { > + if (base_ind) > + *base_ind = base; > + base = TREE_OPERAND (base, 0); > + } > if ((TREE_CODE (base) == INDIRECT_REF > || (TREE_CODE (base) == MEM_REF > && integer_zerop (TREE_OPERAND (base, 1)))) > && DECL_P (TREE_OPERAND (base, 0)) > && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == REFERENCE_TYPE) > - base = TREE_OPERAND (base, 0); > + { > + if (base_ref) > + *base_ref = base; > + base = TREE_OPERAND (base, 0); > + } > + > + STRIP_NOPS (base); > > gcc_assert (offset == NULL_TREE || poly_int_tree_p (offset)); > > @@ -8402,10 +8419,6 @@ extract_base_bit_offset (tree base, tree *base_ref, poly_int64 *bitposp, > *bitposp = bitpos; > *poffsetp = poffset; > > - /* Set *BASE_REF if BASE was a dereferenced reference variable. */ > - if (base_ref && orig_base != base) > - *base_ref = orig_base; > - > return base; > } > > @@ -8422,6 +8435,48 @@ is_or_contains_p (tree expr, tree base_ptr) > return expr == base_ptr; > } > > +/* Remove COMPONENT_REFS and indirections from EXPR. */ > + > +static tree > +strip_components_and_deref (tree expr) > +{ > + while (TREE_CODE (expr) == COMPONENT_REF > + || TREE_CODE (expr) == INDIRECT_REF > + || (TREE_CODE (expr) == MEM_REF > + && integer_zerop (TREE_OPERAND (expr, 1)))) > + expr = TREE_OPERAND (expr, 0); > + > + return expr; > +} > + > +/* Return TRUE if EXPR is something we will use as the base of an aggregate > + access, either: > + > + - a DECL_P. > + - a struct component with no indirection ("a.b.c"). > + - a struct component with indirection ("a->b->c"). > +*/ > + > +static bool > +aggregate_base_p (tree expr) > +{ > + while (TREE_CODE (expr) == COMPONENT_REF > + && (DECL_P (TREE_OPERAND (expr, 0)) > + || (TREE_CODE (TREE_OPERAND (expr, 0)) == COMPONENT_REF))) > + expr = TREE_OPERAND (expr, 0); > + > + if (DECL_P (expr)) > + return true; > + > + if (TREE_CODE (expr) == COMPONENT_REF > + && (TREE_CODE (TREE_OPERAND (expr, 0)) == INDIRECT_REF > + || (TREE_CODE (TREE_OPERAND (expr, 0)) == MEM_REF > + && integer_zerop (TREE_OPERAND (TREE_OPERAND (expr, 0), 1))))) > + return true; > + > + return false; > +} > + > /* Implement OpenMP 5.x map ordering rules for target directives. There are > several rules, and with some level of ambiguity, hopefully we can at least > collect the complexity here in one place. */ > @@ -8715,19 +8770,26 @@ static tree > build_struct_group (struct gimplify_omp_ctx *ctx, > enum omp_region_type region_type, enum tree_code code, > tree decl, unsigned int *flags, tree c, > - hash_map *&struct_map_to_clause, > + hash_map *&struct_map_to_clause, > tree *&prev_list_p, tree *&list_p, bool *cont) > { > poly_offset_int coffset; > poly_int64 cbitpos; > - tree base_ref; > + tree base_ind, base_ref; > + tree *list_in_p = list_p, *prev_list_in_p = prev_list_p; > Is this a kind of debug code? This fails to compile: ../../gcc-trunk/gcc/gimplify.c: In function ‘tree_node* build_struct_group(gimplify_omp_ctx*, omp_region_type, tree_code, tree, unsigned int*, tree, hash_map*&, tree_node**&, tree_node**&, bool*)’: ../../gcc-trunk/gcc/gimplify.c:8779:9: error: unused variable ‘list_in_p’ [-Werror=unused-variable] 8779 | tree *list_in_p = list_p, *prev_list_in_p = prev_list_p; | ^~~~~~~~~ ../../gcc-trunk/gcc/gimplify.c:8779:30: error: unused variable ‘prev_list_in_p’ [-Werror=unused-variable] 8779 | tree *list_in_p = list_p, *prev_list_in_p = prev_list_p; | ^~~~~~~~~~~~~~ You need to boot-strap and do your regression testing before sending a patch to this list. Thanks Bernd.