[compiler-rt] ba1f440 - [profile] Move RuntimeCounterRelocation and ProfileDumped into a separate file

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 24 20:27:49 PDT 2020


Author: Petr Hosek
Date: 2020-03-24T20:27:14-07:00
New Revision: ba1f4405c6828308649b994ecb2d056fabc80a8c

URL: https://github.com/llvm/llvm-project/commit/ba1f4405c6828308649b994ecb2d056fabc80a8c
DIFF: https://github.com/llvm/llvm-project/commit/ba1f4405c6828308649b994ecb2d056fabc80a8c.diff

LOG: [profile] Move RuntimeCounterRelocation and ProfileDumped into a separate file

This avoids the test failure that was introduced in rG32bddad where
this function pulls in the rest of InstrProfilingFile.c which is
undesirable in use cases when profile runtime is being used without
the rest of libc.

This also allows additional cleanup by eliminating another variable
from platforms that don't need it.

Differential Revision: https://reviews.llvm.org/D76750

Added: 
    compiler-rt/lib/profile/InstrProfilingInternal.c

Modified: 
    compiler-rt/lib/profile/CMakeLists.txt
    compiler-rt/lib/profile/InstrProfiling.c
    compiler-rt/lib/profile/InstrProfilingFile.c
    compiler-rt/lib/profile/InstrProfilingInternal.h
    compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt
index 8cedbcf4f806..ece674b2daa1 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -51,6 +51,7 @@ add_compiler_rt_component(profile)
 set(PROFILE_SOURCES
   GCDAProfiling.c
   InstrProfiling.c
+  InstrProfilingInternal.c
   InstrProfilingValue.c
   InstrProfilingBiasVar.c
   InstrProfilingBuffer.c

diff  --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c
index 087d1cdd2efe..31a9fe996293 100644
--- a/compiler-rt/lib/profile/InstrProfiling.c
+++ b/compiler-rt/lib/profile/InstrProfiling.c
@@ -25,18 +25,8 @@ COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
                                             : (INSTR_PROF_RAW_MAGIC_32);
 }
 
-static unsigned ProfileDumped = 0;
-
-COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() {
-  return ProfileDumped;
-}
-
-COMPILER_RT_VISIBILITY void lprofSetProfileDumped() {
-  ProfileDumped = 1;
-}
-
 COMPILER_RT_VISIBILITY void __llvm_profile_set_dumped() {
-  lprofSetProfileDumped();
+  lprofSetProfileDumped(1);
 }
 
 /* Return the number of bytes needed to add to SizeInBytes to make it
@@ -80,5 +70,5 @@ COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
       }
     }
   }
-  ProfileDumped = 0;
+  lprofSetProfileDumped(0);
 }

diff  --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 875de885b2ee..9e1a54a0c373 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -35,16 +35,6 @@
 #include "InstrProfilingPort.h"
 #include "InstrProfilingUtil.h"
 
-static int RuntimeCounterRelocation = 0;
-
-COMPILER_RT_VISIBILITY unsigned lprofRuntimeCounterRelocation(void) {
-  return RuntimeCounterRelocation;
-}
-
-COMPILER_RT_VISIBILITY void lprofSetRuntimeCounterRelocation(void) {
-  RuntimeCounterRelocation = 1;
-}
-
 /* From where is profile name specified.
  * The order the enumerators define their
  * precedence. Re-order them may lead to
@@ -974,7 +964,7 @@ void __llvm_profile_initialize_file(void) {
   int hasCommandLineOverrider = (INSTR_PROF_PROFILE_NAME_VAR[0] != 0);
 
   if (__llvm_profile_counter_bias != -1)
-    lprofSetRuntimeCounterRelocation();
+    lprofSetRuntimeCounterRelocation(1);
 
   EnvFilenamePat = getFilenamePatFromEnv();
   if (EnvFilenamePat) {
@@ -1072,7 +1062,7 @@ int __llvm_profile_dump(void) {
               "in profile name or change profile name before dumping.\n",
               "online profile merging is not on");
   int rc = __llvm_profile_write_file();
-  lprofSetProfileDumped();
+  lprofSetProfileDumped(1);
   return rc;
 }
 

diff  --git a/compiler-rt/lib/profile/InstrProfilingInternal.c b/compiler-rt/lib/profile/InstrProfilingInternal.c
new file mode 100644
index 000000000000..d58bc19ad11e
--- /dev/null
+++ b/compiler-rt/lib/profile/InstrProfilingInternal.c
@@ -0,0 +1,33 @@
+/*===- InstrProfilingInternal.c - Support library for PGO instrumentation -===*\
+|*
+|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+|* See https://llvm.org/LICENSE.txt for license information.
+|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+|*
+\*===----------------------------------------------------------------------===*/
+
+#if !defined(__Fuchsia__)
+
+#include "InstrProfilingInternal.h"
+
+static unsigned ProfileDumped = 0;
+
+COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() {
+  return ProfileDumped;
+}
+
+COMPILER_RT_VISIBILITY void lprofSetProfileDumped(unsigned Value) {
+  ProfileDumped = Value;
+}
+
+static unsigned RuntimeCounterRelocation = 0;
+
+COMPILER_RT_VISIBILITY unsigned lprofRuntimeCounterRelocation(void) {
+  return RuntimeCounterRelocation;
+}
+
+COMPILER_RT_VISIBILITY void lprofSetRuntimeCounterRelocation(unsigned Value) {
+  RuntimeCounterRelocation = Value;
+}
+
+#endif

diff  --git a/compiler-rt/lib/profile/InstrProfilingInternal.h b/compiler-rt/lib/profile/InstrProfilingInternal.h
index 32b63955d937..904bd3945928 100644
--- a/compiler-rt/lib/profile/InstrProfilingInternal.h
+++ b/compiler-rt/lib/profile/InstrProfilingInternal.h
@@ -181,12 +181,12 @@ uint64_t lprofGetLoadModuleSignature();
  * Return non zero value if the profile data has already been
  * dumped to the file.
  */
-unsigned lprofProfileDumped();
-void lprofSetProfileDumped();
+unsigned lprofProfileDumped(void);
+void lprofSetProfileDumped(unsigned);
 
 /* Return non zero value if counters are being relocated at runtime. */
 unsigned lprofRuntimeCounterRelocation(void);
-void lprofSetRuntimeCounterRelocation(void);
+void lprofSetRuntimeCounterRelocation(unsigned);
 
 COMPILER_RT_VISIBILITY extern void (*FreeHook)(void *);
 COMPILER_RT_VISIBILITY extern uint8_t *DynamicBufferIOBuffer;

diff  --git a/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c b/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
index 63c8b75b9d12..828f74221393 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
@@ -34,9 +34,15 @@
 #include "InstrProfilingInternal.h"
 #include "InstrProfilingUtil.h"
 
+COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() {
+  return 1;
+}
+COMPILER_RT_VISIBILITY void lprofSetProfileDumped(unsigned Value) {}
+
 COMPILER_RT_VISIBILITY unsigned lprofRuntimeCounterRelocation(void) {
   return 1;
 }
+COMPILER_RT_VISIBILITY void lprofSetRuntimeCounterRelocation(unsigned Value) {}
 
 /* VMO that contains the profile data for this module. */
 static zx_handle_t __llvm_profile_vmo;


        


More information about the llvm-commits mailing list