This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Implement __builtin_return_address(0) for v850
- To: gcc-patches at gcc dot gnu dot org
- Subject: Implement __builtin_return_address(0) for v850
- From: Nick Clifton <nickc at redhat dot com>
- Date: Fri, 5 Jan 2001 16:00:03 -0800
Hi Guys,
DJ wrote a patch to implement __builtin_return_address(0) for the
v850 and I have applied it.
Cheers
Nick
2001-01-05 DJ Delorie <dj@redhat.com>
* config/v850/v850.h (RETURN_ADDR_RTX): Define.
(INIT_EXPANDERS): Define.
* config/v850/v850.c (struct machine_function): Define.
(v850_save_machine_status): New function.
(v850_restore_machine_status): New function.
(v850_return_addr): New function.
(v850_init_expanders): New function.
* config/v850/v850-protos.h: Add prototypes for v850_return_addr
and v850_init_expanders.
Index: config/v850/v850-protos.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/v850/v850-protos.h,v
retrieving revision 1.4
diff -p -r1.4 v850-protos.h
*** v850-protos.h 2000/09/07 22:24:34 1.4
--- v850-protos.h 2001/01/05 23:58:42
*************** extern void asm_file_start
*** 39,46 ****
--- 39,48 ----
extern void override_options PARAMS ((void));
extern int compute_register_save_size PARAMS ((long *));
extern int compute_frame_size PARAMS ((int, long *));
+ extern void v850_init_expanders PARAMS ((void));
#ifdef RTX_CODE
+ extern rtx v850_return_addr PARAMS ((int));
extern void print_operand PARAMS ((FILE *, rtx, int ));
extern void print_operand_address PARAMS ((FILE *, rtx));
extern int const_costs PARAMS ((rtx, enum rtx_code));
Index: config/v850/v850.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/v850/v850.c,v
retrieving revision 1.35
diff -p -r1.35 v850.c
*** v850.c 2001/01/05 23:31:43 1.35
--- v850.c 2001/01/05 23:58:42
***************
*** 1,5 ****
/* Subroutines for insn-output.c for NEC V850 series
! Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Contributed by Jeff Law (law@cygnus.com).
This file is part of GNU CC.
--- 1,6 ----
/* Subroutines for insn-output.c for NEC V850 series
! Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
! Free Software Foundation, Inc.
Contributed by Jeff Law (law@cygnus.com).
This file is part of GNU CC.
*************** static int const_costs_int PARAM
*** 52,57 ****
--- 53,60 ----
static void substitute_ep_register PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
static int ep_memory_offset PARAMS ((enum machine_mode, int));
static void v850_set_data_area PARAMS ((tree, v850_data_area));
+ static void v850_save_machine_status PARAMS ((struct function *));
+ static void v850_restore_machine_status PARAMS ((struct function *));
/* True if the current function has anonymous arguments. */
int current_function_anonymous_args;
*************** v850_va_arg (valist, type)
*** 2782,2785 ****
--- 2785,2859 ----
}
return addr_rtx;
+ }
+
+ /* Functions to save and restore machine-specific function data. */
+
+ static rtx ra_rtx;
+
+ struct machine_function
+ {
+ /* Records __builtin_return address. */
+ struct rtx_def * ra_rtx;
+ };
+
+ static void
+ v850_save_machine_status (p)
+ struct function * p;
+ {
+ p->machine =
+ (struct machine_function *) xcalloc (1, sizeof (struct machine_function));
+ p->machine->ra_rtx = ra_rtx;
+ }
+
+ static void
+ v850_restore_machine_status (p)
+ struct function * p;
+ {
+ ra_rtx = p->machine->ra_rtx;
+ free (p->machine);
+ p->machine = NULL;
+ }
+
+ /* Return an RTX indicating where the return address to the
+ calling function can be found. */
+
+ rtx
+ v850_return_addr (count)
+ int count;
+ {
+ if (count != 0)
+ return const0_rtx;
+
+ if (ra_rtx == NULL)
+ {
+ rtx init;
+
+ /* No rtx yet. Invent one, and initialize it for r31 (lp) in
+ the prologue. */
+ ra_rtx = gen_reg_rtx (Pmode);
+
+ init = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
+
+ init = gen_rtx_SET (VOIDmode, ra_rtx, init);
+
+ /* Emit the insn to the prologue with the other argument copies. */
+ push_topmost_sequence ();
+ emit_insn_after (init, get_insns ());
+ pop_topmost_sequence ();
+ }
+
+ debug_rtx (ra_rtx);
+ return ra_rtx;
+ }
+
+ /* Do anything needed before RTL is emitted for each function. */
+
+ void
+ v850_init_expanders ()
+ {
+ ra_rtx = NULL;
+
+ save_machine_status = v850_save_machine_status;
+ restore_machine_status = v850_restore_machine_status;
}
Index: config/v850/v850.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/v850/v850.h,v
retrieving revision 1.31
diff -p -r1.31 v850.h
*** v850.h 2000/11/25 00:43:32 1.31
--- v850.h 2001/01/05 23:58:42
***************
*** 1,5 ****
/* Definitions of target machine for GNU compiler. NEC V850 series
! Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
Contributed by Jeff Law (law@cygnus.com).
This file is part of GNU CC.
--- 1,5 ----
/* Definitions of target machine for GNU compiler. NEC V850 series
! Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
Contributed by Jeff Law (law@cygnus.com).
This file is part of GNU CC.
*************** enum reg_class
*** 681,686 ****
--- 681,687 ----
#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) 0
+ #define RETURN_ADDR_RTX(COUNT, FP) v850_return_addr (COUNT)
/* Define a data type for recording info about an argument list
during the scan of that argument list. This data type should
*************** extern int current_function_anonymous_ar
*** 789,794 ****
--- 790,799 ----
#define EXIT_IGNORE_STACK 1
+ /* Initialize data used by insn expanders. This is called from insn_emit,
+ once for every function before code is generated. */
+ #define INIT_EXPANDERS v850_init_expanders ()
+
/* Output assembler code to FILE to increment profiler label # LABELNO
for profiling a function entry. */
*************** extern union tree_node * GHS_current_sec
*** 1618,1624 ****
matched by the predicate. The list should have a trailing comma. */
#define PREDICATE_CODES \
- { "ep_memory_operand", { MEM }}, \
{ "reg_or_0_operand", { REG, SUBREG, CONST_INT, CONST_DOUBLE }}, \
{ "reg_or_int5_operand", { REG, SUBREG, CONST_INT }}, \
{ "call_address_operand", { REG, SYMBOL_REF }}, \
--- 1623,1628 ----