Index: rs6000.c =================================================================== RCS file: /cvs/gcc/egcs/gcc/config/rs6000/rs6000.c,v retrieving revision 1.130 diff -u -p -r1.130 rs6000.c --- rs6000.c 2000/06/14 21:45:43 1.130 +++ rs6000.c 2000/06/30 13:12:46 @@ -98,9 +98,6 @@ const char *rs6000_sdata_name = (char *) int fixuplabelno = 0; #endif -/* Whether a System V.4 varargs area was created. */ -int rs6000_sysv_varargs_p; - /* ABI enumeration available for subtarget to use. */ enum rs6000_abi rs6000_current_abi; @@ -128,6 +125,9 @@ static int toc_hash_eq PARAMS ((const vo static int toc_hash_mark_entry PARAMS ((void **, void *)); static void toc_hash_mark_table PARAMS ((void *)); static int constant_pool_expr_1 PARAMS ((rtx, int *, int *)); +static void rs6000_init_machine_status PARAMS ((struct function *p)); +static void rs6000_mark_machine_status PARAMS ((struct function *p)); +static int rs6000_ra_ever_killed PARAMS ((void)); /* Default register names. */ char rs6000_reg_names[][8] = @@ -393,6 +393,10 @@ rs6000_override_options (default_cpu) if (TARGET_TOC) ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); + + /* Set up function hooks. */ + init_machine_status = rs6000_init_machine_status; + mark_machine_status = rs6000_mark_machine_status; } void @@ -1903,7 +1907,7 @@ setup_incoming_varargs (cum, mode, type, /* Indicate to allocate space on the stack for varargs save area. */ /* ??? Does this really have to be located at a magic spot on the stack, or can we allocate this with assign_stack_local instead. */ - rs6000_sysv_varargs_p = 1; + cfun->machine->sysv_varargs_p = 1; if (! no_rtl) save_area = plus_constant (virtual_stack_vars_rtx, - RS6000_VARARGS_SIZE); @@ -1913,7 +1917,7 @@ setup_incoming_varargs (cum, mode, type, else { save_area = virtual_incoming_args_rtx; - rs6000_sysv_varargs_p = 0; + cfun->machine->sysv_varargs_p = 0; first_reg_offset = cum->words; if (MUST_PASS_IN_STACK (mode, type)) @@ -3232,52 +3236,26 @@ rs6000_got_register (value) return pic_offset_table_rtx; } -/* Define the structure for the machine field in struct function. */ -struct machine_function -{ - int sysv_varargs_p; -}; - -/* Functions to save and restore sysv_varargs_p. +/* Functions to init and mark struct machine_function. These will be called, via pointer variables, from push_function_context and pop_function_context. */ -void -rs6000_save_machine_status (p) +static void +rs6000_init_machine_status (p) struct function *p; { - struct machine_function *machine = - (struct machine_function *) xmalloc (sizeof (struct machine_function)); - - p->machine = machine; - machine->sysv_varargs_p = rs6000_sysv_varargs_p; + p->machine = + (struct machine_function *) xcalloc (1, sizeof (struct machine_function)); } -void -rs6000_restore_machine_status (p) +static void +rs6000_mark_machine_status (p) struct function *p; { struct machine_function *machine = p->machine; - - rs6000_sysv_varargs_p = machine->sysv_varargs_p; - - free (machine); - p->machine = (struct machine_function *)0; -} - -/* Do anything needed before RTL is emitted for each function. */ - -void -rs6000_init_expanders () -{ - /* Reset varargs */ - rs6000_sysv_varargs_p = 0; - /* Arrange to save and restore machine status around nested functions. */ - save_machine_status = rs6000_save_machine_status; - restore_machine_status = rs6000_restore_machine_status; + ggc_mark_rtx (machine->ra_rtx); } - /* Print an operand. Recognize special options, documented below. */ @@ -4341,10 +4319,11 @@ rs6000_stack_info () info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); /* Does this function call anything? */ - info_ptr->calls_p = ! current_function_is_leaf; + info_ptr->calls_p = (! current_function_is_leaf + || cfun->machine->builtin_ra_ge1_used); /* Determine if we need to save the link register */ - if (regs_ever_live[LINK_REGISTER_REGNUM] + if (rs6000_ra_ever_killed () || (DEFAULT_ABI == ABI_AIX && profile_flag) #ifdef TARGET_RELOCATABLE || (TARGET_RELOCATABLE && (get_pool_size () != 0)) @@ -4560,6 +4539,65 @@ debug_stack_info (info) fprintf (stderr, "\n"); } + +rtx +rs6000_return_addr (count, frame) + int count; + rtx frame; +{ + rtx init, reg; + + if (count != 0) + { + cfun->machine->builtin_ra_ge1_used = 1; + return + gen_rtx_MEM (Pmode, + memory_address (Pmode, + plus_constant (copy_to_reg (gen_rtx_MEM (Pmode, + memory_address (Pmode, frame))), + RETURN_ADDRESS_OFFSET))); + } + + reg = cfun->machine->ra_rtx; + if (reg == NULL) + { + /* No rtx yet. Invent one, and initialize it from LR in + the prologue. */ + reg = gen_reg_rtx (Pmode); + cfun->machine->ra_rtx = reg; + init = gen_rtx_SET (VOIDmode, reg, + gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); + + /* Emit the insn to the prologue with the other argument copies. */ + push_topmost_sequence (); + emit_insn_after (init, get_insns ()); + pop_topmost_sequence (); + } + + return reg; +} + +static int +rs6000_ra_ever_killed () +{ + rtx top; + +#ifdef ASM_OUTPUT_MI_THUNK + if (current_function_is_thunk) + return 0; +#endif + if (!cfun->machine->ra_rtx) + return regs_ever_live[LINK_REGISTER_REGNUM]; + + push_topmost_sequence (); + top = get_insns (); + pop_topmost_sequence (); + + return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), + top, NULL_RTX); +} + + /* Emit instructions needed to load the TOC register. This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is Index: rs6000.h =================================================================== RCS file: /cvs/gcc/egcs/gcc/config/rs6000/rs6000.h,v retrieving revision 1.85 diff -u -p -r1.85 rs6000.h --- rs6000.h 2000/06/27 02:26:23 1.85 +++ rs6000.h 2000/06/30 13:12:46 @@ -418,6 +418,17 @@ struct rs6000_cpu_select extern struct rs6000_cpu_select rs6000_select[]; +/* Define the structure for the machine field in struct function. */ +struct machine_function +{ + /* Whether a System V.4 varargs area was created. */ + int sysv_varargs_p; + /* Set if a return address rtx for loading from LR was wreated. */ + struct rtx_def *ra_rtx; + /* Flags if __builtin_return_address (n) with n >= 1 was used. */ + int builtin_ra_ge1_used; +}; + /* Debug support */ extern const char *rs6000_debug_name; /* Name for -mdebug-xxxx option */ extern int rs6000_debug_stack; /* debug stack applications */ @@ -1220,16 +1231,9 @@ typedef struct rs6000_stack { /* Size of the V.4 varargs area if needed */ #define RS6000_VARARGS_AREA 0 -/* Whether a V.4 varargs area is needed */ -extern int rs6000_sysv_varargs_p; - /* Align an address */ #define RS6000_ALIGN(n,a) (((n) + (a) - 1) & ~((a) - 1)) -/* Initialize data used by insn expanders. This is called from - init_emit, once for each function, before code is generated. */ -#define INIT_EXPANDERS rs6000_init_expanders () - /* Size of V.4 varargs area in bytes */ #define RS6000_VARARGS_SIZE \ ((GP_ARG_NUM_REG * (TARGET_32BIT ? 4 : 8)) + (FP_ARG_NUM_REG * 8) + 8) @@ -1629,17 +1633,12 @@ typedef struct rs6000_args /* The current return address is in link register (65). The return address of anything farther back is accessed normally at an offset of 8 from the frame pointer. */ -#define RETURN_ADDR_RTX(COUNT, FRAME) \ - (((COUNT) == -1) \ - ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) \ - : gen_rtx_MEM (Pmode, \ - memory_address \ - (Pmode, \ - plus_constant (copy_to_reg \ - (gen_rtx_MEM (Pmode, \ - memory_address (Pmode, \ - (FRAME)))), \ - RETURN_ADDRESS_OFFSET)))) +#define RETURN_ADDR_RTX(COUNT, FRAME) \ + (rs6000_return_addr (COUNT, FRAME)) + +extern struct rtx_def* rs6000_return_addr (int, struct rtx_def *rtx); + + /* Definitions for register eliminations. Index: sysv4.h =================================================================== RCS file: /cvs/gcc/egcs/gcc/config/rs6000/sysv4.h,v retrieving revision 1.31 diff -u -p -r1.31 sysv4.h --- sysv4.h 2000/06/27 02:26:23 1.31 +++ sysv4.h 2000/06/30 13:12:46 @@ -306,7 +306,8 @@ do { \ /* Size of the V.4 varargs area if needed. */ /* Override rs6000.h definition. */ #undef RS6000_VARARGS_AREA -#define RS6000_VARARGS_AREA ((rs6000_sysv_varargs_p) ? RS6000_VARARGS_SIZE : 0) +#define RS6000_VARARGS_AREA \ + ((cfun->machine->sysv_varargs_p) ? RS6000_VARARGS_SIZE : 0) /* Override default big endianism definitions in rs6000.h. */ #undef BYTES_BIG_ENDIAN