xref: /aosp_15_r20/external/compiler-rt/lib/profile/InstrProfilingPlatformOther.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\
2*7c3d14c8STreehugger Robot |*
3*7c3d14c8STreehugger Robot |*                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot |*
5*7c3d14c8STreehugger Robot |* This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot |* License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot |*
8*7c3d14c8STreehugger Robot \*===----------------------------------------------------------------------===*/
9*7c3d14c8STreehugger Robot 
10*7c3d14c8STreehugger Robot #include "InstrProfiling.h"
11*7c3d14c8STreehugger Robot 
12*7c3d14c8STreehugger Robot #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__)
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot #include <stdlib.h>
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot static const __llvm_profile_data *DataFirst = NULL;
17*7c3d14c8STreehugger Robot static const __llvm_profile_data *DataLast = NULL;
18*7c3d14c8STreehugger Robot static const char *NamesFirst = NULL;
19*7c3d14c8STreehugger Robot static const char *NamesLast = NULL;
20*7c3d14c8STreehugger Robot static uint64_t *CountersFirst = NULL;
21*7c3d14c8STreehugger Robot static uint64_t *CountersLast = NULL;
22*7c3d14c8STreehugger Robot 
getMinAddr(const void * A1,const void * A2)23*7c3d14c8STreehugger Robot static const void *getMinAddr(const void *A1, const void *A2) {
24*7c3d14c8STreehugger Robot   return A1 < A2 ? A1 : A2;
25*7c3d14c8STreehugger Robot }
26*7c3d14c8STreehugger Robot 
getMaxAddr(const void * A1,const void * A2)27*7c3d14c8STreehugger Robot static const void *getMaxAddr(const void *A1, const void *A2) {
28*7c3d14c8STreehugger Robot   return A1 > A2 ? A1 : A2;
29*7c3d14c8STreehugger Robot }
30*7c3d14c8STreehugger Robot 
31*7c3d14c8STreehugger Robot /*!
32*7c3d14c8STreehugger Robot  * \brief Register an instrumented function.
33*7c3d14c8STreehugger Robot  *
34*7c3d14c8STreehugger Robot  * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
35*7c3d14c8STreehugger Robot  * calls are only required (and only emitted) on targets where we haven't
36*7c3d14c8STreehugger Robot  * implemented linker magic to find the bounds of the sections.
37*7c3d14c8STreehugger Robot  */
38*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_register_function(void * Data_)39*7c3d14c8STreehugger Robot void __llvm_profile_register_function(void *Data_) {
40*7c3d14c8STreehugger Robot   /* TODO: Only emit this function if we can't use linker magic. */
41*7c3d14c8STreehugger Robot   const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
42*7c3d14c8STreehugger Robot   if (!DataFirst) {
43*7c3d14c8STreehugger Robot     DataFirst = Data;
44*7c3d14c8STreehugger Robot     DataLast = Data + 1;
45*7c3d14c8STreehugger Robot     CountersFirst = Data->CounterPtr;
46*7c3d14c8STreehugger Robot     CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
47*7c3d14c8STreehugger Robot     return;
48*7c3d14c8STreehugger Robot   }
49*7c3d14c8STreehugger Robot 
50*7c3d14c8STreehugger Robot   DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
51*7c3d14c8STreehugger Robot   CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr);
52*7c3d14c8STreehugger Robot 
53*7c3d14c8STreehugger Robot   DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
54*7c3d14c8STreehugger Robot   CountersLast = (uint64_t *)getMaxAddr(
55*7c3d14c8STreehugger Robot       CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
56*7c3d14c8STreehugger Robot }
57*7c3d14c8STreehugger Robot 
58*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_register_names_function(void * NamesStart,uint64_t NamesSize)59*7c3d14c8STreehugger Robot void __llvm_profile_register_names_function(void *NamesStart,
60*7c3d14c8STreehugger Robot                                             uint64_t NamesSize) {
61*7c3d14c8STreehugger Robot   if (!NamesFirst) {
62*7c3d14c8STreehugger Robot     NamesFirst = (const char *)NamesStart;
63*7c3d14c8STreehugger Robot     NamesLast = (const char *)NamesStart + NamesSize;
64*7c3d14c8STreehugger Robot     return;
65*7c3d14c8STreehugger Robot   }
66*7c3d14c8STreehugger Robot   NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
67*7c3d14c8STreehugger Robot   NamesLast =
68*7c3d14c8STreehugger Robot       (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
69*7c3d14c8STreehugger Robot }
70*7c3d14c8STreehugger Robot 
71*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_begin_data(void)72*7c3d14c8STreehugger Robot const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
73*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_end_data(void)74*7c3d14c8STreehugger Robot const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
75*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_begin_names(void)76*7c3d14c8STreehugger Robot const char *__llvm_profile_begin_names(void) { return NamesFirst; }
77*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_end_names(void)78*7c3d14c8STreehugger Robot const char *__llvm_profile_end_names(void) { return NamesLast; }
79*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_begin_counters(void)80*7c3d14c8STreehugger Robot uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
81*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_end_counters(void)82*7c3d14c8STreehugger Robot uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
83*7c3d14c8STreehugger Robot 
84*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_begin_vnodes(void)85*7c3d14c8STreehugger Robot ValueProfNode *__llvm_profile_begin_vnodes(void) {
86*7c3d14c8STreehugger Robot   return 0;
87*7c3d14c8STreehugger Robot }
88*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY
__llvm_profile_end_vnodes(void)89*7c3d14c8STreehugger Robot ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
90*7c3d14c8STreehugger Robot 
91*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
92*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
93*7c3d14c8STreehugger Robot 
94*7c3d14c8STreehugger Robot #endif
95