From 3c2876c91fc083db3ebcbc859368a149d764796d Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Wed, 11 May 2016 23:21:22 +0000 Subject: [profile] profile writing cleanup Do not precompute value counts for all sites. This eliminates one more use of dynamic allocation in profiler writer. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269254 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/profile/InstrProfData.inc | 50 ++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) (limited to 'lib/profile/InstrProfData.inc') diff --git a/lib/profile/InstrProfData.inc b/lib/profile/InstrProfData.inc index 6db5caeeb..93a69c664 100644 --- a/lib/profile/InstrProfData.inc +++ b/lib/profile/InstrProfData.inc @@ -381,9 +381,6 @@ typedef struct ValueProfRuntimeRecord { /* Total number of value profile kinds which have at least one * value profile sites. */ uint32_t NumValueKinds; - /* An array recording the number of values tracked at each site. - * The size of the array is TotalNumValueSites. */ - uint8_t *SiteCountArray[IPVK_Last + 1]; ValueProfNode **NodesKind[IPVK_Last + 1]; } ValueProfRuntimeRecord; @@ -569,46 +566,23 @@ ValueProfData *serializeValueProfDataFrom(ValueProfRecordClosure *Closure, int initializeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord, const uint16_t *NumValueSites, ValueProfNode **Nodes) { - unsigned I, J, S = 0, NumValueKinds = 0; + unsigned I, S = 0, NumValueKinds = 0; RuntimeRecord->NumValueSites = NumValueSites; RuntimeRecord->Nodes = Nodes; for (I = 0; I <= IPVK_Last; I++) { uint16_t N = NumValueSites[I]; - if (!N) { - RuntimeRecord->SiteCountArray[I] = INSTR_PROF_NULLPTR; + if (!N) continue; - } NumValueKinds++; - RuntimeRecord->SiteCountArray[I] = (uint8_t *)calloc(N, 1); - if (!RuntimeRecord->SiteCountArray[I]) - return 1; + RuntimeRecord->NodesKind[I] = Nodes ? &Nodes[S] : INSTR_PROF_NULLPTR; - for (J = 0; J < N; J++) { - /* Compute value count for each site. */ - uint32_t C = 0; - ValueProfNode *Site = - Nodes ? RuntimeRecord->NodesKind[I][J] : INSTR_PROF_NULLPTR; - while (Site) { - C++; - Site = Site->Next; - } - if (C > UCHAR_MAX) - C = UCHAR_MAX; - RuntimeRecord->SiteCountArray[I][J] = C; - } S += N; } RuntimeRecord->NumValueKinds = NumValueKinds; return 0; } -void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) { - unsigned I; - for (I = 0; I <= IPVK_Last; I++) { - if (RuntimeRecord->SiteCountArray[I]) - free(RuntimeRecord->SiteCountArray[I]); - } -} +void finalizeValueProfRuntimeRecord(ValueProfRuntimeRecord *RuntimeRecord) {} /* ValueProfRecordClosure Interface implementation for * ValueProfDataRuntimeRecord. */ @@ -621,17 +595,25 @@ uint32_t getNumValueSitesRT(const void *R, uint32_t VK) { } uint32_t getNumValueDataForSiteRT(const void *R, uint32_t VK, uint32_t S) { + uint32_t C = 0; const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R; - return Record->SiteCountArray[VK][S]; + ValueProfNode *Site = + Record->NodesKind[VK] ? Record->NodesKind[VK][S] : INSTR_PROF_NULLPTR; + while (Site) { + C++; + Site = Site->Next; + } + if (C > UCHAR_MAX) + C = UCHAR_MAX; + + return C; } uint32_t getNumValueDataRT(const void *R, uint32_t VK) { unsigned I, S = 0; const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R; - if (Record->SiteCountArray[VK] == INSTR_PROF_NULLPTR) - return 0; for (I = 0; I < Record->NumValueSites[VK]; I++) - S += Record->SiteCountArray[VK][I]; + S += getNumValueDataForSiteRT(Record, VK, I); return S; } -- cgit v1.2.3