PR5207: Make APInt::set(), APInt::clear() and APInt::flip() return void.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120413 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jay Foad 2010-11-30 09:02:01 +00:00
parent d872f144e2
commit a99793c5ea
4 changed files with 39 additions and 33 deletions

View File

@ -379,12 +379,17 @@ public:
/// @{ /// @{
/// @brief Gets maximum unsigned value of APInt for specific bit width. /// @brief Gets maximum unsigned value of APInt for specific bit width.
static APInt getMaxValue(unsigned numBits) { static APInt getMaxValue(unsigned numBits) {
return APInt(numBits, 0).set(); APInt API(numBits, 0);
API.set();
return API;
} }
/// @brief Gets maximum signed value of APInt for a specific bit width. /// @brief Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMaxValue(unsigned numBits) { static APInt getSignedMaxValue(unsigned numBits) {
return APInt(numBits, 0).set().clear(numBits - 1); APInt API(numBits, 0);
API.set();
API.clear(numBits - 1);
return API;
} }
/// @brief Gets minimum unsigned value of APInt for a specific bit width. /// @brief Gets minimum unsigned value of APInt for a specific bit width.
@ -394,7 +399,9 @@ public:
/// @brief Gets minimum signed value of APInt for a specific bit width. /// @brief Gets minimum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits) { static APInt getSignedMinValue(unsigned numBits) {
return APInt(numBits, 0).set(numBits - 1); APInt API(numBits, 0);
API.set(numBits - 1);
return API;
} }
/// getSignBit - This is just a wrapper function of getSignedMinValue(), and /// getSignBit - This is just a wrapper function of getSignedMinValue(), and
@ -407,7 +414,9 @@ public:
/// @returns the all-ones value for an APInt of the specified bit-width. /// @returns the all-ones value for an APInt of the specified bit-width.
/// @brief Get the all-ones value. /// @brief Get the all-ones value.
static APInt getAllOnesValue(unsigned numBits) { static APInt getAllOnesValue(unsigned numBits) {
return APInt(numBits, 0).set(); APInt API(numBits, 0);
API.set();
return API;
} }
/// @returns the '0' value for an APInt of the specified bit-width. /// @returns the '0' value for an APInt of the specified bit-width.
@ -1035,51 +1044,49 @@ public:
/// @name Bit Manipulation Operators /// @name Bit Manipulation Operators
/// @{ /// @{
/// @brief Set every bit to 1. /// @brief Set every bit to 1.
APInt &set() { void set() {
if (isSingleWord()) { if (isSingleWord())
VAL = -1ULL; VAL = -1ULL;
return clearUnusedBits(); else {
// Set all the bits in all the words.
for (unsigned i = 0; i < getNumWords(); ++i)
pVal[i] = -1ULL;
} }
// Set all the bits in all the words.
for (unsigned i = 0; i < getNumWords(); ++i)
pVal[i] = -1ULL;
// Clear the unused ones // Clear the unused ones
return clearUnusedBits(); clearUnusedBits();
} }
/// Set the given bit to 1 whose position is given as "bitPosition". /// Set the given bit to 1 whose position is given as "bitPosition".
/// @brief Set a given bit to 1. /// @brief Set a given bit to 1.
APInt &set(unsigned bitPosition); void set(unsigned bitPosition);
/// @brief Set every bit to 0. /// @brief Set every bit to 0.
APInt &clear() { void clear() {
if (isSingleWord()) if (isSingleWord())
VAL = 0; VAL = 0;
else else
memset(pVal, 0, getNumWords() * APINT_WORD_SIZE); memset(pVal, 0, getNumWords() * APINT_WORD_SIZE);
return *this;
} }
/// Set the given bit to 0 whose position is given as "bitPosition". /// Set the given bit to 0 whose position is given as "bitPosition".
/// @brief Set a given bit to 0. /// @brief Set a given bit to 0.
APInt &clear(unsigned bitPosition); void clear(unsigned bitPosition);
/// @brief Toggle every bit to its opposite value. /// @brief Toggle every bit to its opposite value.
APInt &flip() { void flip() {
if (isSingleWord()) { if (isSingleWord())
VAL ^= -1ULL; VAL ^= -1ULL;
return clearUnusedBits(); else {
for (unsigned i = 0; i < getNumWords(); ++i)
pVal[i] ^= -1ULL;
} }
for (unsigned i = 0; i < getNumWords(); ++i) clearUnusedBits();
pVal[i] ^= -1ULL;
return clearUnusedBits();
} }
/// Toggle a given bit to its opposite value whose position is given /// Toggle a given bit to its opposite value whose position is given
/// as "bitPosition". /// as "bitPosition".
/// @brief Toggles a given bit to its opposite value. /// @brief Toggles a given bit to its opposite value.
APInt& flip(unsigned bitPosition); void flip(unsigned bitPosition);
/// @} /// @}
/// @name Value Characterization Functions /// @name Value Characterization Functions

