Chris Lattner | a9a3028 | 2003-10-28 18:56:51 +0000 | [diff] [blame] | 1 | /*===-- BlockProfiling.c - Support library for block profiling ------------===*\ |
| 2 | |* |
| 3 | |* The LLVM Compiler Infrastructure |
| 4 | |* |
| 5 | |* This file was developed by the LLVM research group and is distributed under |
| 6 | |* the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | |* |
| 8 | |*===----------------------------------------------------------------------===*| |
| 9 | |* |
| 10 | |* This file implements the call back routines for the block profiling |
| 11 | |* instrumentation pass. This should be used with the -insert-block-profiling |
| 12 | |* LLVM pass. |
| 13 | |* |
| 14 | \*===----------------------------------------------------------------------===*/ |
| 15 | |
| 16 | #include "Profiling.h" |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | static unsigned *ArrayStart; |
| 20 | static unsigned NumElements; |
| 21 | |
| 22 | /* BlockProfAtExitHandler - When the program exits, just write out the profiling |
| 23 | * data. |
| 24 | */ |
| 25 | static void BlockProfAtExitHandler() { |
Brian Gaeke | 40114b7 | 2004-05-04 16:51:46 +0000 | [diff] [blame] | 26 | /* Note that if this were doing something more intelligent with the |
| 27 | * instrumentation, we could do some computation here to expand what we |
| 28 | * collected into simple block profiles. (Or we could do it in llvm-prof.) |
| 29 | * Regardless, we directly count each block, so no expansion is necessary. |
| 30 | */ |
| 31 | write_profiling_data(BlockInfo, ArrayStart, NumElements); |
Chris Lattner | a9a3028 | 2003-10-28 18:56:51 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | |
| 35 | /* llvm_start_block_profiling - This is the main entry point of the block |
| 36 | * profiling library. It is responsible for setting up the atexit handler. |
| 37 | */ |
Chris Lattner | affce4f | 2004-02-10 17:36:25 +0000 | [diff] [blame] | 38 | int llvm_start_block_profiling(int argc, const char **argv, |
| 39 | unsigned *arrayStart, unsigned numElements) { |
| 40 | int Ret = save_arguments(argc, argv); |
Chris Lattner | a9a3028 | 2003-10-28 18:56:51 +0000 | [diff] [blame] | 41 | ArrayStart = arrayStart; |
| 42 | NumElements = numElements; |
| 43 | atexit(BlockProfAtExitHandler); |
Chris Lattner | affce4f | 2004-02-10 17:36:25 +0000 | [diff] [blame] | 44 | return Ret; |
Chris Lattner | a9a3028 | 2003-10-28 18:56:51 +0000 | [diff] [blame] | 45 | } |