forked from OSchip/llvm-project
				
			[profile] initialize static pool properly
Remove dependency on runtime initializer to avoid issues related to initialization order. llvm-svn: 270371
This commit is contained in:
		
							parent
							
								
									8ec7e7c216
								
							
						
					
					
						commit
						7b41393497
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue