From patchwork Thu Nov 25 14:08:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1559732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0KYx2KPZz9sVc for ; Fri, 26 Nov 2021 01:11:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C6C2385843B for ; Thu, 25 Nov 2021 14:11:47 +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 AF87A385843F for ; Thu, 25 Nov 2021 14:08:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF87A385843F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: yLXA0i34hcm9ecfre1RSC64HOZznMGq21YVLuFMOE7KP6v7Ceaim8g1TzffhetwIYEaismWKHt 5QYKPoyzXY+uH8GUxWSZ5qlYxXt1+FXZ66JLLKJPLf14etE/NiRlq2JGO5vgvG5BiA609j9uSN CnP/p71LNGcf0vNsna92TQ0F7i5IsjhqU211j5z2qp4AZ5Xczb4cN3wSAZ8Ov/kEZ/M8DerRa3 FPo/BJRdlyy4UV0cW6ZT1/XsyEEbvhy4wVh4Frd6MOBepe9T/RUH1SElD37G9SNklXNc12boql MbDcuRWgxlHbdLjLsJyXh/s2 X-IronPort-AV: E=Sophos;i="5.87,263,1631606400"; d="scan'208";a="68932309" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 25 Nov 2021 06:08:52 -0800 IronPort-SDR: aTuhWWNi1bhi2qtUGyAMsPTux7fY1ieOaBeMd9sUmmWonV3dG7uAz1Rxd7HqZ53Sh9hodKKidg IxygOn/VM7esTu0ziEMTcQ8z0QeeAc8oQP0rCQXuDjXoeEkgy4pJQtSPw5U3bO8xcWwZAC4GU7 4VFLqEhJ2P8LqoXfiWfxWQY7bYGaJufpH5I0qSoKMPqFWItILNMezqXRvILmnA+EZM2YZzwmtR cPrJF/m8yEeHD9YeuF3ugIqAft1cETvxceC82OE4R44bFC7w9h2skIROO1EjjI97WBdMiz50rZ uPk= From: Julian Brown To: Subject: [PATCH 05/16] Remove base_ind/base_ref handling from extract_base_bit_offset Date: Thu, 25 Nov 2021 06:08:39 -0800 Message-ID: <20211125140843.111405-1-julian@codesourcery.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Jakub Jelinek , Thomas Schwinge Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In preparation for follow-up patches extending struct dereference handling for OpenMP, this patch removes base_ind/base_ref handling from gimplify.c:extract_base_bit_offset. This arguably simplifies some of the code around the callers of the function also, though subsequent patches modify those parts further. (This one has already been approved, pending approval of the rest of the series: https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581426.html) 2021-09-29 Julian Brown gcc/ * gimplify.c (extract_base_bit_offset): Remove BASE_IND, BASE_REF and OPENMP parameters. (strip_indirections): New function. (build_struct_group): Update calls to extract_base_bit_offset. Rearrange indirect/reference handling accordingly. Use extracted base instead of passed-in decl when grouping component accesses together. --- gcc/gimplify.c | 109 ++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 52 deletions(-) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index fcc278d07cf..73b839daa09 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -8658,9 +8658,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_ind, tree *base_ref, - poly_int64 *bitposp, poly_offset_int *poffsetp, - tree *offsetp, bool openmp) +extract_base_bit_offset (tree base, poly_int64 *bitposp, + poly_offset_int *poffsetp, tree *offsetp) { tree offset; poly_int64 bitsize, bitpos; @@ -8668,38 +8667,12 @@ extract_base_bit_offset (tree base, tree *base_ind, tree *base_ref, int unsignedp, reversep, volatilep = 0; poly_offset_int poffset; - if (base_ind) - *base_ind = NULL_TREE; - - if (base_ref) - *base_ref = NULL_TREE; + STRIP_NOPS (base); base = get_inner_reference (base, &bitsize, &bitpos, &offset, &mode, &unsignedp, &reversep, &volatilep); - if (!openmp - && (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) - { - if (base_ref) - *base_ref = base; - base = TREE_OPERAND (base, 0); - } - - if (!openmp) - STRIP_NOPS (base); + STRIP_NOPS (base); if (offset && poly_int_tree_p (offset)) { @@ -8756,6 +8729,17 @@ strip_components_and_deref (tree expr) return expr; } +static tree +strip_indirections (tree expr) +{ + while (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: @@ -9249,7 +9233,7 @@ build_struct_group (struct gimplify_omp_ctx *ctx, { poly_offset_int coffset; poly_int64 cbitpos; - tree base_ind, base_ref, tree_coffset; + tree tree_coffset; tree ocd = OMP_CLAUSE_DECL (c); bool openmp = !(region_type & ORT_ACC); @@ -9259,10 +9243,25 @@ build_struct_group (struct gimplify_omp_ctx *ctx, if (TREE_CODE (ocd) == INDIRECT_REF) ocd = TREE_OPERAND (ocd, 0); - tree base = extract_base_bit_offset (ocd, &base_ind, &base_ref, &cbitpos, - &coffset, &tree_coffset, openmp); + tree base = extract_base_bit_offset (ocd, &cbitpos, &coffset, &tree_coffset); + tree sbase; - bool do_map_struct = (base == decl && !tree_coffset); + if (openmp) + { + if (TREE_CODE (base) == INDIRECT_REF + && TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) == REFERENCE_TYPE) + sbase = strip_indirections (base); + else + sbase = base; + } + else + { + sbase = strip_indirections (base); + + STRIP_NOPS (sbase); + } + + bool do_map_struct = (sbase == decl && !tree_coffset); /* Here, DECL is usually a DECL_P, unless we have chained indirect member accesses, e.g. mystruct->a->b. In that case it'll be the "mystruct->a" @@ -9322,19 +9321,12 @@ build_struct_group (struct gimplify_omp_ctx *ctx, OMP_CLAUSE_SET_MAP_KIND (l, k); - if (!openmp && base_ind) - OMP_CLAUSE_DECL (l) = unshare_expr (base_ind); - else if (base_ref) - OMP_CLAUSE_DECL (l) = unshare_expr (base_ref); - else - { - OMP_CLAUSE_DECL (l) = unshare_expr (decl); - if (openmp - && !DECL_P (OMP_CLAUSE_DECL (l)) - && (gimplify_expr (&OMP_CLAUSE_DECL (l), pre_p, NULL, - is_gimple_lvalue, fb_lvalue) == GS_ERROR)) - return error_mark_node; - } + OMP_CLAUSE_DECL (l) = unshare_expr (base); + if (openmp + && !DECL_P (OMP_CLAUSE_DECL (l)) + && (gimplify_expr (&OMP_CLAUSE_DECL (l), pre_p, NULL, + is_gimple_lvalue, fb_lvalue) == GS_ERROR)) + return error_mark_node; OMP_CLAUSE_SIZE (l) = (!attach ? size_int (1) : (DECL_P (OMP_CLAUSE_DECL (l)) @@ -9370,6 +9362,20 @@ build_struct_group (struct gimplify_omp_ctx *ctx, else list_p = insert_node_after (l, list_p); + bool base_ref + = (TREE_CODE (base) == INDIRECT_REF + && ((TREE_CODE (TREE_TYPE (TREE_OPERAND (base, 0))) + == REFERENCE_TYPE) + || ((TREE_CODE (TREE_OPERAND (base, 0)) == INDIRECT_REF) + && (TREE_CODE (TREE_TYPE (TREE_OPERAND + (TREE_OPERAND (base, 0), 0))) + == REFERENCE_TYPE)))); + bool base_ind = ((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)); + /* Handle pointers to structs and references to structs: these cases have an additional GOMP_MAP_FIRSTPRIVATE_{REFERENCE,POINTER} node inserted after the GOMP_MAP_STRUCT node. References to pointers @@ -9502,10 +9508,9 @@ build_struct_group (struct gimplify_omp_ctx *ctx, == REFERENCE_TYPE)) sc_decl = TREE_OPERAND (sc_decl, 0); - tree base = extract_base_bit_offset (sc_decl, NULL, NULL, - &bitpos, &offset, - &tree_offset, openmp); - if (!base || !operand_equal_p (base, decl, 0)) + tree base2 = extract_base_bit_offset (sc_decl, &bitpos, &offset, + &tree_offset); + if (!base2 || !operand_equal_p (base2, base, 0)) break; if (scp) continue;