<div dir="ltr">Thanks! I was looking at this code recently and was thinking about doing something similar.<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 12, 2016 at 2:43 PM, Xinliang David Li via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davidxl<br>
Date: Thu May 12 16:43:49 2016<br>
New Revision: 269357<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=269357&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=269357&view=rev</a><br>
Log:<br>
[profile] Code refactoring<br>
<br>
Move runtime specific code from the common header file<br>
to runtime source.<br>
<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/profile/InstrProfData.inc<br>
    compiler-rt/trunk/lib/profile/InstrProfilingValue.c<br>
<br>
Modified: compiler-rt/trunk/lib/profile/InstrProfData.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfData.inc?rev=269357&r1=269356&r2=269357&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfData.inc?rev=269357&r1=269356&r2=269357&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/profile/InstrProfData.inc (original)<br>
+++ compiler-rt/trunk/lib/profile/InstrProfData.inc Thu May 12 16:43:49 2016<br>
@@ -384,16 +384,6 @@ typedef struct ValueProfRuntimeRecord {<br>
   ValueProfNode **NodesKind[IPVK_Last + 1];<br>
 } ValueProfRuntimeRecord;<br>
<br>
-/* Forward declarations of C interfaces.  */<br>
-int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord,<br>
-                                     const uint16_t *NumValueSites,<br>
-                                     ValueProfNode **Nodes);<br>
-void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord);<br>
-uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record);<br>
-ValueProfData *<br>
-serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,<br>
-                             ValueProfData *Dst);<br>
-uint32_t getNumValueKindsRT(const void *R);<br>
 ValueProfRecord *getFirstValueProfRecord(ValueProfData *VPD);<br>
 ValueProfRecord *getValueProfRecordNext(ValueProfRecord *VPR);<br>
 InstrProfValueData *getValueProfRecordValueData(ValueProfRecord *VPR);<br>
@@ -554,115 +544,6 @@ ValueProfData *serializeValueProfDataFro<br>
   return VPD;<br>
 }<br>
