diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-10-02 15:42:23 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-10-02 15:42:23 +0000 |
commit | dd5d86d992eb129ecd0bb013d2db2d6a0e8d2605 (patch) | |
tree | e408dd567e473235623fc853b5b993ea47cf0ce4 /runtime | |
parent | 6ffce6fa9295699078f81fabb9ca32f6f22bdf09 (diff) | |
download | external_llvm-dd5d86d992eb129ecd0bb013d2db2d6a0e8d2605.tar.gz external_llvm-dd5d86d992eb129ecd0bb013d2db2d6a0e8d2605.tar.bz2 external_llvm-dd5d86d992eb129ecd0bb013d2db2d6a0e8d2605.zip |
Remove the very substantial, largely unmaintained legacy PGO
infrastructure.
This was essentially work toward PGO based on a design that had several
flaws, partially dating from a time when LLVM had a different
architecture, and with an effort to modernize it abandoned without being
completed. Since then, it has bitrotted for several years further. The
result is nearly unusable, and isn't helping any of the modern PGO
efforts. Instead, it is getting in the way, adding confusion about PGO
in LLVM and distracting everyone with maintenance on essentially dead
code. Removing it paves the way for modern efforts around PGO.
Among other effects, this removes the last of the runtime libraries from
LLVM. Those are being developed in the separate 'compiler-rt' project
now, with somewhat different licensing specifically more approriate for
runtimes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191835 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/CMakeLists.txt | 5 | ||||
-rw-r--r-- | runtime/LLVMBuild.txt | 21 | ||||
-rw-r--r-- | runtime/Makefile | 25 | ||||
-rw-r--r-- | runtime/README.txt | 4 | ||||
-rw-r--r-- | runtime/libprofile/BasicBlockTracing.c | 67 | ||||
-rw-r--r-- | runtime/libprofile/CMakeLists.txt | 19 | ||||
-rw-r--r-- | runtime/libprofile/CommonProfiling.c | 173 | ||||
-rw-r--r-- | runtime/libprofile/EdgeProfiling.c | 45 | ||||
-rw-r--r-- | runtime/libprofile/Makefile | 52 | ||||
-rw-r--r-- | runtime/libprofile/OptimalEdgeProfiling.c | 45 | ||||
-rw-r--r-- | runtime/libprofile/PathProfiling.c | 270 | ||||
-rw-r--r-- | runtime/libprofile/Profiling.h | 36 |
12 files changed, 0 insertions, 762 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt deleted file mode 100644 index 502b91dc58..0000000000 --- a/runtime/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -if( NOT LLVM_BUILD_RUNTIME ) - set(EXCLUDE_FROM_ALL ON) -endif() - -add_subdirectory(libprofile) diff --git a/runtime/LLVMBuild.txt b/runtime/LLVMBuild.txt deleted file mode 100644 index 05334fda50..0000000000 --- a/runtime/LLVMBuild.txt +++ /dev/null @@ -1,21 +0,0 @@ -;===- ./runtime/LLVMBuild.txt ----------------------------------*- Conf -*--===; -; -; The LLVM Compiler Infrastructure -; -; This file is distributed under the University of Illinois Open Source -; License. See LICENSE.TXT for details. -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[component_0] -type = Group -name = Runtime -parent = $ROOT diff --git a/runtime/Makefile b/runtime/Makefile deleted file mode 100644 index 6a6c6610a7..0000000000 --- a/runtime/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -##===- runtime/Makefile ------------------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL = .. -include $(LEVEL)/Makefile.config - -ifndef NO_RUNTIME_LIBS - -PARALLEL_DIRS := libprofile - -ifeq ($(TARGET_OS), $(filter $(TARGET_OS), Cygwin MingW Minix)) -PARALLEL_DIRS := $(filter-out libprofile, $(PARALLEL_DIRS)) -endif - -endif - -include $(LEVEL)/Makefile.common - -install:: diff --git a/runtime/README.txt b/runtime/README.txt deleted file mode 100644 index 2e2e547de3..0000000000 --- a/runtime/README.txt +++ /dev/null @@ -1,4 +0,0 @@ -This directory contains the various runtime libraries used by components of -the LLVM compiler. For example, the automatic pool allocation transformation -inserts calls to an external pool allocator library. This runtime library is -an example of the type of library that lives in these directories. diff --git a/runtime/libprofile/BasicBlockTracing.c b/runtime/libprofile/BasicBlockTracing.c deleted file mode 100644 index 0815e2e516..0000000000 --- a/runtime/libprofile/BasicBlockTracing.c +++ /dev/null @@ -1,67 +0,0 @@ -/*===-- BasicBlockTracing.c - Support library for basic block tracing -----===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file 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(void) { - 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; -} diff --git a/runtime/libprofile/CMakeLists.txt b/runtime/libprofile/CMakeLists.txt deleted file mode 100644 index 9044f768e1..0000000000 --- a/runtime/libprofile/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -set(SOURCES - BasicBlockTracing.c - CommonProfiling.c - PathProfiling.c - EdgeProfiling.c - OptimalEdgeProfiling.c - Profiling.h - ) - -add_llvm_library( profile_rt-static ${SOURCES} ) -set_target_properties( profile_rt-static - PROPERTIES - OUTPUT_NAME "profile_rt" ) - -set(BUILD_SHARED_LIBS ON) -add_llvm_library( profile_rt-shared ${SOURCES} ) -set_target_properties( profile_rt-shared - PROPERTIES - OUTPUT_NAME "profile_rt" ) diff --git a/runtime/libprofile/CommonProfiling.c b/runtime/libprofile/CommonProfiling.c deleted file mode 100644 index 8f4119c2c6..0000000000 --- a/runtime/libprofile/CommonProfiling.c +++ /dev/null @@ -1,173 +0,0 @@ -/*===-- CommonProfiling.c - Profiling support library support -------------===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file 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 <assert.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdio.h> -#include <string.h> -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include <unistd.h> -#else -#include <io.h> -#endif -#include <stdlib.h> - -static char *SavedArgs = 0; -static unsigned SavedArgsLength = 0; -static const char *SavedEnvVar = 0; - -static const char *OutputFilename = "llvmprof.out"; - -/* check_environment_variable - Check to see if the LLVMPROF_OUTPUT environment - * variable is set. If it is then save it and set OutputFilename. - */ -static void check_environment_variable(void) { - const char *EnvVar; - if (SavedEnvVar) return; /* Guarantee that we can't leak memory. */ - - if ((EnvVar = getenv("LLVMPROF_OUTPUT")) != NULL) { - /* The string that getenv returns is allowed to be statically allocated, - * which means it may be changed by future calls to getenv, so copy it. - */ - SavedEnvVar = strdup(EnvVar); - OutputFilename = SavedEnvVar; - } -} - -/* save_arguments - Save argc and argv as passed into the program for the file - * we output. - * If either the LLVMPROF_OUTPUT environment variable or the -llvmprof-output - * command line argument are set then change OutputFilename to the provided - * value. The command line argument value overrides the environment variable. - */ -int save_arguments(int argc, const char **argv) { - unsigned Length, i; - if (!SavedEnvVar && !SavedArgs) check_environment_variable(); - 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((char**)&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]); - if (SavedEnvVar) { free((void *)SavedEnvVar); SavedEnvVar = 0; } - memmove((char**)&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; - - /* Defensively check for a zero length, even though this is unlikely - * to happen in practice. This avoids calling malloc() below with a - * size of 0. - */ - if (Length == 0) { - SavedArgs = 0; - SavedArgsLength = 0; - return argc; - } - - 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; -} - - -/* - * Retrieves the file descriptor for the profile file. - */ -int getOutFile() { - static int OutFile = -1; - - /* 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, 0666); - lseek(OutFile, 0, SEEK_END); /* O_APPEND prevents seeking */ - if (OutFile == -1) { - fprintf(stderr, "LLVM profiling runtime: while opening '%s': ", - OutputFilename); - perror(""); - return(OutFile); - } - - /* Output the command line arguments to the file. */ - { - int PTy = ArgumentInfo; - int Zeros = 0; - if (write(OutFile, &PTy, sizeof(int)) < 0 || - write(OutFile, &SavedArgsLength, sizeof(unsigned)) < 0 || - write(OutFile, SavedArgs, SavedArgsLength) < 0 ) { - fprintf(stderr,"error: unable to write to output file."); - exit(0); - } - /* Pad out to a multiple of four bytes */ - if (SavedArgsLength & 3) { - if (write(OutFile, &Zeros, 4-(SavedArgsLength&3)) < 0) { - fprintf(stderr,"error: unable to write to output file."); - exit(0); - } - } - } - } - return(OutFile); -} - -/* 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) { - int PTy; - int outFile = getOutFile(); - - /* Write out this record! */ - PTy = PT; - if( write(outFile, &PTy, sizeof(int)) < 0 || - write(outFile, &NumElements, sizeof(unsigned)) < 0 || - write(outFile, Start, NumElements*sizeof(unsigned)) < 0 ) { - fprintf(stderr,"error: unable to write to output file."); - exit(0); - } -} diff --git a/runtime/libprofile/EdgeProfiling.c b/runtime/libprofile/EdgeProfiling.c deleted file mode 100644 index f19e188f0d..0000000000 --- a/runtime/libprofile/EdgeProfiling.c +++ /dev/null @@ -1,45 +0,0 @@ -/*===-- EdgeProfiling.c - Support library for edge profiling --------------===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file 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(void) { - /* 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; -} diff --git a/runtime/libprofile/Makefile b/runtime/libprofile/Makefile deleted file mode 100644 index 2f061adcd5..0000000000 --- a/runtime/libprofile/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -##===- runtime/libprofile/Makefile -------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL = ../.. -include $(LEVEL)/Makefile.config - -LIBRARYNAME = profile_rt -LINK_LIBS_IN_SHARED = 1 -SHARED_LIBRARY = 1 - -# Build and install this archive. -BUILD_ARCHIVE = 1 -override NO_INSTALL_ARCHIVES = - -include $(LEVEL)/Makefile.common - -ifeq ($(HOST_OS),Darwin) - # Special hack to allow libprofile_rt to have an offset version number. - PROFILE_RT_LIBRARY_VERSION := $(LLVM_SUBMIT_VERSION) - - # Set dylib internal version number to llvmCore submission number. - ifdef LLVM_SUBMIT_VERSION - LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \ - -Wl,$(PROFILE_RT_LIBRARY_VERSION).$(LLVM_SUBMIT_SUBVERSION) \ - -Wl,-compatibility_version -Wl,1 - endif - # Extra options to override libtool defaults. - LLVMLibsOptions := $(LLVMLibsOptions) \ - -Wl,-dead_strip - - # Mac OS X 10.4 and earlier tools do not allow a second -install_name on - # command line. - DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/') - ifneq ($(DARWIN_VERS),8) - LLVMLibsOptions := $(LLVMLibsOptions) \ - -Wl,-install_name \ - -Wl,"@rpath/lib$(LIBRARYNAME)$(SHLIBEXT)" - endif - - # If we're doing an Apple-style build, add the LTO object path. - ifeq ($(RC_XBS),YES) - TempFile := $(shell mkdir -p ${OBJROOT}/dSYMs ; mktemp ${OBJROOT}/dSYMs/profile_rt-lto.XXXXXX) - LLVMLibsOptions := $(LLVMLibsOptions) \ - -Wl,-object_path_lto -Wl,$(TempFile) - endif -endif diff --git a/runtime/libprofile/OptimalEdgeProfiling.c b/runtime/libprofile/OptimalEdgeProfiling.c deleted file mode 100644 index 3a7631b6e8..0000000000 --- a/runtime/libprofile/OptimalEdgeProfiling.c +++ /dev/null @@ -1,45 +0,0 @@ -/*===-- OptimalEdgeProfiling.c - Support library for opt. edge profiling --===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file 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-opt-edge-profiling LLVM pass. -|* -\*===----------------------------------------------------------------------===*/ - -#include "Profiling.h" -#include <stdlib.h> - -static unsigned *ArrayStart; -static unsigned NumElements; - -/* OptEdgeProfAtExitHandler - When the program exits, just write out the - * profiling data. - */ -static void OptEdgeProfAtExitHandler(void) { - /* Note that, although the array has a counter for each edge, not all - * counters are updated, the ones that are not used are initialised with -1. - * When loading this information the counters with value -1 have to be - * recalculated, it is guaranteed that this is possible. - */ - write_profiling_data(OptEdgeInfo, ArrayStart, NumElements); -} - - -/* llvm_start_opt_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_opt_edge_profiling(int argc, const char **argv, - unsigned *arrayStart, unsigned numElements) { - int Ret = save_arguments(argc, argv); - ArrayStart = arrayStart; - NumElements = numElements; - atexit(OptEdgeProfAtExitHandler); - return Ret; -} diff --git a/runtime/libprofile/PathProfiling.c b/runtime/libprofile/PathProfiling.c deleted file mode 100644 index 71ee944fc5..0000000000 --- a/runtime/libprofile/PathProfiling.c +++ /dev/null @@ -1,270 +0,0 @@ -/*===-- PathProfiling.c - Support library for path profiling --------------===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file is distributed under the University of Illinois Open Source -|* License. See LICENSE.TXT for details. -|* -|*===----------------------------------------------------------------------===*| -|* -|* This file implements the call back routines for the path profiling -|* instrumentation pass. This should be used with the -insert-path-profiling -|* LLVM pass. -|* -\*===----------------------------------------------------------------------===*/ - -#include "Profiling.h" -#include "llvm/Analysis/ProfileInfoTypes.h" -#include "llvm/Support/DataTypes.h" -#include <sys/types.h> -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include <unistd.h> -#else -#include <io.h> -#endif -#include <string.h> -#include <stdlib.h> -#include <stdio.h> - -/* note that this is used for functions with large path counts, - but it is unlikely those paths will ALL be executed */ -#define ARBITRARY_HASH_BIN_COUNT 100 - -typedef struct pathHashEntry_s { - uint32_t pathNumber; - uint32_t pathCount; - struct pathHashEntry_s* next; -} pathHashEntry_t; - -typedef struct pathHashTable_s { - pathHashEntry_t* hashBins[ARBITRARY_HASH_BIN_COUNT]; - uint32_t pathCounts; -} pathHashTable_t; - -typedef struct { - enum ProfilingStorageType type; - uint32_t size; - void* array; -} ftEntry_t; - -/* pointer to the function table allocated in the instrumented program */ -ftEntry_t* ft; -uint32_t ftSize; - -/* write an array table to file */ -void writeArrayTable(uint32_t fNumber, ftEntry_t* ft, uint32_t* funcCount) { - int outFile = getOutFile(); - uint32_t arrayHeaderLocation = 0; - uint32_t arrayCurrentLocation = 0; - uint32_t arrayIterator = 0; - uint32_t functionUsed = 0; - uint32_t pathCounts = 0; - - /* look through each entry in the array to determine whether the function - was executed at all */ - for( arrayIterator = 0; arrayIterator < ft->size; arrayIterator++ ) { - uint32_t pc = ((uint32_t*)ft->array)[arrayIterator]; - - /* was this path executed? */ - if( pc ) { - PathProfileTableEntry pte; - pte.pathNumber = arrayIterator; - pte.pathCounter = pc; - pathCounts++; - - /* one-time initialization stuff */ - if(!functionUsed) { - arrayHeaderLocation = lseek(outFile, 0, SEEK_CUR); - lseek(outFile, sizeof(PathProfileHeader), SEEK_CUR); - functionUsed = 1; - (*funcCount)++; - } - - /* write path data */ - if (write(outFile, &pte, sizeof(PathProfileTableEntry)) < 0) { - fprintf(stderr, "error: unable to write path entry to output file.\n"); - return; - } - } - } - - /* If this function was executed, write the header */ - if( functionUsed ) { - PathProfileHeader fHeader; - fHeader.fnNumber = fNumber; - fHeader.numEntries = pathCounts; - - arrayCurrentLocation = lseek(outFile, 0, SEEK_CUR); - lseek(outFile, arrayHeaderLocation, SEEK_SET); - - if (write(outFile, &fHeader, sizeof(PathProfileHeader)) < 0) { - fprintf(stderr, - "error: unable to write function header to output file.\n"); - return; - } - - lseek(outFile, arrayCurrentLocation, SEEK_SET); - } -} - -static uint32_t hash (uint32_t key) { - /* this may benefit from a proper hash function */ - return key%ARBITRARY_HASH_BIN_COUNT; -} - -/* output a specific function's hash table to the profile file */ -void writeHashTable(uint32_t functionNumber, pathHashTable_t* hashTable) { - int outFile = getOutFile(); - PathProfileHeader header; - uint32_t i; - - header.fnNumber = functionNumber; - header.numEntries = hashTable->pathCounts; - - if (write(outFile, &header, sizeof(PathProfileHeader)) < 0) { - fprintf(stderr, "error: unable to write function header to output file.\n"); - return; - } - - for (i = 0; i < ARBITRARY_HASH_BIN_COUNT; i++) { - pathHashEntry_t* hashEntry = hashTable->hashBins[i]; - - while (hashEntry) { - pathHashEntry_t* temp; - - PathProfileTableEntry pte; - pte.pathNumber = hashEntry->pathNumber; - pte.pathCounter = hashEntry->pathCount; - - if (write(outFile, &pte, sizeof(PathProfileTableEntry)) < 0) { - fprintf(stderr, "error: unable to write path entry to output file.\n"); - return; - } - - temp = hashEntry; - hashEntry = hashEntry->next; - free (temp); - - } - } -} - -/* Return a pointer to this path's specific path counter */ -static uint32_t* getPathCounter(uint32_t functionNumber, - uint32_t pathNumber) { - pathHashTable_t* hashTable; - pathHashEntry_t* hashEntry; - uint32_t index = hash(pathNumber); - - if( ft[functionNumber-1].array == 0) - ft[functionNumber-1].array = calloc(sizeof(pathHashTable_t), 1); - - hashTable = (pathHashTable_t*)((ftEntry_t*)ft)[functionNumber-1].array; - hashEntry = hashTable->hashBins[index]; - - while (hashEntry) { - if (hashEntry->pathNumber == pathNumber) { - return &hashEntry->pathCount; - } - - hashEntry = hashEntry->next; - } - - hashEntry = malloc(sizeof(pathHashEntry_t)); - hashEntry->pathNumber = pathNumber; - hashEntry->pathCount = 0; - hashEntry->next = hashTable->hashBins[index]; - hashTable->hashBins[index] = hashEntry; - hashTable->pathCounts++; - return &hashEntry->pathCount; -} - -/* Increment a specific path's count */ -void llvm_increment_path_count (uint32_t functionNumber, uint32_t pathNumber) { - uint32_t* pathCounter = getPathCounter(functionNumber, pathNumber); - if( *pathCounter < 0xffffffff ) - (*pathCounter)++; -} - -/* Increment a specific path's count */ -void llvm_decrement_path_count (uint32_t functionNumber, uint32_t pathNumber) { - uint32_t* pathCounter = getPathCounter(functionNumber, pathNumber); - (*pathCounter)--; -} - -/* - * Writes out a path profile given a function table, in the following format. - * - * - * | <-- 32 bits --> | - * +-----------------+-----------------+ - * 0x00 | profileType | functionCount | - * +-----------------+-----------------+ - * 0x08 | functionNum | profileEntries | // function 1 - * +-----------------+-----------------+ - * 0x10 | pathNumber | pathCounter | // entry 1.1 - * +-----------------+-----------------+ - * 0x18 | pathNumber | pathCounter | // entry 1.2 - * +-----------------+-----------------+ - * ... | ... | ... | // entry 1.n - * +-----------------+-----------------+ - * ... | functionNum | profileEntries | // function 2 - * +-----------------+-----------------+ - * ... | pathNumber | pathCounter | // entry 2.1 - * +-----------------+-----------------+ - * ... | pathNumber | pathCounter | // entry 2.2 - * +-----------------+-----------------+ - * ... | ... | ... | // entry 2.n - * +-----------------+-----------------+ - * - */ -static void pathProfAtExitHandler(void) { - int outFile = getOutFile(); - uint32_t i; - uint32_t header[2] = { PathInfo, 0 }; - uint32_t headerLocation; - uint32_t currentLocation; - - /* skip over the header for now */ - headerLocation = lseek(outFile, 0, SEEK_CUR); - lseek(outFile, 2*sizeof(uint32_t), SEEK_CUR); - - /* Iterate through each function */ - for( i = 0; i < ftSize; i++ ) { - if( ft[i].type == ProfilingArray ) { - writeArrayTable(i+1,&ft[i],header + 1); - - } else if( ft[i].type == ProfilingHash ) { - /* If the hash exists, write it to file */ - if( ft[i].array ) { - writeHashTable(i+1,ft[i].array); - header[1]++; - free(ft[i].array); - } - } - } - - /* Setup and write the path profile header */ - currentLocation = lseek(outFile, 0, SEEK_CUR); - lseek(outFile, headerLocation, SEEK_SET); - - if (write(outFile, header, sizeof(header)) < 0) { - fprintf(stderr, - "error: unable to write path profile header to output file.\n"); - return; - } - - lseek(outFile, currentLocation, SEEK_SET); -} -/* llvm_start_path_profiling - This is the main entry point of the path - * profiling library. It is responsible for setting up the atexit handler. - */ -int llvm_start_path_profiling(int argc, const char** argv, - void* functionTable, uint32_t numElements) { - int Ret = save_arguments(argc, argv); - ft = functionTable; - ftSize = numElements; - atexit(pathProfAtExitHandler); - - return Ret; -} diff --git a/runtime/libprofile/Profiling.h b/runtime/libprofile/Profiling.h deleted file mode 100644 index acc6399a18..0000000000 --- a/runtime/libprofile/Profiling.h +++ /dev/null @@ -1,36 +0,0 @@ -/*===-- Profiling.h - Profiling support library support routines ----------===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file 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/ProfileDataTypes.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); - -/* - * Retrieves the file descriptor for the profile file. - */ -int getOutFile(); - -/* 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 |