[llvm] [BOLT] Switch BF::computeHash to xxh3 (PR #65437)

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 5 21:40:03 PDT 2023


https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/65437:

std::hash is C++ STL implementation-specific. Switch to xxh3 as the fast and
STL-independent alternative for basic block hashes which are exposed to users
in YAML profile.

Fixes #65241.


>From 3a8cfcc210667e526ba536e809e6bf0d86649242 Mon Sep 17 00:00:00 2001
From: Amir Aupov <amir.aupov at gmail.com>
Date: Tue, 5 Sep 2023 21:27:38 -0700
Subject: [PATCH] [BOLT] Switch BF::computeHash to xxh3

---
 bolt/lib/Core/BinaryFunction.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 38d97d90acc1374..8998a1b5aaebeed 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/Regex.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/xxhash.h"
 #include <functional>
 #include <limits>
 #include <numeric>
@@ -3585,12 +3586,12 @@ size_t BinaryFunction::computeHash(bool UseDFS,
     llvm::copy(Layout.blocks(), std::back_inserter(Order));
 
   // The hash is computed by creating a string of all instruction opcodes and
-  // possibly their operands and then hashing that string with std::hash.
+  // possibly their operands and then hashing that string with xxh3.
   std::string HashString;
   for (const BinaryBasicBlock *BB : Order)
     HashString.append(hashBlock(BC, *BB, OperandHashFunc));
 
-  return Hash = std::hash<std::string>{}(HashString);
+  return Hash = llvm::xxh3_64bits(HashString);
 }
 
 void BinaryFunction::insertBasicBlocks(



More information about the llvm-commits mailing list