brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 19414ab Raw
126 lines · c
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-exception6|*7\*===----------------------------------------------------------------------===*/8 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__)13 14#include <stdlib.h>15#include <stdio.h>16 17#include "InstrProfiling.h"18#include "InstrProfilingInternal.h"19 20static const __llvm_profile_data *DataFirst = NULL;21static const __llvm_profile_data *DataLast = NULL;22static const VTableProfData *VTableProfDataFirst = NULL;23static const VTableProfData *VTableProfDataLast = NULL;24static const char *NamesFirst = NULL;25static const char *NamesLast = NULL;26static const char *VNamesFirst = NULL;27static const char *VNamesLast = NULL;28static char *CountersFirst = NULL;29static char *CountersLast = NULL;30 31static const void *getMinAddr(const void *A1, const void *A2) {32  return A1 < A2 ? A1 : A2;33}34 35static const void *getMaxAddr(const void *A1, const void *A2) {36  return A1 > A2 ? A1 : A2;37}38 39/*!40 * \brief Register an instrumented function.41 *42 * Calls to this are emitted by clang with -fprofile-instr-generate.  Such43 * calls are only required (and only emitted) on targets where we haven't44 * implemented linker magic to find the bounds of the sections.45 */46COMPILER_RT_VISIBILITY47void __llvm_profile_register_function(void *Data_) {48  /* TODO: Only emit this function if we can't use linker magic. */49  const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;50  if (!DataFirst) {51    DataFirst = Data;52    DataLast = Data + 1;53    CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr);54    CountersLast =55        CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size();56    return;57  }58 59  DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);60  CountersFirst = (char *)getMinAddr(61      CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr));62 63  DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);64  CountersLast = (char *)getMaxAddr(65      CountersLast,66      (char *)((uintptr_t)Data_ + Data->CounterPtr) +67          Data->NumCounters * __llvm_profile_counter_entry_size());68}69 70COMPILER_RT_VISIBILITY71void __llvm_profile_register_names_function(void *NamesStart,72                                            uint64_t NamesSize) {73  if (!NamesFirst) {74    NamesFirst = (const char *)NamesStart;75    NamesLast = (const char *)NamesStart + NamesSize;76    return;77  }78  NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);79  NamesLast =80      (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);81}82 83COMPILER_RT_VISIBILITY84const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }85COMPILER_RT_VISIBILITY86const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }87COMPILER_RT_VISIBILITY const VTableProfData *88__llvm_profile_begin_vtables(void) {89  return VTableProfDataFirst;90}91COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) {92  return VTableProfDataLast;93}94COMPILER_RT_VISIBILITY95const char *__llvm_profile_begin_names(void) { return NamesFirst; }96COMPILER_RT_VISIBILITY97const char *__llvm_profile_end_names(void) { return NamesLast; }98COMPILER_RT_VISIBILITY99const char *__llvm_profile_begin_vtabnames(void) { return VNamesFirst; }100COMPILER_RT_VISIBILITY101const char *__llvm_profile_end_vtabnames(void) { return VNamesLast; }102COMPILER_RT_VISIBILITY103char *__llvm_profile_begin_counters(void) { return CountersFirst; }104COMPILER_RT_VISIBILITY105char *__llvm_profile_end_counters(void) { return CountersLast; }106COMPILER_RT_VISIBILITY107char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; }108COMPILER_RT_VISIBILITY109char *__llvm_profile_end_bitmap(void) { return BitmapLast; }110 111COMPILER_RT_VISIBILITY112ValueProfNode *__llvm_profile_begin_vnodes(void) {113  return 0;114}115COMPILER_RT_VISIBILITY116ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }117 118COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;119COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;120 121COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {122  return 0;123}124 125#endif126