[PATCH] D20651: [profile] pre-allocate a small counter set in profile runtime

David Li via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 09:13:01 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL270862: [profile] pre-allocate a small counter set in profile runtime (authored by davidxl).

Changed prior to commit:
  http://reviews.llvm.org/D20651?vs=58538&id=58628#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20651

Files:
  compiler-rt/trunk/lib/profile/InstrProfilingValue.c

Index: compiler-rt/trunk/lib/profile/InstrProfilingValue.c
===================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingValue.c
+++ compiler-rt/trunk/lib/profile/InstrProfilingValue.c
@@ -18,31 +18,36 @@
 #define INSTR_PROF_COMMON_API_IMPL
 #include "InstrProfData.inc"
 
+static int hasStaticCounters = 1;
+static int OutOfNodesWarnings = 0;
+static int hasNonDefaultValsPerSite = 0;
+#define INSTR_PROF_MAX_VP_WARNS 10
+#define INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE 8
+#define INSTR_PROF_VNODE_POOL_SIZE 1024
+
+/* A shared static pool in addition to the vnodes statically
+ * allocated by the compiler.  */
+COMPILER_RT_VISIBILITY ValueProfNode
+    lprofValueProfNodes[INSTR_PROF_VNODE_POOL_SIZE] COMPILER_RT_SECTION(
+        INSTR_PROF_VNODES_SECT_NAME_STR);
+
 COMPILER_RT_VISIBILITY uint32_t VPMaxNumValsPerSite =
-    INSTR_PROF_MAX_NUM_VAL_PER_SITE;
+    INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE;
 
 COMPILER_RT_VISIBILITY void lprofSetupValueProfiler() {
   const char *Str = 0;
   Str = getenv("LLVM_VP_MAX_NUM_VALS_PER_SITE");
-  if (Str && Str[0])
+  if (Str && Str[0]) {
     VPMaxNumValsPerSite = atoi(Str);
+    hasNonDefaultValsPerSite = 1;
+  }
   if (VPMaxNumValsPerSite > INSTR_PROF_MAX_NUM_VAL_PER_SITE)
     VPMaxNumValsPerSite = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
-
-  if (!(EndVNode > CurrentVNode)) {
-    CurrentVNode = 0;
-    EndVNode = 0;
-  }
-  /* Adjust max vals per site to a smaller value
-   * when static allocation is in use. */
-  else {
-    if (!Str || !Str[0])
-      VPMaxNumValsPerSite = 8;
-  }
 }
 
 COMPILER_RT_VISIBILITY void lprofSetMaxValsPerSite(uint32_t MaxVals) {
   VPMaxNumValsPerSite = MaxVals;
+  hasNonDefaultValsPerSite = 1;
 }
 
 /* This method is only used in value profiler mock testing.  */
@@ -70,17 +75,17 @@
  * 0 if allocation fails.
  */
 
-static int hasStaticCounters = 1;
-static int OutOfNodesWarnings = 0;
-#define MAX_VP_WARNS 10
-
 static int allocateValueProfileCounters(__llvm_profile_data *Data) {
   uint64_t NumVSites = 0;
   uint32_t VKI;
 
   /* This function will never be called when value site array is allocated
      statically at compile time.  */
   hasStaticCounters = 0;
+  /* When dynamic allocation is enabled, allow tracking the max number of
+   * values allowd.  */
+  if (!hasNonDefaultValsPerSite)
+    VPMaxNumValsPerSite = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
 
   for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
     NumVSites += Data->NumValueSites[VKI];
@@ -105,7 +110,7 @@
 
   /* Early check to avoid value wrapping around.  */
   if (CurrentVNode >= EndVNode) {
-    if (OutOfNodesWarnings++ < MAX_VP_WARNS) {
+    if (OutOfNodesWarnings++ < INSTR_PROF_MAX_VP_WARNS) {
       PROF_WARN("Unable to track new values: %s. "
                 " Consider using option -mllvm -vp-counters-per-site=<n> to "
                 "allocate more"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20651.58628.patch
Type: text/x-patch
Size: 2881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160526/2695dc59/attachment.bin>


More information about the llvm-commits mailing list