Reid Spencer | 8b2e141 | 2006-11-17 03:32:33 +0000 | [diff] [blame] | 1 | /*===-- FunctionProfiling.c - Support library for function profiling ------===*\ |
| 2 | |* |
| 3 | |* The LLVM Compiler Infrastructure |
| 4 | |* |
Chris Lattner | 234d529 | 2007-12-29 22:59:10 +0000 | [diff] [blame] | 5 | |* This file is distributed under the University of Illinois Open Source |
| 6 | |* License. See LICENSE.TXT for details. |
Reid Spencer | 8b2e141 | 2006-11-17 03:32:33 +0000 | [diff] [blame] | 7 | |* |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* |
| 10 | |* This file implements the call back routines for the function profiling |
| 11 | |* instrumentation pass. This should be used with the |
| 12 | |* -insert-function-profiling LLVM pass. |
| 13 | |* |
| 14 | \*===----------------------------------------------------------------------===*/ |
| 15 | |
| 16 | #include "Profiling.h" |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | static unsigned *ArrayStart; |
| 20 | static unsigned NumElements; |
| 21 | |
| 22 | /* FuncProfAtExitHandler - When the program exits, just write out the profiling |
| 23 | * data. |
| 24 | */ |
| 25 | static void FuncProfAtExitHandler() { |
| 26 | /* Just write out the data we collected. |
| 27 | */ |
| 28 | write_profiling_data(FunctionInfo, ArrayStart, NumElements); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /* llvm_start_func_profiling - This is the main entry point of the function |
| 33 | * profiling library. It is responsible for setting up the atexit handler. |
| 34 | */ |
| 35 | int llvm_start_func_profiling(int argc, const char **argv, |
| 36 | unsigned *arrayStart, unsigned numElements) { |
| 37 | int Ret = save_arguments(argc, argv); |
| 38 | ArrayStart = arrayStart; |
| 39 | NumElements = numElements; |
| 40 | atexit(FuncProfAtExitHandler); |
| 41 | return Ret; |
| 42 | } |