This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Don't optimize stdarg functions if old-style builtins are used
On Thu, Sep 30, 2004 at 11:33:19AM +0200, Eric Botcazou wrote:
> > The following patch implements that.
> > This patch contains just the infrastructure, not the backend changes
> > to avoid saving unneeded registers.
>
> Nice! Do you plan on implementing the optimization in the SPARC back-end or
> should I take a look?
If you could, I'd appreciate that.
> > Backends that use void * or char * va_list type shouldn't set
> > va_list_gpr_counter_field or va_list_fpr_counter_field, all they
> > need is just to look at cfun->va_list_gpr_size this pass computes
> > (va_list_fpr_size is not used on those arches, as void */char *
> > va_list is just one counter, not two).
>
> I presume you meant va_list_gpr_counter_name and va_list_fpr_counter_name?
I have changed _name to _field - Richard requested to compare FIELD_DECLs
instead of DECL_NAME () of FIELD_DECLs.
I haven't posted the actual patch I have commited here, but the changes
were really minimal.
BTW, as sparc uses __builtin_saveregs () internally, I think a patch like
this is needed, otherwise you would be in trouble if a function calls
both __builtin_saveregs and __builtin_va_start.
2004-09-30 Jakub Jelinek <jakub@redhat.com>
* tree-stdarg.c (execute_optimize_stdarg): Assume all regs need to
be saved if old style stdarg builtins are used.
--- gcc/tree-stdarg.c.jj 2004-09-29 22:27:45.000000000 +0200
+++ gcc/tree-stdarg.c 2004-09-30 13:36:29.995774284 +0200
@@ -509,9 +509,23 @@ execute_optimize_stdarg (void)
callee = get_callee_fndecl (call);
if (!callee
- || DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL
- || DECL_FUNCTION_CODE (callee) != BUILT_IN_VA_START)
- continue;
+ || DECL_BUILT_IN_CLASS (callee) != BUILT_IN_NORMAL)
+ continue;
+
+ switch (DECL_FUNCTION_CODE (callee))
+ {
+ case BUILT_IN_VA_START:
+ break;
+ /* If old style builtins are used, don't optimize anything. */
+ case BUILT_IN_SAVEREGS:
+ case BUILT_IN_STDARG_START:
+ case BUILT_IN_ARGS_INFO:
+ case BUILT_IN_NEXT_ARG:
+ va_list_escapes = true;
+ continue;
+ default:
+ continue;
+ }
si.va_start_count++;
ap = TREE_VALUE (TREE_OPERAND (call, 1));
Jakub