llvm.org GIT mirror llvm / 5449a1d
Move IsSameValue from clang's ASTImporter to be methods on the APInt/APSInt classes. Part of rdar://11875995 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160223 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 8 years ago
2 changed file(s) with 39 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
510510 return getAllOnesValue(numBits).lshr(numBits - loBitsSet);
511511 }
512512
513 /// \brief Determine if two APInts have the same value, after zero-extending
514 /// one of them (if needed!) to ensure that the bit-widths match.
515 static bool isSameValue(const APInt &I1, const APInt &I2) {
516 if (I1.getBitWidth() == I2.getBitWidth())
517 return I1 == I2;
518
519 if (I1.getBitWidth() > I2.getBitWidth())
520 return I1 == I2.zext(I1.getBitWidth());
521
522 return I1.zext(I2.getBitWidth()) == I2;
523 }
524
513525 /// \brief Overload to compute a hash_code for an APInt value.
514526 friend hash_code hash_value(const APInt &Arg);
515527
249249 : APInt::getSignedMinValue(numBits), Unsigned);
250250 }
251251
252 /// \brief Determine if two APSInts have the same value, zero- or
253 /// sign-extending as needed.
254 static bool isSameValue(const APSInt &I1, const APSInt &I2) {
255 if (I1.getBitWidth() == I2.getBitWidth() && I1.isSigned() == I2.isSigned())
256 return I1 == I2;
257
258 // Check for a bit-width mismatch.
259 if (I1.getBitWidth() > I2.getBitWidth())
260 return isSameValue(I1, I2.extend(I1.getBitWidth()));
261 else if (I2.getBitWidth() > I1.getBitWidth())
262 return isSameValue(I1.extend(I2.getBitWidth()), I2);
263
264 // We have a signedness mismatch. Turn the signed value into an unsigned
265 // value.
266 if (I1.isSigned()) {
267 if (I1.isNegative())
268 return false;
269
270 return APSInt(I1, true) == I2;
271 }
272
273 if (I2.isNegative())
274 return false;
275
276 return I1 == APSInt(I2, true);
277 }
278
252279 /// Profile - Used to insert APSInt objects, or objects that contain APSInt
253280 /// objects, into FoldingSets.
254281 void Profile(FoldingSetNodeID& ID) const;