[llvm] [StructuralHash] Global Variable (PR #118412)
Kyungwoo Lee via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 18:43:40 PST 2024
================
@@ -65,19 +65,44 @@ class StructuralHashImpl {
}
}
- stable_hash hashAPInt(const APInt &I) {
+ static stable_hash hashAPInt(const APInt &I) {
SmallVector<stable_hash> Hashes;
Hashes.emplace_back(I.getBitWidth());
auto RawVals = ArrayRef<uint64_t>(I.getRawData(), I.getNumWords());
Hashes.append(RawVals.begin(), RawVals.end());
return stable_hash_combine(Hashes);
}
- stable_hash hashAPFloat(const APFloat &F) {
+ static stable_hash hashAPFloat(const APFloat &F) {
return hashAPInt(F.bitcastToAPInt());
}
- stable_hash hashGlobalValue(const GlobalValue *GV) {
+ static stable_hash hashGlobalVariable(const GlobalVariable &GVar) {
+ if (!GVar.hasInitializer())
+ return hashGlobalValue(&GVar);
+
+ // Hash the contents of a string.
+ if (GVar.getName().starts_with(".str"))
+ return hashConstant(GVar.getInitializer());
----------------
kyulee-com wrote:
I only use `hashInitializer()` to determine if the global variable (beginning with `.str`) has an initializer. While I don't specifically verify if it's a string literal, this approach should suffice for most scenarios. It's still safe for our purposes, even if it's not a string literal. The only concern is avoiding an initializer that recursively references the current global variable itself. I assume that the cases filtered out here and below do not include such instances.
https://github.com/llvm/llvm-project/pull/118412
More information about the llvm-commits
mailing list