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]

Re: Patch to create builtin bzero


 > From: Richard Henderson <rth@cygnus.com>
 > 
 > On Wed, Mar 22, 2000 at 11:36:10AM -0500, Kaveh R. Ghazi wrote:
 > > +      /* Insert a zero parameter to convert bzero(x,y) -> memset(x,0,y).  */
 > > +      TREE_CHAIN (val) = TREE_CHAIN (arglist);
 > > +      TREE_CHAIN (arglist) = val;
 > > +      result = expand_builtin_memset(exp);
 > > +      
 > > +      /* If the above call fails, delete the zero parameter.  */
 > > +      if (result == 0)
 > > +	TREE_CHAIN (arglist) = TREE_CHAIN (TREE_CHAIN (arglist));
 > > +      return result;
 > 
 > I'm pretty sure the C++ front end would be mighty unhappy
 > with you modifying their trees.  Just build a new chain with
 > the same TREE_VALUE contents.  Then you don't have to worry
 > about undoing it either.
 > r~


I didn't see any C++ problems... but here's a revised patch anyway
which builds a new chain of memset parameters.  Okay to install?




2000-03-21  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (expand_builtin_bzero): New function.
	(expand_builtin): Handle bzero.

	* builtins.def: Add BUILT_IN_BZERO.

	* c-common.c (c_common_nodes_and_builtins): Provide builtin
	prototype & function for bzero.

diff -rup orig/egcs-CVS20000323/gcc/builtins.c egcs-CVS20000323/gcc/builtins.c
--- orig/egcs-CVS20000323/gcc/builtins.c	Thu Mar 23 16:27:23 2000
+++ egcs-CVS20000323/gcc/builtins.c	Thu Mar 23 11:48:28 2000
@@ -96,6 +96,7 @@ static rtx expand_builtin_strcmp	PARAMS 
 static rtx expand_builtin_memcpy	PARAMS ((tree));
 static rtx expand_builtin_strcpy	PARAMS ((tree));
 static rtx expand_builtin_memset	PARAMS ((tree));
+static rtx expand_builtin_bzero		PARAMS ((tree));
 static rtx expand_builtin_strlen	PARAMS ((tree, rtx,
 						 enum machine_mode));
 static rtx expand_builtin_alloca	PARAMS ((tree, rtx));
@@ -1574,6 +1575,42 @@ expand_builtin_memset (exp)
     }
 }
 
