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