[llvm] [StableHash] Implement stable global name for the hash computation (PR #106156)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 12:49:15 PDT 2024
================
@@ -50,6 +50,22 @@ inline stable_hash stable_hash_combine(stable_hash A, stable_hash B,
return stable_hash_combine(Hashes);
}
+// Removes suffixes introduced by LLVM from the name to enhance stability and
+// maintain closeness to the original name across different builds.
+inline StringRef get_stable_name(StringRef Name) {
+ auto [P1, S1] = Name.rsplit(".llvm.");
+ auto [P2, S2] = P1.rsplit(".__uniq.");
+ return P2;
+}
+
+// Generates a consistent hash value for a given input name across different
+// program executions and environments. This function first converts the input
+// name into a stable form using the `get_stable_name` function, and then
+// computes a hash of this stable name.
----------------
ellishg wrote:
I guess `foo.llvm.1234` would have the same hash as `foo.llvm.5678`. It might be worth mentioning that hash collisions are not uncommon.
https://github.com/llvm/llvm-project/pull/106156
More information about the llvm-commits
mailing list