[profile] Eliminate dynamic memory allocation for buffered writer
With this change, dynamic memory allocation is only used
for testing purpose. This change is one of the many steps to
make instrument profiler dynamic allocation free.
llvm-svn: 269453
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 14f7517..e2f6800 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -32,18 +32,24 @@
COMPILER_RT_VISIBILITY ProfBufferIO *
lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) {
- CallocHook = calloc;
- FreeHook = free;
- return lprofCreateBufferIO(fileWriter, File, BufferSz);
+ FreeHook = &free;
+ DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1);
+ VPBufferSize = BufferSz;
+ return lprofCreateBufferIO(fileWriter, File);
+}
+
+static void setupIOBuffer() {
+ const char *BufferSzStr = 0;
+ BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE");
+ if (BufferSzStr && BufferSzStr[0]) {
+ VPBufferSize = atoi(BufferSzStr);
+ DynamicBufferIOBuffer = (uint8_t *)calloc(VPBufferSize, 1);
+ }
}
static int writeFile(FILE *File) {
- const char *BufferSzStr = 0;
FreeHook = &free;
- CallocHook = &calloc;
- BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE");
- if (BufferSzStr && BufferSzStr[0])
- VPBufferSize = atoi(BufferSzStr);
+ setupIOBuffer();
return lprofWriteData(fileWriter, File, lprofGatherValueProfData);
}