aboutsummaryrefslogtreecommitdiff
path: root/gcc/config
diff options
context:
space:
mode:
authorRichard Henderson <rth@cygnus.com>1999-09-04 17:16:18 -0700
committerRichard Henderson <rth@gcc.gnu.org>1999-09-04 17:16:18 -0700
commita8b2c8a1bafadd560e057168cde194f18205fdc0 (patch)
tree37b6e2cabd6f1672b8525e0ccc80e082bc7a76b2 /gcc/config
parent1b893504b35693f977761494967aa92b82b62436 (diff)
downloadgcc-a8b2c8a1bafadd560e057168cde194f18205fdc0.zip
gcc-a8b2c8a1bafadd560e057168cde194f18205fdc0.tar.gz
gcc-a8b2c8a1bafadd560e057168cde194f18205fdc0.tar.bz2
sparc.h (EXPAND_BUILTIN_VA_START): Define.
* sparc.h (EXPAND_BUILTIN_VA_START): Define. (EXPAND_BUILTIN_VA_ARG): Define. * sparc.c (sparc_va_start): New. (sparc_va_arg): New. From-SVN: r29115
Diffstat (limited to 'gcc/config')
-rw-r--r--gcc/config/sparc/sparc.c90
-rw-r--r--gcc/config/sparc/sparc.h8
2 files changed, 98 insertions, 0 deletions
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index ad51856..622e04b 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -4280,6 +4280,96 @@ sparc_builtin_saveregs ()
return address;
}
+
+/* Implement `va_start' for varargs and stdarg. */
+
+void
+sparc_va_start (stdarg_p, valist, nextarg)
+ int stdarg_p ATTRIBUTE_UNUSED;
+ tree valist;
+ rtx nextarg;
+{
+ nextarg = expand_builtin_saveregs ();
+ std_expand_builtin_va_start (1, valist, nextarg);
+}
+
+/* Implement `va_arg'. */
+
+rtx
+sparc_va_arg (valist, type)
+ tree valist, type;
+{
+ HOST_WIDE_INT size, rsize, align;
+ tree addr, incr, tmp;
+ rtx addr_rtx;
+ int indirect = 0;
+
+ /* Round up sizeof(type) to a word. */
+ size = int_size_in_bytes (type);
+ rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
+ align = 0;
+
+ if (TARGET_ARCH64)
+ {
+ if (TYPE_ALIGN (type) >= 2 * BITS_PER_WORD)
+ align = 2 * UNITS_PER_WORD;
+
+ if (AGGREGATE_TYPE_P (type) && size > 16)
+ {
+ indirect = 1;
+ size = rsize = UNITS_PER_WORD;
+ }
+ }
+ else
+ {
+ if (AGGREGATE_TYPE_P (type)
+ || TYPE_MODE (type) == TFmode
+ || TYPE_MODE (type) == TCmode)
+ {
+ indirect = 1;
+ size = rsize = UNITS_PER_WORD;
+ }
+ else
+ {
+ /* ??? The old va-sparc.h implementation, for 8 byte objects
+ copied stuff to a temporary -- I don't see that that
+ provides any more alignment than the stack slot did. */
+ }
+ }
+
+ incr = valist;
+ if (align)
+ {
+ incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
+ build_int_2 (align - 1, 0)));
+ incr = fold (build (BIT_AND_EXPR, ptr_type_node, incr,
+ build_int_2 (-align, -1)));
+ }
+
+ addr = incr = save_expr (incr);
+ if (BYTES_BIG_ENDIAN && size < rsize)
+ {
+ addr = fold (build (PLUS_EXPR, ptr_type_node, incr,
+ build_int_2 (rsize - size, 0)));
+ }
+ incr = fold (build (PLUS_EXPR, ptr_type_node, incr,
+ build_int_2 (rsize, 0)));
+
+ incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
+ TREE_SIDE_EFFECTS (incr) = 1;
+ expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
+
+ addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
+
+ if (indirect)
+ {
+ addr_rtx = force_reg (Pmode, addr_rtx);
+ addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
+ MEM_ALIAS_SET (addr_rtx) = get_varargs_alias_set ();
+ }
+
+ return addr_rtx;
+}
/* Return the string to output a conditional branch to LABEL, which is
the operand number of the label. OP is the conditional expression.
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 9d78988..d113248 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -2046,6 +2046,14 @@ void sparc64_initialize_trampoline ();
extern struct rtx_def *sparc_builtin_saveregs ();
#define EXPAND_BUILTIN_SAVEREGS() sparc_builtin_saveregs ()
+/* Implement `va_start' for varargs and stdarg. */
+#define EXPAND_BUILTIN_VA_START(stdarg, valist, nextarg) \
+ sparc_va_start (stdarg, valist, nextarg)
+
+/* Implement `va_arg'. */
+#define EXPAND_BUILTIN_VA_ARG(valist, type) \
+ sparc_va_arg (valist, type)
+
/* Define this macro if the location where a function argument is passed
depends on whether or not it is a named argument.