29 #include "llvm/Config/config.h" 69 for (
unsigned i = 0; i != NumSrcElts; ++i) {
76 if (Element && isa<UndefValue>(Element)) {
81 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
103 if (
auto *VTy = dyn_cast<VectorType>(C->
getType())) {
106 unsigned NumSrcElts = VTy->getNumElements();
107 Type *SrcEltTy = VTy->getElementType();
120 if (
Constant *CE = foldConstVectorToAPInt(Result, DestTy, C,
121 SrcEltTy, NumSrcElts, DL))
124 if (isa<IntegerType>(DestTy))
139 if (isa<ConstantFP>(C) || isa<ConstantInt>(C)) {
145 if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
149 unsigned NumDstElt = DestVTy->getNumElements();
151 if (NumDstElt == NumSrcElt)
155 Type *DstEltTy = DestVTy->getElementType();
188 if (!isa<ConstantVector>(C) &&
189 !isa<ConstantDataVector>(C))
200 if (NumDstElt < NumSrcElt) {
203 unsigned Ratio = NumSrcElt/NumDstElt;
206 for (
unsigned i = 0; i != NumDstElt; ++i) {
209 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
210 for (
unsigned j = 0; j != Ratio; ++j) {
212 if (Src && isa<UndefValue>(Src))
215 Src = dyn_cast_or_null<ConstantInt>(Src);
225 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
236 unsigned Ratio = NumDstElt/NumSrcElt;
240 for (
unsigned i = 0; i != NumSrcElt; ++i) {
246 if (isa<UndefValue>(Element)) {
256 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize*(Ratio-1);
257 for (
unsigned j = 0; j != Ratio; ++j) {
262 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
288 if ((GV = dyn_cast<GlobalValue>(C))) {
290 Offset =
APInt(BitWidth, 0);
296 if (!CE)
return false;
299 if (CE->getOpcode() == Instruction::PtrToInt ||
300 CE->getOpcode() == Instruction::BitCast)
309 APInt TmpOffset(BitWidth, 0);
316 if (!
GEP->accumulateConstantOffset(DL, TmpOffset))
335 Cast = Instruction::IntToPtr;
337 Cast = Instruction::PtrToInt;
364 bool ReadDataFromGlobal(
Constant *C, uint64_t ByteOffset,
unsigned char *CurPtr,
367 "Out of range access");
371 if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
374 if (
auto *CI = dyn_cast<ConstantInt>(C)) {
375 if (CI->getBitWidth() > 64 ||
376 (CI->getBitWidth() & 7) != 0)
379 uint64_t Val = CI->getZExtValue();
380 unsigned IntBytes =
unsigned(CI->getBitWidth()/8);
382 for (
unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
385 n = IntBytes - n - 1;
386 CurPtr[i] = (
unsigned char)(Val >> (n * 8));
392 if (
auto *CFP = dyn_cast<ConstantFP>(C)) {
393 if (CFP->getType()->isDoubleTy()) {
395 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
397 if (CFP->getType()->isFloatTy()){
399 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
401 if (CFP->getType()->isHalfTy()){
403 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
408 if (
auto *CS = dyn_cast<ConstantStruct>(C)) {
412 ByteOffset -= CurEltOffset;
419 if (ByteOffset < EltSize &&
420 !ReadDataFromGlobal(CS->getOperand(Index), ByteOffset, CurPtr,
427 if (Index == CS->getType()->getNumElements())
433 if (BytesLeft <= NextEltOffset - CurEltOffset - ByteOffset)
437 CurPtr += NextEltOffset - CurEltOffset - ByteOffset;
438 BytesLeft -= NextEltOffset - CurEltOffset - ByteOffset;
440 CurEltOffset = NextEltOffset;
445 if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
446 isa<ConstantDataSequential>(C)) {
449 uint64_t
Index = ByteOffset / EltSize;
450 uint64_t
Offset = ByteOffset - Index * EltSize;
452 if (
auto *AT = dyn_cast<ArrayType>(C->
getType()))
453 NumElts = AT->getNumElements();
457 for (; Index != NumElts; ++
Index) {
462 uint64_t BytesWritten = EltSize -
Offset;
463 assert(BytesWritten <= EltSize &&
"Not indexing into this element?");
464 if (BytesWritten >= BytesLeft)
468 BytesLeft -= BytesWritten;
469 CurPtr += BytesWritten;
474 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
475 if (CE->getOpcode() == Instruction::IntToPtr &&
476 CE->getOperand(0)->getType() == DL.
getIntPtrType(CE->getType())) {
477 return ReadDataFromGlobal(CE->getOperand(0), ByteOffset, CurPtr,
488 auto *PTy = cast<PointerType>(C->
getType());
493 unsigned AS = PTy->getAddressSpace();
513 if (
Constant *Res = FoldReinterpretLoadFromConstPtr(C, MapTy, DL))
518 unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
519 if (BytesLoaded > 32 || BytesLoaded == 0)
528 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
529 !GV->getInitializer()->getType()->isSized())
533 int64_t InitializerSize = DL.
getTypeAllocSize(GV->getInitializer()->getType());
536 if (Offset + BytesLoaded <= 0)
540 if (Offset >= InitializerSize)
543 unsigned char RawBytes[32] = {0};
544 unsigned char *CurPtr = RawBytes;
545 unsigned BytesLeft = BytesLoaded;
554 if (!ReadDataFromGlobal(GV->getInitializer(),
Offset, CurPtr, BytesLeft, DL))
557 APInt ResultVal =
APInt(IntType->getBitWidth(), 0);
559 ResultVal = RawBytes[BytesLoaded - 1];
560 for (
unsigned i = 1; i != BytesLoaded; ++i) {
562 ResultVal |= RawBytes[BytesLoaded - 1 - i];
565 ResultVal = RawBytes[0];
566 for (
unsigned i = 1; i != BytesLoaded; ++i) {
568 ResultVal |= RawBytes[i];
595 if (
auto *GV = dyn_cast<GlobalVariable>(C))
596 if (GV->isConstant() && GV->hasDefinitiveInitializer())
597 return GV->getInitializer();
599 if (
auto *GA = dyn_cast<GlobalAlias>(C))
600 if (GA->getAliasee() && !GA->isInterposable())
608 if (CE->getOpcode() == Instruction::GetElementPtr) {
609 if (
auto *GV = dyn_cast<GlobalVariable>(CE->getOperand(0))) {
610 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
618 if (CE->getOpcode() == Instruction::BitCast)
619 if (
Constant *LoadedC = ConstantFoldLoadThroughBitcastExpr(CE, Ty, DL))
626 size_t StrLen = Str.
size();
630 if ((NumBits >> 3) == StrLen + 1 && (NumBits & 7) == 0 &&
633 APInt SingleChar(NumBits, 0);
636 SingleChar =
static_cast<uint64_t
>(
C);
637 StrVal = (StrVal << 8) | SingleChar;
640 for (
unsigned char C : Str.
bytes()) {
641 SingleChar =
static_cast<uint64_t
>(
C);
642 StrVal = (StrVal << 8) | SingleChar;
646 StrVal = (StrVal << 8) | SingleChar;
659 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
660 if (GV->getInitializer()->isNullValue())
662 if (isa<UndefValue>(GV->getInitializer()))
668 return FoldReinterpretLoadFromConstPtr(CE, Ty, DL);
676 if (
auto *C = dyn_cast<Constant>(LI->
getOperand(0)))
694 if (Opc == Instruction::And) {
697 if ((Known1.
One | Known0.
Zero).isAllOnesValue()) {
701 if ((Known0.
One | Known1.
Zero).isAllOnesValue()) {
714 if (Opc == Instruction::Sub) {
743 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i) {
746 SrcElemTy, Ops.
slice(1, i - 1)))) &&
747 Ops[i]->
getType()->getScalarType() != IntPtrScalarTy) {
749 Type *NewType = Ops[i]->getType()->isVectorTy()
765 SrcElemTy, Ops[0], NewIdxs,
false, InRangeIndex);
775 auto *OldPtrTy = cast<PointerType>(Ptr->
getType());
777 auto *NewPtrTy = cast<PointerType>(Ptr->getType());
782 if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
783 NewPtrTy = ElemTy->
getPointerTo(OldPtrTy->getAddressSpace());
803 if (
Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
815 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i)
816 if (!isa<ConstantInt>(Ops[i])) {
822 assert((!CE || CE->getType() == IntPtrTy) &&
823 "CastGEPIndices didn't canonicalize index types!");
824 if (CE && CE->getOpcode() == Instruction::Sub &&
825 CE->getOperand(0)->isNullValue()) {
843 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
846 while (
auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
853 bool AllConstantInt =
true;
854 for (
Value *NestedOp : NestedOps)
855 if (!isa<ConstantInt>(NestedOp)) {
856 AllConstantInt =
false;
865 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
870 APInt BasePtr(BitWidth, 0);
871 if (
auto *CE = dyn_cast<ConstantExpr>(Ptr)) {
872 if (CE->getOpcode() == Instruction::IntToPtr) {
873 if (
auto *
Base = dyn_cast<ConstantInt>(CE->getOperand(0)))
874 BasePtr =
Base->getValue().zextOrTrunc(BitWidth);
878 auto *PTy = cast<PointerType>(Ptr->getType());
896 if (!NewIdxs.
empty())
904 }
else if (
auto *ATy = dyn_cast<SequentialType>(Ty)) {
905 Ty = ATy->getElementType();
925 Offset -= NewIdx * ElemSize;
929 auto *STy = cast<StructType>(Ty);
944 Offset -=
APInt(BitWidth, SL.getElementOffset(ElIdx));
945 Ty = STy->getTypeAtIndex(ElIdx);
947 }
while (Ty != ResElemTy);
960 NewIdxs.
size() > *LastIRIndex) {
961 InRangeIndex = LastIRIndex;
962 for (
unsigned I = 0;
I <= *LastIRIndex; ++
I)
971 InBounds, InRangeIndex);
973 "Computed GetElementPtr has unexpected type!");
993 Constant *ConstantFoldInstOperandsImpl(
const Value *InstOrCE,
unsigned Opcode,
1006 if (
auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
1007 if (
Constant *C = SymbolicallyEvaluateGEP(GEP, Ops, DL, TLI))
1015 if (
auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
1016 return CE->getWithOperands(Ops);
1019 default:
return nullptr;
1020 case Instruction::ICmp:
1023 if (
auto *
F = dyn_cast<Function>(Ops.
back())) {
1031 case Instruction::ExtractElement:
1033 case Instruction::InsertElement:
1035 case Instruction::ShuffleVector:
1052 if (!isa<ConstantVector>(C) && !isa<ConstantExpr>(C))
1057 auto *NewC = cast<Constant>(&NewU);
1060 if (isa<ConstantVector>(NewC) || isa<ConstantExpr>(NewC)) {
1061 auto It = FoldedOps.
find(NewC);
1062 if (It == FoldedOps.
end()) {
1064 ConstantFoldConstantImpl(NewC, DL, TLI, FoldedOps)) {
1065 FoldedOps.
insert({NewC, FoldedC});
1068 FoldedOps.
insert({NewC, NewC});
1077 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1078 if (CE->isCompare())
1082 return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI);
1085 assert(isa<ConstantVector>(C));
1094 if (
auto *PN = dyn_cast<PHINode>(I)) {
1098 for (
Value *Incoming : PN->incoming_values()) {
1103 if (isa<UndefValue>(Incoming))
1110 if (
auto *FoldedC = ConstantFoldConstantImpl(C, DL, TLI, FoldedOps))
1114 if (CommonValue && C != CommonValue)
1131 auto *
Op = cast<Constant>(&OpU);
1133 if (
auto *FoldedOp = ConstantFoldConstantImpl(
Op, DL, TLI, FoldedOps))
1139 if (
const auto *CI = dyn_cast<CmpInst>(I))
1143 if (
const auto *LI = dyn_cast<LoadInst>(I))
1144 return ConstantFoldLoadInst(LI, DL);
1146 if (
auto *IVI = dyn_cast<InsertValueInst>(I)) {
1148 cast<Constant>(IVI->getAggregateOperand()),
1149 cast<Constant>(IVI->getInsertedValueOperand()),
1153 if (
auto *EVI = dyn_cast<ExtractValueInst>(I)) {
1155 cast<Constant>(EVI->getAggregateOperand()),
1165 return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
1172 return ConstantFoldInstOperandsImpl(I, I->
getOpcode(), Ops, DL, TLI);
1189 if (
auto *CE0 = dyn_cast<ConstantExpr>(Ops0)) {
1191 if (CE0->getOpcode() == Instruction::IntToPtr) {
1203 if (CE0->getOpcode() == Instruction::PtrToInt) {
1205 if (CE0->getType() == IntPtrTy) {
1213 if (
auto *CE1 = dyn_cast<ConstantExpr>(Ops1)) {
1214 if (CE0->getOpcode() == CE1->getOpcode()) {
1215 if (CE0->getOpcode() == Instruction::IntToPtr) {
1229 if (CE0->getOpcode() == Instruction::PtrToInt) {
1231 if (CE0->getType() == IntPtrTy &&
1232 CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) {
1234 Predicate, CE0->getOperand(0), CE1->getOperand(0), DL, TLI);
1243 CE0->getOpcode() == Instruction::Or && Ops1->
isNullValue()) {
1245 Predicate, CE0->getOperand(0), Ops1, DL, TLI);
1247 Predicate, CE0->getOperand(1), Ops1, DL, TLI);
1252 }
else if (isa<ConstantExpr>(Ops1)) {
1266 if (isa<ConstantExpr>(LHS) || isa<ConstantExpr>(RHS))
1267 if (
Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL))
1279 case Instruction::PtrToInt:
1282 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1283 if (CE->getOpcode() == Instruction::IntToPtr) {
1284 Constant *Input = CE->getOperand(0);
1287 if (PtrWidth < InWidth) {
1298 case Instruction::IntToPtr:
1303 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1304 if (CE->getOpcode() == Instruction::PtrToInt) {
1305 Constant *SrcPtr = CE->getOperand(0);
1307 unsigned MidIntSize = CE->getType()->getScalarSizeInBits();
1309 if (MidIntSize >= SrcPtrSize) {
1312 return FoldBitCast(CE->getOperand(0), DestTy, DL);
1318 case Instruction::Trunc:
1319 case Instruction::ZExt:
1320 case Instruction::SExt:
1321 case Instruction::FPTrunc:
1322 case Instruction::FPExt:
1323 case Instruction::UIToFP:
1324 case Instruction::SIToFP:
1325 case Instruction::FPToUI:
1326 case Instruction::FPToSI:
1327 case Instruction::AddrSpaceCast:
1329 case Instruction::BitCast:
1370 case Intrinsic::fabs:
1373 case Intrinsic::log:
1375 case Intrinsic::log10:
1376 case Intrinsic::exp:
1377 case Intrinsic::exp2:
1378 case Intrinsic::floor:
1379 case Intrinsic::ceil:
1380 case Intrinsic::sqrt:
1381 case Intrinsic::sin:
1382 case Intrinsic::cos:
1383 case Intrinsic::trunc:
1384 case Intrinsic::rint:
1385 case Intrinsic::nearbyint:
1386 case Intrinsic::pow:
1387 case Intrinsic::powi:
1388 case Intrinsic::bswap:
1389 case Intrinsic::ctpop:
1390 case Intrinsic::ctlz:
1391 case Intrinsic::cttz:
1392 case Intrinsic::fma:
1393 case Intrinsic::fmuladd:
1394 case Intrinsic::copysign:
1395 case Intrinsic::launder_invariant_group:
1396 case Intrinsic::strip_invariant_group:
1398 case Intrinsic::masked_load:
1399 case Intrinsic::sadd_with_overflow:
1400 case Intrinsic::uadd_with_overflow:
1401 case Intrinsic::ssub_with_overflow:
1402 case Intrinsic::usub_with_overflow:
1403 case Intrinsic::smul_with_overflow:
1404 case Intrinsic::umul_with_overflow:
1405 case Intrinsic::convert_from_fp16:
1406 case Intrinsic::convert_to_fp16:
1407 case Intrinsic::bitreverse:
1408 case Intrinsic::x86_sse_cvtss2si:
1409 case Intrinsic::x86_sse_cvtss2si64:
1410 case Intrinsic::x86_sse_cvttss2si:
1411 case Intrinsic::x86_sse_cvttss2si64:
1412 case Intrinsic::x86_sse2_cvtsd2si:
1413 case Intrinsic::x86_sse2_cvtsd2si64:
1414 case Intrinsic::x86_sse2_cvttsd2si:
1415 case Intrinsic::x86_sse2_cvttsd2si64:
1433 return Name ==
"acos" || Name ==
"asin" || Name ==
"atan" ||
1434 Name ==
"atan2" || Name ==
"acosf" || Name ==
"asinf" ||
1435 Name ==
"atanf" || Name ==
"atan2f";
1437 return Name ==
"ceil" || Name ==
"cos" || Name ==
"cosh" ||
1438 Name ==
"ceilf" || Name ==
"cosf" || Name ==
"coshf";
1440 return Name ==
"exp" || Name ==
"exp2" || Name ==
"expf" || Name ==
"exp2f";
1442 return Name ==
"fabs" || Name ==
"floor" || Name ==
"fmod" ||
1443 Name ==
"fabsf" || Name ==
"floorf" || Name ==
"fmodf";
1445 return Name ==
"log" || Name ==
"log10" || Name ==
"logf" ||
1448 return Name ==
"pow" || Name ==
"powf";
1450 return Name ==
"round" || Name ==
"roundf";
1452 return Name ==
"sin" || Name ==
"sinh" || Name ==
"sqrt" ||
1453 Name ==
"sinf" || Name ==
"sinhf" || Name ==
"sqrtf";
1455 return Name ==
"tan" || Name ==
"tanh" || Name ==
"tanf" || Name ==
"tanhf";
1464 if (Name.
size() < 12 || Name[1] !=
'_')
1470 return Name ==
"__acos_finite" || Name ==
"__acosf_finite" ||
1471 Name ==
"__asin_finite" || Name ==
"__asinf_finite" ||
1472 Name ==
"__atan2_finite" || Name ==
"__atan2f_finite";
1474 return Name ==
"__cosh_finite" || Name ==
"__coshf_finite";
1476 return Name ==
"__exp_finite" || Name ==
"__expf_finite" ||
1477 Name ==
"__exp2_finite" || Name ==
"__exp2f_finite";
1479 return Name ==
"__log_finite" || Name ==
"__logf_finite" ||
1480 Name ==
"__log10_finite" || Name ==
"__log10f_finite";
1482 return Name ==
"__pow_finite" || Name ==
"__powf_finite";
1484 return Name ==
"__sinh_finite" || Name ==
"__sinhf_finite";
1506 inline void llvm_fenv_clearexcept() {
1507 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT 1508 feclearexcept(FE_ALL_EXCEPT);
1514 inline bool llvm_fenv_testexcept() {
1515 int errno_val = errno;
1516 if (errno_val == ERANGE || errno_val == EDOM)
1518 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT 1519 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
1525 Constant *ConstantFoldFP(
double (*NativeFP)(
double),
double V,
Type *Ty) {
1526 llvm_fenv_clearexcept();
1528 if (llvm_fenv_testexcept()) {
1529 llvm_fenv_clearexcept();
1533 return GetConstantFoldFPValue(V, Ty);
1536 Constant *ConstantFoldBinaryFP(
double (*NativeFP)(
double,
double),
double V,
1537 double W,
Type *Ty) {
1538 llvm_fenv_clearexcept();
1540 if (llvm_fenv_testexcept()) {
1541 llvm_fenv_clearexcept();
1545 return GetConstantFoldFPValue(V, Ty);
1555 Constant *ConstantFoldSSEConvertToInt(
const APFloat &Val,
bool roundTowardZero,
1559 assert(ResultWidth <= 64 &&
1560 "Can only constant fold conversions to 64 and 32 bit ints");
1563 bool isExact =
false;
1568 true, mode, &isExact);
1594 if (Operands.
size() == 1) {
1595 if (isa<UndefValue>(Operands[0])) {
1597 if (IntrinsicID == Intrinsic::cos)
1599 if (IntrinsicID == Intrinsic::bswap ||
1600 IntrinsicID == Intrinsic::bitreverse ||
1601 IntrinsicID == Intrinsic::launder_invariant_group ||
1602 IntrinsicID == Intrinsic::strip_invariant_group)
1606 if (isa<ConstantPointerNull>(Operands[0])) {
1608 if (IntrinsicID == Intrinsic::launder_invariant_group ||
1609 IntrinsicID == Intrinsic::strip_invariant_group) {
1616 Caller, Operands[0]->
getType()->getPointerAddressSpace())) {
1623 if (
auto *Op = dyn_cast<ConstantFP>(Operands[0])) {
1624 if (IntrinsicID == Intrinsic::convert_to_fp16) {
1642 if (IntrinsicID == Intrinsic::floor) {
1648 if (IntrinsicID == Intrinsic::ceil) {
1654 if (IntrinsicID == Intrinsic::trunc) {
1660 if (IntrinsicID == Intrinsic::rint) {
1666 if (IntrinsicID == Intrinsic::nearbyint) {
1682 double V = getValueAsDouble(Op);
1684 switch (IntrinsicID) {
1686 case Intrinsic::fabs:
1687 return ConstantFoldFP(fabs, V, Ty);
1689 return ConstantFoldFP(
Log2, V, Ty);
1690 case Intrinsic::log:
1691 return ConstantFoldFP(log, V, Ty);
1692 case Intrinsic::log10:
1693 return ConstantFoldFP(log10, V, Ty);
1694 case Intrinsic::exp:
1695 return ConstantFoldFP(exp, V, Ty);
1696 case Intrinsic::exp2:
1697 return ConstantFoldFP(exp2, V, Ty);
1698 case Intrinsic::sin:
1699 return ConstantFoldFP(sin, V, Ty);
1700 case Intrinsic::cos:
1701 return ConstantFoldFP(cos, V, Ty);
1702 case Intrinsic::sqrt:
1703 return ConstantFoldFP(sqrt, V, Ty);
1709 char NameKeyChar = Name[0];
1710 if (Name[0] ==
'_' && Name.
size() > 2 && Name[1] ==
'_')
1711 NameKeyChar = Name[2];
1713 switch (NameKeyChar) {
1715 if ((Name ==
"acos" && TLI->
has(LibFunc_acos)) ||
1716 (Name ==
"acosf" && TLI->
has(LibFunc_acosf)) ||
1717 (Name ==
"__acos_finite" && TLI->
has(LibFunc_acos_finite)) ||
1718 (Name ==
"__acosf_finite" && TLI->
has(LibFunc_acosf_finite)))
1719 return ConstantFoldFP(acos, V, Ty);
1720 else if ((Name ==
"asin" && TLI->
has(LibFunc_asin)) ||
1721 (Name ==
"asinf" && TLI->
has(LibFunc_asinf)) ||
1722 (Name ==
"__asin_finite" && TLI->
has(LibFunc_asin_finite)) ||
1723 (Name ==
"__asinf_finite" && TLI->
has(LibFunc_asinf_finite)))
1724 return ConstantFoldFP(asin, V, Ty);
1725 else if ((Name ==
"atan" && TLI->
has(LibFunc_atan)) ||
1726 (Name ==
"atanf" && TLI->
has(LibFunc_atanf)))
1727 return ConstantFoldFP(atan, V, Ty);
1730 if ((Name ==
"ceil" && TLI->
has(LibFunc_ceil)) ||
1731 (Name ==
"ceilf" && TLI->
has(LibFunc_ceilf)))
1732 return ConstantFoldFP(ceil, V, Ty);
1733 else if ((Name ==
"cos" && TLI->
has(LibFunc_cos)) ||
1734 (Name ==
"cosf" && TLI->
has(LibFunc_cosf)))
1735 return ConstantFoldFP(cos, V, Ty);
1736 else if ((Name ==
"cosh" && TLI->
has(LibFunc_cosh)) ||
1737 (Name ==
"coshf" && TLI->
has(LibFunc_coshf)) ||
1738 (Name ==
"__cosh_finite" && TLI->
has(LibFunc_cosh_finite)) ||
1739 (Name ==
"__coshf_finite" && TLI->
has(LibFunc_coshf_finite)))
1740 return ConstantFoldFP(cosh, V, Ty);
1743 if ((Name ==
"exp" && TLI->
has(LibFunc_exp)) ||
1744 (Name ==
"expf" && TLI->
has(LibFunc_expf)) ||
1745 (Name ==
"__exp_finite" && TLI->
has(LibFunc_exp_finite)) ||
1746 (Name ==
"__expf_finite" && TLI->
has(LibFunc_expf_finite)))
1747 return ConstantFoldFP(exp, V, Ty);
1748 if ((Name ==
"exp2" && TLI->
has(LibFunc_exp2)) ||
1749 (Name ==
"exp2f" && TLI->
has(LibFunc_exp2f)) ||
1750 (Name ==
"__exp2_finite" && TLI->
has(LibFunc_exp2_finite)) ||
1751 (Name ==
"__exp2f_finite" && TLI->
has(LibFunc_exp2f_finite)))
1754 return ConstantFoldBinaryFP(pow, 2.0, V, Ty);
1757 if ((Name ==
"fabs" && TLI->
has(LibFunc_fabs)) ||
1758 (Name ==
"fabsf" && TLI->
has(LibFunc_fabsf)))
1759 return ConstantFoldFP(fabs, V, Ty);
1760 else if ((Name ==
"floor" && TLI->
has(LibFunc_floor)) ||
1761 (Name ==
"floorf" && TLI->
has(LibFunc_floorf)))
1762 return ConstantFoldFP(floor, V, Ty);
1765 if ((Name ==
"log" && V > 0 && TLI->
has(LibFunc_log)) ||
1766 (Name ==
"logf" && V > 0 && TLI->
has(LibFunc_logf)) ||
1767 (Name ==
"__log_finite" && V > 0 &&
1768 TLI->
has(LibFunc_log_finite)) ||
1769 (Name ==
"__logf_finite" && V > 0 &&
1770 TLI->
has(LibFunc_logf_finite)))
1771 return ConstantFoldFP(log, V, Ty);
1772 else if ((Name ==
"log10" && V > 0 && TLI->
has(LibFunc_log10)) ||
1773 (Name ==
"log10f" && V > 0 && TLI->
has(LibFunc_log10f)) ||
1774 (Name ==
"__log10_finite" && V > 0 &&
1775 TLI->
has(LibFunc_log10_finite)) ||
1776 (Name ==
"__log10f_finite" && V > 0 &&
1777 TLI->
has(LibFunc_log10f_finite)))
1778 return ConstantFoldFP(log10, V, Ty);
1781 if ((Name ==
"round" && TLI->
has(LibFunc_round)) ||
1782 (Name ==
"roundf" && TLI->
has(LibFunc_roundf)))
1783 return ConstantFoldFP(
round, V, Ty);
1786 if ((Name ==
"sin" && TLI->
has(LibFunc_sin)) ||
1787 (Name ==
"sinf" && TLI->
has(LibFunc_sinf)))
1788 return ConstantFoldFP(sin, V, Ty);
1789 else if ((Name ==
"sinh" && TLI->
has(LibFunc_sinh)) ||
1790 (Name ==
"sinhf" && TLI->
has(LibFunc_sinhf)) ||
1791 (Name ==
"__sinh_finite" && TLI->
has(LibFunc_sinh_finite)) ||
1792 (Name ==
"__sinhf_finite" && TLI->
has(LibFunc_sinhf_finite)))
1793 return ConstantFoldFP(sinh, V, Ty);
1794 else if ((Name ==
"sqrt" && V >= 0 && TLI->
has(LibFunc_sqrt)) ||
1795 (Name ==
"sqrtf" && V >= 0 && TLI->
has(LibFunc_sqrtf)))
1796 return ConstantFoldFP(sqrt, V, Ty);
1799 if ((Name ==
"tan" && TLI->
has(LibFunc_tan)) ||
1800 (Name ==
"tanf" && TLI->
has(LibFunc_tanf)))
1801 return ConstantFoldFP(tan, V, Ty);
1802 else if ((Name ==
"tanh" && TLI->
has(LibFunc_tanh)) ||
1803 (Name ==
"tanhf" && TLI->
has(LibFunc_tanhf)))
1804 return ConstantFoldFP(tanh, V, Ty);
1812 if (
auto *Op = dyn_cast<ConstantInt>(Operands[0])) {
1813 switch (IntrinsicID) {
1814 case Intrinsic::bswap:
1816 case Intrinsic::ctpop:
1818 case Intrinsic::bitreverse:
1820 case Intrinsic::convert_from_fp16: {
1830 "Precision lost during fp16 constfolding");
1840 if (isa<ConstantVector>(Operands[0]) ||
1841 isa<ConstantDataVector>(Operands[0])) {
1842 auto *Op = cast<Constant>(Operands[0]);
1843 switch (IntrinsicID) {
1845 case Intrinsic::x86_sse_cvtss2si:
1846 case Intrinsic::x86_sse_cvtss2si64:
1847 case Intrinsic::x86_sse2_cvtsd2si:
1848 case Intrinsic::x86_sse2_cvtsd2si64:
1851 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1854 case Intrinsic::x86_sse_cvttss2si:
1855 case Intrinsic::x86_sse_cvttss2si64:
1856 case Intrinsic::x86_sse2_cvttsd2si:
1857 case Intrinsic::x86_sse2_cvttsd2si64:
1860 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1869 if (Operands.
size() == 2) {
1870 if (
auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1873 double Op1V = getValueAsDouble(Op1);
1875 if (
auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1876 if (Op2->getType() != Op1->getType())
1879 double Op2V = getValueAsDouble(Op2);
1880 if (IntrinsicID == Intrinsic::pow) {
1881 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1883 if (IntrinsicID == Intrinsic::copysign) {
1884 APFloat V1 = Op1->getValueAPF();
1891 const APFloat &C1 = Op1->getValueAPF();
1892 const APFloat &C2 = Op2->getValueAPF();
1897 const APFloat &C1 = Op1->getValueAPF();
1898 const APFloat &C2 = Op2->getValueAPF();
1904 if ((Name ==
"pow" && TLI->
has(LibFunc_pow)) ||
1905 (Name ==
"powf" && TLI->
has(LibFunc_powf)) ||
1906 (Name ==
"__pow_finite" && TLI->
has(LibFunc_pow_finite)) ||
1907 (Name ==
"__powf_finite" && TLI->
has(LibFunc_powf_finite)))
1908 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1909 if ((Name ==
"fmod" && TLI->
has(LibFunc_fmod)) ||
1910 (Name ==
"fmodf" && TLI->
has(LibFunc_fmodf)))
1911 return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty);
1912 if ((Name ==
"atan2" && TLI->
has(LibFunc_atan2)) ||
1913 (Name ==
"atan2f" && TLI->
has(LibFunc_atan2f)) ||
1914 (Name ==
"__atan2_finite" && TLI->
has(LibFunc_atan2_finite)) ||
1915 (Name ==
"__atan2f_finite" && TLI->
has(LibFunc_atan2f_finite)))
1916 return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
1917 }
else if (
auto *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
1918 if (IntrinsicID == Intrinsic::powi && Ty->
isHalfTy())
1920 APFloat((
float)std::pow((
float)Op1V,
1921 (
int)Op2C->getZExtValue())));
1922 if (IntrinsicID == Intrinsic::powi && Ty->
isFloatTy())
1924 APFloat((
float)std::pow((
float)Op1V,
1925 (
int)Op2C->getZExtValue())));
1926 if (IntrinsicID == Intrinsic::powi && Ty->
isDoubleTy())
1928 APFloat((
double)std::pow((
double)Op1V,
1929 (
int)Op2C->getZExtValue())));
1934 if (
auto *Op1 = dyn_cast<ConstantInt>(Operands[0])) {
1935 if (
auto *Op2 = dyn_cast<ConstantInt>(Operands[1])) {
1936 switch (IntrinsicID) {
1938 case Intrinsic::sadd_with_overflow:
1939 case Intrinsic::uadd_with_overflow:
1940 case Intrinsic::ssub_with_overflow:
1941 case Intrinsic::usub_with_overflow:
1942 case Intrinsic::smul_with_overflow:
1943 case Intrinsic::umul_with_overflow: {
1946 switch (IntrinsicID) {
1948 case Intrinsic::sadd_with_overflow:
1949 Res = Op1->getValue().
sadd_ov(Op2->getValue(), Overflow);
1951 case Intrinsic::uadd_with_overflow:
1952 Res = Op1->getValue().
uadd_ov(Op2->getValue(), Overflow);
1954 case Intrinsic::ssub_with_overflow:
1955 Res = Op1->getValue().
ssub_ov(Op2->getValue(), Overflow);
1957 case Intrinsic::usub_with_overflow:
1958 Res = Op1->getValue().
usub_ov(Op2->getValue(), Overflow);
1960 case Intrinsic::smul_with_overflow:
1961 Res = Op1->getValue().
smul_ov(Op2->getValue(), Overflow);
1963 case Intrinsic::umul_with_overflow:
1964 Res = Op1->getValue().
umul_ov(Op2->getValue(), Overflow);
1973 case Intrinsic::cttz:
1974 if (Op2->isOne() && Op1->isZero())
1977 case Intrinsic::ctlz:
1978 if (Op2->isOne() && Op1->isZero())
1989 if (Operands.
size() != 3)
1992 if (
const auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1993 if (
const auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1994 if (
const auto *Op3 = dyn_cast<ConstantFP>(Operands[2])) {
1995 switch (IntrinsicID) {
1997 case Intrinsic::fma:
1998 case Intrinsic::fmuladd: {
1999 APFloat V = Op1->getValueAPF();
2025 if (IntrinsicID == Intrinsic::masked_load) {
2026 auto *SrcPtr = Operands[0];
2027 auto *
Mask = Operands[2];
2028 auto *Passthru = Operands[3];
2034 auto *MaskElt =
Mask->getAggregateElement(
I);
2037 auto *PassthruElt = Passthru->getAggregateElement(
I);
2039 if (isa<UndefValue>(MaskElt)) {
2047 if (MaskElt->isNullValue()) {
2051 }
else if (MaskElt->isOneValue()) {
2066 for (
unsigned J = 0, JE = Operands.
size(); J != JE; ++J) {
2069 (IntrinsicID == Intrinsic::cttz || IntrinsicID == Intrinsic::ctlz ||
2070 IntrinsicID == Intrinsic::powi)) {
2071 Lane[J] = Operands[J];
2075 Constant *Agg = Operands[J]->getAggregateElement(
I);
2083 Constant *Folded = ConstantFoldScalarCall(Name, IntrinsicID, Ty, Lane, TLI, CS);
2106 if (
auto *VTy = dyn_cast<VectorType>(Ty))
2107 return ConstantFoldVectorCall(Name, F->
getIntrinsicID(), VTy, Operands,
2110 return ConstantFoldScalarCall(Name, F->
getIntrinsicID(), Ty, Operands, TLI, CS);
2136 case LibFunc_log10l:
2138 case LibFunc_log10f:
2145 if (OpC->getType()->isDoubleTy())
2148 if (OpC->getType()->isFloatTy())
2157 if (OpC->getType()->isDoubleTy())
2160 if (OpC->getType()->isFloatTy())
2175 case LibFunc_tanf: {
2178 Type *Ty = OpC->getType();
2180 double OpV = getValueAsDouble(OpC);
2181 return ConstantFoldFP(tan, OpV, Ty) !=
nullptr;
2204 if (OpC->getType()->isDoubleTy())
2207 if (OpC->getType()->isFloatTy())
2230 const APFloat &Op1 = Op1C->getValueAPF();
2235 case LibFunc_powf: {
2240 if (Ty == Op1C->getType()) {
2241 double Op0V = getValueAsDouble(Op0C);
2242 double Op1V = getValueAsDouble(Op1C);
2243 return ConstantFoldBinaryFP(pow, Op0V, Op1V, Ty) !=
nullptr;
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)
Type * getVectorElementType() const
static Constant * FoldBitCast(Constant *V, Type *DestTy)
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
static IntegerType * getInt1Ty(LLVMContext &C)
uint64_t getZExtValue() const
Get zero extended value.
const T & back() const
back - Get the last element.
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
Compute iterated dominance frontiers using a linear time algorithm.
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.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Optional< unsigned > getInRangeIndex() const
Returns the offset of the index with an inrange attachment, or None if none.
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 * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
float convertToFloat() const
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
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.
LLVMContext & getContext() const
All values hold a context through their type.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
const fltSemantics & getSemantics() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
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)
bool isVectorTy() const
True if this is an instance of VectorType.
static IntegerType * getInt16Ty(LLVMContext &C)
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
unsigned getBitWidth() const
Return the number of bits in the APInt.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
amode Optimize addressing mode
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
bool isVolatile() const
Return true if this is a load from a volatile memory location.
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...
Type * getPointerElementType() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
A Use represents the edge between a Value definition and its users.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Windows NT (Windows on ARM)
iterator_range< const unsigned char * > bytes() const
uint64_t getNumElements() const
This file implements a class to represent arbitrary precision integral constant values and operations...
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)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A constant value that is initialized with an expression using other constant values.
int64_t getSExtValue() const
Get sign extended value.
Type * getType() const
All values are typed, get the type of this value.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
ValTy * getArgOperand(unsigned i) const
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
bool has(LibFunc F) const
Tests whether a library function is available.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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 isLittleEndian() const
Layout endianness...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static const fltSemantics & IEEEdouble() LLVM_READNONE
Value * getOperand(unsigned i) const
Class to represent pointers.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
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 * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isNegative() const
Determine sign of this APInt.
bool isStrictFP() const
Return true if the call requires strict floating point semantics.
Type * getReturnType() const
Returns the type of the ret val.
The instances of the Type class are immutable: once they are created, they are never changed...
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
const APInt & getConstant() const
Returns the value when all bits have a known value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
static Constant * getAnd(Constant *C1, Constant *C2)
ConstantFP - Floating Point Values [float, double].
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
double convertToDouble() const
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...
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
bool isConstant() const
Returns true if we know the value of all bits.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Class to represent integer types.
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
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...
static double log2(double V)
static Constant * getAllOnesValue(Type *Ty)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Constant * stripPointerCasts() const
unsigned getNumArgOperands() const
Constant * ConstantFoldLoadThroughGEPIndices(Constant *C, ArrayRef< Constant *> Indices)
ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr indices (with an implied zero ...
static wasm::ValType getType(const TargetRegisterClass *RC)
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
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 APFloat & getValueAPF() const
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Type * getSequentialElementType() const
unsigned getNumOperands() const
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
double Log2(double Value)
Return 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...
Provides information about what library functions are available for the current target.
bool isAggregateType() const
Return true if the type is an aggregate type.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
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...
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
BBTy * getParent() const
Get the basic block containing the call site.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
unsigned getVectorNumElements() const
Class to represent vector types.
Class for arbitrary precision integers.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Type * getResultElementType() const
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
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...
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isNonIntegralPointerType(PointerType *PT) const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
opStatus
IEEE-754R 7: Default exception handling.
FunTy * getCaller() const
Return the caller function for this call site.
uint64_t getElementOffset(unsigned Idx) const
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...
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getIntegerBitWidth() const
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
APInt smul_ov(const APInt &RHS, bool &Overflow) const
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_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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...
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
APInt umul_ov(const APInt &RHS, bool &Overflow) 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.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
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.
Constant * ConstantFoldLoadThroughBitcast(Constant *C, Type *DestTy, const DataLayout &DL)
ConstantFoldLoadThroughBitcast - try to cast constant to destination type returning null if unsuccess...
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
bool canConstantFoldCallTo(ImmutableCallSite CS, const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
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.
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
Type * getElementType() const
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Type * getSourceElementType() const
APInt bitcastToAPInt() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Constant * ConstantFoldCall(ImmutableCallSite CS, Function *F, ArrayRef< Constant *> Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static Constant * get(ArrayRef< Constant *> V)
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value *> Indices) const
Returns the offset from the beginning of the type for the specified indices.
PointerType * getType() const
Global values are always pointers.
bool isNullValue() const
Determine if all bits are clear.
bool isStructTy() const
True if this is an instance of StructType.
cmpResult compare(const APFloat &RHS) const
APInt sdiv_ov(const APInt &RHS, bool &Overflow) const
const fltSemantics & getFltSemantics() const
APInt usub_ov(const APInt &RHS, bool &Overflow) const
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.