<br>
-/*<br>
- * The value profiler runtime library stores the value profile data<br>
- * for a given function in \c NumValueSites and \c Nodes structures.<br>
- * \c ValueProfRuntimeRecord class is used to encapsulate the runtime<br>
- * profile data and provides fast interfaces to retrieve the profile<br>
- * information. This interface is used to initialize the runtime record<br>
- * and pre-compute the information needed for efficient implementation<br>
- * of callbacks required by ValueProfRecordClosure class.<br>
- */<br>
-int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord,<br>
-                                     const uint16_t *NumValueSites,<br>
-                                     ValueProfNode **Nodes) {<br>
-  unsigned I, S = 0, NumValueKinds = 0;<br>
-  RuntimeRecord->NumValueSites = NumValueSites;<br>
-  RuntimeRecord->Nodes = Nodes;<br>
-  for (I = 0; I <= IPVK_Last; I++) {<br>
-    uint16_t N = NumValueSites[I];<br>
-    if (!N)<br>
-      continue;<br>
-    NumValueKinds++;<br>
-<br>
-    RuntimeRecord->NodesKind[I] = Nodes ? &Nodes[S] : INSTR_PROF_NULLPTR;<br>
-    S += N;<br>
-  }<br>
-  RuntimeRecord->NumValueKinds = NumValueKinds;<br>
-  return 0;<br>
-}<br>
-<br>
-void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) {}<br>
-<br>
-/* ValueProfRecordClosure Interface implementation for<br>
- * ValueProfDataRuntimeRecord.  */<br>
-uint32_t getNumValueKindsRT(const void *R) {<br>
-  return ((const ValueProfRuntimeRecord *)R)->NumValueKinds;<br>
-}<br>
-<br>
-uint32_t getNumValueSitesRT(const void *R, uint32_t VK) {<br>
-  return ((const ValueProfRuntimeRecord *)R)->NumValueSites[VK];<br>
-}<br>
-<br>
-uint32_t getNumValueDataForSiteRT(const void *R, uint32_t VK, uint32_t S) {<br>
-  uint32_t C = 0;<br>
-  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
-  ValueProfNode *Site =<br>
-      Record->NodesKind[VK] ? Record->NodesKind[VK][S] : INSTR_PROF_NULLPTR;<br>
-  while (Site) {<br>
-    C++;<br>
-    Site = Site->Next;<br>
-  }<br>
-  if (C > UCHAR_MAX)<br>
-    C = UCHAR_MAX;<br>
-<br>
-  return C;<br>
-}<br>
-<br>
-uint32_t getNumValueDataRT(const void *R, uint32_t VK) {<br>
-  unsigned I, S = 0;<br>
-  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
-  for (I = 0; I < Record->NumValueSites[VK]; I++)<br>
-    S += getNumValueDataForSiteRT(Record, VK, I);<br>
-  return S;<br>
-}<br>
-<br>
-void getValueForSiteRT(const void *R, InstrProfValueData *Dst, uint32_t VK,<br>
-                       uint32_t S) {<br>
-  unsigned I, N = 0;<br>
-  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
-  N = getNumValueDataForSiteRT(R, VK, S);<br>
-  if (N == 0)<br>
-    return;<br>
-  ValueProfNode *VNode = Record->NodesKind[VK][S];<br>
-  for (I = 0; I < N; I++) {<br>
-    Dst[I] = VNode->VData;<br>
-    VNode = VNode->Next;<br>
-  }<br>
-}<br>
-<br>
-ValueProfData *allocValueProfDataRT(size_t TotalSizeInBytes) {<br>
-  return (ValueProfData *)calloc(TotalSizeInBytes, 1);<br>
-}<br>
-<br>
-static ValueProfRecordClosure RTRecordClosure = {<br>
-    INSTR_PROF_NULLPTR, getNumValueKindsRT,       getNumValueSitesRT,<br>
-    getNumValueDataRT,  getNumValueDataForSiteRT, INSTR_PROF_NULLPTR,<br>
-    getValueForSiteRT,  allocValueProfDataRT};<br>
-<br>
-/*<br>
- * Return the size of ValueProfData structure to store data<br>
- * recorded in the runtime record.<br>
- */<br>
-uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record) {<br>
-  RTRecordClosure.Record = Record;<br>
-  return getValueProfDataSize(&RTRecordClosure);<br>
-}<br>
-<br>
-/*<br>
- * Return a ValueProfData instance that stores the data collected<br>
- * from runtime. If \c DstData is provided by the caller, the value<br>
- * profile data will be store in *DstData and DstData is returned,<br>
- * otherwise the method will allocate space for the value data and<br>
- * return pointer to the newly allocated space.<br>
- */<br>
-ValueProfData *<br>
-serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,<br>
-                             ValueProfData *DstData) {<br>
-  RTRecordClosure.Record = Record;<br>
-  return serializeValueProfDataFrom(&RTRecordClosure, DstData);<br>
-}<br>
-<br>
 #undef INSTR_PROF_COMMON_API_IMPL<br>
 #endif /* INSTR_PROF_COMMON_API_IMPL */<br>
<br>
<br>
Modified: compiler-rt/trunk/lib/profile/InstrProfilingValue.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingValue.c?rev=269357&r1=269356&r2=269357&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingValue.c?rev=269357&r1=269356&r2=269357&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/profile/InstrProfilingValue.c (original)<br>
+++ compiler-rt/trunk/lib/profile/InstrProfilingValue.c Thu May 12 16:43:49 2016<br>
@@ -117,6 +117,118 @@ __llvm_profile_instrument_target(uint64_<br>
   }<br>
 }<br>
