xref: /aosp_15_r20/external/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /*===- InstrProfilingPlatformLinux.c - Profile data Linux 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(__linux__) || defined(__FreeBSD__)
13*7c3d14c8STreehugger Robot #include <stdlib.h>
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot #define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME)
16*7c3d14c8STreehugger Robot #define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_SECT_NAME)
17*7c3d14c8STreehugger Robot #define PROF_NAME_START INSTR_PROF_SECT_START(INSTR_PROF_NAME_SECT_NAME)
18*7c3d14c8STreehugger Robot #define PROF_NAME_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_NAME_SECT_NAME)
19*7c3d14c8STreehugger Robot #define PROF_CNTS_START INSTR_PROF_SECT_START(INSTR_PROF_CNTS_SECT_NAME)
20*7c3d14c8STreehugger Robot #define PROF_CNTS_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_CNTS_SECT_NAME)
21*7c3d14c8STreehugger Robot #define PROF_VNODES_START INSTR_PROF_SECT_START(INSTR_PROF_VNODES_SECT_NAME)
22*7c3d14c8STreehugger Robot #define PROF_VNODES_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_VNODES_SECT_NAME)
23*7c3d14c8STreehugger Robot 
24*7c3d14c8STreehugger Robot /* Declare section start and stop symbols for various sections
25*7c3d14c8STreehugger Robot  * generated by compiler instrumentation.
26*7c3d14c8STreehugger Robot  */
27*7c3d14c8STreehugger Robot extern __llvm_profile_data PROF_DATA_START COMPILER_RT_VISIBILITY;
28*7c3d14c8STreehugger Robot extern __llvm_profile_data PROF_DATA_STOP COMPILER_RT_VISIBILITY;
29*7c3d14c8STreehugger Robot extern uint64_t PROF_CNTS_START COMPILER_RT_VISIBILITY;
30*7c3d14c8STreehugger Robot extern uint64_t PROF_CNTS_STOP COMPILER_RT_VISIBILITY;
31*7c3d14c8STreehugger Robot extern char PROF_NAME_START COMPILER_RT_VISIBILITY;
32*7c3d14c8STreehugger Robot extern char PROF_NAME_STOP COMPILER_RT_VISIBILITY;
33*7c3d14c8STreehugger Robot extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY;
34*7c3d14c8STreehugger Robot extern ValueProfNode PROF_VNODES_STOP COMPILER_RT_VISIBILITY;
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot /* Add dummy data to ensure the section is always created. */
37*7c3d14c8STreehugger Robot __llvm_profile_data
38*7c3d14c8STreehugger Robot     __prof_data_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_DATA_SECT_NAME_STR);
39*7c3d14c8STreehugger Robot uint64_t
40*7c3d14c8STreehugger Robot     __prof_cnts_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_CNTS_SECT_NAME_STR);
41*7c3d14c8STreehugger Robot char __prof_nms_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_NAME_SECT_NAME_STR);
42*7c3d14c8STreehugger Robot ValueProfNode __prof_vnodes_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_VNODES_SECT_NAME_STR);
43*7c3d14c8STreehugger Robot 
44*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY const __llvm_profile_data *
__llvm_profile_begin_data(void)45*7c3d14c8STreehugger Robot __llvm_profile_begin_data(void) {
46*7c3d14c8STreehugger Robot   return &PROF_DATA_START;
47*7c3d14c8STreehugger Robot }
48*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY const __llvm_profile_data *
__llvm_profile_end_data(void)49*7c3d14c8STreehugger Robot __llvm_profile_end_data(void) {
50*7c3d14c8STreehugger Robot   return &PROF_DATA_STOP;
51*7c3d14c8STreehugger Robot }
__llvm_profile_begin_names(void)52*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_names(void) {
53*7c3d14c8STreehugger Robot   return &PROF_NAME_START;
54*7c3d14c8STreehugger Robot }
__llvm_profile_end_names(void)55*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY const char *__llvm_profile_end_names(void) {
56*7c3d14c8STreehugger Robot   return &PROF_NAME_STOP;
57*7c3d14c8STreehugger Robot }
__llvm_profile_begin_counters(void)58*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) {
59*7c3d14c8STreehugger Robot   return &PROF_CNTS_START;
60*7c3d14c8STreehugger Robot }
__llvm_profile_end_counters(void)61*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_end_counters(void) {
62*7c3d14c8STreehugger Robot   return &PROF_CNTS_STOP;
63*7c3d14c8STreehugger Robot }
64*7c3d14c8STreehugger Robot 
65*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *
__llvm_profile_begin_vnodes(void)66*7c3d14c8STreehugger Robot __llvm_profile_begin_vnodes(void) {
67*7c3d14c8STreehugger Robot   return &PROF_VNODES_START;
68*7c3d14c8STreehugger Robot }
__llvm_profile_end_vnodes(void)69*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {
70*7c3d14c8STreehugger Robot   return &PROF_VNODES_STOP;
71*7c3d14c8STreehugger Robot }
72*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &PROF_VNODES_START;
73*7c3d14c8STreehugger Robot COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &PROF_VNODES_STOP;
74*7c3d14c8STreehugger Robot 
75*7c3d14c8STreehugger Robot #endif
76