1 /*===-- BlockProfiling.c - Support library for block profiling ------------===*\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 |*===----------------------------------------------------------------------===*|
10 |* This file implements the call back routines for the block profiling
11 |* instrumentation pass. This should be used with the -insert-block-profiling
14 \*===----------------------------------------------------------------------===*/
16 #include "Profiling.h"
19 static unsigned *ArrayStart
;
20 static unsigned NumElements
;
22 /* BlockProfAtExitHandler - When the program exits, just write out the profiling
25 static void BlockProfAtExitHandler() {
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.
31 write_profiling_data(BlockInfo
, ArrayStart
, NumElements
);
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.
38 int llvm_start_block_profiling(int argc
, const char **argv
,
39 unsigned *arrayStart
, unsigned numElements
) {
40 int Ret
= save_arguments(argc
, argv
);
41 ArrayStart
= arrayStart
;
42 NumElements
= numElements
;
43 atexit(BlockProfAtExitHandler
);