[llvm-commits] CVS: llvm/runtime/libprofile/BasicBlockTracing.c BlockProfiling.c CommonProfiling.c EdgeProfiling.c FunctionProfiling.c Makefile Profiling.h exported_symbols.lst

Reid Spencer reid at x10sys.com
Thu Nov 16 19:33:10 PST 2006



Changes in directory llvm/runtime/libprofile:

BasicBlockTracing.c updated: 1.3 -> 1.4
BlockProfiling.c updated: 1.4 -> 1.5
CommonProfiling.c updated: 1.9 -> 1.10
EdgeProfiling.c updated: 1.3 -> 1.4
FunctionProfiling.c updated: 1.4 -> 1.5
Makefile updated: 1.9 -> 1.10
Profiling.h updated: 1.6 -> 1.7
exported_symbols.lst updated: 1.3 -> 1.4
---
Log message:

Undo removal of the runtime libraries. While this may have been a bit
premature, these libraries will be going away for the 2.0 release. Other
arrangements for profiling, gc, etc. should be made in the next few months.


---
Diffs of the changes:  (+371 -0)

 BasicBlockTracing.c  |   67 +++++++++++++++++++++++++++++
 BlockProfiling.c     |   45 +++++++++++++++++++
 CommonProfiling.c    |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++
 EdgeProfiling.c      |   45 +++++++++++++++++++
 FunctionProfiling.c  |   42 ++++++++++++++++++
 Makefile             |   19 ++++++++
 Profiling.h          |   31 +++++++++++++
 exported_symbols.lst |    5 ++
 8 files changed, 371 insertions(+)


Index: llvm/runtime/libprofile/BasicBlockTracing.c
diff -u /dev/null llvm/runtime/libprofile/BasicBlockTracing.c:1.4
--- /dev/null	Thu Nov 16 21:32:43 2006
+++ llvm/runtime/libprofile/BasicBlockTracing.c	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,67 @@
+/*===-- BasicBlockTracing.c - Support library for basic block tracing -----===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|* 
+|*===----------------------------------------------------------------------===*|
+|* 
+|* This file implements the call back routines for the basic block tracing
+|* instrumentation pass.  This should be used with the -trace-basic-blocks
+|* LLVM pass.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "Profiling.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+static unsigned *ArrayStart, *ArrayEnd, *ArrayCursor;
+
+/* WriteAndFlushBBTraceData - write out the currently accumulated trace data
+ * and reset the cursor to point to the beginning of the buffer.
+ */
+static void WriteAndFlushBBTraceData () {
+  write_profiling_data(BBTraceInfo, ArrayStart, (ArrayCursor - ArrayStart));
+  ArrayCursor = ArrayStart;
+}
+
+/* BBTraceAtExitHandler - When the program exits, just write out any remaining 
+ * data and free the trace buffer.
+ */
+static void BBTraceAtExitHandler() {
+  WriteAndFlushBBTraceData ();
+  free (ArrayStart);
+}
+
+/* llvm_trace_basic_block - called upon hitting a new basic block. */
+void llvm_trace_basic_block (unsigned BBNum) {
+  *ArrayCursor++ = BBNum;
+  if (ArrayCursor == ArrayEnd)
+    WriteAndFlushBBTraceData ();
+}
+
+/* llvm_start_basic_block_tracing - This is the main entry point of the basic
+ * block tracing library.  It is responsible for setting up the atexit
+ * handler and allocating the trace buffer.
+ */
+int llvm_start_basic_block_tracing(int argc, const char **argv,
+                              unsigned *arrayStart, unsigned numElements) {
+  int Ret;
+  const unsigned BufferSize = 128 * 1024;
+  unsigned ArraySize;
+
+  Ret = save_arguments(argc, argv);
+
+  /* Allocate a buffer to contain BB tracing data */
+  ArraySize = BufferSize / sizeof (unsigned);
+  ArrayStart = malloc (ArraySize * sizeof (unsigned));
+  ArrayEnd = ArrayStart + ArraySize;
+  ArrayCursor = ArrayStart;
+
+  /* Set up the atexit handler. */
+  atexit (BBTraceAtExitHandler);
+
+  return Ret;
+}


