diff options
author | Pete Cooper <peter_cooper@apple.com> | 2016-07-22 20:55:46 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2016-07-22 20:55:46 +0000 |
commit | fea2139740e94953749b030b8c1e5b75f9a308b4 (patch) | |
tree | e7d9ffbcdd740bc4465a41ce14d4d841e1e24f96 /llvm/lib/Support | |
parent | 462a5328ddd6ee7612911ea6f91da40ed3d994f4 (diff) | |
download | bcm5719-llvm-fea2139740e94953749b030b8c1e5b75f9a308b4.tar.gz bcm5719-llvm-fea2139740e94953749b030b8c1e5b75f9a308b4.zip |
Use RValue refs in APInt add/sub methods.
This adds versions of operator + and - which are optimized for the LHS/RHS of the
operator being RValue's. When an RValue is available, we can use its storage space
instead of allocating new space.
On code such as ConstantRange which makes heavy use of APInt's over 64-bits in size,
this results in significant numbers of saved allocations.
Thanks to David Blaikie for all the review and most of the code here.
llvm-svn: 276470
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 54 |
1 files changed, 16 insertions, 38 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 66eee99c6ec..8c921ce7948 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -260,6 +260,14 @@ APInt& APInt::operator+=(const APInt& RHS) { return clearUnusedBits(); } +APInt& APInt::operator+=(uint64_t RHS) { + if (isSingleWord()) + VAL += RHS; + else + add_1(pVal, pVal, getNumWords(), RHS); + return clearUnusedBits(); +} + /// Subtracts the integer array y from the integer array x /// @returns returns the borrow out. /// @brief Generalized subtraction of 64-bit integer arrays. @@ -286,6 +294,14 @@ APInt& APInt::operator-=(const APInt& RHS) { return clearUnusedBits(); } +APInt& APInt::operator-=(uint64_t RHS) { + if (isSingleWord()) + VAL -= RHS; + else + sub_1(pVal, getNumWords(), RHS); + return clearUnusedBits(); +} + /// Multiplies an integer array, x, by a uint64_t integer and places the result /// into dest. /// @returns the carry out of the multiplication. @@ -470,44 +486,6 @@ APInt APInt::operator*(const APInt& RHS) const { return Result; } -APInt APInt::operator+(const APInt& RHS) const { - assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); - if (isSingleWord()) - return APInt(BitWidth, VAL + RHS.VAL); - APInt Result(BitWidth, 0); - add(Result.pVal, this->pVal, RHS.pVal, getNumWords()); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator+(uint64_t RHS) const { - if (isSingleWord()) - return APInt(BitWidth, VAL + RHS); - APInt Result(*this); - add_1(Result.pVal, Result.pVal, getNumWords(), RHS); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator-(const APInt& RHS) const { - assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); - if (isSingleWord()) - return APInt(BitWidth, VAL - RHS.VAL); - APInt Result(BitWidth, 0); - sub(Result.pVal, this->pVal, RHS.pVal, getNumWords()); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator-(uint64_t RHS) const { - if (isSingleWord()) - return APInt(BitWidth, VAL - RHS); - APInt Result(*this); - sub_1(Result.pVal, getNumWords(), RHS); - Result.clearUnusedBits(); - return Result; -} - bool APInt::EqualSlowCase(const APInt& RHS) const { return std::equal(pVal, pVal + getNumWords(), RHS.pVal); } |