public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch 01/36] Hookize static chain and trampoline macros
@ 2009-09-21 21:57 Richard Henderson
  2009-09-21 22:14 ` [patch 02/36][alpha] " Richard Henderson
                   ` (34 more replies)
  0 siblings, 35 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 21:57 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 867 bytes --]

In order to solve PR 41246, I need to have the location of the static 
chain be variable, based on the target nested function being called. 
Which requires that we pass around the FUNCTION_DECL when asking for the 
static_chain_rtx and when initializing the trampoline.  I took the 
opportunity to hookize TRAMPOLINE_TEMPLATE and INITIALIZE_TRAMPOLINE at 
the same time.  After all of the following series of patches is applied, 
it will be possible to poison these two macros and remove the fallback 
macro-to-hook adapter functions I added.

I've bootstrapped this on x86_64-linux, i686-linux.

I have built cc1 for every target and compared before-and-after assembly 
by eye.  In most cases the assembly is not identical because I'm now 
properly filling in the MEM_ATTRS while initializing the trampoline, 
which leads to a fair bit of code movement at -O2.


r~

[-- Attachment #2: d-tramp-01 --]
[-- Type: text/plain, Size: 30136 bytes --]

	* target.h (struct gcc_target): Add asm_out.trampoline_template,
	calls.static_chain, calls.trampoline_init,
	calls.trampoline_adjust_address.
	* target-def.h (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_STATIC_CHAIN, TARGET_TRAMPOLINE_INIT): New.
	(TARGET_TRAMPOLINE_ADJUST_ADDRESS): New.
	* builtins.c (expand_builtin_setjmp_receiver): Use
	targetm.calls.static_chain; only clobber registers.
	(expand_builtin_init_trampoline): Use targetm.calls.trampoline_init;
	set up memory attributes properly for the trampoline block.
	(expand_builtin_adjust_trampoline): Use
	targetm.calls.trampoline_adjust_address.
	* calls.c (prepare_call_address): Add fndecl argument.  Use
	targetm.calls.static_chain.
	* df-scan.c (df_need_static_chain_reg): Remove.
	(df_get_entry_block_def_set): Use targetm.calls.static_chain;
	consolodate static chain handling.
	* doc/tm.texi: Document new hooks.
	* emit-rtl.c (static_chain_rtx, static_chain_incoming_rtx): Remove.
	(init_emit_regs): Don't initialize them.
	* expr.h (prepare_call_address): Update decl.
	* final.c (profile_function): Use targetm.calls.static_chain.
	* function.c (expand_function_start): Likewise.
	* rtl.h (static_chain_rtx, static_chain_incoming_rtx): Remove.
	* stmt.c (expand_nl_goto_receiver): Use targetm.calls.static_chain;
	only clobber registers.
	* targhooks.c (default_static_chain): New.
	(default_asm_trampoline_template, default_trampoline_init): New.
	(default_trampoline_adjust_address): New.
	* targhooks.h: Declare them.
	* varasm.c (assemble_trampoline_template): Use
	targetm.asm_out.trampoline_template.  Make the memory block const
	and set its size.


diff --git a/gcc/builtins.c b/gcc/builtins.c
index fddb36c..7227481 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -755,13 +755,17 @@ expand_builtin_setjmp_setup (rtx buf_addr, rtx receiver_label)
 void
 expand_builtin_setjmp_receiver (rtx receiver_label ATTRIBUTE_UNUSED)
 {
+  rtx chain;
+
   /* Clobber the FP when we get here, so we have to make sure it's
      marked as used by this function.  */
   emit_use (hard_frame_pointer_rtx);
 
   /* Mark the static chain as clobbered here so life information
      doesn't get messed up for it.  */
-  emit_clobber (static_chain_rtx);
+  chain = targetm.calls.static_chain (current_function_decl, true);
+  if (chain && REG_P (chain))
+    emit_clobber (chain);
 
   /* Now put in the code to restore the frame pointer, and argument
      pointer, if needed.  */
@@ -839,11 +843,8 @@ expand_builtin_longjmp (rtx buf_addr, rtx value)
 
   buf_addr = force_reg (Pmode, buf_addr);
 
-  /* We used to store value in static_chain_rtx, but that fails if pointers
-     are smaller than integers.  We instead require that the user must pass
-     a second argument of 1, because that is what builtin_setjmp will
-     return.  This also makes EH slightly more efficient, since we are no
-     longer copying around a value that we don't care about.  */
+  /* We require that the user must pass a second argument of 1, because
+     that is what builtin_setjmp will return.  */
   gcc_assert (value == const1_rtx);
 
   last = get_last_insn ();
@@ -1590,7 +1591,7 @@ expand_builtin_apply (rtx function, rtx arguments, rtx argsize)
     }
 
   /* All arguments and registers used for the call are set up by now!  */
-  function = prepare_call_address (function, NULL, &call_fusage, 0, 0);
+  function = prepare_call_address (NULL, function, NULL, &call_fusage, 0, 0);
 
   /* Ensure address is valid.  SYMBOL_REF is already valid, so no need,
      and we don't want to load it into a register as an optimization,
@@ -5815,10 +5816,7 @@ static rtx
 expand_builtin_init_trampoline (tree exp)
 {
   tree t_tramp, t_func, t_chain;
-  rtx r_tramp, r_func, r_chain;
-#ifdef TRAMPOLINE_TEMPLATE
-  rtx blktramp;
-#endif
+  rtx m_tramp, r_tramp, r_chain, tmp;
 
   if (!validate_arglist (exp, POINTER_TYPE, POINTER_TYPE,
 			 POINTER_TYPE, VOID_TYPE))
@@ -5829,20 +5827,36 @@ expand_builtin_init_trampoline (tree exp)
   t_chain = CALL_EXPR_ARG (exp, 2);
 
   r_tramp = expand_normal (t_tramp);
-  r_func = expand_normal (t_func);
+  m_tramp = gen_rtx_MEM (BLKmode, r_tramp);
+  MEM_NOTRAP_P (m_tramp) = 1;
+
+  /* The TRAMP argument should be the address of a field within the
+     local function's FRAME decl.  Let's see if we can fill in the
+     to fill in the MEM_ATTRs for this memory.  */
+  if (TREE_CODE (t_tramp) == ADDR_EXPR)
+    set_mem_attributes_minus_bitpos (m_tramp, TREE_OPERAND (t_tramp, 0),
+				     true, 0);
+
+  tmp = round_trampoline_addr (r_tramp);
+  if (tmp != r_tramp)
+    {
+      m_tramp = change_address (m_tramp, BLKmode, tmp);
+      set_mem_align (m_tramp, TRAMPOLINE_ALIGNMENT);
+      set_mem_size (m_tramp, GEN_INT (TRAMPOLINE_SIZE));
+    }
+
+  /* The FUNC argument should be the address of the nested function.
+     Extract the actual function decl to pass to the hook.  */
+  gcc_assert (TREE_CODE (t_func) == ADDR_EXPR);
+  t_func = TREE_OPERAND (t_func, 0);
+  gcc_assert (TREE_CODE (t_func) == FUNCTION_DECL);
+
   r_chain = expand_normal (t_chain);
 
   /* Generate insns to initialize the trampoline.  */
-  r_tramp = round_trampoline_addr (r_tramp);
-#ifdef TRAMPOLINE_TEMPLATE
-  blktramp = gen_rtx_MEM (BLKmode, r_tramp);
-  set_mem_align (blktramp, TRAMPOLINE_ALIGNMENT);
-  emit_block_move (blktramp, assemble_trampoline_template (),
-		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
-#endif
-  trampolines_created = 1;
-  INITIALIZE_TRAMPOLINE (r_tramp, r_func, r_chain);
+  targetm.calls.trampoline_init (m_tramp, t_func, r_chain);
 
+  trampolines_created = 1;
   return const0_rtx;
 }
 
@@ -5856,9 +5870,8 @@ expand_builtin_adjust_trampoline (tree exp)
 
   tramp = expand_normal (CALL_EXPR_ARG (exp, 0));
   tramp = round_trampoline_addr (tramp);
-#ifdef TRAMPOLINE_ADJUST_ADDRESS
-  TRAMPOLINE_ADJUST_ADDRESS (tramp);
-#endif
+  if (targetm.calls.trampoline_adjust_address)
+    tramp = targetm.calls.trampoline_adjust_address (tramp);
 
   return tramp;
 }
diff --git a/gcc/calls.c b/gcc/calls.c
index 16229cc..f28fb51 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -166,7 +166,7 @@ static void restore_fixed_argument_area (rtx, rtx, int, int);
    CALL_INSN_FUNCTION_USAGE information.  */
 
 rtx
-prepare_call_address (rtx funexp, rtx static_chain_value,
+prepare_call_address (tree fndecl, rtx funexp, rtx static_chain_value,
 		      rtx *call_fusage, int reg_parm_seen, int sibcallp)
 {
   /* Make a valid memory address and copy constants through pseudo-regs,
@@ -187,11 +187,15 @@ prepare_call_address (rtx funexp, rtx static_chain_value,
 
   if (static_chain_value != 0)
     {
+      rtx chain;
+
+      gcc_assert (fndecl);
+      chain = targetm.calls.static_chain (fndecl, false);
       static_chain_value = convert_memory_address (Pmode, static_chain_value);
-      emit_move_insn (static_chain_rtx, static_chain_value);
 
-      if (REG_P (static_chain_rtx))
-	use_reg (call_fusage, static_chain_rtx);
+      emit_move_insn (chain, static_chain_value);
+      if (REG_P (chain))
+	use_reg (call_fusage, chain);
     }
 
   return funexp;
@@ -2807,7 +2811,7 @@ expand_call (tree exp, rtx target, int ignore)
 	}
 
       after_args = get_last_insn ();
-      funexp = prepare_call_address (funexp, static_chain_value,
+      funexp = prepare_call_address (fndecl, funexp, static_chain_value,
 				     &call_fusage, reg_parm_seen, pass == 0);
 
       load_register_parameters (args, num_actuals, &call_fusage, flags,
@@ -3735,7 +3739,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
   else
     argnum = 0;
 
-  fun = prepare_call_address (fun, NULL, &call_fusage, 0, 0);
+  fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0);
 
   /* Now load any reg parms into their regs.  */
 
diff --git a/gcc/df-scan.c b/gcc/df-scan.c
index 35be03c..45df29e 100644
--- a/gcc/df-scan.c
+++ b/gcc/df-scan.c
@@ -3601,18 +3601,6 @@ df_recompute_luids (basic_block bb)
 }
 
 
-/* Returns true if the function entry needs to 
-   define the static chain register.  */
-
-static bool
-df_need_static_chain_reg (struct function *fun)
-{
-  tree fun_context = decl_function_context (fun->decl);
-  return fun_context
-         && DECL_NO_STATIC_CHAIN (fun_context) == false;
-}
-
-
 /* Collect all artificial refs at the block level for BB and add them
    to COLLECTION_REC.  */
 
@@ -3891,24 +3879,17 @@ df_get_entry_block_def_set (bitmap entry_block_defs)
 	if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
 	  bitmap_set_bit (entry_block_defs, i);
     }
-  else
-    {
-      /* If STATIC_CHAIN_INCOMING_REGNUM == STATIC_CHAIN_REGNUM
-	 only STATIC_CHAIN_REGNUM is defined.  If they are different,
-	 we only care about the STATIC_CHAIN_INCOMING_REGNUM.  */
-#ifdef STATIC_CHAIN_INCOMING_REGNUM
-      bitmap_set_bit (entry_block_defs, STATIC_CHAIN_INCOMING_REGNUM);
-#else 
-#ifdef STATIC_CHAIN_REGNUM
-      bitmap_set_bit (entry_block_defs, STATIC_CHAIN_REGNUM);
-#endif
-#endif
-    }
 
   r = targetm.calls.struct_value_rtx (current_function_decl, true);
   if (r && REG_P (r))
     bitmap_set_bit (entry_block_defs, REGNO (r));
 
+  /* If the function has an incoming STATIC_CHAIN, it has to show up
+     in the entry def set.  */
+  r = targetm.calls.static_chain (current_function_decl, true);
+  if (r && REG_P (r))
+    bitmap_set_bit (entry_block_defs, REGNO (r));
+
   if ((!reload_completed) || frame_pointer_needed)
     {
       /* Any reference to any pseudo before reload is a potential
@@ -3946,19 +3927,6 @@ df_get_entry_block_def_set (bitmap entry_block_defs)
 #endif
             
   targetm.live_on_entry (entry_block_defs);
-
-  /* If the function has an incoming STATIC_CHAIN,
-     it has to show up in the entry def set.  */
-  if (df_need_static_chain_reg (cfun))
-    {
-#ifdef STATIC_CHAIN_INCOMING_REGNUM
-      bitmap_set_bit (entry_block_defs, STATIC_CHAIN_INCOMING_REGNUM);
-#else 
-#ifdef STATIC_CHAIN_REGNUM
-      bitmap_set_bit (entry_block_defs, STATIC_CHAIN_REGNUM);
-#endif
-#endif
-    }
 }
 
 
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 0139a8b..8a51a9f 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -3684,6 +3684,16 @@ If the static chain is passed in a register, the two previous macros should
 be defined instead.
 @end defmac
 
+@deftypefn {Target Hook} rtx TARGET_STATIC_CHAIN (const_tree @var{fndecl}, bool @var{incoming_p})
+This hook replaces the use of @code{STATIC_CHAIN_REGNUM} et al for
+targets that may use different static chain locations for different
+nested functions.  This may be required if the target has function
+attributes that affect the calling conventions of the function and
+those calling conventions use different static chain locations.
+
+The default version of this hook uses @code{STATIC_CHAIN_REGNUM} et al.
+@end deftypefn
+
 @defmac DWARF_FRAME_REGISTERS
 This macro specifies the maximum number of hard registers that can be
 saved in a call frame.  This is used to size data structures used in
@@ -5099,17 +5109,17 @@ proper offset from the start of the trampoline.  On a RISC machine, it
 may be necessary to take out pieces of the address and store them
 separately.
 
-@defmac TRAMPOLINE_TEMPLATE (@var{file})
-A C statement to output, on the stream @var{file}, assembler code for a
-block of data that contains the constant parts of a trampoline.  This
-code should not include a label---the label is taken care of
-automatically.
+@deftypefn {Target Hook} void TARGET_ASM_TRAMPOLINE_TEMPLATE (FILE *@var{f})
+This hook is called by @code{assemble_trampoline_template} to output,
+on the stream @var{f}, assembler code for a block of data that contains
+the constant parts of a trampoline.  This code should not include a
+label---the label is taken care of automatically.
 
-If you do not define this macro, it means no template is needed
-for the target.  Do not define this macro on systems where the block move
+If you do not define this hook, it means no template is needed
+for the target.  Do not define this hook on systems where the block move
 code to copy the trampoline into place would be larger than the code
 to generate it on the spot.
-@end defmac
+@end deftypefn
 
 @defmac TRAMPOLINE_SECTION
 Return the section into which the trampoline template is to be placed
@@ -5123,43 +5133,38 @@ A C expression for the size in bytes of the trampoline, as an integer.
 @defmac TRAMPOLINE_ALIGNMENT
 Alignment required for trampolines, in bits.
 
-If you don't define this macro, the value of @code{BIGGEST_ALIGNMENT}
+If you don't define this macro, the value of @code{FUNCTION_ALIGNMENT}
 is used for aligning trampolines.
 @end defmac
 
-@defmac INITIALIZE_TRAMPOLINE (@var{addr}, @var{fnaddr}, @var{static_chain})
-A C statement to initialize the variable parts of a trampoline.
-@var{addr} is an RTX for the address of the trampoline; @var{fnaddr} is
-an RTX for the address of the nested function; @var{static_chain} is an
+@deftypefn {Target Hook} void TARGET_TRAMPOLINE_INIT (rtx @var{m_tramp}, tree @var{fndecl}, rtx @var{static_chain})
+This hook is called to initialize a trampoline.
+@var{m_tramp} is an RTX for the memory block for the trampoline; @var{fndecl}
+is the @code{FUNCTION_DECL} for the nested function; @var{static_chain} is an
 RTX for the static chain value that should be passed to the function
 when it is called.
-@end defmac
 
-@defmac TRAMPOLINE_ADJUST_ADDRESS (@var{addr})
-A C statement that should perform any machine-specific adjustment in
-the address of the trampoline.  Its argument contains the address that
-was passed to @code{INITIALIZE_TRAMPOLINE}.  In case the address to be
-used for a function call should be different from the address in which
-the template was stored, the different address should be assigned to
-@var{addr}.  If this macro is not defined, @var{addr} will be used for
-function calls.
+If the target defines @code{TARGET_ASM_TRAMPOLINE_TEMPLATE}, then the
+first thing this hook should do is emit a block move into @var{m_tramp}
+from the memory block returned by @code{assemble_trampoline_template}.
+Note that the block move need only cover the constant parts of the 
+trampoline.  If the target isolates the variable parts of the trampoline
+to the end, not all @code{TRAMPOLINE_SIZE} bytes need be copied.
 
-@cindex @code{TARGET_ASM_FUNCTION_EPILOGUE} and trampolines
-@cindex @code{TARGET_ASM_FUNCTION_PROLOGUE} and trampolines
-If this macro is not defined, by default the trampoline is allocated as
-a stack slot.  This default is right for most machines.  The exceptions
-are machines where it is impossible to execute instructions in the stack
-area.  On such machines, you may have to implement a separate stack,
-using this macro in conjunction with @code{TARGET_ASM_FUNCTION_PROLOGUE}
-and @code{TARGET_ASM_FUNCTION_EPILOGUE}.
-
-@var{fp} points to a data structure, a @code{struct function}, which
-describes the compilation status of the immediate containing function of
-the function which the trampoline is for.  The stack slot for the
-trampoline is in the stack frame of this containing function.  Other
-allocation strategies probably must do something analogous with this
-information.
-@end defmac
+If the target requires any other actions, such as flushing caches or
+enabling stack execution, these actions should be performed after 
+initializing the trampoline proper.
+@end deftypefn
+
+@deftypefn {Target Hook} rtx TARGET_TRAMPOLINE_ADJUST_ADDRESS (rtx @var{addr})
+This hook should perform any machine-specific adjustment in
+the address of the trampoline.  Its argument contains the address of the
+memory block that was passed to @code{TARGET_TRAMPOLINE_INIT}.  In case
+the address to be used for a function call should be different from the
+address at which the template was stored, the different address should
+be returned; otherwise @var{addr} should be returned unchanged.
+If this hook is not defined, @var{addr} will be used for function calls.
+@end deftypefn
 
 Implementing trampolines is difficult on many machines because they have
 separate instruction and data caches.  Writing into a stack location
@@ -5192,7 +5197,7 @@ code located on the stack.  The macro should expand to a series of C
 file-scope constructs (e.g.@: functions) and provide a unique entry point
 named @code{__enable_execute_stack}.  The target is responsible for
 emitting calls to the entry point in the code, for example from the
-@code{INITIALIZE_TRAMPOLINE} macro.
+@code{TARGET_TRAMPOLINE_INIT} hook.
 @end defmac
 
 To use a standard subroutine, define the following macro.  In addition,
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 9ed36b3..b3672e3 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -136,8 +136,6 @@ FIXED_VALUE_TYPE fconst1[MAX_FCONST1];
 
    In an inline procedure, the stack and frame pointer rtxs may not be
    used for anything else.  */
-rtx static_chain_rtx;		/* (REG:Pmode STATIC_CHAIN_REGNUM) */
-rtx static_chain_incoming_rtx;	/* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
 rtx pic_offset_table_rtx;	/* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
 
 /* This is used to implement __builtin_return_address for some machines.
@@ -5671,28 +5669,6 @@ init_emit_regs (void)
     = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
 #endif
 
-#ifdef STATIC_CHAIN_REGNUM
-  static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
-
-#ifdef STATIC_CHAIN_INCOMING_REGNUM
-  if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
-    static_chain_incoming_rtx
-      = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
-  else
-#endif
-    static_chain_incoming_rtx = static_chain_rtx;
-#endif
-
-#ifdef STATIC_CHAIN
-  static_chain_rtx = STATIC_CHAIN;
-
-#ifdef STATIC_CHAIN_INCOMING
-  static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
-#else
-  static_chain_incoming_rtx = static_chain_rtx;
-#endif
-#endif
-
   if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
     pic_offset_table_rtx = gen_raw_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
   else
diff --git a/gcc/expr.h b/gcc/expr.h
index 9bf0c38..4e02c24 100644
--- a/gcc/expr.h
+++ b/gcc/expr.h
@@ -618,7 +618,7 @@ extern HOST_WIDE_INT int_expr_size (tree);
    in its original home.  This becomes invalid if any more code is emitted.  */
 extern rtx hard_function_value (const_tree, const_tree, const_tree, int);
 
-extern rtx prepare_call_address (rtx, rtx, rtx *, int, int);
+extern rtx prepare_call_address (tree, rtx, rtx, rtx *, int, int);
 
 extern bool shift_return_value (enum machine_mode, bool, rtx);
 
diff --git a/gcc/final.c b/gcc/final.c
index cd36860..78a698b 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -1594,12 +1594,14 @@ profile_function (FILE *file ATTRIBUTE_UNUSED)
 #ifndef NO_PROFILE_COUNTERS
 # define NO_PROFILE_COUNTERS	0
 #endif
-#if defined(ASM_OUTPUT_REG_PUSH)
-  int sval = cfun->returns_struct;
-  rtx svrtx = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl), 1);
-#if defined(STATIC_CHAIN_INCOMING_REGNUM) || defined(STATIC_CHAIN_REGNUM)
-  int cxt = cfun->static_chain_decl != NULL;
-#endif
+#ifdef ASM_OUTPUT_REG_PUSH
+  rtx sval = NULL, chain = NULL;
+
+  if (cfun->returns_struct)
+    sval = targetm.calls.struct_value_rtx (TREE_TYPE (current_function_decl),
+					   true);
+  if (cfun->static_chain_decl)
+    chain = targetm.calls.static_chain (current_function_decl, true);
 #endif /* ASM_OUTPUT_REG_PUSH */
 
   if (! NO_PROFILE_COUNTERS)
@@ -1613,44 +1615,20 @@ profile_function (FILE *file ATTRIBUTE_UNUSED)
 
   switch_to_section (current_function_section ());
 
-#if defined(ASM_OUTPUT_REG_PUSH)
-  if (sval && svrtx != NULL_RTX && REG_P (svrtx))
-    {
-      ASM_OUTPUT_REG_PUSH (file, REGNO (svrtx));
-    }
-#endif
-
-#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
-  if (cxt)
-    ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
-#else
-#if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
-  if (cxt)
-    {
-      ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
-    }
-#endif
+#ifdef ASM_OUTPUT_REG_PUSH
+  if (sval && REG_P (sval))
+    ASM_OUTPUT_REG_PUSH (file, REGNO (sval));
+  if (chain && REG_P (chain))
+    ASM_OUTPUT_REG_PUSH (file, REGNO (chain));
 #endif
 
   FUNCTION_PROFILER (file, current_function_funcdef_no);
 
-#if defined(STATIC_CHAIN_INCOMING_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
-  if (cxt)
-    ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
-#else
-#if defined(STATIC_CHAIN_REGNUM) && defined(ASM_OUTPUT_REG_PUSH)
-  if (cxt)
-    {
-      ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
-    }
-#endif
-#endif
-
-#if defined(ASM_OUTPUT_REG_PUSH)
-  if (sval && svrtx != NULL_RTX && REG_P (svrtx))
-    {
-      ASM_OUTPUT_REG_POP (file, REGNO (svrtx));
-    }
+#ifdef ASM_OUTPUT_REG_PUSH
+  if (chain && REG_P (chain))
+    ASM_OUTPUT_REG_POP (file, REGNO (chain));
+  if (sval && REG_P (sval))
+    ASM_OUTPUT_REG_POP (file, REGNO (sval));
 #endif
 }
 
diff --git a/gcc/function.c b/gcc/function.c
index 85e2f05..6c9bea8 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4453,13 +4453,21 @@ expand_function_start (tree subr)
   if (cfun->static_chain_decl)
     {
       tree parm = cfun->static_chain_decl;
-      rtx local = gen_reg_rtx (Pmode);
+      rtx local, chain, insn;
 
-      set_decl_incoming_rtl (parm, static_chain_incoming_rtx, false);
+      local = gen_reg_rtx (Pmode);
+      chain = targetm.calls.static_chain (current_function_decl, true);
+
+      set_decl_incoming_rtl (parm, chain, false);
       SET_DECL_RTL (parm, local);
       mark_reg_pointer (local, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
 
-      emit_move_insn (local, static_chain_incoming_rtx);
+      insn = emit_move_insn (local, chain);
+
+      /* Mark the register as eliminable, similar to parameters.  */
+      if (MEM_P (chain)
+	  && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0)))
+	set_unique_reg_note (insn, REG_EQUIV, chain);
     }
 
   /* If the function receives a non-local goto, then store the
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 925246f..d415ba4 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2024,8 +2024,6 @@ extern GTY(()) rtx global_rtl[GR_MAX];
 #define arg_pointer_rtx		(global_rtl[GR_ARG_POINTER])
 
 extern GTY(()) rtx pic_offset_table_rtx;
-extern GTY(()) rtx static_chain_rtx;
-extern GTY(()) rtx static_chain_incoming_rtx;
 extern GTY(()) rtx return_address_pointer_rtx;
 
 /* Include the RTL generation functions.  */
diff --git a/gcc/stmt.c b/gcc/stmt.c
index ffd180e..d2583ca 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -1799,13 +1799,17 @@ expand_return (tree retval)
 static void
 expand_nl_goto_receiver (void)
 {
+  rtx chain;
+
   /* Clobber the FP when we get here, so we have to make sure it's
      marked as used by this function.  */
   emit_use (hard_frame_pointer_rtx);
 
   /* Mark the static chain as clobbered here so life information
      doesn't get messed up for it.  */
-  emit_clobber (static_chain_rtx);
+  chain = targetm.calls.static_chain (current_function_decl, true);
+  if (chain && REG_P (chain))
+    emit_clobber (chain);
 
 #ifdef HAVE_nonlocal_goto
   if (! HAVE_nonlocal_goto)
diff --git a/gcc/target-def.h b/gcc/target-def.h
index 728e018..2ccdc66 100644
--- a/gcc/target-def.h
+++ b/gcc/target-def.h
@@ -247,6 +247,12 @@
 #define TARGET_ASM_RECORD_GCC_SWITCHES_SECTION ".GCC.command.line"
 #endif
 
+#ifdef TRAMPOLINE_TEMPLATE
+# define TARGET_ASM_TRAMPOLINE_TEMPLATE default_asm_trampoline_template
+#else
+# define TARGET_ASM_TRAMPOLINE_TEMPLATE NULL
+#endif
+
 #define TARGET_ASM_ALIGNED_INT_OP				\
 		       {TARGET_ASM_ALIGNED_HI_OP,		\
 			TARGET_ASM_ALIGNED_SI_OP,		\
@@ -296,7 +302,8 @@
 			TARGET_ASM_RECORD_GCC_SWITCHES_SECTION,	\
 			TARGET_ASM_OUTPUT_ANCHOR,		\
 			TARGET_ASM_OUTPUT_DWARF_DTPREL,		\
-			TARGET_ASM_FINAL_POSTSCAN_INSN}
+			TARGET_ASM_FINAL_POSTSCAN_INSN,		\
+			TARGET_ASM_TRAMPOLINE_TEMPLATE }
 
 /* Scheduler hooks.  All of these default to null pointers, which
    haifa-sched.c looks for and handles.  */
@@ -607,6 +614,14 @@
 #define TARGET_UPDATE_STACK_BOUNDARY NULL
 #define TARGET_GET_DRAP_RTX NULL
 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS hook_bool_void_true
+#define TARGET_STATIC_CHAIN default_static_chain
+#define TARGET_TRAMPOLINE_INIT default_trampoline_init
+
+#ifdef TRAMPOLINE_ADJUST_ADDRESS
+# define TARGET_TRAMPOLINE_ADJUST_ADDRESS default_trampoline_adjust_address
+#else
+# define TARGET_TRAMPOLINE_ADJUST_ADDRESS NULL
+#endif
 
 #define TARGET_CALLS {						\
    TARGET_PROMOTE_FUNCTION_MODE,				\
@@ -629,7 +644,10 @@
    TARGET_INTERNAL_ARG_POINTER,					\
    TARGET_UPDATE_STACK_BOUNDARY,				\
    TARGET_GET_DRAP_RTX,						\
-   TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS				\
+   TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS,			\
+   TARGET_STATIC_CHAIN,						\
+   TARGET_TRAMPOLINE_INIT,					\
+   TARGET_TRAMPOLINE_ADJUST_ADDRESS				\
    }
 
 #ifndef TARGET_UNWIND_TABLES_DEFAULT
diff --git a/gcc/target.h b/gcc/target.h
index c57b683..f964b69 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -253,6 +253,9 @@ struct gcc_target
 
     /* Some target machines need to postscan each insn after it is output.  */
     void (*final_postscan_insn) (FILE *, rtx, rtx *, int);
+
+    /* Emit the trampoline template.  This hook may be NULL.  */
+    void (*trampoline_template) (FILE *);
   } asm_out;
 
   /* Functions relating to instruction scheduling.  */
@@ -915,7 +918,17 @@ struct gcc_target
     /* Return true if all function parameters should be spilled to the
        stack.  */
     bool (*allocate_stack_slots_for_args) (void);
-    
+
+    /* Return an rtx for the static chain for FNDECL.  If INCOMING_P is true,
+       then it should be for the callee; otherwise for the caller.  */
+    rtx (*static_chain) (const_tree fndecl, bool incoming_p);
+
+    /* Fill in the trampoline at MEM with a call to FNDECL and a 
+       static chain value of CHAIN.  */
+    void (*trampoline_init) (rtx mem, tree fndecl, rtx chain);
+
+    /* Adjust the address of the trampoline in a target-specific way.  */
+    rtx (*trampoline_adjust_address) (rtx addr);
   } calls;
 
   /* Return the diagnostic message string if conversion from FROMTYPE
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 8480c0b..48401fb 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -628,6 +628,69 @@ default_internal_arg_pointer (void)
     return virtual_incoming_args_rtx;
 }
 
+rtx
+default_static_chain (const_tree fndecl, bool incoming_p)
+{
+  if (DECL_NO_STATIC_CHAIN (fndecl))
+    return NULL;
+
+  if (incoming_p)
+    {
+#ifdef STATIC_CHAIN_INCOMING
+      return STATIC_CHAIN_INCOMING;
+#endif
+#ifdef STATIC_CHAIN_INCOMING_REGNUM
+      return gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
+#endif
+    }
+
+#ifdef STATIC_CHAIN
+  return STATIC_CHAIN;
+#endif
+#ifdef STATIC_CHAIN_REGNUM
+  return gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
+#endif
+
+  gcc_unreachable ();
+}
+
+#ifdef TRAMPOLINE_TEMPLATE
+void
+default_asm_trampoline_template (FILE *f)
+{
+  TRAMPOLINE_TEMPLATE (f);
+}
+#endif
+
+void
+default_trampoline_init (rtx ARG_UNUSED (m_tramp), tree ARG_UNUSED (t_func),
+			 rtx ARG_UNUSED (r_chain))
+{
+#ifdef INITIALIZE_TRAMPOLINE
+  rtx r_tramp, r_func;
+
+  if (targetm.asm_out.trampoline_template)
+    emit_block_move (m_tramp, assemble_trampoline_template (),
+		     GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  r_func = XEXP (DECL_RTL (t_func), 0);
+  r_tramp = XEXP (m_tramp, 0);
+
+  INITIALIZE_TRAMPOLINE (r_tramp, r_func, r_chain);
+#else
+  sorry ("nested function trampolines not supported on this target");
+#endif
+}
+
+rtx
+default_trampoline_adjust_address (rtx addr)
+{
+#ifdef TRAMPOLINE_ADJUST_ADDRESS
+  TRAMPOLINE_ADJUST_ADDRESS (addr);
+#endif
+  return addr;
+}
+
 enum reg_class
 default_branch_target_register_class (void)
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 7a93552..1a0dc56 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -100,6 +100,10 @@ extern bool hook_bool_const_rtx_commutative_p (const_rtx, int);
 extern rtx default_function_value (const_tree, const_tree, bool);
 extern rtx default_libcall_value (enum machine_mode, rtx);
 extern rtx default_internal_arg_pointer (void);
+extern rtx default_static_chain (const_tree, bool);
+extern void default_asm_trampoline_template (FILE *);
+extern void default_trampoline_init (rtx, tree, rtx);
+extern rtx default_trampoline_adjust_address (rtx);
 extern enum reg_class default_branch_target_register_class (void);
 #ifdef IRA_COVER_CLASSES
 extern const enum reg_class *default_ira_cover_classes (void);
diff --git a/gcc/varasm.c b/gcc/varasm.c
index f8cc291..1d9bcdd 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -2507,7 +2507,6 @@ assemble_static_space (unsigned HOST_WIDE_INT size)
 
 static GTY(()) rtx initial_trampoline;
 
-#ifdef TRAMPOLINE_TEMPLATE
 rtx
 assemble_trampoline_template (void)
 {
@@ -2516,6 +2515,8 @@ assemble_trampoline_template (void)
   int align;
   rtx symbol;
 
+  gcc_assert (targetm.asm_out.trampoline_template != NULL);
+
   if (initial_trampoline)
     return initial_trampoline;
 
@@ -2530,12 +2531,10 @@ assemble_trampoline_template (void)
   /* Write the assembler code to define one.  */
   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
   if (align > 0)
-    {
-      ASM_OUTPUT_ALIGN (asm_out_file, align);
-    }
+    ASM_OUTPUT_ALIGN (asm_out_file, align);
 
   targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
-  TRAMPOLINE_TEMPLATE (asm_out_file);
+  targetm.asm_out.trampoline_template (asm_out_file);
 
   /* Record the rtl to refer to it.  */
   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
@@ -2543,12 +2542,12 @@ assemble_trampoline_template (void)
   symbol = gen_rtx_SYMBOL_REF (Pmode, name);
   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
 
-  initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
+  initial_trampoline = gen_const_mem (BLKmode, symbol);
   set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
+  set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
 
   return initial_trampoline;
 }
