diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-25 16:49:59 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-03-25 16:49:59 +0000 |
commit | b4b5150dfcff1806e4e31712d11e0f4354af82a9 (patch) | |
tree | 86ef0a4209b9d7edad4ddca3eb1cba48d5403835 /llvm/lib/Support | |
parent | c85b493df4d748a458610b2f01985090950678f0 (diff) | |
download | bcm5719-llvm-b4b5150dfcff1806e4e31712d11e0f4354af82a9.tar.gz bcm5719-llvm-b4b5150dfcff1806e4e31712d11e0f4354af82a9.zip |
[APInt] Add an isSplat helper and use it in some places.
To complement getSplat. This is more general than the binary
decomposition method as it also handles non-pow2 splat sizes.
llvm-svn: 233195
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index dc8a6525c8b..23337bebab1 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -672,6 +672,14 @@ hash_code llvm::hash_value(const APInt &Arg) { return hash_combine_range(Arg.pVal, Arg.pVal + Arg.getNumWords()); } +bool APInt::isSplat(unsigned SplatSizeInBits) const { + assert(getBitWidth() % SplatSizeInBits == 0 && + "SplatSizeInBits must divide width!"); + // We can check that all parts of an integer are equal by making use of a + // little trick: rotate and check if it's still the same value. + return *this == rotl(SplatSizeInBits); +} + /// HiBits - This function returns the high "numBits" bits of this APInt. APInt APInt::getHiBits(unsigned numBits) const { return APIntOps::lshr(*this, BitWidth - numBits); |