1 1.1 joerg /*===- InstrProfiling.h- Support library for PGO instrumentation ----------===*\ 2 1.1 joerg |* 3 1.1 joerg |* The LLVM Compiler Infrastructure 4 1.1 joerg |* 5 1.1 joerg |* This file is distributed under the University of Illinois Open Source 6 1.1 joerg |* License. See LICENSE.TXT for details. 7 1.1 joerg |* 8 1.1 joerg \*===----------------------------------------------------------------------===*/ 9 1.1 joerg 10 1.1 joerg #ifndef PROFILE_INSTRPROFILING_INTERNALH_ 11 1.1 joerg #define PROFILE_INSTRPROFILING_INTERNALH_ 12 1.1 joerg 13 1.1 joerg #include "InstrProfiling.h" 14 1.1 joerg #include "stddef.h" 15 1.1 joerg 16 1.1 joerg /*! 17 1.1 joerg * \brief Write instrumentation data to the given buffer, given explicit 18 1.1 joerg * pointers to the live data in memory. This function is probably not what you 19 1.1 joerg * want. Use __llvm_profile_get_size_for_buffer instead. Use this function if 20 1.1 joerg * your program has a custom memory layout. 21 1.1 joerg */ 22 1.1 joerg uint64_t __llvm_profile_get_size_for_buffer_internal( 23 1.1 joerg const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, 24 1.1 joerg const uint64_t *CountersBegin, const uint64_t *CountersEnd, 25 1.1 joerg const char *NamesBegin, const char *NamesEnd); 26 1.1 joerg 27 1.1 joerg /*! 28 1.1 joerg * \brief Write instrumentation data to the given buffer, given explicit 29 1.1 joerg * pointers to the live data in memory. This function is probably not what you 30 1.1 joerg * want. Use __llvm_profile_write_buffer instead. Use this function if your 31 1.1 joerg * program has a custom memory layout. 32 1.1 joerg * 33 1.1 joerg * \pre \c Buffer is the start of a buffer at least as big as \a 34 1.1 joerg * __llvm_profile_get_size_for_buffer_internal(). 35 1.1 joerg */ 36 1.1 joerg int __llvm_profile_write_buffer_internal( 37 1.1 joerg char *Buffer, const __llvm_profile_data *DataBegin, 38 1.1 joerg const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, 39 1.1 joerg const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd); 40 1.1 joerg 41 1.1 joerg /*! 42 1.1 joerg * The data structure describing the data to be written by the 43 1.1 joerg * low level writer callback function. 44 1.1 joerg */ 45 1.1 joerg typedef struct ProfDataIOVec { 46 1.1 joerg const void *Data; 47 1.1 joerg size_t ElmSize; 48 1.1 joerg size_t NumElm; 49 1.1 joerg } ProfDataIOVec; 50 1.1 joerg 51 1.1 joerg typedef uint32_t (*WriterCallback)(ProfDataIOVec *, uint32_t NumIOVecs, 52 1.1 joerg void **WriterCtx); 53 1.1 joerg 54 1.1 joerg /*! 55 1.1 joerg * The data structure for buffered IO of profile data. 56 1.1 joerg */ 57 1.1 joerg typedef struct ProfBufferIO { 58 1.1 joerg /* File handle. */ 59 1.1 joerg void *File; 60 1.1 joerg /* Low level IO callback. */ 61 1.1 joerg WriterCallback FileWriter; 62 1.1 joerg /* The start of the buffer. */ 63 1.1 joerg uint8_t *BufferStart; 64 1.1 joerg /* Total size of the buffer. */ 65 1.1 joerg uint32_t BufferSz; 66 1.1 joerg /* Current byte offset from the start of the buffer. */ 67 1.1 joerg uint32_t CurOffset; 68 1.1 joerg } ProfBufferIO; 69 1.1 joerg 70 1.1 joerg /* The creator interface used by testing. */ 71 1.1 joerg ProfBufferIO *llvmCreateBufferIOInternal(void *File, uint32_t DefaultBufferSz); 72 1.1 joerg /*! 73 1.1 joerg * This is the interface to create a handle for buffered IO. 74 1.1 joerg */ 75 1.1 joerg ProfBufferIO *llvmCreateBufferIO(WriterCallback FileWriter, void *File, 76 1.1 joerg uint32_t DefaultBufferSz); 77 1.1 joerg /*! 78 1.1 joerg * The interface to destroy the bufferIO handle and reclaim 79 1.1 joerg * the memory. 80 1.1 joerg */ 81 1.1 joerg void llvmDeleteBufferIO(ProfBufferIO *BufferIO); 82 1.1 joerg 83 1.1 joerg /*! 84 1.1 joerg * This is the interface to write \c Data of \c Size bytes through 85 1.1 joerg * \c BufferIO. Returns 0 if successful, otherwise return -1. 86 1.1 joerg */ 87 1.1 joerg int llvmBufferIOWrite(ProfBufferIO *BufferIO, const uint8_t *Data, 88 1.1 joerg uint32_t Size); 89 1.1 joerg /*! 90 1.1 joerg * The interface to flush the remaining data in the buffer. 91 1.1 joerg * through the low level writer callback. 92 1.1 joerg */ 93 1.1 joerg int llvmBufferIOFlush(ProfBufferIO *BufferIO); 94 1.1 joerg 95 1.1 joerg /* The low level interface to write data into a buffer. It is used as the 96 1.1 joerg * callback by other high level writer methods such as buffered IO writer 97 1.1 joerg * and profile data writer. */ 98 1.1 joerg uint32_t llvmBufferWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs, 99 1.1 joerg void **WriterCtx); 100 1.1 joerg 101 1.1 joerg int llvmWriteProfData(WriterCallback Writer, void *WriterCtx, 102 1.1 joerg struct ValueProfData **ValueDataArray, 103 1.1 joerg const uint64_t ValueDataSize); 104 1.1 joerg int llvmWriteProfDataImpl(WriterCallback Writer, void *WriterCtx, 105 1.1 joerg const __llvm_profile_data *DataBegin, 106 1.1 joerg const __llvm_profile_data *DataEnd, 107 1.1 joerg const uint64_t *CountersBegin, 108 1.1 joerg const uint64_t *CountersEnd, 109 1.1 joerg struct ValueProfData **ValueDataBeginArray, 110 1.1 joerg const uint64_t ValueDataSize, const char *NamesBegin, 111 1.1 joerg const char *NamesEnd); 112 1.1 joerg 113 1.1 joerg extern char *(*GetEnvHook)(const char *); 114 1.1 joerg extern void (*FreeHook)(void *); 115 1.1 joerg extern void* (*CallocHook)(size_t, size_t); 116 1.1 joerg extern uint32_t VPBufferSize; 117 1.1 joerg 118 1.1 joerg #endif 119