[llvm] 891ce5b - [NFC][StructuralHash] Use hash_code

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 14:12:19 PDT 2023


Author: Arthur Eubanks
Date: 2023-04-25T14:12:06-07:00
New Revision: 891ce5bdceadd938901289c19ce2b0bf34bdfbb9

URL: https://github.com/llvm/llvm-project/commit/891ce5bdceadd938901289c19ce2b0bf34bdfbb9
DIFF: https://github.com/llvm/llvm-project/commit/891ce5bdceadd938901289c19ce2b0bf34bdfbb9.diff

LOG: [NFC][StructuralHash] Use hash_code

Added: 
    

Modified: 
    llvm/lib/IR/StructuralHash.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp
index 077f8b6562f5..8fcd337c6a0d 100644
--- a/llvm/lib/IR/StructuralHash.cpp
+++ b/llvm/lib/IR/StructuralHash.cpp
@@ -19,19 +19,19 @@ namespace {
 // llvm/lib/Transforms/Utils/FunctionComparator.cpp
 
 class StructuralHashImpl {
-  uint64_t Hash = 0x6acaa36bef8325c5ULL;
+  hash_code Hash;
 
-  void update(uint64_t V) { Hash = hashing::detail::hash_16_bytes(Hash, V); }
+  template <typename T> void hash(const T &V) { Hash = hash_combine(Hash, V); }
 
 public:
-  StructuralHashImpl() = default;
+  StructuralHashImpl() : Hash(4) {}
 
   void update(const Function &F) {
     if (F.empty())
       return;
 
-    update(F.isVarArg());
-    update(F.arg_size());
+    hash(F.isVarArg());
+    hash(F.arg_size());
 
     SmallVector<const BasicBlock *, 8> BBs;
     SmallPtrSet<const BasicBlock *, 16> VisitedBBs;
@@ -40,9 +40,9 @@ class StructuralHashImpl {
     VisitedBBs.insert(BBs[0]);
     while (!BBs.empty()) {
       const BasicBlock *BB = BBs.pop_back_val();
-      update(45798); // Block header
+      hash(45798); // Block header
       for (auto &Inst : *BB)
-        update(Inst.getOpcode());
+        hash(Inst.getOpcode());
 
       const Instruction *Term = BB->getTerminator();
       for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {


        


More information about the llvm-commits mailing list