Skip to content

Commit 6a0d6fc

Browse files
committed
Revert "[StructuralHash] Global Variable (#118412)"
This reverts commit 1afb81d.
1 parent 68bcba6 commit 6a0d6fc

File tree

7 files changed

+13
-244
lines changed

7 files changed

+13
-244
lines changed

llvm/include/llvm/IR/StructuralHash.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class Module;
3131
/// to true includes instruction and operand type information.
3232
stable_hash StructuralHash(const Function &F, bool DetailedHash = false);
3333

34-
/// Returns a hash of the global variable \p G.
35-
stable_hash StructuralHash(const GlobalVariable &G);
36-
3734
/// Returns a hash of the module \p M by hashing all functions and global
3835
/// variables contained within. \param M The module to hash. \param DetailedHash
3936
/// Whether or not to encode additional information in the function hashes that

llvm/lib/CodeGen/MachineStableHash.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include "llvm/CodeGen/Register.h"
2828
#include "llvm/Config/llvm-config.h"
2929
#include "llvm/IR/Constants.h"
30-
#include "llvm/IR/GlobalVariable.h"
31-
#include "llvm/IR/StructuralHash.h"
3230
#include "llvm/MC/MCSymbol.h"
3331
#include "llvm/Support/Alignment.h"
3432
#include "llvm/Support/ErrorHandling.h"
@@ -95,19 +93,13 @@ stable_hash llvm::stableHashValue(const MachineOperand &MO) {
9593
return 0;
9694
case MachineOperand::MO_GlobalAddress: {
9795
const GlobalValue *GV = MO.getGlobal();
98-
stable_hash GVHash = 0;
99-
if (auto *GVar = dyn_cast<GlobalVariable>(GV))
100-
GVHash = StructuralHash(*GVar);
101-
if (!GVHash) {
102-
if (!GV->hasName()) {
103-
++StableHashBailingGlobalAddress;
104-
return 0;
105-
}
106-
GVHash = stable_hash_name(GV->getName());
96+
if (!GV->hasName()) {
97+
++StableHashBailingGlobalAddress;
98+
return 0;
10799
}
108-
109-
return stable_hash_combine(MO.getType(), MO.getTargetFlags(), GVHash,
110-
MO.getOffset());
100+
auto Name = GV->getName();
101+
return stable_hash_combine(MO.getType(), MO.getTargetFlags(),
102+
stable_hash_name(Name), MO.getOffset());
111103
}
112104

113105
case MachineOperand::MO_TargetIndex: {

llvm/lib/IR/StructuralHash.cpp

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
340300
stable_hash llvm::StructuralHash(const Module &M, bool DetailedHash) {
341301
StructuralHashImpl H(DetailedHash);
342302
H.update(M);

llvm/test/CodeGen/AArch64/cgdata-merge-gvar-nsconst.ll

Lines changed: 0 additions & 32 deletions
This file was deleted.

llvm/test/CodeGen/AArch64/cgdata-merge-gvar-objc.ll

Lines changed: 0 additions & 38 deletions
This file was deleted.

llvm/test/CodeGen/AArch64/cgdata-merge-gvar-string.ll

Lines changed: 0 additions & 46 deletions
This file was deleted.

llvm/test/CodeGen/AArch64/cgdata-outline-gvar.ll

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)