[PATCH] Introduce target hook for FUNCTION_VALUE

Richard Guenther rguenther@suse.de
Wed Jul 13 09:41:00 GMT 2005


On Tue, 12 Jul 2005, Richard Henderson wrote:

> Otherwise it looks good.  I think I might appreciate you check in
> the target hook portion of the patch independent of the i386 
> portion of the patch.

This is the target hook portion, rebootstrapped and checked on
x86_64-unknown-linux-gnu.

Ok for mainline?

Richard.
-------------- next part --------------
2005-07-13  Richard Guenther  <rguenther@suse.de>

	* Makefile.in (explow.o, reg-stack.o): Depend on target.h.
	* calls.c (expand_call): Pass fntype to hard_function_value.
	(emit_library_call_value_1): Likewise.
	* explow.c: Include target.h.
	(hard_function_value): Take extra argument, the fntype.
	Use new target hook for function_value.
	* expr.h (hard_function_value): Change prototype.
	* function.c (aggregate_value_p): Pass 0 as fntype to
	hard_function_value.
	(assign_parms): Use new target hook for function_value.
	Pass 0 as fntype to hard_function_value.
	(expand_function_end): Likewise.
	* reg-stack.c: Include target.h.
	(stack_result): Use new target hook for function_value.
	* target-def.h: New target hook function_value.
	* target.h: Likewise.
	* targhooks.c (default_function_value): New function.
	* targhooks.h (default_function_value): Declare.


Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1521
diff -c -3 -p -r1.1521 Makefile.in
*** Makefile.in	10 Jul 2005 00:27:44 -0000	1.1521
--- Makefile.in	13 Jul 2005 08:10:18 -0000
*************** expmed.o : expmed.c $(CONFIG_H) $(SYSTEM
*** 2079,2085 ****
     toplev.h $(TM_P_H) langhooks.h
  explow.o : explow.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) \
     $(FLAGS_H) hard-reg-set.h insn-config.h $(EXPR_H) $(OPTABS_H) $(RECOG_H) \
!    toplev.h function.h $(GGC_H) $(TM_P_H) langhooks.h gt-explow.h
  optabs.o : optabs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(TREE_H) $(FLAGS_H) insn-config.h $(EXPR_H) $(OPTABS_H) libfuncs.h \
     $(RECOG_H) reload.h toplev.h $(GGC_H) real.h $(TM_P_H) except.h \
--- 2079,2085 ----
     toplev.h $(TM_P_H) langhooks.h
  explow.o : explow.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(TREE_H) \
     $(FLAGS_H) hard-reg-set.h insn-config.h $(EXPR_H) $(OPTABS_H) $(RECOG_H) \
!    toplev.h function.h $(GGC_H) $(TM_P_H) langhooks.h gt-explow.h target.h
  optabs.o : optabs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(TREE_H) $(FLAGS_H) insn-config.h $(EXPR_H) $(OPTABS_H) libfuncs.h \
     $(RECOG_H) reload.h toplev.h $(GGC_H) real.h $(TM_P_H) except.h \
*************** recog.o : recog.c $(CONFIG_H) $(SYSTEM_H
*** 2391,2397 ****
  reg-stack.o : reg-stack.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(RTL_H) $(TREE_H) $(RECOG_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) \
     insn-config.h toplev.h reload.h function.h $(TM_P_H) $(GGC_H) \
!    gt-reg-stack.h $(BASIC_BLOCK_H) output.h $(VARRAY_H) timevar.h tree-pass.h
  sreal.o: sreal.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) sreal.h
  predict.o: predict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(TREE_H) $(FLAGS_H) insn-config.h $(BASIC_BLOCK_H) $(REGS_H) \
--- 2391,2398 ----
  reg-stack.o : reg-stack.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
     $(RTL_H) $(TREE_H) $(RECOG_H) $(REGS_H) hard-reg-set.h $(FLAGS_H) \
     insn-config.h toplev.h reload.h function.h $(TM_P_H) $(GGC_H) \
!    gt-reg-stack.h $(BASIC_BLOCK_H) output.h $(VARRAY_H) timevar.h tree-pass.h \
!    target.h
  sreal.o: sreal.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) sreal.h
  predict.o: predict.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(TREE_H) $(FLAGS_H) insn-config.h $(BASIC_BLOCK_H) $(REGS_H) \
