This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[LIBIBERTY]: Expose tail calls in xmemdup and xstrdup
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dj at redhat dot com
- Date: Thu, 24 Mar 2005 10:26:04 -0500 (EST)
- Subject: [LIBIBERTY]: Expose tail calls in xmemdup and xstrdup
This patch exposes tail calls in xmemdup and xstrdup to the optimizer.
It is similar to a patch to plain strdup way back here:
http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00903.html
In order to guarantee that memcpy is declared, I prototype it
explicitly as is done in many other libiberty functions. I also
removed the "register" keyword since we're allowing the compiler to
figure out the best allocation scheme now.
I verified by manually creating a .s file that the tail calls to
memcpy are turned into jmps in both functions.
Bootstrapped/regtest underway on x86_64-unknown-linux-gnu.
Okay for mainline if it passes?
Thanks,
--Kaveh
2005-03-24 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* xmemdup.c, xstrdup.c: Expose the tail call.
diff -rup orig/egcc-CVS20050323/libiberty/xmemdup.c egcc-CVS20050323/libiberty/xmemdup.c
--- orig/egcc-CVS20050323/libiberty/xmemdup.c 2001-09-26 14:16:17.000000000 -0400
+++ egcc-CVS20050323/libiberty/xmemdup.c 2005-03-24 09:47:27.394415056 -0500
@@ -15,17 +15,15 @@ allocated, the remaining memory is zeroe
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "ansidecl.h"
#include "libiberty.h"
-
-#include <sys/types.h> /* For size_t. */
-#ifdef HAVE_STRING_H
-#include <string.h>
+/* libiberty.h will have gotten size_t on an ANSI_PROTOTYPES platform,
+ otherwise... */
+#ifndef ANSI_PROTOTYPES
+#define size_t unsigned long
#endif
+extern PTR memcpy PARAMS ((PTR, const PTR, size_t));
+
PTR
xmemdup (input, copy_size, alloc_size)
const PTR input;
@@ -33,6 +31,5 @@ xmemdup (input, copy_size, alloc_size)
size_t alloc_size;
{
PTR output = xcalloc (1, alloc_size);
- memcpy (output, input, copy_size);
- return output;
+ return memcpy (output, input, copy_size);
}
diff -rup orig/egcc-CVS20050323/libiberty/xstrdup.c egcc-CVS20050323/libiberty/xstrdup.c
--- orig/egcc-CVS20050323/libiberty/xstrdup.c 2001-09-26 14:16:17.000000000 -0400
+++ egcc-CVS20050323/libiberty/xstrdup.c 2005-03-24 09:47:40.558413824 -0500
@@ -13,22 +13,21 @@ obtain memory.
*/
-#include <sys/types.h>
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-#include "ansidecl.h"
#include "libiberty.h"
+/* libiberty.h will have gotten size_t on an ANSI_PROTOTYPES platform,
+ otherwise... */
+#ifndef ANSI_PROTOTYPES
+#define size_t unsigned long
+#endif
+
+extern size_t strlen PARAMS ((const char*));
+extern PTR memcpy PARAMS ((PTR, const PTR, size_t));
char *
xstrdup (s)
const char *s;
{
- register size_t len = strlen (s) + 1;
- register char *ret = xmalloc (len);
- memcpy (ret, s, len);
- return ret;
+ const size_t len = strlen (s) + 1;
+ char *const ret = xmalloc (len);
+ return memcpy (ret, s, len);
}