summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-20 19:23:55 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-20 19:23:55 +0000
commit9dc20e221fee7fc576455aca6e139b835cef2cdc (patch)
treeb6bd4e2712105041e83ff7afcce46776bb42ea58
parentad53c076409f8b6d37de8514b0bcd80432ee342b (diff)
downloadcompiler-rt-9dc20e221fee7fc576455aca6e139b835cef2cdc.tar.gz
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> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204381 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/profile/InstrProfilingExtras.c29
-rw-r--r--lib/profile/InstrProfilingRuntime.cc2
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/profile/InstrProfilingExtras.c b/lib/profile/InstrProfilingExtras.c
index 45a7f8ce5..745bcb0db 100644
--- a/lib/profile/InstrProfilingExtras.c
+++ b/lib/profile/InstrProfilingExtras.c
@@ -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);
}
}
diff --git a/lib/profile/InstrProfilingRuntime.cc b/lib/profile/InstrProfilingRuntime.cc
index e6ef4c941..c493bf74a 100644
--- a/lib/profile/InstrProfilingRuntime.cc
+++ b/lib/profile/InstrProfilingRuntime.cc
@@ -20,7 +20,7 @@ namespace {
class RegisterAtExit {
public:
- RegisterAtExit() { __llvm_pgo_register_write_atexit(); }
+ RegisterAtExit() { __llvm_pgo_register_write_file_atexit(); }
};
RegisterAtExit Registration;