Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | /*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\ |
| 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 | #include "InstrProfiling.h" |
| 11 | #include <string.h> |
| 12 | |
| 13 | __attribute__((visibility("hidden"))) |
| 14 | uint64_t __llvm_profile_get_magic(void) { |
| 15 | /* Magic number to detect file format and endianness. |
| 16 | * |
| 17 | * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0, |
| 18 | * so that utilities, like strings, don't grab it as a string. 129 is also |
| 19 | * invalid UTF-8, and high enough to be interesting. |
| 20 | * |
| 21 | * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR" |
| 22 | * for 32-bit platforms. |
| 23 | */ |
| 24 | unsigned char R = sizeof(void *) == sizeof(uint64_t) ? 'r' : 'R'; |
| 25 | return |
| 26 | (uint64_t)255 << 56 | |
| 27 | (uint64_t)'l' << 48 | |
| 28 | (uint64_t)'p' << 40 | |
| 29 | (uint64_t)'r' << 32 | |
| 30 | (uint64_t)'o' << 24 | |
| 31 | (uint64_t)'f' << 16 | |
| 32 | (uint64_t) R << 8 | |
| 33 | (uint64_t)129; |
| 34 | } |
| 35 | |
| 36 | __attribute__((visibility("hidden"))) |
| 37 | uint64_t __llvm_profile_get_version(void) { |
| 38 | /* This should be bumped any time the output format changes. */ |
| 39 | return 1; |
| 40 | } |
| 41 | |
| 42 | __attribute__((visibility("hidden"))) |
| 43 | void __llvm_profile_reset_counters(void) { |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 44 | uint64_t *I = __llvm_profile_begin_counters(); |
| 45 | uint64_t *E = __llvm_profile_end_counters(); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 46 | |
| 47 | memset(I, 0, sizeof(uint64_t)*(E - I)); |
| 48 | } |