Skip to content

Commit b9e0313

Browse files
committed
[BOLT] Switch BF::computeHash to xxh3
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 llvm#65241.
1 parent 2a7b8ab commit b9e0313

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "llvm/Support/Regex.h"
4141
#include "llvm/Support/Timer.h"
4242
#include "llvm/Support/raw_ostream.h"
43+
#include "llvm/Support/xxhash.h"
4344
#include <functional>
4445
#include <limits>
4546
#include <numeric>
@@ -3585,12 +3586,12 @@ size_t BinaryFunction::computeHash(bool UseDFS,
35853586
llvm::copy(Layout.blocks(), std::back_inserter(Order));
35863587

35873588
// The hash is computed by creating a string of all instruction opcodes and
3588-
// possibly their operands and then hashing that string with std::hash.
3589+
// possibly their operands and then hashing that string with xxh3.
35893590
std::string HashString;
35903591
for (const BinaryBasicBlock *BB : Order)
35913592
HashString.append(hashBlock(BC, *BB, OperandHashFunc));
35923593

3593-
return Hash = std::hash<std::string>{}(HashString);
3594+
return Hash = llvm::xxh3_64bits(HashString);
35943595
}
35953596

35963597
void BinaryFunction::insertBasicBlocks(

bolt/test/X86/pre-aggregated-perf.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PERF2BOLT: 1 usqrt a 1 usqrt 10 0 22
4646

4747
NEWFORMAT: - name: 'frame_dummy/1'
4848
NEWFORMAT: fid: 3
49-
NEWFORMAT: hash: 0x24496F7F9594E89F
49+
NEWFORMAT: hash: 0x28C72085C0BD8D37
5050
NEWFORMAT: exec: 1
5151

5252
NEWFORMAT: - name: usqrt

0 commit comments

Comments
 (0)