1 /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\ 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 12 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) 13 14 #include <stdlib.h> 15 16 static const __llvm_profile_data *DataFirst = NULL; 17 static const __llvm_profile_data *DataLast = NULL; 18 static const char *NamesFirst = NULL; 19 static const char *NamesLast = NULL; 20 static uint64_t *CountersFirst = NULL; 21 static uint64_t *CountersLast = NULL; 22 23 static const void *getMinAddr(const void *A1, const void *A2) { 24 return A1 < A2 ? A1 : A2; 25 } 26 27 static const void *getMaxAddr(const void *A1, const void *A2) { 28 return A1 > A2 ? A1 : A2; 29 } 30 31 /*! 32 * \brief Register an instrumented function. 33 * 34 * Calls to this are emitted by clang with -fprofile-instr-generate. Such 35 * calls are only required (and only emitted) on targets where we haven't 36 * implemented linker magic to find the bounds of the sections. 37 */ 38 COMPILER_RT_VISIBILITY 39 void __llvm_profile_register_function(void *Data_) { 40 /* TODO: Only emit this function if we can't use linker magic. */ 41 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; 42 if (!DataFirst) { 43 DataFirst = Data; 44 DataLast = Data + 1; 45 CountersFirst = Data->CounterPtr; 46 CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters; 47 return; 48 } 49 50 DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data); 51 CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr); 52 53 DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1); 54 CountersLast = (uint64_t *)getMaxAddr( 55 CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters); 56 } 57 58 COMPILER_RT_VISIBILITY 59 void __llvm_profile_register_names_function(void *NamesStart, 60 uint64_t NamesSize) { 61 if (!NamesFirst) { 62 NamesFirst = (const char *)NamesStart; 63 NamesLast = (const char *)NamesStart + NamesSize; 64 return; 65 } 66 NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart); 67 NamesLast = 68 (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize); 69 } 70 71 COMPILER_RT_VISIBILITY 72 const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } 73 COMPILER_RT_VISIBILITY 74 const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } 75 COMPILER_RT_VISIBILITY 76 const char *__llvm_profile_begin_names(void) { return NamesFirst; } 77 COMPILER_RT_VISIBILITY 78 const char *__llvm_profile_end_names(void) { return NamesLast; } 79 COMPILER_RT_VISIBILITY 80 uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } 81 COMPILER_RT_VISIBILITY 82 uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } 83 84 COMPILER_RT_VISIBILITY 85 ValueProfNode *__llvm_profile_begin_vnodes(void) { 86 return 0; 87 } 88 COMPILER_RT_VISIBILITY 89 ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; } 90 91 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0; 92 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0; 93 94 #endif 95