@@ -46,7 +46,7 @@ class StructuralHashImpl {
4646 // / Assign a unique ID to each Value in the order they are first seen.
4747 DenseMap<const Value *, int > ValueToId;
4848
49- static stable_hash hashType (Type *ValueType) {
49+ stable_hash hashType (Type *ValueType) {
5050 SmallVector<stable_hash> Hashes;
5151 Hashes.emplace_back (ValueType->getTypeID ());
5252 if (ValueType->isIntegerTy ())
@@ -65,47 +65,19 @@ class StructuralHashImpl {
6565 }
6666 }
6767
68- static stable_hash hashAPInt (const APInt &I) {
68+ stable_hash hashAPInt (const APInt &I) {
6969 SmallVector<stable_hash> Hashes;
7070 Hashes.emplace_back (I.getBitWidth ());
7171 auto RawVals = ArrayRef<uint64_t >(I.getRawData (), I.getNumWords ());
7272 Hashes.append (RawVals.begin (), RawVals.end ());
7373 return stable_hash_combine (Hashes);
7474 }
7575
76- static stable_hash hashAPFloat (const APFloat &F) {
76+ stable_hash hashAPFloat (const APFloat &F) {
7777 return hashAPInt (F.bitcastToAPInt ());
7878 }
7979
80- static stable_hash hashGlobalVariable (const GlobalVariable &GVar) {
81- if (!GVar.hasInitializer ())
82- return hashGlobalValue (&GVar);
83-
84- // Hash the contents of a string.
85- if (GVar.getName ().starts_with (" .str" )) {
86- auto *C = GVar.getInitializer ();
87- if (const auto *Seq = dyn_cast<ConstantDataSequential>(C))
88- if (Seq->isString ())
89- return stable_hash_name (Seq->getAsString ());
90- }
91-
92- // Hash structural contents of Objective-C metadata in specific sections.
93- // This can be extended to other metadata if needed.
94- static constexpr const char *SectionNames[] = {
95- " __cfstring" , " __cstring" , " __objc_classrefs" ,
96- " __objc_methname" , " __objc_selrefs" ,
97- };
98- if (GVar.hasSection ()) {
99- StringRef SectionName = GVar.getSection ();
100- for (const char *Name : SectionNames)
101- if (SectionName.contains (Name))
102- return hashConstant (GVar.getInitializer ());
103- }
104-
105- return hashGlobalValue (&GVar);
106- }
107-
108- static stable_hash hashGlobalValue (const GlobalValue *GV) {
80+ stable_hash hashGlobalValue (const GlobalValue *GV) {
10981 if (!GV->hasName ())
11082 return 0 ;
11183 return stable_hash_name (GV->getName ());
@@ -115,7 +87,7 @@ class StructuralHashImpl {
11587 // FunctionComparator::cmpConstants() in FunctionComparator.cpp, but here
11688 // we're interested in computing a hash rather than comparing two Constants.
11789 // Some of the logic is simplified, e.g, we don't expand GEPOperator.
118- static stable_hash hashConstant (const Constant *C) {
90+ stable_hash hashConstant (Constant *C) {
11991 SmallVector<stable_hash> Hashes;
12092
12193 Type *Ty = C->getType ();
@@ -126,21 +98,14 @@ class StructuralHashImpl {
12698 return stable_hash_combine (Hashes);
12799 }
128100
129- if (auto *GVar = dyn_cast<GlobalVariable>(C)) {
130- Hashes.emplace_back (hashGlobalVariable (*GVar));
131- return stable_hash_combine (Hashes);
132- }
133-
134101 if (auto *G = dyn_cast<GlobalValue>(C)) {
135102 Hashes.emplace_back (hashGlobalValue (G));
136103 return stable_hash_combine (Hashes);
137104 }
138105
139106 if (const auto *Seq = dyn_cast<ConstantDataSequential>(C)) {
140- if (Seq->isString ()) {
141- Hashes.emplace_back (stable_hash_name (Seq->getAsString ()));
142- return stable_hash_combine (Hashes);
143- }
107+ Hashes.emplace_back (xxh3_64bits (Seq->getRawDataValues ()));
108+ return stable_hash_combine (Hashes);
144109 }
145110
146111 switch (C->getValueID ()) {
@@ -301,7 +266,6 @@ class StructuralHashImpl {
301266 Hashes.emplace_back (Hash);
302267 Hashes.emplace_back (GlobalHeaderHash);
303268 Hashes.emplace_back (GV.getValueType ()->getTypeID ());
304- Hashes.emplace_back (hashGlobalVariable (GV));
305269
306270 // Update the combined hash in place.
307271 Hash = stable_hash_combine (Hashes);
@@ -333,10 +297,6 @@ stable_hash llvm::StructuralHash(const Function &F, bool DetailedHash) {
333297 return H.getHash ();
334298}
335299
336- stable_hash llvm::StructuralHash (const GlobalVariable &GVar) {
337- return StructuralHashImpl::hashGlobalVariable (GVar);
338- }
339-
340300stable_hash llvm::StructuralHash (const Module &M, bool DetailedHash) {
341301 StructuralHashImpl H (DetailedHash);
342302 H.update (M);
0 commit comments