1 1.1.1.2 joerg /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\ 2 1.1 joerg |* 3 1.1 joerg |* The LLVM Compiler Infrastructure 4 1.1 joerg |* 5 1.1 joerg |* This file is distributed under the University of Illinois Open Source 6 1.1 joerg |* License. See LICENSE.TXT for details. 7 1.1 joerg |* 8 1.1 joerg \*===----------------------------------------------------------------------===*/ 9 1.1 joerg 10 1.1 joerg #include "InstrProfiling.h" 11 1.1 joerg 12 1.1.1.3 joerg #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) 13 1.1 joerg #include <stdlib.h> 14 1.1 joerg 15 1.1 joerg static const __llvm_profile_data *DataFirst = NULL; 16 1.1 joerg static const __llvm_profile_data *DataLast = NULL; 17 1.1 joerg static const char *NamesFirst = NULL; 18 1.1 joerg static const char *NamesLast = NULL; 19 1.1 joerg static uint64_t *CountersFirst = NULL; 20 1.1 joerg static uint64_t *CountersLast = NULL; 21 1.1 joerg 22 1.1 joerg /*! 23 1.1 joerg * \brief Register an instrumented function. 24 1.1 joerg * 25 1.1 joerg * Calls to this are emitted by clang with -fprofile-instr-generate. Such 26 1.1 joerg * calls are only required (and only emitted) on targets where we haven't 27 1.1 joerg * implemented linker magic to find the bounds of the sections. 28 1.1 joerg */ 29 1.1.1.3 joerg COMPILER_RT_VISIBILITY 30 1.1 joerg void __llvm_profile_register_function(void *Data_) { 31 1.1 joerg /* TODO: Only emit this function if we can't use linker magic. */ 32 1.1.1.3 joerg const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; 33 1.1 joerg if (!DataFirst) { 34 1.1 joerg DataFirst = Data; 35 1.1 joerg DataLast = Data + 1; 36 1.1.1.3 joerg NamesFirst = Data->NamePtr; 37 1.1.1.3 joerg NamesLast = (const char *)Data->NamePtr + Data->NameSize; 38 1.1.1.3 joerg CountersFirst = Data->CounterPtr; 39 1.1.1.3 joerg CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters; 40 1.1 joerg return; 41 1.1 joerg } 42 1.1 joerg 43 1.1.1.3 joerg #define UPDATE_FIRST(First, New) First = New < First ? New : First 44 1.1 joerg UPDATE_FIRST(DataFirst, Data); 45 1.1.1.3 joerg UPDATE_FIRST(NamesFirst, (const char *)Data->NamePtr); 46 1.1.1.3 joerg UPDATE_FIRST(CountersFirst, (uint64_t *)Data->CounterPtr); 47 1.1 joerg #undef UPDATE_FIRST 48 1.1 joerg 49 1.1.1.3 joerg #define UPDATE_LAST(Last, New) Last = New > Last ? New : Last 50 1.1 joerg UPDATE_LAST(DataLast, Data + 1); 51 1.1.1.3 joerg UPDATE_LAST(NamesLast, (const char *)Data->NamePtr + Data->NameSize); 52 1.1.1.3 joerg UPDATE_LAST(CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters); 53 1.1 joerg #undef UPDATE_LAST 54 1.1 joerg } 55 1.1 joerg 56 1.1.1.3 joerg COMPILER_RT_VISIBILITY 57 1.1.1.3 joerg const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } 58 1.1.1.3 joerg COMPILER_RT_VISIBILITY 59 1.1.1.3 joerg const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } 60 1.1.1.3 joerg COMPILER_RT_VISIBILITY 61 1.1.1.3 joerg const char *__llvm_profile_begin_names(void) { return NamesFirst; } 62 1.1.1.3 joerg COMPILER_RT_VISIBILITY 63 1.1.1.3 joerg const char *__llvm_profile_end_names(void) { return NamesLast; } 64 1.1.1.3 joerg COMPILER_RT_VISIBILITY 65 1.1.1.3 joerg uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } 66 1.1.1.3 joerg COMPILER_RT_VISIBILITY 67 1.1.1.3 joerg uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } 68 1.1 joerg #endif 69