[compiler-rt] r204500 - InstrProf: Unify logic in two profile writers

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Mar 21 11:29:24 PDT 2014


Author: dexonsmith
Date: Fri Mar 21 13:29:24 2014
New Revision: 204500

URL: http://llvm.org/viewvc/llvm-project?rev=204500&view=rev
Log:
InstrProf: Unify logic in two profile writers

<rdar://problem/15943240>

Modified:
    compiler-rt/trunk/lib/profile/InstrProfiling.h
    compiler-rt/trunk/lib/profile/InstrProfilingBuffer.c
    compiler-rt/trunk/lib/profile/InstrProfilingFile.c

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=204500&r1=204499&r2=204500&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Fri Mar 21 13:29:24 2014
@@ -32,6 +32,8 @@ typedef unsigned int uint32_t;
 typedef unsigned long long uint64_t;
 #endif
 
+#define PROFILE_HEADER_SIZE 7
+
 typedef struct __llvm_profile_data {
   const uint32_t NameSize;
   const uint32_t NumCounters;

Modified: compiler-rt/trunk/lib/profile/InstrProfilingBuffer.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingBuffer.c?rev=204500&r1=204499&r2=204500&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingBuffer.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingBuffer.c Fri Mar 21 13:29:24 2014
@@ -11,13 +11,17 @@
 #include <string.h>
 
 uint64_t __llvm_profile_get_size_for_buffer(void) {
-  return sizeof(uint64_t) * 7 +
+  /* Match logic in __llvm_profile_write_buffer(). */
+  return sizeof(uint64_t) * PROFILE_HEADER_SIZE +
      PROFILE_RANGE_SIZE(data) * sizeof(__llvm_profile_data) +
      PROFILE_RANGE_SIZE(counters) * sizeof(uint64_t) +
      PROFILE_RANGE_SIZE(names) * sizeof(char);
 }
 
 int __llvm_profile_write_buffer(char *Buffer) {
+  /* Match logic in __llvm_profile_get_size_for_buffer().
+   * Match logic in __llvm_profile_write_file().
+   */
   const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
   const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
   const uint64_t *CountersBegin = __llvm_profile_counters_begin();
@@ -31,7 +35,7 @@ int __llvm_profile_write_buffer(char *Bu
   const uint64_t NamesSize = NamesEnd - NamesBegin;
 
   /* Create the header. */
-  uint64_t Header[] = {
+  uint64_t Header[PROFILE_HEADER_SIZE] = {
     __llvm_profile_get_magic(),
     __llvm_profile_get_version(),
     DataSize,
@@ -47,10 +51,10 @@ int __llvm_profile_write_buffer(char *Bu
     memcpy(Buffer, Data, Size);   \
     Buffer += Size;               \
   } while (0)
-  UPDATE_memcpy(Header,        sizeof(Header));
-  UPDATE_memcpy(DataBegin,     DataSize     * sizeof(__llvm_profile_data));
-  UPDATE_memcpy(CountersBegin, CountersSize * sizeof(uint64_t));
-  UPDATE_memcpy(NamesBegin,    NamesSize    * sizeof(char));
+  UPDATE_memcpy(Header,  PROFILE_HEADER_SIZE * sizeof(uint64_t));
+  UPDATE_memcpy(DataBegin,     DataSize      * sizeof(__llvm_profile_data));
+  UPDATE_memcpy(CountersBegin, CountersSize  * sizeof(uint64_t));
+  UPDATE_memcpy(NamesBegin,    NamesSize     * sizeof(char));
 #undef UPDATE_memcpy
 
   return 0;

Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=204500&r1=204499&r2=204500&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Fri Mar 21 13:29:24 2014
@@ -13,6 +13,7 @@
 #include <string.h>
 
 static int writeFile(FILE *File) {
+  /* Match logic in __llvm_profile_write_buffer(). */
   const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
   const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
   const uint64_t *CountersBegin = __llvm_profile_counters_begin();
@@ -25,29 +26,24 @@ static int writeFile(FILE *File) {
   const uint64_t CountersSize = CountersEnd - CountersBegin;
   const uint64_t NamesSize = NamesEnd - NamesBegin;
 
-  /* Get rest of header data. */
-  const uint64_t Magic = __llvm_profile_get_magic();
-  const uint64_t Version = __llvm_profile_get_version();
-  const uint64_t CountersDelta = (uint64_t)CountersBegin;
-  const uint64_t NamesDelta = (uint64_t)NamesBegin;
+  /* Create the header. */
+  uint64_t Header[PROFILE_HEADER_SIZE] = {
+    __llvm_profile_get_magic(),
+    __llvm_profile_get_version(),
+    DataSize,
+    CountersSize,
+    NamesSize,
+    (uint64_t)CountersBegin,
+    (uint64_t)NamesBegin
+  };
 
+  /* Write the data. */
 #define CHECK_fwrite(Data, Size, Length, File) \
   do { if (fwrite(Data, Size, Length, File) != Length) return -1; } while (0)
-
-  /* Write the header. */
-  CHECK_fwrite(&Magic,         sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&Version,       sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&DataSize,      sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&CountersSize,  sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&NamesSize,     sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&CountersDelta, sizeof(uint64_t), 1, File);
-  CHECK_fwrite(&NamesDelta,    sizeof(uint64_t), 1, File);
-
-  /* Write the data. */
-  CHECK_fwrite(DataBegin, sizeof(__llvm_profile_data), DataSize, File);
+  CHECK_fwrite(Header,        sizeof(uint64_t), PROFILE_HEADER_SIZE, File);
+  CHECK_fwrite(DataBegin,     sizeof(__llvm_profile_data), DataSize, File);
   CHECK_fwrite(CountersBegin, sizeof(uint64_t), CountersSize, File);
-  CHECK_fwrite(NamesBegin, sizeof(char), NamesSize, File);
-
+  CHECK_fwrite(NamesBegin,    sizeof(char), NamesSize, File);
 #undef CHECK_fwrite
 
    return 0;





More information about the llvm-commits mailing list