[compiler-rt] r254831 - Use macro for common code pattern (NFC)

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 4 19:14:53 PST 2015


Author: davidxl
Date: Fri Dec  4 21:14:53 2015
New Revision: 254831

URL: http://llvm.org/viewvc/llvm-project?rev=254831&view=rev
Log:
Use macro for common code pattern (NFC)

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

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=254831&r1=254830&r2=254831&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Fri Dec  4 21:14:53 2015
@@ -209,6 +209,14 @@ static unsigned getVprofExtraBytes() {
   return (unsigned)atoi(ExtraStr);
 }
 
+/* Extract the value profile data info from the runtime. */
+#define DEF_VALUE_RECORD(R, NS, V)                                             \
+  ValueProfRuntimeRecord R;                                                    \
+  if (initializeValueProfRuntimeRecord(&R, NS, V))                             \
+    PROF_OOM_RETURN("Failed to write value profile data ");
+
+#define DTOR_VALUE_RECORD(R) finalizeValueProfRuntimeRecord(&R);
+
 LLVM_LIBRARY_VISIBILITY uint64_t
 __llvm_profile_gather_value_data(uint8_t **VDataArray) {
   size_t S = 0, RealSize = 0, BufferCapacity = 0, Extra = 0;
@@ -224,14 +232,14 @@ __llvm_profile_gather_value_data(uint8_t
    * structures for functions with value profile data.
    */
   for (I = (__llvm_profile_data *)DataBegin; I != DataEnd; ++I) {
-    ValueProfRuntimeRecord R;
-    /* Extract the value profile data info from the runtime. */
-    if (initializeValueProfRuntimeRecord(&R, I->NumValueSites, I->Values))
-      PROF_OOM_RETURN("Failed to write value profile data ");
+
+    DEF_VALUE_RECORD(R, I->NumValueSites, I->Values);
+
     /* Compute the size of ValueProfData from this runtime record.  */
     if (getNumValueKindsRT(&R) != 0)
       S += getValueProfDataSizeRT(&R);
-    finalizeValueProfRuntimeRecord(&R);
+
+    DTOR_VALUE_RECORD(R);
   }
   /* No value sites or no value profile data is collected. */
   if (!S)
@@ -253,9 +261,7 @@ __llvm_profile_gather_value_data(uint8_t
    * very low taken count.
    */
   for (I = (__llvm_profile_data *)DataBegin; I != DataEnd; ++I) {
-    ValueProfRuntimeRecord R;
-    if (initializeValueProfRuntimeRecord(&R, I->NumValueSites, I->Values))
-      PROF_OOM_RETURN("Failed to write value profile data ");
+    DEF_VALUE_RECORD(R, I->NumValueSites, I->Values);
     if (getNumValueKindsRT(&R) == 0)
       continue;
 
@@ -272,9 +278,9 @@ __llvm_profile_gather_value_data(uint8_t
     serializeValueProfDataFromRT(&R, VD);
     deallocateValueProfileCounters(I);
     I->Values = VD;
-    finalizeValueProfRuntimeRecord(&R);
     RealSize += VD->TotalSize;
     VD = (ValueProfData *)((char *)VD + VD->TotalSize);
+    DTOR_VALUE_RECORD(R);
   }
 
   return RealSize;




More information about the llvm-commits mailing list