@@ -46,7 +46,7 @@ class StructuralHashImpl {
46
46
// / Assign a unique ID to each Value in the order they are first seen.
47
47
DenseMap<const Value *, int > ValueToId;
48
48
49
- static stable_hash hashType (Type *ValueType) {
49
+ stable_hash hashType (Type *ValueType) {
50
50
SmallVector<stable_hash> Hashes;
51
51
Hashes.emplace_back (ValueType->getTypeID ());
52
52
if (ValueType->isIntegerTy ())
@@ -65,47 +65,19 @@ class StructuralHashImpl {
65
65
}
66
66
}
67
67
68
- static stable_hash hashAPInt (const APInt &I) {
68
+ stable_hash hashAPInt (const APInt &I) {
69
69
SmallVector<stable_hash> Hashes;
70
70
Hashes.emplace_back (I.getBitWidth ());
71
71
auto RawVals = ArrayRef<uint64_t >(I.getRawData (), I.getNumWords ());
72
72
Hashes.append (RawVals.begin (), RawVals.end ());
73
73
return stable_hash_combine (Hashes);
74
74
}
75
75
76
- static stable_hash hashAPFloat (const APFloat &F) {
76
+ stable_hash hashAPFloat (const APFloat &F) {
77
77
return hashAPInt (F.bitcastToAPInt ());
78
78
}
79
79
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) {
109
81
if (!GV->hasName ())
110
82
return 0 ;
111
83
return stable_hash_name (GV->getName ());
@@ -115,7 +87,7 @@ class StructuralHashImpl {
115
87
// FunctionComparator::cmpConstants() in FunctionComparator.cpp, but here
116
88
// we're interested in computing a hash rather than comparing two Constants.
117
89
// 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) {
119
91
SmallVector<stable_hash> Hashes;
120
92
121
93
Type *Ty = C->getType ();
@@ -126,21 +98,14 @@ class StructuralHashImpl {
126
98
return stable_hash_combine (Hashes);
127
99
}
128
100
129
- if (auto *GVar = dyn_cast<GlobalVariable>(C)) {
130
- Hashes.emplace_back (hashGlobalVariable (*GVar));
131
- return stable_hash_combine (Hashes);
132
- }
133
-
134
101
if (auto *G = dyn_cast<GlobalValue>(C)) {
135
102
Hashes.emplace_back (hashGlobalValue (G));
136
103
return stable_hash_combine (Hashes);
137
104
}
138
105
139
106
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);
144
109
}
145
110
146
111
switch (C->getValueID ()) {
@@ -301,7 +266,6 @@ class StructuralHashImpl {
301
266
Hashes.emplace_back (Hash);
302
267
Hashes.emplace_back (GlobalHeaderHash);
303
268
Hashes.emplace_back (GV.getValueType ()->getTypeID ());
304
- Hashes.emplace_back (hashGlobalVariable (GV));
305
269
306
270
// Update the combined hash in place.
307
271
Hash = stable_hash_combine (Hashes);
@@ -333,10 +297,6 @@ stable_hash llvm::StructuralHash(const Function &F, bool DetailedHash) {
333
297
return H.getHash ();
334
298
}
335
299
336
- stable_hash llvm::StructuralHash (const GlobalVariable &GVar) {
337
- return StructuralHashImpl::hashGlobalVariable (GVar);
338
- }
339
-
340
300
stable_hash llvm::StructuralHash (const Module &M, bool DetailedHash) {
341
301
StructuralHashImpl H (DetailedHash);
342
302
H.update (M);
0 commit comments