From eeec89e6ba5f1b68aeef969bbfb2a52513d95747 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 24 Aug 2001 05:40:48 +0000 Subject: [PATCH] don't put function args in temps when not needed. still need to take care of the return value, but that can possibly be taken care of in an optimiser pass. --- tools/qfcc/source/expr.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 478b99a31..5740a9b10 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -1000,6 +1000,28 @@ unary_expr (int op, expr_t *e) abort (); } +int +has_function_call (expr_t *e) +{ + switch (e->type) { + case ex_block: + for (e = e->e.block.head; e; e = e->next) + if (has_function_call (e)) + return 1; + return 0; + case ex_expr: + if (e->e.expr.op == 'c') + return 1; + return (has_function_call (e->e.expr.e1) + || has_function_call (e->e.expr.e2)); + case ex_uexpr: + if (e->e.expr.op != 'g') + return has_function_call (e->e.expr.e1); + default: + return 0; + } +} + expr_t * function_expr (expr_t *e1, expr_t *e2) { @@ -1082,10 +1104,14 @@ function_expr (expr_t *e1, expr_t *e2) call = new_block_expr (); for (e = e2, i = 0; e; e = e->next, i++) { - *a = new_temp_def_expr (arg_types[i]); - if (i) // compensate for new_binary_expr and the first arg - inc_users(*a); - append_expr (call, binary_expr ('=', *a, e)); + if (has_function_call (e)) { + *a = new_temp_def_expr (arg_types[i]); + if (i) // compensate for new_binary_expr and the first arg + inc_users(*a); + append_expr (call, binary_expr ('=', *a, e)); + } else { + *a = e; + } a = &(*a)->next; } e = new_binary_expr ('c', e1, args);