InstrProfilingUtil.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*===- InstrProfilingUtil.h - Support library for PGO instrumentation -----===*\
  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. #ifndef PROFILE_INSTRPROFILINGUTIL_H
  9. #define PROFILE_INSTRPROFILINGUTIL_H
  10. #include <inttypes.h>
  11. #include <stddef.h>
  12. #include <stdio.h>
  13. /*! \brief Create a directory tree. */
  14. void __llvm_profile_recursive_mkdir(char *Pathname);
  15. /*! Set the mode used when creating profile directories. */
  16. void __llvm_profile_set_dir_mode(unsigned Mode);
  17. /*! Return the directory creation mode. */
  18. unsigned __llvm_profile_get_dir_mode(void);
  19. int lprofLockFd(int fd);
  20. int lprofUnlockFd(int fd);
  21. int lprofLockFileHandle(FILE *F);
  22. int lprofUnlockFileHandle(FILE *F);
  23. /*! Open file \c Filename for read+write with write
  24. * lock for exclusive access. The caller will block
  25. * if the lock is already held by another process. */
  26. FILE *lprofOpenFileEx(const char *Filename);
  27. /* PS4 doesn't have setenv/getenv/fork. Define a shim. */
  28. #if __ORBIS__
  29. #include <sys/types.h>
  30. static inline char *getenv(const char *name) { return NULL; }
  31. static inline int setenv(const char *name, const char *value, int overwrite)
  32. { return 0; }
  33. static pid_t fork() { return -1; }
  34. #endif /* #if __ORBIS__ */
  35. /* GCOV_PREFIX and GCOV_PREFIX_STRIP support */
  36. /* Return the path prefix specified by GCOV_PREFIX environment variable.
  37. * If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)
  38. * is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.
  39. */
  40. const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);
  41. /* Apply the path prefix specified in \c Prefix to path string in \c PathStr,
  42. * and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip
  43. * is not zero, path prefixes are stripped from \c PathStr (the level of
  44. * stripping is specified by \c PrefixStrip) before \c Prefix is added.
  45. */
  46. void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
  47. size_t PrefixLen, int PrefixStrip);
  48. /* Returns a pointer to the first occurrence of \c DIR_SEPARATOR char in
  49. * the string \c Path, or NULL if the char is not found. */
  50. const char *lprofFindFirstDirSeparator(const char *Path);
  51. /* Returns a pointer to the last occurrence of \c DIR_SEPARATOR char in
  52. * the string \c Path, or NULL if the char is not found. */
  53. const char *lprofFindLastDirSeparator(const char *Path);
  54. int lprofGetHostName(char *Name, int Len);
  55. unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
  56. void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
  57. /* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
  58. * Other return values mean no restore is needed.
  59. */
  60. int lprofSuspendSigKill();
  61. /* Restore previously suspended SIGKILL. */
  62. void lprofRestoreSigKill();
  63. static inline size_t lprofRoundUpTo(size_t x, size_t boundary) {
  64. return (x + boundary - 1) & ~(boundary - 1);
  65. }
  66. static inline size_t lprofRoundDownTo(size_t x, size_t boundary) {
  67. return x & ~(boundary - 1);
  68. }
  69. int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End);
  70. #endif /* PROFILE_INSTRPROFILINGUTIL_H */