1 1.1 joerg /*===- InstrProfilingBuffer.c - Write instrumentation to a memory buffer --===*\ 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 #include "InstrProfiling.h" 11 1.1.1.3 joerg #include "InstrProfilingInternal.h" 12 1.1 joerg 13 1.1.1.3 joerg COMPILER_RT_VISIBILITY 14 1.1 joerg uint64_t __llvm_profile_get_size_for_buffer(void) { 15 1.1.1.3 joerg const __llvm_profile_data *DataBegin = __llvm_profile_begin_data(); 16 1.1.1.3 joerg const __llvm_profile_data *DataEnd = __llvm_profile_end_data(); 17 1.1.1.3 joerg const uint64_t *CountersBegin = __llvm_profile_begin_counters(); 18 1.1.1.3 joerg const uint64_t *CountersEnd = __llvm_profile_end_counters(); 19 1.1.1.3 joerg const char *NamesBegin = __llvm_profile_begin_names(); 20 1.1.1.3 joerg const char *NamesEnd = __llvm_profile_end_names(); 21 1.1.1.3 joerg 22 1.1.1.3 joerg return __llvm_profile_get_size_for_buffer_internal( 23 1.1.1.3 joerg DataBegin, DataEnd, CountersBegin, CountersEnd, NamesBegin, NamesEnd); 24 1.1.1.3 joerg } 25 1.1.1.3 joerg 26 1.1.1.3 joerg #define PROFILE_RANGE_SIZE(Range) (Range##End - Range##Begin) 27 1.1.1.3 joerg 28 1.1.1.3 joerg COMPILER_RT_VISIBILITY 29 1.1.1.3 joerg uint64_t __llvm_profile_get_size_for_buffer_internal( 30 1.1.1.3 joerg const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, 31 1.1.1.3 joerg const uint64_t *CountersBegin, const uint64_t *CountersEnd, 32 1.1.1.3 joerg const char *NamesBegin, const char *NamesEnd) { 33 1.1 joerg /* Match logic in __llvm_profile_write_buffer(). */ 34 1.1.1.3 joerg const uint64_t NamesSize = PROFILE_RANGE_SIZE(Names) * sizeof(char); 35 1.1.1.3 joerg const uint8_t Padding = __llvm_profile_get_num_padding_bytes(NamesSize); 36 1.1.1.3 joerg return sizeof(__llvm_profile_header) + 37 1.1.1.3 joerg PROFILE_RANGE_SIZE(Data) * sizeof(__llvm_profile_data) + 38 1.1.1.3 joerg PROFILE_RANGE_SIZE(Counters) * sizeof(uint64_t) + NamesSize + Padding; 39 1.1 joerg } 40 1.1 joerg 41 1.1.1.3 joerg COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer(char *Buffer) { 42 1.1.1.3 joerg return llvmWriteProfData(llvmBufferWriter, Buffer, 0, 0); 43 1.1.1.3 joerg } 44 1.1 joerg 45 1.1.1.3 joerg COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal( 46 1.1.1.3 joerg char *Buffer, const __llvm_profile_data *DataBegin, 47 1.1.1.3 joerg const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin, 48 1.1.1.3 joerg const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd) { 49 1.1.1.3 joerg return llvmWriteProfDataImpl(llvmBufferWriter, Buffer, DataBegin, DataEnd, 50 1.1.1.3 joerg CountersBegin, CountersEnd, 0, 0, NamesBegin, 51 1.1.1.3 joerg NamesEnd); 52 1.1 joerg } 53