[compiler-rt] r270371 - [profile] initialize static pool properly
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Sun May 22 09:36:05 PDT 2016
Author: davidxl
Date: Sun May 22 11:36:03 2016
New Revision: 270371
URL: http://llvm.org/viewvc/llvm-project?rev=270371&view=rev
Log:
[profile] initialize static pool properly
Remove dependency on runtime initializer to avoid
issues related to initialization order.
Modified:
compiler-rt/trunk/lib/profile/InstrProfilingPlatformDarwin.c
compiler-rt/trunk/lib/profile/InstrProfilingPlatformLinux.c
compiler-rt/trunk/lib/profile/InstrProfilingPlatformOther.c
compiler-rt/trunk/lib/profile/InstrProfilingValue.c
compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c
Modified: compiler-rt/trunk/lib/profile/InstrProfilingPlatformDarwin.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPlatformDarwin.c?rev=270371&r1=270370&r2=270371&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPlatformDarwin.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPlatformDarwin.c Sun May 22 11:36:03 2016
@@ -57,4 +57,7 @@ ValueProfNode *__llvm_profile_begin_vnod
}
COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
+
+COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
+COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
#endif
Modified: compiler-rt/trunk/lib/profile/InstrProfilingPlatformLinux.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPlatformLinux.c?rev=270371&r1=270370&r2=270371&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPlatformLinux.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPlatformLinux.c Sun May 22 11:36:03 2016
@@ -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
Modified: compiler-rt/trunk/lib/profile/InstrProfilingPlatformOther.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPlatformOther.c?rev=270371&r1=270370&r2=270371&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPlatformOther.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPlatformOther.c Sun May 22 11:36:03 2016
@@ -88,4 +88,7 @@ ValueProfNode *__llvm_profile_begin_vnod
COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
+COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
+COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
+
#endif
Modified: compiler-rt/trunk/lib/profile/InstrProfilingValue.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingValue.c?rev=270371&r1=270370&r2=270371&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingValue.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingValue.c Sun May 22 11:36:03 2016
@@ -29,8 +29,6 @@ COMPILER_RT_VISIBILITY void lprofSetupVa
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_pr
* 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(
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_
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_
else if (PrevVNode && !PrevVNode->Next)
Success = COMPILER_RT_BOOL_CMPXCHG(&(PrevVNode->Next), 0, CurrentVNode);
- if (!Success && hasNoStaticCounters()) {
+ if (!Success && !hasStaticCounters) {
free(CurrentVNode);
return;
}
Modified: compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c?rev=270371&r1=270370&r2=270371&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c (original)
+++ compiler-rt/trunk/test/profile/Linux/instrprof-merge-vp.c Sun May 22 11:36:03 2016
@@ -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
More information about the llvm-commits
mailing list