@@ -69,20 +69,13 @@ class StructuralHashImpl {
6969 stable_hash hashAPInt (const APInt &I) {
7070 SmallVector<stable_hash> Hashes;
7171 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 () );
7474 return stable_hash_combine (Hashes);
7575 }
7676
7777 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 ());
8679 }
8780
8881 stable_hash hashGlobalValue (const GlobalValue *GV) {
@@ -106,8 +99,7 @@ class StructuralHashImpl {
10699 return stable_hash_combine (Hashes);
107100 }
108101
109- auto *G = dyn_cast<GlobalValue>(C);
110- if (G) {
102+ if (auto *G = dyn_cast<GlobalValue>(C)) {
111103 Hashes.emplace_back (hashGlobalValue (G));
112104 return stable_hash_combine (Hashes);
113105 }
@@ -135,8 +127,6 @@ class StructuralHashImpl {
135127 }
136128 case Value::ConstantArrayVal: {
137129 const ConstantArray *A = cast<ConstantArray>(C);
138- uint64_t NumElements = cast<ArrayType>(Ty)->getNumElements ();
139- Hashes.emplace_back (NumElements);
140130 for (auto &Op : A->operands ()) {
141131 auto H = hashConstant (cast<Constant>(Op));
142132 Hashes.emplace_back (H);
@@ -145,8 +135,6 @@ class StructuralHashImpl {
145135 }
146136 case Value::ConstantStructVal: {
147137 const ConstantStruct *S = cast<ConstantStruct>(C);
148- unsigned NumElements = cast<StructType>(Ty)->getNumElements ();
149- Hashes.emplace_back (NumElements);
150138 for (auto &Op : S->operands ()) {
151139 auto H = hashConstant (cast<Constant>(Op));
152140 Hashes.emplace_back (H);
@@ -155,8 +143,6 @@ class StructuralHashImpl {
155143 }
156144 case Value::ConstantVectorVal: {
157145 const ConstantVector *V = cast<ConstantVector>(C);
158- unsigned NumElements = cast<FixedVectorType>(Ty)->getNumElements ();
159- Hashes.emplace_back (NumElements);
160146 for (auto &Op : V->operands ()) {
161147 auto H = hashConstant (cast<Constant>(Op));
162148 Hashes.emplace_back (H);
@@ -165,8 +151,6 @@ class StructuralHashImpl {
165151 }
166152 case Value::ConstantExprVal: {
167153 const ConstantExpr *E = cast<ConstantExpr>(C);
168- unsigned NumOperands = E->getNumOperands ();
169- Hashes.emplace_back (NumOperands);
170154 for (auto &Op : E->operands ()) {
171155 auto H = hashConstant (cast<Constant>(Op));
172156 Hashes.emplace_back (H);
@@ -185,10 +169,10 @@ class StructuralHashImpl {
185169 Hashes.emplace_back (H);
186170 return stable_hash_combine (Hashes);
187171 }
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);
190175 }
191- return Hash;
192176 }
193177
194178 stable_hash hashValue (Value *V) {
@@ -203,8 +187,8 @@ class StructuralHashImpl {
203187 Hashes.emplace_back (Arg->getArgNo ());
204188
205189 // 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 );
208192
209193 return stable_hash_combine (Hashes);
210194 }
@@ -233,14 +217,14 @@ class StructuralHashImpl {
233217 unsigned InstIdx = 0 ;
234218 if (IndexInstruction) {
235219 InstIdx = IndexInstruction->size ();
236- IndexInstruction->insert ({ InstIdx, const_cast <Instruction *>(&Inst)} );
220+ IndexInstruction->try_emplace ( InstIdx, const_cast <Instruction *>(&Inst));
237221 }
238222
239223 for (const auto [OpndIdx, Op] : enumerate(Inst.operands ())) {
240224 auto OpndHash = hashOperand (Op);
241225 if (IgnoreOp && IgnoreOp (&Inst, OpndIdx)) {
242226 assert (IndexOperandHashMap);
243- IndexOperandHashMap->insert ({{ InstIdx, OpndIdx}, OpndHash} );
227+ IndexOperandHashMap->try_emplace ({ InstIdx, OpndIdx}, OpndHash);
244228 } else
245229 Hashes.emplace_back (OpndHash);
246230 }
0 commit comments