blob: b6c780ff514fc50ffa489c1be290870af15889c5 [file] [log] [blame]
Xinliang David Lif556a7e2015-10-13 18:40:00 +00001/*===- InstrProfilingPlatformLinux.c - Profile data Linux 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
Vedant Kumar5b0d5b42017-12-14 18:43:14 +000010#include "InstrProfiling.h"
11
Vedant Kumare8e85992017-12-14 18:50:13 +000012#if defined(__linux__) || defined(__FreeBSD__)
13#include <stdlib.h>
14
Xinliang David Li7c7f1202015-11-23 18:56:03 +000015#define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME)
16#define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_SECT_NAME)
17#define PROF_NAME_START INSTR_PROF_SECT_START(INSTR_PROF_NAME_SECT_NAME)
18#define PROF_NAME_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_NAME_SECT_NAME)
19#define PROF_CNTS_START INSTR_PROF_SECT_START(INSTR_PROF_CNTS_SECT_NAME)
20#define PROF_CNTS_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_CNTS_SECT_NAME)
Xinliang David Li4e8754d2016-05-21 22:55:45 +000021#define PROF_VNODES_START INSTR_PROF_SECT_START(INSTR_PROF_VNODES_SECT_NAME)
22#define PROF_VNODES_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_VNODES_SECT_NAME)
Xinliang David Li7c7f1202015-11-23 18:56:03 +000023
24/* Declare section start and stop symbols for various sections
25 * generated by compiler instrumentation.
26 */
Xinliang David Liabfd5532015-12-16 03:29:15 +000027extern __llvm_profile_data PROF_DATA_START COMPILER_RT_VISIBILITY;
28extern __llvm_profile_data PROF_DATA_STOP COMPILER_RT_VISIBILITY;
29extern uint64_t PROF_CNTS_START COMPILER_RT_VISIBILITY;
30extern uint64_t PROF_CNTS_STOP COMPILER_RT_VISIBILITY;
31extern char PROF_NAME_START COMPILER_RT_VISIBILITY;
32extern char PROF_NAME_STOP COMPILER_RT_VISIBILITY;
Xinliang David Li4e8754d2016-05-21 22:55:45 +000033extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY;
34extern ValueProfNode PROF_VNODES_STOP COMPILER_RT_VISIBILITY;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000035
Xinliang David Lib6c81d22015-11-13 22:33:07 +000036/* Add dummy data to ensure the section is always created. */
Xinliang David Li7c7f1202015-11-23 18:56:03 +000037__llvm_profile_data
Xinliang David Liabfd5532015-12-16 03:29:15 +000038 __prof_data_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_DATA_SECT_NAME_STR);
39uint64_t
40 __prof_cnts_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_CNTS_SECT_NAME_STR);
41char __prof_nms_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_NAME_SECT_NAME_STR);
Xinliang David Li4e8754d2016-05-21 22:55:45 +000042ValueProfNode __prof_vnodes_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_VNODES_SECT_NAME_STR);
Xinliang David Lib6c81d22015-11-13 22:33:07 +000043
Xinliang David Liabfd5532015-12-16 03:29:15 +000044COMPILER_RT_VISIBILITY const __llvm_profile_data *
Xinliang David Lif556a7e2015-10-13 18:40:00 +000045__llvm_profile_begin_data(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000046 return &PROF_DATA_START;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000047}
Xinliang David Liabfd5532015-12-16 03:29:15 +000048COMPILER_RT_VISIBILITY const __llvm_profile_data *
Xinliang David Lif556a7e2015-10-13 18:40:00 +000049__llvm_profile_end_data(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000050 return &PROF_DATA_STOP;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000051}
Xinliang David Liabfd5532015-12-16 03:29:15 +000052COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_names(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000053 return &PROF_NAME_START;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000054}
Xinliang David Liabfd5532015-12-16 03:29:15 +000055COMPILER_RT_VISIBILITY const char *__llvm_profile_end_names(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000056 return &PROF_NAME_STOP;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000057}
Xinliang David Liabfd5532015-12-16 03:29:15 +000058COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000059 return &PROF_CNTS_START;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000060}
Xinliang David Liabfd5532015-12-16 03:29:15 +000061COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_end_counters(void) {
Xinliang David Li7c7f1202015-11-23 18:56:03 +000062 return &PROF_CNTS_STOP;
Xinliang David Lif556a7e2015-10-13 18:40:00 +000063}
Xinliang David Li4e8754d2016-05-21 22:55:45 +000064
65COMPILER_RT_VISIBILITY ValueProfNode *
66__llvm_profile_begin_vnodes(void) {
67 return &PROF_VNODES_START;
68}
Xinliang David Li7b413932016-05-22 16:36:03 +000069COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {
Xinliang David Li4e8754d2016-05-21 22:55:45 +000070 return &PROF_VNODES_STOP;
71}
Xinliang David Li7b413932016-05-22 16:36:03 +000072COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &PROF_VNODES_START;
73COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &PROF_VNODES_STOP;
74
Xinliang David Lif556a7e2015-10-13 18:40:00 +000075#endif