View File

@ -875,8 +875,9 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
// Turn Op0 << Op1 into Op0 * 2^Op1 // Turn Op0 << Op1 into Op0 * 2^Op1
APInt Op1Int = Op1CI->getValue(); APInt Op1Int = Op1CI->getValue();
uint64_t BitToSet = Op1Int.getLimitedValue(Op1Int.getBitWidth() - 1); uint64_t BitToSet = Op1Int.getLimitedValue(Op1Int.getBitWidth() - 1);
Op1 = ConstantInt::get(V->getContext(), APInt API(Op1Int.getBitWidth(), 0);
APInt(Op1Int.getBitWidth(), 0).set(BitToSet)); API.set(BitToSet);
Op1 = ConstantInt::get(V->getContext(), API);
} }
Value *Mul0 = NULL; Value *Mul0 = NULL;

View File

@ -133,8 +133,9 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FABS(SDNode *N) {
unsigned Size = NVT.getSizeInBits(); unsigned Size = NVT.getSizeInBits();
// Mask = ~(1 << (Size-1)) // Mask = ~(1 << (Size-1))
SDValue Mask = DAG.getConstant(APInt::getAllOnesValue(Size).clear(Size-1), APInt API = APInt::getAllOnesValue(Size);
NVT); API.clear(Size-1);
SDValue Mask = DAG.getConstant(API, NVT);
SDValue Op = GetSoftenedFloat(N->getOperand(0)); SDValue Op = GetSoftenedFloat(N->getOperand(0));
return DAG.getNode(ISD::AND, N->getDebugLoc(), NVT, Op, Mask); return DAG.getNode(ISD::AND, N->getDebugLoc(), NVT, Op, Mask);
} }

View File

@ -584,22 +584,20 @@ bool APInt::slt(const APInt& RHS) const {
return lhs.ult(rhs); return lhs.ult(rhs);
} }
APInt& APInt::set(unsigned bitPosition) { void APInt::set(unsigned bitPosition) {
if (isSingleWord()) if (isSingleWord())
VAL |= maskBit(bitPosition); VAL |= maskBit(bitPosition);
else else
pVal[whichWord(bitPosition)] |= maskBit(bitPosition); pVal[whichWord(bitPosition)] |= maskBit(bitPosition);
return *this;
} }
/// Set the given bit to 0 whose position is given as "bitPosition". /// Set the given bit to 0 whose position is given as "bitPosition".
/// @brief Set a given bit to 0. /// @brief Set a given bit to 0.
APInt& APInt::clear(unsigned bitPosition) { void APInt::clear(unsigned bitPosition) {
if (isSingleWord()) if (isSingleWord())
VAL &= ~maskBit(bitPosition); VAL &= ~maskBit(bitPosition);
else else
pVal[whichWord(bitPosition)] &= ~maskBit(bitPosition); pVal[whichWord(bitPosition)] &= ~maskBit(bitPosition);
return *this;
} }
/// @brief Toggle every bit to its opposite value. /// @brief Toggle every bit to its opposite value.
@ -607,11 +605,10 @@ APInt& APInt::clear(unsigned bitPosition) {
/// Toggle a given bit to its opposite value whose position is given /// Toggle a given bit to its opposite value whose position is given
/// as "bitPosition". /// as "bitPosition".
/// @brief Toggles a given bit to its opposite value. /// @brief Toggles a given bit to its opposite value.
APInt& APInt::flip(unsigned bitPosition) { void APInt::flip(unsigned bitPosition) {
assert(bitPosition < BitWidth && "Out of the bit-width range!"); assert(bitPosition < BitWidth && "Out of the bit-width range!");
if ((*this)[bitPosition]) clear(bitPosition); if ((*this)[bitPosition]) clear(bitPosition);
else set(bitPosition); else set(bitPosition);
return *this;
} }
unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) { unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {