[PATCH] D113059: [llvm-profgen] Refactor the code of getHashCode

Lei Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 2 19:58:55 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc9f03795512: [llvm-profgen] Refactor the code of getHashCode (authored by wlei).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113059/new/

https://reviews.llvm.org/D113059

Files:
  llvm/tools/llvm-profgen/PerfReader.cpp
  llvm/tools/llvm-profgen/PerfReader.h


Index: llvm/tools/llvm-profgen/PerfReader.h
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.h
+++ llvm/tools/llvm-profgen/PerfReader.h
@@ -314,7 +314,12 @@
 struct ContextKey {
   uint64_t HashCode = 0;
   virtual ~ContextKey() = default;
-  uint64_t getHashCode() const { return HashCode; }
+  uint64_t getHashCode() {
+    if (HashCode == 0)
+      genHashCode();
+    return HashCode;
+  }
+  virtual void genHashCode() = 0;
   virtual bool isEqual(const ContextKey *K) const {
     return HashCode == K->HashCode;
   };
@@ -341,7 +346,9 @@
     return Context == Other->Context;
   }
 
-  void genHashCode() { HashCode = hash_value(SampleContextFrames(Context)); }
+  void genHashCode() override {
+    HashCode = hash_value(SampleContextFrames(Context));
+  }
 };
 
 // Probe based context key as the intermediate key of context
@@ -364,7 +371,7 @@
                       O->Probes.end());
   }
 
-  void genHashCode() {
+  void genHashCode() override {
     for (const auto *P : Probes) {
       HashCode = hash_combine(HashCode, P);
     }
Index: llvm/tools/llvm-profgen/PerfReader.cpp
===================================================================
--- llvm/tools/llvm-profgen/PerfReader.cpp
+++ 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<const MCDecodedPseudoProbe *>(
       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<ContextKey>(Key), SampleCounter());
     readSampleCounters(TraceIt, Ret.first->second);
@@ -851,7 +847,6 @@
          "Sample counter map should be empty before raw profile generation");
   std::shared_ptr<StringBasedCtxKey> Key =
       std::make_shared<StringBasedCtxKey>();
-  Key->genHashCode();
   SampleCounters.emplace(Hashable<ContextKey>(Key), SampleCounter());
   for (const auto &Item : AggregatedSamples) {
     const PerfSample *Sample = Item.first.getPtr();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113059.384315.patch
Type: text/x-patch
Size: 2399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211103/455acf40/attachment.bin>


More information about the llvm-commits mailing list