blob: 58ceb3458a0ad09d16ff1e1e57a5c97a62efc684 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001/*===- 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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080012#if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070013#include <stdlib.h>
14
15static const __llvm_profile_data *DataFirst = NULL;
16static const __llvm_profile_data *DataLast = NULL;
17static const char *NamesFirst = NULL;
18static const char *NamesLast = NULL;
19static uint64_t *CountersFirst = NULL;
20static uint64_t *CountersLast = NULL;
21
22/*!
23 * \brief Register an instrumented function.
24 *
25 * Calls to this are emitted by clang with -fprofile-instr-generate. Such
26 * calls are only required (and only emitted) on targets where we haven't
27 * implemented linker magic to find the bounds of the sections.
28 */
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080029COMPILER_RT_VISIBILITY
Stephen Hines2d1fdb22014-05-28 23:58:16 -070030void __llvm_profile_register_function(void *Data_) {
31 /* TODO: Only emit this function if we can't use linker magic. */
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080032 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070033 if (!DataFirst) {
34 DataFirst = Data;
35 DataLast = Data + 1;
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080036 NamesFirst = Data->NamePtr;
37 NamesLast = (const char *)Data->NamePtr + Data->NameSize;
38 CountersFirst = Data->CounterPtr;
39 CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070040 return;
41 }
42
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080043#define UPDATE_FIRST(First, New) First = New < First ? New : First
Stephen Hines2d1fdb22014-05-28 23:58:16 -070044 UPDATE_FIRST(DataFirst, Data);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080045 UPDATE_FIRST(NamesFirst, (const char *)Data->NamePtr);
46 UPDATE_FIRST(CountersFirst, (uint64_t *)Data->CounterPtr);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070047#undef UPDATE_FIRST
48
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080049#define UPDATE_LAST(Last, New) Last = New > Last ? New : Last
Stephen Hines2d1fdb22014-05-28 23:58:16 -070050 UPDATE_LAST(DataLast, Data + 1);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080051 UPDATE_LAST(NamesLast, (const char *)Data->NamePtr + Data->NameSize);
52 UPDATE_LAST(CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070053#undef UPDATE_LAST
54}
55
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080056COMPILER_RT_VISIBILITY
57const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
58COMPILER_RT_VISIBILITY
59const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
60COMPILER_RT_VISIBILITY
Stephen Hines6d186232014-11-26 17:56:19 -080061const char *__llvm_profile_begin_names(void) { return NamesFirst; }
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080062COMPILER_RT_VISIBILITY
Stephen Hines6d186232014-11-26 17:56:19 -080063const char *__llvm_profile_end_names(void) { return NamesLast; }
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080064COMPILER_RT_VISIBILITY
Stephen Hines6d186232014-11-26 17:56:19 -080065uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080066COMPILER_RT_VISIBILITY
Stephen Hines6d186232014-11-26 17:56:19 -080067uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
Stephen Hines2d1fdb22014-05-28 23:58:16 -070068#endif