From patchwork Wed Aug 26 08:13:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1351695 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=kqRNg+CN; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4BbzCh1bn6z9sSJ for ; Wed, 26 Aug 2020 18:14:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E56D0385DC2E; Wed, 26 Aug 2020 08:14:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E56D0385DC2E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598429646; bh=YiKMXWbWmYUulcXD/XtRxz2rQ8aCErxSbyUEqbfVMbI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kqRNg+CN+VWdanTeuEhckf1yzrU/pFNwFcWNUecNDWXKlfY5HAXwcit0zAZFLA9sn QbII/KWEcsWBvGdLk8BBCqd9tiRFwjQILOAg6im+dmFyVIbTZQ4dOyavcNRsZ65KmW 89PC1jD1NGOazOoHxEM4enzDqooKSXKDLm/fAFJs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id E31453857C4D for ; Wed, 26 Aug 2020 08:14:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E31453857C4D Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4BbzCW4MBGzQlWV; Wed, 26 Aug 2020 10:13:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id kYSpEvQFCvXX; Wed, 26 Aug 2020 10:13:46 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Move d_gimplify_expr and dependencies to d-gimplify.cc Date: Wed, 26 Aug 2020 10:13:42 +0200 Message-Id: <20200826081342.450717-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.21 / 15.00 / 15.00 X-Rspamd-Queue-Id: 750F817D5 X-Rspamd-UID: 0bf4b7 X-Spam-Status: No, score=-15.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch moves D-specific tree lowering parts to its own file. Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, committed to mainline. Regards Iain --- gcc/d/ChangeLog: * Make-lang.in (D_OBJS): Add d-gimplify.o. * d-lang.cc (empty_modify_p): Move to d-gimplify.cc. (d_gimplify_expr): Likewise. * d-tree.h (d_gimplify_expr): Declare. * d-gimplify.cc: New file. --- gcc/d/Make-lang.in | 1 + gcc/d/d-gimplify.cc | 187 ++++++++++++++++++++++++++++++++++++++++++++ gcc/d/d-lang.cc | 160 ------------------------------------- gcc/d/d-tree.h | 3 + 4 files changed, 191 insertions(+), 160 deletions(-) create mode 100644 gcc/d/d-gimplify.cc diff --git a/gcc/d/Make-lang.in b/gcc/d/Make-lang.in index 6c8c611a0f7..18d99abab35 100644 --- a/gcc/d/Make-lang.in +++ b/gcc/d/Make-lang.in @@ -141,6 +141,7 @@ D_OBJS = \ d/d-ctfloat.o \ d/d-diagnostic.o \ d/d-frontend.o \ + d/d-gimplify.o \ d/d-incpath.o \ d/d-lang.o \ d/d-longdouble.o \ diff --git a/gcc/d/d-gimplify.cc b/gcc/d/d-gimplify.cc new file mode 100644 index 00000000000..ed49e5f8dc4 --- /dev/null +++ b/gcc/d/d-gimplify.cc @@ -0,0 +1,187 @@ +/* D-specific tree lowering bits; see also gimple.c. + Copyright (C) 2020 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" + +#include "dmd/globals.h" + +#include "tree.h" +#include "gimple-expr.h" +#include "gimplify.h" + +#include "d-tree.h" + + +/* Return TRUE if an operand OP of a given TYPE being copied has no data. + The middle-end does a similar check with zero sized types. */ + +static bool +empty_modify_p (tree type, tree op) +{ + tree_code code = TREE_CODE (op); + switch (code) + { + case COMPOUND_EXPR: + return empty_modify_p (type, TREE_OPERAND (op, 1)); + + case CONSTRUCTOR: + /* Non-empty construcors are valid. */ + if (CONSTRUCTOR_NELTS (op) != 0 || TREE_CLOBBER_P (op)) + return false; + break; + + case CALL_EXPR: + /* Leave nrvo alone because it isn't a copy. */ + if (CALL_EXPR_RETURN_SLOT_OPT (op)) + return false; + break; + + default: + /* If the operand doesn't have a simple form. */ + if (!is_gimple_lvalue (op) && !INDIRECT_REF_P (op)) + return false; + break; + } + + return empty_aggregate_p (type); +} + +/* Implements the lang_hooks.gimplify_expr routine for language D. + Do gimplification of D specific expression trees in EXPR_P. */ + +int +d_gimplify_expr (tree *expr_p, gimple_seq *pre_p, + gimple_seq *post_p ATTRIBUTE_UNUSED) +{ + tree_code code = TREE_CODE (*expr_p); + enum gimplify_status ret = GS_UNHANDLED; + tree op0, op1; + tree type; + + switch (code) + { + case INIT_EXPR: + case MODIFY_EXPR: + op0 = TREE_OPERAND (*expr_p, 0); + op1 = TREE_OPERAND (*expr_p, 1); + + if (!error_operand_p (op0) && !error_operand_p (op1) + && (AGGREGATE_TYPE_P (TREE_TYPE (op0)) + || AGGREGATE_TYPE_P (TREE_TYPE (op1))) + && !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0))) + { + /* If the back end isn't clever enough to know that the lhs and rhs + types are the same, add an explicit conversion. */ + TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR, + TREE_TYPE (op0), op1); + ret = GS_OK; + } + else if (empty_modify_p (TREE_TYPE (op0), op1)) + { + /* Remove any copies of empty aggregates. */ + gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, + is_gimple_lvalue, fb_lvalue); + + if (TREE_SIDE_EFFECTS (op1)) + gimplify_and_add (op1, pre_p); + + *expr_p = TREE_OPERAND (*expr_p, 0); + ret = GS_OK; + } + break; + + case ADDR_EXPR: + op0 = TREE_OPERAND (*expr_p, 0); + /* Constructors are not lvalues, so make them one. */ + if (TREE_CODE (op0) == CONSTRUCTOR) + { + TREE_OPERAND (*expr_p, 0) = force_target_expr (op0); + ret = GS_OK; + } + break; + + case CALL_EXPR: + if (CALL_EXPR_ARGS_ORDERED (*expr_p)) + { + /* Strictly evaluate all arguments from left to right. */ + int nargs = call_expr_nargs (*expr_p); + location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location); + + /* No need to enforce evaluation order if only one argument. */ + if (nargs < 2) + break; + + /* Or if all arguments are already free of side-effects. */ + bool has_side_effects = false; + for (int i = 0; i < nargs; i++) + { + if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i))) + { + has_side_effects = true; + break; + } + } + + if (!has_side_effects) + break; + + /* Leave the last argument for gimplify_call_expr. */ + for (int i = 0; i < nargs - 1; i++) + { + tree new_arg = CALL_EXPR_ARG (*expr_p, i); + + /* If argument has a side-effect, gimplify_arg will handle it. */ + if (gimplify_arg (&new_arg, pre_p, loc) == GS_ERROR) + ret = GS_ERROR; + + /* Even if an argument itself doesn't have any side-effects, it + might be altered by another argument in the list. */ + if (new_arg == CALL_EXPR_ARG (*expr_p, i) + && !really_constant_p (new_arg)) + new_arg = get_formal_tmp_var (new_arg, pre_p); + + CALL_EXPR_ARG (*expr_p, i) = new_arg; + } + + if (ret != GS_ERROR) + ret = GS_OK; + } + break; + + case UNSIGNED_RSHIFT_EXPR: + /* Convert op0 to an unsigned type. */ + op0 = TREE_OPERAND (*expr_p, 0); + op1 = TREE_OPERAND (*expr_p, 1); + + type = d_unsigned_type (TREE_TYPE (op0)); + + *expr_p = convert (TREE_TYPE (*expr_p), + build2 (RSHIFT_EXPR, type, convert (type, op0), op1)); + ret = GS_OK; + break; + + case FLOAT_MOD_EXPR: + gcc_unreachable (); + + default: + break; + } + + return ret; +} diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index 6412c1c204c..6183389007a 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -48,8 +48,6 @@ along with GCC; see the file COPYING3. If not see #include "varasm.h" #include "output.h" #include "print-tree.h" -#include "gimple-expr.h" -#include "gimplify.h" #include "debug.h" #include "d-tree.h" @@ -843,164 +841,6 @@ d_post_options (const char ** fn) return false; } -/* Return TRUE if an operand OP of a given TYPE being copied has no data. - The middle-end does a similar check with zero sized types. */ - -static bool -empty_modify_p (tree type, tree op) -{ - tree_code code = TREE_CODE (op); - switch (code) - { - case COMPOUND_EXPR: - return empty_modify_p (type, TREE_OPERAND (op, 1)); - - case CONSTRUCTOR: - /* Non-empty construcors are valid. */ - if (CONSTRUCTOR_NELTS (op) != 0 || TREE_CLOBBER_P (op)) - return false; - break; - - case CALL_EXPR: - /* Leave nrvo alone because it isn't a copy. */ - if (CALL_EXPR_RETURN_SLOT_OPT (op)) - return false; - break; - - default: - /* If the operand doesn't have a simple form. */ - if (!is_gimple_lvalue (op) && !INDIRECT_REF_P (op)) - return false; - break; - } - - return empty_aggregate_p (type); -} - -/* Implements the lang_hooks.gimplify_expr routine for language D. - Do gimplification of D specific expression trees in EXPR_P. */ - -static int -d_gimplify_expr (tree *expr_p, gimple_seq *pre_p, - gimple_seq *post_p ATTRIBUTE_UNUSED) -{ - tree_code code = TREE_CODE (*expr_p); - enum gimplify_status ret = GS_UNHANDLED; - tree op0, op1; - tree type; - - switch (code) - { - case INIT_EXPR: - case MODIFY_EXPR: - op0 = TREE_OPERAND (*expr_p, 0); - op1 = TREE_OPERAND (*expr_p, 1); - - if (!error_operand_p (op0) && !error_operand_p (op1) - && (AGGREGATE_TYPE_P (TREE_TYPE (op0)) - || AGGREGATE_TYPE_P (TREE_TYPE (op1))) - && !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0))) - { - /* If the back end isn't clever enough to know that the lhs and rhs - types are the same, add an explicit conversion. */ - TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR, - TREE_TYPE (op0), op1); - ret = GS_OK; - } - else if (empty_modify_p (TREE_TYPE (op0), op1)) - { - /* Remove any copies of empty aggregates. */ - gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p, - is_gimple_lvalue, fb_lvalue); - - if (TREE_SIDE_EFFECTS (op1)) - gimplify_and_add (op1, pre_p); - - *expr_p = TREE_OPERAND (*expr_p, 0); - ret = GS_OK; - } - break; - - case ADDR_EXPR: - op0 = TREE_OPERAND (*expr_p, 0); - /* Constructors are not lvalues, so make them one. */ - if (TREE_CODE (op0) == CONSTRUCTOR) - { - TREE_OPERAND (*expr_p, 0) = force_target_expr (op0); - ret = GS_OK; - } - break; - - case CALL_EXPR: - if (CALL_EXPR_ARGS_ORDERED (*expr_p)) - { - /* Strictly evaluate all arguments from left to right. */ - int nargs = call_expr_nargs (*expr_p); - location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location); - - /* No need to enforce evaluation order if only one argument. */ - if (nargs < 2) - break; - - /* Or if all arguments are already free of side-effects. */ - bool has_side_effects = false; - for (int i = 0; i < nargs; i++) - { - if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i))) - { - has_side_effects = true; - break; - } - } - - if (!has_side_effects) - break; - - /* Leave the last argument for gimplify_call_expr. */ - for (int i = 0; i < nargs - 1; i++) - { - tree new_arg = CALL_EXPR_ARG (*expr_p, i); - - /* If argument has a side-effect, gimplify_arg will handle it. */ - if (gimplify_arg (&new_arg, pre_p, loc) == GS_ERROR) - ret = GS_ERROR; - - /* Even if an argument itself doesn't have any side-effects, it - might be altered by another argument in the list. */ - if (new_arg == CALL_EXPR_ARG (*expr_p, i) - && !really_constant_p (new_arg)) - new_arg = get_formal_tmp_var (new_arg, pre_p); - - CALL_EXPR_ARG (*expr_p, i) = new_arg; - } - - if (ret != GS_ERROR) - ret = GS_OK; - } - break; - - case UNSIGNED_RSHIFT_EXPR: - /* Convert op0 to an unsigned type. */ - op0 = TREE_OPERAND (*expr_p, 0); - op1 = TREE_OPERAND (*expr_p, 1); - - type = d_unsigned_type (TREE_TYPE (op0)); - - *expr_p = convert (TREE_TYPE (*expr_p), - build2 (RSHIFT_EXPR, type, convert (type, op0), op1)); - ret = GS_OK; - break; - - case FLOAT_MOD_EXPR: - gcc_unreachable (); - - default: - break; - } - - return ret; -} - /* Add the module M to the list of modules that may declare GCC builtins. These are scanned after first semantic and before codegen passes. See d_maybe_set_builtin() for the implementation. */ diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 072de7e6543..b01a133fe62 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -593,6 +593,9 @@ extern tree convert_for_condition (tree, Type *); extern tree d_array_convert (Expression *); extern tree d_array_convert (Type *, Expression *); +/* In d-gimplify.cc. */ +extern int d_gimplify_expr (tree *, gimple_seq *, gimple_seq *); + /* In d-incpath.cc. */ extern void add_import_paths (const char *, const char *, bool);