2015-11-18 21:08:03 +00:00
|
|
|
/*===- InstrProfilingWriter.c - Write instrumentation to a file or buffer -===*\
|
|
|
|
|*
|
2019-01-19 08:50:56 +00:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-11-18 21:08:03 +00:00
|
|
|
|*
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
2020-07-29 17:22:27 -07:00
|
|
|
// Note: This is linked into the Darwin kernel, and must remain compatible
|
|
|
|
// with freestanding compilation. See `darwin_add_builtin_libraries`.
|
|
|
|
|
2016-05-14 20:12:42 +00:00
|
|
|
#ifdef _MSC_VER
|
2016-05-15 16:41:58 +00:00
|
|
|
/* For _alloca */
|
2016-05-14 20:12:42 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2015-12-22 18:57:15 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-12-14 19:01:04 +00:00
|
|
|
#include "InstrProfiling.h"
|
|
|
|
#include "InstrProfilingInternal.h"
|
[profile] Add a mode to continuously sync counter updates to a file
Add support for continuously syncing profile counter updates to a file.
The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.
The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.
Continuous mode is (for the moment) incompatible with the online merging
mode. This limitation is lifted in https://reviews.llvm.org/D69586.
Continuous mode is also (for the moment) incompatible with value
profiling, as I'm not sure whether there is interest in this and the
implementation may be tricky.
As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and some UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default. Continuous mode will
not "just work" on Fuchsia or Windows, as it's not possible to mmap() a
section on these platforms. There is a proposal to add a layer of
indirection to the profile instrumentation to support these platforms.
rdar://54210980
Differential Revision: https://reviews.llvm.org/D68351
2019-09-19 11:56:43 -07:00
|
|
|
#include "InstrProfilingPort.h"
|
2017-12-14 19:01:04 +00:00
|
|
|
|
2015-12-29 07:13:59 +00:00
|
|
|
#define INSTR_PROF_VALUE_PROF_DATA
|
2019-11-22 12:09:15 -08:00
|
|
|
#include "profile/InstrProfData.inc"
|
2016-05-13 18:26:26 +00:00
|
|
|
|
2016-05-09 19:01:19 +00:00
|
|
|
COMPILER_RT_VISIBILITY void (*FreeHook)(void *) = NULL;
|
2016-05-13 18:26:26 +00:00
|
|
|
static ProfBufferIO TheBufferIO;
|
|
|
|
#define VP_BUFFER_SIZE 8 * 1024
|
|
|
|
static uint8_t BufferIOBuffer[VP_BUFFER_SIZE];
|
2016-05-14 20:12:42 +00:00
|
|
|
static InstrProfValueData VPDataArray[16];
|
|
|
|
static uint32_t VPDataArraySize = sizeof(VPDataArray) / sizeof(*VPDataArray);
|
|
|
|
|
2016-05-13 18:26:26 +00:00
|
|
|
COMPILER_RT_VISIBILITY uint8_t *DynamicBufferIOBuffer = 0;
|
|
|
|
COMPILER_RT_VISIBILITY uint32_t VPBufferSize = 0;
|
2015-12-29 07:13:59 +00:00
|
|
|
|
2021-09-04 13:01:34 +05:30
|
|
|
/* The buffer writer is responsible in keeping writer state
|
2015-12-22 18:57:15 +00:00
|
|
|
* across the call.
|
|
|
|
*/
|
2017-06-27 17:28:01 +00:00
|
|
|
COMPILER_RT_VISIBILITY uint32_t lprofBufferWriter(ProfDataWriter *This,
|
|
|
|
ProfDataIOVec *IOVecs,
|
|
|
|
uint32_t NumIOVecs) {
|
2015-12-22 18:57:15 +00:00
|
|
|
uint32_t I;
|
2017-06-27 17:28:01 +00:00
|
|
|
char **Buffer = (char **)&This->WriterCtx;
|
2015-12-22 18:57:15 +00:00
|
|
|
for (I = 0; I < NumIOVecs; I++) {
|
|
|
|
size_t Length = IOVecs[I].ElmSize * IOVecs[I].NumElm;
|
2017-06-28 16:46:06 +00:00
|
|
|
if (IOVecs[I].Data)
|
|
|
|
memcpy(*Buffer, IOVecs[I].Data, Length);
|
2019-12-10 18:17:28 -08:00
|
|
|
else if (IOVecs[I].UseZeroPadding) {
|
|
|
|
/* Allocating the buffer should zero fill. */
|
|
|
|
}
|
2015-12-22 18:57:15 +00:00
|
|
|
*Buffer += Length;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-18 21:08:03 +00:00
|
|
|
|
2017-06-27 17:28:01 +00:00
|
|
|
static void llvmInitBufferIO(ProfBufferIO *BufferIO, ProfDataWriter *FileWriter,
|
|
|
|
uint8_t *Buffer, uint32_t BufferSz) {
|
2015-12-29 23:54:41 +00:00
|
|
|
BufferIO->FileWriter = FileWriter;
|
2017-06-27 17:28:01 +00:00
|
|
|
BufferIO->OwnFileWriter = 0;
|
2015-12-29 23:54:41 +00:00
|
|
|
BufferIO->BufferStart = Buffer;
|
|
|
|
BufferIO->BufferSz = BufferSz;
|
|
|
|
BufferIO->CurOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
COMPILER_RT_VISIBILITY ProfBufferIO *
|
2017-06-27 17:28:01 +00:00
|
|
|
lprofCreateBufferIO(ProfDataWriter *FileWriter) {
|
2016-05-13 18:26:26 +00:00
|
|
|
uint8_t *Buffer = DynamicBufferIOBuffer;
|
|
|
|
uint32_t BufferSize = VPBufferSize;
|
2015-12-29 23:54:41 +00:00
|
|
|
if (!Buffer) {
|
2016-05-13 18:26:26 +00:00
|
|
|
Buffer = &BufferIOBuffer[0];
|
|
|
|
BufferSize = sizeof(BufferIOBuffer);
|
2015-12-29 23:54:41 +00:00
|
|
|
}
|
2017-06-27 17:28:01 +00:00
|
|
|
llvmInitBufferIO(&TheBufferIO, FileWriter, Buffer, BufferSize);
|
2016-05-13 18:26:26 +00:00
|
|
|
return &TheBufferIO;
|
2015-12-29 23:54:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 04:18:13 +00:00
|
|
|
COMPILER_RT_VISIBILITY void lprofDeleteBufferIO(ProfBufferIO *BufferIO) {
|
2017-06-27 17:28:01 +00:00
|
|
|
if (BufferIO->OwnFileWriter)
|
|
|
|
FreeHook(BufferIO->FileWriter);
|
2016-05-14 03:16:47 +00:00
|
|
|
if (DynamicBufferIOBuffer) {
|
2016-05-16 23:28:35 +00:00
|
|
|
FreeHook(DynamicBufferIOBuffer);
|
2016-05-14 03:16:47 +00:00
|
|
|
DynamicBufferIOBuffer = 0;
|
|
|
|
VPBufferSize = 0;
|
|
|
|
}
|
2015-12-29 23:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COMPILER_RT_VISIBILITY int
|
2016-03-06 04:18:13 +00:00
|
|
|
lprofBufferIOWrite(ProfBufferIO *BufferIO, const uint8_t *Data, uint32_t Size) {
|
2015-12-29 23:54:41 +00:00
|
|
|
/* Buffer is not large enough, it is time to flush. */
|
|
|
|
if (Size + BufferIO->CurOffset > BufferIO->BufferSz) {
|
2016-03-06 04:18:13 +00:00
|
|
|
if (lprofBufferIOFlush(BufferIO) != 0)
|
|
|
|
return -1;
|
2015-12-29 23:54:41 +00:00
|
|
|
}
|
|
|
|
/* Special case, bypass the buffer completely. */
|
2019-12-10 18:17:28 -08:00
|
|
|
ProfDataIOVec IO[] = {{Data, sizeof(uint8_t), Size, 0}};
|
2015-12-29 23:54:41 +00:00
|
|
|
if (Size > BufferIO->BufferSz) {
|
2017-06-27 17:28:01 +00:00
|
|
|
if (BufferIO->FileWriter->Write(BufferIO->FileWriter, IO, 1))
|
2015-12-29 23:54:41 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
/* Write the data to buffer */
|
|
|
|
uint8_t *Buffer = BufferIO->BufferStart + BufferIO->CurOffset;
|
2017-06-27 17:28:01 +00:00
|
|
|
ProfDataWriter BufferWriter;
|
|
|
|
initBufferWriter(&BufferWriter, (char *)Buffer);
|
|
|
|
lprofBufferWriter(&BufferWriter, IO, 1);
|
|
|
|
BufferIO->CurOffset =
|
|
|
|
(uint8_t *)BufferWriter.WriterCtx - BufferIO->BufferStart;
|
2015-12-29 23:54:41 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-06 04:18:13 +00:00
|
|
|
COMPILER_RT_VISIBILITY int lprofBufferIOFlush(ProfBufferIO *BufferIO) {
|
2015-12-29 23:54:41 +00:00
|
|
|
if (BufferIO->CurOffset) {
|
|
|
|
ProfDataIOVec IO[] = {
|
2019-12-10 18:17:28 -08:00
|
|
|
{BufferIO->BufferStart, sizeof(uint8_t), BufferIO->CurOffset, 0}};
|
2017-06-27 17:28:01 +00:00
|
|
|
if (BufferIO->FileWriter->Write(BufferIO->FileWriter, IO, 1))
|
2015-12-29 23:54:41 +00:00
|
|
|
return -1;
|
|
|
|
BufferIO->CurOffset = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-14 20:12:42 +00:00
|
|
|
/* Write out value profile data for function specified with \c Data.
|
|
|
|
* The implementation does not use the method \c serializeValueProfData
|
|
|
|
* which depends on dynamic memory allocation. In this implementation,
|
|
|
|
* value profile data is written out to \c BufferIO piecemeal.
|
|
|
|
*/
|
2016-05-12 21:18:41 +00:00
|
|
|
static int writeOneValueProfData(ProfBufferIO *BufferIO,
|
2016-05-14 20:12:42 +00:00
|
|
|
VPDataReaderType *VPDataReader,
|
2016-05-12 21:18:41 +00:00
|
|
|
const __llvm_profile_data *Data) {
|
2016-05-14 20:12:42 +00:00
|
|
|
unsigned I, NumValueKinds = 0;
|
|
|
|
ValueProfData VPHeader;
|
|
|
|
uint8_t *SiteCountArray[IPVK_Last + 1];
|
|
|
|
|
|
|
|
for (I = 0; I <= IPVK_Last; I++) {
|
|
|
|
if (!Data->NumValueSites[I])
|
|
|
|
SiteCountArray[I] = 0;
|
|
|
|
else {
|
|
|
|
uint32_t Sz =
|
|
|
|
VPDataReader->GetValueProfRecordHeaderSize(Data->NumValueSites[I]) -
|
|
|
|
offsetof(ValueProfRecord, SiteCountArray);
|
|
|
|
/* Only use alloca for this small byte array to avoid excessive
|
|
|
|
* stack growth. */
|
|
|
|
SiteCountArray[I] = (uint8_t *)COMPILER_RT_ALLOCA(Sz);
|
|
|
|
memset(SiteCountArray[I], 0, Sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If NumValueKinds returned is 0, there is nothing to write, report
|
|
|
|
success and return. This should match the raw profile reader's behavior. */
|
|
|
|
if (!(NumValueKinds = VPDataReader->InitRTRecord(Data, SiteCountArray)))
|
2016-05-12 21:18:41 +00:00
|
|
|
return 0;
|
2016-05-14 20:12:42 +00:00
|
|
|
|
|
|
|
/* First write the header structure. */
|
|
|
|
VPHeader.TotalSize = VPDataReader->GetValueProfDataSize();
|
|
|
|
VPHeader.NumValueKinds = NumValueKinds;
|
|
|
|
if (lprofBufferIOWrite(BufferIO, (const uint8_t *)&VPHeader,
|
|
|
|
sizeof(ValueProfData)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Make sure nothing else needs to be written before value profile
|
|
|
|
* records. */
|
|
|
|
if ((void *)VPDataReader->GetFirstValueProfRecord(&VPHeader) !=
|
|
|
|
(void *)(&VPHeader + 1))
|
2016-05-12 21:18:41 +00:00
|
|
|
return -1;
|
2016-05-14 20:12:42 +00:00
|
|
|
|
|
|
|
/* Write out the value profile record for each value kind
|
|
|
|
* one by one. */
|
|
|
|
for (I = 0; I <= IPVK_Last; I++) {
|
|
|
|
uint32_t J;
|
|
|
|
ValueProfRecord RecordHeader;
|
|
|
|
/* The size of the value prof record header without counting the
|
|
|
|
* site count array .*/
|
|
|
|
uint32_t RecordHeaderSize = offsetof(ValueProfRecord, SiteCountArray);
|
|
|
|
uint32_t SiteCountArraySize;
|
|
|
|
|
|
|
|
if (!Data->NumValueSites[I])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Write out the record header. */
|
|
|
|
RecordHeader.Kind = I;
|
|
|
|
RecordHeader.NumValueSites = Data->NumValueSites[I];
|
|
|
|
if (lprofBufferIOWrite(BufferIO, (const uint8_t *)&RecordHeader,
|
|
|
|
RecordHeaderSize))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Write out the site value count array including padding space. */
|
|
|
|
SiteCountArraySize =
|
|
|
|
VPDataReader->GetValueProfRecordHeaderSize(Data->NumValueSites[I]) -
|
|
|
|
RecordHeaderSize;
|
|
|
|
if (lprofBufferIOWrite(BufferIO, SiteCountArray[I], SiteCountArraySize))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Write out the value profile data for each value site. */
|
|
|
|
for (J = 0; J < Data->NumValueSites[I]; J++) {
|
|
|
|
uint32_t NRead, NRemain;
|
|
|
|
ValueProfNode *NextStartNode = 0;
|
|
|
|
NRemain = VPDataReader->GetNumValueDataForSite(I, J);
|
|
|
|
if (!NRemain)
|
|
|
|
continue;
|
|
|
|
/* Read and write out value data in small chunks till it is done. */
|
|
|
|
do {
|
|
|
|
NRead = (NRemain > VPDataArraySize ? VPDataArraySize : NRemain);
|
|
|
|
NextStartNode =
|
|
|
|
VPDataReader->GetValueData(I, /* ValueKind */
|
|
|
|
J, /* Site */
|
|
|
|
&VPDataArray[0], NextStartNode, NRead);
|
|
|
|
if (lprofBufferIOWrite(BufferIO, (const uint8_t *)&VPDataArray[0],
|
|
|
|
NRead * sizeof(InstrProfValueData)))
|
|
|
|
return -1;
|
|
|
|
NRemain -= NRead;
|
|
|
|
} while (NRemain != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* All done report success. */
|
2016-05-12 21:18:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:28:01 +00:00
|
|
|
static int writeValueProfData(ProfDataWriter *Writer,
|
2016-05-14 20:12:42 +00:00
|
|
|
VPDataReaderType *VPDataReader,
|
2016-05-10 00:17:31 +00:00
|
|
|
const __llvm_profile_data *DataBegin,
|
|
|
|
const __llvm_profile_data *DataEnd) {
|
2015-12-29 23:54:41 +00:00
|
|
|
ProfBufferIO *BufferIO;
|
2016-05-10 00:17:31 +00:00
|
|
|
const __llvm_profile_data *DI = 0;
|
2015-12-29 07:13:59 +00:00
|
|
|
|
2016-05-14 20:12:42 +00:00
|
|
|
if (!VPDataReader)
|
2015-12-29 07:13:59 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-06-27 17:28:01 +00:00
|
|
|
BufferIO = lprofCreateBufferIO(Writer);
|
2015-12-29 07:13:59 +00:00
|
|
|
|
2016-05-10 00:17:31 +00:00
|
|
|
for (DI = DataBegin; DI < DataEnd; DI++) {
|
2016-05-14 20:12:42 +00:00
|
|
|
if (writeOneValueProfData(BufferIO, VPDataReader, DI))
|
2015-12-29 07:13:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-06 04:18:13 +00:00
|
|
|
if (lprofBufferIOFlush(BufferIO) != 0)
|
2015-12-29 23:54:41 +00:00
|
|
|
return -1;
|
2016-03-06 04:18:13 +00:00
|
|
|
lprofDeleteBufferIO(BufferIO);
|
2015-12-29 23:54:41 +00:00
|
|
|
|
2015-12-29 07:13:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:28:01 +00:00
|
|
|
COMPILER_RT_VISIBILITY int lprofWriteData(ProfDataWriter *Writer,
|
2017-06-28 16:46:06 +00:00
|
|
|
VPDataReaderType *VPDataReader,
|
|
|
|
int SkipNameDataWrite) {
|
2016-05-10 00:17:31 +00:00
|
|
|
/* Match logic in __llvm_profile_write_buffer(). */
|
|
|
|
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
|
|
|
|
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
|
2021-12-29 13:36:28 -08:00
|
|
|
const char *CountersBegin = __llvm_profile_begin_counters();
|
|
|
|
const char *CountersEnd = __llvm_profile_end_counters();
|
2023-09-21 13:07:31 -05:00
|
|
|
const char *BitmapBegin = __llvm_profile_begin_bitmap();
|
|
|
|
const char *BitmapEnd = __llvm_profile_end_bitmap();
|
2016-05-10 00:17:31 +00:00
|
|
|
const char *NamesBegin = __llvm_profile_begin_names();
|
|
|
|
const char *NamesEnd = __llvm_profile_end_names();
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
const VTableProfData *VTableBegin = __llvm_profile_begin_vtables();
|
|
|
|
const VTableProfData *VTableEnd = __llvm_profile_end_vtables();
|
|
|
|
const char *VNamesBegin = __llvm_profile_begin_vtabnames();
|
|
|
|
const char *VNamesEnd = __llvm_profile_end_vtabnames();
|
2017-06-27 17:28:01 +00:00
|
|
|
return lprofWriteDataImpl(Writer, DataBegin, DataEnd, CountersBegin,
|
2023-09-21 13:07:31 -05:00
|
|
|
CountersEnd, BitmapBegin, BitmapEnd, VPDataReader,
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
NamesBegin, NamesEnd, VTableBegin, VTableEnd,
|
|
|
|
VNamesBegin, VNamesEnd, SkipNameDataWrite);
|
2016-05-10 00:17:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 04:18:13 +00:00
|
|
|
COMPILER_RT_VISIBILITY int
|
2017-06-27 17:28:01 +00:00
|
|
|
lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
|
2016-03-06 04:18:13 +00:00
|
|
|
const __llvm_profile_data *DataEnd,
|
2021-12-29 13:36:28 -08:00
|
|
|
const char *CountersBegin, const char *CountersEnd,
|
2023-09-21 13:07:31 -05:00
|
|
|
const char *BitmapBegin, const char *BitmapEnd,
|
2016-05-14 20:12:42 +00:00
|
|
|
VPDataReaderType *VPDataReader, const char *NamesBegin,
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
const char *NamesEnd, const VTableProfData *VTableBegin,
|
|
|
|
const VTableProfData *VTableEnd, const char *VNamesBegin,
|
|
|
|
const char *VNamesEnd, int SkipNameDataWrite) {
|
2015-11-18 21:08:03 +00:00
|
|
|
/* Calculate size of sections. */
|
2022-08-25 21:34:09 -07:00
|
|
|
const uint64_t DataSectionSize =
|
2023-11-01 14:16:43 -04:00
|
|
|
__llvm_profile_get_data_size(DataBegin, DataEnd);
|
|
|
|
const uint64_t NumData = __llvm_profile_get_num_data(DataBegin, DataEnd);
|
2022-08-25 21:34:09 -07:00
|
|
|
const uint64_t CountersSectionSize =
|
2021-12-29 13:36:28 -08:00
|
|
|
__llvm_profile_get_counters_size(CountersBegin, CountersEnd);
|
|
|
|
const uint64_t NumCounters =
|
|
|
|
__llvm_profile_get_num_counters(CountersBegin, CountersEnd);
|
2023-09-21 13:07:31 -05:00
|
|
|
const uint64_t NumBitmapBytes =
|
|
|
|
__llvm_profile_get_num_bitmap_bytes(BitmapBegin, BitmapEnd);
|
2023-11-01 14:16:43 -04:00
|
|
|
const uint64_t NamesSize = __llvm_profile_get_name_size(NamesBegin, NamesEnd);
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
const uint64_t NumVTables =
|
|
|
|
__llvm_profile_get_num_vtable(VTableBegin, VTableEnd);
|
|
|
|
const uint64_t VTableSectionSize =
|
|
|
|
__llvm_profile_get_vtable_section_size(VTableBegin, VTableEnd);
|
|
|
|
const uint64_t VNamesSize =
|
|
|
|
__llvm_profile_get_name_size(VNamesBegin, VNamesEnd);
|
2015-11-18 21:08:03 +00:00
|
|
|
|
|
|
|
/* Create the header. */
|
|
|
|
__llvm_profile_header Header;
|
|
|
|
|
[profile] Add a mode to continuously sync counter updates to a file
Add support for continuously syncing profile counter updates to a file.
The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.
The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.
Continuous mode is (for the moment) incompatible with the online merging
mode. This limitation is lifted in https://reviews.llvm.org/D69586.
Continuous mode is also (for the moment) incompatible with value
profiling, as I'm not sure whether there is interest in this and the
implementation may be tricky.
As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and some UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default. Continuous mode will
not "just work" on Fuchsia or Windows, as it's not possible to mmap() a
section on these platforms. There is a proposal to add a layer of
indirection to the profile instrumentation to support these platforms.
rdar://54210980
Differential Revision: https://reviews.llvm.org/D68351
2019-09-19 11:56:43 -07:00
|
|
|
/* Determine how much padding is needed before/after the counters and after
|
|
|
|
* the names. */
|
|
|
|
uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters,
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
PaddingBytesAfterBitmapBytes, PaddingBytesAfterNames,
|
|
|
|
PaddingBytesAfterVTable, PaddingBytesAfterVNames;
|
|
|
|
if (__llvm_profile_get_padding_sizes_for_counters(
|
|
|
|
DataSectionSize, CountersSectionSize, NumBitmapBytes, NamesSize,
|
|
|
|
VTableSectionSize, VNamesSize, &PaddingBytesBeforeCounters,
|
|
|
|
&PaddingBytesAfterCounters, &PaddingBytesAfterBitmapBytes,
|
|
|
|
&PaddingBytesAfterNames, &PaddingBytesAfterVTable,
|
|
|
|
&PaddingBytesAfterVNames) == -1)
|
|
|
|
return -1;
|
[profile] Add a mode to continuously sync counter updates to a file
Add support for continuously syncing profile counter updates to a file.
The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.
The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.
Continuous mode is (for the moment) incompatible with the online merging
mode. This limitation is lifted in https://reviews.llvm.org/D69586.
Continuous mode is also (for the moment) incompatible with value
profiling, as I'm not sure whether there is interest in this and the
implementation may be tricky.
As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and some UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default. Continuous mode will
not "just work" on Fuchsia or Windows, as it's not possible to mmap() a
section on these platforms. There is a proposal to add a layer of
indirection to the profile instrumentation to support these platforms.
rdar://54210980
Differential Revision: https://reviews.llvm.org/D68351
2019-09-19 11:56:43 -07:00
|
|
|
|
2022-01-19 10:09:56 -08:00
|
|
|
{
|
2016-05-10 00:17:31 +00:00
|
|
|
/* Initialize header structure. */
|
2015-11-23 18:36:40 +00:00
|
|
|
#define INSTR_PROF_RAW_HEADER(Type, Name, Init) Header.Name = Init;
|
2019-11-22 12:09:15 -08:00
|
|
|
#include "profile/InstrProfData.inc"
|
2022-01-19 10:09:56 -08:00
|
|
|
}
|
2015-11-18 21:08:03 +00:00
|
|
|
|
2021-07-30 11:52:18 -07:00
|
|
|
/* On WIN64, label differences are truncated 32-bit values. Truncate
|
|
|
|
* CountersDelta to match. */
|
|
|
|
#ifdef _WIN64
|
2021-08-06 09:19:25 +03:00
|
|
|
Header.CountersDelta = (uint32_t)Header.CountersDelta;
|
2023-09-21 13:07:31 -05:00
|
|
|
Header.BitmapDelta = (uint32_t)Header.BitmapDelta;
|
2021-07-30 11:52:18 -07:00
|
|
|
#endif
|
|
|
|
|
2021-12-16 14:19:03 -08:00
|
|
|
/* The data and names sections are omitted in lightweight mode. */
|
2023-11-14 14:03:10 -05:00
|
|
|
if (NumData == 0 && NamesSize == 0) {
|
2021-12-16 14:19:03 -08:00
|
|
|
Header.CountersDelta = 0;
|
|
|
|
Header.NamesDelta = 0;
|
|
|
|
}
|
|
|
|
|
2021-05-06 16:09:12 +00:00
|
|
|
/* Write the profile header. */
|
|
|
|
ProfDataIOVec IOVec[] = {{&Header, sizeof(__llvm_profile_header), 1, 0}};
|
|
|
|
if (Writer->Write(Writer, IOVec, sizeof(IOVec) / sizeof(*IOVec)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Write the binary id lengths and data. */
|
|
|
|
if (__llvm_write_binary_ids(Writer) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Write the profile data. */
|
|
|
|
ProfDataIOVec IOVecData[] = {
|
2023-11-14 14:03:10 -05:00
|
|
|
{DataBegin, sizeof(uint8_t), DataSectionSize, 0},
|
2019-12-10 18:17:28 -08:00
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1},
|
2022-08-25 21:34:09 -07:00
|
|
|
{CountersBegin, sizeof(uint8_t), CountersSectionSize, 0},
|
2019-12-10 18:17:28 -08:00
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1},
|
2023-09-21 13:07:31 -05:00
|
|
|
{BitmapBegin, sizeof(uint8_t), NumBitmapBytes, 0},
|
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesAfterBitmapBytes, 1},
|
2023-11-14 14:03:10 -05:00
|
|
|
{SkipNameDataWrite ? NULL : NamesBegin, sizeof(uint8_t), NamesSize, 0},
|
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed
patch](https://github.com/llvm/llvm-project/pull/81691) are [in commits
after this
one](https://github.com/llvm/llvm-project/pull/82711/commits/d0757f46b3e3865b5f7c552bc0744309a363e0ac).
Previous commits are restored from the remote branch with timestamps.
1. Fix build breakage for non-ELF platforms, by defining the missing
functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`,
`__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`}
everywhere.
* Tested on mac laptop (for darwins) and Windows. Specifically,
functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it
more explicit that type prof isn't supported; see comments for the
reason.
* For the rest (AIX, other), mostly follow existing examples (like this
[one](https://github.com/llvm/llvm-project/commit/f95b2f1acf1171abb0d00089fd4c9238753847e3))
2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section
name, and make returned pointers
[const](https://github.com/llvm/llvm-project/pull/82711/commits/a825d2a4ec00f07772a373091a702f149c3b0c34#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121)
**Original Description**
* Raw profile format
- Header: records the byte size of compressed vtable names, and the
number of profiled vtable entries (call it `VTableProfData`). Header
also records padded bytes of each section.
- Payload: adds a section for compressed vtable names, and a section to
store `VTableProfData`. Both sections are padded so the size is a
multiple of 8.
* Indexed profile format
- Header: records the byte offset of compressed vtable names.
- Payload: adds a section to store compressed vtable names. This section
is used by `llvm-profdata` to show the list of vtables profiled for an
instrumented site.
[The originally reviewed
patch](https://github.com/llvm/llvm-project/pull/66825) will have
profile reader/write change and llvm-profdata change.
- To ensure this PR has all the necessary profile format change along
with profile version bump, created a copy of the originally reviewed
patch in https://github.com/llvm/llvm-project/pull/80761. The copy
doesn't have profile format change, but it has the set of tests which
covers type profile generation, profile read and profile merge. Tests
pass there.
rfc in
https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
---------
Co-authored-by: modiking <modiking213@gmail.com>
2024-02-27 11:07:40 -08:00
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1},
|
|
|
|
{VTableBegin, sizeof(uint8_t), VTableSectionSize, 0},
|
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesAfterVTable, 1},
|
|
|
|
{SkipNameDataWrite ? NULL : VNamesBegin, sizeof(uint8_t), VNamesSize, 0},
|
|
|
|
{NULL, sizeof(uint8_t), PaddingBytesAfterVNames, 1}};
|
2021-05-06 16:09:12 +00:00
|
|
|
if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData)))
|
2015-11-21 04:16:42 +00:00
|
|
|
return -1;
|
2015-12-29 07:13:59 +00:00
|
|
|
|
2023-11-01 14:16:43 -04:00
|
|
|
/* Value profiling is not yet supported in continuous mode and profile
|
|
|
|
* correlation mode. */
|
2023-11-14 14:03:10 -05:00
|
|
|
if (__llvm_profile_is_continuous_mode_enabled() ||
|
|
|
|
(NumData == 0 && NamesSize == 0))
|
[profile] Add a mode to continuously sync counter updates to a file
Add support for continuously syncing profile counter updates to a file.
The motivation for this is that programs do not always exit cleanly. On
iOS, for example, programs are usually killed via a signal from the OS.
Running atexit() handlers after catching a signal is unreliable, so some
method for progressively writing out profile data is necessary.
The approach taken here is to mmap() the `__llvm_prf_cnts` section onto
a raw profile. To do this, the linker must page-align the counter and
data sections, and the runtime must ensure that counters are mapped to a
page-aligned offset within a raw profile.
Continuous mode is (for the moment) incompatible with the online merging
mode. This limitation is lifted in https://reviews.llvm.org/D69586.
Continuous mode is also (for the moment) incompatible with value
profiling, as I'm not sure whether there is interest in this and the
implementation may be tricky.
As I have not been able to test extensively on non-Darwin platforms,
only Darwin support is included for the moment. However, continuous mode
may "just work" without modification on Linux and some UNIX-likes. AIUI
the default value for the GNU linker's `--section-alignment` flag is set
to the page size on many systems. This appears to be true for LLD as
well, as its `no_nmagic` option is on by default. Continuous mode will
not "just work" on Fuchsia or Windows, as it's not possible to mmap() a
section on these platforms. There is a proposal to add a layer of
indirection to the profile instrumentation to support these platforms.
rdar://54210980
Differential Revision: https://reviews.llvm.org/D68351
2019-09-19 11:56:43 -07:00
|
|
|
return 0;
|
|
|
|
|
2017-06-27 17:28:01 +00:00
|
|
|
return writeValueProfData(Writer, VPDataReader, DataBegin, DataEnd);
|
2015-11-18 21:08:03 +00:00
|
|
|
}
|
2023-03-20 15:51:17 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write binary id length and then its data, because binary id does not
|
|
|
|
* have a fixed length.
|
|
|
|
*/
|
|
|
|
COMPILER_RT_VISIBILITY
|
|
|
|
int lprofWriteOneBinaryId(ProfDataWriter *Writer, uint64_t BinaryIdLen,
|
|
|
|
const uint8_t *BinaryIdData,
|
|
|
|
uint64_t BinaryIdPadding) {
|
|
|
|
ProfDataIOVec BinaryIdIOVec[] = {
|
|
|
|
{&BinaryIdLen, sizeof(uint64_t), 1, 0},
|
|
|
|
{BinaryIdData, sizeof(uint8_t), BinaryIdLen, 0},
|
|
|
|
{NULL, sizeof(uint8_t), BinaryIdPadding, 1},
|
|
|
|
};
|
|
|
|
if (Writer->Write(Writer, BinaryIdIOVec,
|
|
|
|
sizeof(BinaryIdIOVec) / sizeof(*BinaryIdIOVec)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Successfully wrote binary id, report success. */
|
|
|
|
return 0;
|
|
|
|
}
|