Index: llvm/runtime/libprofile/BlockProfiling.c
diff -u /dev/null llvm/runtime/libprofile/BlockProfiling.c:1.5
--- /dev/null	Thu Nov 16 21:33:09 2006
+++ llvm/runtime/libprofile/BlockProfiling.c	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,45 @@
+/*===-- BlockProfiling.c - Support library for block profiling ------------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|* 
+|*===----------------------------------------------------------------------===*|
+|* 
+|* This file implements the call back routines for the block profiling
+|* instrumentation pass.  This should be used with the -insert-block-profiling
+|* LLVM pass.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "Profiling.h"
+#include <stdlib.h>
+
+static unsigned *ArrayStart;
+static unsigned NumElements;
+
+/* BlockProfAtExitHandler - When the program exits, just write out the profiling
+ * data.
+ */
+static void BlockProfAtExitHandler() {
+  /* Note that if this were doing something more intelligent with the
+   * instrumentation, we could do some computation here to expand what we
+   * collected into simple block profiles. (Or we could do it in llvm-prof.)
+   * Regardless, we directly count each block, so no expansion is necessary.
+   */
+  write_profiling_data(BlockInfo, ArrayStart, NumElements);
+}
+
+
+/* llvm_start_block_profiling - This is the main entry point of the block
+ * profiling library.  It is responsible for setting up the atexit handler.
+ */
+int llvm_start_block_profiling(int argc, const char **argv,
+                               unsigned *arrayStart, unsigned numElements) {
+  int Ret = save_arguments(argc, argv);
+  ArrayStart = arrayStart;
+  NumElements = numElements;
+  atexit(BlockProfAtExitHandler);
+  return Ret;
+}


