Home | History | Annotate | Line # | Download | only in profile
InstrProfilingPlatformOther.c revision 1.1.1.1
      1 /*===- InstrProfilingPlatformOther.c - Profile data default platfrom ------===*\
      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__)
     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  */
     29 void __llvm_profile_register_function(void *Data_) {
     30   /* TODO: Only emit this function if we can't use linker magic. */
     31   const __llvm_profile_data *Data = (__llvm_profile_data*)Data_;
     32   if (!DataFirst) {
     33     DataFirst = Data;
     34     DataLast = Data + 1;
     35     NamesFirst = Data->Name;
     36     NamesLast = Data->Name + Data->NameSize;
     37     CountersFirst = Data->Counters;
     38     CountersLast = Data->Counters + Data->NumCounters;
     39     return;
     40   }
     41 
     42 #define UPDATE_FIRST(First, New) \
     43   First = New < First ? New : First
     44   UPDATE_FIRST(DataFirst, Data);
     45   UPDATE_FIRST(NamesFirst, Data->Name);
     46   UPDATE_FIRST(CountersFirst, Data->Counters);
     47 #undef UPDATE_FIRST
     48 
     49 #define UPDATE_LAST(Last, New) \
     50   Last = New > Last ? New : Last
     51   UPDATE_LAST(DataLast, Data + 1);
     52   UPDATE_LAST(NamesLast, Data->Name + Data->NameSize);
     53   UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters);
     54 #undef UPDATE_LAST
     55 }
     56 
     57 const __llvm_profile_data *__llvm_profile_data_begin(void) {
     58   return DataFirst;
     59 }
     60 const __llvm_profile_data *__llvm_profile_data_end(void) {
     61   return DataLast;
     62 }
     63 const char *__llvm_profile_names_begin(void) { return NamesFirst; }
     64 const char *__llvm_profile_names_end(void) { return NamesLast; }
     65 uint64_t *__llvm_profile_counters_begin(void) { return CountersFirst; }
     66 uint64_t *__llvm_profile_counters_end(void) { return CountersLast; }
     67 #endif
     68