* [committed] d: Only handle the left-to-right evaluation of a call expression during gimplify
@ 2023-02-21 14:23 Iain Buclaw
0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2023-02-21 14:23 UTC (permalink / raw)
To: gcc-patches; +Cc: Iain Buclaw
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 <tree, va_gc> *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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-21 14:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 14:23 [committed] d: Only handle the left-to-right evaluation of a call expression during gimplify Iain Buclaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).