[compiler-rt] r270862 - [profile] pre-allocate a small counter set in profile runtime
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 09:06:37 PDT 2016
Author: davidxl
Date: Thu May 26 11:06:36 2016
New Revision: 270862
URL: http://llvm.org/viewvc/llvm-project?rev=270862&view=rev
Log:
[profile] pre-allocate a small counter set in profile runtime
Tested with relavant benchmarks in SPEC2006
Differential Revision: http://reviews.llvm.org/D20651
Modified:
compiler-rt/trunk/lib/profile/InstrProfilingValue.c
Modified: compiler-rt/trunk/lib/profile/InstrProfilingValue.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingValue.c?rev=270862&r1=270861&r2=270862&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingValue.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingValue.c Thu May 26 11:06:36 2016
@@ -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,10 +75,6 @@ __llvm_get_function_addr(const __llvm_pr
* 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;
@@ -81,6 +82,10 @@ static int allocateValueProfileCounters(
/* 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 @@ static ValueProfNode *allocateOneNode(__
/* 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"
More information about the llvm-commits
mailing list