Home | History | Annotate | 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_H_
     11 #define PROFILE_INSTRPROFILING_H_
     12 
     13 #include "InstrProfilingPort.h"
     14 #include "InstrProfData.inc"
     15 
     16 enum ValueKind {
     17 #define VALUE_PROF_KIND(Enumerator, Value) Enumerator = Value,
     18 #include "InstrProfData.inc"
     19 };
     20 
     21 typedef void *IntPtrT;
     22 typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT)
     23     __llvm_profile_data {
     24 #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
     25 #include "InstrProfData.inc"
     26 } __llvm_profile_data;
     27 
     28 typedef struct __llvm_profile_header {
     29 #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name;
     30 #include "InstrProfData.inc"
     31 } __llvm_profile_header;
     32 
     33 /*!
     34  * \brief Get number of bytes necessary to pad the argument to eight
     35  * byte boundary.
     36  */
     37 uint8_t __llvm_profile_get_num_padding_bytes(uint64_t SizeInBytes);
     38 
     39 /*!
     40  * \brief Get required size for profile buffer.
     41  */
     42 uint64_t __llvm_profile_get_size_for_buffer(void);
     43 
     44 /*!
     45  * \brief Write instrumentation data to the given buffer.
     46  *
     47  * \pre \c Buffer is the start of a buffer at least as big as \a
     48  * __llvm_profile_get_size_for_buffer().
     49  */
     50 int __llvm_profile_write_buffer(char *Buffer);
     51 
     52 const __llvm_profile_data *__llvm_profile_begin_data(void);
     53 const __llvm_profile_data *__llvm_profile_end_data(void);
     54 const char *__llvm_profile_begin_names(void);
     55 const char *__llvm_profile_end_names(void);
     56 uint64_t *__llvm_profile_begin_counters(void);
     57 uint64_t *__llvm_profile_end_counters(void);
     58 
     59 /*!
     60  * \brief Clear profile counters to zero.
     61  *
     62  */
     63 void __llvm_profile_reset_counters(void);
     64 
     65 /*!
     66  * \brief Counts the number of times a target value is seen.
     67  *
     68  * Records the target value for the CounterIndex if not seen before. Otherwise,
     69  * increments the counter associated w/ the target value.
     70  * void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
     71  *                                       uint32_t CounterIndex);
     72  */
     73 void INSTR_PROF_VALUE_PROF_FUNC(
     74 #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName
     75 #include "InstrProfData.inc"
     76 );
     77 
     78 /*!
     79  * \brief Prepares the value profiling data for output.
     80  *
     81  * Prepares a single __llvm_profile_value_data array out of the many
     82  * ValueProfNode trees (one per instrumented function).
     83  */
     84 uint64_t __llvm_profile_gather_value_data(uint8_t **DataArray);
     85 
     86 /*!
     87  * \brief Write instrumentation data to the current file.
     88  *
     89  * Writes to the file with the last name given to \a __llvm_profile_set_filename(),
     90  * or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
     91  * or if that's not set, the last name given to
     92  * \a __llvm_profile_override_default_filename(), or if that's not set,
     93  * \c "default.profraw".
     94  */
     95 int __llvm_profile_write_file(void);
     96 
     97 /*!
     98  * \brief Set the filename for writing instrumentation data.
     99  *
    100  * Sets the filename to be used for subsequent calls to
    101  * \a __llvm_profile_write_file().
    102  *
    103  * \c Name is not copied, so it must remain valid.  Passing NULL resets the
    104  * filename logic to the default behaviour.
    105  */
    106 void __llvm_profile_set_filename(const char *Name);
    107 
    108 /*!
    109  * \brief Set the filename for writing instrumentation data, unless the
    110  * \c LLVM_PROFILE_FILE environment variable was set.
    111  *
    112  * Unless overridden, sets the filename to be used for subsequent calls to
    113  * \a __llvm_profile_write_file().
    114  *
    115  * \c Name is not copied, so it must remain valid.  Passing NULL resets the
    116  * filename logic to the default behaviour (unless the \c LLVM_PROFILE_FILE
    117  * was set in which case it has no effect).
    118  */
    119 void __llvm_profile_override_default_filename(const char *Name);
    120 
    121 /*! \brief Register to write instrumentation data to file at exit. */
    122 int __llvm_profile_register_write_file_atexit(void);
    123 
    124 /*! \brief Initialize file handling. */
    125 void __llvm_profile_initialize_file(void);
    126 
    127 /*! \brief Get the magic token for the file format. */
    128 uint64_t __llvm_profile_get_magic(void);
    129 
    130 /*! \brief Get the version of the file format. */
    131 uint64_t __llvm_profile_get_version(void);
    132 
    133 #endif /* PROFILE_INSTRPROFILING_H_ */
    134