[compiler-rt] r204299 - PGO: Split out initialization of section bounds

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Mar 19 20:23:10 PDT 2014


Author: dexonsmith
Date: Wed Mar 19 22:23:10 2014
New Revision: 204299

URL: http://llvm.org/viewvc/llvm-project?rev=204299&view=rev
Log:
PGO: Split out initialization of section bounds

Currently we register instrumentation data at runtime to determine the
bounds of the sections where the data lives.  Soon we'll implement
platform-specific linker magic to determine this at link time.

Move this logic to a separate file, so that our build system can choose
the correct platform-specific code.

No functionality change intended.

<rdar://problem/15943240>

Added:
    compiler-rt/trunk/lib/profile/InstrProfilingDefault.c
Modified:
    compiler-rt/trunk/lib/profile/CMakeLists.txt
    compiler-rt/trunk/lib/profile/InstrProfiling.c
    compiler-rt/trunk/lib/profile/InstrProfiling.h
    compiler-rt/trunk/make/platform/clang_darwin.mk

Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=204299&r1=204298&r2=204299&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/profile/CMakeLists.txt Wed Mar 19 22:23:10 2014
@@ -1,6 +1,7 @@
 set(PROFILE_SOURCES
   GCDAProfiling.c
   InstrProfiling.c
+  InstrProfilingDefault.c
   InstrProfilingExtras.c)
 
 filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm)

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=204299&r1=204298&r2=204299&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Wed Mar 19 22:23:10 2014
@@ -9,40 +9,6 @@
 
 #include "InstrProfiling.h"
 
-/* TODO: Calculate these with linker magic. */
-static const __llvm_pgo_data *First = NULL;
-static const __llvm_pgo_data *Last = NULL;
-
-/*!
- * \brief Register an instrumented function.
- *
- * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
- * calls are only required (and only emitted) on targets where we haven't
- * implemented linker magic to find the bounds of the section.
- *
- * For now, that's all targets.
- */
-void __llvm_pgo_register_function(void *Data_) {
-  /* TODO: Only emit this function if we can't use linker magic. */
-  const __llvm_pgo_data *Data = (__llvm_pgo_data*)Data_;
-  if (!First || Data < First)
-    First = Data;
-  if (!Last || Data >= Last)
-    Last = Data + 1;
-}
-
-/*! \brief Get the first instrumentation record. */
-static const __llvm_pgo_data *getFirst() {
-  /* TODO: Use extern + linker magic instead of a static variable. */
-  return First;
-}
-
-/*! \brief Get the last instrumentation record. */
-static const __llvm_pgo_data *getLast() {
-  /* TODO: Use extern + linker magic instead of a static variable. */
-  return Last;
-}
-
 /* TODO: void __llvm_pgo_get_size_for_buffer(void);  */
 
 static void writeFunction(FILE *OutputFile, const __llvm_pgo_data *Data) {
@@ -64,6 +30,7 @@ void __llvm_pgo_write_buffer(FILE *Outpu
    */
   const __llvm_pgo_data *I, *E;
 
-  for (I = getFirst(), E = getLast(); I != E; ++I)
+  for (I = __llvm_pgo_data_begin(), E = __llvm_pgo_data_end();
+       I != E; ++I)
     writeFunction(OutputFile, I);
 }

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=204299&r1=204298&r2=204299&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Wed Mar 19 22:23:10 2014
@@ -50,3 +50,10 @@ typedef struct __llvm_pgo_data {
  * to it.
  */
 void __llvm_pgo_write_buffer(FILE *OutputFile);
+
+const __llvm_pgo_data *__llvm_pgo_data_begin();
+const __llvm_pgo_data *__llvm_pgo_data_end();
+const char *__llvm_pgo_names_begin();
+const char *__llvm_pgo_names_end();
+const uint64_t *__llvm_pgo_counters_begin();
+const uint64_t *__llvm_pgo_counters_end();

Added: compiler-rt/trunk/lib/profile/InstrProfilingDefault.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingDefault.c?rev=204299&view=auto
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingDefault.c (added)
+++ compiler-rt/trunk/lib/profile/InstrProfilingDefault.c Wed Mar 19 22:23:10 2014
@@ -0,0 +1,59 @@
+/*===- InstrProfilingDefault.c - Profile data default platfrom ------------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file is distributed under the University of Illinois Open Source
+|* License. See LICENSE.TXT for details.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "InstrProfiling.h"
+
+static const __llvm_pgo_data *DataFirst = NULL;
+static const __llvm_pgo_data *DataLast = NULL;
+static const char *NamesFirst = NULL;
+static const char *NamesLast = NULL;
+static const uint64_t *CountersFirst = NULL;
+static const uint64_t *CountersLast = NULL;
+
+/*!
+ * \brief Register an instrumented function.
+ *
+ * Calls to this are emitted by clang with -fprofile-instr-generate.  Such
+ * calls are only required (and only emitted) on targets where we haven't
+ * implemented linker magic to find the bounds of the sections.
+ */
+void __llvm_pgo_register_function(void *Data_) {
+  /* TODO: Only emit this function if we can't use linker magic. */
+  const __llvm_pgo_data *Data = (__llvm_pgo_data*)Data_;
+  if (!DataFirst) {
+    DataFirst = Data;
+    DataLast = Data + 1;
+    NamesFirst = Data->Name;
+    NamesLast = Data->Name + Data->NameSize;
+    CountersFirst = Data->Counters;
+    CountersLast = Data->Counters + Data->NumCounters;
+    return;
+  }
+
+#define UPDATE_FIRST(First, New) \
+  First = New < First ? New : First
+  UPDATE_FIRST(DataFirst, Data);
+  UPDATE_FIRST(NamesFirst, Data->Name);
+  UPDATE_FIRST(CountersFirst, Data->Counters);
+#undef UPDATE_FIRST
+
+#define UPDATE_LAST(Last, New) \
+  Last = New > Last ? New : Last
+  UPDATE_LAST(DataLast, Data + 1);
+  UPDATE_LAST(NamesLast, Data->Name + Data->NameSize);
+  UPDATE_LAST(CountersLast, Data->Counters + Data->NumCounters);
+#undef UPDATE_LAST
+}
+
+const __llvm_pgo_data *__llvm_pgo_data_begin() { return DataFirst; }
+const __llvm_pgo_data *__llvm_pgo_data_end() { return DataLast; }
+const char *__llvm_pgo_names_begin() { return NamesFirst; }
+const char *__llvm_pgo_names_end() { return NamesLast; }
+const uint64_t *__llvm_pgo_counters_begin() { return CountersFirst; }
+const uint64_t *__llvm_pgo_counters_end() { return CountersLast; }

Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=204299&r1=204298&r2=204299&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
+++ compiler-rt/trunk/make/platform/clang_darwin.mk Wed Mar 19 22:23:10 2014
@@ -222,8 +222,9 @@ FUNCTIONS.ios.x86_64h := $(FUNCTIONS.ios
 
 FUNCTIONS.osx	:= mulosi4 mulodi4 muloti4
 
-FUNCTIONS.profile_osx := GCDAProfiling InstrProfiling InstrProfilingExtras
-FUNCTIONS.profile_ios := GCDAProfiling InstrProfiling InstrProfilingExtras
+FUNCTIONS.profile_osx := GCDAProfiling InstrProfiling \
+                         InstrProfilingDefault InstrProfilingExtras
+FUNCTIONS.profile_ios := $(FUNCTIONS.profile_osx)
 
 FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(InterceptionFunctions) \
                               $(SanitizerCommonFunctions) \





More information about the llvm-commits mailing list