-#endif
 \f
 /* A and B are either alignments or offsets.  Return the minimum alignment
    that may be assumed after adding the two together.  */

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 02/36][alpha] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
@ 2009-09-21 22:14 ` Richard Henderson
  2009-09-21 22:17 ` [patch 03/36][arc] " Richard Henderson
                   ` (33 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:14 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

I merged the trampoline template into the trampoline initialization 
here.  The odd VMS parameters are gone, replaced by code directly in the 
VMS code block already in alpha_trampoline_init.


r~

[-- Attachment #2: d-tramp-02-alpha --]
[-- Type: text/plain, Size: 8901 bytes --]

	* config/alpha/alpha.c (alpha_trampoline_init): Rename from
	alpha_initialize_trampoline.  Make static.  Merge VMS parameter
	differences into the TARGET_ABI_OPEN_VMS code block.
	(TARGET_TRAMPOLINE_INIT): New.
	* config/alpha/alpha.h (TRAMPOLINE_TEMPLATE): Remove.
	(TRAMPOLINE_SECTION, INITIALIZE_TRAMPOLINE): Remove.
	* config/alpha/vms.h (TRAMPOLINE_SIZE, TRAMPOLINE_ALIGNMENT): Remove.
	(INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 46ad8f4..86fd1ee 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -5541,34 +5541,23 @@ print_operand_address (FILE *file, rtx addr)
 }
 \f
 /* Emit RTL insns to initialize the variable parts of a trampoline at
-   TRAMP. 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.
+   M_TRAMP.  FNDECL is target function's decl.  CHAIN_VALUE is an rtx
+   for the static chain value for the function.  */
 
-   The three offset parameters are for the individual template's
-   layout.  A JMPOFS < 0 indicates that the trampoline does not
-   contain instructions at all.
-
-   We assume here that a function will be called many more times than
-   its address is taken (e.g., it might be passed to qsort), so we
-   take the trouble to initialize the "hint" field in the JMP insn.
-   Note that the hint field is PC (new) + 4 * bits 13:0.  */
-
-void
-alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
-			     int fnofs, int cxtofs, int jmpofs)
+static void
+alpha_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
-  rtx addr;
-  /* VMS really uses DImode pointers in memory at this point.  */
-  enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode;
+  rtx fnaddr, mem, word1, word2;
+
+  fnaddr = XEXP (DECL_RTL (fndecl), 0);
 
 #ifdef POINTERS_EXTEND_UNSIGNED
-  fnaddr = convert_memory_address (mode, fnaddr);
-  cxt = convert_memory_address (mode, cxt);
+  fnaddr = convert_memory_address (Pmode, fnaddr);
+  chain_value = convert_memory_address (Pmode, chain_value);
 #endif
 
   if (TARGET_ABI_OPEN_VMS)
     {
-      rtx temp1, traddr;
       const char *fnname;
       char *trname;
 
@@ -5577,37 +5566,48 @@ alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
       trname = (char *) alloca (strlen (fnname) + 5);
       strcpy (trname, fnname);
       strcat (trname, "..tr");
-      traddr = gen_rtx_SYMBOL_REF
-	(mode, ggc_alloc_string (trname, strlen (trname) + 1));
+      fnname = ggc_alloc_string (trname, strlen (trname) + 1);
+      word2 = gen_rtx_SYMBOL_REF (Pmode, fnname);
 
       /* Trampoline (or "bounded") procedure descriptor is constructed from
 	 the function's procedure descriptor with certain fields zeroed IAW
 	 the VMS calling standard. This is stored in the first quadword.  */
-      temp1 = force_reg (DImode, gen_rtx_MEM (DImode, fnaddr));
-      temp1 = expand_and (DImode, temp1,
-			  GEN_INT (0xffff0fff0000fff0), NULL_RTX);
-      addr = memory_address (mode, plus_constant (tramp, 0));
-      emit_move_insn (gen_rtx_MEM (DImode, addr), temp1);
-
-      /* Trampoline transfer address is stored in the second quadword
-	 of the trampoline.  */
-      addr = memory_address (mode, plus_constant (tramp, 8));
-      emit_move_insn (gen_rtx_MEM (mode, addr), traddr);
+      word1 = force_reg (DImode, gen_const_mem (DImode, fnaddr));
+      word1 = expand_and (DImode, word1, GEN_INT (0xffff0fff0000fff0), NULL);
     }
+  else
+    {
+      /* These 4 instructions are:
+	    ldq $1,24($27)
+	    ldq $27,16($27)
+	    jmp $31,($27),0
+	    nop
+	 We don't bother setting the HINT field of the jump; the nop
+	 is merely there for padding.  */
+      word1 = GEN_INT (0xa77b0010a43b0018);
+      word2 = GEN_INT (0x47ff041f6bfb0000);
+    }
+
+  /* Store the first two words, as computed above.  */
+  mem = adjust_address (m_tramp, DImode, 0);
+  emit_move_insn (mem, word1);
+  mem = adjust_address (m_tramp, DImode, 8);
+  emit_move_insn (mem, word2);
+
+  /* Store function address and static chain value.  */
+  mem = adjust_address (m_tramp, Pmode, 16);
+  emit_move_insn (mem, fnaddr);
+  mem = adjust_address (m_tramp, Pmode, 24);
+  emit_move_insn (mem, chain_value);
 
-  /* Store function address and CXT.  */
-  addr = memory_address (mode, plus_constant (tramp, fnofs));
-  emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr);
-  addr = memory_address (mode, plus_constant (tramp, cxtofs));
-  emit_move_insn (gen_rtx_MEM (mode, addr), cxt);
-
+  if (!TARGET_ABI_OPEN_VMS)
+    {
+      emit_insn (gen_imb ());
 #ifdef ENABLE_EXECUTE_STACK
-  emit_library_call (init_one_libfunc ("__enable_execute_stack"),
-		     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+      emit_library_call (init_one_libfunc ("__enable_execute_stack"),
+			 LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
 #endif
-
-  if (jmpofs >= 0)
-    emit_insn (gen_imb ());
+    }
 }
 \f
 /* Determine where to put an argument to a function.
@@ -11114,6 +11114,8 @@ alpha_init_libfuncs (void)
 #define TARGET_GIMPLIFY_VA_ARG_EXPR alpha_gimplify_va_arg
 #undef TARGET_ARG_PARTIAL_BYTES
 #define TARGET_ARG_PARTIAL_BYTES alpha_arg_partial_bytes
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT alpha_trampoline_init
 
 #undef TARGET_SECONDARY_RELOAD
 #define TARGET_SECONDARY_RELOAD alpha_secondary_reload
diff --git a/gcc/config/alpha/alpha.h b/gcc/config/alpha/alpha.h
index cd8c11e..6235d9f 100644
--- a/gcc/config/alpha/alpha.h
+++ b/gcc/config/alpha/alpha.h
@@ -838,28 +838,6 @@ extern int alpha_memory_latency;
 
 #define EPILOGUE_USES(REGNO)	((REGNO) == 26)
 \f
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.
-
-   The trampoline should set the static chain pointer to value placed
-   into the trampoline and should branch to the specified routine.
-   Note that $27 has been set to the address of the trampoline, so we can
-   use it for addressability of the two data items.  */
-
-#define TRAMPOLINE_TEMPLATE(FILE)		\
-do {						\
-  fprintf (FILE, "\tldq $1,24($27)\n");		\
-  fprintf (FILE, "\tldq $27,16($27)\n");	\
-  fprintf (FILE, "\tjmp $31,($27),0\n");	\
-  fprintf (FILE, "\tnop\n");			\
-  fprintf (FILE, "\t.quad 0,0\n");		\
-} while (0)
-
-/* Section in which to place the trampoline.  On Alpha, instructions
-   may only be placed in a text segment.  */
-
-#define TRAMPOLINE_SECTION text_section
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE    32
@@ -868,13 +846,6 @@ do {						\
 
 #define TRAMPOLINE_ALIGNMENT  64
 
-/* 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) \
-  alpha_initialize_trampoline (TRAMP, FNADDR, CXT, 16, 24, 8)
-
 /* A C expression whose value is RTL representing the value of the return
    address for the frame COUNT steps up from the current frame.
    FRAMEADDR is the frame pointer of the COUNT frame, or the frame pointer of
diff --git a/gcc/config/alpha/alpha.md b/gcc/config/alpha/alpha.md
index ca90327..2773008 100644
--- a/gcc/config/alpha/alpha.md
+++ b/gcc/config/alpha/alpha.md
@@ -4869,7 +4869,7 @@
   "jmp $31,(%0),0"
   [(set_attr "type" "ibr")])
 
-;; Cache flush.  Used by INITIALIZE_TRAMPOLINE.  0x86 is PAL_imb, but we don't
+;; Cache flush.  Used by alpha_trampoline_init.  0x86 is PAL_imb, but we don't
 ;; want to have to include pal.h in our .s file.
 (define_insn "imb"
   [(unspec_volatile [(const_int 0)] UNSPECV_IMB)]
diff --git a/gcc/config/alpha/vms.h b/gcc/config/alpha/vms.h
index cb84a04..c0b20f8 100644
--- a/gcc/config/alpha/vms.h
+++ b/gcc/config/alpha/vms.h
@@ -225,26 +225,6 @@ typedef struct {int num_args; enum avms_arg_type atypes[6];} avms_arg_info;
 #define ASM_OUTPUT_ALIGNED_DECL_COMMON(FILE, DECL, NAME, SIZE, ALIGN) \
   vms_output_aligned_decl_common (FILE, DECL, NAME, SIZE, ALIGN)
 \f
-#undef TRAMPOLINE_TEMPLATE
-
-/* Length in units of the trampoline for entering a nested function.  */
-
-#undef TRAMPOLINE_SIZE
-#define TRAMPOLINE_SIZE    32
-
-/* The alignment of a trampoline, in bits.  */
-
-#undef TRAMPOLINE_ALIGNMENT
-#define TRAMPOLINE_ALIGNMENT  64
-
-/* 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.  */
-
-#undef INITIALIZE_TRAMPOLINE
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
-  alpha_initialize_trampoline (TRAMP, FNADDR, CXT, 16, 24, -1)
-
 /* Control how constructors and destructors are emitted.  */
 #define TARGET_ASM_CONSTRUCTOR  vms_asm_out_constructor
 #define TARGET_ASM_DESTRUCTOR   vms_asm_out_destructor

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 03/36][arc] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
  2009-09-21 22:14 ` [patch 02/36][alpha] " Richard Henderson
@ 2009-09-21 22:17 ` Richard Henderson
  2009-09-21 22:19 ` [patch 04/36][ARM] " Richard Henderson
                   ` (32 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:17 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 213 bytes --]

If anyone ever tries to revive the ARC port, I've added a note saying 
that they should look into TARGET_TRAMPOLINE_ADJUST_ADDRESS to solve 
some problem concerning some sort of right-shift that's mentioned.


r~

[-- Attachment #2: d-tramp-03-arc --]
[-- Type: text/plain, Size: 4022 bytes --]

	* config/arc/arc.h (TRAMPOLINE_ALIGNMENT): New.
	(TRAMPOLINE_TEMPLATE): Merge with ...
	(INITIALIZE_TRAMPOLINE): ... this and move ...
	* config/arc/arc.c (arc_trampoline_init): ... here.
	(TARGET_TRAMPOLINE_INIT): New.


diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index f53c898..9239a34 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -94,6 +94,8 @@ static void arc_external_libcall (rtx);
 static bool arc_return_in_memory (const_tree, const_tree);
 static bool arc_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 				   const_tree, bool);
+static void arc_trampoline_init (rtx, tree, rtx);
+
 \f
 /* ARC specific attributs.  */
 
@@ -151,6 +153,9 @@ static const struct attribute_spec arc_attribute_table[] =
 #undef TARGET_EXPAND_BUILTIN_VA_START
 #define TARGET_EXPAND_BUILTIN_VA_START arc_va_start
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT arc_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Implement TARGET_HANDLE_OPTION.  */
@@ -2343,3 +2348,39 @@ arc_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
 
   return size > 8;
 }
+
+/* Trampolines.  */
+/* ??? This doesn't work yet because GCC will use as the address of a nested
+   function the address of the trampoline.  We need to use that address
+   right shifted by 2.  It looks like we'll need PSImode after all. :-( 
+
+   ??? The above comment sounds like it's doable via
+   TARGET_TRAMPOLINE_ADJUST_ADDRESS; no PSImode needed.
+
+   On the ARC, the trampoline is quite simple as we have 32-bit immediate
+   constants.
+
+	mov r24,STATIC
+	j.nd FUNCTION
+*/
+
+static void
+arc_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTX (fndecl), 0);
+  rtx mem;
+
+  mem = adjust_address (m_tramp, SImode, 0);
+  emit_move_insn (mem, GEN_INT (0x631f7c00));
+
+  mem = adjust_address (m_tramp, SImode, 4);
+  emit_move_insn (mem, chain_value);
+
+  mem = adjust_address (m_tramp, SImode, 8);
+  emit_move_insn (mem, GEN_INT (0x381f0000));
+
+  mem = adjust_address (m_tramp, SImode, 12);
+  emit_move_insn (mem, fnaddr);
+
+  emit_insn (gen_flush_icache (m_tramp));
+}
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index e19048d..5127a12 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -657,39 +657,8 @@ arc_eligible_for_epilogue_delay (TRIAL, SLOTS_FILLED)
    for profiling a function entry.  */
 #define FUNCTION_PROFILER(FILE, LABELNO)
 \f
-/* Trampolines.  */
-/* ??? This doesn't work yet because GCC will use as the address of a nested
-   function the address of the trampoline.  We need to use that address
-   right shifted by 2.  It looks like we'll need PSImode after all. :-(  */
-
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.  */
-/* On the ARC, the trampoline is quite simple as we have 32-bit immediate
-   constants.
-
-	mov r24,STATIC
-	j.nd FUNCTION
-*/
-#define TRAMPOLINE_TEMPLATE(FILE) \
-do { \
-  assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0x631f7c00)); \
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); \
-  assemble_aligned_integer (UNITS_PER_WORD, GEN_INT (0x381f0000)); \
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx); \
-} while (0)
-
-/* Length in units of the trampoline for entering a nested function.  */
+#define TRAMPOLINE_ALIGNMENT 32
 #define TRAMPOLINE_SIZE 16
-
-/* 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) \
-do { \
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 4)), CXT); \
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 12)), FNADDR); \
-  emit_insn (gen_flush_icache (validize_mem (gen_rtx_MEM (SImode, TRAMP)))); \
-} while (0)
 \f
 /* Addressing modes, and classification of registers for them.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 04/36][ARM] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
  2009-09-21 22:14 ` [patch 02/36][alpha] " Richard Henderson
  2009-09-21 22:17 ` [patch 03/36][arc] " Richard Henderson
@ 2009-09-21 22:19 ` Richard Henderson
  2009-09-21 22:26 ` [patch 05/36][AVR] " Richard Henderson
                   ` (31 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:19 UTC (permalink / raw)
  To: GCC Patches, richard.earnshaw

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

This is a straght-forward conversion to the target hooks.

I suspect that the ASM_OUTPUT_ALIGN that had been in the 
THUMB1_TRAMPOLINE_TEMPLATE isn't needed.  We already have that alignment 
from assemble_trampoline_template.


r~

[-- Attachment #2: d-tramp-04-arm --]
[-- Type: text/plain, Size: 8705 bytes --]

	* config/arm/arm.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT, TARGET_TRAMPOLINE_ADJUST_ADDRESS): New.
	(arm_asm_trampoline_template): New.
	(arm_trampoline_init, arm_trampoline_adjust_address): New.
	* config/arm/arm.h (TRAMPOLINE_TEMPLATE, ARM_TRAMPOLINE_TEMPLATE,
	THUMB2_TRAMPOLINE_TEMPLATE, THUMB1_TRAMPOLINE_TEMPLATE): Move all
	code to arm_asm_trampoline_template.
	(TRAMPOLINE_ADJUST_ADDRESS): Move code to
	arm_trampoline_adjust_address.
	(INITIALIZE_TRAMPOLINE): Move code to arm_trampoline_init;
	adjust for target hook parameters.



diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 1cc9557..efc329b 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -219,6 +219,9 @@ static tree arm_convert_to_type (tree type, tree expr);
 static bool arm_scalar_mode_supported_p (enum machine_mode);
 static bool arm_frame_pointer_required (void);
 static bool arm_can_eliminate (const int, const int);
+static void arm_asm_trampoline_template (FILE *);
+static void arm_trampoline_init (rtx, tree, rtx);
+static rtx arm_trampoline_adjust_address (rtx);
 
 \f
 /* Table of machine attributes.  */
@@ -366,6 +369,13 @@ static const struct attribute_spec arm_attribute_table[] =
 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS arm_allocate_stack_slots_for_args
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE arm_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT arm_trampoline_init
+#undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
+#define TARGET_TRAMPOLINE_ADJUST_ADDRESS arm_trampoline_adjust_address
+
 #undef TARGET_DEFAULT_SHORT_ENUMS
 #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums
 
@@ -1986,6 +1996,84 @@ arm_allocate_stack_slots_for_args (void)
 }
 
 \f
+/* Output assembler code for a block containing the constant parts
+   of a trampoline, leaving space for the variable parts.
+
+   On the ARM, (if r8 is the static chain regnum, and remembering that
+   referencing pc adds an offset of 8) the trampoline looks like:
+	   ldr 		r8, [pc, #0]
+	   ldr		pc, [pc]
+	   .word	static chain value
+	   .word	function's address
+   XXX FIXME: When the trampoline returns, r8 will be clobbered.  */
+
+static void
+arm_asm_trampoline_template (FILE *f)
+{
+  if (TARGET_ARM)
+    {
+      asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", STATIC_CHAIN_REGNUM, PC_REGNUM);
+      asm_fprintf (f, "\tldr\t%r, [%r, #0]\n", PC_REGNUM, PC_REGNUM);
+    }
+  else if (TARGET_THUMB2)
+    {
+      /* The Thumb-2 trampoline is similar to the arm implementation.
+	 Unlike 16-bit Thumb, we enter the stub in thumb mode.  */
+      asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n",
+		   STATIC_CHAIN_REGNUM, PC_REGNUM);
+      asm_fprintf (f, "\tldr.w\t%r, [%r, #4]\n", PC_REGNUM, PC_REGNUM);
+    }
+  else
+    {
+      ASM_OUTPUT_ALIGN (f, 2);
+      fprintf (f, "\t.code\t16\n");
+      fprintf (f, ".Ltrampoline_start:\n");
+      asm_fprintf (f, "\tpush\t{r0, r1}\n");
+      asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
+      asm_fprintf (f, "\tmov\t%r, r0\n", STATIC_CHAIN_REGNUM);
+      asm_fprintf (f, "\tldr\tr0, [%r, #8]\n", PC_REGNUM);
+      asm_fprintf (f, "\tstr\tr0, [%r, #4]\n", SP_REGNUM);
+      asm_fprintf (f, "\tpop\t{r0, %r}\n", PC_REGNUM);
+    }
+  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
+  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);
+}
+
+/* Emit RTL insns to initialize the variable parts of a trampoline.  */
+
+static void
+arm_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr, mem, a_tramp;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 8 : 12);
+  emit_move_insn (mem, chain_value);
+
+  mem = adjust_address (m_tramp, SImode, TARGET_32BIT ? 12 : 16);
+  fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  emit_move_insn (mem, fnaddr);
+
+  a_tramp = XEXP (m_tramp, 0);
+  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
+		     LCT_NORMAL, VOIDmode, 2, a_tramp, Pmode,
+		     plus_constant (a_tramp, TRAMPOLINE_SIZE), Pmode);
+}
+
+/* Thumb trampolines should be entered in thumb mode, so set
+   the bottom bit of the address.  */
+
+static rtx
+arm_trampoline_adjust_address (rtx addr)
+{
+  if (TARGET_THUMB)
+    addr = expand_simple_binop (Pmode, IOR, addr, const1_rtx,
+				NULL, 0, OPTAB_LIB_WIDEN);
+  return addr;
+}
+\f
 /* Return 1 if it is possible to return using a single instruction.
    If SIBLING is non-null, this is a test for a return before a sibling
    call.  SIBLING is the call insn, so we can examine its register usage.  */
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index 215c9fb..9272ca5 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -1861,102 +1861,11 @@ typedef struct
    once for every function before code is generated.  */
 #define INIT_EXPANDERS  arm_init_expanders ()
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.
-
-   On the ARM, (if r8 is the static chain regnum, and remembering that
-   referencing pc adds an offset of 8) the trampoline looks like:
-	   ldr 		r8, [pc, #0]
-	   ldr		pc, [pc]
-	   .word	static chain value
-	   .word	function's address
-   XXX FIXME: When the trampoline returns, r8 will be clobbered.  */
-#define ARM_TRAMPOLINE_TEMPLATE(FILE)				\
-{								\
-  asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",			\
-	       STATIC_CHAIN_REGNUM, PC_REGNUM);			\
-  asm_fprintf (FILE, "\tldr\t%r, [%r, #0]\n",			\
-	       PC_REGNUM, PC_REGNUM);				\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-}
-
-/* The Thumb-2 trampoline is similar to the arm implementation.
-   Unlike 16-bit Thumb, we enter the stub in thumb mode.  */
-#define THUMB2_TRAMPOLINE_TEMPLATE(FILE)			\
-{								\
-  asm_fprintf (FILE, "\tldr.w\t%r, [%r, #4]\n",			\
-	       STATIC_CHAIN_REGNUM, PC_REGNUM);			\
-  asm_fprintf (FILE, "\tldr.w\t%r, [%r, #4]\n",			\
-	       PC_REGNUM, PC_REGNUM);				\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-}
-
-#define THUMB1_TRAMPOLINE_TEMPLATE(FILE)	\
-{						\
-  ASM_OUTPUT_ALIGN(FILE, 2);			\
-  fprintf (FILE, "\t.code\t16\n");		\
-  fprintf (FILE, ".Ltrampoline_start:\n");	\
-  asm_fprintf (FILE, "\tpush\t{r0, r1}\n");	\
-  asm_fprintf (FILE, "\tldr\tr0, [%r, #8]\n",	\
-	       PC_REGNUM);			\
-  asm_fprintf (FILE, "\tmov\t%r, r0\n",		\
-	       STATIC_CHAIN_REGNUM);		\
-  asm_fprintf (FILE, "\tldr\tr0, [%r, #8]\n",	\
-	       PC_REGNUM);			\
-  asm_fprintf (FILE, "\tstr\tr0, [%r, #4]\n",	\
-	       SP_REGNUM);			\
-  asm_fprintf (FILE, "\tpop\t{r0, %r}\n",	\
-	       PC_REGNUM);			\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-  assemble_aligned_integer (UNITS_PER_WORD, const0_rtx);	\
-}
-
-#define TRAMPOLINE_TEMPLATE(FILE)		\
-  if (TARGET_ARM)				\
-    ARM_TRAMPOLINE_TEMPLATE (FILE)		\
-  else if (TARGET_THUMB2)			\
-    THUMB2_TRAMPOLINE_TEMPLATE (FILE)		\
-  else						\
-    THUMB1_TRAMPOLINE_TEMPLATE (FILE)
-
-/* Thumb trampolines should be entered in thumb mode, so set the bottom bit
-   of the address.  */
-#define TRAMPOLINE_ADJUST_ADDRESS(ADDR) do				    \
-{									    \
-  if (TARGET_THUMB)							    \
-    (ADDR) = expand_simple_binop (Pmode, IOR, (ADDR), GEN_INT(1),	    \
-				  gen_reg_rtx (Pmode), 0, OPTAB_LIB_WIDEN); \
-} while(0)
-
 /* Length in units of the trampoline for entering a nested function.  */
 #define TRAMPOLINE_SIZE  (TARGET_32BIT ? 16 : 20)
 
 /* Alignment required for a trampoline in bits.  */
 #define TRAMPOLINE_ALIGNMENT  32
-
-
-/* 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.  */
-#ifndef INITIALIZE_TRAMPOLINE
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (SImode,					\
-			       plus_constant (TRAMP,			\
-					      TARGET_32BIT ? 8 : 12)),	\
-		  CXT);							\
-  emit_move_insn (gen_rtx_MEM (SImode,					\
-			       plus_constant (TRAMP,			\
-					      TARGET_32BIT ? 12 : 16)),	\
-		  FNADDR);						\
-  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),	\
-		     LCT_NORMAL, VOIDmode, 2, TRAMP, Pmode,		\
-		     plus_constant (TRAMP, TRAMPOLINE_SIZE), Pmode);	\
-}
-#endif
-
 \f
 /* Addressing modes, and classification of registers for them.  */
 #define HAVE_POST_INCREMENT   1

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 05/36][AVR] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (2 preceding siblings ...)
  2009-09-21 22:19 ` [patch 04/36][ARM] " Richard Henderson
@ 2009-09-21 22:26 ` Richard Henderson
  2009-09-21 22:28 ` [patch 06/36][bfin] " Richard Henderson
                   ` (30 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:26 UTC (permalink / raw)
  To: GCC Patches; +Cc: aesok

[-- Attachment #1: Type: text/plain, Size: 183 bytes --]

AVR doesn't support templates, and so doesn't require these macros 
simply to compile.  Unfortunately, TRAMPOLINE_SIZE is still required; I 
didn't get *that* far in my cleanup.


r~

[-- Attachment #2: d-tramp-05-avr --]
[-- Type: text/plain, Size: 829 bytes --]

	* config/avr/avr.h (TRAMPOLINE_TEMPLATE, INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h
index ff40939..53e20f9 100644
--- a/gcc/config/avr/avr.h
+++ b/gcc/config/avr/avr.h
@@ -722,16 +722,8 @@ fprintf (STREAM, "\t.skip %lu,0\n", (unsigned long)(N))
 
 #define NO_DOLLAR_IN_LABEL 1
 
-#define TRAMPOLINE_TEMPLATE(FILE) \
-  internal_error ("trampolines not supported")
-
 #define TRAMPOLINE_SIZE 4
 
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			      \
-{									      \
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant ((TRAMP), 2)), CXT);    \
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant ((TRAMP), 6)), FNADDR); \
-}
 /* Store in cc_status the expressions
    that the condition codes will describe
    after execution of an instruction whose pattern is EXP.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 06/36][bfin] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (3 preceding siblings ...)
  2009-09-21 22:26 ` [patch 05/36][AVR] " Richard Henderson
@ 2009-09-21 22:28 ` Richard Henderson
  2009-09-21 22:29 ` [patch 07/36][cris] " Richard Henderson
                   ` (29 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:28 UTC (permalink / raw)
  To: GCC Patches; +Cc: bernd.schmidt

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

A straight-forward conversion to hooks.

As an improvement, a TARGET_FDPIC trampoline should not contain 
instructions at all.  It should build a fake function descriptor and use 
an external helper routine, similar to how we handle ia64.


r~

[-- Attachment #2: d-tramp-06-bfin --]
[-- Type: text/plain, Size: 6444 bytes --]

	* config/bfin/bfin-protos.h (initialize_trampoline): Remove.
	* config/bfin/bfin.c (bfin_asm_trampoline_template): New.
	(bfin_trampoline_init): Rename from initialize_trampoline;
	make static; update for target hook parameters.
	(TARGET_ASM_TRAMPOLINE_TEMPLATE, TARGET_TRAMPOLINE_INIT): New.
	* config/bfin/bfin.h (TRAMPOLINE_TEMPLATE): Move code to
	bfin_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/bfin/bfin-protos.h b/gcc/config/bfin/bfin-protos.h
index b2d3d8c..4a9b7a1 100644
--- a/gcc/config/bfin/bfin-protos.h
+++ b/gcc/config/bfin/bfin-protos.h
@@ -110,7 +110,6 @@ extern void asm_conditional_branch (rtx, rtx *, int, int);
 extern rtx bfin_gen_compare (rtx, Mmode);
 
 extern int bfin_local_alignment (tree, int);
-extern void initialize_trampoline (rtx, rtx, rtx);
 extern rtx bfin_va_arg (tree, tree);
 
 extern void bfin_expand_prologue (void);
diff --git a/gcc/config/bfin/bfin.c b/gcc/config/bfin/bfin.c
index 92aaf57..32d72ab 100644
--- a/gcc/config/bfin/bfin.c
+++ b/gcc/config/bfin/bfin.c
@@ -2094,37 +2094,67 @@ bfin_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
   return !called_func->local || this_func->local;
 }
 \f
+/* Write a template for a trampoline to F.  */
+
+static void
+bfin_asm_trampoline_template (FILE *f)
+{
+  if (TARGET_FDPIC)
+    {
+      fprintf (f, "\t.dd\t0x00000000\n");	/* 0 */
+      fprintf (f, "\t.dd\t0x00000000\n");	/* 0 */
+      fprintf (f, "\t.dd\t0x0000e109\n");	/* p1.l = fn low */
+      fprintf (f, "\t.dd\t0x0000e149\n");	/* p1.h = fn high */
+      fprintf (f, "\t.dd\t0x0000e10a\n");	/* p2.l = sc low */
+      fprintf (f, "\t.dd\t0x0000e14a\n");	/* p2.h = sc high */
+      fprintf (f, "\t.dw\t0xac4b\n");		/* p3 = [p1 + 4] */
+      fprintf (f, "\t.dw\t0x9149\n");		/* p1 = [p1] */
+      fprintf (f, "\t.dw\t0x0051\n");		/* jump (p1)*/
+    }
+  else
+    {
+      fprintf (f, "\t.dd\t0x0000e109\n");	/* p1.l = fn low */
+      fprintf (f, "\t.dd\t0x0000e149\n");	/* p1.h = fn high */
+      fprintf (f, "\t.dd\t0x0000e10a\n");	/* p2.l = sc low */
+      fprintf (f, "\t.dd\t0x0000e14a\n");	/* p2.h = sc high */
+      fprintf (f, "\t.dw\t0x0051\n");		/* jump (p1)*/
+    }
+}
+
 /* Emit RTL insns to initialize the variable parts of a trampoline at
-   TRAMP. 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.  */
+   M_TRAMP. FNDECL is the target function.  CHAIN_VALUE is an RTX for
+   the static chain value for the function.  */
 
-void
-initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+bfin_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
-  rtx t1 = copy_to_reg (fnaddr);
-  rtx t2 = copy_to_reg (cxt);
-  rtx addr;
+  rtx t1 = copy_to_reg (XEXP (DECL_RTL (fndecl), 0));
+  rtx t2 = copy_to_reg (chain_value);
+  rtx mem;
   int i = 0;
 
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
   if (TARGET_FDPIC)
     {
-      rtx a = memory_address (Pmode, plus_constant (tramp, 8));
-      addr = memory_address (Pmode, tramp);
-      emit_move_insn (gen_rtx_MEM (SImode, addr), a);
+      rtx a = force_reg (Pmode, plus_constant (XEXP (m_tramp, 0), 8));
+      mem = adjust_address (m_tramp, Pmode, 0);
+      emit_move_insn (mem, a);
       i = 8;
     }
 
-  addr = memory_address (Pmode, plus_constant (tramp, i + 2));
-  emit_move_insn (gen_rtx_MEM (HImode, addr), gen_lowpart (HImode, t1));
+  mem = adjust_address (m_tramp, HImode, i + 2);
+  emit_move_insn (mem, gen_lowpart (HImode, t1));
   emit_insn (gen_ashrsi3 (t1, t1, GEN_INT (16)));
-  addr = memory_address (Pmode, plus_constant (tramp, i + 6));
-  emit_move_insn (gen_rtx_MEM (HImode, addr), gen_lowpart (HImode, t1));
+  mem = adjust_address (m_tramp, HImode, i + 6);
+  emit_move_insn (mem, gen_lowpart (HImode, t1));
 
-  addr = memory_address (Pmode, plus_constant (tramp, i + 10));
-  emit_move_insn (gen_rtx_MEM (HImode, addr), gen_lowpart (HImode, t2));
+  mem = adjust_address (m_tramp, HImode, i + 10);
+  emit_move_insn (mem, gen_lowpart (HImode, t2));
   emit_insn (gen_ashrsi3 (t2, t2, GEN_INT (16)));
-  addr = memory_address (Pmode, plus_constant (tramp, i + 14));
-  emit_move_insn (gen_rtx_MEM (HImode, addr), gen_lowpart (HImode, t2));
+  mem = adjust_address (m_tramp, HImode, i + 14);
+  emit_move_insn (mem, gen_lowpart (HImode, t2));
 }
 
 /* Emit insns to move operands[1] into operands[0].  */
@@ -6619,4 +6649,9 @@ bfin_expand_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE bfin_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE bfin_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT bfin_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
diff --git a/gcc/config/bfin/bfin.h b/gcc/config/bfin/bfin.h
index 34032b2..03a2790 100644
--- a/gcc/config/bfin/bfin.h
+++ b/gcc/config/bfin/bfin.h
@@ -386,30 +386,6 @@ extern const char *bfin_library_id_string;
    && (ALIGN) < BITS_PER_WORD ? BITS_PER_WORD : (ALIGN))    
 
 #define TRAMPOLINE_SIZE (TARGET_FDPIC ? 30 : 18)
-#define TRAMPOLINE_TEMPLATE(FILE)                                       \
-  if (TARGET_FDPIC)							\
-    {									\
-      fprintf(FILE, "\t.dd\t0x00000000\n"); /* 0 */			\
-      fprintf(FILE, "\t.dd\t0x00000000\n"); /* 0 */			\
-      fprintf(FILE, "\t.dd\t0x0000e109\n"); /* p1.l = fn low */		\
-      fprintf(FILE, "\t.dd\t0x0000e149\n"); /* p1.h = fn high */	\
-      fprintf(FILE, "\t.dd\t0x0000e10a\n"); /* p2.l = sc low */		\
-      fprintf(FILE, "\t.dd\t0x0000e14a\n"); /* p2.h = sc high */	\
-      fprintf(FILE, "\t.dw\t0xac4b\n"); /* p3 = [p1 + 4] */		\
-      fprintf(FILE, "\t.dw\t0x9149\n"); /* p1 = [p1] */			\
-      fprintf(FILE, "\t.dw\t0x0051\n"); /* jump (p1)*/			\
-    }									\
-  else									\
-    {									\
-      fprintf(FILE, "\t.dd\t0x0000e109\n"); /* p1.l = fn low */		\
-      fprintf(FILE, "\t.dd\t0x0000e149\n"); /* p1.h = fn high */	\
-      fprintf(FILE, "\t.dd\t0x0000e10a\n"); /* p2.l = sc low */		\
-      fprintf(FILE, "\t.dd\t0x0000e14a\n"); /* p2.h = sc high */	\
-      fprintf(FILE, "\t.dw\t0x0051\n"); /* jump (p1)*/			\
-    }
-
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
-  initialize_trampoline (TRAMP, FNADDR, CXT)
 \f
 /* Definitions for register eliminations.
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 07/36][cris] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (4 preceding siblings ...)
  2009-09-21 22:28 ` [patch 06/36][bfin] " Richard Henderson
@ 2009-09-21 22:29 ` Richard Henderson
  2009-09-22  2:31   ` Hans-Peter Nilsson
  2009-09-21 22:30 ` [patch 08/36][crx] " Richard Henderson
                   ` (28 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:29 UTC (permalink / raw)
  To: GCC Patches; +Cc: hp

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-07-cris --]
[-- Type: text/plain, Size: 9685 bytes --]

	* config/cris/cris.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
	TARGET_TRAMPOLINE_INIT, cris_asm_trampoline_template,
	cris_trampoline_init): New.
	* config/cris/cris.h (TRAMPOLINE_TEMPLATE): Move code to
	cris_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to cris_trampoline_init;
	adjust for target hook parameters.


diff --git a/gcc/config/cris/cris.c b/gcc/config/cris/cris.c
index 6b3fd0f..bf00a57 100644
--- a/gcc/config/cris/cris.c
+++ b/gcc/config/cris/cris.c
@@ -127,6 +127,9 @@ static bool cris_handle_option (size_t, const char *, int);
 
 static bool cris_frame_pointer_required (void);
 
+static void cris_asm_trampoline_template (FILE *);
+static void cris_trampoline_init (rtx, tree, rtx);
+
 /* This is the parsed result of the "-max-stack-stackframe=" option.  If
    it (still) is zero, then there was no such option given.  */
 int cris_max_stackframe = 0;
