[patch] h8300.h: Emit the entire trampoline with INITIALIZE_TRAMPOLINE.

Kazu Hirata kazu@cs.umass.edu
Tue Dec 31 10:32:00 GMT 2002


Hi,

Attached is a patch to optimize trampoline-related code.

Without the patch, gcc outputs a trampoline using TRAMPOLINE_TEMPLATE
and modifies that later using INITIALIZE_TRAMPOLINE.

Since the invariant

Tested on h8300 port.  Committed.

Kazu Hirata

2002-12-31  Kazu Hirata  <kazu@cs.umass.edu>

	* config/h8300/h8300.h (TRAMPOLINE_TEMPLATE): Remove.
	(TRAMPOLINE_SIZE): Support the normal mode.
	(INITIALIZE_TRAMPOLINE): Emit the entire trampoline.

Index: h8300.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/h8300.h,v
retrieving revision 1.127
diff -c -r1.127 h8300.h
*** h8300.h	31 Dec 2002 09:07:36 -0000	1.127
--- h8300.h	31 Dec 2002 17:26:25 -0000
***************
*** 719,772 ****
  
  #define EXIT_IGNORE_STACK 0
  
! /* Output assembler code for a block containing the constant parts
!    of a trampoline, leaving space for the variable parts.
  
!    H8/300
  	      vvvv context
     1 0000 7903xxxx		mov.w	#0x1234,r3
     2 0004 5A00xxxx		jmp	@0x1234
  	      ^^^^ function
  
!    H8/300H
  	      vvvvvvvv context
     2 0000 7A03xxxxxxxx		mov.l	#0x12345678,er3
     3 0006 5Axxxxxx		jmp	@0x123456
  	    ^^^^^^ function
  */
  
- #define TRAMPOLINE_TEMPLATE(FILE)				\
-   do								\
-     {								\
-       if (TARGET_H8300)						\
- 	{							\
- 	  fprintf (FILE, "\tmov.w	#0x1234,r3\n");		\
- 	  fprintf (FILE, "\tjmp	@0x1234\n");			\
- 	}							\
-       else							\
- 	{							\
- 	  fprintf (FILE, "\tmov.l	#0x12345678,er3\n");	\
- 	  fprintf (FILE, "\tjmp	@0x123456\n");			\
- 	}							\
-     }								\
-   while (0)
- 
  /* Length in units of the trampoline for entering a nested function.  */
  
! #define TRAMPOLINE_SIZE (TARGET_H8300 ? 8 : 12)
  
! /* Emit RTL insns to initialize the variable parts of a trampoline.
     FNADDR is an RTX for the address of the function's pure code.
     CXT is an RTX for the static chain value for the function.  */
  
  #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			    \
! {									    \
!   emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 2)), CXT);    \
!   emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 6)), FNADDR); \
!   if (TARGET_H8300H || TARGET_H8300S)					    \
!     emit_move_insn (gen_rtx_MEM (QImode, plus_constant ((TRAMP), 6)),	    \
! 		    GEN_INT (0x5A));					    \
! }
  
  /* Addressing modes, and classification of registers for them.  */
  
--- 719,776 ----
  
  #define EXIT_IGNORE_STACK 0
  
! /* We emit the entire trampoline with INITIALIZE_TRAMPOLINE.
!    Depending on the pointer size, we use a different trampoline.
  
!    Pmode == HImode
  	      vvvv context
     1 0000 7903xxxx		mov.w	#0x1234,r3
     2 0004 5A00xxxx		jmp	@0x1234
  	      ^^^^ function
  
!    Pmode == SImode
  	      vvvvvvvv context
     2 0000 7A03xxxxxxxx		mov.l	#0x12345678,er3
     3 0006 5Axxxxxx		jmp	@0x123456
  	    ^^^^^^ function
  */
  
  /* Length in units of the trampoline for entering a nested function.  */
  
! #define TRAMPOLINE_SIZE ((TARGET_H8300 || TARGET_NORMAL_MODE) ? 8 : 12)
  
! /* Emit RTL insns to build a trampoline.
     FNADDR is an RTX for the address of the function's pure code.
     CXT is an RTX for the static chain value for the function.  */
  
  #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			    \
!   do									    \
!     {									    \
!       if (Pmode == HImode)						    \
! 	{								    \
! 	  emit_move_insn (gen_rtx_MEM (HImode, (TRAMP)), GEN_INT (0x7903)); \
! 	  emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 2)),  \
! 			  (CXT));					    \
! 	  emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 4)),  \
! 			  GEN_INT (0x5a00));				    \
! 	  emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 6)),  \
! 			  (FNADDR));					    \
! 	}								    \
!       else								    \
! 	{								    \
! 	  rtx tem = gen_reg_rtx (Pmode);				    \
! 									    \
! 	  emit_move_insn (gen_rtx_MEM (HImode, (TRAMP)), GEN_INT (0x7a03)); \
! 	  emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 2)),  \
! 			  (CXT));					    \
! 	  emit_move_insn (tem, (FNADDR));				    \
! 	  emit_insn (gen_andsi3 (tem, tem, GEN_INT (0x00ffffff)));	    \
! 	  emit_insn (gen_iorsi3 (tem, tem, GEN_INT (0x5a000000)));	    \
! 	  emit_move_insn (gen_rtx_MEM (Pmode, plus_constant ((TRAMP), 6)),  \
! 			  tem);						    \
! 	}								    \
!     }									    \
!   while (0)
  
  /* Addressing modes, and classification of registers for them.  */
  



More information about the Gcc-patches mailing list