[compiler-rt] r204381 - PGO: Update interface for writing instrumentation data to file

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Mar 20 12:23:55 PDT 2014


Author: dexonsmith
Date: Thu Mar 20 14:23:55 2014
New Revision: 204381

URL: http://llvm.org/viewvc/llvm-project?rev=204381&view=rev
Log:
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>

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingExtras.c
    compiler-rt/trunk/lib/profile/InstrProfilingRuntime.cc

Modified: compiler-rt/trunk/lib/profile/InstrProfilingExtras.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingExtras.c?rev=204381&r1=204380&r2=204381&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingExtras.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingExtras.c Thu Mar 20 14:23:55 2014
@@ -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 *O
   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);
   }
 }

Modified: compiler-rt/trunk/lib/profile/InstrProfilingRuntime.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingRuntime.cc?rev=204381&r1=204380&r2=204381&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingRuntime.cc (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingRuntime.cc Thu Mar 20 14:23:55 2014
@@ -20,7 +20,7 @@ namespace {
 
 class RegisterAtExit {
 public:
-  RegisterAtExit() { __llvm_pgo_register_write_atexit(); }
+  RegisterAtExit() { __llvm_pgo_register_write_file_atexit(); }
 };
 
 RegisterAtExit Registration;





More information about the llvm-commits mailing list