@@ -189,6 +192,11 @@ int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
 #undef TARGET_FRAME_POINTER_REQUIRED
 #define TARGET_FRAME_POINTER_REQUIRED cris_frame_pointer_required
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE cris_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT cris_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Helper for cris_load_multiple_op and cris_ret_movem_op.  */
@@ -3853,6 +3861,103 @@ cris_frame_pointer_required (void)
   return !current_function_sp_is_unchanging;
 }
 
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
+
+   This looks too complicated, and it is.  I assigned r7 to be the
+   static chain register, but it is call-saved, so we have to save it,
+   and come back to restore it after the call, so we have to save srp...
+   Anyway, trampolines are rare enough that we can cope with this
+   somewhat lack of elegance.
+    (Do not be tempted to "straighten up" whitespace in the asms; the
+   assembler #NO_APP state mandates strict spacing).  */
+/* ??? See the i386 regparm=3 implementation that pushes the static
+   chain value to the stack in the trampoline, and uses a call-saved
+   register when called directly.  */
+
+static void
+cris_asm_trampoline_template (FILE *f)
+{
+  if (TARGET_V32)
+    {
+      /* This normally-unused nop insn acts as an instruction to
+	 the simulator to flush its instruction cache.  None of
+	 the other instructions in the trampoline template suits
+	 as a trigger for V32.  The pc-relative addressing mode
+	 works nicely as a trigger for V10.
+	 FIXME: Have specific V32 template (possibly avoiding the
+	 use of a special instruction).  */
+      fprintf (f, "\tclearf x\n");
+      /* We have to use a register as an intermediate, choosing
+	 semi-randomly R1 (which has to not be the STATIC_CHAIN_REGNUM),
+	 so we can use it for address indirection and jsr target.  */
+      fprintf (f, "\tmove $r1,$mof\n");
+      /* +4 */
+      fprintf (f, "\tmove.d 0,$r1\n");
+      fprintf (f, "\tmove.d $%s,[$r1]\n", reg_names[STATIC_CHAIN_REGNUM]);
+      fprintf (f, "\taddq 6,$r1\n");
+      fprintf (f, "\tmove $mof,[$r1]\n");
+      fprintf (f, "\taddq 6,$r1\n");
+      fprintf (f, "\tmove $srp,[$r1]\n");
+      /* +20 */
+      fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
+      /* +26 */
+      fprintf (f, "\tmove.d 0,$r1\n");
+      fprintf (f, "\tjsr $r1\n");
+      fprintf (f, "\tsetf\n");
+      /* +36 */
+      fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
+      /* +42 */
+      fprintf (f, "\tmove.d 0,$r1\n");
+      /* +48 */
+      fprintf (f, "\tmove.d 0,$r9\n");
+      fprintf (f, "\tjump $r9\n");
+      fprintf (f, "\tsetf\n");
+    }
+  else
+    {
+      fprintf (f, "\tmove.d $%s,[$pc+20]\n", reg_names[STATIC_CHAIN_REGNUM]);
+      fprintf (f, "\tmove $srp,[$pc+22]\n");
+      fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
+      fprintf (f, "\tjsr 0\n");
+      fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
+      fprintf (f, "\tjump 0\n");
+    }
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
+
+static void
+cris_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx tramp = XEXP (m_tramp, 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  if (TARGET_V32)
+    {
+      mem = adjust_address (m_tramp, SImode, 6);
+      emit_move_insn (mem, plus_constant (tramp, 38));
+      mem = adjust_address (m_tramp, SImode, 22);
+      emit_move_insn (mem, chain_value);
+      mem = adjust_address (m_tramp, SImode, 28);
+      emit_move_insn (mem, fnaddr);
+    }
+  else
+    {
+      mem = adjust_address (m_tramp, SImode, 10);
+      emit_move_insn (mem, chain_value);
+      mem = adjust_address (m_tramp, SImode, 16);
+      emit_move_insn (mem, fnaddr);
+    }
+
+  /* Note that there is no need to do anything with the cache for
+     sake of a trampoline.  */
+}
+
+
 #if 0
 /* Various small functions to replace macros.  Only called from a
    debugger.  They might collide with gcc functions or system functions,
diff --git a/gcc/config/cris/cris.h b/gcc/config/cris/cris.h
index 3929107..586f7ff 100644
--- a/gcc/config/cris/cris.h
+++ b/gcc/config/cris/cris.h
@@ -935,108 +935,11 @@ struct cum_args {int regs;};
 
 /* Node: Trampolines */
 
-/* This looks too complicated, and it is.  I assigned r7 to be the
-   static chain register, but it is call-saved, so we have to save it,
-   and come back to restore it after the call, so we have to save srp...
-   Anyway, trampolines are rare enough that we can cope with this
-   somewhat lack of elegance.
-    (Do not be tempted to "straighten up" whitespace in the asms; the
-   assembler #NO_APP state mandates strict spacing).  */
-#define TRAMPOLINE_TEMPLATE(FILE)				       \
-  do								       \
-    {								       \
-      if (TARGET_V32)						       \
-       {							       \
-	 /* This normally-unused nop insn acts as an instruction to    \
-	    the simulator to flush its instruction cache.  None of     \
-	    the other instructions in the trampoline template suits    \
-	    as a trigger for V32.  The pc-relative addressing mode     \
-	    works nicely as a trigger for V10.			       \
-	    FIXME: Have specific V32 template (possibly avoiding the   \
-	    use of a special instruction).  */			       \
-	 fprintf (FILE, "\tclearf x\n");			       \
-	 /* We have to use a register as an intermediate, choosing     \
-	    semi-randomly R1 (which has to not be the		       \
-	    STATIC_CHAIN_REGNUM), so we can use it for address	       \
-	    indirection and jsr target.	 */			       \
-	 fprintf (FILE, "\tmove $r1,$mof\n");			       \
-	 /* +4 */						       \
-	 fprintf (FILE, "\tmove.d 0,$r1\n");			       \
-	 fprintf (FILE, "\tmove.d $%s,[$r1]\n",			       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 fprintf (FILE, "\taddq 6,$r1\n");			       \
-	 fprintf (FILE, "\tmove $mof,[$r1]\n");			       \
-	 fprintf (FILE, "\taddq 6,$r1\n");			       \
-	 fprintf (FILE, "\tmove $srp,[$r1]\n");			       \
-	 /* +20 */						       \
-	 fprintf (FILE, "\tmove.d 0,$%s\n",			       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 /* +26 */						       \
-	 fprintf (FILE, "\tmove.d 0,$r1\n");			       \
-	 fprintf (FILE, "\tjsr $r1\n");				       \
-	 fprintf (FILE, "\tsetf\n");				       \
-	 /* +36 */						       \
-	 fprintf (FILE, "\tmove.d 0,$%s\n",			       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 /* +42 */						       \
-	 fprintf (FILE, "\tmove.d 0,$r1\n");			       \
-	 /* +48 */						       \
-	 fprintf (FILE, "\tmove.d 0,$r9\n");			       \
-	 fprintf (FILE, "\tjump $r9\n");			       \
-	 fprintf (FILE, "\tsetf\n");				       \
-       }							       \
-      else							       \
-       {							       \
-	 fprintf (FILE, "\tmove.d $%s,[$pc+20]\n",		       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 fprintf (FILE, "\tmove $srp,[$pc+22]\n");		       \
-	 fprintf (FILE, "\tmove.d 0,$%s\n",			       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 fprintf (FILE, "\tjsr 0\n");				       \
-	 fprintf (FILE, "\tmove.d 0,$%s\n",			       \
-		  reg_names[STATIC_CHAIN_REGNUM]);		       \
-	 fprintf (FILE, "\tjump 0\n");				       \
-       }							       \
-    }								       \
-  while (0)
-
 #define TRAMPOLINE_SIZE (TARGET_V32 ? 58 : 32)
 
-/* CRIS wants instructions on word-boundary.
-   Note that due to a bug (reported) in 2.7.2 and earlier, this is
-   actually treated as alignment in _bytes_, not _bits_.  (Obviously
-   this is not fatal, only a slight waste of stack space).  */
+/* CRIS wants instructions on word-boundary.  */
 #define TRAMPOLINE_ALIGNMENT 16
 
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-  do									\
-    if (TARGET_V32)							\
-      {									\
-	emit_move_insn (gen_rtx_MEM (SImode,				\
-				     plus_constant (TRAMP, 6)),		\
-		 	plus_constant (TRAMP, 38));			\
-	emit_move_insn (gen_rtx_MEM (SImode,				\
-				     plus_constant (TRAMP, 22)),	\
-			CXT);						\
-	emit_move_insn (gen_rtx_MEM (SImode,				\
-				     plus_constant (TRAMP, 28)),	\
-		 	FNADDR);					\
-      }									\
-    else								\
-      {									\
-	emit_move_insn (gen_rtx_MEM (SImode,				\
-				     plus_constant (TRAMP, 10)),	\
-			CXT);						\
-	emit_move_insn (gen_rtx_MEM (SImode,				\
-				     plus_constant (TRAMP, 16)),	\
-		 	FNADDR);					\
-      }									\
-  while (0)
-
-/* Note that there is no need to do anything with the cache for sake of
-   a trampoline.  */
-
-
 /* Node: Library Calls */
 
 /* If you change this, you have to check whatever libraries and systems

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 08/36][crx] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (5 preceding siblings ...)
  2009-09-21 22:29 ` [patch 07/36][cris] " Richard Henderson
@ 2009-09-21 22:30 ` Richard Henderson
  2009-09-21 22:32 ` [patch 09/36][fr30] " Richard Henderson
                   ` (27 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:30 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 56 bytes --]

CRX doesn't support hooks; this macro can go away.


r~

[-- Attachment #2: d-tramp-08-crx --]
[-- Type: text/plain, Size: 594 bytes --]

	* config/crx/crx.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/crx/crx.h b/gcc/config/crx/crx.h
index ed6d3d6..1d5cb87 100644
--- a/gcc/config/crx/crx.h
+++ b/gcc/config/crx/crx.h
@@ -369,11 +369,6 @@ struct cumulative_args
 
 #define TRAMPOLINE_SIZE	32
 
-#define INITIALIZE_TRAMPOLINE(addr, fnaddr, static_chain)	\
-{								\
-    sorry ("Trampoline support for CRX");			\
-}
-
 /*****************************************************************************/
 /* ADDRESSING MODES							     */
 /*****************************************************************************/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 09/36][fr30] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (6 preceding siblings ...)
  2009-09-21 22:30 ` [patch 08/36][crx] " Richard Henderson
@ 2009-09-21 22:32 ` Richard Henderson
  2009-09-21 22:34 ` [patch 10/36][frv] " Richard Henderson
                   ` (26 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:32 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-09-fr30 --]
[-- Type: text/plain, Size: 4802 bytes --]

	* config/fr30/fr30.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
	TARGET_TRAMPOLINE_INIT, fr30_asm_trampoline_template,
	fr30_trampoline_init): New.
	* config/fr30/fr30.h (TRAMPOLINE_TEMPLATE): Move code to
	fr30_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to fr30_trampoline_init;
	adjust for target hook parameters.



diff --git a/gcc/config/fr30/fr30.c b/gcc/config/fr30/fr30.c
index 431af8f..faa637c 100644
--- a/gcc/config/fr30/fr30.c
+++ b/gcc/config/fr30/fr30.c
@@ -121,6 +121,8 @@ static int fr30_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
 				   tree, bool);
 static bool fr30_frame_pointer_required (void);
 static bool fr30_can_eliminate (const int, const int);
+static void fr30_asm_trampoline_template (FILE *);
+static void fr30_trampoline_init (rtx, tree, rtx);
 
 #define FRAME_POINTER_MASK 	(1 << (FRAME_POINTER_REGNUM))
 #define RETURN_POINTER_MASK 	(1 << (RETURN_POINTER_REGNUM))
@@ -165,6 +167,11 @@ static bool fr30_can_eliminate (const int, const int);
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 
@@ -924,6 +931,50 @@ fr30_frame_pointer_required (void)
 }
 
 /*}}}*/
+/*{{{  Trampoline Output Routines  */
+
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
+   On the FR30, the trampoline is:
+
+   nop
+   ldi:32 STATIC, r12
+   nop
+   ldi:32 FUNCTION, r0
+   jmp    @r0
+
+   The no-ops are to guarantee that the static chain and final
+   target are 32 bit aligned within the trampoline.  That allows us to
+   initialize those locations with simple SImode stores.   The alternative
+   would be to use HImode stores.  */
+   
+static void
+fr30_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\tnop\n");
+  fprintf (f, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);
+  fprintf (f, "\tnop\n");
+  fprintf (f, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
+  fprintf (f, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
+
+static void
+fr30_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, 4);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, SImode, 12);
+  emit_move_insn (mem, fnaddr);
+}
+
+/*}}}*/
 /* Local Variables: */
 /* folded-file: t   */
 /* End:		    */
diff --git a/gcc/config/fr30/fr30.h b/gcc/config/fr30/fr30.h
index f055a1a..20e1571 100644
--- a/gcc/config/fr30/fr30.h
+++ b/gcc/config/fr30/fr30.h
@@ -730,31 +730,6 @@ enum reg_class
 /*}}}*/ \f
 /*{{{  Trampolines for Nested Functions.  */ 
 
-/* On the FR30, the trampoline is:
-
-   nop
-   ldi:32 STATIC, r12
-   nop
-   ldi:32 FUNCTION, r0
-   jmp    @r0
-
-   The no-ops are to guarantee that the static chain and final
-   target are 32 bit aligned within the trampoline.  That allows us to
-   initialize those locations with simple SImode stores.   The alternative
-   would be to use HImode stores.  */
-   
-/* A C statement to output, on the stream FILE, assembler code for a block of
-   data that contains the constant parts of a trampoline.  This code should not
-   include a label--the label is taken care of automatically.  */
-#define TRAMPOLINE_TEMPLATE(FILE)						\
-{										\
-  fprintf (FILE, "\tnop\n");							\
-  fprintf (FILE, "\tldi:32\t#0, %s\n", reg_names [STATIC_CHAIN_REGNUM]);	\
-  fprintf (FILE, "\tnop\n");							\
-  fprintf (FILE, "\tldi:32\t#0, %s\n", reg_names [COMPILER_SCRATCH_REGISTER]);	\
-  fprintf (FILE, "\tjmp\t@%s\n", reg_names [COMPILER_SCRATCH_REGISTER]);	\
-}
-
 /* A C expression for the size in bytes of the trampoline, as an integer.  */
 #define TRAMPOLINE_SIZE 18
 
@@ -763,17 +738,6 @@ enum reg_class
    the trampoline is also aligned on a 32bit boundary.  */
 #define TRAMPOLINE_ALIGNMENT 32
 
-/* A C statement to initialize the variable parts of a trampoline.  ADDR is an
-   RTX for the address of the trampoline; FNADDR is an RTX for the address of
-   the nested function; STATIC_CHAIN is an RTX for the static chain value that
-   should be passed to the function when it is called.  */
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN)			\
-do										\
-{										\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (ADDR, 4)), STATIC_CHAIN);\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (ADDR, 12)), FNADDR);	\
-} while (0);
-
 /*}}}*/ \f
 /*{{{  Addressing Modes.  */ 
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 10/36][frv] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (7 preceding siblings ...)
  2009-09-21 22:32 ` [patch 09/36][fr30] " Richard Henderson
@ 2009-09-21 22:34 ` Richard Henderson
  2009-09-21 22:35 ` [patch 11/36][h8] " Richard Henderson
                   ` (25 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:34 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 85 bytes --]

A trivial conversion to hooks, since a library call does all the actual 
setup.


r~

[-- Attachment #2: d-tramp-10-frv --]
[-- Type: text/plain, Size: 3035 bytes --]

	* config/frv/frv.c (TARGET_TRAMPOLINE_INIT): New.
	(frv_trampoline_init): Rename from frv_initialize_trampoline;
	make static, adjust arguments for TARGET_TRAMPOLINE_INIT hook.
	* config/frv/frv.h (INITIALIZE_TRAMPOLINE): Remove.
	* config/frv/frv-protos.h (frv_initialize_trampoline): Remove.


diff --git a/gcc/config/frv/frv-protos.h b/gcc/config/frv/frv-protos.h
index 8734694..2bfdc65 100644
--- a/gcc/config/frv/frv-protos.h
+++ b/gcc/config/frv/frv-protos.h
@@ -100,7 +100,6 @@ extern void frv_ifcvt_modify_final	(ce_if_block_t *);
 extern void frv_ifcvt_modify_cancel	(ce_if_block_t *);
 #endif
 extern int frv_trampoline_size		(void);
-extern void frv_initialize_trampoline	(rtx, rtx, rtx);
 extern enum reg_class frv_secondary_reload_class
 					(enum reg_class,
 					 enum machine_mode, rtx);
diff --git a/gcc/config/frv/frv.c b/gcc/config/frv/frv.c
index 63e65fb..d8901e9 100644
--- a/gcc/config/frv/frv.c
+++ b/gcc/config/frv/frv.c
@@ -383,6 +383,7 @@ static bool frv_secondary_reload                (bool, rtx, enum reg_class,
 						 secondary_reload_info *);
 static bool frv_frame_pointer_required		(void);
 static bool frv_can_eliminate			(const int, const int);
+static void frv_trampoline_init			(rtx, tree, rtx);
 \f
 /* Allow us to easily change the default for -malloc-cc.  */
 #ifndef DEFAULT_NO_ALLOC_CC
@@ -479,6 +480,9 @@ static bool frv_can_eliminate			(const int, const int);
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE frv_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT frv_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #define FRV_SYMBOL_REF_TLS_P(RTX) \
@@ -6300,9 +6304,11 @@ frv_trampoline_size (void)
 	sethi #0, <static_chain>
 	jmpl @(gr0,<jmp_reg>) */
 
-void
-frv_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
+static void
+frv_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
 {
+  rtx addr = XEXP (m_tramp, 0);
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
   rtx sc_reg = force_reg (Pmode, static_chain);
 
   emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h
index 0516ecf..53966de 100644
--- a/gcc/config/frv/frv.h
+++ b/gcc/config/frv/frv.h
@@ -1840,13 +1840,6 @@ typedef struct frv_stack {
    aligning trampolines.  */
 #define TRAMPOLINE_ALIGNMENT (TARGET_FDPIC ? 64 : 32)
 
-/* A C statement to initialize the variable parts of a trampoline.  ADDR is an
-   RTX for the address of the trampoline; FNADDR is an RTX for the address of
-   the nested function; STATIC_CHAIN is an RTX for the static chain value that
-   should be passed to the function when it is called.  */
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
-  frv_initialize_trampoline (ADDR, FNADDR, STATIC_CHAIN)
-
 /* Define this macro if trampolines need a special subroutine to do their work.
    The macro should expand to a series of `asm' statements which will be
    compiled with GCC.  They go in a library function named

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 11/36][h8] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (8 preceding siblings ...)
  2009-09-21 22:34 ` [patch 10/36][frv] " Richard Henderson
@ 2009-09-21 22:35 ` Richard Henderson
  2009-09-21 22:36 ` [patch 12/36][ia64] " Richard Henderson
                   ` (24 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:35 UTC (permalink / raw)
  To: GCC Patches; +Cc: kazu

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-11-h8300 --]
[-- Type: text/plain, Size: 4561 bytes --]

	* config/h8300/h8300.c (h8300_trampoline_init): New.
	(TARGET_TRAMPOLINE_INIT): New.
	* config/h8300/h8300.h (INITIALIZE_TRAMPOLINE): Move code
	to h8300_trampoline_init and adjust for hook parameters.


diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c
index 02b3ff6..4045954 100644
--- a/gcc/config/h8300/h8300.c
+++ b/gcc/config/h8300/h8300.c
@@ -5773,6 +5773,56 @@ h8300_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
 	  || GET_MODE_SIZE (TYPE_MODE (type)) > (TARGET_H8300 ? 4 : 8));
 }
 \f
+/* We emit the entire trampoline here.  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
+*/
+
+static void
+h8300_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  if (Pmode == HImode)
+    {
+      mem = adjust_address (m_tramp, HImode, 0);
+      emit_move_insn (mem, GEN_INT (0x7903));
+      mem = adjust_address (m_tramp, Pmode, 2);
+      emit_move_insn (mem, cxt);
+      mem = adjust_address (m_tramp, HImode, 4);
+      emit_move_insn (mem, GEN_INT (0x5a00));
+      mem = adjust_address (m_tramp, Pmode, 6);
+      emit_move_insn (mem, fnaddr);
+    }
+  else
+    {
+      rtx tem;
+
+      mem = adjust_address (m_tramp, HImode, 0);
+      emit_move_insn (mem, GEN_INT (0x7a03));
+      mem = adjust_address (m_tramp, Pmode, 2);
+      emit_move_insn (mem, cxt);
+
+      tem = copy_to_reg (fnaddr);
+      emit_insn (gen_andsi3 (tem, tem, GEN_INT (0x00ffffff)));
+      emit_insn (gen_iorsi3 (tem, tem, GEN_INT (0x5a000000)));
+      mem = adjust_address (m_tramp, SImode, 6);
+      emit_move_insn (mem, tem);
+    }
+}
+\f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ATTRIBUTE_TABLE
 #define TARGET_ATTRIBUTE_TABLE h8300_attribute_table
@@ -5818,4 +5868,7 @@ h8300_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE h8300_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT h8300_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
diff --git a/gcc/config/h8300/h8300.h b/gcc/config/h8300/h8300.h
index 884e49a..e0f0ea6 100644
--- a/gcc/config/h8300/h8300.h
+++ b/gcc/config/h8300/h8300.h
@@ -672,58 +672,9 @@ struct cum_arg
 
 #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 ((Pmode == HImode) ? 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)
 \f
 /* Addressing modes, and classification of registers for them.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 12/36][ia64] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (9 preceding siblings ...)
  2009-09-21 22:35 ` [patch 11/36][h8] " Richard Henderson
@ 2009-09-21 22:36 ` Richard Henderson
  2009-09-21 22:40 ` [patch 13/36][iq2000] " Richard Henderson
                   ` (23 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:36 UTC (permalink / raw)
  To: GCC Patches; +Cc: sje

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-12-ia64 --]
[-- Type: text/plain, Size: 6532 bytes --]

	* config/ia64/ia64-protos.h (ia64_initialize_trampoline): Remove.
	* config/ia64/ia64.c (TARGET_TRAMPOLINE_INIT): New.
	(ia64_trampoline_init): Rename from ia64_initialize_trampoline;
	make static; adjust for hook parameters.
	* config/ia64/ia64.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/ia64/ia64-protos.h b/gcc/config/ia64/ia64-protos.h
index 6d9440e..3c6a153 100644
--- a/gcc/config/ia64/ia64-protos.h
+++ b/gcc/config/ia64/ia64-protos.h
@@ -54,7 +54,6 @@ extern int ia64_direct_return (void);
 extern bool ia64_expand_load_address (rtx, rtx);
 extern int ia64_hard_regno_rename_ok (int, int);
 
-extern void ia64_initialize_trampoline (rtx, rtx, rtx);
 extern void ia64_print_operand_address (FILE *, rtx);
 extern void ia64_print_operand (FILE *, rtx, int);
 extern enum reg_class ia64_preferred_reload_class (rtx, enum reg_class);
diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c
index 7e75752..75c8f0e 100644
--- a/gcc/config/ia64/ia64.c
+++ b/gcc/config/ia64/ia64.c
@@ -302,6 +302,7 @@ static enum machine_mode ia64_promote_function_mode (const_tree,
 						     int *,
 						     const_tree,
 						     int);
+static void ia64_trampoline_init (rtx, tree, rtx);
 \f
 /* Table of valid machine attributes.  */
 static const struct attribute_spec ia64_attribute_table[] =
@@ -532,6 +533,9 @@ static const struct attribute_spec ia64_attribute_table[] =
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE ia64_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT ia64_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 typedef enum
@@ -3945,10 +3949,35 @@ ia64_dbx_register_number (int regno)
     return regno;
 }
 
-void
-ia64_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
+/* Implement TARGET_TRAMPOLINE_INIT.
+
+   The trampoline should set the static chain pointer to value placed
+   into the trampoline and should branch to the specified routine.
+   To make the normal indirect-subroutine calling convention work,
+   the trampoline must look like a function descriptor; the first
+   word being the target address and the second being the target's
+   global pointer.
+
+   We abuse the concept of a global pointer by arranging for it
+   to point to the data we need to load.  The complete trampoline
+   has the following form:
+
+		+-------------------+ \
+	TRAMP:	| __ia64_trampoline | |
+		+-------------------+  > fake function descriptor
+		| TRAMP+16          | |
+		+-------------------+ /
+		| target descriptor |
+		+-------------------+
+		| static link	    |
+		+-------------------+
+*/
+
+static void
+ia64_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
 {
-  rtx addr_reg, tramp, eight = GEN_INT (8);
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx addr, addr_reg, tramp, eight = GEN_INT (8);
 
   /* The Intel assembler requires that the global __ia64_trampoline symbol
      be declared explicitly */
@@ -3965,13 +3994,13 @@ ia64_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
     }
 
   /* Make sure addresses are Pmode even if we are in ILP32 mode. */
-  addr = convert_memory_address (Pmode, addr);
+  addr = convert_memory_address (Pmode, XEXP (m_tramp, 0));
   fnaddr = convert_memory_address (Pmode, fnaddr);
   static_chain = convert_memory_address (Pmode, static_chain);
 
   /* Load up our iterator.  */
-  addr_reg = gen_reg_rtx (Pmode);
-  emit_move_insn (addr_reg, addr);
+  addr_reg = copy_to_reg (addr);
+  m_tramp = adjust_automodify_address (m_tramp, Pmode, addr_reg, 0);
 
   /* The first two words are the fake descriptor:
      __ia64_trampoline, ADDR+16.  */
@@ -3989,19 +4018,21 @@ ia64_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
       emit_move_insn (reg, gen_rtx_MEM (Pmode, reg));
       tramp = reg;
    }
-  emit_move_insn (gen_rtx_MEM (Pmode, addr_reg), tramp);
+  emit_move_insn (m_tramp, tramp);
   emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
+  m_tramp = adjust_automodify_address (m_tramp, VOIDmode, NULL, 8);
 
-  emit_move_insn (gen_rtx_MEM (Pmode, addr_reg),
-		  copy_to_reg (plus_constant (addr, 16)));
+  emit_move_insn (m_tramp, force_reg (Pmode, plus_constant (addr, 16)));
   emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
+  m_tramp = adjust_automodify_address (m_tramp, VOIDmode, NULL, 8);
 
   /* The third word is the target descriptor.  */
-  emit_move_insn (gen_rtx_MEM (Pmode, addr_reg), fnaddr);
+  emit_move_insn (m_tramp, force_reg (Pmode, fnaddr));
   emit_insn (gen_adddi3 (addr_reg, addr_reg, eight));
+  m_tramp = adjust_automodify_address (m_tramp, VOIDmode, NULL, 8);
 
   /* The fourth word is the static chain.  */
-  emit_move_insn (gen_rtx_MEM (Pmode, addr_reg), static_chain);
+  emit_move_insn (m_tramp, static_chain);
 }
 \f
 /* Do any needed setup for a variadic function.  CUM has not been updated
diff --git a/gcc/config/ia64/ia64.h b/gcc/config/ia64/ia64.h
index 40c8550..53bbda2 100644
--- a/gcc/config/ia64/ia64.h
+++ b/gcc/config/ia64/ia64.h
@@ -1247,31 +1247,6 @@ do {									\
 #define STACK_SAVEAREA_MODE(LEVEL) \
   ((LEVEL) == SAVE_NONLOCAL ? OImode : Pmode)
 
-/* Output assembler code for a block containing the constant parts of
-   a trampoline, leaving space for the variable parts.
-
-   The trampoline should set the static chain pointer to value placed
-   into the trampoline and should branch to the specified routine.
-   To make the normal indirect-subroutine calling convention work,
-   the trampoline must look like a function descriptor; the first
-   word being the target address and the second being the target's
-   global pointer.
-
-   We abuse the concept of a global pointer by arranging for it
-   to point to the data we need to load.  The complete trampoline
-   has the following form:
-
-		+-------------------+ \
-	TRAMP:	| __ia64_trampoline | |
-		+-------------------+  > fake function descriptor
-		| TRAMP+16          | |
-		+-------------------+ /
-		| target descriptor |
-		+-------------------+
-		| static link	    |
-		+-------------------+
-*/
-
 /* A C expression for the size in bytes of the trampoline, as an integer.  */
 
 #define TRAMPOLINE_SIZE		32
@@ -1279,11 +1254,6 @@ do {									\
 /* Alignment required for trampolines, in bits.  */
 
 #define TRAMPOLINE_ALIGNMENT	64
-
-/* A C statement to initialize the variable parts of a trampoline.  */
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
-  ia64_initialize_trampoline((ADDR), (FNADDR), (STATIC_CHAIN))
 \f
 /* Addressing Modes */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 13/36][iq2000] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (10 preceding siblings ...)
  2009-09-21 22:36 ` [patch 12/36][ia64] " Richard Henderson
@ 2009-09-21 22:40 ` Richard Henderson
  2009-09-21 22:41 ` [patch 14/36][m32c] " Richard Henderson
                   ` (22 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:40 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]

A straight-forward conversion to hooks.

There seems to be half-hearted support for Pmode==DImode here.  I added 
TRAMPOLINE_ALIGNMENT to make at least that part work, but I doubt this 
had ever been tested before.


r~

[-- Attachment #2: d-tramp-13-iq2000 --]
[-- Type: text/plain, Size: 5250 bytes --]

	* config/iq2000/iq2000.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(iq2000_asm_trampoline_template, iq2000_trampoline_init): New.
	* config/iq2000/iq2000.h (TRAMPOLINE_TEMPLATE): Move code to
	iq2000_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to iq2000_trampoline_init.
	(TRAMPOLINE_CODE_SIZE): New.
	(TRAMPOLINE_SIZE): Use it.
	(TRAMPOLINE_ALIGNMENT): Follow Pmode.


diff --git a/gcc/config/iq2000/iq2000.c b/gcc/config/iq2000/iq2000.c
index 85a8e5a..2e2f29a 100644
--- a/gcc/config/iq2000/iq2000.c
+++ b/gcc/config/iq2000/iq2000.c
@@ -166,6 +166,8 @@ static int  iq2000_arg_partial_bytes  (CUMULATIVE_ARGS *, enum machine_mode,
 static void iq2000_va_start	      (tree, rtx);
 static bool iq2000_legitimate_address_p (enum machine_mode, rtx, bool);
 static bool iq2000_can_eliminate      (const int, const int);
+static void iq2000_asm_trampoline_template (FILE *);
+static void iq2000_trampoline_init    (rtx, tree, rtx);
 
 #undef  TARGET_INIT_BUILTINS
 #define TARGET_INIT_BUILTINS 		iq2000_init_builtins
@@ -218,6 +220,11 @@ static bool iq2000_can_eliminate      (const int, const int);
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE            iq2000_can_eliminate
 
+#undef  TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE	iq2000_asm_trampoline_template
+#undef  TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT		iq2000_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Return nonzero if we split the address into high and low parts.  */
@@ -3410,4 +3417,47 @@ iq2000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int * total,
   return true;
 }
 
+/* Worker for TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+static void
+iq2000_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\t.word\t0x03e00821\t\t# move   $1,$31\n");
+  fprintf (f, "\t.word\t0x04110001\t\t# bgezal $0,.+8\n");
+  fprintf (f, "\t.word\t0x00000000\t\t# nop\n");
+  if (Pmode == DImode)
+    {
+      fprintf (f, "\t.word\t0xdfe30014\t\t# ld     $3,20($31)\n");
+      fprintf (f, "\t.word\t0xdfe2001c\t\t# ld     $2,28($31)\n");
+    }
+  else
+    {
+      fprintf (f, "\t.word\t0x8fe30014\t\t# lw     $3,20($31)\n");
+      fprintf (f, "\t.word\t0x8fe20018\t\t# lw     $2,24($31)\n");
+    }
+  fprintf (f, "\t.word\t0x0060c821\t\t# move   $25,$3 (abicalls)\n");
+  fprintf (f, "\t.word\t0x00600008\t\t# jr     $3\n");
+  fprintf (f, "\t.word\t0x0020f821\t\t# move   $31,$1\n");
+  fprintf (f, "\t.word\t0x00000000\t\t# <function address>\n");
+  fprintf (f, "\t.word\t0x00000000\t\t# <static chain value>\n");
+}
+
+/* Worker for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+iq2000_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_CODE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, Pmode, TRAMPOLINE_CODE_SIZE);
+  emit_move_insn (mem, fnaddr);
+  mem = adjust_address (m_tramp, Pmode,
+			TRAMPOLINE_CODE_SIZE + GET_MODE_SIZE (Pmode));
+  emit_move_insn (mem, chain_value);
+}
+
 #include "gt-iq2000.h"
diff --git a/gcc/config/iq2000/iq2000.h b/gcc/config/iq2000/iq2000.h
index 43bacfd..4dadbdb 100644
--- a/gcc/config/iq2000/iq2000.h
+++ b/gcc/config/iq2000/iq2000.h
@@ -469,43 +469,9 @@ typedef struct iq2000_args
 \f
 /* Trampolines for Nested Functions.  */
 
-/* A C statement to output, on the stream FILE, assembler code for a
-   block of data that contains the constant parts of a trampoline.
-   This code should not include a label--the label is taken care of
-   automatically.  */
-
-#define TRAMPOLINE_TEMPLATE(STREAM)					 \
-{									 \
-  fprintf (STREAM, "\t.word\t0x03e00821\t\t# move   $1,$31\n");		\
-  fprintf (STREAM, "\t.word\t0x04110001\t\t# bgezal $0,.+8\n");		\
-  fprintf (STREAM, "\t.word\t0x00000000\t\t# nop\n");			\
-  if (Pmode == DImode)							\
-    {									\
-      fprintf (STREAM, "\t.word\t0xdfe30014\t\t# ld     $3,20($31)\n");	\
-      fprintf (STREAM, "\t.word\t0xdfe2001c\t\t# ld     $2,28($31)\n");	\
-    }									\
-  else									\
-    {									\
-      fprintf (STREAM, "\t.word\t0x8fe30014\t\t# lw     $3,20($31)\n");	\
-      fprintf (STREAM, "\t.word\t0x8fe20018\t\t# lw     $2,24($31)\n");	\
-    }									\
-  fprintf (STREAM, "\t.word\t0x0060c821\t\t# move   $25,$3 (abicalls)\n"); \
-  fprintf (STREAM, "\t.word\t0x00600008\t\t# jr     $3\n");		\
-  fprintf (STREAM, "\t.word\t0x0020f821\t\t# move   $31,$1\n");		\
-  fprintf (STREAM, "\t.word\t0x00000000\t\t# <function address>\n"); \
-  fprintf (STREAM, "\t.word\t0x00000000\t\t# <static chain value>\n"); \
-}
-
-#define TRAMPOLINE_SIZE (40)
-
-#define TRAMPOLINE_ALIGNMENT 32
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FUNC, CHAIN)			    \
-{									    \
-  rtx addr = ADDR;							    \
-    emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, 32)), FUNC); \
-    emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, 36)), CHAIN);\
-}
+#define TRAMPOLINE_CODE_SIZE  (8*4)
+#define TRAMPOLINE_SIZE       (TRAMPOLINE_CODE_SIZE + 2*GET_MODE_SIZE (Pmode))
+#define TRAMPOLINE_ALIGNMENT  GET_MODE_ALIGNMENT (Pmode)
 
 \f
 /* Addressing Modes.  */

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (11 preceding siblings ...)
  2009-09-21 22:40 ` [patch 13/36][iq2000] " Richard Henderson
@ 2009-09-21 22:41 ` Richard Henderson
  2009-09-21 22:49   ` DJ Delorie
  2009-09-21 22:42 ` [patch 15/36][m68hc11] " Richard Henderson
                   ` (21 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:41 UTC (permalink / raw)
  To: GCC Patches; +Cc: dj

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-14-m32c --]
[-- Type: text/plain, Size: 2022 bytes --]

	* config/m32c/m32c-protos.h (m32c_initialize_trampoline): Remove.
	* config/m32c/m32c.c (TARGET_TRAMPOLINE_INIT): New.
	(m32c_trampoline_init): Rename from m32c_initialize_trampoline;
	adjust for hook parameters.
	* config/m32c/m32c.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/m32c/m32c-protos.h b/gcc/config/m32c/m32c-protos.h
index d332475..e571fe9 100644
--- a/gcc/config/m32c/m32c-protos.h
+++ b/gcc/config/m32c/m32c-protos.h
@@ -73,7 +73,6 @@ int  m32c_hard_regno_ok (int, MM);
 bool m32c_illegal_subreg_p (rtx);
 bool m32c_immd_dbl_mov (rtx *, MM);
 rtx  m32c_incoming_return_addr_rtx (void);
-void m32c_initialize_trampoline (rtx, rtx, rtx);
 int  m32c_legitimate_constant_p (rtx);
 int  m32c_legitimize_reload_address (rtx *, MM, int, int, int);
 rtx  m32c_libcall_value (MM);
diff --git a/gcc/config/m32c/m32c.c b/gcc/config/m32c/m32c.c
index 1bf3d1b..a068949 100644
--- a/gcc/config/m32c/m32c.c
+++ b/gcc/config/m32c/m32c.c
@@ -1717,11 +1717,16 @@ m32c_trampoline_alignment (void)
   return 2;
 }
 
-/* Implements INITIALIZE_TRAMPOLINE.  */
-void
-m32c_initialize_trampoline (rtx tramp, rtx function, rtx chainval)
+/* Implements TARGET_TRAMPOLINE_INIT.  */
+
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT m32c_trampoline_init
+static void
+m32c_trampoline_init (rtx m_tramp, tree fndecl, rtx chainval)
 {
-#define A0(m,i) gen_rtx_MEM (m, plus_constant (tramp, i))
+  rtx function = XEXP (DECL_RTL (fndecl), 0);
+
+#define A0(m,i) adjust_address (m_tramp, m, i)
   if (TARGET_A16)
     {
       /* Note: we subtract a "word" because the moves want signed
diff --git a/gcc/config/m32c/m32c.h b/gcc/config/m32c/m32c.h
index ee092a5..48e669b 100644
--- a/gcc/config/m32c/m32c.h
+++ b/gcc/config/m32c/m32c.h
@@ -555,7 +555,6 @@ typedef struct m32c_cumulative_args
 
 #define TRAMPOLINE_SIZE m32c_trampoline_size ()
 #define TRAMPOLINE_ALIGNMENT m32c_trampoline_alignment ()
-#define INITIALIZE_TRAMPOLINE(a,fn,sc) m32c_initialize_trampoline (a, fn, sc)
 
 /* Addressing Modes */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 15/36][m68hc11] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (12 preceding siblings ...)
  2009-09-21 22:41 ` [patch 14/36][m32c] " Richard Henderson