+/* Expand expression EXP, which is a call to the bzero builtin.  Return 0
+   if we failed the caller should emit a normal call.  */
+static rtx
+expand_builtin_bzero (exp)
+     tree exp;
+{
+  tree arglist = TREE_OPERAND (exp, 1);
+
+  if (arglist == 0
+      /* Arg could be non-pointer if user redeclared this fcn wrong.  */
+      || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE
+      || TREE_CHAIN (arglist) == 0
+      || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist))))
+	  != INTEGER_TYPE))
+    return 0;
+  else
+    {
+      tree newarglist;
+      rtx result;
+
+      /* New argument list transforming bzero(x, y) -> memset(x, 0, y).  */
+      newarglist = build_tree_list (NULL_TREE, TREE_VALUE (arglist));
+      chainon (newarglist, build_tree_list (NULL_TREE, integer_zero_node));
+      chainon (newarglist,
+	       build_tree_list (NULL_TREE, TREE_VALUE (TREE_CHAIN (arglist))));
+      TREE_OPERAND (exp, 1) = newarglist;
+
+      result = expand_builtin_memset(exp);
+      
+      /* If the above call fails, delete the zero parameter.  */
+      if (result == 0)
+	TREE_OPERAND (exp, 1) = arglist;
+      return result;
+    }
+}
+
 #ifdef HAVE_cmpstrsi
 /* Expand expression EXP, which is a call to the memcmp or the strcmp builtin.
    ARGLIST is the argument list for this call.  Return 0 if we failed and the
@@ -2313,7 +2350,7 @@ expand_builtin (exp, target, subtarget, 
       && (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
 	  || fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET
 	  || fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
-	  || fcode == BUILT_IN_BCMP
+	  || fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
 	  || fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY
 	  || fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_FFS))
     return expand_call (exp, target, ignore);
@@ -2447,6 +2484,12 @@ expand_builtin (exp, target, subtarget, 
 
     case BUILT_IN_MEMSET:
       target = expand_builtin_memset (exp);
+      if (target)
+	return target;
+      break;
+
+    case BUILT_IN_BZERO:
+      target = expand_builtin_bzero (exp);
       if (target)
 	return target;
       break;
diff -rup orig/egcs-CVS20000323/gcc/builtins.def egcs-CVS20000323/gcc/builtins.def
--- orig/egcs-CVS20000323/gcc/builtins.def	Thu Mar 23 16:27:23 2000
+++ egcs-CVS20000323/gcc/builtins.def	Thu Mar 23 11:32:25 2000
@@ -33,6 +33,7 @@ DEF_BUILTIN(BUILT_IN_FREM)
 DEF_BUILTIN(BUILT_IN_MEMCPY)
 DEF_BUILTIN(BUILT_IN_MEMCMP)
 DEF_BUILTIN(BUILT_IN_MEMSET)
+DEF_BUILTIN(BUILT_IN_BZERO)
 DEF_BUILTIN(BUILT_IN_BCMP)
 DEF_BUILTIN(BUILT_IN_STRCPY)
 DEF_BUILTIN(BUILT_IN_STRCMP)
diff -rup orig/egcs-CVS20000323/gcc/c-common.c egcs-CVS20000323/gcc/c-common.c
--- orig/egcs-CVS20000323/gcc/c-common.c	Thu Mar 23 16:30:21 2000
+++ egcs-CVS20000323/gcc/c-common.c	Thu Mar 23 11:34:38 2000
@@ -3462,7 +3462,7 @@ c_common_nodes_and_builtins (cplus_mode,
 {
   tree temp;
   tree memcpy_ftype, memset_ftype, strlen_ftype;
-  tree bcmp_ftype;
+  tree bzero_ftype, bcmp_ftype;
   tree endlink, int_endlink, double_endlink, unsigned_endlink;
   tree sizetype_endlink;
   tree ptr_ftype, ptr_ftype_unsigned;
@@ -3597,6 +3597,12 @@ c_common_nodes_and_builtins (cplus_mode,
 							    sizetype,
 							    endlink))));
 
+  /* Prototype for bzero.  */
+  bzero_ftype
+    = build_function_type (void_type_node,
+			   tree_cons (NULL_TREE, traditional_ptr_type_node,
+				      traditional_len_endlink));
+
   /* Prototype for bcmp.  */
   bcmp_ftype
     = build_function_type (integer_type_node,
@@ -3639,6 +3645,11 @@ c_common_nodes_and_builtins (cplus_mode,
       /* Suppress error if redefined as a non-function.  */
       DECL_BUILT_IN_NONANSI (temp) = 1;
 
+      /* In C mode, don't conflict with system prototype variations.  */
+      temp = builtin_function ("bzero",
+			       cplus_mode ? bzero_ftype : void_ftype_any,
+			       BUILT_IN_BZERO, BUILT_IN_NORMAL, NULL_PTR);
+      DECL_BUILT_IN_NONANSI (temp) = 1;
       temp = builtin_function ("bcmp",
 			       cplus_mode ? bcmp_ftype : int_ftype_any,
 			       BUILT_IN_BCMP, BUILT_IN_NORMAL, NULL_PTR);
@@ -3748,6 +3759,8 @@ c_common_nodes_and_builtins (cplus_mode,
 		    BUILT_IN_MEMCMP, BUILT_IN_NORMAL, "memcmp");
   builtin_function ("__builtin_memset", memset_ftype, BUILT_IN_MEMSET,
 		    BUILT_IN_NORMAL, "memset");
+  builtin_function ("__builtin_bzero", bzero_ftype, BUILT_IN_BZERO,
+		    BUILT_IN_NORMAL, "bzero");
   builtin_function ("__builtin_bcmp", bcmp_ftype,
 		    BUILT_IN_BCMP, BUILT_IN_NORMAL, "bcmp");
   builtin_function ("__builtin_strcmp", int_ftype_string_string,

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