]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / profile / InstrProfilingPlatformOther.c
1 /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\
2 |*
3 |*                     The LLVM Compiler Infrastructure
4 |*
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
7 |*
8 \*===----------------------------------------------------------------------===*/
9
10 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
11     !(defined(__sun__) && defined(__svr4__)) && !defined(__NetBSD__)
12
13 #include <stdlib.h>
14
15 #include "InstrProfiling.h"
16
17 static const __llvm_profile_data *DataFirst = NULL;
18 static const __llvm_profile_data *DataLast = NULL;
19 static const char *NamesFirst = NULL;
20 static const char *NamesLast = NULL;
21 static uint64_t *CountersFirst = NULL;
22 static uint64_t *CountersLast = NULL;
23
24 static const void *getMinAddr(const void *A1, const void *A2) {
25   return A1 < A2 ? A1 : A2;
26 }
27
28 static const void *getMaxAddr(const void *A1, const void *A2) {
29   return A1 > A2 ? A1 : A2;
30 }
31
32 /*!
33  * \brief Register an instrumented function.
34  *
35  * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
36  * calls are only required (and only emitted) on targets where we haven't
37  * implemented linker magic to find the bounds of the sections.
38  */
39 COMPILER_RT_VISIBILITY
40 void __llvm_profile_register_function(void *Data_) {
41   /* TODO: Only emit this function if we can't use linker magic. */
42   const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
43   if (!DataFirst) {
44     DataFirst = Data;
45     DataLast = Data + 1;
46     CountersFirst = Data->CounterPtr;
47     CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
48     return;
49   }
50
51   DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
52   CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr);
53
54   DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
55   CountersLast = (uint64_t *)getMaxAddr(
56       CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
57 }
58
59 COMPILER_RT_VISIBILITY
60 void __llvm_profile_register_names_function(void *NamesStart,
61                                             uint64_t NamesSize) {
62   if (!NamesFirst) {
63     NamesFirst = (const char *)NamesStart;
64     NamesLast = (const char *)NamesStart + NamesSize;
65     return;
66   }
67   NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
68   NamesLast =
69       (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
70 }
71
72 COMPILER_RT_VISIBILITY
73 const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
74 COMPILER_RT_VISIBILITY
75 const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
76 COMPILER_RT_VISIBILITY
77 const char *__llvm_profile_begin_names(void) { return NamesFirst; }
78 COMPILER_RT_VISIBILITY
79 const char *__llvm_profile_end_names(void) { return NamesLast; }
80 COMPILER_RT_VISIBILITY
81 uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
82 COMPILER_RT_VISIBILITY
83 uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
84
85 COMPILER_RT_VISIBILITY
86 ValueProfNode *__llvm_profile_begin_vnodes(void) {
87   return 0;
88 }
89 COMPILER_RT_VISIBILITY
90 ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
91
92 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
93 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
94
95 #endif