@ 2009-09-21 22:42 ` Richard Henderson
  2009-09-21 22:47 ` [patch 16/36][m68k] " Richard Henderson
                   ` (20 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:42 UTC (permalink / raw)
  To: GCC Patches, stcarrez

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-15-m68hc11 --]
[-- Type: text/plain, Size: 5477 bytes --]

	* config/m68hc11/m68hc11.c (TARGET_TRAMPOLINE_INIT): New.
	(m68hc11_trampoline_init): Rename from m68hc11_initialize_trampoline;
	make static; update for hook parameters.
	* config/m68hc11/m68hc11-protos.h: Update.
	* config/m68hc11/m68hc11.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/m68hc11/m68hc11-protos.h b/gcc/config/m68hc11/m68hc11-protos.h
index e4f8ba7..59154fa 100644
--- a/gcc/config/m68hc11/m68hc11-protos.h
+++ b/gcc/config/m68hc11/m68hc11-protos.h
@@ -43,8 +43,6 @@ extern void m68hc11_function_arg_advance (CUMULATIVE_ARGS*,
 #ifdef RTX_CODE
 extern int m68hc11_auto_inc_p (rtx);
 
-extern void m68hc11_initialize_trampoline (rtx, rtx, rtx);
-
 extern rtx m68hc11_expand_compare_and_branch (enum rtx_code, rtx, rtx, rtx);
 extern enum reg_class preferred_reload_class (rtx, enum reg_class);
 
diff --git a/gcc/config/m68hc11/m68hc11.c b/gcc/config/m68hc11/m68hc11.c
index d30b84c..5f8011c 100644
--- a/gcc/config/m68hc11/m68hc11.c
+++ b/gcc/config/m68hc11/m68hc11.c
@@ -92,6 +92,7 @@ static void m68hc11_init_libfuncs (void);
 static rtx m68hc11_struct_value_rtx (tree, int);
 static bool m68hc11_return_in_memory (const_tree, const_tree);
 static bool m68hc11_can_eliminate (const int, const int);
+static void m68hc11_trampoline_init (rtx, tree, rtx);
 
 /* Must be set to 1 to produce debug messages.  */
 int debug_m6811 = 0;
@@ -282,6 +283,9 @@ static const struct attribute_spec m68hc11_attribute_table[] =
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE m68hc11_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT m68hc11_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 int
@@ -1072,39 +1076,49 @@ symbolic_memory_operand (rtx op, enum machine_mode mode)
    jmp FNADDR
 
 */
-void
-m68hc11_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+m68hc11_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
 {
   const char *static_chain_reg = reg_names[STATIC_CHAIN_REGNUM];
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
 
   /* Skip the '*'.  */
   if (*static_chain_reg == '*')
     static_chain_reg++;
   if (TARGET_M6811)
     {
-      emit_move_insn (gen_rtx_MEM (HImode, tramp), GEN_INT (0x18ce));
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 2)), cxt);
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 4)),
-                      GEN_INT (0x18df));
-      emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 6)),
+      mem = adjust_address (m_tramp, HImode, 0);
+      emit_move_insn (mem, GEN_INT (0x18ce));
+      mem = adjust_address (m_tramp, HImode, 2);
+      emit_move_insn (mem, cxt);
+      mem = adjust_address (m_tramp, HImode, 4);
+      emit_move_insn (mem, GEN_INT (0x18df));
+      mem = adjust_address (m_tramp, QImode, 6);
+      emit_move_insn (mem,
                       gen_rtx_CONST (QImode,
                                      gen_rtx_SYMBOL_REF (Pmode,
                                                          static_chain_reg)));
-      emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 7)),
-                      GEN_INT (0x7e));
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 8)), fnaddr);
+      mem = adjust_address (m_tramp, QImode, 7);
+      emit_move_insn (mem, GEN_INT (0x7e));
+      mem = adjust_address (m_tramp, HImode, 8);
+      emit_move_insn (mem, fnaddr);
     }
   else
     {
-      emit_move_insn (gen_rtx_MEM (HImode, tramp), GEN_INT (0x1803));
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 2)), cxt);
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 4)),
+      mem = adjust_address (m_tramp, HImode, 0);
+      emit_move_insn (mem, GEN_INT (0x1803));
+      mem = adjust_address (m_tramp, HImode, 2);
+      emit_move_insn (mem, cxt);
+      mem = adjust_address (m_tramp, HImode, 4);
+      emit_move_insn (mem,
                       gen_rtx_CONST (HImode,
                                      gen_rtx_SYMBOL_REF (Pmode,
                                                          static_chain_reg)));
-      emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 6)),
-                      GEN_INT (0x06));
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, 7)), fnaddr);
+      mem = adjust_address (m_tramp, QImode, 6);
+      emit_move_insn (mem, GEN_INT (0x06));
+      mem = adjust_address (m_tramp, HImode, 7);
+      emit_move_insn (mem, fnaddr);
     }
 }
 \f
diff --git a/gcc/config/m68hc11/m68hc11.h b/gcc/config/m68hc11/m68hc11.h
index 9b19c33..ee0f9f6 100644
--- a/gcc/config/m68hc11/m68hc11.h
+++ b/gcc/config/m68hc11/m68hc11.h
@@ -1005,17 +1005,10 @@ typedef struct m68hc11_args
    for profiling a function entry.  */
 #define FUNCTION_PROFILER(FILE, LABELNO)		\
     fprintf (FILE, "\tldy\t.LP%d\n\tjsr mcount\n", (LABELNO))
+
 /* Length in units of the trampoline for entering a nested function.  */
 #define TRAMPOLINE_SIZE		(TARGET_M6811 ? 11 : 9)
 
-/* A C statement to initialize the variable parts of a trampoline.
-   ADDR is an RTX for the address of the trampoline; FNADDR is an
-   RTX for the address of the nested function; STATIC_CHAIN is an
-   RTX for the static chain value that should be passed to the
-   function when it is called.  */
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
-  m68hc11_initialize_trampoline ((TRAMP), (FNADDR), (CXT))
-
 \f
 /* Addressing modes, and classification of registers for them.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 16/36][m68k] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (13 preceding siblings ...)
  2009-09-21 22:42 ` [patch 15/36][m68hc11] " Richard Henderson
@ 2009-09-21 22:47 ` Richard Henderson
  2009-09-22 15:53   ` Richard Henderson
  2009-09-21 22:50 ` [patch 17/36][mcore] " Richard Henderson
                   ` (19 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:47 UTC (permalink / raw)
  To: GCC Patches; +Cc: schwab

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]

A tricky bit here is that m68k used static_chain_rtx in 
m68k_output_mi_thunk apparently for a scratch register.  It suddenly 
occurs to me to wonder if it did that to avoid clobbering A0 when that's 
used for the structure return value?  If so, my conversion is incorrect.

I've removed the separate trampoline implementation that was present in 
netbsd-elf.h.  The comments say that it is "different" by using A1 as 
the static call chain.  Of course, it's larger and slower as well, and 
the default implementation also handles STATIC_CHAIN_REGNUM being set to 
A1, so I can't see why this still exists.


r~

[-- Attachment #2: d-tramp-16-m68k --]
[-- Type: text/plain, Size: 6643 bytes --]

	* config/m68k/m68k.c (TARGET_TRAMPOLINE_INIT): New.
	(m68k_output_mi_thunk): Don't use static_chain_rtx.
	(m68k_trampoline_init): New.
	* config/m68k/m68k.h (INITIALIZE_TRAMPOLINE): Move code to
	m68k_trampoline_init and adjust for hook parameters.
	* config/m68k/netbsd-elf.h (TRAMPOLINE_TEMPLATE): Remove.
	(TRAMPOLINE_SIZE, INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c
index 033872c..edfd661 100644
--- a/gcc/config/m68k/m68k.c
+++ b/gcc/config/m68k/m68k.c
@@ -153,6 +153,7 @@ static bool m68k_rtx_costs (rtx, int, int, int *, bool);
 static bool m68k_return_in_memory (const_tree, const_tree);
 #endif
 static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
+static void m68k_trampoline_init (rtx, tree, rtx);
 \f
 
 /* Specify the identification number of the library being built */
@@ -267,6 +268,9 @@ const char *m68k_library_id_string = "_current_shared_library_a5_offset_";
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE m68k_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT m68k_trampoline_init
+
 static const struct attribute_spec m68k_attribute_table[] =
 {
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
@@ -4984,16 +4988,18 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
   /* If needed, add *(*THIS + VCALL_OFFSET) to THIS.  */
   if (vcall_offset != 0)
     {
+      rtx tmp = gen_rtx_REG (Pmode, A0_REG);
+
       /* Set the static chain register to *THIS.  */
-      emit_move_insn (static_chain_rtx, this_slot);
-      emit_move_insn (static_chain_rtx, gen_rtx_MEM (Pmode, static_chain_rtx));
+      emit_move_insn (tmp, this_slot);
+      emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
 
       /* Set ADDR to a legitimate address for *THIS + VCALL_OFFSET.  */
-      addr = plus_constant (static_chain_rtx, vcall_offset);
+      addr = plus_constant (tmp, vcall_offset);
       if (!m68k_legitimate_address_p (Pmode, addr, true))
 	{
-	  emit_insn (gen_rtx_SET (VOIDmode, static_chain_rtx, addr));
-	  addr = static_chain_rtx;
+	  emit_insn (gen_rtx_SET (VOIDmode, tmp, addr));
+	  addr = tmp;
 	}
 
       /* Load the offset into %d0 and add it to THIS.  */
@@ -5009,6 +5015,8 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
   mem = DECL_RTL (function);
   if (!sibcall_operand (XEXP (mem, 0), VOIDmode))
     {
+      rtx tmp = gen_rtx_REG (Pmode, A0_REG);
+
       gcc_assert (flag_pic);
 
       if (!TARGET_SEP_DATA)
@@ -5019,8 +5027,8 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
 	  SET_REGNO (pic_offset_table_rtx, STATIC_CHAIN_REGNUM);
 	  emit_insn (gen_load_got (pic_offset_table_rtx));
 	}
-      legitimize_pic_address (XEXP (mem, 0), Pmode, static_chain_rtx);
-      mem = replace_equiv_address (mem, static_chain_rtx);
+      legitimize_pic_address (XEXP (mem, 0), Pmode, tmp);
+      mem = replace_equiv_address (mem, tmp);
     }
   insn = emit_call_insn (gen_sibcall (mem, const0_rtx));
   SIBLING_CALL_P (insn) = 1;
@@ -6390,4 +6398,30 @@ m68k_sched_indexed_address_bypass_p (rtx pro, rtx con)
     }
 }
 
+/* We generate a two-instructions program at M_TRAMP :
+	movea.l &CHAIN_VALUE,%a0
+	jmp FNADDR
+   where %a0 can be modified by changing STATIC_CHAIN_REGNUM.  */
+
+static void
+m68k_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  gcc_assert (ADDRESS_REGNO_P (STATIC_CHAIN_REGNUM));
+
+  mem = adjust_address (m_tramp, HImode, 0);
+  emit_move_insn (mem, GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9)));
+  mem = adjust_address (m_tramp, SImode, 2);
+  emit_move_insn (mem, chain_value);
+
+  mem = adjust_address (m_tramp, HImode, 6);
+  emit_move_insn (mem, GEN_INT(0x4EF9));
+  mem = adjust_address (m_tramp, SImode, 8);
+  emit_move_insn (mem, fnaddr);
+
+  FINALIZE_TRAMPOLINE (XEXP (m_tramp, 0));
+}
+
 #include "gt-m68k.h"
diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h
index b2cfb1d..5787e8a 100644
--- a/gcc/config/m68k/m68k.h
+++ b/gcc/config/m68k/m68k.h
@@ -617,20 +617,6 @@ extern enum reg_class regno_reg_class[];
 #define FINALIZE_TRAMPOLINE(TRAMP)
 #endif
 
-/* We generate a two-instructions program at address TRAMP :
-	movea.l &CXT,%a0
-	jmp FNADDR  */
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (HImode, TRAMP),				\
-		  GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9)));	\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 2)), CXT); \
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (TRAMP, 6)),	\
-		  GEN_INT(0x4EF9));					\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 8)), FNADDR); \
-  FINALIZE_TRAMPOLINE(TRAMP);						\
-}
-
 /* This is the library routine that is used to transfer control from the
    trampoline to the actual nested function.  It is defined for backward
    compatibility, for linking with object code that used the old trampoline
diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h
index 258b9e1..fd65418 100644
--- a/gcc/config/m68k/netbsd-elf.h
+++ b/gcc/config/m68k/netbsd-elf.h
@@ -312,39 +312,5 @@ while (0)
 #undef DEFAULT_PCC_STRUCT_RETURN
 #define DEFAULT_PCC_STRUCT_RETURN 1
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.  */
-
-/* On m68k svr4, the trampoline is different from the generic version
-   in that we use a1 as the static call chain.  */
-
-#undef TRAMPOLINE_TEMPLATE
-#define TRAMPOLINE_TEMPLATE(FILE)					\
-{									\
-  assemble_aligned_integer (2, GEN_INT (0x227a));			\
-  assemble_aligned_integer (2, GEN_INT (8));				\
-  assemble_aligned_integer (2, GEN_INT (0x2f3a));			\
-  assemble_aligned_integer (2, GEN_INT (8));				\
-  assemble_aligned_integer (2, GEN_INT (0x4e75));			\
-  assemble_aligned_integer (4, const0_rtx);				\
-  assemble_aligned_integer (4, const0_rtx);				\
-}
-
-/* Redefine since we are using a different trampoline */
-#undef TRAMPOLINE_SIZE
-#define TRAMPOLINE_SIZE 18
-
-/* 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.  */
-
-#undef INITIALIZE_TRAMPOLINE
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 10)), CXT); \
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 14)), FNADDR); \
-}
-
-
 /* XXX
    This is the end of the chunk lifted from m68kv4.h  */

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 22:41 ` [patch 14/36][m32c] " Richard Henderson
@ 2009-09-21 22:49   ` DJ Delorie
  2009-09-21 22:57     ` Richard Henderson
  0 siblings, 1 reply; 58+ messages in thread
From: DJ Delorie @ 2009-09-21 22:49 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches


> A straight-forward conversion to hooks.

Why the change from "tramp" to "m_tramp" ?  If we're worried about
political correctness, use "trampoline".

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 17/36][mcore] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (14 preceding siblings ...)
  2009-09-21 22:47 ` [patch 16/36][m68k] " Richard Henderson
@ 2009-09-21 22:50 ` Richard Henderson
  2009-09-21 22:52 ` [patch 18/36][mep] " Richard Henderson
                   ` (18 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:50 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

A straight-forward conversion to hooks.

Given that you're emitting integer constants in the trampoline template, 
why not merge that into two 32-bit integer stores in the trampoline_init 
routine?


r~

[-- Attachment #2: d-tramp-17-mcore --]
[-- Type: text/plain, Size: 4847 bytes --]

	* config/mcore/mcore.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(mcore_function_value): Fix typo.
	(mcore_asm_trampoline_template, mcore_trampoline_init): New.
	* config/mcore/mcore.h (TRAMPOLINE_TEMPLATE): Move code 
	to mcore_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to mcore_trampoline_init.


diff --git a/gcc/config/mcore/mcore.c b/gcc/config/mcore/mcore.c
index 170b4b0..de897fd 100644
--- a/gcc/config/mcore/mcore.c
+++ b/gcc/config/mcore/mcore.c
@@ -144,7 +144,8 @@ static bool       mcore_return_in_memory	(const_tree, const_tree);
 static int        mcore_arg_partial_bytes       (CUMULATIVE_ARGS *,
 						 enum machine_mode,
 						 tree, bool);
-
+static void       mcore_asm_trampoline_template (FILE *);
+static void       mcore_trampoline_init		(rtx, tree, rtx);
 \f
 /* MCore specific attributes.  */
 
@@ -209,6 +210,11 @@ static const struct attribute_spec mcore_attribute_table[] =
 #undef  TARGET_SETUP_INCOMING_VARARGS
 #define TARGET_SETUP_INCOMING_VARARGS	mcore_setup_incoming_varargs
 
+#undef  TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE	mcore_asm_trampoline_template
+#undef  TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT		mcore_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Adjust the stack and return the number of bytes taken to do it.  */
@@ -2736,7 +2742,7 @@ mcore_function_value (const_tree valtype, const_tree func)
   mode = TYPE_MODE (valtype);
 
   /* Since we promote return types, we must promote the mode here too.  */
-  mode = promote_function_mode (valtype, mode, &unsignedp, func, 1);
+  mode = promote_function_mode (valtype, mode, &unsigned_p, func, 1);
   
   return handle_structs_in_regs (mode, valtype, FIRST_RET_REG);
 }
@@ -3105,3 +3111,42 @@ mcore_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
   const HOST_WIDE_INT size = int_size_in_bytes (type);
   return (size == -1 || size > 2 * UNITS_PER_WORD);
 }
+
+/* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE.
+   Output assembler code for a block containing the constant parts
+   of a trampoline, leaving space for the variable parts.
+
+   On the MCore, the trampoline looks like:
+   	lrw	r1,  function
+     	lrw	r13, area
+   	jmp	r13
+   	or	r0, r0
+    .literals                                                */
+
+static void
+mcore_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\t.short	0x7102\n");
+  fprintf (f, "\t.short	0x7d02\n");
+  fprintf (f, "\t.short	0x00cd\n");
+  fprintf (f, "\t.short	0x1e00\n");
+  fprintf (f, "\t.long	0\n");
+  fprintf (f, "\t.long	0\n");
+}
+
+/* Worker function for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+mcore_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, 8);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, SImode, 12);
+  emit_move_insn (mem, fnaddr);
+}
diff --git a/gcc/config/mcore/mcore.h b/gcc/config/mcore/mcore.h
index acc5449..630a11f 100644
--- a/gcc/config/mcore/mcore.h
+++ b/gcc/config/mcore/mcore.h
@@ -631,42 +631,12 @@ extern const enum reg_class reg_class_from_letter[];
    No definition is equivalent to always zero.  */
 #define EXIT_IGNORE_STACK 0
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.
-
-   On the MCore, the trampoline looks like:
-   	lrw	r1,  function
-     	lrw	r13, area
-   	jmp	r13
-   	or	r0, r0
-    .literals                                                */
-#define TRAMPOLINE_TEMPLATE(FILE)  		\
-{						\
-  fprintf ((FILE), "	.short	0x7102\n");	\
-  fprintf ((FILE), "	.short	0x7d02\n");	\
-  fprintf ((FILE), "	.short	0x00cd\n");     \
-  fprintf ((FILE), "	.short	0x1e00\n");	\
-  fprintf ((FILE), "	.long	0\n");		\
-  fprintf ((FILE), "	.long	0\n");		\
-}
-
 /* Length in units of the trampoline for entering a nested function.  */
 #define TRAMPOLINE_SIZE  12
 
 /* Alignment required for a trampoline in bits.  */
 #define TRAMPOLINE_ALIGNMENT  32
 
-/* 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 (SImode, plus_constant ((TRAMP), 8)),	\
-		  (CXT));						\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant ((TRAMP), 12)),	\
-		  (FNADDR));						\
-}
-
 /* Macros to check register numbers against specific register classes.  */
 
 /* These assume that REGNO is a hard or pseudo reg number.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 18/36][mep] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (15 preceding siblings ...)
  2009-09-21 22:50 ` [patch 17/36][mcore] " Richard Henderson
@ 2009-09-21 22:52 ` Richard Henderson
  2009-09-21 22:59 ` [patch 19/36][mips] " Richard Henderson
                   ` (17 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:52 UTC (permalink / raw)
  To: GCC Patches; +Cc: dj

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-18-mep --]
[-- Type: text/plain, Size: 2670 bytes --]

	* config/mep/mep.h (INITIALIZE_TRAMPOLINE): Remove.
	* config/mep/mep.c (TARGET_TRAMPOLINE_INIT): New.
	(mep_trampoline_init): Rename from mep_init_trampoline; make static;
	update for hook parameters.
	* config/mep/mep-protos.h (mep_init_trampoline): Remove.


diff --git a/gcc/config/mep/mep-protos.h b/gcc/config/mep/mep-protos.h
index e53ca79..82be465 100644
--- a/gcc/config/mep/mep-protos.h
+++ b/gcc/config/mep/mep-protos.h
@@ -89,7 +89,6 @@ extern void mep_file_cleanups (void);
 extern const char *mep_strip_name_encoding (const char *);
 extern void mep_output_aligned_common (FILE *, tree, const char *,
 				       int, int, int);
-extern void mep_init_trampoline (rtx, rtx, rtx);
 extern void mep_emit_doloop (rtx *, int);
 extern bool mep_vliw_function_p (tree);
 extern bool mep_store_data_bypass_p (rtx, rtx);
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index 4c37d38..dcf5362 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -229,6 +229,7 @@ static tree mep_build_builtin_va_list (void);
 static void mep_expand_va_start (tree, rtx);
 static tree mep_gimplify_va_arg_expr (tree, tree, tree *, tree *);
 static bool mep_can_eliminate (const int, const int);
+static void mep_trampoline_init (rtx, tree, rtx);
 \f
 /* Initialize the GCC target structure.  */
 
@@ -300,8 +301,10 @@ static bool mep_can_eliminate (const int, const int);
 #define TARGET_EXPAND_BUILTIN_VA_START	mep_expand_va_start
 #undef	TARGET_GIMPLIFY_VA_ARG_EXPR
 #define	TARGET_GIMPLIFY_VA_ARG_EXPR	mep_gimplify_va_arg_expr
-#undef TARGET_CAN_ELIMINATE
+#undef  TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE            mep_can_eliminate
+#undef  TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT		mep_trampoline_init
 
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
@@ -4922,9 +4925,12 @@ mep_output_aligned_common (FILE *stream, tree decl, const char *name,
 
 /* Trampolines.  */
 
-void
-mep_init_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
+static void
+mep_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
 {
+  rtx addr = XEXP (m_tramp, 0);
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__mep_trampoline_helper"),
 		     LCT_NORMAL, VOIDmode, 3,
 		     addr, Pmode,
diff --git a/gcc/config/mep/mep.h b/gcc/config/mep/mep.h
index fff7962..8b00a44 100644
--- a/gcc/config/mep/mep.h
+++ b/gcc/config/mep/mep.h
@@ -565,10 +565,6 @@ typedef struct
    run-time also.  */
 
 #define TRAMPOLINE_SIZE 20
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
-	mep_init_trampoline (ADDR, FNADDR, STATIC_CHAIN)
-
 \f
 
 #define CONSTANT_ADDRESS_P(X) CONSTANT_P (X)

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 22:49   ` DJ Delorie
@ 2009-09-21 22:57     ` Richard Henderson
  2009-09-21 23:00       ` DJ Delorie
  0 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:57 UTC (permalink / raw)
  To: DJ Delorie; +Cc: gcc-patches

On 09/21/2009 03:47 PM, DJ Delorie wrote:
>> A straight-forward conversion to hooks.
>
> Why the change from "tramp" to "m_tramp" ?  If we're worried about
> political correctness, use "trampoline".

"tramp" was a raw address.
"m_tramp" is a MEM with all the proper MEM_ATTRS set.

I consistently changed the variable name to (1) make that clear and (2) 
catch any incomplete conversion problems.


r~

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 19/36][mips] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (16 preceding siblings ...)
  2009-09-21 22:52 ` [patch 18/36][mep] " Richard Henderson
@ 2009-09-21 22:59 ` Richard Henderson
  2009-09-22 18:19   ` Richard Sandiford
  2009-09-21 23:01 ` [patch 20/36][mmix] " Richard Henderson
                   ` (16 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 22:59 UTC (permalink / raw)
  To: GCC Patches; +Cc: rdsandiford

[-- Attachment #1: Type: text/plain, Size: 430 bytes --]

A straight-forward conversion to hooks.

Your trampoline can be greatly simplified for N32 and N64 abis.  Recall 
that the current address is passed in via $25.  Which simplifies your 
trampoline to e.g.

	lw	$1,20($25)
	lw	$25,16($25)
	jr	$25
	 nop

And why emit raw integers to the template?  It just makes things a bit 
confusing in my opinion.  Integers are of course acceptable if you're 
not going to use a template...


r~

[-- Attachment #2: d-tramp-19-mips --]
[-- Type: text/plain, Size: 6872 bytes --]

	* config/mips/mips.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
	mips_asm_trampoline_template, TARGET_TRAMPOLINE_INIT,
	mips_trampoline_init): New.
	* config/mips/mips.h (TRAMPOLINE_TEMPLATE): Move code to
	mips_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to mips_trampoline_init;
	update for hook parameters.


diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index ace48ba..4c83ea5 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -15874,6 +15874,66 @@ mips_final_postscan_insn (FILE *file ATTRIBUTE_UNUSED, rtx insn,
     mips_pop_asm_switch (&mips_noat);
 }
 \f
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+static void
+mips_asm_trampoline_template (FILE *f)
+{
+  if (ptr_mode == DImode)
+    fprintf (f, "\t.word\t0x03e0082d\t\t# dmove   $1,$31\n");
+  else
+    fprintf (f, "\t.word\t0x03e00821\t\t# move   $1,$31\n");
+  fprintf (f, "\t.word\t0x04110001\t\t# bgezal $0,.+8\n");
+  fprintf (f, "\t.word\t0x00000000\t\t# nop\n");
+  if (ptr_mode == DImode)
+    {
+      fprintf (f, "\t.word\t0xdff90014\t\t# ld     $25,20($31)\n");
+      fprintf (f, "\t.word\t0xdfef001c\t\t# ld     $15,28($31)\n");
+    }
+  else
+    {
+      fprintf (f, "\t.word\t0x8ff90010\t\t# lw     $25,16($31)\n");
+      fprintf (f, "\t.word\t0x8fef0014\t\t# lw     $15,20($31)\n");
+    }
+  fprintf (f, "\t.word\t0x03200008\t\t# jr     $25\n");
+  if (ptr_mode == DImode)
+    {
+      fprintf (f, "\t.word\t0x0020f82d\t\t# dmove   $31,$1\n");
+      fprintf (f, "\t.word\t0x00000000\t\t# <padding>\n");
+      fprintf (f, "\t.dword\t0x00000000\t\t# <function address>\n");
+      fprintf (f, "\t.dword\t0x00000000\t\t# <static chain value>\n");
+    }
+  else
+    {
+      fprintf (f, "\t.word\t0x0020f821\t\t# move   $31,$1\n");
+      fprintf (f, "\t.word\t0x00000000\t\t# <function address>\n");
+      fprintf (f, "\t.word\t0x00000000\t\t# <static chain value>\n");
+    }
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
+
+static void
+mips_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem, addr, end_addr;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, ptr_mode, ptr_mode == DImode ? 32 : 28);
+  mips_emit_move (mem, force_reg (ptr_mode, fnaddr));
+  mem = adjust_address (mem, ptr_mode, GET_MODE_SIZE (ptr_mode));
+  mips_emit_move (mem, force_reg (ptr_mode, chain_value));
+
+  addr = force_reg (ptr_mode, XEXP (m_tramp, 0));
+  end_addr = gen_reg_rtx (ptr_mode);
+  emit_insn (gen_add3_insn (end_addr, addr, GEN_INT (TRAMPOLINE_SIZE)));
+  emit_insn (gen_clear_cache (addr, end_addr));
+}
+
+\f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
@@ -16054,6 +16114,11 @@ mips_final_postscan_insn (FILE *file ATTRIBUTE_UNUSED, rtx insn,
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE mips_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE mips_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT mips_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 #include "gt-mips.h"
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index defcd6e..934e0fa 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -2433,45 +2433,6 @@ typedef struct mips_args {
 #define EXIT_IGNORE_STACK 1
 
 \f
-/* A C statement to output, on the stream FILE, assembler code for a
-   block of data that contains the constant parts of a trampoline.
-   This code should not include a label--the label is taken care of
-   automatically.  */
-
-#define TRAMPOLINE_TEMPLATE(STREAM)					\
-{									\
-  if (ptr_mode == DImode)						\
-    fprintf (STREAM, "\t.word\t0x03e0082d\t\t# dmove   $1,$31\n");	\
-  else									\
-    fprintf (STREAM, "\t.word\t0x03e00821\t\t# move   $1,$31\n");	\
-  fprintf (STREAM, "\t.word\t0x04110001\t\t# bgezal $0,.+8\n");		\
-  fprintf (STREAM, "\t.word\t0x00000000\t\t# nop\n");			\
-  if (ptr_mode == DImode)						\
-    {									\
-      fprintf (STREAM, "\t.word\t0xdff90014\t\t# ld     $25,20($31)\n"); \
-      fprintf (STREAM, "\t.word\t0xdfef001c\t\t# ld     $15,28($31)\n"); \
-    }									\
-  else									\
-    {									\
-      fprintf (STREAM, "\t.word\t0x8ff90010\t\t# lw     $25,16($31)\n"); \
-      fprintf (STREAM, "\t.word\t0x8fef0014\t\t# lw     $15,20($31)\n"); \
-    }									\
-  fprintf (STREAM, "\t.word\t0x03200008\t\t# jr     $25\n");		\
-  if (ptr_mode == DImode)						\
-    {									\
-      fprintf (STREAM, "\t.word\t0x0020f82d\t\t# dmove   $31,$1\n");	\
-      fprintf (STREAM, "\t.word\t0x00000000\t\t# <padding>\n");		\
-      fprintf (STREAM, "\t.dword\t0x00000000\t\t# <function address>\n"); \
-      fprintf (STREAM, "\t.dword\t0x00000000\t\t# <static chain value>\n"); \
-    }									\
-  else									\
-    {									\
-      fprintf (STREAM, "\t.word\t0x0020f821\t\t# move   $31,$1\n");	\
-      fprintf (STREAM, "\t.word\t0x00000000\t\t# <function address>\n"); \
-      fprintf (STREAM, "\t.word\t0x00000000\t\t# <static chain value>\n"); \
-    }									\
-}
-
 /* A C expression for the size in bytes of the trampoline, as an
    integer.  */
 
@@ -2481,7 +2442,7 @@ typedef struct mips_args {
 
 #define TRAMPOLINE_ALIGNMENT GET_MODE_BITSIZE (ptr_mode)
 
-/* INITIALIZE_TRAMPOLINE calls this library function to flush
+/* mips_trampoline_init calls this library function to flush
    program and data caches.  */
 
 #ifndef CACHE_FLUSH_FUNC
@@ -2495,25 +2456,6 @@ typedef struct mips_args {
 		     LCT_NORMAL, VOIDmode, 3, ADDR, Pmode, SIZE, Pmode,	\
 		     GEN_INT (3), TYPE_MODE (integer_type_node))
 
-/* A C statement to initialize the variable parts of a trampoline.
-   ADDR is an RTX for the address of the trampoline; FNADDR is an
-   RTX for the address of the nested function; STATIC_CHAIN is an
-   RTX for the static chain value that should be passed to the
-   function when it is called.  */
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FUNC, CHAIN)			    \
-{									    \
-  rtx func_addr, chain_addr, end_addr;                                      \
-									    \
-  func_addr = plus_constant (ADDR, ptr_mode == DImode ? 32 : 28);	    \
-  chain_addr = plus_constant (func_addr, GET_MODE_SIZE (ptr_mode));	    \
-  mips_emit_move (gen_rtx_MEM (ptr_mode, func_addr), FUNC);		    \
-  mips_emit_move (gen_rtx_MEM (ptr_mode, chain_addr), CHAIN);		    \
-  end_addr = gen_reg_rtx (Pmode);					    \
-  emit_insn (gen_add3_insn (end_addr, copy_rtx (ADDR),			    \
-                            GEN_INT (TRAMPOLINE_SIZE)));		    \
-  emit_insn (gen_clear_cache (copy_rtx (ADDR), end_addr));		    \
-}
 \f
 /* Addressing modes, and classification of registers for them.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 22:57     ` Richard Henderson
@ 2009-09-21 23:00       ` DJ Delorie
  2009-09-21 23:13         ` Richard Henderson
  0 siblings, 1 reply; 58+ messages in thread
From: DJ Delorie @ 2009-09-21 23:00 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches


> "tramp" was a raw address.
> "m_tramp" is a MEM with all the proper MEM_ATTRS set.
> 
> I consistently changed the variable name to (1) make that clear and (2) 
> catch any incomplete conversion problems.

Ah, ok.  Apparently not clear enough to me ;-)

m32c and mep are OK, but of course you don't need *my* approval.

Don't forget to update doc/tm.texi, please.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 20/36][mmix] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (17 preceding siblings ...)
  2009-09-21 22:59 ` [patch 19/36][mips] " Richard Henderson
@ 2009-09-21 23:01 ` Richard Henderson
  2009-09-22  2:03   ` Hans-Peter Nilsson
  2009-09-21 23:04 ` [patch 21/36][mn10300] " Richard Henderson
                   ` (15 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:01 UTC (permalink / raw)
  To: GCC Patches; +Cc: hp

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]

A mostly straight-forward conversion to hooks.

Note that I removed the mmix_trampoline_size variable; there didn't seem 
to be any point to that.  I also added TRAMPOLINE_ALIGNMENT, which gets 
propagated into the MEM we create for the trampoline, which solves:

-  /* FIXME: GCC copies this using *intsize* (tetra), when it should use
-     register size (octa).  */


r~

[-- Attachment #2: d-tramp-20-mmix --]
[-- Type: text/plain, Size: 5729 bytes --]

	* gcc/config/mmix/mmix.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(mmix_trampoline_size): Remove.
	(mmix_asm_trampoline_template): Rename from mmix_trampoline_template;
	make static.  Remove out-of-date tetra vs octa comment.
	(mmix_trampoline_init): Rename from mmix_initialize_trampoline;
	make static; update for hook parameters.
	* config/mmix/mmix.h (TRAMPOLINE_TEMPLATE): Remove.
	(INITIALIZE_TRAMPOLINE): Remove.
	(TRAMPOLINE_SIZE): Use a constant instead of mmix_trampoline_size.
	(TRAMPOLINE_ALIGNMENT): New.
	* gcc/config/mmix/mmix-protos.h: Update.


diff --git a/gcc/config/mmix/mmix-protos.h b/gcc/config/mmix/mmix-protos.h
index e839d86..957164b 100644
--- a/gcc/config/mmix/mmix-protos.h
+++ b/gcc/config/mmix/mmix-protos.h
@@ -25,8 +25,6 @@ extern int mmix_initial_elimination_offset (int, int);
 extern int mmix_starting_frame_offset (void);
 extern int mmix_function_arg_regno_p (int, int);
 extern void mmix_function_profiler (FILE *, int);
-extern void mmix_trampoline_template (FILE *);
-extern int mmix_trampoline_size;
 extern int mmix_reversible_cc_mode (enum machine_mode);
 extern int mmix_register_move_cost
   (enum machine_mode, enum reg_class, enum reg_class);
@@ -80,7 +78,6 @@ extern rtx mmix_dynamic_chain_address (rtx);
 extern rtx mmix_return_addr_rtx (int, rtx);
 extern rtx mmix_eh_return_stackadj_rtx (void);
 extern rtx mmix_eh_return_handler_rtx (void);
-extern void mmix_initialize_trampoline (rtx, rtx, rtx);
 extern int mmix_constant_address_p (rtx);
 extern int mmix_legitimate_constant_p (rtx);
 extern void mmix_print_operand (FILE *, rtx, int);
diff --git a/gcc/config/mmix/mmix.c b/gcc/config/mmix/mmix.c
index 8521f37..b589db9 100644
--- a/gcc/config/mmix/mmix.c
+++ b/gcc/config/mmix/mmix.c
@@ -141,6 +141,8 @@ static enum machine_mode mmix_promote_function_mode (const_tree,
 static bool mmix_pass_by_reference (CUMULATIVE_ARGS *,
 				    enum machine_mode, const_tree, bool);
 static bool mmix_frame_pointer_required (void);
+static void mmix_asm_trampoline_template (FILE *);
+static void mmix_trampoline_init (rtx, tree, rtx);
 
 /* Target structure macros.  Listed by node.  See `Using and Porting GCC'
    for a general description.  */
@@ -212,6 +214,11 @@ static bool mmix_frame_pointer_required (void);
 #undef TARGET_FRAME_POINTER_REQUIRED
 #define TARGET_FRAME_POINTER_REQUIRED mmix_frame_pointer_required
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE mmix_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT mmix_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Functions that are expansions for target macros.
@@ -886,46 +893,44 @@ mmix_setup_incoming_varargs (CUMULATIVE_ARGS *args_so_farp,
     internal_error ("MMIX Internal: Last named vararg would not fit in a register");
 }
 
-/* TRAMPOLINE_SIZE.  */
-/* Four 4-byte insns plus two 8-byte values.  */
-int mmix_trampoline_size = 32;
-
-
-/* TRAMPOLINE_TEMPLATE.  */
+/* TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
 
-void
-mmix_trampoline_template (FILE *stream)
+static void
+mmix_asm_trampoline_template (FILE *stream)
 {
   /* Read a value into the static-chain register and jump somewhere.  The
      static chain is stored at offset 16, and the function address is
      stored at offset 24.  */
-  /* FIXME: GCC copies this using *intsize* (tetra), when it should use
-     register size (octa).  */
+
   fprintf (stream, "\tGETA $255,1F\n\t");
-  fprintf (stream, "LDOU %s,$255,0\n\t",
-	   reg_names[MMIX_STATIC_CHAIN_REGNUM]);
+  fprintf (stream, "LDOU %s,$255,0\n\t", reg_names[MMIX_STATIC_CHAIN_REGNUM]);
   fprintf (stream, "LDOU $255,$255,8\n\t");
   fprintf (stream, "GO $255,$255,0\n");
   fprintf (stream, "1H\tOCTA 0\n\t");
   fprintf (stream, "OCTA 0\n");
 }
 
-/* INITIALIZE_TRAMPOLINE.  */
+/* TARGET_TRAMPOLINE_INIT.  */
 /* Set the static chain and function pointer field in the trampoline.
    We also SYNCID here to be sure (doesn't matter in the simulator, but
    some day it will).  */
 
