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#include "InstrProfiling.h"
11
12#if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__)
13
14#include <stdlib.h>
15
16static const __llvm_profile_data *DataFirst = NULL;
17static const __llvm_profile_data *DataLast = NULL;
18static const char *NamesFirst = NULL;
19static const char *NamesLast = NULL;
20static uint64_t *CountersFirst = NULL;
21static uint64_t *CountersLast = NULL;
22
23static const void *getMinAddr(const void *A1, const void *A2) {
24  return A1 < A2 ? A1 : A2;
25}
26
27static const void *getMaxAddr(const void *A1, const void *A2) {
28  return A1 > A2 ? A1 : A2;
29}
30
31/*!
32 * \brief Register an instrumented function.
33 *
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.
37 */
38COMPILER_RT_VISIBILITY
39void __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_;
42  if (!DataFirst) {
43    DataFirst = Data;
44    DataLast = Data + 1;
45    CountersFirst = Data->CounterPtr;
46    CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
47    return;
48  }
49
50  DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
51  CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr);
52
53  DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
54  CountersLast = (uint64_t *)getMaxAddr(
55      CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
56}
57
58COMPILER_RT_VISIBILITY
59void __llvm_profile_register_names_function(void *NamesStart,
60                                            uint64_t NamesSize) {
61  if (!NamesFirst) {
62    NamesFirst = (const char *)NamesStart;
63    NamesLast = (const char *)NamesStart + NamesSize;
64    return;
65  }
66  NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
67  NamesLast =
68      (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
69}
70
71COMPILER_RT_VISIBILITY
72const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
73COMPILER_RT_VISIBILITY
74const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
75COMPILER_RT_VISIBILITY
76const char *__llvm_profile_begin_names(void) { return NamesFirst; }
77COMPILER_RT_VISIBILITY
78const char *__llvm_profile_end_names(void) { return NamesLast; }
79COMPILER_RT_VISIBILITY
80uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
81COMPILER_RT_VISIBILITY
82uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
83
84COMPILER_RT_VISIBILITY
85ValueProfNode *__llvm_profile_begin_vnodes(void) {
86  return 0;
87}
88COMPILER_RT_VISIBILITY
89ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
90
91COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
92COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
93
94#endif
95