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