summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c3
-rw-r--r--compiler-rt/lib/profile/InstrProfilingPlatformLinux.c6
-rw-r--r--compiler-rt/lib/profile/InstrProfilingPlatformOther.c3
-rw-r--r--compiler-rt/lib/profile/InstrProfilingValue.c19
-rw-r--r--compiler-rt/test/profile/Linux/instrprof-merge-vp.c2
5 files changed, 20 insertions, 13 deletions
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c b/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c
index 477020a01a5..8931abaddf7 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c
@@ -57,4 +57,7 @@ ValueProfNode *__llvm_profile_begin_vnodes(void) {
}
COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
+
+COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
+COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
#endif
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
index 679f183859e..b6c780ff514 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -66,8 +66,10 @@ COMPILER_RT_VISIBILITY ValueProfNode *
__llvm_profile_begin_vnodes(void) {
return &PROF_VNODES_START;
}
-COMPILER_RT_VISIBILITY ValueProfNode *
-__llvm_profile_end_vnodes(void) {
+COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {
return &PROF_VNODES_STOP;
}
+COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &PROF_VNODES_START;
+COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &PROF_VNODES_STOP;
+
#endif
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
index 66cfa903720..b25966487e9 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
@@ -88,4 +88,7 @@ ValueProfNode *__llvm_profile_begin_vnodes(void) {
COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
+COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
+COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
+
#endif
diff --git a/compiler-rt/lib/profile/InstrProfilingValue.c b/compiler-rt/lib/profile/InstrProfilingValue.c
index 0c404e0ba5c..c78e75540f8 100644
--- a/compiler-rt/lib/profile/InstrProfilingValue.c
+++ b/compiler-rt/lib/profile/InstrProfilingValue.c
@@ -29,8 +29,6 @@ COMPILER_RT_VISIBILITY void lprofSetupValueProfiler() {
if (VPMaxNumValsPerSite > INSTR_PROF_MAX_NUM_VAL_PER_SITE)
VPMaxNumValsPerSite = INSTR_PROF_MAX_NUM_VAL_PER_SITE;
- CurrentVNode = __llvm_profile_begin_vnodes();
- EndVNode = __llvm_profile_end_vnodes();
if (!(EndVNode > CurrentVNode)) {
CurrentVNode = 0;
EndVNode = 0;
@@ -72,9 +70,16 @@ __llvm_get_function_addr(const __llvm_profile_data *Data) {
* 0 if allocation fails.
*/
+static int hasStaticCounters = 1;
+
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;
+
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
NumVSites += Data->NumValueSites[VKI];
@@ -89,15 +94,11 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) {
return 1;
}
-COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
-COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
-static int hasNoStaticCounters() { return (EndVNode == 0); }
-
static ValueProfNode *allocateOneNode(__llvm_profile_data *Data, uint32_t Index,
uint64_t Value) {
ValueProfNode *Node;
- if (hasNoStaticCounters())
+ if (!hasStaticCounters)
return (ValueProfNode *)calloc(1, sizeof(ValueProfNode));
Node = COMPILER_RT_PTR_FETCH_ADD(ValueProfNode, CurrentVNode, 1);
@@ -116,8 +117,6 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
if (!PData)
return;
- /* This path will never be taken when value site array is allocated
- statically at compile time. */
if (!PData->Values) {
if (!allocateValueProfileCounters(PData))
return;
@@ -195,7 +194,7 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
else if (PrevVNode && !PrevVNode->Next)
Success = COMPILER_RT_BOOL_CMPXCHG(&(PrevVNode->Next), 0, CurrentVNode);
- if (!Success && hasNoStaticCounters()) {
+ if (!Success && !hasStaticCounters) {
free(CurrentVNode);
return;
}
diff --git a/compiler-rt/test/profile/Linux/instrprof-merge-vp.c b/compiler-rt/test/profile/Linux/instrprof-merge-vp.c
index 21d83750830..8daed3352b2 100644
--- a/compiler-rt/test/profile/Linux/instrprof-merge-vp.c
+++ b/compiler-rt/test/profile/Linux/instrprof-merge-vp.c
@@ -1,4 +1,4 @@
-// RUN: %clang_profgen -mllvm --enable-value-profiling=true -O2 -o %t %s
+// RUN: %clang_profgen -mllvm --enable-value-profiling=true -mllvm -vp-static-alloc=true -mllvm -vp-counters-per-site=3 -O2 -o %t %s
// RUN: %run %t %t.profraw
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: llvm-profdata show --all-functions --counts --ic-targets %t.profdata > %t.profdump
OpenPOWER on IntegriCloud