Path: blob/main/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
35233 views
/*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\1|*2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3|* See https://llvm.org/LICENSE.txt for license information.4|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5|*6\*===----------------------------------------------------------------------===*/78#if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \9!defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \10!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)1112#include <stdlib.h>13#include <stdio.h>1415#include "InstrProfiling.h"16#include "InstrProfilingInternal.h"1718static const __llvm_profile_data *DataFirst = NULL;19static const __llvm_profile_data *DataLast = NULL;20static const VTableProfData *VTableProfDataFirst = NULL;21static const VTableProfData *VTableProfDataLast = NULL;22static const char *NamesFirst = NULL;23static const char *NamesLast = NULL;24static const char *VNamesFirst = NULL;25static const char *VNamesLast = NULL;26static char *CountersFirst = NULL;27static char *CountersLast = NULL;28static uint32_t *OrderFileFirst = NULL;2930static const void *getMinAddr(const void *A1, const void *A2) {31return A1 < A2 ? A1 : A2;32}3334static const void *getMaxAddr(const void *A1, const void *A2) {35return A1 > A2 ? A1 : A2;36}3738/*!39* \brief Register an instrumented function.40*41* Calls to this are emitted by clang with -fprofile-instr-generate. Such42* calls are only required (and only emitted) on targets where we haven't43* implemented linker magic to find the bounds of the sections.44*/45COMPILER_RT_VISIBILITY46void __llvm_profile_register_function(void *Data_) {47/* TODO: Only emit this function if we can't use linker magic. */48const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;49if (!DataFirst) {50DataFirst = Data;51DataLast = Data + 1;52CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr);53CountersLast =54CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size();55return;56}5758DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);59CountersFirst = (char *)getMinAddr(60CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr));6162DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);63CountersLast = (char *)getMaxAddr(64CountersLast,65(char *)((uintptr_t)Data_ + Data->CounterPtr) +66Data->NumCounters * __llvm_profile_counter_entry_size());67}6869COMPILER_RT_VISIBILITY70void __llvm_profile_register_names_function(void *NamesStart,71uint64_t NamesSize) {72if (!NamesFirst) {73NamesFirst = (const char *)NamesStart;74NamesLast = (const char *)NamesStart + NamesSize;75return;76}77NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);78NamesLast =79(const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);80}8182COMPILER_RT_VISIBILITY83const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }84COMPILER_RT_VISIBILITY85const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }86COMPILER_RT_VISIBILITY const VTableProfData *87__llvm_profile_begin_vtables(void) {88return VTableProfDataFirst;89}90COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) {91return VTableProfDataLast;92}93COMPILER_RT_VISIBILITY94const char *__llvm_profile_begin_names(void) { return NamesFirst; }95COMPILER_RT_VISIBILITY96const char *__llvm_profile_end_names(void) { return NamesLast; }97COMPILER_RT_VISIBILITY98const char *__llvm_profile_begin_vtabnames(void) { return VNamesFirst; }99COMPILER_RT_VISIBILITY100const char *__llvm_profile_end_vtabnames(void) { return VNamesLast; }101COMPILER_RT_VISIBILITY102char *__llvm_profile_begin_counters(void) { return CountersFirst; }103COMPILER_RT_VISIBILITY104char *__llvm_profile_end_counters(void) { return CountersLast; }105COMPILER_RT_VISIBILITY106char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; }107COMPILER_RT_VISIBILITY108char *__llvm_profile_end_bitmap(void) { return BitmapLast; }109/* TODO: correctly set up OrderFileFirst. */110COMPILER_RT_VISIBILITY111uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; }112113COMPILER_RT_VISIBILITY114ValueProfNode *__llvm_profile_begin_vnodes(void) {115return 0;116}117COMPILER_RT_VISIBILITY118ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }119120COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;121COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;122123COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {124return 0;125}126127#endif128129130