Skip to content

Commit 8f4af07

Browse files
committed
Address 2nd comments from boomanaiden154
1 parent 68d1ec1 commit 8f4af07

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

llvm/include/llvm/IR/StructuralHash.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ namespace llvm {
2222
class Function;
2323
class Module;
2424

25-
using IRHash = stable_hash;
26-
2725
/// Returns a hash of the function \p F.
2826
/// \param F The function to hash.
2927
/// \param DetailedHash Whether or not to encode additional information in the
3028
/// hash. The additional information added into the hash when this flag is set
3129
/// to true includes instruction and operand type information.
32-
IRHash StructuralHash(const Function &F, bool DetailedHash = false);
30+
stable_hash StructuralHash(const Function &F, bool DetailedHash = false);
3331

3432
/// Returns a hash of the module \p M by hashing all functions and global
3533
/// variables contained within. \param M The module to hash. \param DetailedHash
3634
/// Whether or not to encode additional information in the function hashes that
3735
/// composed the module hash.
38-
IRHash StructuralHash(const Module &M, bool DetailedHash = false);
36+
stable_hash StructuralHash(const Module &M, bool DetailedHash = false);
3937

4038
} // end namespace llvm
4139

llvm/lib/IR/StructuralHash.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ class StructuralHashImpl {
2828

2929
bool DetailedHash;
3030

31-
const stable_hash GlobalHeaderHash = stable_hash_name("Global Header");
32-
const stable_hash FunctionHeaderHash = stable_hash_name("Function Header");
33-
const stable_hash BlockHeaderHash = stable_hash_name("Block Header");
31+
// This random value acts as a block header, as otherwise the partition of
32+
// opcodes into BBs wouldn't affect the hash, only the order of the opcodes.
33+
static constexpr stable_hash BlockHeaderHash = 45798;
34+
static constexpr stable_hash FunctionHeaderHash = 0x62642d6b6b2d6b72;
35+
static constexpr stable_hash GlobalHeaderHash = 23456;
3436

3537
// This will produce different values on 32-bit and 64-bit systens as
3638
// hash_combine returns a size_t. However, this is only used for
@@ -150,9 +152,6 @@ class StructuralHashImpl {
150152
while (!BBs.empty()) {
151153
const BasicBlock *BB = BBs.pop_back_val();
152154

153-
// This random value acts as a block header, as otherwise the partition of
154-
// opcodes into BBs wouldn't affect the hash, only the order of the
155-
// opcodes
156155
Hashes.emplace_back(BlockHeaderHash);
157156
for (auto &Inst : *BB)
158157
Hashes.emplace_back(hashInstruction(Inst));
@@ -193,13 +192,13 @@ class StructuralHashImpl {
193192

194193
} // namespace
195194

196-
IRHash llvm::StructuralHash(const Function &F, bool DetailedHash) {
195+
stable_hash llvm::StructuralHash(const Function &F, bool DetailedHash) {
197196
StructuralHashImpl H(DetailedHash);
198197
H.update(F);
199198
return H.getHash();
200199
}
201200

202-
IRHash llvm::StructuralHash(const Module &M, bool DetailedHash) {
201+
stable_hash llvm::StructuralHash(const Module &M, bool DetailedHash) {
203202
StructuralHashImpl H(DetailedHash);
204203
H.update(M);
205204
return H.getHash();

llvm/lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ namespace {
172172

173173
class FunctionNode {
174174
mutable AssertingVH<Function> F;
175-
IRHash Hash;
175+
stable_hash Hash;
176176

177177
public:
178178
// Note the hash is recalculated potentially multiple times, but it is cheap.
179179
FunctionNode(Function *F) : F(F), Hash(StructuralHash(*F)) {}
180180

181181
Function *getFunc() const { return F; }
182-
IRHash getHash() const { return Hash; }
182+
stable_hash getHash() const { return Hash; }
183183

184184
/// Replace the reference to the function F by the function G, assuming their
185185
/// implementations are equal.
@@ -420,7 +420,7 @@ bool MergeFunctions::runOnModule(Module &M) {
420420

421421
// All functions in the module, ordered by hash. Functions with a unique
422422
// hash value are easily eliminated.
423-
std::vector<std::pair<IRHash, Function *>> HashedFuncs;
423+
std::vector<std::pair<stable_hash, Function *>> HashedFuncs;
424424
for (Function &Func : M) {
425425
if (isEligibleForMerging(Func)) {
426426
HashedFuncs.push_back({StructuralHash(Func), &Func});

llvm/test/Transforms/MergeFunc/call-and-invoke-with-ranges-attr.ll

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,6 @@ lpad:
7979
resume { ptr, i32 } zeroinitializer
8080
}
8181

82-
define i8 @call_with_same_range_attr(i8 range(i8 0, 2) %v) {
83-
; CHECK-LABEL: @call_with_same_range_attr
84-
; CHECK: tail call i8 @call_with_range_attr
85-
%out = call i8 @dummy2(i8 %v)
86-
ret i8 %out
87-
}
88-
89-
define i8 @call_with_same_range() {
90-
; CHECK-LABEL: @call_with_same_range
91-
; CHECK: tail call i8 @call_with_range
92-
%out = call range(i8 0, 2) i8 @dummy()
93-
ret i8 %out
94-
}
95-
9682
define i8 @invoke_with_same_range() personality ptr undef {
9783
; CHECK-LABEL: @invoke_with_same_range()
9884
; CHECK: tail call i8 @invoke_with_range()
@@ -106,6 +92,20 @@ lpad:
10692
resume { ptr, i32 } zeroinitializer
10793
}
10894

95+
define i8 @call_with_same_range() {
96+
; CHECK-LABEL: @call_with_same_range
97+
; CHECK: tail call i8 @call_with_range
98+
%out = call range(i8 0, 2) i8 @dummy()
99+
ret i8 %out
100+
}
101+
102+
define i8 @call_with_same_range_attr(i8 range(i8 0, 2) %v) {
103+
; CHECK-LABEL: @call_with_same_range_attr
104+
; CHECK: tail call i8 @call_with_range_attr
105+
%out = call i8 @dummy2(i8 %v)
106+
ret i8 %out
107+
}
108+
109109
declare i8 @dummy();
110110
declare i8 @dummy2(i8);
111111
declare i32 @__gxx_personality_v0(...)

llvm/test/Transforms/MergeFunc/inline-asm.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
; CHECK-LABEL: @int_ptr_arg_different
44
; CHECK-NEXT: call void asm
55

6-
; CHECK-LABEL: @int_ptr_arg_same
7-
; CHECK-NEXT: tail call void @float_ptr_arg_same(ptr %0)
8-
96
; CHECK-LABEL: @int_ptr_null
107
; CHECK-NEXT: tail call void @float_ptr_null()
118

9+
; CHECK-LABEL: @int_ptr_arg_same
10+
; CHECK-NEXT: tail call void @float_ptr_arg_same(ptr %0)
11+
1212
; Used to satisfy minimum size limit
1313
declare void @stuff()
1414

0 commit comments

Comments
 (0)