-void
-mmix_initialize_trampoline (rtx trampaddr, rtx fnaddr, rtx static_chain)
-{
-  emit_move_insn (gen_rtx_MEM (DImode, plus_constant (trampaddr, 16)),
-		  static_chain);
-  emit_move_insn (gen_rtx_MEM (DImode,
-			       plus_constant (trampaddr, 24)),
-		  fnaddr);
-  emit_insn (gen_sync_icache (validize_mem (gen_rtx_MEM (DImode,
-							 trampaddr)),
-			      GEN_INT (mmix_trampoline_size - 1)));
+static void
+mmix_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, DImode, 2*UNITS_PER_WORD);
+  emit_move_insn (mem, static_chain);
+  mem = adjust_address (m_tramp, DImode, 3*UNITS_PER_WORD);
+  emit_move_insn (mem, fnaddr);
+
+  mem = adjust_address (m_tramp, DImode, 0);
+  emit_insn (gen_sync_icache (mem, GEN_INT (TRAMPOLINE_SIZE - 1)));
 }
 
 /* We must exclude constant addresses that have an increment that is not a
diff --git a/gcc/config/mmix/mmix.h b/gcc/config/mmix/mmix.h
index 4146654..1e76e46 100644
--- a/gcc/config/mmix/mmix.h
+++ b/gcc/config/mmix/mmix.h
@@ -651,13 +651,8 @@ typedef struct { int regs; int lib; } CUMULATIVE_ARGS;
 
 /* Node: Trampolines */
 
-#define TRAMPOLINE_TEMPLATE(FILE) \
- mmix_trampoline_template (FILE)
-
-#define TRAMPOLINE_SIZE mmix_trampoline_size
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
- mmix_initialize_trampoline (ADDR, FNADDR, STATIC_CHAIN)
-
+#define TRAMPOLINE_SIZE		(4*UNITS_PER_WORD)
+#define TRAMPOLINE_ALIGNMENT	BITS_PER_WORD
 
 /* Node: Addressing Modes */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 21/36][mn10300] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (18 preceding siblings ...)
  2009-09-21 23:01 ` [patch 20/36][mmix] " Richard Henderson
@ 2009-09-21 23:04 ` Richard Henderson
  2009-09-21 23:11   ` Richard Henderson
  2009-09-21 23:06 ` [patch 22/36][moxie] " Richard Henderson
                   ` (14 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:04 UTC (permalink / raw)
  To: GCC Patches; +Cc: aoliva

A straight-forward conversion to hooks.


r~

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 22/36][moxie] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (19 preceding siblings ...)
  2009-09-21 23:04 ` [patch 21/36][mn10300] " Richard Henderson
@ 2009-09-21 23:06 ` Richard Henderson
  2009-09-21 23:08 ` [patch 23/36][parisc] " Richard Henderson
                   ` (13 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:06 UTC (permalink / raw)
  To: GCC Patches; +Cc: green

[-- Attachment #1: Type: text/plain, Size: 260 bytes --]

A straight-forward conversion to hooks.

I assume there's a red-zone in the kernel that prevents ($sp-4) from 
being overwritten by an interrupt?  You might do well to add a comment 
to that effect, because otherwise it looks wrong to random maintainers.


r~

[-- Attachment #2: d-tramp-22-moxie --]
[-- Type: text/plain, Size: 4713 bytes --]

	* config/moxie/moxie.c (moxie_static_chain,
	moxie_asm_trampoline_template, moxie_trampoline_init,
	TARGET_STATIC_CHAIN, TARGET_ASM_TRAMPOLINE_TEMPLATE,
	TARGET_TRAMPOLINE_INIT): New.
	* config/moxie/moxie.h (INITIALIZE_TRAMPOLINE): Move code to
	moxie_trampoline_init.
	(TRAMPOLINE_TEMPLATE): Move code to moxie_asm_trampoline_template.
	(STATIC_CHAIN, STATIC_CHAIN_INCOMING): Remove.


diff --git a/gcc/config/moxie/moxie.c b/gcc/config/moxie/moxie.c
index 8b2d8b2..215bbdf 100644
--- a/gcc/config/moxie/moxie.c
+++ b/gcc/config/moxie/moxie.c
@@ -453,6 +453,55 @@ moxie_arg_partial_bytes (CUMULATIVE_ARGS *cum,
     return 0;
 }
 
+/* Worker function for TARGET_STATIC_CHAIN.  */
+
+static rtx
+moxie_static_chain (const_tree fndecl, bool incoming_p)
+{
+  rtx addr, mem;
+
+  if (DECL_NO_STATIC_CHAIN (fndecl))
+    return NULL;
+
+  if (incoming_p)
+    addr = plus_constant (arg_pointer_rtx, 2 * UNITS_PER_WORD);
+  else
+    addr = plus_constant (stack_pointer_rtx, -UNITS_PER_WORD);
+
+  mem = gen_rtx_MEM (Pmode, addr);
+  MEM_NOTRAP_P (mem) = 1;
+
+  return mem;
+}
+
+/* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+static void
+moxie_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\tpush  $sp, $r0\n");
+  fprintf (f, "\tldi.l $r0, 0x0\n");
+  fprintf (f, "\tsto.l 0x8($fp), $r0\n");
+  fprintf (f, "\tpop   $sp, $r0\n");
+  fprintf (f, "\tjmpa  0x0\n");
+}
+
+/* Worker function for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+moxie_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx mem, fnaddr = XEXP (DECL_RTL (fndecl), 0);
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, 4);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, SImode, 18);
+  emit_move_insn (mem, fnaddr);
+}
+
 /* The Global `targetm' Variable.  */
 
 /* Initialize the GCC target structure.  */
@@ -485,6 +534,13 @@ moxie_arg_partial_bytes (CUMULATIVE_ARGS *cum,
 #undef TARGET_FRAME_POINTER_REQUIRED
 #define TARGET_FRAME_POINTER_REQUIRED hook_bool_void_true
 
+#undef TARGET_STATIC_CHAIN
+#define TARGET_STATIC_CHAIN moxie_static_chain
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE moxie_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT moxie_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-moxie.h"
diff --git a/gcc/config/moxie/moxie.h b/gcc/config/moxie/moxie.h
index 21792da..f1b77ea 100644
--- a/gcc/config/moxie/moxie.h
+++ b/gcc/config/moxie/moxie.h
@@ -391,31 +391,6 @@ enum reg_class
 /* Alignment required for trampolines, in bits.  */
 #define TRAMPOLINE_ALIGNMENT 16
 
-/* A C statement to initialize the variable parts of a trampoline.  ADDR is an
-   RTX for the address of the trampoline; FNADDR is an RTX for the address of
-   the nested function; STATIC_CHAIN is an RTX for the static chain value that
-   should be passed to the function when it is called.  */
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN)		      \
-do									      \
-{									      \
-  emit_move_insn (gen_rtx_MEM (SImode,                                        \
-                               plus_constant (ADDR, 4)), STATIC_CHAIN);       \
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (ADDR, 18)), FNADDR);    \
-} while (0);
-
-/* A C statement to output, on the stream FILE, assembler code for a
-   block of data that contains the constant parts of a trampoline.
-   This code should not include a label--the label is taken care of
-   automatically.  */
-#define TRAMPOLINE_TEMPLATE(FILE)	       	\
-{						\
-  fprintf (FILE, "\tpush  $sp, $r0\n");         \
-  fprintf (FILE, "\tldi.l $r0, 0x0\n"); 	\
-  fprintf (FILE, "\tsto.l 0x8($fp), $r0\n");	\
-  fprintf (FILE, "\tpop   $sp, $r0\n");		\
-  fprintf (FILE, "\tjmpa  0x0\n");	        \
-}
-
 /* An alias for the machine mode for pointers.  */
 #define Pmode         SImode
 
@@ -435,17 +410,6 @@ do									      \
    access the function's argument list.  */
 #define ARG_POINTER_REGNUM MOXIE_QAP
 
-/* If the static chain is passed in memory, these macros provide rtx
-   giving 'mem' expressions that denote where they are stored.
-   'STATIC_CHAIN' and 'STATIC_CHAIN_INCOMING' give the locations as
-   seen by the calling and called functions, respectively.  */
-
-#define STATIC_CHAIN							\
-  gen_rtx_MEM (Pmode, plus_constant (stack_pointer_rtx, -UNITS_PER_WORD))
-
-#define STATIC_CHAIN_INCOMING						\
-  gen_rtx_MEM (Pmode, plus_constant (arg_pointer_rtx, 2 * UNITS_PER_WORD))
-
 #define HARD_FRAME_POINTER_REGNUM MOXIE_FP
 
 #define ELIMINABLE_REGS							\

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 23/36][parisc] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (20 preceding siblings ...)
  2009-09-21 23:06 ` [patch 22/36][moxie] " Richard Henderson
@ 2009-09-21 23:08 ` Richard Henderson
  2009-09-22  2:03   ` John David Anglin
  2009-09-21 23:09 ` [patch 24/36][pdp11] " Richard Henderson
                   ` (12 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:08 UTC (permalink / raw)
  To: GCC Patches; +Cc: dave.anglin

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-23-pa --]
[-- Type: text/plain, Size: 15945 bytes --]

	* gcc/config/pa/pa.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
	pa_asm_trampoline_template, TARGET_TRAMPOLINE_INIT,
	pa_trampoline_init, TARGET_TRAMPOLINE_ADJUST_ADDRESS,
	pa_trampoline_adjust_address): New.
	* config/pa/pa.h (TRAMPOLINE_TEMPLATE): Move code to
	pa_asm_trampoline_template.
	(TRAMPOLINE_ALIGNMENT): New.
	(TRAMPOLINE_CODE_SIZE): Move to pa.c.
	(INITIALIZE_TRAMPOLINE): Move code to pa_trampoline_init;
	adjust for hook parameters.
	(TRAMPOLINE_ADJUST_ADDRESS): Move code to pa_trampoline_adjust_address.


diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index 65a07d9..09c830e 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -163,6 +163,10 @@ static enum machine_mode pa_promote_function_mode (const_tree,
 						   enum machine_mode, int *,
 						   const_tree, int);
 
+static void pa_asm_trampoline_template (FILE *);
+static void pa_trampoline_init (rtx, tree, rtx);
+static rtx pa_trampoline_adjust_address (rtx);
+
 /* The following extra sections are only used for SOM.  */
 static GTY(()) section *som_readonly_data_section;
 static GTY(()) section *som_one_only_readonly_data_section;
@@ -325,6 +329,13 @@ static size_t n_deferred_plabels = 0;
 #undef TARGET_EXTRA_LIVE_ON_ENTRY
 #define TARGET_EXTRA_LIVE_ON_ENTRY pa_extra_live_on_entry
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE pa_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT pa_trampoline_init
+#undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
+#define TARGET_TRAMPOLINE_ADJUST_ADDRESS pa_trampoline_adjust_address
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Parse the -mfixed-range= option string.  */
@@ -9808,4 +9819,174 @@ pa_modes_tieable_p (enum machine_mode mode1, enum machine_mode mode2)
   return true;
 }
 
+\f
+/* Length in units of the trampoline instruction code.  */
+
+#define TRAMPOLINE_CODE_SIZE (TARGET_64BIT ? 24 : (TARGET_PA_20 ? 32 : 40))
+
+
+/* Output assembler code for a block containing the constant parts
+   of a trampoline, leaving space for the variable parts.\
+
+   The trampoline sets the static chain pointer to STATIC_CHAIN_REGNUM
+   and then branches to the specified routine.
+
+   This code template is copied from text segment to stack location
+   and then patched with pa_trampoline_init to contain valid values,
+   and then entered as a subroutine.
+
+   It is best to keep this as small as possible to avoid having to
+   flush multiple lines in the cache.  */
+
+static void
+pa_asm_trampoline_template (FILE *f)
+{
+  if (!TARGET_64BIT)
+    {
+      fputs ("\tldw	36(%r22),%r21\n", f);
+      fputs ("\tbb,>=,n	%r21,30,.+16\n", f);
+      if (ASSEMBLER_DIALECT == 0)
+	fputs ("\tdepi	0,31,2,%r21\n", f);
+      else
+	fputs ("\tdepwi	0,31,2,%r21\n", f);
+      fputs ("\tldw	4(%r21),%r19\n", f);
+      fputs ("\tldw	0(%r21),%r21\n", f);
+      if (TARGET_PA_20)
+	{
+	  fputs ("\tbve	(%r21)\n", f);
+	  fputs ("\tldw	40(%r22),%r29\n", f);
+	  fputs ("\t.word	0\n", f);
+	  fputs ("\t.word	0\n", f);
+	}
+      else
+	{
+	  fputs ("\tldsid	(%r21),%r1\n", f);
+	  fputs ("\tmtsp	%r1,%sr0\n", f);
+	  fputs ("\tbe	0(%sr0,%r21)\n", f);
+	  fputs ("\tldw	40(%r22),%r29\n", f);
+	}
+      fputs ("\t.word	0\n", f);
+      fputs ("\t.word	0\n", f);
+      fputs ("\t.word	0\n", f);
+      fputs ("\t.word	0\n", f);
+    }
+  else
+    {
+      fputs ("\t.dword 0\n", f);
+      fputs ("\t.dword 0\n", f);
+      fputs ("\t.dword 0\n", f);
+      fputs ("\t.dword 0\n", f);
+      fputs ("\tmfia	%r31\n", f);
+      fputs ("\tldd	24(%r31),%r1\n", f);
+      fputs ("\tldd	24(%r1),%r27\n", f);
+      fputs ("\tldd	16(%r1),%r1\n", f);
+      fputs ("\tbve	(%r1)\n", f);
+      fputs ("\tldd	32(%r31),%r31\n", f);
+      fputs ("\t.dword 0  ; fptr\n", f);
+      fputs ("\t.dword 0  ; static link\n", f);
+    }
+}
+
+/* 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.
+
+   Move the function address to the trampoline template at offset 36.
+   Move the static chain value to trampoline template at offset 40.
+   Move the trampoline address to trampoline template at offset 44.
+   Move r19 to trampoline template at offset 48.  The latter two
+   words create a plabel for the indirect call to the trampoline.
+
+   A similar sequence is used for the 64-bit port but the plabel is
+   at the beginning of the trampoline.
+
+   Finally, the cache entries for the trampoline code are flushed.
+   This is necessary to ensure that the trampoline instruction sequence
+   is written to memory prior to any attempts at prefetching the code
+   sequence.  */
+
+static void
+pa_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx start_addr = gen_reg_rtx (Pmode);
+  rtx end_addr = gen_reg_rtx (Pmode);
+  rtx line_length = gen_reg_rtx (Pmode);
+  rtx r_tramp, tmp;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+  r_tramp = force_reg (Pmode, XEXP (m_tramp, 0));
+
+  if (!TARGET_64BIT)
+    {
+      tmp = adjust_address (m_tramp, Pmode, 36);
+      emit_move_insn (tmp, fnaddr);
+      tmp = adjust_address (m_tramp, Pmode, 40);
+      emit_move_insn (tmp, chain_value);
+
+      /* Create a fat pointer for the trampoline.  */
+      tmp = adjust_address (m_tramp, Pmode, 44);
+      emit_move_insn (tmp, r_tramp);
+      tmp = adjust_address (m_tramp, Pmode, 48);
+      emit_move_insn (tmp, gen_rtx_REG (Pmode, 19));
+
+      /* fdc and fic only use registers for the address to flush,
+	 they do not accept integer displacements.  We align the
+	 start and end addresses to the beginning of their respective
+	 cache lines to minimize the number of lines flushed.  */
+      emit_insn (gen_andsi3 (start_addr, r_tramp,
+			     GEN_INT (-MIN_CACHELINE_SIZE)));
+      tmp = force_reg (Pmode, plus_constant (r_tramp, TRAMPOLINE_CODE_SIZE-1));
+      emit_insn (gen_andsi3 (end_addr, tmp,
+			     GEN_INT (-MIN_CACHELINE_SIZE)));
+      emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
+      emit_insn (gen_dcacheflushsi (start_addr, end_addr, line_length));
+      emit_insn (gen_icacheflushsi (start_addr, end_addr, line_length,
+				    gen_reg_rtx (Pmode),
+				    gen_reg_rtx (Pmode)));
+    }
+  else
+    {
+      tmp = adjust_address (m_tramp, Pmode, 56);
+      emit_move_insn (tmp, fnaddr);
+      tmp = adjust_address (m_tramp, Pmode, 64);
+      emit_move_insn (tmp, chain_value);
+
+      /* Create a fat pointer for the trampoline.  */
+      tmp = adjust_address (m_tramp, Pmode, 16);
+      emit_move_insn (tmp, force_reg (Pmode, plus_constant (r_tramp, 32)));
+      tmp = adjust_address (m_tramp, Pmode, 24);
+      emit_move_insn (tmp, gen_rtx_REG (Pmode, 27));
+
+      /* fdc and fic only use registers for the address to flush,
+	 they do not accept integer displacements.  We align the
+	 start and end addresses to the beginning of their respective
+	 cache lines to minimize the number of lines flushed.  */
+      tmp = force_reg (Pmode, plus_constant (r_tramp, 32));
+      emit_insn (gen_anddi3 (start_addr, tmp,
+			     GEN_INT (-MIN_CACHELINE_SIZE)));
+      tmp = force_reg (Pmode, plus_constant (tmp, TRAMPOLINE_CODE_SIZE - 1));
+      emit_insn (gen_anddi3 (end_addr, tmp,
+			     GEN_INT (-MIN_CACHELINE_SIZE)));
+      emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));
+      emit_insn (gen_dcacheflushdi (start_addr, end_addr, line_length));
+      emit_insn (gen_icacheflushdi (start_addr, end_addr, line_length,
+				    gen_reg_rtx (Pmode),
+				    gen_reg_rtx (Pmode)));
+    }
+}
+
+/* Perform any machine-specific adjustment in the address of the trampoline.
+   ADDR contains the address that was passed to pa_trampoline_init.
+   Adjust the trampoline address to point to the plabel at offset 44.  */
+
+static rtx
+pa_trampoline_adjust_address (rtx addr)
+{
+  if (!TARGET_64BIT)
+    addr = memory_address (Pmode, plus_constant (addr, 46));
+  return addr;
+}
+\f
 #include "gt-pa.h"
diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h
index 3b0dded..7716e73 100644
--- a/gcc/config/pa/pa.h
+++ b/gcc/config/pa/pa.h
@@ -778,74 +778,13 @@ extern int may_call_alloca;
  (get_frame_size () != 0	\
   || cfun->calls_alloca || crtl->outgoing_args_size)
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.\
-
-   The trampoline sets the static chain pointer to STATIC_CHAIN_REGNUM
-   and then branches to the specified routine.
-
-   This code template is copied from text segment to stack location
-   and then patched with INITIALIZE_TRAMPOLINE to contain
-   valid values, and then entered as a subroutine.
-
-   It is best to keep this as small as possible to avoid having to
-   flush multiple lines in the cache.  */
-
-#define TRAMPOLINE_TEMPLATE(FILE) 					\
-  {									\
-    if (!TARGET_64BIT)							\
-      {									\
-	fputs ("\tldw	36(%r22),%r21\n", FILE);			\
-	fputs ("\tbb,>=,n	%r21,30,.+16\n", FILE);			\
-	if (ASSEMBLER_DIALECT == 0)					\
-	  fputs ("\tdepi	0,31,2,%r21\n", FILE);			\
-	else								\
-	  fputs ("\tdepwi	0,31,2,%r21\n", FILE);			\
-	fputs ("\tldw	4(%r21),%r19\n", FILE);				\
-	fputs ("\tldw	0(%r21),%r21\n", FILE);				\
-	if (TARGET_PA_20)						\
-	  {								\
-	    fputs ("\tbve	(%r21)\n", FILE);			\
-	    fputs ("\tldw	40(%r22),%r29\n", FILE);		\
-	    fputs ("\t.word	0\n", FILE);				\
-	    fputs ("\t.word	0\n", FILE);				\
-	  }								\
-	else								\
-	  {								\
-	    fputs ("\tldsid	(%r21),%r1\n", FILE);			\
-	    fputs ("\tmtsp	%r1,%sr0\n", FILE);			\
-	    fputs ("\tbe	0(%sr0,%r21)\n", FILE);			\
-	    fputs ("\tldw	40(%r22),%r29\n", FILE);		\
-	  }								\
-	fputs ("\t.word	0\n", FILE);					\
-	fputs ("\t.word	0\n", FILE);					\
-	fputs ("\t.word	0\n", FILE);					\
-	fputs ("\t.word	0\n", FILE);					\
-      }									\
-    else								\
-      {									\
-	fputs ("\t.dword 0\n", FILE);					\
-	fputs ("\t.dword 0\n", FILE);					\
-	fputs ("\t.dword 0\n", FILE);					\
-	fputs ("\t.dword 0\n", FILE);					\
-	fputs ("\tmfia	%r31\n", FILE);					\
-	fputs ("\tldd	24(%r31),%r1\n", FILE);				\
-	fputs ("\tldd	24(%r1),%r27\n", FILE);				\
-	fputs ("\tldd	16(%r1),%r1\n", FILE);				\
-	fputs ("\tbve	(%r1)\n", FILE);				\
-	fputs ("\tldd	32(%r31),%r31\n", FILE);			\
-	fputs ("\t.dword 0  ; fptr\n", FILE);				\
-	fputs ("\t.dword 0  ; static link\n", FILE);			\
-      }									\
-  }
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE (TARGET_64BIT ? 72 : 52)
 
-/* Length in units of the trampoline instruction code.  */
+/* Alignment required by the trampoline.  */
 
-#define TRAMPOLINE_CODE_SIZE (TARGET_64BIT ? 24 : (TARGET_PA_20 ? 32 : 40))
+#define TRAMPOLINE_ALIGNMENT BITS_PER_WORD
 
 /* Minimum length of a cache line.  A length of 16 will work on all
    PA-RISC processors.  All PA 1.1 processors have a cache line of
@@ -855,102 +794,6 @@ extern int may_call_alloca;
 
 #define MIN_CACHELINE_SIZE 32
 
-/* 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.
-
-   Move the function address to the trampoline template at offset 36.
-   Move the static chain value to trampoline template at offset 40.
-   Move the trampoline address to trampoline template at offset 44.
-   Move r19 to trampoline template at offset 48.  The latter two
-   words create a plabel for the indirect call to the trampoline.
-
-   A similar sequence is used for the 64-bit port but the plabel is
-   at the beginning of the trampoline.
-
-   Finally, the cache entries for the trampoline code are flushed.
-   This is necessary to ensure that the trampoline instruction sequence
-   is written to memory prior to any attempts at prefetching the code
-   sequence.  */
-
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) 			\
-{									\
-  rtx start_addr = gen_reg_rtx (Pmode);					\
-  rtx end_addr = gen_reg_rtx (Pmode);					\
-  rtx line_length = gen_reg_rtx (Pmode);				\
-  rtx tmp;								\
-									\
-  if (!TARGET_64BIT)							\
-    {									\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 36));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp), (FNADDR));		\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 40));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp), (CXT));			\
-									\
-      /* Create a fat pointer for the trampoline.  */			\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 44));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp), (TRAMP));		\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 48));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp),				\
-		      gen_rtx_REG (Pmode, 19));				\
-									\
-      /* fdc and fic only use registers for the address to flush,	\
-	 they do not accept integer displacements.  We align the	\
-	 start and end addresses to the beginning of their respective	\
-	 cache lines to minimize the number of lines flushed.  */	\
-      tmp = force_reg (Pmode, (TRAMP));					\
-      emit_insn (gen_andsi3 (start_addr, tmp,				\
-			     GEN_INT (-MIN_CACHELINE_SIZE)));		\
-      tmp = force_reg (Pmode,						\
-		       plus_constant (tmp, TRAMPOLINE_CODE_SIZE - 1));	\
-      emit_insn (gen_andsi3 (end_addr, tmp,				\
-			     GEN_INT (-MIN_CACHELINE_SIZE)));		\
-      emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));	\
-      emit_insn (gen_dcacheflushsi (start_addr, end_addr, line_length));\
-      emit_insn (gen_icacheflushsi (start_addr, end_addr, line_length,	\
-				  gen_reg_rtx (Pmode),			\
-				  gen_reg_rtx (Pmode)));		\
-    }									\
-  else									\
-    {									\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 56));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp), (FNADDR));		\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 64));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp), (CXT));			\
-									\
-      /* Create a fat pointer for the trampoline.  */			\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 16));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp),				\
-		      force_reg (Pmode, plus_constant ((TRAMP), 32)));	\
-      tmp = memory_address (Pmode, plus_constant ((TRAMP), 24));	\
-      emit_move_insn (gen_rtx_MEM (Pmode, tmp),				\
-		      gen_rtx_REG (Pmode, 27));				\
-									\
-      /* fdc and fic only use registers for the address to flush,	\
-	 they do not accept integer displacements.  We align the	\
-	 start and end addresses to the beginning of their respective	\
-	 cache lines to minimize the number of lines flushed.  */	\
-      tmp = force_reg (Pmode, plus_constant ((TRAMP), 32));		\
-      emit_insn (gen_anddi3 (start_addr, tmp,				\
-			     GEN_INT (-MIN_CACHELINE_SIZE)));		\
-      tmp = force_reg (Pmode,						\
-		       plus_constant (tmp, TRAMPOLINE_CODE_SIZE - 1));	\
-      emit_insn (gen_anddi3 (end_addr, tmp,				\
-			     GEN_INT (-MIN_CACHELINE_SIZE)));		\
-      emit_move_insn (line_length, GEN_INT (MIN_CACHELINE_SIZE));	\
-      emit_insn (gen_dcacheflushdi (start_addr, end_addr, line_length));\
-      emit_insn (gen_icacheflushdi (start_addr, end_addr, line_length,	\
-				  gen_reg_rtx (Pmode),			\
-				  gen_reg_rtx (Pmode)));		\
-    }									\
-}
-
-/* Perform any machine-specific adjustment in the address of the trampoline.
-   ADDR contains the address that was passed to INITIALIZE_TRAMPOLINE.
-   Adjust the trampoline address to point to the plabel at offset 44.  */
-   
-#define TRAMPOLINE_ADJUST_ADDRESS(ADDR) \
-  if (!TARGET_64BIT) (ADDR) = memory_address (Pmode, plus_constant ((ADDR), 46))
 \f
 /* Addressing modes, and classification of registers for them. 
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 24/36][pdp11] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (21 preceding siblings ...)
  2009-09-21 23:08 ` [patch 23/36][parisc] " Richard Henderson
@ 2009-09-21 23:09 ` Richard Henderson
  2009-09-22 18:31   ` Paul Koning
  2009-09-21 23:10 ` [patch 25/36][picochip] " Richard Henderson
                   ` (11 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:09 UTC (permalink / raw)
  To: GCC Patches; +Cc: ni1d

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

I merged the trampoline template into the initialization function, since 
the integer values were already available.  Otherwise straight-forward.


r~

[-- Attachment #2: d-tramp-24-pdp11 --]
[-- Type: text/plain, Size: 3760 bytes --]

	* config/pdp11/pdp11.c (pdp11_trampoline_init): New.
	(TARGET_TRAMPOLINE_INIT): New.
	* config/pdp11/pdp11.h (TRAMPOLINE_TEMPLATE): Remove.
	(INITIALIZE_TRAMPOLINE): Move code to pdp11_trampoline_init.


diff --git a/gcc/config/pdp11/pdp11.c b/gcc/config/pdp11/pdp11.c
index b467608..f95d03c 100644
--- a/gcc/config/pdp11/pdp11.c
+++ b/gcc/config/pdp11/pdp11.c
@@ -152,6 +152,7 @@ static void pdp11_output_function_prologue (FILE *, HOST_WIDE_INT);
 static void pdp11_output_function_epilogue (FILE *, HOST_WIDE_INT);
 static bool pdp11_rtx_costs (rtx, int, int, int *, bool);
 static bool pdp11_return_in_memory (const_tree, const_tree);
+static void pdp11_trampoline_init (rtx, tree, rtx);
 \f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_BYTE_OP
@@ -185,6 +186,9 @@ static bool pdp11_return_in_memory (const_tree, const_tree);
 #undef TARGET_RETURN_IN_MEMORY
 #define TARGET_RETURN_IN_MEMORY pdp11_return_in_memory
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT pdp11_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Implement TARGET_HANDLE_OPTION.  */
@@ -1740,3 +1744,31 @@ pdp11_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
   return (TYPE_MODE (type) == DImode
 	  || (TYPE_MODE (type) == DFmode && ! TARGET_AC0));
 }
+
+/* Worker function for TARGET_TRAMPOLINE_INIT.
+
+   trampoline - how should i do it in separate i+d ? 
+   have some allocate_trampoline magic??? 
+
+   the following should work for shared I/D:
+
+   MV	#STATIC, $4	0x940Y	0x0000 <- STATIC; Y = STATIC_CHAIN_REGNUM
+   JMP	FUNCTION	0x0058  0x0000 <- FUNCTION
+*/
+
+static void
+pdp11_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  gcc_assert (!TARGET_SPLIT);
+
+  mem = adjust_address (m_tramp, HImode, 0);
+  emit_move_insn (mem, GEN_INT (0x9400+STATIC_CHAIN_REGNUM));
+  mem = adjust_address (m_tramp, HImode, 2);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, HImode, 4);
+  emit_move_insn (mem, GEN_INT (0x0058));
+  emit_move_insn (mem, fnaddr);
+}
diff --git a/gcc/config/pdp11/pdp11.h b/gcc/config/pdp11/pdp11.h
index ac678f5..8997612 100644
--- a/gcc/config/pdp11/pdp11.h
+++ b/gcc/config/pdp11/pdp11.h
@@ -983,42 +983,9 @@ extern struct rtx_def *cc0_reg_rtx;
   fprintf (FILE, "\tmov (sp)+, %s\n", reg_names[REGNO])     	\
 )
 
-/* trampoline - how should i do it in separate i+d ? 
-   have some allocate_trampoline magic??? 
-
-   the following should work for shared I/D: */
-
-/* lets see whether this works as trampoline:
-MV	#STATIC, $4	0x940Y	0x0000 <- STATIC; Y = STATIC_CHAIN_REGNUM
-JMP	FUNCTION	0x0058  0x0000 <- FUNCTION
-*/
-
-#define TRAMPOLINE_TEMPLATE(FILE)	\
-{					\
-  gcc_assert (!TARGET_SPLIT);		\
-					\
-  assemble_aligned_integer (2, GEN_INT (0x9400+STATIC_CHAIN_REGNUM));	\
-  assemble_aligned_integer (2, const0_rtx);				\
-  assemble_aligned_integer (2, GEN_INT(0x0058));			\
-  assemble_aligned_integer (2, const0_rtx);				\
-}
-
 #define TRAMPOLINE_SIZE 8
 #define TRAMPOLINE_ALIGNMENT 16
 
-/* 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)	\
-{					\
-  gcc_assert (!TARGET_SPLIT);		\
-					\
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (TRAMP, 2)), CXT); \
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (TRAMP, 6)), FNADDR); \
-}
-
-
 /* Some machines may desire to change what optimizations are
    performed for various optimization levels.   This macro, if
    defined, is executed once just after the optimization level is

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 25/36][picochip] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (22 preceding siblings ...)
  2009-09-21 23:09 ` [patch 24/36][pdp11] " Richard Henderson
@ 2009-09-21 23:10 ` Richard Henderson
  2009-09-21 23:14 ` [patch 26/36][rs6000] " Richard Henderson
                   ` (10 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:10 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

This port doesn't support trampolines.


r~

[-- Attachment #2: d-tramp-25-picochip --]
[-- Type: text/plain, Size: 476 bytes --]

	* config/picochip/picochip.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/picochip/picochip.h b/gcc/config/picochip/picochip.h
index c08b89d..35c66d2 100644
--- a/gcc/config/picochip/picochip.h
+++ b/gcc/config/picochip/picochip.h
@@ -482,7 +482,6 @@ extern const enum reg_class picochip_regno_reg_class[FIRST_PSEUDO_REGISTER];
 
 /* No trampolines.  */
 #define TRAMPOLINE_SIZE 0
-#define INITIALIZE_TRAMPOLINE(ADDR,FNADDR,CHAIN)
 \f
 /* Addressing Modes  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 21/36][mn10300] Hookize static chain and trampoline macros
  2009-09-21 23:04 ` [patch 21/36][mn10300] " Richard Henderson
@ 2009-09-21 23:11   ` Richard Henderson
  2009-09-22 20:53     ` Alexandre Oliva
  0 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:11 UTC (permalink / raw)
  To: GCC Patches; +Cc: aoliva

[-- Attachment #1: Type: text/plain, Size: 11 bytes --]

Blah.


r~

[-- Attachment #2: d-tramp-21-mn10300 --]
[-- Type: text/plain, Size: 4031 bytes --]

	* config/mn10300/mn10300.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
	mn10300_asm_trampoline_template, TARGET_TRAMPOLINE_INIT,
	mn10300_trampoline_init): New.
	* config/mn10300/mn10300.h (TRAMPOLINE_TEMPLATE): Move code to
	mn10300_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to mn10300_trampoline_init.

	
diff --git a/gcc/config/mn10300/mn10300.c b/gcc/config/mn10300/mn10300.c
index 608f8a0..1a0eb37 100644
--- a/gcc/config/mn10300/mn10300.c
+++ b/gcc/config/mn10300/mn10300.c
@@ -83,6 +83,9 @@ static bool mn10300_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 static int mn10300_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
 				      tree, bool);
 static unsigned int mn10300_case_values_threshold (void);
+static void mn10300_encode_section_info (tree, rtx, int);
+static void mn10300_asm_trampoline_template (FILE *);
+static void mn10300_trampoline_init (rtx, tree, rtx);
 \f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
@@ -131,7 +134,11 @@ static unsigned int mn10300_case_values_threshold (void);
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P	mn10300_legitimate_address_p
 
-static void mn10300_encode_section_info (tree, rtx, int);
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE mn10300_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT mn10300_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Implement TARGET_HANDLE_OPTION.  */
@@ -2165,3 +2172,36 @@ unsigned int mn10300_case_values_threshold (void)
 {
   return 6;
 }
+
+/* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+static void
+mn10300_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\tadd -4,sp\n");
+  fprintf (f, "\t.long 0x0004fffa\n");
+  fprintf (f, "\tmov (0,sp),a0\n");
+  fprintf (f, "\tadd 4,sp\n");
+  fprintf (f, "\tmov (13,a0),a1\n");	
+  fprintf (f, "\tmov (17,a0),a0\n");
+  fprintf (f, "\tjmp (a0)\n");
+  fprintf (f, "\t.long 0\n");
+  fprintf (f, "\t.long 0\n");
+}
+
+/* Worker function for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+mn10300_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, 0x14);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, SImode, 0x18);
+  emit_move_insn (mem, fnaddr);
+}
diff --git a/gcc/config/mn10300/mn10300.h b/gcc/config/mn10300/mn10300.h
index 7d15e05..fc2ece3 100644
--- a/gcc/config/mn10300/mn10300.h
+++ b/gcc/config/mn10300/mn10300.h
@@ -598,36 +598,12 @@ struct cum_arg {int nbytes; };
 
 #define FUNCTION_PROFILER(FILE, LABELNO) ;
 
-#define TRAMPOLINE_TEMPLATE(FILE)			\
-  do {							\
-    fprintf (FILE, "\tadd -4,sp\n");			\
-    fprintf (FILE, "\t.long 0x0004fffa\n");		\
-    fprintf (FILE, "\tmov (0,sp),a0\n");		\
-    fprintf (FILE, "\tadd 4,sp\n");			\
-    fprintf (FILE, "\tmov (13,a0),a1\n");		\
-    fprintf (FILE, "\tmov (17,a0),a0\n");		\
-    fprintf (FILE, "\tjmp (a0)\n");			\
-    fprintf (FILE, "\t.long 0\n");			\
-    fprintf (FILE, "\t.long 0\n");			\
-  } while (0)
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE 0x1b
 
 #define TRAMPOLINE_ALIGNMENT 32
 
-/* 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 (SImode, plus_constant ((TRAMP), 0x14)),	\
- 		 (CXT));						\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant ((TRAMP), 0x18)),	\
-		 (FNADDR));						\
-}
 /* A C expression whose value is RTL representing the value of the return
    address for the frame COUNT steps up from the current frame.
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 23:00       ` DJ Delorie
@ 2009-09-21 23:13         ` Richard Henderson
  2009-09-21 23:18           ` DJ Delorie
  0 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:13 UTC (permalink / raw)
  To: DJ Delorie; +Cc: gcc-patches

On 09/21/2009 03:59 PM, DJ Delorie wrote:
> Don't forget to update doc/tm.texi, please.

Done, in patch 1.  Proofread if you like.  :-)


r~

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 26/36][rs6000] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (23 preceding siblings ...)
  2009-09-21 23:10 ` [patch 25/36][picochip] " Richard Henderson
@ 2009-09-21 23:14 ` Richard Henderson
  2009-09-22  2:16   ` David Edelsohn
  2009-09-21 23:16 ` [patch 27/36][s390] " Richard Henderson
                   ` (9 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:14 UTC (permalink / raw)
  To: GCC Patches; +Cc: edelsohn

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-26-rs6000 --]
[-- Type: text/plain, Size: 4640 bytes --]

	* config/rs6000/rs6000-protos.h (rs6000_initialize_trampoline): Remove.
	* config/rs6000/rs6000.c (TARGET_TRAMPOLINE_INIT): New.
	(rs6000_trampoline_init): Rename from rs6000_initialize_trampoline;
	make static; adjust parameters for the hook.
	* config/rs6000/rs6000.h (INITIALIZE_TRAMPOLINE): Remove.

diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h
index 6e6bb9e..9eaddc3 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -109,7 +109,6 @@ extern void rs6000_emit_swdivsf (rtx, rtx, rtx);
 extern void rs6000_emit_swdivdf (rtx, rtx, rtx);
 extern void rs6000_emit_swrsqrtsf (rtx, rtx);
 extern void output_toc (FILE *, rtx, int, enum machine_mode);
-extern void rs6000_initialize_trampoline (rtx, rtx, rtx);
 extern rtx rs6000_longcall_ref (rtx);
 extern void rs6000_fatal_bad_address (rtx);
 extern rtx create_TOC_reference (rtx);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 564b540..3ba52d4 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1094,6 +1094,7 @@ static const enum reg_class *rs6000_ira_cover_classes (void);
 const int INSN_NOT_AVAILABLE = -1;
 static enum machine_mode rs6000_eh_return_filter_mode (void);
 static bool rs6000_can_eliminate (const int, const int);
+static void rs6000_trampoline_init (rtx, tree, rtx);
 
 /* Hash table stuff for keeping track of TOC entries.  */
 
