1 /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\ 2 |* 3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 |* See https://llvm.org/LICENSE.txt for license information. 5 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 |* 7 \*===----------------------------------------------------------------------===*/ 8 9 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \ 10 !(defined(__sun__) && defined(__svr4__)) && !defined(__NetBSD__) && \ 11 !defined(_WIN32) 12 13 #include <stdlib.h> 14 #include <stdio.h> 15 16 #include "InstrProfiling.h" 17 18 static const __llvm_profile_data *DataFirst = NULL; 19 static const __llvm_profile_data *DataLast = NULL; 20 static const char *NamesFirst = NULL; 21 static const char *NamesLast = NULL; 22 static uint64_t *CountersFirst = NULL; 23 static uint64_t *CountersLast = NULL; 24 static uint32_t *OrderFileFirst = NULL; 25 26 static const void *getMinAddr(const void *A1, const void *A2) { 27 return A1 < A2 ? A1 : A2; 28 } 29 30 static const void *getMaxAddr(const void *A1, const void *A2) { 31 return A1 > A2 ? A1 : A2; 32 } 33 34 /*! 35 * \brief Register an instrumented function. 36 * 37 * Calls to this are emitted by clang with -fprofile-instr-generate. Such 38 * calls are only required (and only emitted) on targets where we haven't 39 * implemented linker magic to find the bounds of the sections. 40 */ 41 COMPILER_RT_VISIBILITY 42 void __llvm_profile_register_function(void *Data_) { 43 /* TODO: Only emit this function if we can't use linker magic. */ 44 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; 45 if (!DataFirst) { 46 DataFirst = Data; 47 DataLast = Data + 1; 48 CountersFirst = Data->CounterPtr; 49 CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters; 50 return; 51 } 52 53 DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data); 54 CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr); 55 56 DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1); 57 CountersLast = (uint64_t *)getMaxAddr( 58 CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters); 59 } 60 61 COMPILER_RT_VISIBILITY 62 void __llvm_profile_register_names_function(void *NamesStart, 63 uint64_t NamesSize) { 64 if (!NamesFirst) { 65 NamesFirst = (const char *)NamesStart; 66 NamesLast = (const char *)NamesStart + NamesSize; 67 return; 68 } 69 NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart); 70 NamesLast = 71 (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize); 72 } 73 74 COMPILER_RT_VISIBILITY 75 const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } 76 COMPILER_RT_VISIBILITY 77 const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } 78 COMPILER_RT_VISIBILITY 79 const char *__llvm_profile_begin_names(void) { return NamesFirst; } 80 COMPILER_RT_VISIBILITY 81 const char *__llvm_profile_end_names(void) { return NamesLast; } 82 COMPILER_RT_VISIBILITY 83 uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } 84 COMPILER_RT_VISIBILITY 85 uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } 86 /* TODO: correctly set up OrderFileFirst. */ 87 COMPILER_RT_VISIBILITY 88 uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; } 89 90 COMPILER_RT_VISIBILITY 91 ValueProfNode *__llvm_profile_begin_vnodes(void) { 92 return 0; 93 } 94 COMPILER_RT_VISIBILITY 95 ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; } 96 97 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0; 98 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0; 99 100 #endif 101