summaryrefslogtreecommitdiff
path: root/lib/profile/InstrProfilingValue.c
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-26 16:06:36 +0000
committerXinliang David Li <davidxl@google.com>2016-05-26 16:06:36 +0000
commit9329d69852d734a8375c006a57f1fa6805698884 (patch)
tree76b509b20b2d5593e7853622fd98735704da5d22 /lib/profile/InstrProfilingValue.c
parentc01d55815718528a56b4fdb27c7db34f7a04c6f0 (diff)
[profile] pre-allocate a small counter set in profile runtime
Tested with relavant benchmarks in SPEC2006 Differential Revision: http://reviews.llvm.org/D20651 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270862 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile/InstrProfilingValue.c')
-rw-r--r--lib/profile/InstrProfilingValue.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/profile/InstrProfilingValue.c b/lib/profile/InstrProfilingValue.c
index 63b5e6fca..ff149b5b8 100644
--- a/lib/profile/InstrProfilingValue.c
+++ b/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,10 +75,6 @@ __llvm_get_function_addr(const __llvm_profile_data *Data) {
* 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(__llvm_profile_data *Data) {
/* 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(__llvm_profile_data *Data, uint32_t Index,
/* 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"