@@ -1467,6 +1468,9 @@ static const struct attribute_spec rs6000_attribute_table[] =
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE rs6000_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT rs6000_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Return number of consecutive hard regs needed starting at reg REGNO
@@ -22962,32 +22966,38 @@ rs6000_trampoline_size (void)
    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.  */
 
-void
-rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
+static void
+rs6000_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
 {
   int regsize = (TARGET_32BIT) ? 4 : 8;
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
   rtx ctx_reg = force_reg (Pmode, cxt);
+  rtx addr = force_reg (Pmode, XEXP (m_tramp, 0));
 
   switch (DEFAULT_ABI)
     {
     default:
       gcc_unreachable ();
 
-/* Macros to shorten the code expansions below.  */
-#define MEM_DEREF(addr) gen_rtx_MEM (Pmode, memory_address (Pmode, addr))
-#define MEM_PLUS(addr,offset) \
-  gen_rtx_MEM (Pmode, memory_address (Pmode, plus_constant (addr, offset)))
-
     /* Under AIX, just build the 3 word function descriptor */
     case ABI_AIX:
       {
+	rtx fnmem = gen_const_mem (Pmode, force_reg (Pmode, fnaddr));
 	rtx fn_reg = gen_reg_rtx (Pmode);
 	rtx toc_reg = gen_reg_rtx (Pmode);
-	emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
-	emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
-	emit_move_insn (MEM_DEREF (addr), fn_reg);
-	emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
-	emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
+
+  /* Macro to shorten the code expansions below.  */
+# define MEM_PLUS(MEM, OFFSET) adjust_address (MEM, Pmode, OFFSET)
+
+	m_tramp = replace_equiv_address (m_tramp, addr);
+
+	emit_move_insn (fn_reg, MEM_PLUS (fnmem, 0));
+	emit_move_insn (toc_reg, MEM_PLUS (fnmem, regsize));
+	emit_move_insn (MEM_PLUS (m_tramp, 0), fn_reg);
+	emit_move_insn (MEM_PLUS (m_tramp, regsize), toc_reg);
+	emit_move_insn (MEM_PLUS (m_tramp, 2*regsize), ctx_reg);
+
+# undef MEM_PLUS
       }
       break;
 
@@ -23002,8 +23012,6 @@ rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
 			 ctx_reg, Pmode);
       break;
     }
-
-  return;
 }
 
 \f
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 6152e36..e52a9a0 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1727,18 +1727,9 @@ typedef struct rs6000_args
        && (REGNO) == 2))
 
 \f
-/* TRAMPOLINE_TEMPLATE deleted */
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE rs6000_trampoline_size ()
-
-/* 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(ADDR, FNADDR, CXT)		\
-  rs6000_initialize_trampoline (ADDR, FNADDR, CXT)
 \f
 /* Definitions for __builtin_return_address and __builtin_frame_address.
    __builtin_return_address (0) should give link register (65), enable

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 27/36][s390] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (24 preceding siblings ...)
  2009-09-21 23:14 ` [patch 26/36][rs6000] " Richard Henderson
@ 2009-09-21 23:16 ` Richard Henderson
  2009-09-22 14:55   ` Andreas Krebbel
  2009-09-21 23:21 ` [patch 28/36][score] " Richard Henderson
                   ` (8 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:16 UTC (permalink / raw)
  To: GCC Patches; +Cc: uweigand, Andreas.Krebbel

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-27-s390 --]
[-- Type: text/plain, Size: 3730 bytes --]

	* config/s390/s390.c (s390_asm_trampoline_template): Rename from
	s390_trampoline_template; make static.
	(s390_trampoline_init): Rename from s390_initialize_trampoline;
	make static; adjust for target hook.
	(TARGET_ASM_TRAMPOLINE_TEMPLATE, TARGET_TRAMPOLINE_INIT): New.
	* config/s390/s390-protos.h: Remove trampoline decls.
	* config/s390/s390.h (INITIALIZE_TRAMPOLINE): Remove.
	(TRAMPOLINE_TEMPLATE): Remove.
	(TRAMPOLINE_ALIGNMENT): New.


diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
index be68bd5..8a2f1b7 100644
--- a/gcc/config/s390/s390-protos.h
+++ b/gcc/config/s390/s390-protos.h
@@ -106,8 +106,6 @@ extern bool s390_output_addr_const_extra (FILE*, rtx);
 extern void print_operand_address (FILE *, rtx);
 extern void print_operand (FILE *, rtx, int);
 extern void s390_output_pool_entry (rtx, enum machine_mode, unsigned int);
-extern void s390_trampoline_template (FILE *);
-extern void s390_initialize_trampoline (rtx, rtx, rtx);
 extern int s390_agen_dep_p (rtx, rtx);
 extern rtx s390_load_got (void);
 extern rtx s390_get_thread_pointer (void);
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index a4ac3a3..7054e45 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -8863,8 +8863,8 @@ s390_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
    On S/390, we use gpr 1 internally in the trampoline code;
    gpr 0 is used to hold the static chain.  */
 
-void
-s390_trampoline_template (FILE *file)
+static void
+s390_asm_trampoline_template (FILE *file)
 {
   rtx op[2];
   op[0] = gen_rtx_REG (Pmode, 0);
@@ -8890,15 +8890,19 @@ s390_trampoline_template (FILE *file)
    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.  */
 
-void
-s390_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
+static void
+s390_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
 {
-  emit_move_insn (gen_rtx_MEM (Pmode,
-		   memory_address (Pmode,
-		   plus_constant (addr, (TARGET_64BIT ? 16 : 8)))), cxt);
-  emit_move_insn (gen_rtx_MEM (Pmode,
-		   memory_address (Pmode,
-		   plus_constant (addr, (TARGET_64BIT ? 24 : 12)))), fnaddr);
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+  
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (2*UNITS_PER_WORD), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, Pmode, 2*UNITS_PER_WORD);
+  emit_move_insn (mem, cxt);
+  mem = adjust_address (m_tramp, Pmode, 3*UNITS_PER_WORD);
+  emit_move_insn (mem, fnaddr);
 }
 
 /* Output assembler code to FILE to increment profiler label # LABELNO
@@ -10152,6 +10156,11 @@ s390_reorg (void)
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE s390_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE s390_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT s390_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-s390.h"
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index 3c93fb7..ffb96cd 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -712,14 +712,8 @@ CUMULATIVE_ARGS;
 
 /* Trampolines for nested functions.  */
 
-#define TRAMPOLINE_SIZE (TARGET_64BIT ? 32 : 16)
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, CXT)                       \
-   s390_initialize_trampoline ((ADDR), (FNADDR), (CXT))
-
-#define TRAMPOLINE_TEMPLATE(FILE)                                       \
-   s390_trampoline_template (FILE)
-
+#define TRAMPOLINE_SIZE		(TARGET_64BIT ? 32 : 16)
+#define TRAMPOLINE_ALIGNMENT	BITS_PER_WORD
 
 /* Addressing modes, and classification of registers for them.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 14/36][m32c] Hookize static chain and trampoline macros
  2009-09-21 23:13         ` Richard Henderson
@ 2009-09-21 23:18           ` DJ Delorie
  0 siblings, 0 replies; 58+ messages in thread
From: DJ Delorie @ 2009-09-21 23:18 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches


> Done, in patch 1.  Proofread if you like.  :-)

Honest, I looked there first... :-P

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 28/36][score] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (25 preceding siblings ...)
  2009-09-21 23:16 ` [patch 27/36][s390] " Richard Henderson
@ 2009-09-21 23:21 ` Richard Henderson
  2009-09-22 11:02   ` 答复: " liqin
  2009-09-22 11:25   ` Paolo Bonzini
  2009-09-21 23:22 ` [patch 29/36][sh] " Richard Henderson
                   ` (7 subsequent siblings)
  34 siblings, 2 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:21 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 573 bytes --]

A less straight-forward conversion to hooks.

I'd like to complain about this port.  No other port doubles the amount 
of effort required to support two differing cpu models.  This score3 vs 
score7 thing is absolutely for the birds.

Also, no one's bothering to see that it continues to compile -- there 
was a trivial error in the placement of one of the GTY tags that surely 
would have been noticed.

Also, there's no listed maintainer.  Isn't that a requirement for new 
ports?  This certainly isn't some legacy something that's been in there 
for ages like ARC.


r~

[-- Attachment #2: d-tramp-28-score --]
[-- Type: text/plain, Size: 12528 bytes --]

	* config/score/score-protos.h (score_initialize_trampoline): Remove.
	* config/score/score.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(score_asm_trampoline_template): New.
	(score_trampoline_init): Rename from score_initialize_trampoline;
	make static; adjust for hook parameters.
	* config/score/score.h (TRAMPOLINE_TEMPLATE): Move code to
	score[37]_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Remove.
	* config/score/score3.c (score3_asm_trampoline_template): New.
	(score3_trampoline_init): Rename from score3_initialize_trampoline;
	adjust for target hook.
	* config/score/score7.c (score7_asm_trampoline_template): New.
	(score7_trampoline_init): Rename from score7_initialize_trampoline;
	adjust for target hook.
	* config/score/score3.h, config/score/score7.h: Update.


diff --git a/gcc/config/score/score-protos.h b/gcc/config/score/score-protos.h
index 204dc18..d42ec14 100644
--- a/gcc/config/score/score-protos.h
+++ b/gcc/config/score/score-protos.h
@@ -50,7 +50,6 @@ extern int score_hard_regno_mode_ok (unsigned int, enum machine_mode);
 extern int score_const_ok_for_letter_p (HOST_WIDE_INT value, char c);
 extern int score_extra_constraint (rtx op, char c);
 extern rtx score_return_addr (int count, rtx frame);
-extern void score_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN);
 extern int score_regno_mode_ok_for_base_p (int regno, int strict);
 extern void score_function_arg_advance (CUMULATIVE_ARGS *cum,
                                         enum machine_mode mode,
diff --git a/gcc/config/score/score.c b/gcc/config/score/score.c
index 12eb76b..4324d65 100644
--- a/gcc/config/score/score.c
+++ b/gcc/config/score/score.c
@@ -119,6 +119,11 @@
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE            score_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE	score_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT		score_trampoline_init
+
 struct extern_list *extern_head = 0;
 
 /* default 0 = NO_REGS  */
@@ -519,14 +524,27 @@ score_function_value (tree valtype, tree func ATTRIBUTE_UNUSED,
   gcc_unreachable ();
 }
 
-/* Implement INITIALIZE_TRAMPOLINE macro.  */
-void
-score_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN)
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+static void
+score_asm_trampoline_template (FILE *f)
+{
+  if (TARGET_SCORE5 || TARGET_SCORE5U || TARGET_SCORE7 || TARGET_SCORE7D)
+    return score7_asm_trampoline_template (f);
+  else if (TARGET_SCORE3)
+    return score3_asm_trampoline_template (f);
+
+  gcc_unreachable ();
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
+static void
+score_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
+  /* ??? These two routines are identical.  */
   if (TARGET_SCORE5 || TARGET_SCORE5U || TARGET_SCORE7 || TARGET_SCORE7D)
-    return score7_initialize_trampoline (ADDR, FUNC, CHAIN);
+    return score7_trampoline_init (m_tramp, fndecl, chain_value);
   else if (TARGET_SCORE3)
-    return score3_initialize_trampoline (ADDR, FUNC, CHAIN);
+    return score3_trampoline_init (m_tramp, fndecl, chain_value);
 
   gcc_unreachable ();
 }
diff --git a/gcc/config/score/score.h b/gcc/config/score/score.h
index ea3e016..0b7af7b 100644
--- a/gcc/config/score/score.h
+++ b/gcc/config/score/score.h
@@ -673,54 +673,12 @@ typedef struct score_args
       }                                                               \
   } while (0)
 
-#define TRAMPOLINE_TEMPLATE(STREAM)                                   \
-  do {                                                                \
-    if (TARGET_SCORE7)                                                \
-      {                                                               \
-        fprintf (STREAM, "\t.set r1\n");                              \
-        fprintf (STREAM, "\tmv r31, r3\n");                           \
-        fprintf (STREAM, "\tbl nextinsn\n");                          \
-        fprintf (STREAM, "nextinsn:\n");                              \
-        fprintf (STREAM, "\tlw r1, [r3, 6*4-8]\n");                   \
-        fprintf (STREAM, "\tlw r23, [r3, 6*4-4]\n");                  \
-        fprintf (STREAM, "\tmv r3, r31\n");                           \
-        fprintf (STREAM, "\tbr! r1\n");                               \
-        fprintf (STREAM, "\tnop!\n");                                 \
-        fprintf (STREAM, "\t.set nor1\n");                            \
-      }                                                               \
-    else if (TARGET_SCORE3)                                           \
-      {                                                               \
-        fprintf (STREAM, "\t.set r1\n");                              \
-        fprintf (STREAM, "\tmv! r31, r3\n");                          \
-        fprintf (STREAM, "\tnop!\n");                                 \
-        fprintf (STREAM, "\tbl nextinsn\n");                          \
-        fprintf (STREAM, "nextinsn:\n");                              \
-        fprintf (STREAM, "\tlw! r1, [r3, 6*4-8]\n");                  \
-        fprintf (STREAM, "\tnop!\n");                                 \
-        fprintf (STREAM, "\tlw r23, [r3, 6*4-4]\n");                  \
-        fprintf (STREAM, "\tmv! r3, r31\n");                          \
-        fprintf (STREAM, "\tnop!\n");                                 \
-        fprintf (STREAM, "\tbr! r1\n");                               \
-        fprintf (STREAM, "\tnop!\n");                                 \
-        fprintf (STREAM, "\t.set nor1\n");                            \
-      }                                                               \
-  } while (0)
-
 /* Trampolines for Nested Functions.  */
 #define TRAMPOLINE_INSNS                6
 
 /* A C expression for the size in bytes of the trampoline, as an integer.  */
 #define TRAMPOLINE_SIZE                (24 + GET_MODE_SIZE (ptr_mode) * 2)
 
-/* A C statement to initialize the variable parts of a trampoline.
-   ADDR is an RTX for the address of the trampoline; FNADDR is an
-   RTX for the address of the nested function; STATIC_CHAIN is an
-   RTX for the static chain value that should be passed to the
-   function when it is called.  */
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FUNC, CHAIN) \
-  score_initialize_trampoline (ADDR, FUNC, CHAIN)
-
 #define HAVE_PRE_INCREMENT              1
 #define HAVE_PRE_DECREMENT              1
 #define HAVE_POST_INCREMENT             1
@@ -1067,7 +1025,7 @@ typedef struct score_args
    for 32-bit targets.  */
 #define FUNCTION_MODE                   Pmode
 
-struct extern_list GTY ((chain_next ("%h.next")))
+struct GTY ((chain_next ("%h.next"))) extern_list
 {
   struct extern_list *next;             /* next external  */
   const char *name;                     /* name of the external  */
diff --git a/gcc/config/score/score3.c b/gcc/config/score/score3.c
index d27d1f9..a5c8e60 100644
--- a/gcc/config/score/score3.c
+++ b/gcc/config/score/score3.c
@@ -870,23 +870,48 @@ score3_function_value (tree valtype, tree func, enum machine_mode mode)
   return gen_rtx_REG (mode, RT_REGNUM);
 }
 
-/* Implement INITIALIZE_TRAMPOLINE macro.  */
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+void
+score3_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\t.set r1\n");
+  fprintf (f, "\tmv! r31, r3\n");
+  fprintf (f, "\tnop!\n");
+  fprintf (f, "\tbl nextinsn\n");
+  fprintf (f, "nextinsn:\n");
+  fprintf (f, "\tlw! r1, [r3, 6*4-8]\n");
+  fprintf (f, "\tnop!\n");
+  fprintf (f, "\tlw r23, [r3, 6*4-4]\n");
+  fprintf (f, "\tmv! r3, r31\n");
+  fprintf (f, "\tnop!\n");
+  fprintf (f, "\tbr! r1\n");
+  fprintf (f, "\tnop!\n");
+  fprintf (f, "\t.set nor1\n");
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
 void
-score3_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN)
+score3_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
 #define FFCACHE          "_flush_cache"
 #define CODE_SIZE        (TRAMPOLINE_INSNS * UNITS_PER_WORD)
 
-  rtx pfunc, pchain;
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx addr = XEXP (m_tramp, 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
 
-  pfunc = plus_constant (ADDR, CODE_SIZE);
-  pchain = plus_constant (ADDR, CODE_SIZE + GET_MODE_SIZE (SImode));
+  mem = adjust_address (m_tramp, SImode, CODE_SIZE);
+  emit_move_insn (mem, fnaddr);
+  mem = adjust_address (m_tramp, SImode, CODE_SIZE + GET_MODE_SIZE (SImode));
+  emit_move_insn (mem, chain_value);
 
-  emit_move_insn (gen_rtx_MEM (SImode, pfunc), FUNC);
-  emit_move_insn (gen_rtx_MEM (SImode, pchain), CHAIN);
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, FFCACHE),
                      0, VOIDmode, 2,
-                     ADDR, Pmode,
+                     addr, Pmode,
                      GEN_INT (TRAMPOLINE_SIZE), SImode);
 #undef FFCACHE
 #undef CODE_SIZE
diff --git a/gcc/config/score/score3.h b/gcc/config/score/score3.h
index 001b2f0..4e545fc 100644
--- a/gcc/config/score/score3.h
+++ b/gcc/config/score/score3.h
@@ -120,7 +120,8 @@ extern rtx score3_function_arg (const CUMULATIVE_ARGS *cum,
 extern rtx score3_function_value (tree valtype,
                                   tree func ATTRIBUTE_UNUSED,
                                   enum machine_mode mode);
-extern void score3_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN);
+extern void score3_asm_trampoline_template (FILE *);
+extern void score3_trampoline_init (rtx, tree, rtx);
 extern int score3_regno_mode_ok_for_base_p (int regno, int strict);
 extern bool score3_legitimate_address_p (enum machine_mode mode, rtx x,
 					 bool strict);
diff --git a/gcc/config/score/score7.c b/gcc/config/score/score7.c
index 4ba3dce..2307201 100644
--- a/gcc/config/score/score7.c
+++ b/gcc/config/score/score7.c
@@ -861,23 +861,45 @@ score7_function_value (tree valtype, tree func, enum machine_mode mode)
   return gen_rtx_REG (mode, RT_REGNUM);
 }
 
-/* Implement INITIALIZE_TRAMPOLINE macro.  */
+/* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+void
+score7_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\t.set r1\n");
+  fprintf (f, "\tmv r31, r3\n");
+  fprintf (f, "\tbl nextinsn\n");
+  fprintf (f, "nextinsn:\n");
+  fprintf (f, "\tlw r1, [r3, 6*4-8]\n");
+  fprintf (f, "\tlw r23, [r3, 6*4-4]\n");
+  fprintf (f, "\tmv r3, r31\n");
+  fprintf (f, "\tbr! r1\n");
+  fprintf (f, "\tnop!\n");
+  fprintf (f, "\t.set nor1\n");
+}
+
+/* Implement TARGET_TRAMPOLINE_INIT.  */
 void
-score7_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN)
+score7_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
 #define FFCACHE          "_flush_cache"
 #define CODE_SIZE        (TRAMPOLINE_INSNS * UNITS_PER_WORD)
 
-  rtx pfunc, pchain;
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx addr = XEXP (m_tramp, 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
 
-  pfunc = plus_constant (ADDR, CODE_SIZE);
-  pchain = plus_constant (ADDR, CODE_SIZE + GET_MODE_SIZE (SImode));
+  mem = adjust_address (m_tramp, SImode, CODE_SIZE);
+  emit_move_insn (mem, fnaddr);
+  mem = adjust_address (m_tramp, SImode, CODE_SIZE + GET_MODE_SIZE (SImode));
+  emit_move_insn (mem, chain_value);
 
-  emit_move_insn (gen_rtx_MEM (SImode, pfunc), FUNC);
-  emit_move_insn (gen_rtx_MEM (SImode, pchain), CHAIN);
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, FFCACHE),
                      0, VOIDmode, 2,
-                     ADDR, Pmode,
+                     addr, Pmode,
                      GEN_INT (TRAMPOLINE_SIZE), SImode);
 #undef FFCACHE
 #undef CODE_SIZE
diff --git a/gcc/config/score/score7.h b/gcc/config/score/score7.h
index ae3f4e8..0931a2b 100644
--- a/gcc/config/score/score7.h
+++ b/gcc/config/score/score7.h
@@ -120,7 +120,8 @@ extern rtx score7_function_arg (const CUMULATIVE_ARGS *cum,
 extern rtx score7_function_value (tree valtype,
                                   tree func ATTRIBUTE_UNUSED,
                                   enum machine_mode mode);
-extern void score7_initialize_trampoline (rtx ADDR, rtx FUNC, rtx CHAIN);
+extern void score7_asm_trampoline_template (FILE *);
+extern void score7_trampoline_init (rtx, tree, rtx);
 extern int score7_regno_mode_ok_for_base_p (int regno, int strict);
 extern bool score7_legitimate_address_p (enum machine_mode mode, rtx x,
 					 bool strict);

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 30/36][sparc] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (27 preceding siblings ...)
  2009-09-21 23:22 ` [patch 29/36][sh] " Richard Henderson
@ 2009-09-21 23:22 ` Richard Henderson
  2009-09-22 13:09   ` Eric Botcazou
  2009-09-21 23:26 ` [patch 31/36][spu] " Richard Henderson
                   ` (5 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:22 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jakub Jelinek, ebotcazou

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-30-sparc --]
[-- Type: text/plain, Size: 8955 bytes --]

	* config/sparc/sparc.c (TARGET_TRAMPOLINE_INIT): New.
	(sparc32_initialize_trampoline): Rename from
	sparc_initialize_trampoline; make static; replace tramp parameter
	with m_tramp and update memory accesses.
	(sparc64_initialize_trampoline): Similarly.
	(sparc_trampoline_init): New.
	* config/sparc/sparc-protos.h: Remove trampoline decls.
	* config/sparc/sparc.h (INITIALIZE_TRAMPOLINE): Remove.
	* config/sparc/sparc.md (nonlocal_goto): Don't use static_chain_rtx.


diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
index 4ece6c0..097b709 100644
--- a/gcc/config/sparc/sparc-protos.h
+++ b/gcc/config/sparc/sparc-protos.h
@@ -61,9 +61,6 @@ extern void sparc_emit_fixunsdi (rtx [2], enum machine_mode);
 extern void emit_tfmode_binop (enum rtx_code, rtx *);
 extern void emit_tfmode_unop (enum rtx_code, rtx *);
 extern void emit_tfmode_cvt (enum rtx_code, rtx *);
-/* This function handles all v9 scc insns */
-extern void sparc_initialize_trampoline (rtx, rtx, rtx);
-extern void sparc64_initialize_trampoline (rtx, rtx, rtx);
 extern bool legitimate_constant_p (rtx);
 extern bool constant_address_p (rtx);
 extern bool legitimate_pic_operand_p (rtx);
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index ea43914..0bfde6f 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -424,6 +424,7 @@ static bool sparc_can_eliminate (const int, const int);
 #ifdef TARGET_ALTERNATE_LONG_DOUBLE_MANGLING
 static const char *sparc_mangle_type (const_tree);
 #endif
+static void sparc_trampoline_init (rtx, tree, rtx);
 \f
 #ifdef SUBTARGET_ATTRIBUTE_TABLE
 /* Table of valid machine attributes.  */
@@ -600,6 +601,9 @@ static bool fpu_option_set = false;
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P sparc_legitimate_address_p
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT sparc_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Implement TARGET_HANDLE_OPTION.  */
@@ -7404,8 +7408,8 @@ sparc_type_code (register tree type)
 
    Emit enough FLUSH insns to synchronize the data and instruction caches.  */
 
-void
-sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+sparc32_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
 {
   /* SPARC 32-bit trampoline:
 
@@ -7419,7 +7423,7 @@ sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
    */
 
   emit_move_insn
-    (gen_rtx_MEM (SImode, plus_constant (tramp, 0)),
+    (adjust_address (m_tramp, SImode, 0),
      expand_binop (SImode, ior_optab,
 		   expand_shift (RSHIFT_EXPR, SImode, fnaddr,
 				 size_int (10), 0, 1),
@@ -7427,7 +7431,7 @@ sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
 		   NULL_RTX, 1, OPTAB_DIRECT));
 
   emit_move_insn
-    (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
+    (adjust_address (m_tramp, SImode, 4),
      expand_binop (SImode, ior_optab,
 		   expand_shift (RSHIFT_EXPR, SImode, cxt,
 				 size_int (10), 0, 1),
@@ -7435,14 +7439,14 @@ sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
 		   NULL_RTX, 1, OPTAB_DIRECT));
 
   emit_move_insn
-    (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
+    (adjust_address (m_tramp, SImode, 8),
      expand_binop (SImode, ior_optab,
 		   expand_and (SImode, fnaddr, GEN_INT (0x3ff), NULL_RTX),
 		   GEN_INT (trunc_int_for_mode (0x81c06000, SImode)),
 		   NULL_RTX, 1, OPTAB_DIRECT));
 
   emit_move_insn
-    (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
+    (adjust_address (m_tramp, SImode, 12),
      expand_binop (SImode, ior_optab,
 		   expand_and (SImode, cxt, GEN_INT (0x3ff), NULL_RTX),
 		   GEN_INT (trunc_int_for_mode (0x8410a000, SImode)),
@@ -7450,19 +7454,18 @@ sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
 
   /* On UltraSPARC a flush flushes an entire cache line.  The trampoline is
      aligned on a 16 byte boundary so one flush clears it all.  */
-  emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode, tramp))));
+  emit_insn (gen_flush (validize_mem (adjust_address (m_tramp, SImode, 0))));
   if (sparc_cpu != PROCESSOR_ULTRASPARC
       && sparc_cpu != PROCESSOR_ULTRASPARC3
       && sparc_cpu != PROCESSOR_NIAGARA
       && sparc_cpu != PROCESSOR_NIAGARA2)
-    emit_insn (gen_flush (validize_mem (gen_rtx_MEM (SImode,
-						     plus_constant (tramp, 8)))));
+    emit_insn (gen_flush (validize_mem (adjust_address (m_tramp, SImode, 8))));
 
   /* Call __enable_execute_stack after writing onto the stack to make sure
      the stack address is accessible.  */
 #ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
-                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+                     LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
 #endif
 
 }
@@ -7471,8 +7474,8 @@ sparc_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
    values as "immediate" data out of the trampoline.  It's also easier since
    we can read the PC without clobbering a register.  */
 
-void
-sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+sparc64_initialize_trampoline (rtx m_tramp, rtx fnaddr, rtx cxt)
 {
   /* SPARC 64-bit trampoline:
 
@@ -7483,31 +7486,44 @@ sparc64_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
 	+16 bytes data
    */
 
-  emit_move_insn (gen_rtx_MEM (SImode, tramp),
+  emit_move_insn (adjust_address (m_tramp, SImode, 0),
 		  GEN_INT (trunc_int_for_mode (0x83414000, SImode)));
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 4)),
+  emit_move_insn (adjust_address (m_tramp, SImode, 4),
 		  GEN_INT (trunc_int_for_mode (0xca586018, SImode)));
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 8)),
+  emit_move_insn (adjust_address (m_tramp, SImode, 8),
 		  GEN_INT (trunc_int_for_mode (0x81c14000, SImode)));
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 12)),
+  emit_move_insn (adjust_address (m_tramp, SImode, 12),
 		  GEN_INT (trunc_int_for_mode (0xca586010, SImode)));
-  emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 16)), cxt);
-  emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, 24)), fnaddr);
-  emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, tramp))));
+  emit_move_insn (adjust_address (m_tramp, DImode, 16), cxt);
+  emit_move_insn (adjust_address (m_tramp, DImode, 24), fnaddr);
+  emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 0))));
 
   if (sparc_cpu != PROCESSOR_ULTRASPARC
       && sparc_cpu != PROCESSOR_ULTRASPARC3
       && sparc_cpu != PROCESSOR_NIAGARA
       && sparc_cpu != PROCESSOR_NIAGARA2)
-    emit_insn (gen_flushdi (validize_mem (gen_rtx_MEM (DImode, plus_constant (tramp, 8)))));
+    emit_insn (gen_flushdi (validize_mem (adjust_address (m_tramp, DImode, 8))));
 
   /* Call __enable_execute_stack after writing onto the stack to make sure
      the stack address is accessible.  */
 #ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
-                     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+                     LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
 #endif
 }
+
+/* Worker for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+sparc_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
+{
+  rtx fnaddr = force_reg (Pmode, XEXP (DECL_RTL (fndecl), 0));
+  cxt = force_reg (Pmode, cxt);
+  if (TARGET_ARCH64)
+    sparc64_initialize_trampoline (m_tramp, fnaddr, cxt);
+  else
+    sparc32_initialize_trampoline (m_tramp, fnaddr, cxt);
+}
 \f
 /* Adjust the cost of a scheduling dependency.  Return the new cost of
    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index c5c762a..13efc69 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -1612,16 +1612,6 @@ do {									\
 #define TRAMPOLINE_SIZE (TARGET_ARCH64 ? 32 : 16)
 
 #define TRAMPOLINE_ALIGNMENT 128 /* 16 bytes */
-
-/* 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) \
-    if (TARGET_ARCH64)						\
-      sparc64_initialize_trampoline (TRAMP, FNADDR, CXT);	\
-    else							\
-      sparc_initialize_trampoline (TRAMP, FNADDR, CXT)
 \f
 /* Generate RTL to flush the register windows so as to make arbitrary frames
    available.  */
diff --git a/gcc/config/sparc/sparc.md b/gcc/config/sparc/sparc.md
index 9e35910..5167792 100644
--- a/gcc/config/sparc/sparc.md
+++ b/gcc/config/sparc/sparc.md
@@ -6397,7 +6397,6 @@
   emit_move_insn (hard_frame_pointer_rtx, stack);
 
   emit_use (stack_pointer_rtx);
-  emit_use (static_chain_rtx);
 
   /* ??? The V9-specific version was disabled in rev 1.65.  */
   emit_jump_insn (gen_goto_handler_and_restore (labreg));

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 29/36][sh] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (26 preceding siblings ...)
  2009-09-21 23:21 ` [patch 28/36][score] " Richard Henderson
