1 /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\
3 |* The LLVM Compiler Infrastructure
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
8 \*===----------------------------------------------------------------------===*/
10 #include "InstrProfiling.h"
12 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__)
16 static const __llvm_profile_data *DataFirst = NULL;
17 static const __llvm_profile_data *DataLast = NULL;
18 static const char *NamesFirst = NULL;
19 static const char *NamesLast = NULL;
20 static uint64_t *CountersFirst = NULL;
21 static uint64_t *CountersLast = NULL;
23 static const void *getMinAddr(const void *A1, const void *A2) {
24 return A1 < A2 ? A1 : A2;
27 static const void *getMaxAddr(const void *A1, const void *A2) {
28 return A1 > A2 ? A1 : A2;
32 * \brief Register an instrumented function.
34 * Calls to this are emitted by clang with -fprofile-instr-generate. Such
35 * calls are only required (and only emitted) on targets where we haven't
36 * implemented linker magic to find the bounds of the sections.
38 COMPILER_RT_VISIBILITY
39 void __llvm_profile_register_function(void *Data_) {
40 /* TODO: Only emit this function if we can't use linker magic. */
41 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
45 CountersFirst = Data->CounterPtr;
46 CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
50 DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
51 CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr);
53 DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
54 CountersLast = (uint64_t *)getMaxAddr(
55 CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
58 COMPILER_RT_VISIBILITY
59 void __llvm_profile_register_names_function(void *NamesStart,
62 NamesFirst = (const char *)NamesStart;
63 NamesLast = (const char *)NamesStart + NamesSize;
66 NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
68 (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
71 COMPILER_RT_VISIBILITY
72 const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
73 COMPILER_RT_VISIBILITY
74 const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
75 COMPILER_RT_VISIBILITY
76 const char *__llvm_profile_begin_names(void) { return NamesFirst; }
77 COMPILER_RT_VISIBILITY
78 const char *__llvm_profile_end_names(void) { return NamesLast; }
79 COMPILER_RT_VISIBILITY
80 uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
81 COMPILER_RT_VISIBILITY
82 uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
84 COMPILER_RT_VISIBILITY
85 ValueProfNode *__llvm_profile_begin_vnodes(void) {
88 COMPILER_RT_VISIBILITY
89 ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
91 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
92 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;