diff --git a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h --- a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h +++ b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h @@ -12,6 +12,7 @@ #ifndef LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H #define LLVM_PROFILEDATA_INSTRPROFCORRELATOR_H +#include "llvm/ADT/StringSet.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" @@ -105,11 +106,13 @@ void addProbe(StringRef FunctionName, uint64_t CFGHash, IntPtrT CounterOffset, IntPtrT FunctionPtr, uint32_t NumCounters); + bool hasProbe(StringRef FunctionName) const; + private: InstrProfCorrelatorImpl(InstrProfCorrelatorKind Kind, std::unique_ptr Ctx) : InstrProfCorrelator(Kind, std::move(Ctx)){}; - std::vector Names; + llvm::StringSet<> Names; // Byte-swap the value if necessary. template T maybeSwap(T Value) const { diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp --- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp +++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp @@ -127,8 +127,9 @@ Error InstrProfCorrelatorImpl::correlateProfileData() { assert(Data.empty() && CompressedNames.empty() && Names.empty()); correlateProfileDataImpl(); - auto Result = - collectPGOFuncNameStrings(Names, /*doCompression=*/true, CompressedNames); + std::vector NamesVec(Names.keys().begin(), Names.keys().end()); + auto Result = collectPGOFuncNameStrings(NamesVec, /*doCompression=*/true, + CompressedNames); Names.clear(); return Result; } @@ -139,6 +140,7 @@ IntPtrT CounterOffset, IntPtrT FunctionPtr, uint32_t NumCounters) { + assert(!hasProbe(FunctionName)); Data.push_back({ maybeSwap(IndexedInstrProf::ComputeHash(FunctionName)), maybeSwap(CFGHash), @@ -151,7 +153,12 @@ maybeSwap(NumCounters), /*NumValueSites=*/{maybeSwap(0), maybeSwap(0)}, }); - Names.push_back(FunctionName.str()); + Names.insert(FunctionName); +} + +template +bool InstrProfCorrelatorImpl::hasProbe(StringRef FunctionName) const { + return Names.contains(FunctionName); } template @@ -219,6 +226,8 @@ if (auto EC = AnnotationFormValue->getAsCString().moveInto(FunctionName)) consumeError(std::move(EC)); + if (this->hasProbe(*FunctionName)) + return; } else if (AnnotationName.compare( InstrProfCorrelator::CFGHashAttributeName) == 0) { CFGHash = AnnotationFormValue->getAsUnsignedConstant();