From 019c78a994327bb1d41b2a1f6f8305993058d7a7 Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Tue, 24 Nov 2015 17:03:24 +0000 Subject: [PATCH] Minor refactor to make VP writing more efficient git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253994 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ProfileData/InstrProf.h | 14 ++++++++++---- lib/ProfileData/InstrProf.cpp | 4 +--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index b28689bfce1..872cc764bc0 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -259,8 +259,11 @@ struct InstrProfRecord { /// site: Site. inline uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const; + /// Return the array of profiled values at \p Site. inline std::unique_ptr getValueForSite(uint32_t ValueKind, uint32_t Site) const; + inline void getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, + uint32_t Site) const; /// Reserve space for NumValueSites sites. inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites); /// Add ValueData for ValueKind at value Site. @@ -369,14 +372,17 @@ InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const { return std::unique_ptr(nullptr); auto VD = llvm::make_unique(N); + getValueForSite(VD.get(), ValueKind, Site); + + return VD; +} +void InstrProfRecord::getValueForSite(InstrProfValueData Dest[], + uint32_t ValueKind, uint32_t Site) const { uint32_t I = 0; for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) { - VD[I] = V; + Dest[I] = V; I++; } - assert(I == N); - - return VD; } void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site, diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index fc7fc8aa1e2..b670902f3f9 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -166,10 +166,8 @@ void ValueProfRecord::serializeFrom(const InstrProfRecord &Record, for (uint32_t S = 0; S < NumValueSites; S++) { uint32_t ND = Record.getNumValueDataForSite(ValueKind, S); SiteCountArray[S] = ND; - std::unique_ptr SrcVD = - Record.getValueForSite(ValueKind, S); + Record.getValueForSite(DstVD, ValueKind, S); for (uint32_t I = 0; I < ND; I++) { - DstVD[I] = SrcVD[I]; switch (ValueKind) { case IPVK_IndirectCallTarget: DstVD[I].Value = IndexedInstrProf::ComputeHash( -- 2.34.1