summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-20 19:23:53 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-20 19:23:53 +0000
commit775c178a90d8859a5da939d738fad248fde6edcd (patch)
treed17e6c76c1c82ebde6a55a4d38537ebd90f279c7 /compiler-rt/lib
parent5188e91cd4c7463029654119860e972541e8dd42 (diff)
downloadbcm5719-llvm-775c178a90d8859a5da939d738fad248fde6edcd.tar.gz
bcm5719-llvm-775c178a90d8859a5da939d738fad248fde6edcd.zip
PGO: Add explicit static initialization
Instead of relying on explicit static initialization from translation units, create a new file, InstrProfilingRuntime.cc, with an __llvm_pgo_runtime variable. After this commit (and its pair in clang), the driver will create a use of this variable. Unless the user defines their own version, the new object file will get pulled in, including that C++ static initialization that calls __llvm_pgo_register_write_atexit. The result is that, at least on Darwin, static initialization typically consists of a single function call, which registers a writeout functino atexit. Furthermore, users can skip even this behaviour by defining their own __llvm_pgo_runtime. <rdar://problem/15943240> llvm-svn: 204380
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/profile/CMakeLists.txt2
-rw-r--r--compiler-rt/lib/profile/InstrProfilingExtras.c5
-rw-r--r--compiler-rt/lib/profile/InstrProfilingRuntime.cc28
-rw-r--r--compiler-rt/lib/profile/Makefile.mk4
4 files changed, 32 insertions, 7 deletions
diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt
index 7de9c5e4b9b..949e174b40c 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -7,6 +7,7 @@ if(APPLE)
GCDAProfiling.c
InstrProfiling.c
InstrProfilingPlatformDarwin.c
+ InstrProfilingRuntime.cc
InstrProfilingExtras.c)
add_compiler_rt_osx_static_runtime(clang_rt.profile_osx
@@ -18,6 +19,7 @@ else()
GCDAProfiling.c
InstrProfiling.c
InstrProfilingPlatformOther.c
+ InstrProfilingRuntime.cc
InstrProfilingExtras.c)
foreach(arch ${PROFILE_SUPPORTED_ARCH})
diff --git a/compiler-rt/lib/profile/InstrProfilingExtras.c b/compiler-rt/lib/profile/InstrProfilingExtras.c
index 03399a3477f..45a7f8ce52c 100644
--- a/compiler-rt/lib/profile/InstrProfilingExtras.c
+++ b/compiler-rt/lib/profile/InstrProfilingExtras.c
@@ -9,7 +9,6 @@
#include "InstrProfiling.h"
-/*! \brief Write instrumentation data to the given file. */
void __llvm_pgo_write_file(const char *OutputName) {
/* TODO: Requires libc: move to separate translation unit. */
FILE *OutputFile;
@@ -26,7 +25,6 @@ void __llvm_pgo_write_file(const char *OutputName) {
fclose(OutputFile);
}
-/*! \brief Write instrumentation data to the default file. */
void __llvm_pgo_write_default_file() {
/* TODO: Requires libc: move to separate translation unit. */
const char *OutputName = getenv("LLVM_PROFILE_FILE");
@@ -35,9 +33,6 @@ void __llvm_pgo_write_default_file() {
__llvm_pgo_write_file(OutputName);
}
-/*!
- * \brief Register to write instrumentation data to the default file at exit.
- */
void __llvm_pgo_register_write_atexit() {
/* TODO: Requires libc: move to separate translation unit. */
static int HasBeenRegistered = 0;
diff --git a/compiler-rt/lib/profile/InstrProfilingRuntime.cc b/compiler-rt/lib/profile/InstrProfilingRuntime.cc
new file mode 100644
index 00000000000..e6ef4c94189
--- /dev/null
+++ b/compiler-rt/lib/profile/InstrProfilingRuntime.cc
@@ -0,0 +1,28 @@
+//===- InstrProfilingRuntime.cpp - PGO runtime initialization -------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+extern "C" {
+
+#include "InstrProfilingExtras.h"
+
+extern int __llvm_pgo_runtime;
+int __llvm_pgo_runtime;
+
+}
+
+namespace {
+
+class RegisterAtExit {
+public:
+ RegisterAtExit() { __llvm_pgo_register_write_atexit(); }
+};
+
+RegisterAtExit Registration;
+
+}
diff --git a/compiler-rt/lib/profile/Makefile.mk b/compiler-rt/lib/profile/Makefile.mk
index 7689c9a068c..dd3a36faf3b 100644
--- a/compiler-rt/lib/profile/Makefile.mk
+++ b/compiler-rt/lib/profile/Makefile.mk
@@ -10,8 +10,8 @@
ModuleName := profile
SubDirs :=
-Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file)))
-ObjNames := $(Sources:%.c=%.o)
+Sources := $(foreach file,$(wildcard $(Dir)/*.c $(Dir)/*.cc),$(notdir $(file)))
+ObjNames := $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(Sources)))
Implementation := Generic
# FIXME: use automatic dependencies?
OpenPOWER on IntegriCloud