@ 2009-09-21 23:22 ` Richard Henderson
  2009-09-22 20:47   ` Alexandre Oliva
  2009-09-21 23:22 ` [patch 30/36][sparc] " Richard Henderson
                   ` (6 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:22 UTC (permalink / raw)
  To: GCC Patches; +Cc: kkojima, aoliva

[-- Attachment #1: Type: text/plain, Size: 255 bytes --]

A straight-forward conversion to hooks.

I'm pleased to see this port already used the adjust_address family of 
functions.  Although there's a change_address in there that *probably* 
wants to use replace_equiv_address or adjust_automodify instead.


r~

[-- Attachment #2: d-tramp-29-sh --]
[-- Type: text/plain, Size: 4656 bytes --]

	* config/sh/sh-protos.h (sh_initialize_trampoline): Remove.
	* config/sh/sh.c (TARGET_TRAMPOLINE_INIT): New.
	(TARGET_TRAMPOLINE_ADJUST_ADDRESS): New.
	(sh_trampoline_init): Rename from sh_initialize_trampoline;
	make static; adjust for target hook parameters.
	(sh_trampoline_adjust_address): New.
	* config/sh/sh.h (INITIALIZE_TRAMPOLINE): New.
	(TRAMPOLINE_ADJUST_ADDRESS): Move code to sh_trampoline_adjust_address.


diff --git a/gcc/config/sh/sh-protos.h b/gcc/config/sh/sh-protos.h
index 35cd730..f61c5d5 100644
--- a/gcc/config/sh/sh-protos.h
+++ b/gcc/config/sh/sh-protos.h
@@ -142,7 +142,6 @@ extern int sh_cfun_interrupt_handler_p (void);
 extern int sh_cfun_resbank_handler_p (void);
 extern int sh_attr_renesas_p (const_tree);
 extern int sh_cfun_attr_renesas_p (void);
-extern void sh_initialize_trampoline (rtx, rtx, rtx);
 extern bool sh_cannot_change_mode_class
 	      (enum machine_mode, enum machine_mode, enum reg_class);
 extern void sh_mark_label (rtx, int);
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index d0f9932..df03c14 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -272,6 +272,8 @@ static bool sh_scalar_mode_supported_p (enum machine_mode);
 static int sh_dwarf_calling_convention (const_tree);
 static void sh_encode_section_info (tree, rtx, int);
 static int sh2a_function_vector_p (tree);
+static void sh_trampoline_init (rtx, tree, rtx);
+static rtx sh_trampoline_adjust_address (rtx);
 \f
 static const struct attribute_spec sh_attribute_table[] =
 {
@@ -511,6 +513,11 @@ static const struct attribute_spec sh_attribute_table[] =
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P	sh_legitimate_address_p
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT		sh_trampoline_init
+#undef TARGET_TRAMPOLINE_ADJUST_ADDRESS
+#define TARGET_TRAMPOLINE_ADJUST_ADDRESS sh_trampoline_adjust_address
+
 /* Machine-specific symbol_ref flags.  */
 #define SYMBOL_FLAG_FUNCVEC_FUNCTION    (SYMBOL_FLAG_MACH_DEP << 0)
 
@@ -10327,10 +10334,11 @@ sh_ms_bitfield_layout_p (const_tree record_type ATTRIBUTE_UNUSED)
    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.  */
 
-void
-sh_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+sh_trampoline_init (rtx tramp_mem, tree fndecl, rtx cxt)
 {
-  rtx tramp_mem = gen_frame_mem (BLKmode, tramp);
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx tramp = force_reg (Pmode, XEXP (tramp_mem, 0));
 
   if (TARGET_SHMEDIA64)
     {
@@ -10421,7 +10429,6 @@ sh_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
       rtx ptabs = force_reg (DImode, GEN_INT (0x6bf10600));
       rtx blink = force_reg (DImode, GEN_INT (0x4401fff0));
 
-      tramp = force_reg (Pmode, tramp);
       fnaddr = force_reg (SImode, fnaddr);
       cxt = force_reg (SImode, cxt);
       emit_insn (gen_mshflo_w_x (gen_rtx_SUBREG (V4HImode, quad0, 0),
@@ -10477,6 +10484,17 @@ sh_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
     }
 }
 
+/* On SH5, trampolines are SHmedia code, so add 1 to the address.  */
+
+static rtx
+sh_trampoline_adjust_address (rtx tramp)
+{
+  if (TARGET_SHMEDIA)
+    tramp = expand_simple_binop (Pmode, PLUS, tramp, const1_rtx,
+				 gen_reg_rtx (Pmode), 0, OPTAB_LIB_WIDEN);
+  return tramp;
+}
+
 /* FIXME: This is overly conservative.  A SHcompact function that
    receives arguments ``by reference'' will have them stored in its
    own stack frame, so it must not pass pointers or references to
diff --git a/gcc/config/sh/sh.h b/gcc/config/sh/sh.h
index 9b3d99f..c24555f 100644
--- a/gcc/config/sh/sh.h
+++ b/gcc/config/sh/sh.h
@@ -1829,23 +1829,6 @@ struct sh_args {
   ((CACHE_LOG < 3 || (TARGET_SMALLCODE && ! TARGET_HARVARD)) ? 32 \
    : TARGET_SHMEDIA ? 256 : 64)
 
-/* 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) \
-  sh_initialize_trampoline ((TRAMP), (FNADDR), (CXT))
-
-/* On SH5, trampolines are SHmedia code, so add 1 to the address.  */
-
-#define TRAMPOLINE_ADJUST_ADDRESS(TRAMP) do				\
-{									\
-  if (TARGET_SHMEDIA)							\
-    (TRAMP) = expand_simple_binop (Pmode, PLUS, (TRAMP), const1_rtx,	\
-				   gen_reg_rtx (Pmode), 0,		\
-				   OPTAB_LIB_WIDEN);			\
-} while (0)
-
 /* A C expression whose value is RTL representing the value of the return
    address for the frame COUNT steps up from the current frame.
    FRAMEADDR is already the frame pointer of the COUNT frame, so we

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 31/36][spu] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (28 preceding siblings ...)
  2009-09-21 23:22 ` [patch 30/36][sparc] " Richard Henderson
@ 2009-09-21 23:26 ` Richard Henderson
  2009-09-21 23:44   ` Andrew Pinski
  2009-09-21 23:27 ` [patch 32/36][stormy16] " Richard Henderson
                   ` (4 subsequent siblings)
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:26 UTC (permalink / raw)
  To: GCC Patches; +Cc: andrew_pinski, edelsohn

[-- Attachment #1: Type: text/plain, Size: 246 bytes --]

A straight-forward conversion to hooks.

One thing that could probably have been separated out and changed en 
masse is const-ifying array_to_constant, and making any arrays feeding 
it static.  I did change the ones in spu_trampoline_init.


r~

[-- Attachment #2: d-tramp-31-spu --]
[-- Type: text/plain, Size: 5330 bytes --]

	* config/spu/spu.c (TARGET_TRAMPOLINE_INIT): New.
	(array_to_constant): Make ARR parameter const.
	(spu_trampoline_init): Rename from spu_initialize_trampoline;
	make static; update for hook parameters.
	* config/spu/spu-protos.h: Update decls.
	* config/spu/spu.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/spu/spu-protos.h b/gcc/config/spu/spu-protos.h
index 65cdd07..a1f5d13 100644
--- a/gcc/config/spu/spu-protos.h
+++ b/gcc/config/spu/spu-protos.h
@@ -70,7 +70,7 @@ extern int cpat_const_p (rtx x, enum machine_mode mode);
 extern rtx gen_cpat_const (rtx * ops);
 extern void constant_to_array (enum machine_mode mode, rtx x,
 			       unsigned char *arr);
-extern rtx array_to_constant (enum machine_mode mode, unsigned char *arr);
+extern rtx array_to_constant (enum machine_mode mode, const unsigned char *arr);
 extern rtx spu_gen_exp2 (enum machine_mode mode, rtx x);
 extern void spu_allocate_stack (rtx op0, rtx op1);
 extern void spu_restore_stack_nonlocal (rtx op0, rtx op1);
@@ -81,7 +81,6 @@ extern void spu_builtin_splats (rtx ops[]);
 extern void spu_builtin_extract (rtx ops[]);
 extern void spu_builtin_insert (rtx ops[]);
 extern void spu_builtin_promote (rtx ops[]);
-extern void spu_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt);
 extern void spu_expand_sign_extend (rtx ops[]);
 extern void spu_expand_vector_init (rtx target, rtx vals);
 extern void spu_init_expanders (void);
diff --git a/gcc/config/spu/spu.c b/gcc/config/spu/spu.c
index 37488b2..b0b2fd2 100644
--- a/gcc/config/spu/spu.c
+++ b/gcc/config/spu/spu.c
@@ -212,6 +212,7 @@ static int spu_sms_res_mii (struct ddg *g);
 static void asm_file_start (void);
 static unsigned int spu_section_type_flags (tree, const char *, int);
 static rtx spu_expand_load (rtx, rtx, rtx, int);
+static void spu_trampoline_init (rtx, tree, rtx);
 
 extern const char *reg_names[];
 
@@ -411,6 +412,9 @@ static const struct attribute_spec spu_attribute_table[] =
 #undef TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P spu_legitimate_address_p
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT spu_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 void
@@ -4876,7 +4880,7 @@ constant_to_array (enum machine_mode mode, rtx x, unsigned char arr[16])
    smaller than 16 bytes, use the bytes that would represent that value
    in a register, e.g., for QImode return the value of arr[3].  */
 rtx
-array_to_constant (enum machine_mode mode, unsigned char arr[16])
+array_to_constant (enum machine_mode mode, const unsigned char arr[16])
 {
   enum machine_mode inner_mode;
   rtvec v;
@@ -5580,9 +5584,10 @@ spu_builtin_promote (rtx ops[])
   emit_insn (gen_rotqby_ti (rot, from, offset));
 }
 
-void
-spu_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+static void
+spu_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
 {
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
   rtx shuf = gen_reg_rtx (V4SImode);
   rtx insn = gen_reg_rtx (V4SImode);
   rtx shufc;
@@ -5597,11 +5602,11 @@ spu_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
       rtx rotl = gen_reg_rtx (V4SImode);
       rtx mask = gen_reg_rtx (V4SImode);
       rtx bi = gen_reg_rtx (SImode);
-      unsigned char shufa[16] = {
+      static unsigned char const shufa[16] = {
 	2, 3, 0, 1, 18, 19, 16, 17,
 	0, 1, 2, 3, 16, 17, 18, 19
       };
-      unsigned char insna[16] = {
+      static unsigned char const insna[16] = {
 	0x41, 0, 0, 79,
 	0x41, 0, 0, STATIC_CHAIN_REGNUM,
 	0x60, 0x80, 0, 79,
@@ -5616,18 +5621,18 @@ spu_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
       emit_insn (gen_movv4si (mask, spu_const (V4SImode, 0xffff << 7)));
       emit_insn (gen_selb (insn, insnc, rotl, mask));
 
-      mem = memory_address (Pmode, tramp);
-      emit_move_insn (gen_rtx_MEM (V4SImode, mem), insn);
+      mem = adjust_address (m_tramp, V4SImode, 0);
+      emit_move_insn (mem, insn);
 
       emit_move_insn (bi, GEN_INT (0x35000000 + (79 << 7)));
-      mem = memory_address (Pmode, plus_constant (tramp, 16));
-      emit_move_insn (gen_rtx_MEM (Pmode, mem), bi);
+      mem = adjust_address (m_tramp, Pmode, 16);
+      emit_move_insn (mem, bi);
     }
   else
     {
       rtx scxt = gen_reg_rtx (SImode);
       rtx sfnaddr = gen_reg_rtx (SImode);
-      unsigned char insna[16] = {
+      static unsigned char const insna[16] = {
 	0x42, 0, 0, STATIC_CHAIN_REGNUM,
 	0x30, 0, 0, 0,
 	0, 0, 0, 0,
@@ -5649,9 +5654,8 @@ spu_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
       emit_insn (gen_shufb (shuf, sfnaddr, scxt, shufc));
       emit_insn (gen_iorv4si3 (insn, insnc, shuf));
 
-      mem = memory_address (Pmode, tramp);
-      emit_move_insn (gen_rtx_MEM (V4SImode, mem), insn);
-
+      mem = adjust_address (m_tramp, V4SImode, 0);
+      emit_move_insn (mem, insn);
     }
   emit_insn (gen_sync ());
 }
diff --git a/gcc/config/spu/spu.h b/gcc/config/spu/spu.h
index 6b56a45..67011a6 100644
--- a/gcc/config/spu/spu.h
+++ b/gcc/config/spu/spu.h
@@ -403,10 +403,6 @@ targetm.resolve_overloaded_builtin = spu_resolve_overloaded_builtin;	\
 #define TRAMPOLINE_SIZE (TARGET_LARGE_MEM ? 20 : 16)
 
 #define TRAMPOLINE_ALIGNMENT 128
-
-#define INITIALIZE_TRAMPOLINE(TRAMP,FNADDR,CXT) \
-	  spu_initialize_trampoline(TRAMP,FNADDR,CXT)
-
 \f
 /* Addressing Modes */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 32/36][stormy16] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (29 preceding siblings ...)
  2009-09-21 23:26 ` [patch 31/36][spu] " Richard Henderson
@ 2009-09-21 23:27 ` Richard Henderson
  2009-09-21 23:30 ` [patch 33/36][v850] " Richard Henderson
                   ` (3 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:27 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-32-stormy --]
[-- Type: text/plain, Size: 3447 bytes --]

	* config/stormy16/stormy16.c (xstormy16_trampoline_init): Rename
	from xstormy16_initialize_trampoline; make static; update for
	hook parameters.
	(TARGET_TRAMPOLINE_INIT): New.
	* config/stormy16/stormy16.h (INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index 1c076b2..03e716f 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -1456,34 +1456,36 @@ xstormy16_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
   return build_va_arg_indirect_ref (addr);
 }
 
-/* Initialize the variable parts of a trampoline.  ADDR is an RTX for
-   the address of the trampoline; FNADDR is an RTX for the address of
-   the nested function; STATIC_CHAIN is an RTX for the static chain
-   value that should be passed to the function when it is called.  */
+/* Worker function for TARGET_TRAMPOLINE_INIT.  */
 
-void
-xstormy16_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
+static void
+xstormy16_trampoline_init (rtx m_tramp, tree fndecl, rtx static_chain)
 {
-  rtx reg_addr = gen_reg_rtx (Pmode);
   rtx temp = gen_reg_rtx (HImode);
   rtx reg_fnaddr = gen_reg_rtx (HImode);
-  rtx reg_addr_mem;
+  rtx reg_addr, reg_addr_mem;
 
-  reg_addr_mem = gen_rtx_MEM (HImode, reg_addr);
+  reg_addr = copy_to_reg (XEXP (m_tramp, 0));
+  reg_addr_mem = adjust_automodify_address (m_tramp, HImode, reg_addr, 0);
 
-  emit_move_insn (reg_addr, addr);
   emit_move_insn (temp, GEN_INT (0x3130 | STATIC_CHAIN_REGNUM));
   emit_move_insn (reg_addr_mem, temp);
   emit_insn (gen_addhi3 (reg_addr, reg_addr, const2_rtx));
+  reg_addr_mem = adjust_automodify_address (reg_addr_mem, VOIDmode, NULL, 2);
+
   emit_move_insn (temp, static_chain);
   emit_move_insn (reg_addr_mem, temp);
   emit_insn (gen_addhi3 (reg_addr, reg_addr, const2_rtx));
-  emit_move_insn (reg_fnaddr, fnaddr);
+  reg_addr_mem = adjust_automodify_address (reg_addr_mem, VOIDmode, NULL, 2);
+
+  emit_move_insn (reg_fnaddr, XEXP (DECL_RTL (fndecl), 0));
   emit_move_insn (temp, reg_fnaddr);
   emit_insn (gen_andhi3 (temp, temp, GEN_INT (0xFF)));
   emit_insn (gen_iorhi3 (temp, temp, GEN_INT (0x0200)));
   emit_move_insn (reg_addr_mem, temp);
   emit_insn (gen_addhi3 (reg_addr, reg_addr, const2_rtx));
+  reg_addr_mem = adjust_automodify_address (reg_addr_mem, VOIDmode, NULL, 2);
+
   emit_insn (gen_lshrhi3 (reg_fnaddr, reg_fnaddr, GEN_INT (8)));
   emit_move_insn (reg_addr_mem, reg_fnaddr);
 }
@@ -2667,6 +2669,9 @@ xstormy16_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE xstormy16_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT xstormy16_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-stormy16.h"
diff --git a/gcc/config/stormy16/stormy16.h b/gcc/config/stormy16/stormy16.h
index 49505b5..682f7e6 100644
--- a/gcc/config/stormy16/stormy16.h
+++ b/gcc/config/stormy16/stormy16.h
@@ -454,12 +454,7 @@ enum reg_class
 /* Trampolines for Nested Functions.  */
 
 #define TRAMPOLINE_SIZE 8
-
 #define TRAMPOLINE_ALIGNMENT 16
-
-#define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, STATIC_CHAIN) \
-  xstormy16_initialize_trampoline (ADDR, FNADDR, STATIC_CHAIN)
-
 \f
 /* Define this macro to override the type used by the library routines to pick
    up arguments of type `float'.  (By default, they use a union of `float' and

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 33/36][v850] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (30 preceding siblings ...)
  2009-09-21 23:27 ` [patch 32/36][stormy16] " Richard Henderson
@ 2009-09-21 23:30 ` Richard Henderson
  2009-09-21 23:31 ` [patch 34/36][vax] " Richard Henderson
                   ` (2 subsequent siblings)
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:30 UTC (permalink / raw)
  To: GCC Patches; +Cc: nickc

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-33-v850 --]
[-- Type: text/plain, Size: 3925 bytes --]

	* config/v850/v850.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(v850_can_eliminate): Make static.
	(v850_asm_trampoline_template, v850_trampoline_init): New.
	* config/v850/v850.h (TRAMPOLINE_TEMPLATE): Move code to
	v850_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to v850_trampoline_init
	and adjust for target hook parameters.


diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c
index 19268e2..8e1f27b 100644
--- a/gcc/config/v850/v850.c
+++ b/gcc/config/v850/v850.c
@@ -73,6 +73,8 @@ static bool v850_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 static int v850_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
 				   tree, bool);
 static bool v850_can_eliminate       (const int, const int);
+static void v850_asm_trampoline_template (FILE *);
+static void v850_trampoline_init (rtx, tree, rtx);
 
 /* Information about the various small memory areas.  */
 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
@@ -177,6 +179,11 @@ static const struct attribute_spec v850_attribute_table[] =
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE v850_can_eliminate
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE v850_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT v850_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Set the maximum size of small memory area TYPE to the value given
@@ -2963,10 +2970,41 @@ v850_setup_incoming_varargs (CUMULATIVE_ARGS *ca,
 
 /* Worker function for TARGET_CAN_ELIMINATE.  */
 
-bool
+static bool
 v850_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
 {
   return (to == STACK_POINTER_REGNUM ? ! frame_pointer_needed : true);
 }
 
+\f
+/* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE.  */
+
+static void
+v850_asm_trampoline_template (FILE *f)
+{
+  fprintf (f, "\tjarl .+4,r12\n");
+  fprintf (f, "\tld.w 12[r12],r20\n");
+  fprintf (f, "\tld.w 16[r12],r12\n");
+  fprintf (f, "\tjmp [r12]\n");
+  fprintf (f, "\tnop\n");
+  fprintf (f, "\t.long 0\n");
+  fprintf (f, "\t.long 0\n");
+}
+
+/* Worker function for TARGET_TRAMPOLINE_INIT.  */
+
+static void
+v850_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx mem, fnaddr = XEXP (DECL_RTL (fndecl), 0);
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, SImode, 16);
+  emit_move_insn (mem, chain_value);
+  mem = adjust_address (m_tramp, SImode, 20);
+  emit_move_insn (mem, fnaddr);
+}
+\f
 #include "gt-v850.h"
diff --git a/gcc/config/v850/v850.h b/gcc/config/v850/v850.h
index 026a229..1a4ca74 100644
--- a/gcc/config/v850/v850.h
+++ b/gcc/config/v850/v850.h
@@ -658,33 +658,10 @@ struct cum_arg { int nbytes; int anonymous_args; };
 
 #define FUNCTION_PROFILER(FILE, LABELNO) ;
 
-#define TRAMPOLINE_TEMPLATE(FILE)			\
-  do {							\
-    fprintf (FILE, "\tjarl .+4,r12\n");			\
-    fprintf (FILE, "\tld.w 12[r12],r20\n");		\
-    fprintf (FILE, "\tld.w 16[r12],r12\n");		\
-    fprintf (FILE, "\tjmp [r12]\n");			\
-    fprintf (FILE, "\tnop\n");				\
-    fprintf (FILE, "\t.long 0\n");			\
-    fprintf (FILE, "\t.long 0\n");			\
-  } while (0)
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE 24
 
-/* 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 (SImode, plus_constant ((TRAMP), 16)),	\
- 		 (CXT));						\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant ((TRAMP), 20)),	\
-		 (FNADDR));						\
-}
-
 /* Addressing modes, and classification of registers for them.  */
 
 \f

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 34/36][vax] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (31 preceding siblings ...)
  2009-09-21 23:30 ` [patch 33/36][v850] " Richard Henderson
@ 2009-09-21 23:31 ` Richard Henderson
  2009-09-21 23:35 ` [patch 35/36][xtensa] " Richard Henderson
  2009-09-21 23:41 ` [patch 36/36][i386] " Richard Henderson
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:31 UTC (permalink / raw)
  To: GCC Patches; +Cc: matt

[-- Attachment #1: Type: text/plain, Size: 162 bytes --]

A straight-forward conversion to hooks.

I suspect that the trampoline template could trivially be merged with 
the initializer, but I didn't bother to try.


r~

[-- Attachment #2: d-tramp-34-vax --]
[-- Type: text/plain, Size: 4879 bytes --]

	* config/vax/vax.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(vax_asm_trampoline_template, vax_trampoline_init): New.
	* config/vax/vax.h (TRAMPOLINE_TEMPLATE): Move code to
	vax_asm_trampoline_template.
	(INITIALIZE_TRAMPOLINE): Move code to vax_trampoline_init.


diff --git a/gcc/config/vax/vax.c b/gcc/config/vax/vax.c
index 4dfaa2e..d75d11f 100644
--- a/gcc/config/vax/vax.c
+++ b/gcc/config/vax/vax.c
@@ -57,6 +57,8 @@ static int vax_address_cost (rtx, bool);
 static bool vax_rtx_costs (rtx, int, int, int *, bool);
 static rtx vax_struct_value_rtx (tree, int);
 static rtx vax_builtin_setjmp_frame_value (void);
+static void vax_asm_trampoline_template (FILE *);
+static void vax_trampoline_init (rtx, tree, rtx);
 \f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
@@ -101,6 +103,11 @@ static rtx vax_builtin_setjmp_frame_value (void);
 #undef TARGET_FRAME_POINTER_REQUIRED
 #define TARGET_FRAME_POINTER_REQUIRED hook_bool_void_true
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE vax_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT vax_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 \f
 /* Set global variables as needed for the options enabled.  */
@@ -2020,3 +2027,45 @@ adjacent_operands_p (rtx lo, rtx hi, enum machine_mode mode)
   return rtx_equal_p (lo, hi)
 	 && hi_offset - lo_offset == GET_MODE_SIZE (mode);
 }
+
+/* Output assembler code for a block containing the constant parts
+   of a trampoline, leaving space for the variable parts.  */
+
+/* On the VAX, the trampoline contains an entry mask and two instructions:
+     .word NN
+     movl $STATIC,r0   (store the functions static chain)
+     jmp  *$FUNCTION   (jump to function code at address FUNCTION)  */
+
+static void
+vax_asm_trampoline_template (FILE *f ATTRIBUTE_UNUSED)
+{
+  assemble_aligned_integer (2, const0_rtx);
+  assemble_aligned_integer (2, GEN_INT (0x8fd0));
+  assemble_aligned_integer (4, const0_rtx);
+  assemble_aligned_integer (1, GEN_INT (0x50 + STATIC_CHAIN_REGNUM));
+  assemble_aligned_integer (2, GEN_INT (0x9f17));
+  assemble_aligned_integer (4, const0_rtx);
+}
+
+/* We copy the register-mask from the function's pure code
+   to the start of the trampoline.  */
+
+static void
+vax_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  mem = adjust_address (m_tramp, HImode, 0);
+  emit_move_insn (mem, gen_const_mem (HImode, fnaddr));
+
+  mem = adjust_address (m_tramp, SImode, 4);
+  emit_move_insn (mem, cxt);
+  mem = adjust_address (m_tramp, SImode, 11);
+  emit_move_insn (mem, plus_constant (fnaddr, 2));
+  emit_insn (gen_sync_istream ());
+}
+
diff --git a/gcc/config/vax/vax.h b/gcc/config/vax/vax.h
index 0ac7ba5..e85ce01 100644
--- a/gcc/config/vax/vax.h
+++ b/gcc/config/vax/vax.h
@@ -428,44 +428,10 @@ enum reg_class { NO_REGS, ALL_REGS, LIM_REG_CLASSES };
 
 #define INITIAL_FRAME_POINTER_OFFSET(DEPTH) (DEPTH) = 0;
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.  */
-
-/* On the VAX, the trampoline contains an entry mask and two instructions:
-     .word NN
-     movl $STATIC,r0   (store the functions static chain)
-     jmp  *$FUNCTION   (jump to function code at address FUNCTION)  */
-
-#define TRAMPOLINE_TEMPLATE(FILE)					\
-{									\
-  assemble_aligned_integer (2, const0_rtx);				\
-  assemble_aligned_integer (2, GEN_INT (0x8fd0));			\
-  assemble_aligned_integer (4, const0_rtx);				\
-  assemble_aligned_integer (1, GEN_INT (0x50 + STATIC_CHAIN_REGNUM));	\
-  assemble_aligned_integer (2, GEN_INT (0x9f17));			\
-  assemble_aligned_integer (4, const0_rtx);				\
-}
-
 /* Length in units of the trampoline for entering a nested function.  */
 
 #define TRAMPOLINE_SIZE 15
 
-/* 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.  */
-
-/* We copy the register-mask from the function's pure code
-   to the start of the trampoline.  */
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (HImode, TRAMP),				\
-		  gen_rtx_MEM (HImode, FNADDR));			\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 4)), CXT);	\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 11)),	\
-		  plus_constant (FNADDR, 2));				\
-  emit_insn (gen_sync_istream ());					\
-}
-
 /* Byte offset of return address in a stack frame.  The "saved PC" field
    is in element [4] when treating the frame as an array of longwords.  */
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 35/36][xtensa] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (32 preceding siblings ...)
  2009-09-21 23:31 ` [patch 34/36][vax] " Richard Henderson
@ 2009-09-21 23:35 ` Richard Henderson
  2009-09-21 23:41 ` [patch 36/36][i386] " Richard Henderson
  34 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:35 UTC (permalink / raw)
  To: GCC Patches; +Cc: bob.wilson

[-- Attachment #1: Type: text/plain, Size: 45 bytes --]

A straight-forward conversion to hooks.


r~

[-- Attachment #2: d-tramp-35-xtensa --]
[-- Type: text/plain, Size: 4785 bytes --]

	* config/xtensa/xtensa.c (TARGET_ASM_TRAMPOLINE_TEMPLATE): New.
	(TARGET_TRAMPOLINE_INIT): New.
	(xtensa_asm_trampoline_template): Rename from
	xtensa_trampoline_template; make static.
	(xtensa_trampoline_init): Rename from xtensa_initialize_trampoline;
	make static; update for hook parameters.
	* config/xtensa/xtensa-protos.h: Remove trampoline decls.
	* config/xtensa/xtensa.h (TRAMPOLINE_TEMPLATE): Remove.
	(INITIALIZE_TRAMPOLINE): Remove.


diff --git a/gcc/config/xtensa/xtensa-protos.h b/gcc/config/xtensa/xtensa-protos.h
index 73176f6..6bd1e56 100644
--- a/gcc/config/xtensa/xtensa-protos.h
+++ b/gcc/config/xtensa/xtensa-protos.h
@@ -70,7 +70,6 @@ struct secondary_reload_info;
 extern enum reg_class xtensa_secondary_reload (bool, rtx, enum reg_class,
 					       enum machine_mode,
 					       struct secondary_reload_info *);
-extern void xtensa_initialize_trampoline (rtx, rtx, rtx);
 #endif /* RTX_CODE */
 
 #ifdef TREE_CODE
@@ -86,6 +85,5 @@ extern void override_options (void);
 extern long compute_frame_size (int);
 extern void xtensa_expand_prologue (void);
 extern void order_regs_for_local_alloc (void);
-extern void xtensa_trampoline_template (FILE *);
 
 #endif /* !__XTENSA_PROTOS_H__ */
diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
index 77ba2d9..0264868 100644
--- a/gcc/config/xtensa/xtensa.c
+++ b/gcc/config/xtensa/xtensa.c
@@ -146,6 +146,8 @@ static tree xtensa_fold_builtin (tree, tree, bool);
 static rtx xtensa_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
 static void xtensa_va_start (tree, rtx);
 static bool xtensa_frame_pointer_required (void);
+static void xtensa_asm_trampoline_template (FILE *);
+static void xtensa_trampoline_init (rtx, tree, rtx);
 
 static const int reg_nonleaf_alloc_order[FIRST_PSEUDO_REGISTER] =
   REG_ALLOC_ORDER;
@@ -229,6 +231,11 @@ static const int reg_nonleaf_alloc_order[FIRST_PSEUDO_REGISTER] =
 #undef TARGET_FRAME_POINTER_REQUIRED
 #define TARGET_FRAME_POINTER_REQUIRED xtensa_frame_pointer_required
 
+#undef TARGET_ASM_TRAMPOLINE_TEMPLATE
+#define TARGET_ASM_TRAMPOLINE_TEMPLATE xtensa_asm_trampoline_template
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT xtensa_trampoline_init
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 \f
@@ -3435,8 +3442,8 @@ xtensa_function_value (const_tree valtype, const_tree func ATTRIBUTE_UNUSED,
    control to the instruction following the ENTRY at the target.  Note:
    this assumes that the target begins with an ENTRY instruction.  */
 
-void
-xtensa_trampoline_template (FILE *stream)
+static void
+xtensa_asm_trampoline_template (FILE *stream)
 {
   bool use_call0 = (TARGET_CONST16 || TARGET_ABSOLUTE_LITERALS);
 
@@ -3503,17 +3510,21 @@ xtensa_trampoline_template (FILE *stream)
   fprintf (stream, "\t.end no-transform\n");
 }
 
-
-void
-xtensa_initialize_trampoline (rtx addr, rtx func, rtx chain)
+static void
+xtensa_trampoline_init (rtx m_tramp, tree fndecl, rtx chain)
 {
+  rtx func = XEXP (DECL_RTL (fndecl), 0);
   bool use_call0 = (TARGET_CONST16 || TARGET_ABSOLUTE_LITERALS);
   int chain_off = use_call0 ? 12 : 8;
   int func_off = use_call0 ? 16 : 12;
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, chain_off)), chain);
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (addr, func_off)), func);
+
+  emit_block_move (m_tramp, assemble_trampoline_template (),
+		   GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
+
+  emit_move_insn (adjust_address (m_tramp, SImode, chain_off), chain);
+  emit_move_insn (adjust_address (m_tramp, SImode, func_off), func);
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__xtensa_sync_caches"),
-		     0, VOIDmode, 1, addr, Pmode);
+		     0, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
 }
 
 
diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 84d320b..4fefbfd 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -677,8 +677,6 @@ typedef struct xtensa_args
 /* Stack pointer value doesn't matter at exit.  */
 #define EXIT_IGNORE_STACK 1
 
-#define TRAMPOLINE_TEMPLATE(STREAM) xtensa_trampoline_template (STREAM)
-
 /* Size in bytes of the trampoline, as an integer.  Make sure this is
    a multiple of TRAMPOLINE_ALIGNMENT to avoid -Wpadded warnings.  */
 #define TRAMPOLINE_SIZE (TARGET_CONST16 || TARGET_ABSOLUTE_LITERALS ? 60 : 52)
@@ -686,11 +684,6 @@ typedef struct xtensa_args
 /* Alignment required for trampolines, in bits.  */
 #define TRAMPOLINE_ALIGNMENT 32
 
-/* A C statement to initialize the variable parts of a trampoline.  */
-#define INITIALIZE_TRAMPOLINE(ADDR, FUNC, CHAIN)			\
-  xtensa_initialize_trampoline (ADDR, FUNC, CHAIN)
-
-
 /* If defined, a C expression that produces the machine-specific code
    to setup the stack so that arbitrary frames can be accessed.
 

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [patch 36/36][i386] Hookize static chain and trampoline macros
  2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
                   ` (33 preceding siblings ...)
  2009-09-21 23:35 ` [patch 35/36][xtensa] " Richard Henderson
@ 2009-09-21 23:41 ` Richard Henderson
  2009-09-23  0:37   ` H.J. Lu
  34 siblings, 1 reply; 58+ messages in thread
From: Richard Henderson @ 2009-09-21 23:41 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 525 bytes --]

Finally, the reason for this entire patch series, and the fix for PR41240.

In addition to hook-izing the i386 backend, I also fill in the 
TARGET_STATIC_CHAIN hook with a function that examines what register, if 
any, the calling convention specified for this function leaves 
available.  For fastcall, we use EAX.  For regparm=3, we arrange for the 
trampoline to push the static chain onto the stack.  This requires a few 
adjustments to the prologue and epilogue code to manipulate the stack 
offsets appropriately.


r~

[-- Attachment #2: d-tramp-36-i386 --]
[-- Type: text/plain, Size: 21785 bytes --]

	* config/i386/i386.c (ix86_function_regparm): Do not issue an
	error for nested functions with regparm=3.
	(ix86_compute_frame_layout): Adjust frame pointer offset for
	ix86_static_chain_on_stack.
	(ix86_expand_prologue): Handle ix86_static_chain_on_stack.
	(ix86_emit_restore_reg_using_pop): Increment ix86_cfa_state->offset,
	don't reset to UNITS_PER_WORD.
	(ix86_emit_leave): Adjust ix86_cfa_state.
	(ix86_expand_epilogue): Handle ix86_static_chain_on_stack.
	(ix86_static_chain): New.
	(ix86_trampoline_init): Rename from x86_initialize_trampoline;
	make static; update for target hook parameters; use ix86_static_chain.
	(TARGET_STATIC_CHAIN, TARGET_TRAMPOLINE_INIT): New.
	* config/i386/i386.h (STATIC_CHAIN_REGNUM): Remove.
	(INITIALIZE_TRAMPOLINE): Remove.
	(TRAMPOLINE_SIZE): Use 24 for 64-bit.
	(struct machine_function): Use BOOL_BITFIELD; rearrange bitfields
	to the end.  Add static_chain_on_stack.
	(ix86_static_chain_on_stack): New.


diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 335a526..bda1c5f 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1879,6 +1879,7 @@ static bool ext_80387_constants_init = 0;
 \f
 static struct machine_function * ix86_init_machine_status (void);
 static rtx ix86_function_value (const_tree, const_tree, bool);
+static rtx ix86_static_chain (const_tree, bool);
 static int ix86_function_regparm (const_tree, const_tree);
 static void ix86_compute_frame_layout (struct ix86_frame *);
 static bool ix86_expand_vector_init_one_nonzero (bool, enum machine_mode,
@@ -4472,8 +4473,6 @@ ix86_function_regparm (const_tree type, const_tree decl)
   tree attr;
   int regparm;
 
-  static bool error_issued;
-
   if (TARGET_64BIT)
     return (ix86_function_type_abi (type) == SYSV_ABI
 	    ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
@@ -4482,23 +4481,7 @@ ix86_function_regparm (const_tree type, const_tree decl)
   attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
   if (attr)
     {
-      regparm
-	= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
-
-      if (decl && TREE_CODE (decl) == FUNCTION_DECL)
-	{
-	  /* We can't use regparm(3) for nested functions because
-	     these pass static chain pointer in %ecx register.  */
-	  if (!error_issued && regparm == 3
-	      && decl_function_context (decl)
-	      && !DECL_NO_STATIC_CHAIN (decl))
-	    {
-	      error ("nested functions are limited to 2 register parameters");
-	      error_issued = true;
-	      return 0;
-	    }
-	}
-
+      regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
       return regparm;
     }
 
@@ -4512,7 +4495,7 @@ ix86_function_regparm (const_tree type, const_tree decl)
       && !profile_flag)
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
-      struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
+      struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE (decl));
       if (i && i->local)
 	{
 	  int local_regparm, globals = 0, regno;
@@ -4523,8 +4506,8 @@ ix86_function_regparm (const_tree type, const_tree decl)
 	    if (fixed_regs[local_regparm])
 	      break;
 
-	  /* We can't use regparm(3) for nested functions as these use
-	     static chain pointer in third argument.  */
+	  /* We don't want to use regparm(3) for nested functions as
+	     these use a static chain pointer in the third argument.  */
 	  if (local_regparm == 3
 	      && decl_function_context (decl)
 	      && !DECL_NO_STATIC_CHAIN (decl))
@@ -7873,9 +7856,16 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
   else
     frame->save_regs_using_mov = false;
 
+  /* Skip return address.  */
+  offset = UNITS_PER_WORD;
 
-  /* Skip return address and saved base pointer.  */
-  offset = frame_pointer_needed ? UNITS_PER_WORD * 2 : UNITS_PER_WORD;
+  /* Skip pushed static chain.  */
+  if (ix86_static_chain_on_stack)
+    offset += UNITS_PER_WORD;
+
+  /* Skip saved base pointer.  */
+  if (frame_pointer_needed)
+    offset += UNITS_PER_WORD;
 
   frame->hard_frame_pointer_offset = offset;
 
@@ -8297,20 +8287,42 @@ ix86_expand_prologue (void)
 
   ix86_compute_frame_layout (&frame);
 
+  /* The first insn of a function that accepts its static chain on the
+     stack is to push the register that would be filled in by a direct
+     call.  This insn will be skipped by the trampoline.  */
+  if (ix86_static_chain_on_stack)
+    {
+      rtx t;
+
+      insn = emit_insn (gen_push (ix86_static_chain (cfun->decl, false)));
+      emit_insn (gen_blockage ());
+
+      /* We don't want to interpret this push insn as a register save,
+	 only as a stack adjustment.  The real copy of the register as
+	 a save will be done later, if needed.  */
+      t = plus_constant (stack_pointer_rtx, -UNITS_PER_WORD);
+      t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
+      add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
+      RTX_FRAME_RELATED_P (insn) = 1;
+    }
+
   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
      of DRAP is needed and stack realignment is really needed after reload */
   if (crtl->drap_reg && crtl->stack_realign_needed)
     {
       rtx x, y;
       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
-      int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
-			      ? 0 : UNITS_PER_WORD);
+      int param_ptr_offset = UNITS_PER_WORD;
+
+      if (ix86_static_chain_on_stack)
+	param_ptr_offset += UNITS_PER_WORD;
+      if (!call_used_regs[REGNO (crtl->drap_reg)])
+	param_ptr_offset += UNITS_PER_WORD;
 
       gcc_assert (stack_realign_drap);
 
       /* Grab the argument pointer.  */
-      x = plus_constant (stack_pointer_rtx, 
-                         (UNITS_PER_WORD + param_ptr_offset));
+      x = plus_constant (stack_pointer_rtx, param_ptr_offset);
       y = crtl->drap_reg;
 
       /* Only need to push parameter pointer reg if it is caller
@@ -8519,14 +8531,18 @@ ix86_expand_prologue (void)
       /* vDRAP is setup but after reload it turns out stack realign
          isn't necessary, here we will emit prologue to setup DRAP
          without stack realign adjustment */
+      rtx x;
       int drap_bp_offset = UNITS_PER_WORD * 2;
-      rtx x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
+
+      if (ix86_static_chain_on_stack)
+	drap_bp_offset += UNITS_PER_WORD;
+      x = plus_constant (hard_frame_pointer_rtx, drap_bp_offset);
       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, x));
     }
 
   /* Prevent instructions from being scheduled into register save push
      sequence when access to the redzone area is done through frame pointer.
-     The offset betweeh the frame pointer and the stack pointer is calculated
+     The offset between the frame pointer and the stack pointer is calculated
      relative to the value of the stack pointer at the end of the function
      prologue, and moving instructions that access redzone area via frame
      pointer inside push sequence violates this assumption.  */
@@ -8575,11 +8591,11 @@ ix86_emit_restore_reg_using_pop (rtx reg, HOST_WIDE_INT red_offset)
 	   && reg == hard_frame_pointer_rtx)
     {
       ix86_cfa_state->reg = stack_pointer_rtx;
-      ix86_cfa_state->offset = UNITS_PER_WORD;
+      ix86_cfa_state->offset -= UNITS_PER_WORD;
 
       add_reg_note (insn, REG_CFA_DEF_CFA,
 		    gen_rtx_PLUS (Pmode, stack_pointer_rtx,
-				  GEN_INT (UNITS_PER_WORD)));
+				  GEN_INT (ix86_cfa_state->offset)));
       RTX_FRAME_RELATED_P (insn) = 1;
     }
 
@@ -8613,6 +8629,9 @@ ix86_emit_leave (HOST_WIDE_INT red_offset)
 
   if (ix86_cfa_state->reg == hard_frame_pointer_rtx)
     {
+      ix86_cfa_state->reg = stack_pointer_rtx;
+      ix86_cfa_state->offset -= UNITS_PER_WORD;
+
       add_reg_note (insn, REG_CFA_ADJUST_CFA, 
 		    copy_rtx (XVECEXP (PATTERN (insn), 0, 0)));
       RTX_FRAME_RELATED_P (insn) = 1;
@@ -8757,6 +8776,8 @@ ix86_expand_epilogue (int style)
   else if (stack_realign_fp)
     red_offset -= crtl->stack_alignment_needed / BITS_PER_UNIT
 		  - UNITS_PER_WORD;
+  if (ix86_static_chain_on_stack)
+    red_offset -= UNITS_PER_WORD;
   if (frame_pointer_needed)
     red_offset -= UNITS_PER_WORD;
 
@@ -8829,6 +8850,8 @@ ix86_expand_epilogue (int style)
 
 	  /* Stack align doesn't work with eh_return.  */
 	  gcc_assert (!crtl->stack_realign_needed);
+	  /* Neither does regparm nested functions.  */
+	  gcc_assert (!ix86_static_chain_on_stack);
 
 	  if (frame_pointer_needed)
 	    {
@@ -8961,29 +8984,50 @@ ix86_expand_epilogue (int style)
 
   if (using_drap)
     {
-      int param_ptr_offset = (call_used_regs[REGNO (crtl->drap_reg)]
-			      ? 0 : UNITS_PER_WORD);
+      int param_ptr_offset = UNITS_PER_WORD;
       rtx insn;
 
       gcc_assert (stack_realign_drap);
 
+      if (ix86_static_chain_on_stack)
+	param_ptr_offset += UNITS_PER_WORD;
+      if (!call_used_regs[REGNO (crtl->drap_reg)])
+	param_ptr_offset += UNITS_PER_WORD;
+
       insn = emit_insn ((*ix86_gen_add3) (stack_pointer_rtx,
 					  crtl->drap_reg,
-					  GEN_INT (-(UNITS_PER_WORD
-						     + param_ptr_offset))));
+					  GEN_INT (-param_ptr_offset)));
 
       ix86_cfa_state->reg = stack_pointer_rtx;
-      ix86_cfa_state->offset = UNITS_PER_WORD + param_ptr_offset;
+      ix86_cfa_state->offset = param_ptr_offset;
 
       add_reg_note (insn, REG_CFA_DEF_CFA,
 		    gen_rtx_PLUS (Pmode, ix86_cfa_state->reg,
 				  GEN_INT (ix86_cfa_state->offset)));
       RTX_FRAME_RELATED_P (insn) = 1;
 
-      if (param_ptr_offset)
+      if (!call_used_regs[REGNO (crtl->drap_reg)])
 	ix86_emit_restore_reg_using_pop (crtl->drap_reg, -UNITS_PER_WORD);
     }
 
+  /* Remove the saved static chain from the stack.  The use of ECX is
+     merely as a scratch register, not as the actual static chain.  */
+  if (ix86_static_chain_on_stack)
+    {
+      rtx r, insn;
+
+      gcc_assert (ix86_cfa_state->reg == stack_pointer_rtx);
+      ix86_cfa_state->offset += UNITS_PER_WORD;
+    
+      r = gen_rtx_REG (Pmode, CX_REG);
+      insn = emit_insn (ix86_gen_pop1 (r));
+
+      r = plus_constant (stack_pointer_rtx, UNITS_PER_WORD);
+      r = gen_rtx_SET (VOIDmode, stack_pointer_rtx, r);
+      add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
+      RTX_FRAME_RELATED_P (insn) = 1;
+    }
+
   /* Sibcall epilogues don't want a return instruction.  */
   if (style == 0)
     {
@@ -19759,66 +19803,162 @@ ix86_minimum_alignment (tree exp, enum machine_mode mode,
   return align;
 }
 \f
+/* Find a location for the static chain incoming to a nested function.
+   This is a register, unless all free registers are used by arguments.  */
+
+static rtx
+ix86_static_chain (const_tree fndecl, bool incoming_p)
+{
+  unsigned regno;
+
+  if (DECL_NO_STATIC_CHAIN (fndecl))
+    return NULL;
+
+  if (TARGET_64BIT)
+    {
+      /* We always use R10 in 64-bit mode.  */
+      regno = R10_REG;
+    }
+  else
+    {
+      tree fntype;
+      /* By default in 32-bit mode we use ECX to pass the static chain.  */
+      regno = CX_REG;
+
+      fntype = TREE_TYPE (fndecl);
+      if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)))
+	{
+	  /* Fastcall functions use ecx/edx for arguments, which leaves
+	     us with EAX for the static chain.  */
+	  regno = AX_REG;
+	}
+      else if (ix86_function_regparm (fntype, fndecl) == 3)
+	{
+	  /* For regparm 3, we have no free call-clobbered registers in
+	     which to store the static chain.  In order to implement this,
+	     we have the trampoline push the static chain to the stack.
+	     However, we can't push a value below the return address when
+	     we call the nested function directly, so we have to use an
+	     alternate entry point.  For this we use ESI, and have the
+	     alternate entry point push ESI, so that things appear the
+	     same once we're executing the nested function.  */
+	  if (incoming_p)
+	    {
+	      if (fndecl == current_function_decl)
+		ix86_static_chain_on_stack = true;
+	      return gen_frame_mem (SImode,
+				    plus_constant (arg_pointer_rtx, -8));
+	    }
+	  regno = SI_REG;
+	}
+    }
+
+  return gen_rtx_REG (Pmode, regno);
+}
+
 /* 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.  */
-void
-x86_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt)
+   FNDECL is the decl of the target address; M_TRAMP is a MEM for 
+   the trampoline, and CHAIN_VALUE is an RTX for the static chain
+   to be passed to the target function.  */
+
+static void
+ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
 {
+  rtx mem, fnaddr;
+
+  fnaddr = XEXP (DECL_RTL (fndecl), 0);
+
   if (!TARGET_64BIT)
     {
-      /* Compute offset from the end of the jmp to the target function.  */
-      rtx disp = expand_binop (SImode, sub_optab, fnaddr,
-			       plus_constant (tramp, 10),
-			       NULL_RTX, 1, OPTAB_DIRECT);
-      emit_move_insn (gen_rtx_MEM (QImode, tramp),
-		      gen_int_mode (0xb9, QImode));
-      emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 1)), cxt);
-      emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, 5)),
-		      gen_int_mode (0xe9, QImode));
-      emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, 6)), disp);
+      rtx disp, chain;
+      int opcode;
+
+      /* Depending on the static chain location, either load a register
+	 with a constant, or push the constant to the stack.  All of the
+	 instructions are the same size.  */
+      chain = ix86_static_chain (fndecl, true);
+      if (REG_P (chain))
+	{
+	  if (REGNO (chain) == CX_REG)
+	    opcode = 0xb9;
+	  else if (REGNO (chain) == AX_REG)
+	    opcode = 0xb8;
+	  else
+	    gcc_unreachable ();
+	}
+      else
+	opcode = 0x68;
+
+      mem = adjust_address (m_tramp, QImode, 0);
+      emit_move_insn (mem, gen_int_mode (opcode, QImode));
+
+      mem = adjust_address (m_tramp, SImode, 1);
+      emit_move_insn (mem, chain_value);
+
+      /* Compute offset from the end of the jmp to the target function.
+	 In the case in which the trampoline stores the static chain on
+	 the stack, we need to skip the first insn which pushes the
+	 (call-saved) register static chain; this push is 1 byte.  */
+      disp = expand_binop (SImode, sub_optab, fnaddr,
+			   plus_constant (XEXP (m_tramp, 0),
+					  MEM_P (chain) ? 9 : 10),
+			   NULL_RTX, 1, OPTAB_DIRECT);
+
+      mem = adjust_address (m_tramp, QImode, 5);
+      emit_move_insn (mem, gen_int_mode (0xe9, QImode));
+
+      mem = adjust_address (m_tramp, SImode, 6);
+      emit_move_insn (mem, disp);
     }
   else
     {
       int offset = 0;
-      /* Try to load address using shorter movl instead of movabs.
-         We may want to support movq for kernel mode, but kernel does not use
-         trampolines at the moment.  */
+
+      /* Load the function address to r11.  Try to load address using
+	 the shorter movl instead of movabs.  We may want to support
+	 movq for kernel mode, but kernel does not use trampolines at
+	 the moment.  */
       if (x86_64_zext_immediate_operand (fnaddr, VOIDmode))
 	{
 	  fnaddr = copy_to_mode_reg (DImode, fnaddr);
-	  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
-			  gen_int_mode (0xbb41, HImode));
-	  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (tramp, offset + 2)),
-			  gen_lowpart (SImode, fnaddr));
+
+	  mem = adjust_address (m_tramp, HImode, offset);
+	  emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
+
+	  mem = adjust_address (m_tramp, SImode, offset + 2);
+	  emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
 	  offset += 6;
 	}
       else
 	{
-	  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
-			  gen_int_mode (0xbb49, HImode));
-	  emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
-			  fnaddr);
+	  mem = adjust_address (m_tramp, HImode, offset);
+	  emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
+
+	  mem = adjust_address (m_tramp, DImode, offset + 2);
+	  emit_move_insn (mem, fnaddr);
 	  offset += 10;
 	}
+
       /* Load static chain using movabs to r10.  */
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
-		      gen_int_mode (0xba49, HImode));
-      emit_move_insn (gen_rtx_MEM (DImode, plus_constant (tramp, offset + 2)),
-		      cxt);
+      mem = adjust_address (m_tramp, HImode, offset);
+      emit_move_insn (mem, gen_int_mode (0xba49, HImode));
+
+      mem = adjust_address (m_tramp, DImode, offset + 2);
+      emit_move_insn (mem, chain_value);
       offset += 10;
-      /* Jump to the r11 */
-      emit_move_insn (gen_rtx_MEM (HImode, plus_constant (tramp, offset)),
-		      gen_int_mode (0xff49, HImode));
-      emit_move_insn (gen_rtx_MEM (QImode, plus_constant (tramp, offset+2)),
-		      gen_int_mode (0xe3, QImode));
-      offset += 3;
+
+      /* Jump to r11; the last (unused) byte is a nop, only there to
+	 pad the write out to a single 32-bit store.  */
+      mem = adjust_address (m_tramp, SImode, offset);
+      emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
+      offset += 4;
+
       gcc_assert (offset <= TRAMPOLINE_SIZE);
     }
 
 #ifdef ENABLE_EXECUTE_STACK
   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
-		     LCT_NORMAL, VOIDmode, 1, tramp, Pmode);
+		     LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
 #endif
 }
 \f
@@ -29229,6 +29369,10 @@ ix86_enum_va_list (int idx, const char **pname, tree *ptree)
 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
 #undef TARGET_STRICT_ARGUMENT_NAMING
 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
+#undef TARGET_STATIC_CHAIN
+#define TARGET_STATIC_CHAIN ix86_static_chain
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
 
 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index e898a65..f825948 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1131,11 +1131,6 @@ enum target_cpu_default
 /* Base register for access to arguments of the function.  */
 #define ARG_POINTER_REGNUM 16
 
-/* Register in which static-chain is passed to a function.
-   We do use ECX as static chain register for 32 bit ABI.  On the
-   64bit ABI, ECX is an argument register, so we use R10 instead.  */
-#define STATIC_CHAIN_REGNUM (TARGET_64BIT ? R10_REG : CX_REG)
-
 /* Register to hold the addressing base for position independent
    code access to data items.  We don't use PIC pointer for 64bit
    mode.  Define the regnum to dummy value to prevent gcc from
@@ -1659,14 +1654,7 @@ typedef struct ix86_args {
 
 /* Length in units of the trampoline for entering a nested function.  */
 
-#define TRAMPOLINE_SIZE (TARGET_64BIT ? 23 : 10)
-
-/* 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) \
-  x86_initialize_trampoline ((TRAMP), (FNADDR), (CXT))
+#define TRAMPOLINE_SIZE (TARGET_64BIT ? 24 : 10)
 \f
 /* Definitions for register eliminations.
 
@@ -2365,15 +2353,29 @@ struct GTY(()) machine_function {
   const char *some_ld_name;
   int varargs_gpr_size;
   int varargs_fpr_size;
-  int accesses_prev_frame;
   int optimize_mode_switching[MAX_386_ENTITIES];
-  int needs_cld;
+
+  /* Number of saved registers USE_FAST_PROLOGUE_EPILOGUE
+     has been computed for.  */
+  int use_fast_prologue_epilogue_nregs;
+
+  /* The CFA state at the end of the prologue.  */
+  struct machine_cfa_state cfa;
+
+  /* This value is used for amd64 targets and specifies the current abi
+     to be used. MS_ABI means ms abi. Otherwise SYSV_ABI means sysv abi.  */
+  enum calling_abi call_abi;
+
+  /* Nonzero if the function accesses a previous frame.  */
+  BOOL_BITFIELD accesses_prev_frame : 1;
+
+  /* Nonzero if the function requires a CLD in the prologue.  */
+  BOOL_BITFIELD needs_cld : 1;
+
   /* Set by ix86_compute_frame_layout and used by prologue/epilogue
      expander to determine the style used.  */
-  int use_fast_prologue_epilogue;
-  /* Number of saved registers USE_FAST_PROLOGUE_EPILOGUE has been computed
-     for.  */
-  int use_fast_prologue_epilogue_nregs;
+  BOOL_BITFIELD use_fast_prologue_epilogue : 1;
+
   /* If true, the current function needs the default PIC register, not
      an alternate register (on x86) and must not use the red zone (on
      x86_64), even if it's a leaf function.  We don't want the
@@ -2383,11 +2385,11 @@ struct GTY(()) machine_function {
      if all such instructions are optimized away.  Use the
      ix86_current_function_calls_tls_descriptor macro for a better
      approximation.  */
-  int tls_descriptor_call_expanded_p;
-  /* This value is used for amd64 targets and specifies the current abi
-     to be used. MS_ABI means ms abi. Otherwise SYSV_ABI means sysv abi.  */
-  enum calling_abi call_abi;
-  struct machine_cfa_state cfa;
+  BOOL_BITFIELD tls_descriptor_call_expanded_p : 1;
+
+  /* If true, the current function has a STATIC_CHAIN is placed on the
+     stack below the return address.  */
+  BOOL_BITFIELD static_chain_on_stack : 1;
 };
 #endif
 
@@ -2406,6 +2408,7 @@ struct GTY(()) machine_function {
 #define ix86_current_function_calls_tls_descriptor \
   (ix86_tls_descriptor_calls_expanded_in_cfun && df_regs_ever_live_p (SP_REG))
 #define ix86_cfa_state (&cfun->machine->cfa)
+#define ix86_static_chain_on_stack (cfun->machine->static_chain_on_stack)
 
 /* Control behavior of x86_file_start.  */
 #define X86_FILE_START_VERSION_DIRECTIVE false

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 31/36][spu] Hookize static chain and trampoline macros
  2009-09-21 23:26 ` [patch 31/36][spu] " Richard Henderson
