Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 12 | #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | |
| 15 | static const __llvm_profile_data *DataFirst = NULL; |
| 16 | static const __llvm_profile_data *DataLast = NULL; |
| 17 | static const char *NamesFirst = NULL; |
| 18 | static const char *NamesLast = NULL; |
| 19 | static uint64_t *CountersFirst = NULL; |
| 20 | static 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 Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 29 | COMPILER_RT_VISIBILITY |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 30 | void __llvm_profile_register_function(void *Data_) { |
| 31 | /* TODO: Only emit this function if we can't use linker magic. */ |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 32 | const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 33 | if (!DataFirst) { |
| 34 | DataFirst = Data; |
| 35 | DataLast = Data + 1; |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 36 | NamesFirst = Data->NamePtr; |
| 37 | NamesLast = (const char *)Data->NamePtr + Data->NameSize; |
| 38 | CountersFirst = Data->CounterPtr; |
| 39 | CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters; |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 40 | return; |
| 41 | } |
| 42 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 43 | #define UPDATE_FIRST(First, New) First = New < First ? New : First |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 44 | UPDATE_FIRST(DataFirst, Data); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 45 | UPDATE_FIRST(NamesFirst, (const char *)Data->NamePtr); |
| 46 | UPDATE_FIRST(CountersFirst, (uint64_t *)Data->CounterPtr); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 47 | #undef UPDATE_FIRST |
| 48 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 49 | #define UPDATE_LAST(Last, New) Last = New > Last ? New : Last |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 50 | UPDATE_LAST(DataLast, Data + 1); |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 51 | UPDATE_LAST(NamesLast, (const char *)Data->NamePtr + Data->NameSize); |
| 52 | UPDATE_LAST(CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 53 | #undef UPDATE_LAST |
| 54 | } |
| 55 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 56 | COMPILER_RT_VISIBILITY |
| 57 | const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } |
| 58 | COMPILER_RT_VISIBILITY |
| 59 | const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } |
| 60 | COMPILER_RT_VISIBILITY |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 61 | const char *__llvm_profile_begin_names(void) { return NamesFirst; } |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 62 | COMPILER_RT_VISIBILITY |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 63 | const char *__llvm_profile_end_names(void) { return NamesLast; } |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 64 | COMPILER_RT_VISIBILITY |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 65 | uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 66 | COMPILER_RT_VISIBILITY |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 67 | uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 68 | #endif |