@@ -72,20 +72,13 @@ class StructuralHashImpl {
7272 stable_hash hashAPInt (const APInt &I) {
7373 SmallVector<stable_hash> Hashes;
7474 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 () );
7777 return stable_hash_combine (Hashes);
7878 }
7979
8080 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 ());
8982 }
9083
9184 stable_hash hashGlobalValue (const GlobalValue *GV) {
@@ -109,8 +102,7 @@ class StructuralHashImpl {
109102 return stable_hash_combine (Hashes);
110103 }
111104
112- auto *G = dyn_cast<GlobalValue>(C);
113- if (G) {
105+ if (auto *G = dyn_cast<GlobalValue>(C)) {
114106 Hashes.emplace_back (hashGlobalValue (G));
115107 return stable_hash_combine (Hashes);
116108 }
@@ -138,8 +130,6 @@ class StructuralHashImpl {
138130 }
139131 case Value::ConstantArrayVal: {
140132 const ConstantArray *A = cast<ConstantArray>(C);
141- uint64_t NumElements = cast<ArrayType>(Ty)->getNumElements ();
142- Hashes.emplace_back (NumElements);
143133 for (auto &Op : A->operands ()) {
144134 auto H = hashConstant (cast<Constant>(Op));
145135 Hashes.emplace_back (H);
@@ -148,8 +138,6 @@ class StructuralHashImpl {
148138 }
149139 case Value::ConstantStructVal: {
150140 const ConstantStruct *S = cast<ConstantStruct>(C);
151- unsigned NumElements = cast<StructType>(Ty)->getNumElements ();
152- Hashes.emplace_back (NumElements);
153141 for (auto &Op : S->operands ()) {
154142 auto H = hashConstant (cast<Constant>(Op));
155143 Hashes.emplace_back (H);
@@ -158,8 +146,6 @@ class StructuralHashImpl {
158146 }
159147 case Value::ConstantVectorVal: {
160148 const ConstantVector *V = cast<ConstantVector>(C);
161- unsigned NumElements = cast<FixedVectorType>(Ty)->getNumElements ();
162- Hashes.emplace_back (NumElements);
163149 for (auto &Op : V->operands ()) {
164150 auto H = hashConstant (cast<Constant>(Op));
165151 Hashes.emplace_back (H);
@@ -168,8 +154,6 @@ class StructuralHashImpl {
168154 }
169155 case Value::ConstantExprVal: {
170156 const ConstantExpr *E = cast<ConstantExpr>(C);
171- unsigned NumOperands = E->getNumOperands ();
172- Hashes.emplace_back (NumOperands);
173157 for (auto &Op : E->operands ()) {
174158 auto H = hashConstant (cast<Constant>(Op));
175159 Hashes.emplace_back (H);
@@ -188,10 +172,10 @@ class StructuralHashImpl {
188172 Hashes.emplace_back (H);
189173 return stable_hash_combine (Hashes);
190174 }
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);
193178 }
194- return Hash;
195179 }
196180
197181 stable_hash hashValue (Value *V) {
@@ -206,8 +190,8 @@ class StructuralHashImpl {
206190 Hashes.emplace_back (Arg->getArgNo ());
207191
208192 // 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 );
211195
212196 return stable_hash_combine (Hashes);
213197 }
@@ -236,14 +220,14 @@ class StructuralHashImpl {
236220 unsigned InstIdx = 0 ;
237221 if (IndexInstruction) {
238222 InstIdx = IndexInstruction->size ();
239- IndexInstruction->insert ({ InstIdx, const_cast <Instruction *>(&Inst)} );
223+ IndexInstruction->try_emplace ( InstIdx, const_cast <Instruction *>(&Inst));
240224 }
241225
242226 for (const auto [OpndIdx, Op] : enumerate(Inst.operands ())) {
243227 auto OpndHash = hashOperand (Op);
244228 if (IgnoreOp && IgnoreOp (&Inst, OpndIdx)) {
245229 assert (IndexOperandHashMap);
246- IndexOperandHashMap->insert ({{ InstIdx, OpndIdx}, OpndHash} );
230+ IndexOperandHashMap->try_emplace ({ InstIdx, OpndIdx}, OpndHash);
247231 } else
248232 Hashes.emplace_back (OpndHash);
249233 }
0 commit comments