eb7887b2aea92ed4b17c8d5b01584d7be30b46f4
[oota-llvm.git] / runtime / libprofile / OptimalEdgeProfiling.c
1 /*===-- OptimalEdgeProfiling.c - Support library for opt. edge profiling --===*\
2 |*
3 |*                     The LLVM Compiler Infrastructure
4 |*
5 |* This file is distributed under the University of Illinois Open Source      
6 |* License. See LICENSE.TXT for details.                                      
7 |* 
8 |*===----------------------------------------------------------------------===*|
9 |* 
10 |* This file implements the call back routines for the edge profiling
11 |* instrumentation pass.  This should be used with the
12 |* -insert-opt-edge-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 /* OptEdgeProfAtExitHandler - When the program exits, just write out the
23  * profiling data.
24  */
25 static void OptEdgeProfAtExitHandler() {
26   /* Note that, although the array has a counter for each edge, not all
27    * counters are updated, the ones that are not used are initialised with -1.
28    * When loading this information the counters with value -1 have to be
29    * recalculated, it is guranteed that this is possible.
30    */
31   write_profiling_data(OptEdgeInfo, ArrayStart, NumElements);
32 }
33
34
35 /* llvm_start_opt_edge_profiling - This is the main entry point of the edge
36  * profiling library.  It is responsible for setting up the atexit handler.
37  */
38 int llvm_start_opt_edge_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(OptEdgeProfAtExitHandler);
44   return Ret;
45 }