29 #include "llvm/Config/config.h"
68 for (
unsigned i = 0;
i != NumSrcElts; ++
i) {
75 if (Element && isa<UndefValue>(Element)) {
80 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
102 if (
auto *VTy = dyn_cast<VectorType>(C->
getType())) {
105 unsigned NumSrcElts = VTy->getNumElements();
106 Type *SrcEltTy = VTy->getElementType();
119 if (
Constant *CE = foldConstVectorToAPInt(Result, DestTy, C,
120 SrcEltTy, NumSrcElts, DL))
123 if (isa<IntegerType>(DestTy))
138 if (isa<ConstantFP>(C) || isa<ConstantInt>(C)) {
144 if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
148 unsigned NumDstElt = DestVTy->getNumElements();
150 if (NumDstElt == NumSrcElt)
154 Type *DstEltTy = DestVTy->getElementType();
187 if (!isa<ConstantVector>(C) &&
188 !isa<ConstantDataVector>(C))
199 if (NumDstElt < NumSrcElt) {
202 unsigned Ratio = NumSrcElt/NumDstElt;
205 for (
unsigned i = 0;
i != NumDstElt; ++
i) {
208 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
209 for (
unsigned j = 0; j != Ratio; ++j) {
211 if (Src && isa<UndefValue>(Src))
214 Src = dyn_cast_or_null<ConstantInt>(Src);
224 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
235 unsigned Ratio = NumDstElt/NumSrcElt;
239 for (
unsigned i = 0;
i != NumSrcElt; ++
i) {
245 if (isa<UndefValue>(Element)) {
255 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize*(Ratio-1);
256 for (
unsigned j = 0; j != Ratio; ++j) {
261 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
287 if ((GV = dyn_cast<GlobalValue>(C))) {
289 Offset =
APInt(BitWidth, 0);
295 if (!CE)
return false;
298 if (CE->getOpcode() == Instruction::PtrToInt ||
299 CE->getOpcode() == Instruction::BitCast)
308 APInt TmpOffset(BitWidth, 0);
315 if (!
GEP->accumulateConstantOffset(DL, TmpOffset))
328 bool ReadDataFromGlobal(
Constant *C, uint64_t ByteOffset,
unsigned char *CurPtr,
331 "Out of range access");
335 if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
338 if (
auto *CI = dyn_cast<ConstantInt>(C)) {
339 if (CI->getBitWidth() > 64 ||
340 (CI->getBitWidth() & 7) != 0)
343 uint64_t Val = CI->getZExtValue();
344 unsigned IntBytes =
unsigned(CI->getBitWidth()/8);
346 for (
unsigned i = 0;
i != BytesLeft && ByteOffset != IntBytes; ++
i) {
349 n = IntBytes - n - 1;
350 CurPtr[
i] = (
unsigned char)(Val >> (n * 8));
356 if (
auto *CFP = dyn_cast<ConstantFP>(C)) {
357 if (CFP->getType()->isDoubleTy()) {
359 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
361 if (CFP->getType()->isFloatTy()){
363 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
365 if (CFP->getType()->isHalfTy()){
367 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
372 if (
auto *CS = dyn_cast<ConstantStruct>(C)) {
376 ByteOffset -= CurEltOffset;
383 if (ByteOffset < EltSize &&
384 !ReadDataFromGlobal(
CS->getOperand(Index), ByteOffset, CurPtr,
391 if (Index ==
CS->getType()->getNumElements())
397 if (BytesLeft <= NextEltOffset - CurEltOffset - ByteOffset)
401 CurPtr += NextEltOffset - CurEltOffset - ByteOffset;
402 BytesLeft -= NextEltOffset - CurEltOffset - ByteOffset;
404 CurEltOffset = NextEltOffset;
409 if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
410 isa<ConstantDataSequential>(C)) {
413 uint64_t Index = ByteOffset / EltSize;
414 uint64_t
Offset = ByteOffset - Index * EltSize;
416 if (
auto *AT = dyn_cast<ArrayType>(C->
getType()))
417 NumElts = AT->getNumElements();
421 for (; Index != NumElts; ++Index) {
426 uint64_t BytesWritten = EltSize -
Offset;
427 assert(BytesWritten <= EltSize &&
"Not indexing into this element?");
428 if (BytesWritten >= BytesLeft)
432 BytesLeft -= BytesWritten;
433 CurPtr += BytesWritten;
438 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
439 if (
CE->getOpcode() == Instruction::IntToPtr &&
441 return ReadDataFromGlobal(
CE->getOperand(0), ByteOffset, CurPtr,
452 auto *PTy = cast<PointerType>(C->
getType());
457 unsigned AS = PTy->getAddressSpace();
477 if (
Constant *Res = FoldReinterpretLoadFromConstPtr(C, MapTy, DL))
482 unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
483 if (BytesLoaded > 32 || BytesLoaded == 0)
492 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
493 !GV->getInitializer()->getType()->isSized())
497 int64_t InitializerSize = DL.
getTypeAllocSize(GV->getInitializer()->getType());
500 if (Offset + BytesLoaded <= 0)
504 if (Offset >= InitializerSize)
507 unsigned char RawBytes[32] = {0};
508 unsigned char *CurPtr = RawBytes;
509 unsigned BytesLeft = BytesLoaded;
518 if (!ReadDataFromGlobal(GV->getInitializer(),
Offset, CurPtr, BytesLeft, DL))
521 APInt ResultVal =
APInt(IntType->getBitWidth(), 0);
523 ResultVal = RawBytes[BytesLoaded - 1];
524 for (
unsigned i = 1;
i != BytesLoaded; ++
i) {
526 ResultVal |= RawBytes[BytesLoaded - 1 -
i];
529 ResultVal = RawBytes[0];
530 for (
unsigned i = 1;
i != BytesLoaded; ++
i) {
532 ResultVal |= RawBytes[
i];
561 Cast = Instruction::IntToPtr;
563 Cast = Instruction::PtrToInt;
589 if (
auto *GV = dyn_cast<GlobalVariable>(C))
590 if (GV->isConstant() && GV->hasDefinitiveInitializer())
591 return GV->getInitializer();
593 if (
auto *GA = dyn_cast<GlobalAlias>(C))
594 if (GA->getAliasee() && !GA->isInterposable())
602 if (CE->
getOpcode() == Instruction::GetElementPtr) {
603 if (
auto *GV = dyn_cast<GlobalVariable>(CE->
getOperand(0))) {
604 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
612 if (CE->
getOpcode() == Instruction::BitCast)
613 if (
Constant *LoadedC = ConstantFoldLoadThroughBitcast(CE, Ty, DL))
620 size_t StrLen = Str.
size();
624 if ((NumBits >> 3) == StrLen + 1 && (NumBits & 7) == 0 &&
627 APInt SingleChar(NumBits, 0);
630 SingleChar =
static_cast<uint64_t
>(
C);
631 StrVal = (StrVal << 8) | SingleChar;
634 for (
unsigned char C : Str.
bytes()) {
635 SingleChar =
static_cast<uint64_t
>(
C);
636 StrVal = (StrVal << 8) | SingleChar;
640 StrVal = (StrVal << 8) | SingleChar;
653 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
654 if (GV->getInitializer()->isNullValue())
656 if (isa<UndefValue>(GV->getInitializer()))
662 return FoldReinterpretLoadFromConstPtr(CE, Ty, DL);
670 if (
auto *C = dyn_cast<Constant>(LI->
getOperand(0)))
690 APInt KnownZero0(BitWidth, 0), KnownOne0(BitWidth, 0);
691 APInt KnownZero1(BitWidth, 0), KnownOne1(BitWidth, 0);
694 if ((KnownOne1 | KnownZero0).isAllOnesValue()) {
698 if ((KnownOne0 | KnownZero1).isAllOnesValue()) {
703 APInt KnownZero = KnownZero0 | KnownZero1;
704 APInt KnownOne = KnownOne0 & KnownOne1;
705 if ((KnownZero | KnownOne).isAllOnesValue()) {
712 if (Opc == Instruction::Sub) {
741 for (
unsigned i = 1, e = Ops.
size();
i != e; ++
i) {
744 SrcElemTy, Ops.
slice(1,
i - 1)))) &&
747 Type *NewType = Ops[
i]->getType()->isVectorTy()
763 SrcElemTy, Ops[0], NewIdxs,
false, InRangeIndex);
773 auto *OldPtrTy = cast<PointerType>(Ptr->
getType());
775 auto *NewPtrTy = cast<PointerType>(Ptr->getType());
780 if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
781 NewPtrTy = ElemTy->
getPointerTo(OldPtrTy->getAddressSpace());
801 if (
Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
813 for (
unsigned i = 1, e = Ops.
size();
i != e; ++
i)
814 if (!isa<ConstantInt>(Ops[
i])) {
821 "CastGEPIndices didn't canonicalize index types!");
822 if (CE && CE->
getOpcode() == Instruction::Sub &&
841 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
844 while (
auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
851 bool AllConstantInt =
true;
852 for (
Value *NestedOp : NestedOps)
853 if (!isa<ConstantInt>(NestedOp)) {
854 AllConstantInt =
false;
863 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
868 APInt BasePtr(BitWidth, 0);
869 if (
auto *CE = dyn_cast<ConstantExpr>(Ptr)) {
870 if (CE->
getOpcode() == Instruction::IntToPtr) {
871 if (
auto *Base = dyn_cast<ConstantInt>(CE->
getOperand(0)))
872 BasePtr = Base->getValue().zextOrTrunc(BitWidth);
876 auto *PTy = cast<PointerType>(Ptr->getType());
877 if ((Ptr->isNullValue() || BasePtr != 0) &&
894 if (!NewIdxs.
empty())
902 }
else if (
auto *ATy = dyn_cast<SequentialType>(Ty)) {
903 Ty = ATy->getElementType();
923 Offset -= NewIdx * ElemSize;
927 auto *STy = cast<StructType>(Ty);
942 Offset -=
APInt(BitWidth, SL.getElementOffset(ElIdx));
943 Ty = STy->getTypeAtIndex(ElIdx);
945 }
while (Ty != ResElemTy);
958 NewIdxs.
size() > *LastIRIndex) {
959 InRangeIndex = LastIRIndex;
960 for (
unsigned I = 0;
I <= *LastIRIndex; ++
I)
969 InBounds, InRangeIndex);
971 "Computed GetElementPtr has unexpected type!");
991 Constant *ConstantFoldInstOperandsImpl(
const Value *InstOrCE,
unsigned Opcode,
1004 if (
auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
1005 if (
Constant *C = SymbolicallyEvaluateGEP(GEP, Ops, DL, TLI))
1013 if (
auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
1017 default:
return nullptr;
1018 case Instruction::ICmp:
1021 if (
auto *
F = dyn_cast<Function>(Ops.
back()))
1027 case Instruction::ExtractElement:
1029 case Instruction::InsertElement:
1031 case Instruction::ShuffleVector:
1048 if (!isa<ConstantVector>(C) && !isa<ConstantExpr>(C))
1053 auto *NewC = cast<Constant>(&NewU);
1056 if (isa<ConstantVector>(NewC) || isa<ConstantExpr>(NewC)) {
1057 auto It = FoldedOps.
find(NewC);
1058 if (It == FoldedOps.
end()) {
1060 ConstantFoldConstantImpl(NewC, DL, TLI, FoldedOps)) {
1062 FoldedOps.
insert({NewC, FoldedC});
1064 FoldedOps.
insert({NewC, NewC});
1073 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1078 return ConstantFoldInstOperandsImpl(CE, CE->
getOpcode(), Ops, DL, TLI);
1081 assert(isa<ConstantVector>(C));
1090 if (
auto *PN = dyn_cast<PHINode>(I)) {
1094 for (
Value *Incoming : PN->incoming_values()) {
1099 if (isa<UndefValue>(Incoming))
1106 if (
auto *FoldedC = ConstantFoldConstantImpl(C, DL, TLI, FoldedOps))
1110 if (CommonValue && C != CommonValue)
1127 auto *
Op = cast<Constant>(&OpU);
1129 if (
auto *FoldedOp = ConstantFoldConstantImpl(
Op, DL, TLI, FoldedOps))
1135 if (
const auto *CI = dyn_cast<CmpInst>(I))
1139 if (
const auto *LI = dyn_cast<LoadInst>(I))
1140 return ConstantFoldLoadInst(LI, DL);
1142 if (
auto *IVI = dyn_cast<InsertValueInst>(I)) {
1144 cast<Constant>(IVI->getAggregateOperand()),
1145 cast<Constant>(IVI->getInsertedValueOperand()),
1149 if (
auto *EVI = dyn_cast<ExtractValueInst>(I)) {
1151 cast<Constant>(EVI->getAggregateOperand()),
1161 return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
1168 return ConstantFoldInstOperandsImpl(I, I->
getOpcode(), Ops, DL, TLI);
1183 if (
auto *CE0 = dyn_cast<ConstantExpr>(Ops0)) {
1185 if (CE0->getOpcode() == Instruction::IntToPtr) {
1197 if (CE0->getOpcode() == Instruction::PtrToInt) {
1199 if (CE0->getType() == IntPtrTy) {
1207 if (
auto *CE1 = dyn_cast<ConstantExpr>(Ops1)) {
1208 if (CE0->getOpcode() == CE1->getOpcode()) {
1209 if (CE0->getOpcode() == Instruction::IntToPtr) {
1223 if (CE0->getOpcode() == Instruction::PtrToInt) {
1225 if (CE0->getType() == IntPtrTy &&
1226 CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) {
1228 Predicate, CE0->getOperand(0), CE1->getOperand(0), DL, TLI);
1239 Predicate, CE0->getOperand(0), Ops1, DL, TLI);
1241 Predicate, CE0->getOperand(1), Ops1, DL, TLI);
1255 if (isa<ConstantExpr>(LHS) || isa<ConstantExpr>(RHS))
1256 if (
Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL))
1268 case Instruction::PtrToInt:
1271 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1272 if (CE->
getOpcode() == Instruction::IntToPtr) {
1276 if (PtrWidth < InWidth) {
1287 case Instruction::IntToPtr:
1292 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1293 if (CE->
getOpcode() == Instruction::PtrToInt) {
1298 if (MidIntSize >= SrcPtrSize) {
1307 case Instruction::Trunc:
1308 case Instruction::ZExt:
1309 case Instruction::SExt:
1310 case Instruction::FPTrunc:
1311 case Instruction::FPExt:
1312 case Instruction::UIToFP:
1313 case Instruction::SIToFP:
1314 case Instruction::FPToUI:
1315 case Instruction::FPToSI:
1316 case Instruction::AddrSpaceCast:
1318 case Instruction::BitCast:
1357 case Intrinsic::fabs:
1360 case Intrinsic::log:
1361 case Intrinsic::log2:
1362 case Intrinsic::log10:
1363 case Intrinsic::exp:
1364 case Intrinsic::exp2:
1365 case Intrinsic::floor:
1366 case Intrinsic::ceil:
1367 case Intrinsic::sqrt:
1368 case Intrinsic::sin:
1369 case Intrinsic::cos:
1370 case Intrinsic::trunc:
1371 case Intrinsic::rint:
1372 case Intrinsic::nearbyint:
1373 case Intrinsic::pow:
1374 case Intrinsic::powi:
1375 case Intrinsic::bswap:
1376 case Intrinsic::ctpop:
1377 case Intrinsic::ctlz:
1378 case Intrinsic::cttz:
1379 case Intrinsic::fma:
1380 case Intrinsic::fmuladd:
1381 case Intrinsic::copysign:
1383 case Intrinsic::masked_load:
1384 case Intrinsic::sadd_with_overflow:
1385 case Intrinsic::uadd_with_overflow:
1386 case Intrinsic::ssub_with_overflow:
1387 case Intrinsic::usub_with_overflow:
1388 case Intrinsic::smul_with_overflow:
1389 case Intrinsic::umul_with_overflow:
1390 case Intrinsic::convert_from_fp16:
1391 case Intrinsic::convert_to_fp16:
1392 case Intrinsic::bitreverse:
1393 case Intrinsic::x86_sse_cvtss2si:
1394 case Intrinsic::x86_sse_cvtss2si64:
1395 case Intrinsic::x86_sse_cvttss2si:
1396 case Intrinsic::x86_sse_cvttss2si64:
1397 case Intrinsic::x86_sse2_cvtsd2si:
1398 case Intrinsic::x86_sse2_cvtsd2si64:
1399 case Intrinsic::x86_sse2_cvttsd2si:
1400 case Intrinsic::x86_sse2_cvttsd2si64:
1418 return Name ==
"acos" || Name ==
"asin" || Name ==
"atan" ||
1419 Name ==
"atan2" || Name ==
"acosf" || Name ==
"asinf" ||
1420 Name ==
"atanf" || Name ==
"atan2f";
1422 return Name ==
"ceil" || Name ==
"cos" || Name ==
"cosh" ||
1423 Name ==
"ceilf" || Name ==
"cosf" || Name ==
"coshf";
1425 return Name ==
"exp" || Name ==
"exp2" || Name ==
"expf" || Name ==
"exp2f";
1427 return Name ==
"fabs" || Name ==
"floor" || Name ==
"fmod" ||
1428 Name ==
"fabsf" || Name ==
"floorf" || Name ==
"fmodf";
1430 return Name ==
"log" || Name ==
"log10" || Name ==
"logf" ||
1433 return Name ==
"pow" || Name ==
"powf";
1435 return Name ==
"round" || Name ==
"roundf";
1437 return Name ==
"sin" || Name ==
"sinh" || Name ==
"sqrt" ||
1438 Name ==
"sinf" || Name ==
"sinhf" || Name ==
"sqrtf";
1440 return Name ==
"tan" || Name ==
"tanh" || Name ==
"tanf" || Name ==
"tanhf";
1461 inline void llvm_fenv_clearexcept() {
1462 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
1463 feclearexcept(FE_ALL_EXCEPT);
1469 inline bool llvm_fenv_testexcept() {
1470 int errno_val = errno;
1471 if (errno_val == ERANGE || errno_val == EDOM)
1473 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
1474 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
1480 Constant *ConstantFoldFP(
double (*NativeFP)(
double),
double V,
Type *Ty) {
1481 llvm_fenv_clearexcept();
1483 if (llvm_fenv_testexcept()) {
1484 llvm_fenv_clearexcept();
1488 return GetConstantFoldFPValue(V, Ty);
1491 Constant *ConstantFoldBinaryFP(
double (*NativeFP)(
double,
double),
double V,
1492 double W,
Type *Ty) {
1493 llvm_fenv_clearexcept();
1495 if (llvm_fenv_testexcept()) {
1496 llvm_fenv_clearexcept();
1500 return GetConstantFoldFPValue(V, Ty);
1510 Constant *ConstantFoldSSEConvertToInt(
const APFloat &Val,
bool roundTowardZero,
1514 assert(ResultWidth <= 64 &&
1515 "Can only constant fold conversions to 64 and 32 bit ints");
1518 bool isExact =
false;
1548 if (Operands.
size() == 1) {
1549 if (isa<UndefValue>(Operands[0])) {
1551 if (IntrinsicID == Intrinsic::cos)
1554 if (
auto *Op = dyn_cast<ConstantFP>(Operands[0])) {
1555 if (IntrinsicID == Intrinsic::convert_to_fp16) {
1573 if (IntrinsicID == Intrinsic::floor) {
1579 if (IntrinsicID == Intrinsic::ceil) {
1585 if (IntrinsicID == Intrinsic::trunc) {
1591 if (IntrinsicID == Intrinsic::rint) {
1597 if (IntrinsicID == Intrinsic::nearbyint) {
1613 double V = getValueAsDouble(Op);
1615 switch (IntrinsicID) {
1617 case Intrinsic::fabs:
1618 return ConstantFoldFP(fabs, V, Ty);
1619 case Intrinsic::log2:
1620 return ConstantFoldFP(
Log2, V, Ty);
1621 case Intrinsic::log:
1622 return ConstantFoldFP(log, V, Ty);
1623 case Intrinsic::log10:
1624 return ConstantFoldFP(log10, V, Ty);
1625 case Intrinsic::exp:
1626 return ConstantFoldFP(exp, V, Ty);
1627 case Intrinsic::exp2:
1628 return ConstantFoldFP(exp2, V, Ty);
1629 case Intrinsic::sin:
1630 return ConstantFoldFP(sin, V, Ty);
1631 case Intrinsic::cos:
1632 return ConstantFoldFP(cos, V, Ty);
1640 if ((Name ==
"acos" && TLI->
has(LibFunc::acos)) ||
1641 (Name ==
"acosf" && TLI->
has(LibFunc::acosf)))
1642 return ConstantFoldFP(acos, V, Ty);
1643 else if ((Name ==
"asin" && TLI->
has(LibFunc::asin)) ||
1644 (Name ==
"asinf" && TLI->
has(LibFunc::asinf)))
1645 return ConstantFoldFP(asin, V, Ty);
1646 else if ((Name ==
"atan" && TLI->
has(LibFunc::atan)) ||
1647 (Name ==
"atanf" && TLI->
has(LibFunc::atanf)))
1648 return ConstantFoldFP(atan, V, Ty);
1651 if ((Name ==
"ceil" && TLI->
has(LibFunc::ceil)) ||
1652 (Name ==
"ceilf" && TLI->
has(LibFunc::ceilf)))
1653 return ConstantFoldFP(ceil, V, Ty);
1654 else if ((Name ==
"cos" && TLI->
has(LibFunc::cos)) ||
1655 (Name ==
"cosf" && TLI->
has(LibFunc::cosf)))
1656 return ConstantFoldFP(cos, V, Ty);
1657 else if ((Name ==
"cosh" && TLI->
has(LibFunc::cosh)) ||
1658 (Name ==
"coshf" && TLI->
has(LibFunc::coshf)))
1659 return ConstantFoldFP(cosh, V, Ty);
1662 if ((Name ==
"exp" && TLI->
has(LibFunc::exp)) ||
1663 (Name ==
"expf" && TLI->
has(LibFunc::expf)))
1664 return ConstantFoldFP(exp, V, Ty);
1665 if ((Name ==
"exp2" && TLI->
has(LibFunc::exp2)) ||
1666 (Name ==
"exp2f" && TLI->
has(LibFunc::exp2f)))
1669 return ConstantFoldBinaryFP(pow, 2.0, V, Ty);
1672 if ((Name ==
"fabs" && TLI->
has(LibFunc::fabs)) ||
1673 (Name ==
"fabsf" && TLI->
has(LibFunc::fabsf)))
1674 return ConstantFoldFP(fabs, V, Ty);
1675 else if ((Name ==
"floor" && TLI->
has(LibFunc::floor)) ||
1676 (Name ==
"floorf" && TLI->
has(LibFunc::floorf)))
1677 return ConstantFoldFP(floor, V, Ty);
1680 if ((Name ==
"log" && V > 0 && TLI->
has(LibFunc::log)) ||
1681 (Name ==
"logf" && V > 0 && TLI->
has(LibFunc::logf)))
1682 return ConstantFoldFP(log, V, Ty);
1683 else if ((Name ==
"log10" && V > 0 && TLI->
has(LibFunc::log10)) ||
1684 (Name ==
"log10f" && V > 0 && TLI->
has(LibFunc::log10f)))
1685 return ConstantFoldFP(log10, V, Ty);
1686 else if (IntrinsicID == Intrinsic::sqrt &&
1689 return ConstantFoldFP(sqrt, V, Ty);
1702 (Name ==
"roundf" && TLI->
has(LibFunc::roundf)))
1703 return ConstantFoldFP(
round, V, Ty);
1705 if ((Name ==
"sin" && TLI->
has(LibFunc::sin)) ||
1706 (Name ==
"sinf" && TLI->
has(LibFunc::sinf)))
1707 return ConstantFoldFP(sin, V, Ty);
1708 else if ((Name ==
"sinh" && TLI->
has(LibFunc::sinh)) ||
1709 (Name ==
"sinhf" && TLI->
has(LibFunc::sinhf)))
1710 return ConstantFoldFP(sinh, V, Ty);
1711 else if ((Name ==
"sqrt" && V >= 0 && TLI->
has(LibFunc::sqrt)) ||
1712 (Name ==
"sqrtf" && V >= 0 && TLI->
has(LibFunc::sqrtf)))
1713 return ConstantFoldFP(sqrt, V, Ty);
1716 if ((Name ==
"tan" && TLI->
has(LibFunc::tan)) ||
1717 (Name ==
"tanf" && TLI->
has(LibFunc::tanf)))
1718 return ConstantFoldFP(tan, V, Ty);
1719 else if ((Name ==
"tanh" && TLI->
has(LibFunc::tanh)) ||
1720 (Name ==
"tanhf" && TLI->
has(LibFunc::tanhf)))
1721 return ConstantFoldFP(tanh, V, Ty);
1729 if (
auto *Op = dyn_cast<ConstantInt>(Operands[0])) {
1730 switch (IntrinsicID) {
1731 case Intrinsic::bswap:
1733 case Intrinsic::ctpop:
1735 case Intrinsic::bitreverse:
1737 case Intrinsic::convert_from_fp16: {
1747 "Precision lost during fp16 constfolding");
1757 if (isa<ConstantVector>(Operands[0]) ||
1758 isa<ConstantDataVector>(Operands[0])) {
1759 auto *Op = cast<Constant>(Operands[0]);
1760 switch (IntrinsicID) {
1762 case Intrinsic::x86_sse_cvtss2si:
1763 case Intrinsic::x86_sse_cvtss2si64:
1764 case Intrinsic::x86_sse2_cvtsd2si:
1765 case Intrinsic::x86_sse2_cvtsd2si64:
1768 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1770 case Intrinsic::x86_sse_cvttss2si:
1771 case Intrinsic::x86_sse_cvttss2si64:
1772 case Intrinsic::x86_sse2_cvttsd2si:
1773 case Intrinsic::x86_sse2_cvttsd2si64:
1776 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1781 if (isa<UndefValue>(Operands[0])) {
1782 if (IntrinsicID == Intrinsic::bswap)
1790 if (Operands.
size() == 2) {
1791 if (
auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1794 double Op1V = getValueAsDouble(Op1);
1796 if (
auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1797 if (Op2->getType() != Op1->
getType())
1800 double Op2V = getValueAsDouble(Op2);
1801 if (IntrinsicID == Intrinsic::pow) {
1802 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1804 if (IntrinsicID == Intrinsic::copysign) {
1805 APFloat V1 = Op1->getValueAPF();
1812 const APFloat &C1 = Op1->getValueAPF();
1813 const APFloat &C2 = Op2->getValueAPF();
1818 const APFloat &C1 = Op1->getValueAPF();
1819 const APFloat &C2 = Op2->getValueAPF();
1825 if ((Name ==
"pow" && TLI->
has(LibFunc::pow)) ||
1826 (Name ==
"powf" && TLI->
has(LibFunc::powf)))
1827 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1828 if ((Name ==
"fmod" && TLI->
has(LibFunc::fmod)) ||
1829 (Name ==
"fmodf" && TLI->
has(LibFunc::fmodf)))
1830 return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty);
1831 if ((Name ==
"atan2" && TLI->
has(LibFunc::atan2)) ||
1832 (Name ==
"atan2f" && TLI->
has(LibFunc::atan2f)))
1833 return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
1834 }
else if (
auto *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
1835 if (IntrinsicID == Intrinsic::powi && Ty->
isHalfTy())
1837 APFloat((
float)std::pow((
float)Op1V,
1838 (
int)Op2C->getZExtValue())));
1839 if (IntrinsicID == Intrinsic::powi && Ty->
isFloatTy())
1841 APFloat((
float)std::pow((
float)Op1V,
1842 (
int)Op2C->getZExtValue())));
1843 if (IntrinsicID == Intrinsic::powi && Ty->
isDoubleTy())
1845 APFloat((
double)std::pow((
double)Op1V,
1846 (
int)Op2C->getZExtValue())));
1851 if (
auto *Op1 = dyn_cast<ConstantInt>(Operands[0])) {
1852 if (
auto *Op2 = dyn_cast<ConstantInt>(Operands[1])) {
1853 switch (IntrinsicID) {
1855 case Intrinsic::sadd_with_overflow:
1856 case Intrinsic::uadd_with_overflow:
1857 case Intrinsic::ssub_with_overflow:
1858 case Intrinsic::usub_with_overflow:
1859 case Intrinsic::smul_with_overflow:
1860 case Intrinsic::umul_with_overflow: {
1863 switch (IntrinsicID) {
1865 case Intrinsic::sadd_with_overflow:
1866 Res = Op1->getValue().sadd_ov(Op2->getValue(), Overflow);
1868 case Intrinsic::uadd_with_overflow:
1869 Res = Op1->getValue().uadd_ov(Op2->getValue(), Overflow);
1871 case Intrinsic::ssub_with_overflow:
1872 Res = Op1->getValue().ssub_ov(Op2->getValue(), Overflow);
1874 case Intrinsic::usub_with_overflow:
1875 Res = Op1->getValue().usub_ov(Op2->getValue(), Overflow);
1877 case Intrinsic::smul_with_overflow:
1878 Res = Op1->getValue().smul_ov(Op2->getValue(), Overflow);
1880 case Intrinsic::umul_with_overflow:
1881 Res = Op1->getValue().umul_ov(Op2->getValue(), Overflow);
1890 case Intrinsic::cttz:
1891 if (Op2->isOne() && Op1->isZero())
1894 case Intrinsic::ctlz:
1895 if (Op2->isOne() && Op1->isZero())
1906 if (Operands.
size() != 3)
1909 if (
const auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1910 if (
const auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1911 if (
const auto *Op3 = dyn_cast<ConstantFP>(Operands[2])) {
1912 switch (IntrinsicID) {
1914 case Intrinsic::fma:
1915 case Intrinsic::fmuladd: {
1916 APFloat V = Op1->getValueAPF();
1941 if (IntrinsicID == Intrinsic::masked_load) {
1942 auto *SrcPtr = Operands[0];
1943 auto *
Mask = Operands[2];
1944 auto *Passthru = Operands[3];
1950 auto *MaskElt =
Mask->getAggregateElement(
I);
1953 auto *PassthruElt = Passthru->getAggregateElement(
I);
1955 if (isa<UndefValue>(MaskElt)) {
1963 if (MaskElt->isNullValue()) {
1967 }
else if (MaskElt->isOneValue()) {
1982 for (
unsigned J = 0, JE = Operands.
size(); J != JE; ++J) {
1983 Constant *Agg = Operands[J]->getAggregateElement(
I);
1991 Constant *Folded = ConstantFoldScalarCall(Name, IntrinsicID, Ty, Lane, TLI);
2011 if (
auto *VTy = dyn_cast<VectorType>(Ty))
2012 return ConstantFoldVectorCall(Name, F->
getIntrinsicID(), VTy, Operands,
2015 return ConstantFoldScalarCall(Name, F->
getIntrinsicID(), Ty, Operands, TLI);
2036 case LibFunc::log2l:
2038 case LibFunc::log2f:
2039 case LibFunc::log10l:
2040 case LibFunc::log10:
2041 case LibFunc::log10f:
2048 if (OpC->getType()->isDoubleTy())
2051 if (OpC->getType()->isFloatTy())
2056 case LibFunc::exp2l:
2058 case LibFunc::exp2f:
2060 if (OpC->getType()->isDoubleTy())
2063 if (OpC->getType()->isFloatTy())
2078 case LibFunc::tanf: {
2081 Type *Ty = OpC->getType();
2083 double OpV = getValueAsDouble(OpC);
2084 return ConstantFoldFP(tan, OpV, Ty) !=
nullptr;
2089 case LibFunc::asinl:
2091 case LibFunc::asinf:
2092 case LibFunc::acosl:
2094 case LibFunc::acosf:
2102 case LibFunc::sinhf:
2103 case LibFunc::coshf:
2104 case LibFunc::sinhl:
2105 case LibFunc::coshl:
2107 if (OpC->getType()->isDoubleTy())
2110 if (OpC->getType()->isFloatTy())
2115 case LibFunc::sqrtl:
2117 case LibFunc::sqrtf:
2133 const APFloat &Op1 = Op1C->getValueAPF();
2138 case LibFunc::powf: {
2143 if (Ty == Op1C->getType()) {
2144 double Op0V = getValueAsDouble(Op0C);
2145 double Op1V = getValueAsDouble(Op1C);
2146 return ConstantFoldBinaryFP(pow, Op0V, Op1V, Ty) !=
nullptr;
2152 case LibFunc::fmodl:
2154 case LibFunc::fmodf:
Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
opStatus roundToIntegral(roundingMode RM)
static Constant * FoldBitCast(Constant *V, Type *DestTy)
void computeKnownBits(const Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
Type * getSourceElementType() const
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static IntegerType * getInt1Ty(LLVMContext &C)
uint64_t getZExtValue() const
Get zero extended value.
bool isNonIntegralPointerType(PointerType *PT) const
Constant * ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE)
ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a getelementptr constantexpr, return the constant value being addressed by the constant expression, or null if something is funny and we can't decide.
bool canConstantFoldCallTo(const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
float convertToFloat() const
Type * getSequentialElementType() const
unsigned getNumOperands() const
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static uint64_t round(uint64_t Acc, uint64_t Input)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL)
If this constant is a constant offset from a global, return the global and the constant.
opt Optimize addressing mode
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Type * getReturnType() const
Returns the type of the ret val.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static IntegerType * getInt16Ty(LLVMContext &C)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Type * getPointerElementType() const
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
bool isNegative() const
Determine sign of this APInt.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool has(LibFunc::Func F) const
Tests whether a library function is available.
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
A Use represents the edge between a Value definition and its users.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static Constant * get(ArrayRef< Constant * > V)
APInt bitcastToAPInt() const
Windows NT (Windows on ARM)
Type * getVectorElementType() const
This file implements a class to represent arbitrary precision integral constant values and operations...
LLVM_NODISCARD bool empty() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A constant value that is initialized with an expression using other constant values.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool isMathLibCallNoop(CallSite CS, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
bool isLittleEndian() const
Layout endianness...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Type * getElementType() const
size_t size() const
size - Get the array size.
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
uint64_t getElementOffset(unsigned Idx) const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Type * getResultElementType() const
Optional< unsigned > getInRangeIndex() const
Returns the offset of the index with an inrange attachment, or None if none.
bool getLibFunc(StringRef funcName, LibFunc::Func &F) const
Searches for a particular function name.
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Constant * stripPointerCasts()
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
int64_t getSExtValue() const
Get sign extended value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
ConstantFP - Floating Point Values [float, double].
static const fltSemantics & IEEEhalf()
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
APInt sdiv_ov(const APInt &RHS, bool &Overflow) const
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
unsigned getIntegerBitWidth() const
Class to represent integer types.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
opStatus convertToInteger(integerPart *Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCompareInstOperands - Attempt to constant fold a compare instruction (icmp/fcmp) with the...
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void copySign(const APFloat &RHS)
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
const T & back() const
back - Get the last element.
bool isCompare() const
Return true if this is a compare constant expression.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is the shared class of boolean and integer constants.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
double Log2(double Value)
Log2 - This function returns the log base 2 of the specified value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
const fltSemantics & getFltSemantics() const
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
unsigned getNumArgOperands() const
Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
double convertToDouble() const
static const fltSemantics & IEEEdouble()
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isStructTy() const
True if this is an instance of StructType.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
opStatus
IEEE-754R 7: Default exception handling.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isAggregateType() const
Return true if the type is an aggregate type.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getOr(Constant *C1, Constant *C2)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
iterator find(const KeyT &Val)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const APFloat & getValueAPF() const
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
iterator_range< const unsigned char * > bytes() const
Constant * ConstantFoldInstOperands(Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
ValTy * getArgOperand(unsigned i) const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
cmpResult compare(const APFloat &RHS) const
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
Constant * ConstantFoldLoadThroughGEPIndices(Constant *C, ArrayRef< Constant * > Indices)
ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr indices (with an implied zero ...
std::error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values...
const fltSemantics & getSemantics() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.