Index: llvm/runtime/libprofile/CommonProfiling.c
diff -u /dev/null llvm/runtime/libprofile/CommonProfiling.c:1.10
--- /dev/null	Thu Nov 16 21:33:09 2006
+++ llvm/runtime/libprofile/CommonProfiling.c	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,117 @@
+/*===-- CommonProfiling.c - Profiling support library support -------------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|* 
+|*===----------------------------------------------------------------------===*|
+|* 
+|* This file implements functions used by the various different types of
+|* profiling implementations.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "Profiling.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+static char *SavedArgs = 0;
+static unsigned SavedArgsLength = 0;
+
+static const char *OutputFilename = "llvmprof.out";
+
+/* save_arguments - Save argc and argv as passed into the program for the file
+ * we output.
+ */
+int save_arguments(int argc, const char **argv) {
+  unsigned Length, i;
+  if (SavedArgs || !argv) return argc;  /* This can be called multiple times */
+
+  /* Check to see if there are any arguments passed into the program for the
+   * profiler.  If there are, strip them off and remember their settings.
+   */
+  while (argc > 1 && !strncmp(argv[1], "-llvmprof-", 10)) {
+    /* Ok, we have an llvmprof argument.  Remove it from the arg list and decide
+     * what to do with it.
+     */
+    const char *Arg = argv[1];
+    memmove(&argv[1], &argv[2], (argc-1)*sizeof(char*));
+    --argc;
+
+    if (!strcmp(Arg, "-llvmprof-output")) {
+      if (argc == 1)
+        puts("-llvmprof-output requires a filename argument!");
+      else {
+        OutputFilename = strdup(argv[1]);
+        memmove(&argv[1], &argv[2], (argc-1)*sizeof(char*));
+        --argc;
+      }
+    } else {
+      printf("Unknown option to the profiler runtime: '%s' - ignored.\n", Arg);
+    }
+  }
+
+  for (Length = 0, i = 0; i != (unsigned)argc; ++i)
+    Length += strlen(argv[i])+1;
+
+  SavedArgs = (char*)malloc(Length);
+  for (Length = 0, i = 0; i != (unsigned)argc; ++i) {
+    unsigned Len = strlen(argv[i]);
+    memcpy(SavedArgs+Length, argv[i], Len);
+    Length += Len;
+    SavedArgs[Length++] = ' ';
+  }
+
+  SavedArgsLength = Length;
+
+  return argc;
+}
+
+
+/* write_profiling_data - Write a raw block of profiling counters out to the
+ * llvmprof.out file.  Note that we allow programs to be instrumented with
+ * multiple different kinds of instrumentation.  For this reason, this function
+ * may be called more than once.
+ */
+void write_profiling_data(enum ProfilingType PT, unsigned *Start,
+                          unsigned NumElements) {
+  static int OutFile = -1;
+  int PTy;
+  
+  /* If this is the first time this function is called, open the output file for
+   * appending, creating it if it does not already exist.
+   */
+  if (OutFile == -1) {
+    OutFile = open(OutputFilename, O_CREAT | O_WRONLY | O_APPEND, 0666);
+    if (OutFile == -1) {
+      fprintf(stderr, "LLVM profiling runtime: while opening '%s': ",
+              OutputFilename);
+      perror("");
+      return;
+    }
+
+    /* Output the command line arguments to the file. */
+    {
+      int PTy = ArgumentInfo;
+      int Zeros = 0;
+      write(OutFile, &PTy, sizeof(int));
+      write(OutFile, &SavedArgsLength, sizeof(unsigned));
+      write(OutFile, SavedArgs, SavedArgsLength);
+      /* Pad out to a multiple of four bytes */
+      if (SavedArgsLength & 3)
+        write(OutFile, &Zeros, 4-(SavedArgsLength&3));
+    }
+  }
+ 
+  /* Write out this record! */
+  PTy = PT;
+  write(OutFile, &PTy, sizeof(int));
+  write(OutFile, &NumElements, sizeof(unsigned));
+  write(OutFile, Start, NumElements*sizeof(unsigned));
+}


Index: llvm/runtime/libprofile/EdgeProfiling.c
diff -u /dev/null llvm/runtime/libprofile/EdgeProfiling.c:1.4
--- /dev/null	Thu Nov 16 21:33:09 2006
+++ llvm/runtime/libprofile/EdgeProfiling.c	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,45 @@
+/*===-- EdgeProfiling.c - Support library for edge profiling --------------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|* 
+|*===----------------------------------------------------------------------===*|
+|* 
+|* This file implements the call back routines for the edge profiling
+|* instrumentation pass.  This should be used with the -insert-edge-profiling
+|* LLVM pass.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "Profiling.h"
+#include <stdlib.h>
+
+static unsigned *ArrayStart;
+static unsigned NumElements;
+
+/* EdgeProfAtExitHandler - When the program exits, just write out the profiling
+ * data.
+ */
+static void EdgeProfAtExitHandler() {
+  /* Note that if this were doing something more intelligent with the
+   * instrumentation, we could do some computation here to expand what we
+   * collected into simple edge profiles.  Since we directly count each edge, we
+   * just write out all of the counters directly.
+   */
+  write_profiling_data(EdgeInfo, ArrayStart, NumElements);
+}
+
+
+/* llvm_start_edge_profiling - This is the main entry point of the edge
+ * profiling library.  It is responsible for setting up the atexit handler.
+ */
+int llvm_start_edge_profiling(int argc, const char **argv,
+                              unsigned *arrayStart, unsigned numElements) {
+  int Ret = save_arguments(argc, argv);
+  ArrayStart = arrayStart;
+  NumElements = numElements;
+  atexit(EdgeProfAtExitHandler);
+  return Ret;
+}


