This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch builtins.c: avoid duplicate work passing the entire expression


For builtins, the main function expand_builtin takes the expression
`exp' and pulls out the `arglist' and other bits.  Many of the
specific expand_builtin_foo functions take as parameters just the bits
they need.  But in some cases we pass `exp' into the specific builtin
expander which then proceeds again to pull out the needed bits.

This patch avoids some of that duplicate work by passing in the
already pulled out bits to more of these functions.  In some functions
I standardized a variable name `value_mode' into `target_mode' to
match what was used in the main expand_builtin.

Tested on sparc-sun-solaris2.7, no regressions.

Ok for mainline?

		Thanks,
		--Kaveh


2003-05-02  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (expand_builtin_constant_p, expand_builtin_strlen,
	expand_builtin_frame_address): Update prototypes.
	(expand_builtin_constant_p, expand_builtin_strlen,
	expand_builtin_strcpy, expand_builtin_memset,
	expand_builtin_bzero, expand_builtin_args_info,
	expand_builtin_frame_address): Pass in just the argument(s)
	needed, not the entire expression `exp'.
	(expand_builtin): Update all calls to these functions.
	
diff -rup orig/egcc-CVS20030501/gcc/builtins.c egcc-CVS20030501/gcc/builtins.c
--- orig/egcc-CVS20030501/gcc/builtins.c	2003-04-28 10:00:20.000000000 -0400
+++ egcc-CVS20030501/gcc/builtins.c	2003-05-01 23:28:15.430702026 -0400
@@ -102,7 +102,7 @@ static rtx expand_builtin_classify_type	
 static void expand_errno_check		PARAMS ((tree, rtx));
 static rtx expand_builtin_mathfn	PARAMS ((tree, rtx, rtx));
 static rtx expand_builtin_mathfn_2	PARAMS ((tree, rtx, rtx));
-static rtx expand_builtin_constant_p	PARAMS ((tree));
+static rtx expand_builtin_constant_p	PARAMS ((tree, enum machine_mode));
 static rtx expand_builtin_args_info	PARAMS ((tree));
 static rtx expand_builtin_next_arg	PARAMS ((tree));
 static rtx expand_builtin_va_start	PARAMS ((tree));
@@ -144,7 +144,7 @@ static rtx builtin_memset_gen_str	PARAMS
 static rtx expand_builtin_memset	PARAMS ((tree, rtx,
 						 enum machine_mode));
 static rtx expand_builtin_bzero		PARAMS ((tree));
-static rtx expand_builtin_strlen	PARAMS ((tree, rtx));
+static rtx expand_builtin_strlen	PARAMS ((tree, rtx, enum machine_mode));
 static rtx expand_builtin_strstr	PARAMS ((tree, rtx,
 						 enum machine_mode));
 static rtx expand_builtin_strpbrk	PARAMS ((tree, rtx,
@@ -156,7 +156,7 @@ static rtx expand_builtin_strrchr	PARAMS
 static rtx expand_builtin_alloca	PARAMS ((tree, rtx));
 static rtx expand_builtin_unop		PARAMS ((enum machine_mode,
 						 tree, rtx, rtx, optab));
-static rtx expand_builtin_frame_address	PARAMS ((tree));
+static rtx expand_builtin_frame_address	PARAMS ((tree, tree));
 static rtx expand_builtin_fputs		PARAMS ((tree, int, int));
 static tree stabilize_va_list		PARAMS ((tree, int));
 static rtx expand_builtin_expect	PARAMS ((tree, rtx));
@@ -1462,11 +1462,10 @@ expand_builtin_classify_type (arglist)
 /* Expand expression EXP, which is a call to __builtin_constant_p.  */
 
 static rtx
-expand_builtin_constant_p (exp)
-     tree exp;
+expand_builtin_constant_p (arglist, target_mode)
+     tree arglist;
+     enum machine_mode target_mode;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
-  enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
   rtx tmp;
 
   if (arglist == 0)
@@ -1480,7 +1479,7 @@ expand_builtin_constant_p (exp)
   current_function_calls_constant_p = 1;
 
   tmp = expand_expr (arglist, NULL_RTX, VOIDmode, 0);
-  tmp = gen_rtx_CONSTANT_P_RTX (value_mode, tmp);
+  tmp = gen_rtx_CONSTANT_P_RTX (target_mode, tmp);
   return tmp;
 }
 
@@ -1926,13 +1925,11 @@ expand_builtin_mathfn_2 (exp, target, su
    try to get the result in TARGET, if convenient.  */
 
 static rtx
-expand_builtin_strlen (exp, target)
-     tree exp;
+expand_builtin_strlen (arglist, target, target_mode)
+     tree arglist;
      rtx target;
+     enum machine_mode target_mode;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
-  enum machine_mode value_mode = TYPE_MODE (TREE_TYPE (exp));
-
   if (!validate_arglist (arglist, POINTER_TYPE, VOID_TYPE))
     return 0;
   else
@@ -1940,14 +1937,14 @@ expand_builtin_strlen (exp, target)
       rtx pat;
       tree len, src = TREE_VALUE (arglist);
       rtx result, src_reg, char_rtx, before_strlen;
-      enum machine_mode insn_mode = value_mode, char_mode;
+      enum machine_mode insn_mode = target_mode, char_mode;
       enum insn_code icode = CODE_FOR_nothing;
       int align;
 
       /* If the length can be computed at compile-time, return it.  */
       len = c_strlen (src);
       if (len)
-	return expand_expr (len, target, value_mode, EXPAND_NORMAL);
+	return expand_expr (len, target, target_mode, EXPAND_NORMAL);
 
       align = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
 
@@ -2011,12 +2008,12 @@ expand_builtin_strlen (exp, target)
 	emit_insn_before (pat, get_insns ());
 
       /* Return the value in the proper mode for this function.  */
-      if (GET_MODE (result) == value_mode)
+      if (GET_MODE (result) == target_mode)
 	target = result;
       else if (target != 0)
 	convert_move (target, result, 0);
       else
-	target = convert_to_mode (value_mode, result, 0);
+	target = convert_to_mode (target_mode, result, 0);
 
       return target;
     }
@@ -2451,12 +2448,11 @@ expand_builtin_bcopy (arglist)
    convenient).  */
 
 static rtx
-expand_builtin_strcpy (exp, target, mode)
-     tree exp;
+expand_builtin_strcpy (arglist, target, mode)
+     tree arglist;
      rtx target;
      enum machine_mode mode;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
   tree fn, len;
 
   if (!validate_arglist (arglist, POINTER_TYPE, POINTER_TYPE, VOID_TYPE))
@@ -2649,13 +2645,11 @@ builtin_memset_gen_str (data, offset, mo
    convenient).  */
 
 static rtx
-expand_builtin_memset (exp, target, mode)
-     tree exp;
+expand_builtin_memset (arglist, target, mode)
+     tree arglist;
      rtx target;
      enum machine_mode mode;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
-
   if (!validate_arglist (arglist,
 			 POINTER_TYPE, INTEGER_TYPE, INTEGER_TYPE, VOID_TYPE))
     return 0;
@@ -2765,12 +2759,10 @@ expand_builtin_memset (exp, target, mode
    if we failed the caller should emit a normal call.  */
 
 static rtx
-expand_builtin_bzero (exp)
-     tree exp;
+expand_builtin_bzero (arglist)
+     tree arglist;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
   tree dest, size, newarglist;
-  rtx result;
 
   if (!validate_arglist (arglist, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
     return NULL_RTX;
@@ -2787,13 +2779,7 @@ expand_builtin_bzero (exp)
   newarglist = tree_cons (NULL_TREE, integer_zero_node, newarglist);
   newarglist = tree_cons (NULL_TREE, dest, newarglist);
 
-  TREE_OPERAND (exp, 1) = newarglist;
-  result = expand_builtin_memset (exp, const0_rtx, VOIDmode);
-
-  /* Always restore the original arguments.  */
-  TREE_OPERAND (exp, 1) = arglist;
-
-  return result;
+  return expand_builtin_memset (newarglist, const0_rtx, VOIDmode);
 }
 
 /* Expand expression EXP, which is a call to the memcmp built-in function.
@@ -3427,10 +3413,9 @@ expand_builtin_saveregs ()
    is controlled by the definition of CUMULATIVE_ARGS.  */
 
 static rtx
-expand_builtin_args_info (exp)
-     tree exp;
+expand_builtin_args_info (arglist)
+     tree arglist;
 {
-  tree arglist = TREE_OPERAND (exp, 1);
   int nwords = sizeof (CUMULATIVE_ARGS) / sizeof (int);
   int *word_ptr = (int *) &current_function_args_info;
 
@@ -3834,12 +3819,9 @@ expand_builtin_va_copy (arglist)
    __builtin_return_address.  */
 
 static rtx
-expand_builtin_frame_address (exp)
-     tree exp;
+expand_builtin_frame_address (fndecl, arglist)
+     tree fndecl, arglist;
 {
-  tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
-  tree arglist = TREE_OPERAND (exp, 1);
-
   /* The argument must be a nonnegative integer constant.
      It counts the number of frames to scan up the stack.
      The value is the return address saved in that frame.  */
@@ -4463,7 +4445,7 @@ expand_builtin (exp, target, subtarget, 
       return expand_builtin_saveregs ();
 
     case BUILT_IN_ARGS_INFO:
-      return expand_builtin_args_info (exp);
+      return expand_builtin_args_info (arglist);
 
       /* Return the address of the first anonymous stack arg.  */
     case BUILT_IN_NEXT_ARG:
@@ -4473,11 +4455,11 @@ expand_builtin (exp, target, subtarget, 
       return expand_builtin_classify_type (arglist);
 
     case BUILT_IN_CONSTANT_P:
-      return expand_builtin_constant_p (exp);
+      return expand_builtin_constant_p (arglist, target_mode);
 
     case BUILT_IN_FRAME_ADDRESS:
     case BUILT_IN_RETURN_ADDRESS:
-      return expand_builtin_frame_address (exp);
+      return expand_builtin_frame_address (fndecl, arglist);
 
     /* Returns the address of the area where the structure is returned.
        0 otherwise.  */
@@ -4541,13 +4523,13 @@ expand_builtin (exp, target, subtarget, 
       break;
 
     case BUILT_IN_STRLEN:
-      target = expand_builtin_strlen (exp, target);
+      target = expand_builtin_strlen (arglist, target, target_mode);
       if (target)
 	return target;
       break;
 
     case BUILT_IN_STRCPY:
-      target = expand_builtin_strcpy (exp, target, mode);
+      target = expand_builtin_strcpy (arglist, target, mode);
       if (target)
 	return target;
       break;
@@ -4639,13 +4621,13 @@ expand_builtin (exp, target, subtarget, 
       break;
 
     case BUILT_IN_MEMSET:
-      target = expand_builtin_memset (exp, target, mode);
+      target = expand_builtin_memset (arglist, target, mode);
       if (target)
 	return target;
       break;
 
     case BUILT_IN_BZERO:
-      target = expand_builtin_bzero (exp);
+      target = expand_builtin_bzero (arglist);
       if (target)
 	return target;
       break;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]