[llvm] [AllocToken] Add TypeFuncHash and TypeFuncHashPointerSplit modes (PR #227686)
Ai Nozaki via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 08:56:22 PDT 2026
================
@@ -47,6 +55,32 @@ static uint64_t getStableHash(const AllocTokenMetadata &Metadata,
return getStableSipHash(Metadata.TypeName) % MaxTokens;
}
+/// Rounds the ID space down to the largest power of two <= MaxTokens, then
+/// splits its floor(log2(MaxTokens)) bits into: [pointer flag,] type name hash,
+/// function name hash. The function name hash gets floor(log2(MaxTokens)) / 2
+/// bits. With pointer split, the MSB of this rounded-down space is the flag.
+static uint64_t getTypeFuncHash(const AllocTokenMetadata &Metadata,
----------------
ainozaki wrote:
The truncation was intentional to keep the token range consistent with the other modes, i.e., `[0, MaxTokens)`. However, as you pointed out, it makes the position of the pointer flag confusing.
I'll special-case `MaxTokens` of the form `2^k - 1` (for `k > 1`, using `isMask_64(MaxTokens)` since `MaxTokens + 1` wraps around for `UINT64_MAX`) to use all `k` bits. With this change, the pointer flag sits in the MSB (e.g., bit 63 for `UINT64_MAX`), and the upper half (pointer flag + type hash) and lower half (function hash) are split evenly. Consequently, the token range becomes `[0, MaxTokens]` in this case.
https://github.com/llvm/llvm-project/pull/227686
More information about the llvm-commits
mailing list