Index: llvm/runtime/libprofile/FunctionProfiling.c
diff -u /dev/null llvm/runtime/libprofile/FunctionProfiling.c:1.5
--- /dev/null	Thu Nov 16 21:33:09 2006
+++ llvm/runtime/libprofile/FunctionProfiling.c	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,42 @@
+/*===-- FunctionProfiling.c - Support library for function profiling ------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|* 
+|*===----------------------------------------------------------------------===*|
+|* 
+|* This file implements the call back routines for the function profiling
+|* instrumentation pass.  This should be used with the
+|* -insert-function-profiling LLVM pass.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "Profiling.h"
+#include <stdlib.h>
+
+static unsigned *ArrayStart;
+static unsigned NumElements;
+
+/* FuncProfAtExitHandler - When the program exits, just write out the profiling
+ * data.
+ */
+static void FuncProfAtExitHandler() {
+  /* Just write out the data we collected.
+   */
+  write_profiling_data(FunctionInfo, ArrayStart, NumElements);
+}
+
+
+/* llvm_start_func_profiling - This is the main entry point of the function
+ * profiling library.  It is responsible for setting up the atexit handler.
+ */
+int llvm_start_func_profiling(int argc, const char **argv,
+                              unsigned *arrayStart, unsigned numElements) {
+  int Ret = save_arguments(argc, argv);
+  ArrayStart = arrayStart;
+  NumElements = numElements;
+  atexit(FuncProfAtExitHandler);
+  return Ret;
+}


Index: llvm/runtime/libprofile/Makefile
diff -u /dev/null llvm/runtime/libprofile/Makefile:1.10
--- /dev/null	Thu Nov 16 21:33:10 2006
+++ llvm/runtime/libprofile/Makefile	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,19 @@
+##===- runtime/libprofile/Makefile -------------------------*- Makefile -*-===##
+# 
+#                     The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+# 
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+BYTECODE_LIBRARY = 1
+SHARED_LIBRARY = 1
+LOADABLE_MODULE = 1
+LIBRARYNAME = profile_rt
+EXTRA_DIST = exported_symbols.lst
+EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/exported_symbols.lst
+BYTECODE_DESTINATION = $(CFERuntimeLibDir)
+
+include $(LEVEL)/Makefile.common


Index: llvm/runtime/libprofile/Profiling.h
diff -u /dev/null llvm/runtime/libprofile/Profiling.h:1.7
--- /dev/null	Thu Nov 16 21:33:10 2006
+++ llvm/runtime/libprofile/Profiling.h	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,31 @@
+/*===-- Profiling.h - Profiling support library support routines --*- C -*-===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file was developed by the LLVM research group and is distributed under
+|* the University of Illinois Open Source License. See LICENSE.TXT for details.
+|*
+|*===----------------------------------------------------------------------===*|
+|*
+|* This file defines functions shared by the various different profiling
+|* implementations.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#ifndef PROFILING_H
+#define PROFILING_H
+
+#include "llvm/Analysis/ProfileInfoTypes.h" /* for enum ProfilingType */
+
+/* save_arguments - Save argc and argv as passed into the program for the file
+ * we output.
+ */
+int save_arguments(int argc, const char **argv);
+
+/* write_profiling_data - Write out a typed packet of profiling data to the
+ * current output file.
+ */
+void write_profiling_data(enum ProfilingType PT, unsigned *Start,
+                          unsigned NumElements);
+
+#endif


Index: llvm/runtime/libprofile/exported_symbols.lst
diff -u /dev/null llvm/runtime/libprofile/exported_symbols.lst:1.4
--- /dev/null	Thu Nov 16 21:33:10 2006
+++ llvm/runtime/libprofile/exported_symbols.lst	Thu Nov 16 21:32:33 2006
@@ -0,0 +1,5 @@
+
+llvm_start_func_profiling
+llvm_start_block_profiling
+llvm_start_basic_block_tracing
+llvm_trace_basic_block






More information about the llvm-commits mailing list