@@ -72,20 +72,13 @@ class StructuralHashImpl {
72
72
stable_hash hashAPInt (const APInt &I) {
73
73
SmallVector<stable_hash> Hashes;
74
74
Hashes.emplace_back (I.getBitWidth ());
75
- for ( unsigned J = 0 ; J < I.getNumWords (); ++J)
76
- Hashes.emplace_back ((I. getRawData ())[J] );
75
+ auto RawVals = ArrayRef< uint64_t >(I. getRawData (), I.getNumWords ());
76
+ Hashes.append (RawVals. begin (), RawVals. end () );
77
77
return stable_hash_combine (Hashes);
78
78
}
79
79
80
80
stable_hash hashAPFloat (const APFloat &F) {
81
- SmallVector<stable_hash> Hashes;
82
- const fltSemantics &S = F.getSemantics ();
83
- Hashes.emplace_back (APFloat::semanticsPrecision (S));
84
- Hashes.emplace_back (APFloat::semanticsMaxExponent (S));
85
- Hashes.emplace_back (APFloat::semanticsMinExponent (S));
86
- Hashes.emplace_back (APFloat::semanticsSizeInBits (S));
87
- Hashes.emplace_back (hashAPInt (F.bitcastToAPInt ()));
88
- return stable_hash_combine (Hashes);
81
+ return hashAPInt (F.bitcastToAPInt ());
89
82
}
90
83
91
84
stable_hash hashGlobalValue (const GlobalValue *GV) {
@@ -109,8 +102,7 @@ class StructuralHashImpl {
109
102
return stable_hash_combine (Hashes);
110
103
}
111
104
112
- auto *G = dyn_cast<GlobalValue>(C);
113
- if (G) {
105
+ if (auto *G = dyn_cast<GlobalValue>(C)) {
114
106
Hashes.emplace_back (hashGlobalValue (G));
115
107
return stable_hash_combine (Hashes);
116
108
}
@@ -138,8 +130,6 @@ class StructuralHashImpl {
138
130
}
139
131
case Value::ConstantArrayVal: {
140
132
const ConstantArray *A = cast<ConstantArray>(C);
141
- uint64_t NumElements = cast<ArrayType>(Ty)->getNumElements ();
142
- Hashes.emplace_back (NumElements);
143
133
for (auto &Op : A->operands ()) {
144
134
auto H = hashConstant (cast<Constant>(Op));
145
135
Hashes.emplace_back (H);
@@ -148,8 +138,6 @@ class StructuralHashImpl {
148
138
}
149
139
case Value::ConstantStructVal: {
150
140
const ConstantStruct *S = cast<ConstantStruct>(C);
151
- unsigned NumElements = cast<StructType>(Ty)->getNumElements ();
152
- Hashes.emplace_back (NumElements);
153
141
for (auto &Op : S->operands ()) {
154
142
auto H = hashConstant (cast<Constant>(Op));
155
143
Hashes.emplace_back (H);
@@ -158,8 +146,6 @@ class StructuralHashImpl {
158
146
}
159
147
case Value::ConstantVectorVal: {
160
148
const ConstantVector *V = cast<ConstantVector>(C);
161
- unsigned NumElements = cast<FixedVectorType>(Ty)->getNumElements ();
162
- Hashes.emplace_back (NumElements);
163
149
for (auto &Op : V->operands ()) {
164
150
auto H = hashConstant (cast<Constant>(Op));
165
151
Hashes.emplace_back (H);
@@ -168,8 +154,6 @@ class StructuralHashImpl {
168
154
}
169
155
case Value::ConstantExprVal: {
170
156
const ConstantExpr *E = cast<ConstantExpr>(C);
171
- unsigned NumOperands = E->getNumOperands ();
172
- Hashes.emplace_back (NumOperands);
173
157
for (auto &Op : E->operands ()) {
174
158
auto H = hashConstant (cast<Constant>(Op));
175
159
Hashes.emplace_back (H);
@@ -188,10 +172,10 @@ class StructuralHashImpl {
188
172
Hashes.emplace_back (H);
189
173
return stable_hash_combine (Hashes);
190
174
}
191
- default : // Unknown constant, abort.
192
- llvm_unreachable (" Constant ValueID not recognized." );
175
+ default :
176
+ // Skip other types of constants for simplicity.
177
+ return stable_hash_combine (Hashes);
193
178
}
194
- return Hash;
195
179
}
196
180
197
181
stable_hash hashValue (Value *V) {
@@ -206,8 +190,8 @@ class StructuralHashImpl {
206
190
Hashes.emplace_back (Arg->getArgNo ());
207
191
208
192
// Get an index (an insertion order) for the non-constant value.
209
- auto I = ValueToId.insert ({ V, ValueToId.size ()} );
210
- Hashes.emplace_back (I. first ->second );
193
+ auto [It, WasInserted] = ValueToId.try_emplace ( V, ValueToId.size ());
194
+ Hashes.emplace_back (It ->second );
211
195
212
196
return stable_hash_combine (Hashes);
213
197
}
@@ -236,14 +220,14 @@ class StructuralHashImpl {
236
220
unsigned InstIdx = 0 ;
237
221
if (IndexInstruction) {
238
222
InstIdx = IndexInstruction->size ();
239
- IndexInstruction->insert ({ InstIdx, const_cast <Instruction *>(&Inst)} );
223
+ IndexInstruction->try_emplace ( InstIdx, const_cast <Instruction *>(&Inst));
240
224
}
241
225
242
226
for (const auto [OpndIdx, Op] : enumerate(Inst.operands ())) {
243
227
auto OpndHash = hashOperand (Op);
244
228
if (IgnoreOp && IgnoreOp (&Inst, OpndIdx)) {
245
229
assert (IndexOperandHashMap);
246
- IndexOperandHashMap->insert ({{ InstIdx, OpndIdx}, OpndHash} );
230
+ IndexOperandHashMap->try_emplace ({ InstIdx, OpndIdx}, OpndHash);
247
231
} else
248
232
Hashes.emplace_back (OpndHash);
249
233
}
0 commit comments