From patchwork Thu Sep 16 13:06:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 45081 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22EAC3857432 for ; Thu, 16 Sep 2021 13:07:28 +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 63CC03857435; Thu, 16 Sep 2021 13:06:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63CC03857435 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: 8TDm+FjX8N7z4GSxjr/y2/FgvMsfs4JPyG/qBIFhvuGqkAH6OVCz7vn5zgt4NZmtaKrHaTfuFh LNH1Aqp+TB4OIVqYgkdr9iHuGQQQZxLBbKglfa0OmP4R4o/3oXtErWuvf40lpB1Bp/o4bDY0r/ 3+W+p9kp7UArA2BiIie/pfjo+hxLPKfK1n5SMSsl7z220pxdLxdhmEw1aui5PNyJjXSUIwY6a/ VIcV/fCJs03CluTvs+qxvoOZhcsAhZmwWkDq+ndNduIJyR2RUzy/nUFv8OxPM4Mt54g8rRb2fB zV6wew3QrrHTai0HhUVTCzS/ X-IronPort-AV: E=Sophos;i="5.85,298,1624348800"; d="diff'?scan'208";a="66123981" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 16 Sep 2021 05:06:39 -0800 IronPort-SDR: K9rLfWU1LzRRGGGmdvDd1vVrMIH4xvGfjZY5ALPCh+WFqvbOY4ezOiHkGnBVu97smKq+h5O5zZ 4pp6kbuWXv3oodCtar5jqKC9K96f8HYmI0tQ7KLVq2ysdto6ricf3vj8C1MaxnSA3xfJBHhQJi pg6DZJl2PxYbCbZnwNZVBVqix1TOzMhINlbh9VvUVEIg4PGyiNoidbXK2rtbwtelErvXWMt+U3 l2exhrTyDYOxYuFIfMl92Du+2Iu0p5tvDr90J4ChVQXQrTuilIoGE3cXnHECcIB5+k06oTkHfb lYw= To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran: Add gfc_simple_for_loop aux function Message-ID: Date: Thu, 16 Sep 2021 15:06:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.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 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds a useful auxiliary function to generate a loop. I intent to use it for: (A) An updated/cleaned-up version of "[Patch] Fortran: Fix Bind(C) Array-Descriptor Conversion (Move to Front-End Code)" https://gcc.gnu.org/pipermail/gcc-patches/2021-September/578904.html → new function used four times (B) For the SIZE handling part of PR94070 - Assumed-rank arrays – bounds mishandled, SIZE/SHAPE/UBOUND/LBOUND which I am currently writing (→ used once) The main reason of splitting this patch off is to permit to be able to submit/commit the two patches separately without having a code overlap. However, in principle there is no reason that this patch cannot be reviewed and/or committed separately instead of in the same review and/or commit with one of the other patches. 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 Fortran: Add gfc_simple_for_loop aux function Function to generate a simple loop (to be used internally). Callers will be added in follow-up commits. gcc/fortran/ * trans-expr.c (gfc_simple_for_loop): New. * trans.h (gfc_simple_for_loop): New prototype. diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 18d665192f0..761f8c65234 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -11717,3 +11717,37 @@ gfc_trans_assign (gfc_code * code) { return gfc_trans_assignment (code->expr1, code->expr2, false, true); } + +/* Generate a simple loop for internal use of the form + for (var = begin; var end; var += step) + body; */ +void +gfc_simple_for_loop (stmtblock_t *block, tree var, tree begin, tree end, + enum tree_code cond, tree step, tree body) +{ + tree tmp; + + /* var = begin. */ + gfc_add_modify (block, var, begin); + + /* Loop: for (var = begin; var end; var += step). */ + tree label_loop = gfc_build_label_decl (NULL_TREE); + tree label_cond = gfc_build_label_decl (NULL_TREE); + TREE_USED (label_loop) = 1; + TREE_USED (label_cond) = 1; + + gfc_add_expr_to_block (block, build1_v (GOTO_EXPR, label_cond)); + gfc_add_expr_to_block (block, build1_v (LABEL_EXPR, label_loop)); + + /* Loop body. */ + gfc_add_expr_to_block (block, body); + + /* End of loop body. */ + tmp = fold_build2_loc (input_location, PLUS_EXPR, TREE_TYPE (var), var, step); + gfc_add_modify (block, var, tmp); + gfc_add_expr_to_block (block, build1_v (LABEL_EXPR, label_cond)); + tmp = fold_build2_loc (input_location, cond, boolean_type_node, var, end); + tmp = build3_v (COND_EXPR, tmp, build1_v (GOTO_EXPR, label_loop), + build_empty_stmt (input_location)); + gfc_add_expr_to_block (block, tmp); +} diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 78578cfd732..1b622fc1f2e 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -518,6 +518,8 @@ tree gfc_string_to_single_character (tree len, tree str, int kind); tree gfc_get_tree_for_caf_expr (gfc_expr *); void gfc_get_caf_token_offset (gfc_se*, tree *, tree *, tree, tree, gfc_expr *); tree gfc_caf_get_image_index (stmtblock_t *, gfc_expr *, tree); +void gfc_simple_for_loop (stmtblock_t *, tree, tree, tree, enum tree_code, tree, + tree); /* Find the decl containing the auxiliary variables for assigned variables. */