[compiler-rt] 3b0a9e7 - [profile] Move assertIsZero to InstrProfilingUtil.c

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 15:25:22 PDT 2021


Author: Vedant Kumar
Date: 2021-08-02T15:25:09-07:00
New Revision: 3b0a9e7b392a916d961c5a8c09b570e4656267d5

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

LOG: [profile] Move assertIsZero to InstrProfilingUtil.c

... and rename it to 'warnIfNonZero' to better-reflect what it actually
does.

The goal is to minimize the amount of logic that's conditionally
compiled under '#if __APPLE__'.

Added: 
    

Modified: 
    compiler-rt/lib/profile/InstrProfilingFile.c
    compiler-rt/lib/profile/InstrProfilingUtil.c
    compiler-rt/lib/profile/InstrProfilingUtil.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 9f25af0f94449..8adb860c49d4f 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -428,11 +428,6 @@ static void truncateCurrentFile(void) {
 
 // TODO: Move these functions into InstrProfilingPlatform* files.
 #if defined(__APPLE__)
-static void assertIsZero(int *i) {
-  if (*i)
-    PROF_WARN("Expected flag to be 0, but got: %d\n", *i);
-}
-
 /* Write a partial profile to \p Filename, which is required to be backed by
  * the open file object \p File. */
 static int writeProfileWithFileObject(const char *Filename, FILE *File) {
@@ -495,7 +490,7 @@ static void initializeProfileForContinuousMode(void) {
 
   /* Whether an exclusive lock on the profile must be dropped after init.
    * Use a cleanup to warn if the unlock does not occur. */
-  COMPILER_RT_CLEANUP(assertIsZero) int ProfileRequiresUnlock = 0;
+  COMPILER_RT_CLEANUP(warnIfNonZero) int ProfileRequiresUnlock = 0;
 
   if (!doMerging()) {
     /* We are not merging profiles, so open the raw profile in append mode. */

diff  --git a/compiler-rt/lib/profile/InstrProfilingUtil.c b/compiler-rt/lib/profile/InstrProfilingUtil.c
index 4fa792b72eac8..ebc05e88b4a77 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -353,3 +353,8 @@ COMPILER_RT_VISIBILITY int lprofReleaseMemoryPagesToOS(uintptr_t Begin,
   }
   return 0;
 }
+
+COMPILER_RT_VISIBILITY void warnIfNonZero(int *i) {
+  if (*i)
+    PROF_WARN("Expected flag to be 0, but got: %d\n", *i);
+}

diff  --git a/compiler-rt/lib/profile/InstrProfilingUtil.h b/compiler-rt/lib/profile/InstrProfilingUtil.h
index 4a88a03580941..6d5d6c1c4675a 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.h
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.h
@@ -84,4 +84,7 @@ static inline size_t lprofRoundDownTo(size_t x, size_t boundary) {
 
 int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End);
 
+/// Noisly warn if *i is non-zero. Intended for use with COMPILER_RT_CLEANUP.
+void warnIfNonZero(int *i);
+
 #endif /* PROFILE_INSTRPROFILINGUTIL_H */


        


More information about the llvm-commits mailing list