Index: calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.392
diff -c -3 -p -r1.392 calls.c
*** calls.c	26 Jun 2005 05:27:05 -0000	1.392
--- calls.c	13 Jul 2005 08:10:18 -0000
*************** expand_call (tree exp, rtx target, int i
*** 2517,2525 ****
  	{
  	  if (pcc_struct_value)
  	    valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
! 					  fndecl, (pass == 0));
  	  else
! 	    valreg = hard_function_value (TREE_TYPE (exp), fndecl, (pass == 0));
  	}
  
        /* Precompute all register parameters.  It isn't safe to compute anything
--- 2517,2526 ----
  	{
  	  if (pcc_struct_value)
  	    valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)),
! 					  fndecl, NULL, (pass == 0));
  	  else
! 	    valreg = hard_function_value (TREE_TYPE (exp), fndecl, fntype,
! 					  (pass == 0));
  	}
  
        /* Precompute all register parameters.  It isn't safe to compute anything
*************** emit_library_call_value_1 (int retval, r
*** 3266,3272 ****
  	{
  #ifdef PCC_STATIC_STRUCT_RETURN
  	  rtx pointer_reg
! 	    = hard_function_value (build_pointer_type (tfom), 0, 0);
  	  mem_value = gen_rtx_MEM (outmode, pointer_reg);
  	  pcc_struct_value = 1;
  	  if (value == 0)
--- 3267,3273 ----
  	{
  #ifdef PCC_STATIC_STRUCT_RETURN
  	  rtx pointer_reg
! 	    = hard_function_value (build_pointer_type (tfom), 0, 0, 0);
  	  mem_value = gen_rtx_MEM (outmode, pointer_reg);
  	  pcc_struct_value = 1;
  	  if (value == 0)
Index: explow.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/explow.c,v
retrieving revision 1.147
diff -c -3 -p -r1.147 explow.c
*** explow.c	25 Jun 2005 01:59:47 -0000	1.147
--- explow.c	13 Jul 2005 08:10:18 -0000
*************** Software Foundation, 51 Franklin Street,
*** 37,42 ****
--- 37,43 ----
  #include "ggc.h"
  #include "recog.h"
  #include "langhooks.h"
+ #include "target.h"
  
  static rtx break_out_memory_refs (rtx);
  static void emit_stack_probe (rtx);
*************** probe_stack_range (HOST_WIDE_INT first, 
*** 1405,1428 ****
  /* Return an rtx representing the register or memory location
     in which a scalar value of data type VALTYPE
     was returned by a function call to function FUNC.
!    FUNC is a FUNCTION_DECL node if the precise function is known,
!    otherwise 0.
     OUTGOING is 1 if on a machine with register windows this function
     should return the register in which the function will put its result
     and 0 otherwise.  */
  
  rtx
