/3rd_party/llvm/runtime/libprofile/EdgeProfiling.c

https://code.google.com/p/softart/ · C · 45 lines · 15 code · 5 blank · 25 comment · 0 complexity · 8426cd88ff8c7bfe779392f4924f57ba MD5 · raw file

  1. /*===-- EdgeProfiling.c - Support library for 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 -insert-edge-profiling
  12. |* LLVM pass.
  13. |*
  14. \*===----------------------------------------------------------------------===*/
  15. #include "Profiling.h"
  16. #include <stdlib.h>
  17. static unsigned *ArrayStart;
  18. static unsigned NumElements;
  19. /* EdgeProfAtExitHandler - When the program exits, just write out the profiling
  20. * data.
  21. */
  22. static void EdgeProfAtExitHandler(void) {
  23. /* Note that if this were doing something more intelligent with the
  24. * instrumentation, we could do some computation here to expand what we
  25. * collected into simple edge profiles. Since we directly count each edge, we
  26. * just write out all of the counters directly.
  27. */
  28. write_profiling_data(EdgeInfo, ArrayStart, NumElements);
  29. }
  30. /* llvm_start_edge_profiling - This is the main entry point of the edge
  31. * profiling library. It is responsible for setting up the atexit handler.
  32. */
  33. int llvm_start_edge_profiling(int argc, const char **argv,
  34. unsigned *arrayStart, unsigned numElements) {
  35. int Ret = save_arguments(argc, argv);
  36. ArrayStart = arrayStart;
  37. NumElements = numElements;
  38. atexit(EdgeProfAtExitHandler);
  39. return Ret;
  40. }