mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-16 19:19:10 +00:00
Add APInt(numBits, ArrayRef<uint64_t> bigVal) constructor to prevent future ambiguity
errors like the one corrected by r135261. Migrate all LLVM callers of the old constructor to the new one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135431 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3a594f4876
commit
3ba292dbc2
@ -15,6 +15,7 @@
|
||||
#ifndef LLVM_APINT_H
|
||||
#define LLVM_APINT_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
@ -176,6 +177,9 @@ class APInt {
|
||||
/// out-of-line slow case for inline constructor
|
||||
void initSlowCase(unsigned numBits, uint64_t val, bool isSigned);
|
||||
|
||||
/// shared code between two array constructors
|
||||
void initFromArray(ArrayRef<uint64_t> array);
|
||||
|
||||
/// out-of-line slow case for inline copy constructor
|
||||
void initSlowCase(const APInt& that);
|
||||
|
||||
@ -230,12 +234,19 @@ public:
|
||||
clearUnusedBits();
|
||||
}
|
||||
|
||||
/// Note that numWords can be smaller or larger than the corresponding bit
|
||||
/// width but any extraneous bits will be dropped.
|
||||
/// Note that bigVal.size() can be smaller or larger than the corresponding
|
||||
/// bit width but any extraneous bits will be dropped.
|
||||
/// @param numBits the bit width of the constructed APInt
|
||||
/// @param numWords the number of words in bigVal
|
||||
/// @param bigVal a sequence of words to form the initial value of the APInt
|
||||
/// @brief Construct an APInt of numBits width, initialized as bigVal[].
|
||||
APInt(unsigned numBits, ArrayRef<uint64_t> bigVal);
|
||||
/// Equivalent to APInt(numBits, ArrayRef<uint64_t>(bigVal, numWords)), but
|
||||
/// deprecated because this constructor is prone to ambiguity with the
|
||||
/// APInt(unsigned, uint64_t, bool) constructor.
|
||||
///
|
||||
/// If this overload is ever deleted, care should be taken to prevent calls
|
||||
/// from being incorrectly captured by the APInt(unsigned, uint64_t, bool)
|
||||
/// constructor.
|
||||
APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
|
||||
|
||||
/// This constructor interprets the string \arg str in the given radix. The
|
||||
@ -342,7 +353,8 @@ public:
|
||||
|
||||
if (isSingleWord())
|
||||
return isUIntN(N, VAL);
|
||||
return APInt(N, getNumWords(), pVal).zext(getBitWidth()) == (*this);
|
||||
return APInt(N, makeArrayRef(pVal, getNumWords())).zext(getBitWidth())
|
||||
== (*this);
|
||||
}
|
||||
|
||||
/// @brief Check if this APInt has an N-bits signed integer value.
|
||||
|
@ -704,17 +704,17 @@ lltok::Kind LLLexer::Lex0x() {
|
||||
case 'K':
|
||||
// F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
|
||||
FP80HexToIntPair(TokStart+3, CurPtr, Pair);
|
||||
APFloatVal = APFloat(APInt(80, 2, Pair));
|
||||
APFloatVal = APFloat(APInt(80, Pair));
|
||||
return lltok::APFloat;
|
||||
case 'L':
|
||||
// F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
|
||||
HexToIntPair(TokStart+3, CurPtr, Pair);
|
||||
APFloatVal = APFloat(APInt(128, 2, Pair), true);
|
||||
APFloatVal = APFloat(APInt(128, Pair), true);
|
||||
return lltok::APFloat;
|
||||
case 'M':
|
||||
// PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
|
||||
HexToIntPair(TokStart+3, CurPtr, Pair);
|
||||
APFloatVal = APFloat(APInt(128, 2, Pair));
|
||||
APFloatVal = APFloat(APInt(128, Pair));
|
||||
return lltok::APFloat;
|
||||
}
|
||||
}
|
||||
|
@ -1218,7 +1218,7 @@ bool BitcodeReader::ParseConstants() {
|
||||
Words[i] = DecodeSignRotatedValue(Record[i]);
|
||||
V = ConstantInt::get(Context,
|
||||
APInt(cast<IntegerType>(CurTy)->getBitWidth(),
|
||||
NumWords, &Words[0]));
|
||||
Words));
|
||||
break;
|
||||
}
|
||||
case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
|
||||
@ -1233,11 +1233,11 @@ bool BitcodeReader::ParseConstants() {
|
||||
uint64_t Rearrange[2];
|
||||
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
|
||||
Rearrange[1] = Record[0] >> 48;
|
||||
V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange)));
|
||||
V = ConstantFP::get(Context, APFloat(APInt(80, Rearrange)));
|
||||
} else if (CurTy->isFP128Ty())
|
||||
V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true));
|
||||
V = ConstantFP::get(Context, APFloat(APInt(128, Record), true));
|
||||
else if (CurTy->isPPC_FP128Ty())
|
||||
V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0])));
|
||||
V = ConstantFP::get(Context, APFloat(APInt(128, Record)));
|
||||
else
|
||||
V = UndefValue::get(CurTy);
|
||||
break;
|
||||
|
@ -183,7 +183,7 @@ unsigned FastISel::materializeRegForValue(const Value *V, MVT VT) {
|
||||
(void) Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
|
||||
APFloat::rmTowardZero, &isExact);
|
||||
if (isExact) {
|
||||
APInt IntVal(IntBitWidth, 2, x);
|
||||
APInt IntVal(IntBitWidth, x);
|
||||
|
||||
unsigned IntegerReg =
|
||||
getRegForValue(ConstantInt::get(V->getContext(), IntVal));
|
||||
|
@ -879,10 +879,10 @@ void DAGTypeLegalizer::ExpandFloatRes_ConstantFP(SDNode *N, SDValue &Lo,
|
||||
assert(NVT.getSizeInBits() == integerPartWidth &&
|
||||
"Do not know how to expand this float constant!");
|
||||
APInt C = cast<ConstantFPSDNode>(N)->getValueAPF().bitcastToAPInt();
|
||||
Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
|
||||
&C.getRawData()[1])), NVT);
|
||||
Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
|
||||
&C.getRawData()[0])), NVT);
|
||||
Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, C.getRawData()[1])),
|
||||
NVT);
|
||||
Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, C.getRawData()[0])),
|
||||
NVT);
|
||||
}
|
||||
|
||||
void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDValue &Lo,
|
||||
@ -1201,7 +1201,7 @@ void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo,
|
||||
static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 };
|
||||
static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 };
|
||||
static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
|
||||
const uint64_t *Parts = 0;
|
||||
ArrayRef<uint64_t> Parts;
|
||||
|
||||
switch (SrcVT.getSimpleVT().SimpleTy) {
|
||||
default:
|
||||
@ -1218,7 +1218,7 @@ void DAGTypeLegalizer::ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo,
|
||||
}
|
||||
|
||||
Lo = DAG.getNode(ISD::FADD, dl, VT, Hi,
|
||||
DAG.getConstantFP(APFloat(APInt(128, 2, Parts)),
|
||||
DAG.getConstantFP(APFloat(APInt(128, Parts)),
|
||||
MVT::ppcf128));
|
||||
Lo = DAG.getNode(ISD::SELECT_CC, dl, VT, Src, DAG.getConstant(0, SrcVT),
|
||||
Lo, Hi, DAG.getCondCode(ISD::SETLT));
|
||||
@ -1373,7 +1373,7 @@ SDValue DAGTypeLegalizer::ExpandFloatOp_FP_TO_UINT(SDNode *N) {
|
||||
assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
|
||||
"Logic only correct for ppcf128!");
|
||||
const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
|
||||
APFloat APF = APFloat(APInt(128, 2, TwoE31));
|
||||
APFloat APF = APFloat(APInt(128, TwoE31));
|
||||
SDValue Tmp = DAG.getConstantFP(APF, MVT::ppcf128);
|
||||
// X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
|
||||
// FIXME: generated code sucks.
|
||||
|
@ -2437,7 +2437,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, DebugLoc DL,
|
||||
APFloat::rmTowardZero, &ignored);
|
||||
if (s==APFloat::opInvalidOp) // inexact is OK, in fact usual
|
||||
break;
|
||||
APInt api(VT.getSizeInBits(), 2, x);
|
||||
APInt api(VT.getSizeInBits(), x);
|
||||
return getConstant(api, VT);
|
||||
}
|
||||
case ISD::BITCAST:
|
||||
|
@ -932,7 +932,7 @@ void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
|
||||
// FIXME: Will not trap if loading a signaling NaN.
|
||||
uint64_t y[2];
|
||||
memcpy(y, Ptr, 10);
|
||||
Result.IntVal = APInt(80, 2, y);
|
||||
Result.IntVal = APInt(80, y);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -2098,7 +2098,7 @@ APFloat::convertToInteger(APSInt &result,
|
||||
opStatus status = convertToInteger(
|
||||
parts.data(), bitWidth, result.isSigned(), rounding_mode, isExact);
|
||||
// Keeps the original signed-ness.
|
||||
result = APInt(bitWidth, (unsigned)parts.size(), parts.data());
|
||||
result = APInt(bitWidth, parts);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -2192,7 +2192,7 @@ APFloat::convertFromZeroExtendedInteger(const integerPart *parts,
|
||||
roundingMode rounding_mode)
|
||||
{
|
||||
unsigned int partCount = partCountForBits(width);
|
||||
APInt api = APInt(width, partCount, parts);
|
||||
APInt api = APInt(width, makeArrayRef(parts, partCount));
|
||||
|
||||
sign = false;
|
||||
if (isSigned && APInt::tcExtractBit(parts, width - 1)) {
|
||||
@ -2746,7 +2746,7 @@ APFloat::convertF80LongDoubleAPFloatToAPInt() const
|
||||
words[0] = mysignificand;
|
||||
words[1] = ((uint64_t)(sign & 1) << 15) |
|
||||
(myexponent & 0x7fffLL);
|
||||
return APInt(80, 2, words);
|
||||
return APInt(80, words);
|
||||
}
|
||||
|
||||
APInt
|
||||
@ -2791,7 +2791,7 @@ APFloat::convertPPCDoubleDoubleAPFloatToAPInt() const
|
||||
words[1] = ((uint64_t)(sign2 & 1) << 63) |
|
||||
((myexponent2 & 0x7ff) << 52) |
|
||||
(mysignificand2 & 0xfffffffffffffLL);
|
||||
return APInt(128, 2, words);
|
||||
return APInt(128, words);
|
||||
}
|
||||
|
||||
APInt
|
||||
@ -2827,7 +2827,7 @@ APFloat::convertQuadrupleAPFloatToAPInt() const
|
||||
((myexponent & 0x7fff) << 48) |
|
||||
(mysignificand2 & 0xffffffffffffLL);
|
||||
|
||||
return APInt(128, 2, words);
|
||||
return APInt(128, words);
|
||||
}
|
||||
|
||||
APInt
|
||||
@ -3413,8 +3413,8 @@ void APFloat::toString(SmallVectorImpl<char> &Str,
|
||||
// Decompose the number into an APInt and an exponent.
|
||||
int exp = exponent - ((int) semantics->precision - 1);
|
||||
APInt significand(semantics->precision,
|
||||
partCountForBits(semantics->precision),
|
||||
significandParts());
|
||||
makeArrayRef(significandParts(),
|
||||
partCountForBits(semantics->precision)));
|
||||
|
||||
// Set FormatPrecision if zero. We want to do this before we
|
||||
// truncate trailing zeros, as those are part of the precision.
|
||||
|
@ -83,25 +83,33 @@ void APInt::initSlowCase(const APInt& that) {
|
||||
memcpy(pVal, that.pVal, getNumWords() * APINT_WORD_SIZE);
|
||||
}
|
||||
|
||||
|
||||
APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
|
||||
: BitWidth(numBits), VAL(0) {
|
||||
void APInt::initFromArray(ArrayRef<uint64_t> bigVal) {
|
||||
assert(BitWidth && "Bitwidth too small");
|
||||
assert(bigVal && "Null pointer detected!");
|
||||
assert(bigVal.data() && "Null pointer detected!");
|
||||
if (isSingleWord())
|
||||
VAL = bigVal[0];
|
||||
else {
|
||||
// Get memory, cleared to 0
|
||||
pVal = getClearedMemory(getNumWords());
|
||||
// Calculate the number of words to copy
|
||||
unsigned words = std::min<unsigned>(numWords, getNumWords());
|
||||
unsigned words = std::min<unsigned>(bigVal.size(), getNumWords());
|
||||
// Copy the words from bigVal to pVal
|
||||
memcpy(pVal, bigVal, words * APINT_WORD_SIZE);
|
||||
memcpy(pVal, bigVal.data(), words * APINT_WORD_SIZE);
|
||||
}
|
||||
// Make sure unused high bits are cleared
|
||||
clearUnusedBits();
|
||||
}
|
||||
|
||||
APInt::APInt(unsigned numBits, ArrayRef<uint64_t> bigVal)
|
||||
: BitWidth(numBits), VAL(0) {
|
||||
initFromArray(bigVal);
|
||||
}
|
||||
|
||||
APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
|
||||
: BitWidth(numBits), VAL(0) {
|
||||
initFromArray(makeArrayRef(bigVal, numWords));
|
||||
}
|
||||
|
||||
APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix)
|
||||
: BitWidth(numbits), VAL(0) {
|
||||
assert(BitWidth && "Bitwidth too small");
|
||||
|
@ -590,7 +590,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
|
||||
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
(void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
|
||||
APFloat::rmTowardZero, &ignored);
|
||||
APInt Val(DestBitWidth, 2, x);
|
||||
APInt Val(DestBitWidth, x);
|
||||
return ConstantInt::get(FPC->getContext(), Val);
|
||||
}
|
||||
return 0; // Can't fold.
|
||||
|
@ -525,7 +525,8 @@ LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
|
||||
const uint64_t Words[]) {
|
||||
IntegerType *Ty = unwrap<IntegerType>(IntTy);
|
||||
return wrap(ConstantInt::get(Ty->getContext(),
|
||||
APInt(Ty->getBitWidth(), NumWords, Words)));
|
||||
APInt(Ty->getBitWidth(),
|
||||
makeArrayRef(Words, NumWords))));
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
|
||||
|
@ -239,6 +239,10 @@ TEST(APIntTest, fromString) {
|
||||
EXPECT_EQ(APInt(32, uint64_t(-32LL)), APInt(32, "-20", 16));
|
||||
}
|
||||
|
||||
TEST(APIntTest, FromArray) {
|
||||
EXPECT_EQ(APInt(32, uint64_t(1)), APInt(32, ArrayRef<uint64_t>(1)));
|
||||
}
|
||||
|
||||
TEST(APIntTest, StringBitsNeeded2) {
|
||||
EXPECT_EQ(1U, APInt::getBitsNeeded( "0", 2));
|
||||
EXPECT_EQ(1U, APInt::getBitsNeeded( "1", 2));
|
||||
|
Loading…
x
Reference in New Issue
Block a user