diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 17:15:32 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 17:15:32 +0000 |
commit | 742d1704e1cc1870c44a17181df694a66f1dc2f9 (patch) | |
tree | ba50d6ab1c722110eeb8cab2b71e6ccb5653deb7 /llvm/lib/Support | |
parent | af8be4458fd0dc046703c1ce0012579c10563a36 (diff) | |
download | bcm5719-llvm-742d1704e1cc1870c44a17181df694a66f1dc2f9.tar.gz bcm5719-llvm-742d1704e1cc1870c44a17181df694a66f1dc2f9.zip |
Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
llvm-svn: 34789
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 93442f344c1..50b0dc34fea 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -985,6 +985,22 @@ APInt &APInt::zext(uint32_t width) { return *this; } +APInt &APInt::zextOrTrunc(uint32_t width) { + if (BitWidth < width) + return zext(width); + if (BitWidth > width) + return trunc(width); + return *this; +} + +APInt &APInt::sextOrTrunc(uint32_t width) { + if (BitWidth < width) + return sext(width); + if (BitWidth > width) + return trunc(width); + return *this; +} + /// Arithmetic right-shift this APInt by shiftAmt. /// @brief Arithmetic right-shift function. APInt APInt::ashr(uint32_t shiftAmt) const { |