InstrProfilingPlatformOther.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. \*===----------------------------------------------------------------------===*/
  8. #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
  9. !(defined(__sun__) && defined(__svr4__)) && !defined(__NetBSD__) && \
  10. !defined(_WIN32)
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include "InstrProfiling.h"
  14. #include "InstrProfilingInternal.h"
  15. static const __llvm_profile_data *DataFirst = NULL;
  16. static const __llvm_profile_data *DataLast = NULL;
  17. static const char *NamesFirst = NULL;
  18. static const char *NamesLast = NULL;
  19. static char *CountersFirst = NULL;
  20. static char *CountersLast = NULL;
  21. static uint32_t *OrderFileFirst = NULL;
  22. static const void *getMinAddr(const void *A1, const void *A2) {
  23. return A1 < A2 ? A1 : A2;
  24. }
  25. static const void *getMaxAddr(const void *A1, const void *A2) {
  26. return A1 > A2 ? A1 : A2;
  27. }
  28. /*!
  29. * \brief Register an instrumented function.
  30. *
  31. * Calls to this are emitted by clang with -fprofile-instr-generate. Such
  32. * calls are only required (and only emitted) on targets where we haven't
  33. * implemented linker magic to find the bounds of the sections.
  34. */
  35. COMPILER_RT_VISIBILITY
  36. void __llvm_profile_register_function(void *Data_) {
  37. /* TODO: Only emit this function if we can't use linker magic. */
  38. const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
  39. if (!DataFirst) {
  40. DataFirst = Data;
  41. DataLast = Data + 1;
  42. CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr);
  43. CountersLast =
  44. CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size();
  45. return;
  46. }
  47. DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
  48. CountersFirst = (char *)getMinAddr(
  49. CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr));
  50. DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
  51. CountersLast = (char *)getMaxAddr(
  52. CountersLast,
  53. (char *)((uintptr_t)Data_ + Data->CounterPtr) +
  54. Data->NumCounters * __llvm_profile_counter_entry_size());
  55. }
  56. COMPILER_RT_VISIBILITY
  57. void __llvm_profile_register_names_function(void *NamesStart,
  58. uint64_t NamesSize) {
  59. if (!NamesFirst) {
  60. NamesFirst = (const char *)NamesStart;
  61. NamesLast = (const char *)NamesStart + NamesSize;
  62. return;
  63. }
  64. NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
  65. NamesLast =
  66. (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
  67. }
  68. COMPILER_RT_VISIBILITY
  69. const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
  70. COMPILER_RT_VISIBILITY
  71. const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
  72. COMPILER_RT_VISIBILITY
  73. const char *__llvm_profile_begin_names(void) { return NamesFirst; }
  74. COMPILER_RT_VISIBILITY
  75. const char *__llvm_profile_end_names(void) { return NamesLast; }
  76. COMPILER_RT_VISIBILITY
  77. char *__llvm_profile_begin_counters(void) { return CountersFirst; }
  78. COMPILER_RT_VISIBILITY
  79. char *__llvm_profile_end_counters(void) { return CountersLast; }
  80. /* TODO: correctly set up OrderFileFirst. */
  81. COMPILER_RT_VISIBILITY
  82. uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; }
  83. COMPILER_RT_VISIBILITY
  84. ValueProfNode *__llvm_profile_begin_vnodes(void) {
  85. return 0;
  86. }
  87. COMPILER_RT_VISIBILITY
  88. ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
  89. COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
  90. COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
  91. COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
  92. return 0;
  93. }
  94. #endif