summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingPlatformOther.c
blob: 407ca0a7ea96892fe8fc0e31d06a4a1c4b6a2be3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\
|*
|*                     The LLVM Compiler Infrastructure
|*
|* This file is distributed under the University of Illinois Open Source
|* License. See LICENSE.TXT for details.
|*
\*===----------------------------------------------------------------------===*/

#include "InstrProfiling.h"

#if !defined(__APPLE__)
#include <stdlib.h>

static const __llvm_profile_data *DataFirst = NULL;
static const __llvm_profile_data *DataLast = NULL;
static const char *NamesFirst = NULL;
static const char *NamesLast = NULL;
static uint64_t *CountersFirst = NULL;
static uint64_t *CountersLast = NULL;

/*!
 * \brief Register an instrumented function.
 *
 * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
 * calls are only required (and only emitted) on targets where we haven't
 * implemented linker magic to find the bounds of the sections.
 */
void __llvm_profile_register_function(void *Data_) {
  /* TODO: Only emit this function if we can't use linker magic. */
  const __llvm_profile_data *Data = (__llvm_profile_data*)Data_;
  if (!DataFirst) {
    DataFirst = Data;
    DataLast = Data + 1;
    NamesFirst = Data->Name;
    NamesLast = Data->Name + Data->NameSize;
    CountersFirst = Data->Counters;
    CountersLast = Data->Counters + Data->NumCounters;
    return;
  }

#define UPDATE_FIRST(First, New) \
  First = New < First ? New : First
  UPDATE_FIRST(DataFirst, Data);
  UPDATE_FIRST(NamesFirst, Data->Name);
  UPDATE_FIRST(CountersFirst, Data->Counters);
#undef UPDATE_FIRST

#define UPDATE_LAST(Last, New) \
  Last = New > Last ? New : Last
  UPDATE_LAST(DataLast, Data + 1);
  UPDATE_LAST(NamesLast, Data->Name + Data->NameSize);
  UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters);
#undef UPDATE_LAST
}

const __llvm_profile_data *__llvm_profile_data_begin(void) {
  return DataFirst;
}
const __llvm_profile_data *__llvm_profile_data_end(void) {
  return DataLast;
}
const char *__llvm_profile_names_begin(void) { return NamesFirst; }
const char *__llvm_profile_names_end(void) { return NamesLast; }
uint64_t *__llvm_profile_counters_begin(void) { return CountersFirst; }
uint64_t *__llvm_profile_counters_end(void) { return CountersLast; }
#endif