summaryrefslogtreecommitdiff
path: root/SDKs/darwin
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-05-23 07:18:59 +0000
committerBill Wendling <isanbard@gmail.com>2013-05-23 07:18:59 +0000
commitd06f2fc03087e7cccda19bd550bf6fb3bc2f5ae7 (patch)
tree20e66e4fe3b4b74778e405e043a0ac0f17b94f14 /SDKs/darwin
parenta05fd3189eec45af6d737be89194471c0972905d (diff)
downloadcompiler-rt-d06f2fc03087e7cccda19bd550bf6fb3bc2f5ae7.tar.gz
compiler-rt-d06f2fc03087e7cccda19bd550bf6fb3bc2f5ae7.tar.bz2
compiler-rt-d06f2fc03087e7cccda19bd550bf6fb3bc2f5ae7.tar.xz
Performance improvement.
Using fwrite and fread was very *very* slow. The resulting code was multiple times slower than GCC's implementation of gcov. Replace the fwrite/fread system with an mmap() version. If the `.gcda' file doesn't exist, we (re)allocate a buffer that we write into. That gets written to the `.gcda' file in one chunk. If the `.gcda' file already exists, we simply mmap() the file, modify the mapped data, and use msync() to write the contents out to disk. It's much easier than implementing our own buffering scheme, and we don't have to use fwrite's and fread's buffering. For those who are numbers-oriented, here are some timings: GCC Verison ----------- `.gcda' files don't exist: 23s `.gcda' files do exist: 14s LLVM Version (before this change) --------------------------------- `.gcda' files don't exist: 28s `.gcda' files do exist: 28s LLVM Version (with this change) ------------------------------- `.gcda' files don't exist: 18s `.gcda' files do exist: 4s It's a win-win-win-win-lose-win-win scenario! <rdar://problem/13466086> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182563 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'SDKs/darwin')
-rw-r--r--SDKs/darwin/usr/include/fcntl.h17
-rw-r--r--SDKs/darwin/usr/include/stdio.h10
-rw-r--r--SDKs/darwin/usr/include/stdlib.h1
-rw-r--r--SDKs/darwin/usr/include/sys/fcntl.h52
-rw-r--r--SDKs/darwin/usr/include/sys/mman.h42
5 files changed, 119 insertions, 3 deletions
diff --git a/SDKs/darwin/usr/include/fcntl.h b/SDKs/darwin/usr/include/fcntl.h
new file mode 100644
index 00000000..a5f91e3a
--- /dev/null
+++ b/SDKs/darwin/usr/include/fcntl.h
@@ -0,0 +1,17 @@
+/* ===-- fcntl.h - stub SDK header for compiler-rt --------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ * ===-----------------------------------------------------------------------===
+ *
+ * This is a stub SDK header file. This file is not part of the interface of
+ * this library nor an official version of the appropriate SDK header. It is
+ * intended only to stub the features of this header required by compiler-rt.
+ *
+ * ===-----------------------------------------------------------------------===
+ */
+
+#include <sys/fcntl.h>
diff --git a/SDKs/darwin/usr/include/stdio.h b/SDKs/darwin/usr/include/stdio.h
index 5bbd8a55..006652fb 100644
--- a/SDKs/darwin/usr/include/stdio.h
+++ b/SDKs/darwin/usr/include/stdio.h
@@ -24,15 +24,18 @@ extern "C" {
typedef struct __sFILE FILE;
typedef __SIZE_TYPE__ size_t;
-/* Determine the appropriate fopen() and fwrite() functions. */
+/* Determine the appropriate fdopen, fopen(), and fwrite() functions. */
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
# if defined(__i386)
+# define __FDOPEN_NAME "_fdopen$UNIX2003"
# define __FOPEN_NAME "_fopen$UNIX2003"
# define __FWRITE_NAME "_fwrite$UNIX2003"
# elif defined(__x86_64__)
+# define __FDOPEN_NAME "_fdopen"
# define __FOPEN_NAME "_fopen"
# define __FWRITE_NAME "_fwrite"
# elif defined(__arm)
+# define __FDOPEN_NAME "_fdopen"
# define __FOPEN_NAME "_fopen"
# define __FWRITE_NAME "_fwrite"
# else
@@ -40,9 +43,11 @@ typedef __SIZE_TYPE__ size_t;
# endif
#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
# if defined(__i386) || defined (__x86_64)
+# define __FDOPEN_NAME "_fdopen"
# define __FOPEN_NAME "_fopen"
# define __FWRITE_NAME "_fwrite"
# elif defined(__arm)
+# define __FDOPEN_NAME "_fdopen"
# define __FOPEN_NAME "_fopen"
# define __FWRITE_NAME "_fwrite"
# else
@@ -68,14 +73,13 @@ extern FILE *__stderrp;
int fclose(FILE *);
int fflush(FILE *);
FILE *fopen(const char * __restrict, const char * __restrict) __asm(__FOPEN_NAME);
+FILE *fdopen(int, const char *) __asm(__FDOPEN_NAME);
int fprintf(FILE * __restrict, const char * __restrict, ...);
size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict)
__asm(__FWRITE_NAME);
size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
long ftell(FILE *);
int fseek(FILE *, long, int);
-void setbuf(FILE * __restrict, char * __restrict);
-
int snprintf(char * __restrict, size_t, const char * __restrict, ...);
#if defined(__cplusplus)
diff --git a/SDKs/darwin/usr/include/stdlib.h b/SDKs/darwin/usr/include/stdlib.h
index 7c973dcc..b6d3171c 100644
--- a/SDKs/darwin/usr/include/stdlib.h
+++ b/SDKs/darwin/usr/include/stdlib.h
@@ -27,5 +27,6 @@ int atoi(const char *);
void free(void *);
char *getenv(const char *);
void *malloc(size_t);
+void *realloc(void *, size_t);
#endif /* __STDLIB_H__ */
diff --git a/SDKs/darwin/usr/include/sys/fcntl.h b/SDKs/darwin/usr/include/sys/fcntl.h
new file mode 100644
index 00000000..b71706bf
--- /dev/null
+++ b/SDKs/darwin/usr/include/sys/fcntl.h
@@ -0,0 +1,52 @@
+/* ===-- fcntl.h - stub SDK header for compiler-rt --------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ * ===-----------------------------------------------------------------------===
+ *
+ * This is a stub SDK header file. This file is not part of the interface of
+ * this library nor an official version of the appropriate SDK header. It is
+ * intended only to stub the features of this header required by compiler-rt.
+ *
+ * ===-----------------------------------------------------------------------===
+ */
+
+#ifndef _SYS_FCNTL_H_
+#define _SYS_FCNTL_H_
+
+/* Determine the appropriate open function. */
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
+# if defined(__i386)
+# define __OPEN_NAME "_open$UNIX2003"
+# elif defined(__x86_64__)
+# define __OPEN_NAME "_open"
+# elif defined(__arm)
+# define __OPEN_NAME "_open"
+# else
+# error "unrecognized architecture for targetting OS X"
+# endif
+#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
+# if defined(__i386) || defined (__x86_64)
+# define __OPEN_NAME "_open"
+# elif defined(__arm)
+# define __OPEN_NAME "_open"
+# else
+# error "unrecognized architecture for targetting iOS"
+# endif
+#else
+# error "unrecognized architecture for targetting Darwin"
+#endif
+
+#define O_RDONLY 0x0000 /* open for reading only */
+#define O_WRONLY 0x0001 /* open for writing only */
+#define O_RDWR 0x0002 /* open for reading and writing */
+#define O_ACCMODE 0x0003 /* mask for above modes */
+
+#define O_CREAT 0x0200 /* create if nonexistant */
+
+int open(const char *, int, ...) __asm(__OPEN_NAME);
+
+#endif /* !_SYS_FCNTL_H_ */
diff --git a/SDKs/darwin/usr/include/sys/mman.h b/SDKs/darwin/usr/include/sys/mman.h
new file mode 100644
index 00000000..84561f1b
--- /dev/null
+++ b/SDKs/darwin/usr/include/sys/mman.h
@@ -0,0 +1,42 @@
+/* ===-- mman.h - stub SDK header for compiler-rt ---------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ * ===-----------------------------------------------------------------------===
+ *
+ * This is a stub SDK header file. This file is not part of the interface of
+ * this library nor an official version of the appropriate SDK header. It is
+ * intended only to stub the features of this header required by compiler-rt.
+ *
+ * ===-----------------------------------------------------------------------===
+ */
+
+#ifndef __SYS_MMAN_H__
+#define __SYS_MMAN_H__
+
+typedef __SIZE_TYPE__ size_t;
+
+#define PROT_NONE 0x00
+#define PROT_READ 0x01
+#define PROT_WRITE 0x02
+#define PROT_EXEC 0x04
+
+#define MAP_SHARED 0x0001
+#define MAP_PRIVATE 0x0002
+
+#define MAP_FILE 0x0000
+#define MAP_ANON 0x1000
+
+#define MS_ASYNC 0x0001
+#define MS_INVALIDATE 0x0002
+#define MS_SYNC 0x0010
+
+void *mmap(void *addr, size_t len, int prot, int flags, int fd,
+ long long offset);
+int munmap(void *addr, size_t len);
+int msync(void *addr, size_t len, int flags);
+
+#endif /* __SYS_MMAN_H__ */