@ 2009-09-21 23:44   ` Andrew Pinski
  0 siblings, 0 replies; 58+ messages in thread
From: Andrew Pinski @ 2009-09-21 23:44 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches, edelsohn

On Mon, Sep 21, 2009 at 4:24 PM, Richard Henderson <rth@redhat.com> wrote:
> A straight-forward conversion to hooks.
>
> One thing that could probably have been separated out and changed en masse
> is const-ifying array_to_constant, and making any arrays feeding it static.
>  I did change the ones in spu_trampoline_init.


And yes this looks good.  Thanks for doing it.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 20/36][mmix] Hookize static chain and trampoline macros
  2009-09-21 23:01 ` [patch 20/36][mmix] " Richard Henderson
@ 2009-09-22  2:03   ` Hans-Peter Nilsson
  0 siblings, 0 replies; 58+ messages in thread
From: Hans-Peter Nilsson @ 2009-09-22  2:03 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On Mon, 21 Sep 2009, Richard Henderson wrote:
> Note that I removed the mmix_trampoline_size variable; there didn't seem to be
> any point to that.

I'm just blank.

>  I also added TRAMPOLINE_ALIGNMENT, which gets propagated
> into the MEM we create for the trampoline, which solves:
>
> -  /* FIXME: GCC copies this using *intsize* (tetra), when it should use
> -     register size (octa).  */

Whee.
Ok.

brgds, H-P

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 23/36][parisc] Hookize static chain and trampoline macros
  2009-09-21 23:08 ` [patch 23/36][parisc] " Richard Henderson
@ 2009-09-22  2:03   ` John David Anglin
  0 siblings, 0 replies; 58+ messages in thread
From: John David Anglin @ 2009-09-22  2:03 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches, dave.anglin

> A straight-forward conversion to hooks.

Untested but looks ok.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 26/36][rs6000] Hookize static chain and trampoline macros
  2009-09-21 23:14 ` [patch 26/36][rs6000] " Richard Henderson
@ 2009-09-22  2:16   ` David Edelsohn
  0 siblings, 0 replies; 58+ messages in thread
From: David Edelsohn @ 2009-09-22  2:16 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On Mon, Sep 21, 2009 at 7:13 PM, Richard Henderson <rth@redhat.com> wrote:
> A straight-forward conversion to hooks.

Thanks for converting all of the ports.  The rs6000 patch looks fine.

Thanks, David

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 07/36][cris] Hookize static chain and trampoline macros
  2009-09-21 22:29 ` [patch 07/36][cris] " Richard Henderson
@ 2009-09-22  2:31   ` Hans-Peter Nilsson
  0 siblings, 0 replies; 58+ messages in thread
From: Hans-Peter Nilsson @ 2009-09-22  2:31 UTC (permalink / raw)
  To: rth; +Cc: gcc-patches, hans-peter.nilsson

Ok.  Thanks for the i386 regparm=3 hint.

(As you may have noticed, there's a bug there, exposed by
e.g. gcc.dg/trampoline-1.c or anything that passes through the
same initialized trampoline twice or somehing like that.  But
since nobody uses trampolines...)

brgds, H-P

^ permalink raw reply	[flat|nested] 58+ messages in thread

* 答复: [patch 28/36][score] Hookize static chain and trampoline macros
  2009-09-21 23:21 ` [patch 28/36][score] " Richard Henderson
@ 2009-09-22 11:02   ` liqin
  2009-09-22 13:58     ` Richard Henderson
  2009-09-22 11:25   ` Paolo Bonzini
  1 sibling, 1 reply; 58+ messages in thread
From: liqin @ 2009-09-22 11:02 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

gcc-patches-owner@gcc.gnu.org 写于 2009-09-22 07:18:26:

> A less straight-forward conversion to hooks.
> 
> I'd like to complain about this port.  No other port doubles the amount 
> of effort required to support two differing cpu models.  This score3 vs 
> score7 thing is absolutely for the birds.
> 

score3 and score7 have different ISA,
they are 2 different CPU.

liqin

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 28/36][score] Hookize static chain and trampoline macros
  2009-09-21 23:21 ` [patch 28/36][score] " Richard Henderson
  2009-09-22 11:02   ` 答复: " liqin
@ 2009-09-22 11:25   ` Paolo Bonzini
  1 sibling, 0 replies; 58+ messages in thread
From: Paolo Bonzini @ 2009-09-22 11:25 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On 09/22/2009 01:18 AM, Richard Henderson wrote:
>
> I'd like to complain about this port.  No other port doubles the amount
> of effort required to support two differing cpu models.  This score3 vs
> score7 thing is absolutely for the birds.

This is more or less the same situation as SH vs. SHmedia (or ARM vs. 
Thumb2 for that matter...).

Paolo

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 30/36][sparc] Hookize static chain and trampoline macros
  2009-09-21 23:22 ` [patch 30/36][sparc] " Richard Henderson
@ 2009-09-22 13:09   ` Eric Botcazou
  0 siblings, 0 replies; 58+ messages in thread
From: Eric Botcazou @ 2009-09-22 13:09 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches, Jakub Jelinek

> A straight-forward conversion to hooks.

Thanks, looks OK to me.

-- 
Eric Botcazou

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: 答复: [patch 28/36][score] Hookize static chain and trampoline macros
  2009-09-22 11:02   ` 答复: " liqin
@ 2009-09-22 13:58     ` Richard Henderson
  0 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-22 13:58 UTC (permalink / raw)
  To: liqin; +Cc: GCC Patches

On 09/22/2009 03:37 AM, liqin@sunnorth.com.cn wrote:
> score3 and score7 have different ISA拢卢
> they are 2 different CPU.

They're not *that* different.

But you really should add yourself to the MAINTAINERS file
if you intend to support these cpus.


r~

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 27/36][s390] Hookize static chain and trampoline macros
  2009-09-21 23:16 ` [patch 27/36][s390] " Richard Henderson
@ 2009-09-22 14:55   ` Andreas Krebbel
  0 siblings, 0 replies; 58+ messages in thread
From: Andreas Krebbel @ 2009-09-22 14:55 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches, uweigand, Andreas.Krebbel

Richard Henderson wrote:
> A straight-forward conversion to hooks.

This is ok. Thanks!

Bye,

-Andreas-

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 16/36][m68k] Hookize static chain and trampoline macros
  2009-09-21 22:47 ` [patch 16/36][m68k] " Richard Henderson
@ 2009-09-22 15:53   ` Richard Henderson
  0 siblings, 0 replies; 58+ messages in thread
From: Richard Henderson @ 2009-09-22 15:53 UTC (permalink / raw)
  To: GCC Patches; +Cc: schwab

[-- Attachment #1: Type: text/plain, Size: 563 bytes --]

On 09/21/2009 03:46 PM, Richard Henderson wrote:
> A tricky bit here is that m68k used static_chain_rtx in
> m68k_output_mi_thunk apparently for a scratch register. It suddenly
> occurs to me to wonder if it did that to avoid clobbering A0 when that's
> used for the structure return value? If so, my conversion is incorrect.

I'm pretty sure my second guess is correct, so I've modified the
patch to continue to use STATIC_CHAIN_REGNUM, even though not
directly through static_chain_rtx.  I've added a comment to the
effect of avoiding STRUCT_VALUE_REGNUM.


r~

[-- Attachment #2: z --]
[-- Type: text/plain, Size: 6400 bytes --]

diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c
index 033872c..0862936 100644
--- a/gcc/config/m68k/m68k.c
+++ b/gcc/config/m68k/m68k.c
@@ -153,6 +153,7 @@ static bool m68k_rtx_costs (rtx, int, int, int *, bool);
 static bool m68k_return_in_memory (const_tree, const_tree);
 #endif
 static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
+static void m68k_trampoline_init (rtx, tree, rtx);
 \f
 
 /* Specify the identification number of the library being built */
@@ -267,6 +268,9 @@ const char *m68k_library_id_string = "_current_shared_library_a5_offset_";
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE m68k_can_eliminate
 
+#undef TARGET_TRAMPOLINE_INIT
+#define TARGET_TRAMPOLINE_INIT m68k_trampoline_init
+
 static const struct attribute_spec m68k_attribute_table[] =
 {
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
@@ -4958,7 +4962,11 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
 		      HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
 		      tree function)
 {
-  rtx this_slot, offset, addr, mem, insn;
+  rtx this_slot, offset, addr, mem, insn, tmp;
+
+  /* Avoid clobbering the struct value reg by using the
+     static chain reg as a temporary.  */
+  tmp = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
 
   /* Pretend to be a post-reload pass while generating rtl.  */
   reload_completed = 1;
@@ -4985,15 +4993,15 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
   if (vcall_offset != 0)
     {
       /* Set the static chain register to *THIS.  */
-      emit_move_insn (static_chain_rtx, this_slot);
-      emit_move_insn (static_chain_rtx, gen_rtx_MEM (Pmode, static_chain_rtx));
+      emit_move_insn (tmp, this_slot);
+      emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
 
       /* Set ADDR to a legitimate address for *THIS + VCALL_OFFSET.  */
-      addr = plus_constant (static_chain_rtx, vcall_offset);
+      addr = plus_constant (tmp, vcall_offset);
       if (!m68k_legitimate_address_p (Pmode, addr, true))
 	{
-	  emit_insn (gen_rtx_SET (VOIDmode, static_chain_rtx, addr));
-	  addr = static_chain_rtx;
+	  emit_insn (gen_rtx_SET (VOIDmode, tmp, addr));
+	  addr = tmp;
 	}
 
       /* Load the offset into %d0 and add it to THIS.  */
@@ -5019,8 +5027,8 @@ m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
 	  SET_REGNO (pic_offset_table_rtx, STATIC_CHAIN_REGNUM);
 	  emit_insn (gen_load_got (pic_offset_table_rtx));
 	}
-      legitimize_pic_address (XEXP (mem, 0), Pmode, static_chain_rtx);
-      mem = replace_equiv_address (mem, static_chain_rtx);
+      legitimize_pic_address (XEXP (mem, 0), Pmode, tmp);
+      mem = replace_equiv_address (mem, tmp);
     }
   insn = emit_call_insn (gen_sibcall (mem, const0_rtx));
   SIBLING_CALL_P (insn) = 1;
@@ -6390,4 +6398,30 @@ m68k_sched_indexed_address_bypass_p (rtx pro, rtx con)
     }
 }
 
+/* We generate a two-instructions program at M_TRAMP :
+	movea.l &CHAIN_VALUE,%a0
+	jmp FNADDR
+   where %a0 can be modified by changing STATIC_CHAIN_REGNUM.  */
+
+static void
+m68k_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
+{
+  rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
+  rtx mem;
+
+  gcc_assert (ADDRESS_REGNO_P (STATIC_CHAIN_REGNUM));
+
+  mem = adjust_address (m_tramp, HImode, 0);
+  emit_move_insn (mem, GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9)));
+  mem = adjust_address (m_tramp, SImode, 2);
+  emit_move_insn (mem, chain_value);
+
+  mem = adjust_address (m_tramp, HImode, 6);
+  emit_move_insn (mem, GEN_INT(0x4EF9));
+  mem = adjust_address (m_tramp, SImode, 8);
+  emit_move_insn (mem, fnaddr);
+
+  FINALIZE_TRAMPOLINE (XEXP (m_tramp, 0));
+}
+
 #include "gt-m68k.h"
diff --git a/gcc/config/m68k/m68k.h b/gcc/config/m68k/m68k.h
index b2cfb1d..5787e8a 100644
--- a/gcc/config/m68k/m68k.h
+++ b/gcc/config/m68k/m68k.h
@@ -617,20 +617,6 @@ extern enum reg_class regno_reg_class[];
 #define FINALIZE_TRAMPOLINE(TRAMP)
 #endif
 
-/* We generate a two-instructions program at address TRAMP :
-	movea.l &CXT,%a0
-	jmp FNADDR  */
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (HImode, TRAMP),				\
-		  GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9)));	\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 2)), CXT); \
-  emit_move_insn (gen_rtx_MEM (HImode, plus_constant (TRAMP, 6)),	\
-		  GEN_INT(0x4EF9));					\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 8)), FNADDR); \
-  FINALIZE_TRAMPOLINE(TRAMP);						\
-}
-
 /* This is the library routine that is used to transfer control from the
    trampoline to the actual nested function.  It is defined for backward
    compatibility, for linking with object code that used the old trampoline
diff --git a/gcc/config/m68k/netbsd-elf.h b/gcc/config/m68k/netbsd-elf.h
index 258b9e1..fd65418 100644
--- a/gcc/config/m68k/netbsd-elf.h
+++ b/gcc/config/m68k/netbsd-elf.h
@@ -312,39 +312,5 @@ while (0)
 #undef DEFAULT_PCC_STRUCT_RETURN
 #define DEFAULT_PCC_STRUCT_RETURN 1
 
-/* Output assembler code for a block containing the constant parts
-   of a trampoline, leaving space for the variable parts.  */
-
-/* On m68k svr4, the trampoline is different from the generic version
-   in that we use a1 as the static call chain.  */
-
-#undef TRAMPOLINE_TEMPLATE
-#define TRAMPOLINE_TEMPLATE(FILE)					\
-{									\
-  assemble_aligned_integer (2, GEN_INT (0x227a));			\
-  assemble_aligned_integer (2, GEN_INT (8));				\
-  assemble_aligned_integer (2, GEN_INT (0x2f3a));			\
-  assemble_aligned_integer (2, GEN_INT (8));				\
-  assemble_aligned_integer (2, GEN_INT (0x4e75));			\
-  assemble_aligned_integer (4, const0_rtx);				\
-  assemble_aligned_integer (4, const0_rtx);				\
-}
-
-/* Redefine since we are using a different trampoline */
-#undef TRAMPOLINE_SIZE
-#define TRAMPOLINE_SIZE 18
-
-/* 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.  */
-
-#undef INITIALIZE_TRAMPOLINE
-#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT)			\
-{									\
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 10)), CXT); \
-  emit_move_insn (gen_rtx_MEM (SImode, plus_constant (TRAMP, 14)), FNADDR); \
-}
-
-
 /* XXX
    This is the end of the chunk lifted from m68kv4.h  */

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 19/36][mips] Hookize static chain and trampoline macros
  2009-09-21 22:59 ` [patch 19/36][mips] " Richard Henderson
@ 2009-09-22 18:19   ` Richard Sandiford
  0 siblings, 0 replies; 58+ messages in thread
From: Richard Sandiford @ 2009-09-22 18:19 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

Richard Henderson <rth@redhat.com> writes:
> Your trampoline can be greatly simplified for N32 and N64 abis.  Recall 
> that the current address is passed in via $25.  Which simplifies your 
> trampoline to e.g.
>
> 	lw	$1,20($25)
> 	lw	$25,16($25)
> 	jr	$25
> 	 nop

Ah, good point.

FTR, this is a "hosted" vs. "freestanding" thing really.  Non-abicalls
o32, n32 and n64 all use arbitrary pointers while the abicalls versions
all use $25.  Same goes for VxWorks kernel mode vs. RTP mode.  Maybe the
worry was that it wasn't worth complicating things, but...

> And why emit raw integers to the template?  It just makes things a bit 
> confusing in my opinion.  Integers are of course acceptable if you're 
> not going to use a template...

...that's an excellent question.  I've no idea.

Using asm would certainly make it easier to handle the $25/not-$25 and
pointer size differences.  (As will having it all in mips.c, so thanks
for that.)  I'll give it a go.

Richard

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 24/36][pdp11] Hookize static chain and trampoline macros
  2009-09-21 23:09 ` [patch 24/36][pdp11] " Richard Henderson
@ 2009-09-22 18:31   ` Paul Koning
  0 siblings, 0 replies; 58+ messages in thread
From: Paul Koning @ 2009-09-22 18:31 UTC (permalink / raw)
  To: rth; +Cc: gcc-patches

Excerpt of message (sent 21 September 2009) by Richard Henderson:
> I merged the trampoline template into the initialization function, since 
> the integer values were already available.  Otherwise straight-forward.

Looks good.  Thanks!

Nit: typo also in the original, in the comment on
pdp11_trampoline_init: s/MV/MOV/

       paul

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 29/36][sh] Hookize static chain and trampoline macros
  2009-09-21 23:22 ` [patch 29/36][sh] " Richard Henderson
@ 2009-09-22 20:47   ` Alexandre Oliva
  0 siblings, 0 replies; 58+ messages in thread
From: Alexandre Oliva @ 2009-09-22 20:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches, kkojima

On Sep 21, 2009, Richard Henderson <rth@redhat.com> wrote:

> 	* config/sh/sh-protos.h (sh_initialize_trampoline): Remove.
> 	* config/sh/sh.c (TARGET_TRAMPOLINE_INIT): New.
> 	(TARGET_TRAMPOLINE_ADJUST_ADDRESS): New.
> 	(sh_trampoline_init): Rename from sh_initialize_trampoline;
> 	make static; adjust for target hook parameters.
> 	(sh_trampoline_adjust_address): New.
> 	* config/sh/sh.h (INITIALIZE_TRAMPOLINE): New.
> 	(TRAMPOLINE_ADJUST_ADDRESS): Move code to sh_trampoline_adjust_address.

This looks good, thanks.

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 21/36][mn10300] Hookize static chain and trampoline macros
  2009-09-21 23:11   ` Richard Henderson
@ 2009-09-22 20:53     ` Alexandre Oliva
  0 siblings, 0 replies; 58+ messages in thread
From: Alexandre Oliva @ 2009-09-22 20:53 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On Sep 21, 2009, Richard Henderson <rth@redhat.com> wrote:

> 	* config/mn10300/mn10300.c (TARGET_ASM_TRAMPOLINE_TEMPLATE,
> 	mn10300_asm_trampoline_template, TARGET_TRAMPOLINE_INIT,
> 	mn10300_trampoline_init): New.
> 	* config/mn10300/mn10300.h (TRAMPOLINE_TEMPLATE): Move code to
> 	mn10300_asm_trampoline_template.
> 	(INITIALIZE_TRAMPOLINE): Move code to mn10300_trampoline_init.

This looks good, thanks.

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [patch 36/36][i386] Hookize static chain and trampoline macros
  2009-09-21 23:41 ` [patch 36/36][i386] " Richard Henderson
@ 2009-09-23  0:37   ` H.J. Lu
  0 siblings, 0 replies; 58+ messages in thread
From: H.J. Lu @ 2009-09-23  0:37 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On Mon, Sep 21, 2009 at 4:35 PM, Richard Henderson <rth@redhat.com> wrote:
> Finally, the reason for this entire patch series, and the fix for PR41240.
>
> In addition to hook-izing the i386 backend, I also fill in the
> TARGET_STATIC_CHAIN hook with a function that examines what register, if
> any, the calling convention specified for this function leaves available.
>  For fastcall, we use EAX.  For regparm=3, we arrange for the trampoline to
> push the static chain onto the stack.  This requires a few adjustments to
> the prologue and epilogue code to manipulate the stack offsets
> appropriately.
>

This breaks Linux/ia32:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41436

-- 
H.J.

^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2009-09-23  0:15 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-21 21:57 [patch 01/36] Hookize static chain and trampoline macros Richard Henderson
2009-09-21 22:14 ` [patch 02/36][alpha] " Richard Henderson
2009-09-21 22:17 ` [patch 03/36][arc] " Richard Henderson
2009-09-21 22:19 ` [patch 04/36][ARM] " Richard Henderson
2009-09-21 22:26 ` [patch 05/36][AVR] " Richard Henderson
2009-09-21 22:28 ` [patch 06/36][bfin] " Richard Henderson
2009-09-21 22:29 ` [patch 07/36][cris] " Richard Henderson
2009-09-22  2:31   ` Hans-Peter Nilsson
2009-09-21 22:30 ` [patch 08/36][crx] " Richard Henderson
2009-09-21 22:32 ` [patch 09/36][fr30] " Richard Henderson
2009-09-21 22:34 ` [patch 10/36][frv] " Richard Henderson
2009-09-21 22:35 ` [patch 11/36][h8] " Richard Henderson
2009-09-21 22:36 ` [patch 12/36][ia64] " Richard Henderson
2009-09-21 22:40 ` [patch 13/36][iq2000] " Richard Henderson
2009-09-21 22:41 ` [patch 14/36][m32c] " Richard Henderson
2009-09-21 22:49   ` DJ Delorie
2009-09-21 22:57     ` Richard Henderson
2009-09-21 23:00       ` DJ Delorie
2009-09-21 23:13         ` Richard Henderson
2009-09-21 23:18           ` DJ Delorie
2009-09-21 22:42 ` [patch 15/36][m68hc11] " Richard Henderson
2009-09-21 22:47 ` [patch 16/36][m68k] " Richard Henderson
2009-09-22 15:53   ` Richard Henderson
2009-09-21 22:50 ` [patch 17/36][mcore] " Richard Henderson
2009-09-21 22:52 ` [patch 18/36][mep] " Richard Henderson
2009-09-21 22:59 ` [patch 19/36][mips] " Richard Henderson
2009-09-22 18:19   ` Richard Sandiford
2009-09-21 23:01 ` [patch 20/36][mmix] " Richard Henderson
2009-09-22  2:03   ` Hans-Peter Nilsson
2009-09-21 23:04 ` [patch 21/36][mn10300] " Richard Henderson
2009-09-21 23:11   ` Richard Henderson
2009-09-22 20:53     ` Alexandre Oliva
2009-09-21 23:06 ` [patch 22/36][moxie] " Richard Henderson
2009-09-21 23:08 ` [patch 23/36][parisc] " Richard Henderson
2009-09-22  2:03   ` John David Anglin
2009-09-21 23:09 ` [patch 24/36][pdp11] " Richard Henderson
2009-09-22 18:31   ` Paul Koning
2009-09-21 23:10 ` [patch 25/36][picochip] " Richard Henderson
2009-09-21 23:14 ` [patch 26/36][rs6000] " Richard Henderson
2009-09-22  2:16   ` David Edelsohn
2009-09-21 23:16 ` [patch 27/36][s390] " Richard Henderson
2009-09-22 14:55   ` Andreas Krebbel
2009-09-21 23:21 ` [patch 28/36][score] " Richard Henderson
2009-09-22 11:02   ` 答复: " liqin
2009-09-22 13:58     ` Richard Henderson
2009-09-22 11:25   ` Paolo Bonzini
2009-09-21 23:22 ` [patch 29/36][sh] " Richard Henderson
2009-09-22 20:47   ` Alexandre Oliva
2009-09-21 23:22 ` [patch 30/36][sparc] " Richard Henderson
2009-09-22 13:09   ` Eric Botcazou
2009-09-21 23:26 ` [patch 31/36][spu] " Richard Henderson
2009-09-21 23:44   ` Andrew Pinski
2009-09-21 23:27 ` [patch 32/36][stormy16] " Richard Henderson
2009-09-21 23:30 ` [patch 33/36][v850] " Richard Henderson
2009-09-21 23:31 ` [patch 34/36][vax] " Richard Henderson
2009-09-21 23:35 ` [patch 35/36][xtensa] " Richard Henderson
2009-09-21 23:41 ` [patch 36/36][i386] " Richard Henderson
2009-09-23  0:37   ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).