1 /*===- InstrProfilingPlatformOther.c - Profile data default platfrom ------===*\ 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 <stdlib.h> 12 13 static const __llvm_profile_data *DataFirst = NULL; 14 static const __llvm_profile_data *DataLast = NULL; 15 static const char *NamesFirst = NULL; 16 static const char *NamesLast = NULL; 17 static uint64_t *CountersFirst = NULL; 18 static uint64_t *CountersLast = NULL; 19 20 /*! 21 * \brief Register an instrumented function. 22 * 23 * Calls to this are emitted by clang with -fprofile-instr-generate. Such 24 * calls are only required (and only emitted) on targets where we haven't 25 * implemented linker magic to find the bounds of the sections. 26 */ 27 void __llvm_profile_register_function(void *Data_) { 28 /* TODO: Only emit this function if we can't use linker magic. */ 29 const __llvm_profile_data *Data = (__llvm_profile_data*)Data_; 30 if (!DataFirst) { 31 DataFirst = Data; 32 DataLast = Data + 1; 33 NamesFirst = Data->Name; 34 NamesLast = Data->Name + Data->NameSize; 35 CountersFirst = Data->Counters; 36 CountersLast = Data->Counters + Data->NumCounters; 37 return; 38 } 39 40 #define UPDATE_FIRST(First, New) \ 41 First = New < First ? New : First 42 UPDATE_FIRST(DataFirst, Data); 43 UPDATE_FIRST(NamesFirst, Data->Name); 44 UPDATE_FIRST(CountersFirst, Data->Counters); 45 #undef UPDATE_FIRST 46 47 #define UPDATE_LAST(Last, New) \ 48 Last = New > Last ? New : Last 49 UPDATE_LAST(DataLast, Data + 1); 50 UPDATE_LAST(NamesLast, Data->Name + Data->NameSize); 51 UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters); 52 #undef UPDATE_LAST 53 } 54 55 const __llvm_profile_data *__llvm_profile_data_begin(void) { 56 return DataFirst; 57 } 58 const __llvm_profile_data *__llvm_profile_data_end(void) { 59 return DataLast; 60 } 61 const char *__llvm_profile_names_begin(void) { return NamesFirst; } 62 const char *__llvm_profile_names_end(void) { return NamesLast; } 63 uint64_t *__llvm_profile_counters_begin(void) { return CountersFirst; } 64 uint64_t *__llvm_profile_counters_end(void) { return CountersLast; } 65