| 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(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \ |
| 11 | !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) && \ |
| 12 | !defined(__wasm__) && !defined(__HAIKU__) |
| 13 | |
| 14 | #include <stdlib.h> |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | #include "InstrProfiling.h" |
| 18 | #include "InstrProfilingInternal.h" |
| 19 | |
| 20 | static const __llvm_profile_data *DataFirst = NULL; |
| 21 | static const __llvm_profile_data *DataLast = NULL; |
| 22 | static const VTableProfData *VTableProfDataFirst = NULL; |
| 23 | static const VTableProfData *VTableProfDataLast = NULL; |
| 24 | static const char *NamesFirst = NULL; |
| 25 | static const char *NamesLast = NULL; |
| 26 | static const char *VNamesFirst = NULL; |
| 27 | static const char *VNamesLast = NULL; |
| 28 | static char *CountersFirst = NULL; |
| 29 | static char *CountersLast = NULL; |
| 30 | |
| 31 | static const void *getMinAddr(const void *A1, const void *A2) { |
| 32 | return A1 < A2 ? A1 : A2; |
| 33 | } |
| 34 | |
| 35 | static const void *getMaxAddr(const void *A1, const void *A2) { |
| 36 | return A1 > A2 ? A1 : A2; |
| 37 | } |
| 38 | |
| 39 | /*! |
| 40 | * \brief Register an instrumented function. |
| 41 | * |
| 42 | * Calls to this are emitted by clang with -fprofile-instr-generate. Such |
| 43 | * calls are only required (and only emitted) on targets where we haven't |
| 44 | * implemented linker magic to find the bounds of the sections. |
| 45 | */ |
| 46 | COMPILER_RT_VISIBILITY |
| 47 | void __llvm_profile_register_function(void *Data_) { |
| 48 | /* TODO: Only emit this function if we can't use linker magic. */ |
| 49 | const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; |
| 50 | if (!DataFirst) { |
| 51 | DataFirst = Data; |
| 52 | DataLast = Data + 1; |
| 53 | CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr); |
| 54 | CountersLast = |
| 55 | CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size(); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data); |
| 60 | CountersFirst = (char *)getMinAddr( |
| 61 | CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr)); |
| 62 | |
| 63 | DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1); |
| 64 | CountersLast = (char *)getMaxAddr( |
| 65 | CountersLast, |
| 66 | (char *)((uintptr_t)Data_ + Data->CounterPtr) + |
| 67 | Data->NumCounters * __llvm_profile_counter_entry_size()); |
| 68 | } |
| 69 | |
| 70 | COMPILER_RT_VISIBILITY |
| 71 | void __llvm_profile_register_names_function(void *NamesStart, |
| 72 | uint64_t NamesSize) { |
| 73 | if (!NamesFirst) { |
| 74 | NamesFirst = (const char *)NamesStart; |
| 75 | NamesLast = (const char *)NamesStart + NamesSize; |
| 76 | return; |
| 77 | } |
| 78 | NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart); |
| 79 | NamesLast = |
| 80 | (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize); |
| 81 | } |
| 82 | |
| 83 | COMPILER_RT_VISIBILITY |
| 84 | const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } |
| 85 | COMPILER_RT_VISIBILITY |
| 86 | const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } |
| 87 | COMPILER_RT_VISIBILITY const VTableProfData * |
| 88 | __llvm_profile_begin_vtables(void) { |
| 89 | return VTableProfDataFirst; |
| 90 | } |
| 91 | COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) { |
| 92 | return VTableProfDataLast; |
| 93 | } |
| 94 | COMPILER_RT_VISIBILITY |
| 95 | const char *__llvm_profile_begin_names(void) { return NamesFirst; } |
| 96 | COMPILER_RT_VISIBILITY |
| 97 | const char *__llvm_profile_end_names(void) { return NamesLast; } |
| 98 | COMPILER_RT_VISIBILITY |
| 99 | const char *__llvm_profile_begin_vtabnames(void) { return VNamesFirst; } |
| 100 | COMPILER_RT_VISIBILITY |
| 101 | const char *__llvm_profile_end_vtabnames(void) { return VNamesLast; } |
| 102 | COMPILER_RT_VISIBILITY |
| 103 | char *__llvm_profile_begin_counters(void) { return CountersFirst; } |
| 104 | COMPILER_RT_VISIBILITY |
| 105 | char *__llvm_profile_end_counters(void) { return CountersLast; } |
| 106 | COMPILER_RT_VISIBILITY |
| 107 | char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; } |
| 108 | COMPILER_RT_VISIBILITY |
| 109 | char *__llvm_profile_end_bitmap(void) { return BitmapLast; } |
| 110 | |
| 111 | COMPILER_RT_VISIBILITY |
| 112 | ValueProfNode *__llvm_profile_begin_vnodes(void) { |
| 113 | return 0; |
| 114 | } |
| 115 | COMPILER_RT_VISIBILITY |
| 116 | ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; } |
| 117 | |
| 118 | COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0; |
| 119 | COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0; |
| 120 | |
| 121 | COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) { |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | #endif |
| 126 | |