2014-03-22 02:29:15 +08:00
|
|
|
/*===- InstrProfilingBuffer.c - Write instrumentation to a memory buffer --===*\
|
|
|
|
|*
|
|
|
|
|* The LLVM Compiler Infrastructure
|
|
|
|
|*
|
|
|
|
|* This file is distributed under the University of Illinois Open Source
|
|
|
|
|* License. See LICENSE.TXT for details.
|
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#include "InstrProfiling.h"
|
2014-12-10 06:07:25 +08:00
|
|
|
#include "InstrProfilingInternal.h"
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY
|
2014-03-22 02:29:22 +08:00
|
|
|
uint64_t __llvm_profile_get_size_for_buffer(void) {
|
2014-12-10 06:07:25 +08:00
|
|
|
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
|
|
|
|
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
|
|
|
|
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
|
|
|
|
const uint64_t *CountersEnd = __llvm_profile_end_counters();
|
|
|
|
const char *NamesBegin = __llvm_profile_begin_names();
|
|
|
|
const char *NamesEnd = __llvm_profile_end_names();
|
|
|
|
|
|
|
|
return __llvm_profile_get_size_for_buffer_internal(
|
|
|
|
DataBegin, DataEnd, CountersBegin, CountersEnd, NamesBegin, NamesEnd);
|
|
|
|
}
|
|
|
|
|
2016-02-26 10:49:41 +08:00
|
|
|
COMPILER_RT_VISIBILITY
|
|
|
|
uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
|
|
|
|
const __llvm_profile_data *End) {
|
|
|
|
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
|
|
|
|
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
|
|
|
|
sizeof(__llvm_profile_data);
|
|
|
|
}
|
2014-12-10 06:07:25 +08:00
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY
|
2014-12-10 06:07:25 +08:00
|
|
|
uint64_t __llvm_profile_get_size_for_buffer_internal(
|
2015-11-23 12:38:17 +08:00
|
|
|
const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd,
|
|
|
|
const uint64_t *CountersBegin, const uint64_t *CountersEnd,
|
|
|
|
const char *NamesBegin, const char *NamesEnd) {
|
2014-03-22 02:29:24 +08:00
|
|
|
/* Match logic in __llvm_profile_write_buffer(). */
|
2016-02-26 10:49:41 +08:00
|
|
|
const uint64_t NamesSize = (NamesEnd - NamesBegin) * sizeof(char);
|
2015-11-19 02:12:35 +08:00
|
|
|
const uint8_t Padding = __llvm_profile_get_num_padding_bytes(NamesSize);
|
2015-10-17 06:21:56 +08:00
|
|
|
return sizeof(__llvm_profile_header) +
|
2016-02-26 10:49:41 +08:00
|
|
|
(__llvm_profile_get_data_size(DataBegin, DataEnd) *
|
|
|
|
sizeof(__llvm_profile_data)) +
|
|
|
|
(CountersEnd - CountersBegin) * sizeof(uint64_t) + NamesSize + Padding;
|
2014-03-22 02:29:22 +08:00
|
|
|
}
|
|
|
|
|
2017-06-28 01:28:01 +08:00
|
|
|
COMPILER_RT_VISIBILITY
|
|
|
|
void initBufferWriter(ProfDataWriter *BufferWriter, char *Buffer) {
|
|
|
|
BufferWriter->Write = lprofBufferWriter;
|
|
|
|
BufferWriter->WriterCtx = Buffer;
|
|
|
|
}
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer(char *Buffer) {
|
2017-06-28 01:28:01 +08:00
|
|
|
ProfDataWriter BufferWriter;
|
|
|
|
initBufferWriter(&BufferWriter, Buffer);
|
2017-06-29 00:46:06 +08:00
|
|
|
return lprofWriteData(&BufferWriter, 0, 0);
|
2014-12-10 06:07:25 +08:00
|
|
|
}
|
|
|
|
|
2015-12-16 11:29:15 +08:00
|
|
|
COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal(
|
2014-12-10 06:07:25 +08:00
|
|
|
char *Buffer, const __llvm_profile_data *DataBegin,
|
|
|
|
const __llvm_profile_data *DataEnd, const uint64_t *CountersBegin,
|
|
|
|
const uint64_t *CountersEnd, const char *NamesBegin, const char *NamesEnd) {
|
2017-06-28 01:28:01 +08:00
|
|
|
ProfDataWriter BufferWriter;
|
|
|
|
initBufferWriter(&BufferWriter, Buffer);
|
|
|
|
return lprofWriteDataImpl(&BufferWriter, DataBegin, DataEnd, CountersBegin,
|
2017-06-29 00:46:06 +08:00
|
|
|
CountersEnd, 0, NamesBegin, NamesEnd, 0);
|
2014-03-22 02:29:22 +08:00
|
|
|
}
|