Skip to content

Commit c8aa7a3

Browse files
committed
[IR] Introduce hash_value for FMF, GEPNoWrapFlags
This patch is motivated by wanting to do CSE at the VPlan-level: as VPlan stores FMF and GEPNoWrapFlags among other things in its recipes, de-duplicating them for common-subexpression-elimination would require hashing the VPlan recipes along with their embedded information.
1 parent 440a4de commit c8aa7a3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/include/llvm/IR/FMF.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_IR_FMF_H
1414
#define LLVM_IR_FMF_H
1515

16+
#include "llvm/ADT/Hashing.h"
1617
#include "llvm/Support/Compiler.h"
1718

1819
namespace llvm {
@@ -121,6 +122,9 @@ class FastMathFlags {
121122
const unsigned ValueMask = NoNaNs | NoInfs | NoSignedZeros;
122123
return FastMathFlags(ValueMask & (LHS.Flags | RHS.Flags));
123124
}
125+
126+
// Hashing.
127+
friend hash_code hash_value(const FastMathFlags &FMF);
124128
};
125129

126130
inline FastMathFlags operator|(FastMathFlags LHS, FastMathFlags RHS) {
@@ -138,6 +142,9 @@ inline raw_ostream &operator<<(raw_ostream &O, FastMathFlags FMF) {
138142
return O;
139143
}
140144

145+
inline hash_code hash_value(const FastMathFlags &FMF) {
146+
return hash_value(FMF.Flags);
147+
}
141148
} // end namespace llvm
142149

143150
#endif // LLVM_IR_FMF_H

llvm/include/llvm/IR/GEPNoWrapFlags.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_IR_GEPNOWRAPFLAGS_H
1414
#define LLVM_IR_GEPNOWRAPFLAGS_H
1515

16+
#include "llvm/ADT/Hashing.h"
1617
#include <assert.h>
1718

1819
namespace llvm {
@@ -101,8 +102,14 @@ class GEPNoWrapFlags {
101102
Flags |= Other.Flags;
102103
return *this;
103104
}
105+
106+
// Hashing.
107+
friend hash_code hash_value(const GEPNoWrapFlags &NW);
104108
};
105109

110+
inline hash_code hash_value(const GEPNoWrapFlags &NW) {
111+
return hash_value(NW.Flags);
112+
}
106113
} // end namespace llvm
107114

108115
#endif // LLVM_IR_GEPNOWRAPFLAGS_H

0 commit comments

Comments
 (0)