[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / compiler-rt / lib / profile / InstrProfilingPlatformOther.c
blob29e570b9fba920a0f8085c7d636c52133a7a2200
1 /*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\
2 |*
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 |* See https://llvm.org/LICENSE.txt for license information.
5 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 |*
7 \*===----------------------------------------------------------------------===*/
9 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
10 !defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \
11 !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) && \
12 !defined(__wasm__) && !defined(__HAIKU__)
14 #include <stdlib.h>
15 #include <stdio.h>
17 #include "InstrProfiling.h"
18 #include "InstrProfilingInternal.h"
20 static const __llvm_profile_data *DataFirst = NULL;
21 static const __llvm_profile_data *DataLast = NULL;
22 static const VTableProfData *VTableProfDataFirst = NULL;
23 static const VTableProfData *VTableProfDataLast = NULL;
24 static const char *NamesFirst = NULL;
25 static const char *NamesLast = NULL;
26 static const char *VNamesFirst = NULL;
27 static const char *VNamesLast = NULL;
28 static char *CountersFirst = NULL;
29 static char *CountersLast = NULL;
30 static uint32_t *OrderFileFirst = NULL;
32 static const void *getMinAddr(const void *A1, const void *A2) {
33 return A1 < A2 ? A1 : A2;
36 static const void *getMaxAddr(const void *A1, const void *A2) {
37 return A1 > A2 ? A1 : A2;
40 /*!
41 * \brief Register an instrumented function.
43 * Calls to this are emitted by clang with -fprofile-instr-generate. Such
44 * calls are only required (and only emitted) on targets where we haven't
45 * implemented linker magic to find the bounds of the sections.
47 COMPILER_RT_VISIBILITY
48 void __llvm_profile_register_function(void *Data_) {
49 /* TODO: Only emit this function if we can't use linker magic. */
50 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
51 if (!DataFirst) {
52 DataFirst = Data;
53 DataLast = Data + 1;
54 CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr);
55 CountersLast =
56 CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size();
57 return;
60 DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
61 CountersFirst = (char *)getMinAddr(
62 CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr));
64 DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
65 CountersLast = (char *)getMaxAddr(
66 CountersLast,
67 (char *)((uintptr_t)Data_ + Data->CounterPtr) +
68 Data->NumCounters * __llvm_profile_counter_entry_size());
71 COMPILER_RT_VISIBILITY
72 void __llvm_profile_register_names_function(void *NamesStart,
73 uint64_t NamesSize) {
74 if (!NamesFirst) {
75 NamesFirst = (const char *)NamesStart;
76 NamesLast = (const char *)NamesStart + NamesSize;
77 return;
79 NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
80 NamesLast =
81 (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
84 COMPILER_RT_VISIBILITY
85 const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
86 COMPILER_RT_VISIBILITY
87 const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
88 COMPILER_RT_VISIBILITY const VTableProfData *
89 __llvm_profile_begin_vtables(void) {
90 return VTableProfDataFirst;
92 COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) {
93 return VTableProfDataLast;
95 COMPILER_RT_VISIBILITY
96 const char *__llvm_profile_begin_names(void) { return NamesFirst; }
97 COMPILER_RT_VISIBILITY
98 const char *__llvm_profile_end_names(void) { return NamesLast; }
99 COMPILER_RT_VISIBILITY
100 const char *__llvm_profile_begin_vtabnames(void) { return VNamesFirst; }
101 COMPILER_RT_VISIBILITY
102 const char *__llvm_profile_end_vtabnames(void) { return VNamesLast; }
103 COMPILER_RT_VISIBILITY
104 char *__llvm_profile_begin_counters(void) { return CountersFirst; }
105 COMPILER_RT_VISIBILITY
106 char *__llvm_profile_end_counters(void) { return CountersLast; }
107 COMPILER_RT_VISIBILITY
108 char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; }
109 COMPILER_RT_VISIBILITY
110 char *__llvm_profile_end_bitmap(void) { return BitmapLast; }
111 /* TODO: correctly set up OrderFileFirst. */
112 COMPILER_RT_VISIBILITY
113 uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; }
115 COMPILER_RT_VISIBILITY
116 ValueProfNode *__llvm_profile_begin_vnodes(void) {
117 return 0;
119 COMPILER_RT_VISIBILITY
120 ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
122 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
123 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
125 COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
126 return 0;
129 #endif