diff --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h --- a/llvm/tools/llvm-profgen/PerfReader.h +++ b/llvm/tools/llvm-profgen/PerfReader.h @@ -312,12 +312,9 @@ // Base class for sample counter key with context struct ContextKey { - uint64_t HashCode = 0; virtual ~ContextKey() = default; - uint64_t getHashCode() const { return HashCode; } - virtual bool isEqual(const ContextKey *K) const { - return HashCode == K->HashCode; - }; + virtual uint64_t getHashCode() = 0; + virtual bool isEqual(const ContextKey *K) const = 0; // Utilities for LLVM-style RTTI enum ContextKind { CK_StringBased, CK_ProbeBased }; @@ -341,7 +338,9 @@ return Context == Other->Context; } - void genHashCode() { HashCode = hash_value(SampleContextFrames(Context)); } + uint64_t getHashCode() override { + return hash_value(SampleContextFrames(Context)); + } }; // Probe based context key as the intermediate key of context @@ -364,7 +363,8 @@ O->Probes.end()); } - void genHashCode() { + uint64_t getHashCode() override { + uint64_t HashCode = 0; for (const auto *P : Probes) { HashCode = hash_combine(HashCode, P); } @@ -372,6 +372,7 @@ // Avoid zero value of HashCode when it's an empty list HashCode = 1; } + return HashCode; } }; diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -129,7 +129,6 @@ KeyStr->Context = Binary->getExpandedContext(Stack, KeyStr->WasLeafInlined); if (KeyStr->Context.empty()) return nullptr; - KeyStr->genHashCode(); return KeyStr; } @@ -143,8 +142,6 @@ ProbeBasedKey->Probes); CSProfileGenerator::trimContext( ProbeBasedKey->Probes); - - ProbeBasedKey->genHashCode(); return ProbeBasedKey; } @@ -802,7 +799,6 @@ SampleContext::createCtxVectorFromStr(*I.first, Key->Context); TraceIt.advance(); } - Key->genHashCode(); auto Ret = SampleCounters.emplace(Hashable(Key), SampleCounter()); readSampleCounters(TraceIt, Ret.first->second); @@ -851,7 +847,6 @@ "Sample counter map should be empty before raw profile generation"); std::shared_ptr Key = std::make_shared(); - Key->genHashCode(); SampleCounters.emplace(Hashable(Key), SampleCounter()); for (const auto &Item : AggregatedSamples) { const PerfSample *Sample = Item.first.getPtr();