From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id 5CF4A3858410 for ; Tue, 21 Feb 2023 14:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CF4A3858410 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gdcproject.org Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4PLhNm0hDnz9sTL; Tue, 21 Feb 2023 15:23:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org; s=MBO0001; t=1676989432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=s6Kvi/vRfqPOcXlAEgH322O6lN/GSoZ+5NfFn9OSklk=; b=uLpdKm4y8GGpj15BvUDzJ9MwHPNco2satPARZXiREdaxTSDtzcRKD8p59Czo95QZGyq+03 7GDXX4DDxQAlywmqNSelywoC8ZXowNr29FknnB/cHMkjk5PatI6zCwTmIjDK1+zmbg0tDH vPT0SU/pQgzVTFU/ISD9L57Qis3NIMhV1WsKHsaTD9jc/gDj7H313XytQ5UElroTWtzPqO 897jVOWT//UaJXGmzv2oMZq9dKxzVUY+wKL+h+9diCGN5HZhBMnKDVeh+K3uXG4g82KtFm vNWY3JDoRIieKAodhBw9bqqCShPlgdnd+k/C0Pr8BbmNv2NNAjTXx3BGuutLmw== From: Iain Buclaw To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Only handle the left-to-right evaluation of a call expression during gimplify Date: Tue, 21 Feb 2023 15:23:50 +0100 Message-Id: <20230221142350.1806182-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This patch removes an unnecessary rewriting of the front-end AST during lowering. As all functions regardless of their linkage are evaluated strictly left-to-right now, there's no point trying to handle all temp saving during the code generation pass. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to mainline. Regards, Iain. --- gcc/d/ChangeLog: * d-codegen.cc (d_build_call): Remove front-end expansion of side-effects in a call expression. * d-gimplify.cc (d_gimplify_call_expr): Gimplify the callee before its arguments. --- gcc/d/d-codegen.cc | 29 +++-------------------------- gcc/d/d-gimplify.cc | 9 +++++++++ 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 920b45d0480..0e8e07366ee 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2172,7 +2172,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object, /* Build the argument list for the call. */ vec *args = NULL; - tree saved_args = NULL_TREE; bool noreturn_call = false; /* If this is a delegate call or a nested function being called as @@ -2182,23 +2181,6 @@ d_build_call (TypeFunction *tf, tree callable, tree object, if (arguments) { - /* First pass, evaluated expanded tuples in function arguments. */ - for (size_t i = 0; i < arguments->length; ++i) - { - Lagain: - Expression *arg = (*arguments)[i]; - gcc_assert (arg->op != EXP::tuple); - - if (arg->op == EXP::comma) - { - CommaExp *ce = arg->isCommaExp (); - tree tce = build_expr (ce->e1); - saved_args = compound_expr (saved_args, tce); - (*arguments)[i] = ce->e2; - goto Lagain; - } - } - const size_t nparams = tf->parameterList.length (); /* if _arguments[] is the first argument. */ const size_t varargs = tf->isDstyleVariadic (); @@ -2257,17 +2239,12 @@ d_build_call (TypeFunction *tf, tree callable, tree object, } } - /* Evaluate the callee before calling it. */ - if (TREE_SIDE_EFFECTS (callee)) - { - callee = d_save_expr (callee); - saved_args = compound_expr (callee, saved_args); - } - /* If we saw a `noreturn` parameter, any unreachable argument evaluations after it are discarded, as well as the function call itself. */ if (noreturn_call) { + tree saved_args = NULL_TREE; + if (TREE_SIDE_EFFECTS (callee)) saved_args = compound_expr (callee, saved_args); @@ -2297,7 +2274,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object, result = force_target_expr (result); } - return compound_expr (saved_args, result); + return result; } /* Build and return the correct call to fmod depending on TYPE. diff --git a/gcc/d/d-gimplify.cc b/gcc/d/d-gimplify.cc index 4072a3d92cf..04cb631244c 100644 --- a/gcc/d/d-gimplify.cc +++ b/gcc/d/d-gimplify.cc @@ -162,6 +162,15 @@ d_gimplify_call_expr (tree *expr_p, gimple_seq *pre_p) if (!has_side_effects) return GS_UNHANDLED; + /* Evaluate the callee before calling it. */ + tree new_call_fn = CALL_EXPR_FN (*expr_p); + + if (gimplify_expr (&new_call_fn, pre_p, NULL, + is_gimple_call_addr, fb_rvalue) == GS_ERROR) + return GS_ERROR; + + CALL_EXPR_FN (*expr_p) = new_call_fn; + /* Leave the last argument for gimplify_call_expr. */ for (int i = 0; i < nargs - 1; i++) { -- 2.37.2