[compiler-rt] r253700 - [PGO] Profile runtime name cleanups

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 20 11:41:03 PST 2015


Author: davidxl
Date: Fri Nov 20 13:41:02 2015
New Revision: 253700

URL: http://llvm.org/viewvc/llvm-project?rev=253700&view=rev
Log:
[PGO] Profile runtime name cleanups

Value profile enumerator change to match LLVM code
ProfData new member field name change to match LLVM code
ProfData member type change to match LLVM code
Do not use lower case for types that are internal to implementation (not exposed to APIs)
There is no functional change. This is a preparation patch to enable more code sharing
in follow up patches

Differential Revision: http://reviews.llvm.org/D14841


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

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=253700&r1=253699&r2=253700&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Fri Nov 20 13:41:02 2015
@@ -12,6 +12,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+typedef struct ValueProfNode {
+  __llvm_profile_value_data VData;
+  struct ValueProfNode *Next;
+} ValueProfNode;
+
 __attribute__((visibility("hidden"))) uint64_t __llvm_profile_get_magic(void) {
   /* Magic number to detect file format and endianness.
    *
@@ -54,14 +59,16 @@ __attribute__((visibility("hidden"))) vo
   for (DI = DataBegin; DI != DataEnd; ++DI) {
     uint64_t CurrentVSiteCount = 0;
     uint32_t VKI, i;
-    if (!DI->ValueCounters)
+    if (!DI->Values)
       continue;
 
-    for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
+    ValueProfNode **ValueCounters = (ValueProfNode **)DI->Values;
+
+    for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
       CurrentVSiteCount += DI->NumValueSites[VKI];
 
     for (i = 0; i < CurrentVSiteCount; ++i) {
-      __llvm_profile_value_node *CurrentVNode = DI->ValueCounters[i];
+      ValueProfNode *CurrentVNode = ValueCounters[i];
 
       while (CurrentVNode) {
         CurrentVNode->VData.NumTaken = 0;
@@ -91,14 +98,14 @@ __llvm_profile_instrument_target(uint64_
 static int allocateValueProfileCounters(__llvm_profile_data *Data) {
   uint64_t NumVSites = 0;
   uint32_t VKI;
-  for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
+  for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
     NumVSites += Data->NumValueSites[VKI];
 
-  __llvm_profile_value_node **Mem = (__llvm_profile_value_node **)calloc(
-      NumVSites, sizeof(__llvm_profile_value_node *));
+  ValueProfNode **Mem =
+      (ValueProfNode **)calloc(NumVSites, sizeof(ValueProfNode *));
   if (!Mem)
     return 0;
-  if (!__sync_bool_compare_and_swap(&Data->ValueCounters, 0, Mem)) {
+  if (!__sync_bool_compare_and_swap(&Data->Values, 0, Mem)) {
     free(Mem);
     return 0;
   }
@@ -113,20 +120,21 @@ static int allocateValueProfileCounters(
 }
 
 __attribute__((visibility("hidden"))) void
-__llvm_profile_instrument_target(uint64_t TargetValue, void *Data_,
+__llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
                                  uint32_t CounterIndex) {
 
-  __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
-  if (!Data)
+  __llvm_profile_data *VData = (__llvm_profile_data *)Data;
+  if (!VData)
     return;
 
-  if (!Data->ValueCounters) {
-    if (!allocateValueProfileCounters(Data))
+  if (!VData->Values) {
+    if (!allocateValueProfileCounters(VData))
       return;
   }
 
-  __llvm_profile_value_node *PrevVNode = NULL;
-  __llvm_profile_value_node *CurrentVNode = Data->ValueCounters[CounterIndex];
+  ValueProfNode **ValueCounters = (ValueProfNode **)VData->Values;
+  ValueProfNode *PrevVNode = NULL;
+  ValueProfNode *CurrentVNode = ValueCounters[CounterIndex];
 
   uint8_t VDataCount = 0;
   while (CurrentVNode) {
@@ -142,8 +150,7 @@ __llvm_profile_instrument_target(uint64_
   if (VDataCount >= UCHAR_MAX)
     return;
 
-  CurrentVNode =
-      (__llvm_profile_value_node *)calloc(1, sizeof(__llvm_profile_value_node));
+  CurrentVNode = (ValueProfNode *)calloc(1, sizeof(ValueProfNode));
   if (!CurrentVNode)
     return;
 
@@ -151,9 +158,9 @@ __llvm_profile_instrument_target(uint64_
   CurrentVNode->VData.NumTaken++;
 
   uint32_t Success = 0;
-  if (!Data->ValueCounters[CounterIndex])
-    Success = __sync_bool_compare_and_swap(&(Data->ValueCounters[CounterIndex]),
-                                           0, CurrentVNode);
+  if (!ValueCounters[CounterIndex])
+    Success = __sync_bool_compare_and_swap(&ValueCounters[CounterIndex], 0,
+                                           CurrentVNode);
   else if (PrevVNode && !PrevVNode->Next)
     Success = __sync_bool_compare_and_swap(&(PrevVNode->Next), 0, CurrentVNode);
 
@@ -161,8 +168,7 @@ __llvm_profile_instrument_target(uint64_
     free(CurrentVNode);
     return;
   }
-  __sync_fetch_and_add(&TotalValueDataSize,
-                       Success * sizeof(__llvm_profile_value_data));
+  __sync_fetch_and_add(&TotalValueDataSize, Success * sizeof(ValueProfNode));
 }
 #endif
 
@@ -187,10 +193,12 @@ __llvm_profile_gather_value_data(uint8_t
     uint64_t NumVSites = 0;
     uint32_t VKI, i;
 
-    if (!I->ValueCounters)
+    if (!I->Values)
       continue;
 
-    for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
+    ValueProfNode **ValueCounters = (ValueProfNode **)I->Values;
+
+    for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
       NumVSites += I->NumValueSites[VKI];
     uint8_t Padding = __llvm_profile_get_num_padding_bytes(NumVSites);
 
@@ -200,7 +208,7 @@ __llvm_profile_gather_value_data(uint8_t
 
     for (i = 0; i < NumVSites; ++i) {
 
-      __llvm_profile_value_node *VNode = I->ValueCounters[i];
+      ValueProfNode *VNode = ValueCounters[i];
 
       uint8_t VDataCount = 0;
       while (VNode && ((uint8_t *)(VDataPtr + 1) <= VDataEnd)) {
@@ -213,7 +221,7 @@ __llvm_profile_gather_value_data(uint8_t
       *PerSiteCountPtr = VDataCount;
       ++PerSiteCountPtr;
     }
-    I->ValueCounters = (void *)PerSiteCountsHead;
+    I->Values = (void *)PerSiteCountsHead;
     PerSiteCountsHead = (uint8_t *)VDataPtr;
   }
   return PerSiteCountsHead - *VDataArray;

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=253700&r1=253699&r2=253700&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.h Fri Nov 20 13:41:02 2015
@@ -35,31 +35,27 @@ typedef uint32_t uintptr_t;
 
 #endif /* defined(__FreeBSD__) && defined(__i386__) */
 
-typedef enum ValueKind {
-  VK_IndirectCallTarget = 0,
-  VK_FIRST = VK_IndirectCallTarget,
-  VK_LAST = VK_IndirectCallTarget
-} __llvm_profile_value_kind;
+enum ValueKind {
+  IPVK_IndirectCallTarget = 0,
+  IPVK_First = IPVK_IndirectCallTarget,
+  IPVK_Last = IPVK_IndirectCallTarget
+};
 
 typedef struct __llvm_profile_value_data {
   uint64_t TargetValue;
   uint64_t NumTaken;
 } __llvm_profile_value_data;
 
-typedef struct __llvm_profile_value_node {
-  __llvm_profile_value_data VData;
-  struct __llvm_profile_value_node *Next;
-} __llvm_profile_value_node;
-
+typedef void *IntPtrT;
 typedef struct LLVM_ALIGNAS(8) __llvm_profile_data {
   const uint32_t NameSize;
   const uint32_t NumCounters;
   const uint64_t FuncHash;
-  const char *const NamePtr;
-  uint64_t *const CounterPtr;
-  const uint8_t *FunctionPointer;
-  __llvm_profile_value_node **ValueCounters;
-  const uint16_t NumValueSites[VK_LAST + 1];
+  const IntPtrT NamePtr;
+  const IntPtrT CounterPtr;
+  const IntPtrT FunctionPointer;
+  IntPtrT Values;
+  const uint16_t NumValueSites[IPVK_Last + 1];
 } __llvm_profile_data;
 
 typedef struct __llvm_profile_header {
@@ -113,14 +109,14 @@ void __llvm_profile_reset_counters(void)
  * Records the target value for the CounterIndex if not seen before. Otherwise,
  * increments the counter associated w/ the target value.
  */
-void __llvm_profile_instrument_target(uint64_t TargetValue,
-  void *Data_, uint32_t CounterIndex);
+void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
+                                      uint32_t CounterIndex);
 
 /*!
  * \brief Prepares the value profiling data for output.
  *
  * Prepares a single __llvm_profile_value_data array out of the many
- * __llvm_profile_value_node trees (one per instrumented function).
+ * ValueProfNode trees (one per instrumented function).
  */
 uint64_t __llvm_profile_gather_value_data(uint8_t **DataArray);
 

Modified: compiler-rt/trunk/lib/profile/InstrProfilingWriter.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingWriter.c?rev=253700&r1=253699&r2=253700&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingWriter.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingWriter.c Fri Nov 20 13:41:02 2015
@@ -54,7 +54,7 @@ __attribute__((visibility("hidden"))) in
   Header.NamesSize = NamesSize;
   Header.CountersDelta = (uintptr_t)CountersBegin;
   Header.NamesDelta = (uintptr_t)NamesBegin;
-  Header.ValueKindLast = VK_LAST;
+  Header.ValueKindLast = IPVK_Last;
   Header.ValueDataSize = ValueDataSize;
   Header.ValueDataDelta = (uintptr_t)ValueDataBegin;
 




More information about the llvm-commits mailing list