1*0a6a1f1dSLionel Sambuc /*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\ 2*0a6a1f1dSLionel Sambuc |* 3*0a6a1f1dSLionel Sambuc |* The LLVM Compiler Infrastructure 4*0a6a1f1dSLionel Sambuc |* 5*0a6a1f1dSLionel Sambuc |* This file is distributed under the University of Illinois Open Source 6*0a6a1f1dSLionel Sambuc |* License. See LICENSE.TXT for details. 7*0a6a1f1dSLionel Sambuc |* 8*0a6a1f1dSLionel Sambuc \*===----------------------------------------------------------------------===*/ 9*0a6a1f1dSLionel Sambuc 10*0a6a1f1dSLionel Sambuc #include "InstrProfiling.h" 11*0a6a1f1dSLionel Sambuc #include <string.h> 12*0a6a1f1dSLionel Sambuc 13*0a6a1f1dSLionel Sambuc __attribute__((visibility("hidden"))) __llvm_profile_get_magic(void)14*0a6a1f1dSLionel Sambucuint64_t __llvm_profile_get_magic(void) { 15*0a6a1f1dSLionel Sambuc /* Magic number to detect file format and endianness. 16*0a6a1f1dSLionel Sambuc * 17*0a6a1f1dSLionel Sambuc * Use 255 at one end, since no UTF-8 file can use that character. Avoid 0, 18*0a6a1f1dSLionel Sambuc * so that utilities, like strings, don't grab it as a string. 129 is also 19*0a6a1f1dSLionel Sambuc * invalid UTF-8, and high enough to be interesting. 20*0a6a1f1dSLionel Sambuc * 21*0a6a1f1dSLionel Sambuc * Use "lprofr" in the centre to stand for "LLVM Profile Raw", or "lprofR" 22*0a6a1f1dSLionel Sambuc * for 32-bit platforms. 23*0a6a1f1dSLionel Sambuc */ 24*0a6a1f1dSLionel Sambuc unsigned char R = sizeof(void *) == sizeof(uint64_t) ? 'r' : 'R'; 25*0a6a1f1dSLionel Sambuc return 26*0a6a1f1dSLionel Sambuc (uint64_t)255 << 56 | 27*0a6a1f1dSLionel Sambuc (uint64_t)'l' << 48 | 28*0a6a1f1dSLionel Sambuc (uint64_t)'p' << 40 | 29*0a6a1f1dSLionel Sambuc (uint64_t)'r' << 32 | 30*0a6a1f1dSLionel Sambuc (uint64_t)'o' << 24 | 31*0a6a1f1dSLionel Sambuc (uint64_t)'f' << 16 | 32*0a6a1f1dSLionel Sambuc (uint64_t) R << 8 | 33*0a6a1f1dSLionel Sambuc (uint64_t)129; 34*0a6a1f1dSLionel Sambuc } 35*0a6a1f1dSLionel Sambuc 36*0a6a1f1dSLionel Sambuc __attribute__((visibility("hidden"))) __llvm_profile_get_version(void)37*0a6a1f1dSLionel Sambucuint64_t __llvm_profile_get_version(void) { 38*0a6a1f1dSLionel Sambuc /* This should be bumped any time the output format changes. */ 39*0a6a1f1dSLionel Sambuc return 1; 40*0a6a1f1dSLionel Sambuc } 41*0a6a1f1dSLionel Sambuc 42*0a6a1f1dSLionel Sambuc __attribute__((visibility("hidden"))) __llvm_profile_reset_counters(void)43*0a6a1f1dSLionel Sambucvoid __llvm_profile_reset_counters(void) { 44*0a6a1f1dSLionel Sambuc uint64_t *I = __llvm_profile_counters_begin(); 45*0a6a1f1dSLionel Sambuc uint64_t *E = __llvm_profile_counters_end(); 46*0a6a1f1dSLionel Sambuc 47*0a6a1f1dSLionel Sambuc memset(I, 0, sizeof(uint64_t)*(E - I)); 48*0a6a1f1dSLionel Sambuc } 49