Patch to create builtin bzero

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Fri Mar 24 12:23:00 GMT 2000


 > From: Richard Henderson <rth@cygnus.com>
 > 
 > > Okay to install?
 > 
 > Not quite.
 > 
 > > +      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;
 > 
 > exp must always look *exactly* like it did before you got it.
 > Always put arglist back.
 > r~

Okay done.  Here's what I installed.  Thanks for reviewing my patch.

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/egcs/gcc/ChangeLog,v
retrieving revision 1.6021
diff -u -p -r1.6021 ChangeLog
--- ChangeLog	2000/03/24 02:05:07	1.6021
+++ ChangeLog	2000/03/24 20:18:09
@@ -1,3 +1,13 @@
+2000-03-24  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.
+
 2000-03-23  Michael Meissner  <meissner@redhat.com>
 
 	* config/alpha/alpha.md (TF floating point insns): Undo 2000-03-21
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.c,v
retrieving revision 1.39
diff -u -p -r1.39 builtins.c
--- builtins.c	2000/03/23 21:32:10	1.39
+++ builtins.c	2000/03/24 20:18:14
@@ -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);
+      
+      /* Always restore the original arguments.  */
+      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;
Index: builtins.def
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.def,v
retrieving revision 1.2
diff -u -p -r1.2 builtins.def
--- builtins.def	2000/03/23 21:32:10	1.2
+++ builtins.def	2000/03/24 20:18:14
@@ -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)
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-common.c,v
retrieving revision 1.101
diff -u -p -r1.101 c-common.c
--- c-common.c	2000/03/23 21:32:10	1.101
+++ c-common.c	2000/03/24 20:18:18
@@ -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);
@@ -3746,8 +3757,10 @@ c_common_nodes_and_builtins (cplus_mode,
 		    BUILT_IN_NORMAL, "memcpy");
   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
 		    BUILT_IN_MEMCMP, BUILT_IN_NORMAL, "memcmp");
-  builtin_function ("__builtin_memset", memset_ftype, BUILT_IN_MEMSET,
-		    BUILT_IN_NORMAL, "memset");
+  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,


More information about the Gcc-patches mailing list