2014-03-20 06:10:27 +08:00
|
|
|
/*===- InstrProfiling.c - Support library for PGO instrumentation ---------===*\
|
|
|
|
|*
|
|
|
|
|* 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-03-21 03:44:31 +08:00
|
|
|
#include <string.h>
|
2014-03-20 06:10:27 +08:00
|
|
|
|
2014-03-21 04:00:44 +08:00
|
|
|
/* TODO: void __llvm_profile_get_size_for_buffer(void); */
|
2014-03-20 06:10:27 +08:00
|
|
|
|
2014-03-21 08:27:50 +08:00
|
|
|
static int writeFunction(FILE *OutputFile, const __llvm_profile_data *Data) {
|
2014-03-20 06:10:27 +08:00
|
|
|
/* TODO: Requires libc: break requirement by writing directly to a buffer
|
|
|
|
* instead of a FILE stream.
|
|
|
|
*/
|
|
|
|
uint32_t I;
|
|
|
|
for (I = 0; I < Data->NameSize; ++I)
|
2014-03-21 08:27:50 +08:00
|
|
|
if (fputc(Data->Name[I], OutputFile) != Data->Name[I])
|
|
|
|
return -1;
|
|
|
|
if (fprintf(OutputFile, "\n%" PRIu64 "\n%u\n", Data->FuncHash,
|
|
|
|
Data->NumCounters) < 0)
|
|
|
|
return -1;
|
2014-03-20 06:10:27 +08:00
|
|
|
for (I = 0; I < Data->NumCounters; ++I)
|
2014-03-21 08:27:50 +08:00
|
|
|
if (fprintf(OutputFile, "%" PRIu64 "\n", Data->Counters[I]) < 0)
|
|
|
|
return -1;
|
|
|
|
if (fprintf(OutputFile, "\n") < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2014-03-20 06:10:27 +08:00
|
|
|
}
|
|
|
|
|
2014-03-21 08:27:50 +08:00
|
|
|
int __llvm_profile_write_buffer(FILE *OutputFile) {
|
2014-03-20 06:10:27 +08:00
|
|
|
/* TODO: Requires libc: break requirement by taking a char* buffer instead of
|
|
|
|
* a FILE stream.
|
|
|
|
*/
|
2014-03-21 04:00:44 +08:00
|
|
|
const __llvm_profile_data *I, *E;
|
2014-03-20 06:10:27 +08:00
|
|
|
|
2014-03-21 04:00:44 +08:00
|
|
|
for (I = __llvm_profile_data_begin(), E = __llvm_profile_data_end();
|
2014-03-20 11:23:10 +08:00
|
|
|
I != E; ++I)
|
2014-03-21 08:27:50 +08:00
|
|
|
if (writeFunction(OutputFile, I))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
2014-03-20 06:10:27 +08:00
|
|
|
}
|
2014-03-21 03:44:31 +08:00
|
|
|
|
2014-03-21 04:00:44 +08:00
|
|
|
void __llvm_profile_reset_counters(void) {
|
|
|
|
uint64_t *I = __llvm_profile_counters_begin();
|
|
|
|
uint64_t *E = __llvm_profile_counters_end();
|
2014-03-21 03:44:31 +08:00
|
|
|
|
|
|
|
memset(I, 0, sizeof(uint64_t)*(E - I));
|
|
|
|
}
|