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