! hard_function_value (tree valtype, tree func ATTRIBUTE_UNUSED,
  		     int outgoing ATTRIBUTE_UNUSED)
  {
    rtx val;
  
! #ifdef FUNCTION_OUTGOING_VALUE
!   if (outgoing)
!     val = FUNCTION_OUTGOING_VALUE (valtype, func);
!   else
! #endif
!     val = FUNCTION_VALUE (valtype, func);
  
    if (REG_P (val)
        && GET_MODE (val) == BLKmode)
--- 1406,1424 ----
  /* Return an rtx representing the register or memory location
     in which a scalar value of data type VALTYPE
     was returned by a function call to function FUNC.
!    FUNC is a FUNCTION_DECL, FNTYPE a FUNCTION_TYPE node if the precise
!    function is known, otherwise 0.
     OUTGOING is 1 if on a machine with register windows this function
     should return the register in which the function will put its result
     and 0 otherwise.  */
  
  rtx
! hard_function_value (tree valtype, tree func, tree fntype,
  		     int outgoing ATTRIBUTE_UNUSED)
  {
    rtx val;
  
!   val = targetm.calls.function_value (valtype, func ? func : fntype, outgoing);
  
    if (REG_P (val)
        && GET_MODE (val) == BLKmode)
Index: expr.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.h,v
retrieving revision 1.191
diff -c -3 -p -r1.191 expr.h
*** expr.h	28 Jun 2005 19:55:52 -0000	1.191
--- expr.h	13 Jul 2005 08:10:19 -0000
*************** extern HOST_WIDE_INT int_expr_size (tree
*** 550,556 ****
  
  /* Return an rtx that refers to the value returned by a function
     in its original home.  This becomes invalid if any more code is emitted.  */
! extern rtx hard_function_value (tree, tree, int);
  
  extern rtx prepare_call_address (rtx, rtx, rtx *, int, int);
  
--- 550,556 ----
  
  /* Return an rtx that refers to the value returned by a function
     in its original home.  This becomes invalid if any more code is emitted.  */
! extern rtx hard_function_value (tree, tree, tree, int);
  
  extern rtx prepare_call_address (rtx, rtx, rtx *, int, int);
  
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.635
diff -c -3 -p -r1.635 function.c
*** function.c	7 Jul 2005 21:04:31 -0000	1.635
--- function.c	13 Jul 2005 08:10:19 -0000
*************** aggregate_value_p (tree exp, tree fntype
*** 1732,1738 ****
      return 1;
    /* Make sure we have suitable call-clobbered regs to return
       the value in; if not, we must return it in memory.  */
!   reg = hard_function_value (type, 0, 0);
  
    /* If we have something other than a REG (e.g. a PARALLEL), then assume
       it is OK.  */
--- 1732,1738 ----
      return 1;
    /* Make sure we have suitable call-clobbered regs to return
       the value in; if not, we must return it in memory.  */
!   reg = hard_function_value (type, 0, fntype, 0);
  
    /* If we have something other than a REG (e.g. a PARALLEL), then assume
       it is OK.  */
*************** assign_parms (tree fndecl)
*** 3055,3067 ****
  	{
  	  rtx real_decl_rtl;
  
! #ifdef FUNCTION_OUTGOING_VALUE
! 	  real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
! 						   fndecl);
! #else
! 	  real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
! 					  fndecl);
! #endif
  	  REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
  	  /* The delay slot scheduler assumes that current_function_return_rtx
  	     holds the hard register containing the return value, not a
--- 3055,3062 ----
  	{
  	  rtx real_decl_rtl;
  
! 	  real_decl_rtl = targetm.calls.function_value (TREE_TYPE (decl_result),
! 							fndecl, true);
  	  REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
  	  /* The delay slot scheduler assumes that current_function_return_rtx
  	     holds the hard register containing the return value, not a
*************** expand_function_start (tree subr)
*** 4149,4155 ****
  	  /* In order to figure out what mode to use for the pseudo, we
  	     figure out what the mode of the eventual return register will
  	     actually be, and use that.  */
! 	  rtx hard_reg = hard_function_value (return_type, subr, 1);
  
  	  /* Structures that are returned in registers are not
  	     aggregate_value_p, so we may see a PARALLEL or a REG.  */
--- 4144,4150 ----
  	  /* In order to figure out what mode to use for the pseudo, we
  	     figure out what the mode of the eventual return register will
  	     actually be, and use that.  */
! 	  rtx hard_reg = hard_function_value (return_type, subr, 0, 1);
  
  	  /* Structures that are returned in registers are not
  	     aggregate_value_p, so we may see a PARALLEL or a REG.  */
*************** expand_function_end (void)
*** 4499,4511 ****
        else
  	value_address = XEXP (value_address, 0);
  
! #ifdef FUNCTION_OUTGOING_VALUE
!       outgoing = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
! 					  current_function_decl);
! #else
!       outgoing = FUNCTION_VALUE (build_pointer_type (type),
! 				 current_function_decl);
! #endif 
  
        /* Mark this as a function return value so integrate will delete the
  	 assignment and USE below when inlining this function.  */
--- 4494,4501 ----
        else
  	value_address = XEXP (value_address, 0);
  
!       outgoing = targetm.calls.function_value (build_pointer_type (type),
! 					       current_function_decl, true);
  
        /* Mark this as a function return value so integrate will delete the
  	 assignment and USE below when inlining this function.  */
Index: reg-stack.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reg-stack.c,v
retrieving revision 1.187
diff -c -3 -p -r1.187 reg-stack.c
*** reg-stack.c	5 Jul 2005 16:20:11 -0000	1.187
--- reg-stack.c	13 Jul 2005 08:10:19 -0000
***************
*** 172,177 ****
--- 172,178 ----
  #include "ggc.h"
  #include "timevar.h"
  #include "tree-pass.h"
+ #include "target.h"
  
  /* We use this array to cache info about insns, because otherwise we
     spend too much time in stack_regs_mentioned_p.
*************** stack_result (tree decl)
*** 667,680 ****
  
    result = DECL_RTL_IF_SET (DECL_RESULT (decl));
    if (result != 0)
!     {
! #ifdef FUNCTION_OUTGOING_VALUE
!       result
! 	= FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
! #else
!       result = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (decl)), decl);
! #endif
!     }
  
    return result != 0 && STACK_REG_P (result) ? result : 0;
  }
--- 668,675 ----
  
    result = DECL_RTL_IF_SET (DECL_RESULT (decl));
    if (result != 0)
!     result = targetm.calls.function_value (TREE_TYPE (DECL_RESULT (decl)),
! 					   decl, true);
  
    return result != 0 && STACK_REG_P (result) ? result : 0;
  }
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.131
diff -c -3 -p -r1.131 target-def.h
*** target-def.h	7 Jul 2005 11:48:13 -0000	1.131
--- target-def.h	13 Jul 2005 08:10:19 -0000
*************** Foundation, 51 Franklin Street, Fifth Fl
*** 438,443 ****
--- 438,445 ----
  #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false
  #define TARGET_ARG_PARTIAL_BYTES hook_int_CUMULATIVE_ARGS_mode_tree_bool_0
  
+ #define TARGET_FUNCTION_VALUE default_function_value
+ 
  #define TARGET_CALLS {						\
     TARGET_PROMOTE_FUNCTION_ARGS,				\
     TARGET_PROMOTE_FUNCTION_RETURN,				\
*************** Foundation, 51 Franklin Street, Fifth Fl
*** 454,460 ****
     TARGET_MUST_PASS_IN_STACK,					\
     TARGET_CALLEE_COPIES,					\
     TARGET_ARG_PARTIAL_BYTES,					\
!    TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN			\
     }
  
  #ifndef TARGET_UNWIND_TABLES_DEFAULT
--- 456,463 ----
     TARGET_MUST_PASS_IN_STACK,					\
     TARGET_CALLEE_COPIES,					\
     TARGET_ARG_PARTIAL_BYTES,					\
!    TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN,			\
!    TARGET_FUNCTION_VALUE					\
     }
  
  #ifndef TARGET_UNWIND_TABLES_DEFAULT
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.143
diff -c -3 -p -r1.143 target.h
*** target.h	7 Jul 2005 11:48:13 -0000	1.143
--- target.h	13 Jul 2005 08:16:02 -0000
*************** struct gcc_target
*** 603,608 ****
--- 603,613 ----
         is not allowed for this 'val' argument; NULL otherwise. */
      const char *(*invalid_arg_for_unprototyped_fn) (tree typelist, 
  					     	    tree funcdecl, tree val);
+ 
+     /* Return an rtx for the return value location of the function
+        specified by FN_DECL_OR_TYPE with a return type of RET_TYPE.  */
+     rtx (*function_value) (tree ret_type, tree fn_decl_or_type,
+ 			   bool outgoing);
    } calls;
  
    /* Return the diagnostic message string if conversion from FROMTYPE
Index: targhooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/targhooks.c,v
retrieving revision 2.45
diff -c -3 -p -r2.45 targhooks.c
*** targhooks.c	7 Jul 2005 11:48:13 -0000	2.45
--- targhooks.c	13 Jul 2005 08:10:19 -0000
*************** hook_bool_rtx_commutative_p (rtx x, int 
*** 417,420 ****
--- 417,442 ----
    return COMMUTATIVE_P (x);
  }
  
+ rtx
+ default_function_value (tree ret_type ATTRIBUTE_UNUSED,
+ 			tree fn_decl_or_type,
+ 			bool outgoing ATTRIBUTE_UNUSED)
+ {
+   /* The old interface doesn't handle receiving the function type.  */
+   if (fn_decl_or_type
+       && !DECL_P (fn_decl_or_type))
+     fn_decl_or_type = NULL;
+ 
+ #ifdef FUNCTION_OUTGOING_VALUE
+   if (outgoing)
+     return FUNCTION_OUTGOING_VALUE (ret_type, fn_decl_or_type);
+ #endif
+ 
+ #ifdef FUNCTION_VALUE
+   return FUNCTION_VALUE (ret_type, fn_decl_or_type);
+ #else
+   return NULL_RTX;
+ #endif
+ }
+ 
  #include "gt-targhooks.h"
Index: targhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/targhooks.h,v
retrieving revision 2.32
diff -c -3 -p -r2.32 targhooks.h
*** targhooks.h	7 Jul 2005 11:48:13 -0000	2.32
--- targhooks.h	13 Jul 2005 08:10:19 -0000
*************** extern int hook_int_CUMULATIVE_ARGS_mode
*** 67,69 ****
--- 67,71 ----
  extern const char *hook_invalid_arg_for_unprototyped_fn
    (tree, tree, tree);
  extern bool hook_bool_rtx_commutative_p (rtx, int);
+ extern rtx default_function_value (tree, tree, bool);
+ 



More information about the Gcc-patches mailing list