<br>
+ValueProfData *allocValueProfDataRT(size_t TotalSizeInBytes) {<br>
+  return (ValueProfData *)calloc(TotalSizeInBytes, 1);<br>
+}<br>
+<br>
+/*<br>
+ * The value profiler runtime library stores the value profile data<br>
+ * for a given function in \c NumValueSites and \c Nodes structures.<br>
+ * \c ValueProfRuntimeRecord class is used to encapsulate the runtime<br>
+ * profile data and provides fast interfaces to retrieve the profile<br>
+ * information. This interface is used to initialize the runtime record<br>
+ * and pre-compute the information needed for efficient implementation<br>
+ * of callbacks required by ValueProfRecordClosure class.<br>
+ */<br>
+static int<br>
+initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord,<br>
+                                 const uint16_t *NumValueSites,<br>
+                                 ValueProfNode **Nodes) {<br>
+  unsigned I, S = 0, NumValueKinds = 0;<br>
+  RuntimeRecord->NumValueSites = NumValueSites;<br>
+  RuntimeRecord->Nodes = Nodes;<br>
+  for (I = 0; I <= IPVK_Last; I++) {<br>
+    uint16_t N = NumValueSites[I];<br>
+    if (!N)<br>
+      continue;<br>
+    NumValueKinds++;<br>
+<br>
+    RuntimeRecord->NodesKind[I] = Nodes ? &Nodes[S] : INSTR_PROF_NULLPTR;<br>
+    S += N;<br>
+  }<br>
+  RuntimeRecord->NumValueKinds = NumValueKinds;<br>
+  return 0;<br>
+}<br>
+<br>
+static void<br>
+finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) {}<br>
+<br>
+/* ValueProfRecordClosure Interface implementation for<br>
+ * ValueProfDataRuntimeRecord.  */<br>
+static uint32_t getNumValueKindsRT(const void *R) {<br>
+  return ((const ValueProfRuntimeRecord *)R)->NumValueKinds;<br>
+}<br>
+<br>
+static uint32_t getNumValueSitesRT(const void *R, uint32_t VK) {<br>
+  return ((const ValueProfRuntimeRecord *)R)->NumValueSites[VK];<br>
+}<br>
+<br>
+static uint32_t getNumValueDataForSiteRT(const void *R, uint32_t VK,<br>
+                                         uint32_t S) {<br>
+  uint32_t C = 0;<br>
+  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
+  ValueProfNode *Site =<br>
+      Record->NodesKind[VK] ? Record->NodesKind[VK][S] : INSTR_PROF_NULLPTR;<br>
+  while (Site) {<br>
+    C++;<br>
+    Site = Site->Next;<br>
+  }<br>
+  if (C > UCHAR_MAX)<br>
+    C = UCHAR_MAX;<br>
+<br>
+  return C;<br>
+}<br>
+<br>
+static uint32_t getNumValueDataRT(const void *R, uint32_t VK) {<br>
+  unsigned I, S = 0;<br>
+  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
+  for (I = 0; I < Record->NumValueSites[VK]; I++)<br>
+    S += getNumValueDataForSiteRT(Record, VK, I);<br>
+  return S;<br>
+}<br>
+<br>
+static void getValueForSiteRT(const void *R, InstrProfValueData *Dst,<br>
+                              uint32_t VK, uint32_t S) {<br>
+  unsigned I, N = 0;<br>
+  const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;<br>
+  N = getNumValueDataForSiteRT(R, VK, S);<br>
+  if (N == 0)<br>
+    return;<br>
+  ValueProfNode *VNode = Record->NodesKind[VK][S];<br>
+  for (I = 0; I < N; I++) {<br>
+    Dst[I] = VNode->VData;<br>
+    VNode = VNode->Next;<br>
+  }<br>
+}<br>
+<br>
+static ValueProfRecordClosure RTRecordClosure = {<br>
+    INSTR_PROF_NULLPTR, getNumValueKindsRT,       getNumValueSitesRT,<br>
+    getNumValueDataRT,  getNumValueDataForSiteRT, INSTR_PROF_NULLPTR,<br>
+    getValueForSiteRT,  allocValueProfDataRT};<br>
+<br>
+/*<br>
+ * Return a ValueProfData instance that stores the data collected<br>
+ * from runtime. If \c DstData is provided by the caller, the value<br>
+ * profile data will be store in *DstData and DstData is returned,<br>
+ * otherwise the method will allocate space for the value data and<br>
+ * return pointer to the newly allocated space.<br>
+ */<br>
+static ValueProfData *<br>
+serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,<br>
+                             ValueProfData *DstData) {<br>
+  RTRecordClosure.Record = Record;<br>
+  return serializeValueProfDataFrom(&RTRecordClosure, DstData);<br>
+}<br>
+<br>
+/*<br>
+ * Return the size of ValueProfData structure to store data<br>
+ * recorded in the runtime record.<br>
+ */<br>
+static uint32_t getValueProfDataSizeRT(const ValueProfRuntimeRecord *Record) {<br>
+  RTRecordClosure.Record = Record;<br>
+  return getValueProfDataSize(&RTRecordClosure);<br>
+}<br>
+<br>
 COMPILER_RT_VISIBILITY struct ValueProfData *<br>
 lprofGatherValueProfData(const __llvm_profile_data *Data) {<br>
   ValueProfData *VD = NULL;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>