[llvm] [StructuralHash] Global Variable (PR #118412)

Mingming Liu via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 18:00: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());
----------------
mingmingl-llvm wrote:

`.str` is the prefix of almost all (if not all) string literals in the LLVM IR. I'm wondering if there is a place to verify it's true (e.g., `.str` prefix means it's a string literal, and a string literal starts with `.str`).

Ask for my information since I'm making the same assumption for one recent prototype.

https://github.com/llvm/llvm-project/pull/118412


More information about the llvm-commits mailing list