llvm.org GIT mirror llvm / 3ba292d
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 Jeffrey Yasskin 9 years ago
12 changed file(s) with 61 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
1414 #ifndef LLVM_APINT_H
1515 #define LLVM_APINT_H
1616
17 #include "llvm/ADT/ArrayRef.h"
1718 #include "llvm/Support/MathExtras.h"
1819 #include
1920 #include
175176 /// out-of-line slow case for inline constructor
176177 void initSlowCase(unsigned numBits, uint64_t val, bool isSigned);
177178
179 /// shared code between two array constructors
180 void initFromArray(ArrayRef array);
181
178182 /// out-of-line slow case for inline copy constructor
179183 void initSlowCase(const APInt& that);
180184
229233 clearUnusedBits();
230234 }
231235
232 /// Note that numWords can be smaller or larger than the corresponding bit
233 /// width but any extraneous bits will be dropped.
236 /// Note that bigVal.size() can be smaller or larger than the corresponding
237 /// bit width but any extraneous bits will be dropped.
234238 /// @param numBits the bit width of the constructed APInt
235 /// @param numWords the number of words in bigVal
236239 /// @param bigVal a sequence of words to form the initial value of the APInt
237240 /// @brief Construct an APInt of numBits width, initialized as bigVal[].
241 APInt(unsigned numBits, ArrayRef bigVal);
242 /// Equivalent to APInt(numBits, ArrayRef(bigVal, numWords)), but
243 /// deprecated because this constructor is prone to ambiguity with the
244 /// APInt(unsigned, uint64_t, bool) constructor.
245 ///
246 /// If this overload is ever deleted, care should be taken to prevent calls
247 /// from being incorrectly captured by the APInt(unsigned, uint64_t, bool)
248 /// constructor.
238249 APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
239250
240251 /// This constructor interprets the string \arg str in the given radix. The
341352
342353 if (isSingleWord())
343354 return isUIntN(N, VAL);
344 return APInt(N, getNumWords(), pVal).zext(getBitWidth()) == (*this);
355 return APInt(N, makeArrayRef(pVal, getNumWords())).zext(getBitWidth())
356 == (*this);
345357 }
346358
347359 /// @brief Check if this APInt has an N-bits signed integer value.
703703 case 'K':
704704 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
705705 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
706 APFloatVal = APFloat(APInt(80, 2, Pair));
706 APFloatVal = APFloat(APInt(80, Pair));
707707 return lltok::APFloat;
708708 case 'L':
709709 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
710710 HexToIntPair(TokStart+3, CurPtr, Pair);
711 APFloatVal = APFloat(APInt(128, 2, Pair), true);
711 APFloatVal = APFloat(APInt(128, Pair), true);
712712 return lltok::APFloat;
713713 case 'M':
714714 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
715715 HexToIntPair(TokStart+3, CurPtr, Pair);
716 APFloatVal = APFloat(APInt(128, 2, Pair));
716 APFloatVal = APFloat(APInt(128, Pair));
717717 return lltok::APFloat;
718718 }
719719 }
12171217 Words[i] = DecodeSignRotatedValue(Record[i]);
12181218 V = ConstantInt::get(Context,
12191219 APInt(cast(CurTy)->getBitWidth(),
1220 NumWords, &Words[0]));
1220 Words));
12211221 break;
12221222 }
12231223 case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
12321232 uint64_t Rearrange[2];
12331233 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
12341234 Rearrange[1] = Record[0] >> 48;
1235 V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange)));
1235 V = ConstantFP::get(Context, APFloat(APInt(80, Rearrange)));
12361236 } else if (CurTy->isFP128Ty())
1237 V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true));
1237 V = ConstantFP::get(Context, APFloat(APInt(128, Record), true));
12381238 else if (CurTy->isPPC_FP128Ty())
1239 V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0])));
1239 V = ConstantFP::get(Context, APFloat(APInt(128, Record)));
12401240 else
12411241 V = UndefValue::get(CurTy);
12421242 break;
182182 (void) Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
183183 APFloat::rmTowardZero, &isExact);
184184 if (isExact) {
185 APInt IntVal(IntBitWidth, 2, x);
185 APInt IntVal(IntBitWidth, x);
186186
187187 unsigned IntegerReg =
188188 getRegForValue(ConstantInt::get(V->getContext(), IntVal));
878878 assert(NVT.getSizeInBits() == integerPartWidth &&
879879 "Do not know how to expand this float constant!");
880880 APInt C = cast(N)->getValueAPF().bitcastToAPInt();
881 Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
882 &C.getRawData()[1])), NVT);
883 Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, 1,
884 &C.getRawData()[0])), NVT);
881 Lo = DAG.getConstantFP(APFloat(APInt(integerPartWidth, C.getRawData()[1])),
882 NVT);
883 Hi = DAG.getConstantFP(APFloat(APInt(integerPartWidth, C.getRawData()[0])),
884 NVT);
885885 }
886886
887887 void DAGTypeLegalizer::ExpandFloatRes_FABS(SDNode *N, SDValue &Lo,
12001200 static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 };
12011201 static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 };
12021202 static const uint64_t TwoE128[] = { 0x47f0000000000000LL, 0 };
1203 const uint64_t *Parts = 0;
1203 ArrayRef Parts;
12041204
12051205 switch (SrcVT.getSimpleVT().SimpleTy) {
12061206 default:
12171217 }
12181218
12191219 Lo = DAG.getNode(ISD::FADD, dl, VT, Hi,
1220 DAG.getConstantFP(APFloat(APInt(128, 2, Parts)),
1220 DAG.getConstantFP(APFloat(APInt(128, Parts)),
12211221 MVT::ppcf128));
12221222 Lo = DAG.getNode(ISD::SELECT_CC, dl, VT, Src, DAG.getConstant(0, SrcVT),
12231223 Lo, Hi, DAG.getCondCode(ISD::SETLT));
13721372 assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
13731373 "Logic only correct for ppcf128!");
13741374 const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
1375 APFloat APF = APFloat(APInt(128, 2, TwoE31));
1375 APFloat APF = APFloat(APInt(128, TwoE31));
13761376 SDValue Tmp = DAG.getConstantFP(APF, MVT::ppcf128);
13771377 // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
13781378 // FIXME: generated code sucks.
24362436 APFloat::rmTowardZero, &ignored);
24372437 if (s==APFloat::opInvalidOp) // inexact is OK, in fact usual
24382438 break;
2439 APInt api(VT.getSizeInBits(), 2, x);
2439 APInt api(VT.getSizeInBits(), x);
24402440 return getConstant(api, VT);
24412441 }
24422442 case ISD::BITCAST:
931931 // FIXME: Will not trap if loading a signaling NaN.
932932 uint64_t y[2];
933933 memcpy(y, Ptr, 10);
934 Result.IntVal = APInt(80, 2, y);
934 Result.IntVal = APInt(80, y);
935935 break;
936936 }
937937 default:
20972097 opStatus status = convertToInteger(
20982098 parts.data(), bitWidth, result.isSigned(), rounding_mode, isExact);
20992099 // Keeps the original signed-ness.
2100 result = APInt(bitWidth, (unsigned)parts.size(), parts.data());
2100 result = APInt(bitWidth, parts);
21012101 return status;
21022102 }
21032103
21912191 roundingMode rounding_mode)
21922192 {
21932193 unsigned int partCount = partCountForBits(width);
2194 APInt api = APInt(width, partCount, parts);
2194 APInt api = APInt(width, makeArrayRef(parts, partCount));
21952195
21962196 sign = false;
21972197 if (isSigned && APInt::tcExtractBit(parts, width - 1)) {
27452745 words[0] = mysignificand;
27462746 words[1] = ((uint64_t)(sign & 1) << 15) |
27472747 (myexponent & 0x7fffLL);
2748 return APInt(80, 2, words);
2748 return APInt(80, words);
27492749 }
27502750
27512751 APInt
27902790 words[1] = ((uint64_t)(sign2 & 1) << 63) |
27912791 ((myexponent2 & 0x7ff) << 52) |
27922792 (mysignificand2 & 0xfffffffffffffLL);
2793 return APInt(128, 2, words);
2793 return APInt(128, words);
27942794 }
27952795
27962796 APInt
28262826 ((myexponent & 0x7fff) << 48) |
28272827 (mysignificand2 & 0xffffffffffffLL);
28282828
2829 return APInt(128, 2, words);
2829 return APInt(128, words);
28302830 }
28312831
28322832 APInt
34123412 // Decompose the number into an APInt and an exponent.
34133413 int exp = exponent - ((int) semantics->precision - 1);
34143414 APInt significand(semantics->precision,
3415 partCountForBits(semantics->precision),
3416 significandParts());
3415 makeArrayRef(significandParts(),
3416 partCountForBits(semantics->precision)));
34173417
34183418 // Set FormatPrecision if zero. We want to do this before we
34193419 // truncate trailing zeros, as those are part of the precision.
8282 memcpy(pVal, that.pVal, getNumWords() * APINT_WORD_SIZE);
8383 }
8484
85
86 APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
87 : BitWidth(numBits), VAL(0) {
85 void APInt::initFromArray(ArrayRef bigVal) {
8886 assert(BitWidth && "Bitwidth too small");
89 assert(bigVal && "Null pointer detected!");
87 assert(bigVal.data() && "Null pointer detected!");
9088 if (isSingleWord())
9189 VAL = bigVal[0];
9290 else {
9391 // Get memory, cleared to 0
9492 pVal = getClearedMemory(getNumWords());
9593 // Calculate the number of words to copy
96 unsigned words = std::min(numWords, getNumWords());
94 unsigned words = std::min(bigVal.size(), getNumWords());
9795 // Copy the words from bigVal to pVal
98 memcpy(pVal, bigVal, words * APINT_WORD_SIZE);
96 memcpy(pVal, bigVal.data(), words * APINT_WORD_SIZE);
9997 }
10098 // Make sure unused high bits are cleared
10199 clearUnusedBits();
100 }
101
102 APInt::APInt(unsigned numBits, ArrayRef bigVal)
103 : BitWidth(numBits), VAL(0) {
104 initFromArray(bigVal);
105 }
106
107 APInt::APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[])
108 : BitWidth(numBits), VAL(0) {
109 initFromArray(makeArrayRef(bigVal, numWords));
102110 }
103111
104112 APInt::APInt(unsigned numbits, StringRef Str, uint8_t radix)
589589 uint32_t DestBitWidth = cast(DestTy)->getBitWidth();
590590 (void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
591591 APFloat::rmTowardZero, &ignored);
592 APInt Val(DestBitWidth, 2, x);
592 APInt Val(DestBitWidth, x);
593593 return ConstantInt::get(FPC->getContext(), Val);
594594 }
595595 return 0; // Can't fold.
524524 const uint64_t Words[]) {
525525 IntegerType *Ty = unwrap(IntTy);
526526 return wrap(ConstantInt::get(Ty->getContext(),
527 APInt(Ty->getBitWidth(), NumWords, Words)));
527 APInt(Ty->getBitWidth(),
528 makeArrayRef(Words, NumWords))));
528529 }
529530
530531 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
236236 EXPECT_EQ(APInt(32, uint64_t(-16LL)), APInt(32, "-10", 16));
237237 EXPECT_EQ(APInt(32, uint64_t(-31LL)), APInt(32, "-1F", 16));
238238 EXPECT_EQ(APInt(32, uint64_t(-32LL)), APInt(32, "-20", 16));
239 }
240
241 TEST(APIntTest, FromArray) {
242 EXPECT_EQ(APInt(32, uint64_t(1)), APInt(32, ArrayRef(1)));
239243 }
240244
241245 TEST(APIntTest, StringBitsNeeded2) {