blob: 8d010df28f18b4ec53000fda0fe2cfb440076062 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001/*===- 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")))
14uint64_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")))
37uint64_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")))
43void __llvm_profile_reset_counters(void) {
Stephen Hines6d186232014-11-26 17:56:19 -080044 uint64_t *I = __llvm_profile_begin_counters();
45 uint64_t *E = __llvm_profile_end_counters();
Stephen Hines2d1fdb22014-05-28 23:58:16 -070046
47 memset(I, 0, sizeof(uint64_t)*(E - I));
48}