PGO: Update interface for writing instrumentation data to file

__llvm_pgo_write_default_file() was a bad name, since it checked the
environment (it wasn't just a default file).

  - Change __llvm_pgo_write_file() to __llvm_pgo_write_file_with_name()
    and make it static.

  - Rename __llvm_pgo_write_default_file() to __llvm_pgo_write_file().

  - Add __llvm_pgo_set_filename(), which sets the filename for
    subsequent calls to __llvm_pgo_write_file().

<rdar://problem/15943240>

llvm-svn: 204381
This commit is contained in:
Duncan P. N. Exon Smith 2014-03-20 19:23:55 +00:00
parent 775c178a90
commit 54cc0e2d81
2 changed files with 19 additions and 12 deletions

View File

@ -9,8 +9,7 @@
#include "InstrProfiling.h"
void __llvm_pgo_write_file(const char *OutputName) {
/* TODO: Requires libc: move to separate translation unit. */
static void __llvm_pgo_write_file_with_name(const char *OutputName) {
FILE *OutputFile;
if (!OutputName || !OutputName[0])
return;
@ -25,20 +24,28 @@ void __llvm_pgo_write_file(const char *OutputName) {
fclose(OutputFile);
}
void __llvm_pgo_write_default_file() {
/* TODO: Requires libc: move to separate translation unit. */
const char *OutputName = getenv("LLVM_PROFILE_FILE");
if (OutputName == NULL || OutputName[0] == '\0')
OutputName = "default.profdata";
__llvm_pgo_write_file(OutputName);
static const char *CurrentFilename = NULL;
void __llvm_pgo_set_filename(const char *Filename) {
CurrentFilename = Filename;
}
void __llvm_pgo_register_write_atexit() {
/* TODO: Requires libc: move to separate translation unit. */
void __llvm_pgo_write_file() {
const char *Filename = CurrentFilename;
#define UPDATE_FILENAME(NextFilename) \
if (!Filename || !Filename[0]) Filename = NextFilename
UPDATE_FILENAME(getenv("LLVM_PROFILE_FILE"));
UPDATE_FILENAME("default.profdata");
#undef UPDATE_FILENAME
__llvm_pgo_write_file_with_name(Filename);
}
void __llvm_pgo_register_write_file_atexit() {
static int HasBeenRegistered = 0;
if (!HasBeenRegistered) {
HasBeenRegistered = 1;
atexit(__llvm_pgo_write_default_file);
atexit(__llvm_pgo_write_file);
}
}

View File

@ -20,7 +20,7 @@ namespace {
class RegisterAtExit {
public:
RegisterAtExit() { __llvm_pgo_register_write_atexit(); }
RegisterAtExit() { __llvm_pgo_register_write_file_atexit(); }
};
RegisterAtExit Registration;