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;
375 bool ReadDataFromGlobal(
Constant *C, uint64_t ByteOffset,
unsigned char *CurPtr,
378 "Out of range access");
382 if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
385 if (
auto *CI = dyn_cast<ConstantInt>(C)) {
386 if (CI->getBitWidth() > 64 ||
387 (CI->getBitWidth() & 7) != 0)
390 uint64_t Val = CI->getZExtValue();
391 unsigned IntBytes =
unsigned(CI->getBitWidth()/8);
393 for (
unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
396 n = IntBytes - n - 1;
397 CurPtr[i] = (
unsigned char)(Val >> (n * 8));
403 if (
auto *CFP = dyn_cast<ConstantFP>(C)) {
404 if (CFP->getType()->isDoubleTy()) {
406 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
408 if (CFP->getType()->isFloatTy()){
410 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
412 if (CFP->getType()->isHalfTy()){
414 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
419 if (
auto *CS = dyn_cast<ConstantStruct>(C)) {
423 ByteOffset -= CurEltOffset;
430 if (ByteOffset < EltSize &&
431 !ReadDataFromGlobal(CS->getOperand(Index), ByteOffset, CurPtr,
438 if (Index == CS->getType()->getNumElements())
444 if (BytesLeft <= NextEltOffset - CurEltOffset - ByteOffset)
448 CurPtr += NextEltOffset - CurEltOffset - ByteOffset;
449 BytesLeft -= NextEltOffset - CurEltOffset - ByteOffset;
451 CurEltOffset = NextEltOffset;
456 if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
457 isa<ConstantDataSequential>(C)) {
460 uint64_t
Index = ByteOffset / EltSize;
461 uint64_t
Offset = ByteOffset - Index * EltSize;
463 if (
auto *AT = dyn_cast<ArrayType>(C->
getType()))
464 NumElts = AT->getNumElements();
468 for (; Index != NumElts; ++
Index) {
473 uint64_t BytesWritten = EltSize -
Offset;
474 assert(BytesWritten <= EltSize &&
"Not indexing into this element?");
475 if (BytesWritten >= BytesLeft)
479 BytesLeft -= BytesWritten;
480 CurPtr += BytesWritten;
485 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
486 if (CE->getOpcode() == Instruction::IntToPtr &&
487 CE->getOperand(0)->getType() == DL.
getIntPtrType(CE->getType())) {
488 return ReadDataFromGlobal(CE->getOperand(0), ByteOffset, CurPtr,
499 auto *PTy = cast<PointerType>(C->
getType());
504 unsigned AS = PTy->getAddressSpace();
524 if (
Constant *Res = FoldReinterpretLoadFromConstPtr(C, MapTy, DL))
529 unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
530 if (BytesLoaded > 32 || BytesLoaded == 0)
539 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
540 !GV->getInitializer()->getType()->isSized())
544 int64_t InitializerSize = DL.
getTypeAllocSize(GV->getInitializer()->getType());
547 if (Offset + BytesLoaded <= 0)
551 if (Offset >= InitializerSize)
554 unsigned char RawBytes[32] = {0};
555 unsigned char *CurPtr = RawBytes;
556 unsigned BytesLeft = BytesLoaded;
565 if (!ReadDataFromGlobal(GV->getInitializer(),
Offset, CurPtr, BytesLeft, DL))
568 APInt ResultVal =
APInt(IntType->getBitWidth(), 0);
570 ResultVal = RawBytes[BytesLoaded - 1];
571 for (
unsigned i = 1; i != BytesLoaded; ++i) {
573 ResultVal |= RawBytes[BytesLoaded - 1 - i];
576 ResultVal = RawBytes[0];
577 for (
unsigned i = 1; i != BytesLoaded; ++i) {
579 ResultVal |= RawBytes[i];
606 if (
auto *GV = dyn_cast<GlobalVariable>(C))
607 if (GV->isConstant() && GV->hasDefinitiveInitializer())
608 return GV->getInitializer();
610 if (
auto *GA = dyn_cast<GlobalAlias>(C))
611 if (GA->getAliasee() && !GA->isInterposable())
619 if (CE->getOpcode() == Instruction::GetElementPtr) {
620 if (
auto *GV = dyn_cast<GlobalVariable>(CE->getOperand(0))) {
621 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
629 if (CE->getOpcode() == Instruction::BitCast)
630 if (
Constant *LoadedC = ConstantFoldLoadThroughBitcastExpr(CE, Ty, DL))
637 size_t StrLen = Str.
size();
641 if ((NumBits >> 3) == StrLen + 1 && (NumBits & 7) == 0 &&
644 APInt SingleChar(NumBits, 0);
647 SingleChar =
static_cast<uint64_t
>(
C);
648 StrVal = (StrVal << 8) | SingleChar;
651 for (
unsigned char C : Str.
bytes()) {
652 SingleChar =
static_cast<uint64_t
>(
C);
653 StrVal = (StrVal << 8) | SingleChar;
657 StrVal = (StrVal << 8) | SingleChar;
670 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
671 if (GV->getInitializer()->isNullValue())
673 if (isa<UndefValue>(GV->getInitializer()))
679 return FoldReinterpretLoadFromConstPtr(CE, Ty, DL);
687 if (
auto *C = dyn_cast<Constant>(LI->
getOperand(0)))
705 if (Opc == Instruction::And) {
708 if ((Known1.
One | Known0.
Zero).isAllOnesValue()) {
712 if ((Known0.
One | Known1.
Zero).isAllOnesValue()) {
725 if (Opc == Instruction::Sub) {
754 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i) {
757 SrcElemTy, Ops.
slice(1, i - 1)))) &&
758 Ops[i]->
getType()->getScalarType() != IntPtrScalarTy) {
760 Type *NewType = Ops[i]->getType()->isVectorTy()
776 SrcElemTy, Ops[0], NewIdxs,
false, InRangeIndex);
786 auto *OldPtrTy = cast<PointerType>(Ptr->
getType());
788 auto *NewPtrTy = cast<PointerType>(Ptr->getType());
793 if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
794 NewPtrTy = ElemTy->
getPointerTo(OldPtrTy->getAddressSpace());
814 if (
Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
826 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i)
827 if (!isa<ConstantInt>(Ops[i])) {
833 assert((!CE || CE->getType() == IntPtrTy) &&
834 "CastGEPIndices didn't canonicalize index types!");
835 if (CE && CE->getOpcode() == Instruction::Sub &&
836 CE->getOperand(0)->isNullValue()) {
854 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
857 while (
auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
864 bool AllConstantInt =
true;
865 for (
Value *NestedOp : NestedOps)
866 if (!isa<ConstantInt>(NestedOp)) {
867 AllConstantInt =
false;
876 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
881 APInt BasePtr(BitWidth, 0);
882 if (
auto *CE = dyn_cast<ConstantExpr>(Ptr)) {
883 if (CE->getOpcode() == Instruction::IntToPtr) {
884 if (
auto *
Base = dyn_cast<ConstantInt>(CE->getOperand(0)))
885 BasePtr =
Base->getValue().zextOrTrunc(BitWidth);
889 auto *PTy = cast<PointerType>(Ptr->getType());
907 if (!NewIdxs.
empty())
915 }
else if (
auto *ATy = dyn_cast<SequentialType>(Ty)) {
916 Ty = ATy->getElementType();
936 Offset -= NewIdx * ElemSize;
940 auto *STy = cast<StructType>(Ty);
955 Offset -=
APInt(BitWidth, SL.getElementOffset(ElIdx));
956 Ty = STy->getTypeAtIndex(ElIdx);
958 }
while (Ty != ResElemTy);
971 NewIdxs.
size() > *LastIRIndex) {
972 InRangeIndex = LastIRIndex;
973 for (
unsigned I = 0;
I <= *LastIRIndex; ++
I)
980 InBounds, InRangeIndex);
982 "Computed GetElementPtr has unexpected type!");
997 Constant *ConstantFoldInstOperandsImpl(
const Value *InstOrCE,
unsigned Opcode,
1010 if (
auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
1011 if (
Constant *C = SymbolicallyEvaluateGEP(GEP, Ops, DL, TLI))
1019 if (
auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
1020 return CE->getWithOperands(Ops);
1023 default:
return nullptr;
1024 case Instruction::ICmp:
1027 if (
auto *
F = dyn_cast<Function>(Ops.
back())) {
1035 case Instruction::ExtractElement:
1037 case Instruction::InsertElement:
1039 case Instruction::ShuffleVector:
1056 if (!isa<ConstantVector>(C) && !isa<ConstantExpr>(C))
1061 auto *NewC = cast<Constant>(&NewU);
1064 if (isa<ConstantVector>(NewC) || isa<ConstantExpr>(NewC)) {
1065 auto It = FoldedOps.
find(NewC);
1066 if (It == FoldedOps.
end()) {
1068 ConstantFoldConstantImpl(NewC, DL, TLI, FoldedOps)) {
1069 FoldedOps.
insert({NewC, FoldedC});
1072 FoldedOps.
insert({NewC, NewC});
1081 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1082 if (CE->isCompare())
1086 return ConstantFoldInstOperandsImpl(CE, CE->getOpcode(), Ops, DL, TLI);
1089 assert(isa<ConstantVector>(C));
1098 if (
auto *PN = dyn_cast<PHINode>(I)) {
1102 for (
Value *Incoming : PN->incoming_values()) {
1107 if (isa<UndefValue>(Incoming))
1114 if (
auto *FoldedC = ConstantFoldConstantImpl(C, DL, TLI, FoldedOps))
1118 if (CommonValue && C != CommonValue)
1135 auto *
Op = cast<Constant>(&OpU);
1137 if (
auto *FoldedOp = ConstantFoldConstantImpl(
Op, DL, TLI, FoldedOps))
1143 if (
const auto *CI = dyn_cast<CmpInst>(I))
1147 if (
const auto *LI = dyn_cast<LoadInst>(I))
1148 return ConstantFoldLoadInst(LI, DL);
1150 if (
auto *IVI = dyn_cast<InsertValueInst>(I)) {
1152 cast<Constant>(IVI->getAggregateOperand()),
1153 cast<Constant>(IVI->getInsertedValueOperand()),
1157 if (
auto *EVI = dyn_cast<ExtractValueInst>(I)) {
1159 cast<Constant>(EVI->getAggregateOperand()),
1169 return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
1176 return ConstantFoldInstOperandsImpl(I, I->
getOpcode(), Ops, DL, TLI);
1193 if (
auto *CE0 = dyn_cast<ConstantExpr>(Ops0)) {
1195 if (CE0->getOpcode() == Instruction::IntToPtr) {
1207 if (CE0->getOpcode() == Instruction::PtrToInt) {
1209 if (CE0->getType() == IntPtrTy) {
1217 if (
auto *CE1 = dyn_cast<ConstantExpr>(Ops1)) {
1218 if (CE0->getOpcode() == CE1->getOpcode()) {
1219 if (CE0->getOpcode() == Instruction::IntToPtr) {
1233 if (CE0->getOpcode() == Instruction::PtrToInt) {
1235 if (CE0->getType() == IntPtrTy &&
1236 CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) {
1238 Predicate, CE0->getOperand(0), CE1->getOperand(0), DL, TLI);
1247 CE0->getOpcode() == Instruction::Or && Ops1->
isNullValue()) {
1249 Predicate, CE0->getOperand(0), Ops1, DL, TLI);
1251 Predicate, CE0->getOperand(1), Ops1, DL, TLI);
1256 }
else if (isa<ConstantExpr>(Ops1)) {
1270 if (isa<ConstantExpr>(LHS) || isa<ConstantExpr>(RHS))
1271 if (
Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL))
1283 case Instruction::PtrToInt:
1286 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1287 if (CE->getOpcode() == Instruction::IntToPtr) {
1288 Constant *Input = CE->getOperand(0);
1291 if (PtrWidth < InWidth) {
1302 case Instruction::IntToPtr:
1307 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1308 if (CE->getOpcode() == Instruction::PtrToInt) {
1309 Constant *SrcPtr = CE->getOperand(0);
1311 unsigned MidIntSize = CE->getType()->getScalarSizeInBits();
1313 if (MidIntSize >= SrcPtrSize) {
1316 return FoldBitCast(CE->getOperand(0), DestTy, DL);
1322 case Instruction::Trunc:
1323 case Instruction::ZExt:
1324 case Instruction::SExt:
1325 case Instruction::FPTrunc:
1326 case Instruction::FPExt:
1327 case Instruction::UIToFP:
1328 case Instruction::SIToFP:
1329 case Instruction::FPToUI:
1330 case Instruction::FPToSI:
1331 case Instruction::AddrSpaceCast:
1333 case Instruction::BitCast:
1462 return Name ==
"acos" || Name ==
"asin" || Name ==
"atan" ||
1463 Name ==
"atan2" || Name ==
"acosf" || Name ==
"asinf" ||
1464 Name ==
"atanf" || Name ==
"atan2f";
1466 return Name ==
"ceil" || Name ==
"cos" || Name ==
"cosh" ||
1467 Name ==
"ceilf" || Name ==
"cosf" || Name ==
"coshf";
1469 return Name ==
"exp" || Name ==
"exp2" || Name ==
"expf" || Name ==
"exp2f";
1471 return Name ==
"fabs" || Name ==
"floor" || Name ==
"fmod" ||
1472 Name ==
"fabsf" || Name ==
"floorf" || Name ==
"fmodf";
1474 return Name ==
"log" || Name ==
"log10" || Name ==
"logf" ||
1477 return Name ==
"pow" || Name ==
"powf";
1479 return Name ==
"round" || Name ==
"roundf";
1481 return Name ==
"sin" || Name ==
"sinh" || Name ==
"sqrt" ||
1482 Name ==
"sinf" || Name ==
"sinhf" || Name ==
"sqrtf";
1484 return Name ==
"tan" || Name ==
"tanh" || Name ==
"tanf" || Name ==
"tanhf";
1493 if (Name.
size() < 12 || Name[1] !=
'_')
1499 return Name ==
"__acos_finite" || Name ==
"__acosf_finite" ||
1500 Name ==
"__asin_finite" || Name ==
"__asinf_finite" ||
1501 Name ==
"__atan2_finite" || Name ==
"__atan2f_finite";
1503 return Name ==
"__cosh_finite" || Name ==
"__coshf_finite";
1505 return Name ==
"__exp_finite" || Name ==
"__expf_finite" ||
1506 Name ==
"__exp2_finite" || Name ==
"__exp2f_finite";
1508 return Name ==
"__log_finite" || Name ==
"__logf_finite" ||
1509 Name ==
"__log10_finite" || Name ==
"__log10f_finite";
1511 return Name ==
"__pow_finite" || Name ==
"__powf_finite";
1513 return Name ==
"__sinh_finite" || Name ==
"__sinhf_finite";
1535 inline void llvm_fenv_clearexcept() {
1536 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT 1537 feclearexcept(FE_ALL_EXCEPT);
1543 inline bool llvm_fenv_testexcept() {
1544 int errno_val = errno;
1545 if (errno_val == ERANGE || errno_val == EDOM)
1547 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT 1548 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
1554 Constant *ConstantFoldFP(
double (*NativeFP)(
double),
double V,
Type *Ty) {
1555 llvm_fenv_clearexcept();
1557 if (llvm_fenv_testexcept()) {
1558 llvm_fenv_clearexcept();
1562 return GetConstantFoldFPValue(V, Ty);
1565 Constant *ConstantFoldBinaryFP(
double (*NativeFP)(
double,
double),
double V,
1566 double W,
Type *Ty) {
1567 llvm_fenv_clearexcept();
1569 if (llvm_fenv_testexcept()) {
1570 llvm_fenv_clearexcept();
1574 return GetConstantFoldFPValue(V, Ty);
1584 Constant *ConstantFoldSSEConvertToInt(
const APFloat &Val,
bool roundTowardZero,
1585 Type *Ty,
bool IsSigned) {
1588 assert(ResultWidth <= 64 &&
1589 "Can only constant fold conversions to 64 and 32 bit ints");
1592 bool isExact =
false;
1597 IsSigned, mode, &isExact);
1619 static bool isManifestConstant(
const Constant *c) {
1620 if (isa<ConstantData>(c)) {
1622 }
else if (isa<ConstantAggregate>(c) || isa<ConstantExpr>(c)) {
1624 if (!isManifestConstant(cast<Constant>(subc)))
1632 static bool getConstIntOrUndef(
Value *Op,
const APInt *&C) {
1633 if (
auto *CI = dyn_cast<ConstantInt>(Op)) {
1634 C = &CI->getValue();
1637 if (isa<UndefValue>(Op)) {
1648 if (Operands.
size() == 1) {
1653 if (isManifestConstant(Operands[0]))
1657 if (isa<UndefValue>(Operands[0])) {
1670 if (isa<ConstantPointerNull>(Operands[0])) {
1680 Caller, Operands[0]->
getType()->getPointerAddressSpace())) {
1687 if (
auto *Op = dyn_cast<ConstantFP>(Operands[0])) {
1689 APFloat Val(Op->getValueAPF());
1701 APFloat V = Op->getValueAPF();
1707 APFloat V = Op->getValueAPF();
1713 APFloat V = Op->getValueAPF();
1719 APFloat V = Op->getValueAPF();
1725 APFloat V = Op->getValueAPF();
1731 APFloat V = Op->getValueAPF();
1739 if (Op->getValueAPF().isNaN() || Op->getValueAPF().isInfinity())
1746 double V = getValueAsDouble(Op);
1748 switch (IntrinsicID) {
1751 return ConstantFoldFP(
fabs, V, Ty);
1753 return ConstantFoldFP(
Log2, V, Ty);
1755 return ConstantFoldFP(
log, V, Ty);
1757 return ConstantFoldFP(
log10, V, Ty);
1759 return ConstantFoldFP(
exp, V, Ty);
1761 return ConstantFoldFP(
exp2, V, Ty);
1763 return ConstantFoldFP(
sin, V, Ty);
1765 return ConstantFoldFP(
cos, V, Ty);
1767 return ConstantFoldFP(
sqrt, V, Ty);
1773 char NameKeyChar = Name[0];
1774 if (Name[0] ==
'_' && Name.
size() > 2 && Name[1] ==
'_')
1775 NameKeyChar = Name[2];
1777 switch (NameKeyChar) {
1779 if ((Name ==
"acos" && TLI->
has(LibFunc_acos)) ||
1780 (Name ==
"acosf" && TLI->
has(LibFunc_acosf)) ||
1781 (Name ==
"__acos_finite" && TLI->
has(LibFunc_acos_finite)) ||
1782 (Name ==
"__acosf_finite" && TLI->
has(LibFunc_acosf_finite)))
1783 return ConstantFoldFP(acos, V, Ty);
1784 else if ((Name ==
"asin" && TLI->
has(LibFunc_asin)) ||
1785 (Name ==
"asinf" && TLI->
has(LibFunc_asinf)) ||
1786 (Name ==
"__asin_finite" && TLI->
has(LibFunc_asin_finite)) ||
1787 (Name ==
"__asinf_finite" && TLI->
has(LibFunc_asinf_finite)))
1788 return ConstantFoldFP(asin, V, Ty);
1789 else if ((Name ==
"atan" && TLI->
has(LibFunc_atan)) ||
1790 (Name ==
"atanf" && TLI->
has(LibFunc_atanf)))
1791 return ConstantFoldFP(atan, V, Ty);
1794 if ((Name ==
"ceil" && TLI->
has(LibFunc_ceil)) ||
1795 (Name ==
"ceilf" && TLI->
has(LibFunc_ceilf)))
1796 return ConstantFoldFP(
ceil, V, Ty);
1797 else if ((Name ==
"cos" && TLI->
has(LibFunc_cos)) ||
1798 (Name ==
"cosf" && TLI->
has(LibFunc_cosf)))
1799 return ConstantFoldFP(
cos, V, Ty);
1800 else if ((Name ==
"cosh" && TLI->
has(LibFunc_cosh)) ||
1801 (Name ==
"coshf" && TLI->
has(LibFunc_coshf)) ||
1802 (Name ==
"__cosh_finite" && TLI->
has(LibFunc_cosh_finite)) ||
1803 (Name ==
"__coshf_finite" && TLI->
has(LibFunc_coshf_finite)))
1804 return ConstantFoldFP(cosh, V, Ty);
1807 if ((Name ==
"exp" && TLI->
has(LibFunc_exp)) ||
1808 (Name ==
"expf" && TLI->
has(LibFunc_expf)) ||
1809 (Name ==
"__exp_finite" && TLI->
has(LibFunc_exp_finite)) ||
1810 (Name ==
"__expf_finite" && TLI->
has(LibFunc_expf_finite)))
1811 return ConstantFoldFP(
exp, V, Ty);
1812 if ((Name ==
"exp2" && TLI->
has(LibFunc_exp2)) ||
1813 (Name ==
"exp2f" && TLI->
has(LibFunc_exp2f)) ||
1814 (Name ==
"__exp2_finite" && TLI->
has(LibFunc_exp2_finite)) ||
1815 (Name ==
"__exp2f_finite" && TLI->
has(LibFunc_exp2f_finite)))
1818 return ConstantFoldBinaryFP(
pow, 2.0, V, Ty);
1821 if ((Name ==
"fabs" && TLI->
has(LibFunc_fabs)) ||
1822 (Name ==
"fabsf" && TLI->
has(LibFunc_fabsf)))
1823 return ConstantFoldFP(
fabs, V, Ty);
1824 else if ((Name ==
"floor" && TLI->
has(LibFunc_floor)) ||
1825 (Name ==
"floorf" && TLI->
has(LibFunc_floorf)))
1826 return ConstantFoldFP(
floor, V, Ty);
1829 if ((Name ==
"log" && V > 0 && TLI->
has(LibFunc_log)) ||
1830 (Name ==
"logf" && V > 0 && TLI->
has(LibFunc_logf)) ||
1831 (Name ==
"__log_finite" && V > 0 &&
1832 TLI->
has(LibFunc_log_finite)) ||
1833 (Name ==
"__logf_finite" && V > 0 &&
1834 TLI->
has(LibFunc_logf_finite)))
1835 return ConstantFoldFP(
log, V, Ty);
1836 else if ((Name ==
"log10" && V > 0 && TLI->
has(LibFunc_log10)) ||
1837 (Name ==
"log10f" && V > 0 && TLI->
has(LibFunc_log10f)) ||
1838 (Name ==
"__log10_finite" && V > 0 &&
1839 TLI->
has(LibFunc_log10_finite)) ||
1840 (Name ==
"__log10f_finite" && V > 0 &&
1841 TLI->
has(LibFunc_log10f_finite)))
1842 return ConstantFoldFP(
log10, V, Ty);
1845 if ((Name ==
"round" && TLI->
has(LibFunc_round)) ||
1846 (Name ==
"roundf" && TLI->
has(LibFunc_roundf)))
1847 return ConstantFoldFP(
round, V, Ty);
1850 if ((Name ==
"sin" && TLI->
has(LibFunc_sin)) ||
1851 (Name ==
"sinf" && TLI->
has(LibFunc_sinf)))
1852 return ConstantFoldFP(
sin, V, Ty);
1853 else if ((Name ==
"sinh" && TLI->
has(LibFunc_sinh)) ||
1854 (Name ==
"sinhf" && TLI->
has(LibFunc_sinhf)) ||
1855 (Name ==
"__sinh_finite" && TLI->
has(LibFunc_sinh_finite)) ||
1856 (Name ==
"__sinhf_finite" && TLI->
has(LibFunc_sinhf_finite)))
1857 return ConstantFoldFP(sinh, V, Ty);
1858 else if ((Name ==
"sqrt" && V >= 0 && TLI->
has(LibFunc_sqrt)) ||
1859 (Name ==
"sqrtf" && V >= 0 && TLI->
has(LibFunc_sqrtf)))
1860 return ConstantFoldFP(
sqrt, V, Ty);
1863 if ((Name ==
"tan" && TLI->
has(LibFunc_tan)) ||
1864 (Name ==
"tanf" && TLI->
has(LibFunc_tanf)))
1865 return ConstantFoldFP(tan, V, Ty);
1866 else if ((Name ==
"tanh" && TLI->
has(LibFunc_tanh)) ||
1867 (Name ==
"tanhf" && TLI->
has(LibFunc_tanhf)))
1868 return ConstantFoldFP(tanh, V, Ty);
1876 if (
auto *Op = dyn_cast<ConstantInt>(Operands[0])) {
1877 switch (IntrinsicID) {
1894 "Precision lost during fp16 constfolding");
1904 if (isa<ConstantVector>(Operands[0]) ||
1905 isa<ConstantDataVector>(Operands[0])) {
1906 auto *Op = cast<Constant>(Operands[0]);
1907 switch (IntrinsicID) {
1914 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
1915 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1924 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
1925 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1935 if (Operands.
size() == 2) {
1936 if (
auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1939 double Op1V = getValueAsDouble(Op1);
1941 if (
auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1942 if (Op2->getType() != Op1->getType())
1945 double Op2V = getValueAsDouble(Op2);
1947 return ConstantFoldBinaryFP(
pow, Op1V, Op2V, Ty);
1950 APFloat V1 = Op1->getValueAPF();
1957 const APFloat &C1 = Op1->getValueAPF();
1958 const APFloat &C2 = Op2->getValueAPF();
1963 const APFloat &C1 = Op1->getValueAPF();
1964 const APFloat &C2 = Op2->getValueAPF();
1969 const APFloat &C1 = Op1->getValueAPF();
1970 const APFloat &C2 = Op2->getValueAPF();
1975 const APFloat &C1 = Op1->getValueAPF();
1976 const APFloat &C2 = Op2->getValueAPF();
1982 if ((Name ==
"pow" && TLI->
has(LibFunc_pow)) ||
1983 (Name ==
"powf" && TLI->
has(LibFunc_powf)) ||
1984 (Name ==
"__pow_finite" && TLI->
has(LibFunc_pow_finite)) ||
1985 (Name ==
"__powf_finite" && TLI->
has(LibFunc_powf_finite)))
1986 return ConstantFoldBinaryFP(
pow, Op1V, Op2V, Ty);
1987 if ((Name ==
"fmod" && TLI->
has(LibFunc_fmod)) ||
1988 (Name ==
"fmodf" && TLI->
has(LibFunc_fmodf)))
1989 return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty);
1990 if ((Name ==
"atan2" && TLI->
has(LibFunc_atan2)) ||
1991 (Name ==
"atan2f" && TLI->
has(LibFunc_atan2f)) ||
1992 (Name ==
"__atan2_finite" && TLI->
has(LibFunc_atan2_finite)) ||
1993 (Name ==
"__atan2f_finite" && TLI->
has(LibFunc_atan2f_finite)))
1994 return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
1995 }
else if (
auto *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
1999 (
int)Op2C->getZExtValue())));
2003 (
int)Op2C->getZExtValue())));
2007 (
int)Op2C->getZExtValue())));
2012 if (Operands[0]->
getType()->isIntegerTy() &&
2013 Operands[1]->getType()->isIntegerTy()) {
2014 const APInt *C0, *C1;
2015 if (!getConstIntOrUndef(Operands[0], C0) ||
2016 !getConstIntOrUndef(Operands[1], C1))
2019 switch (IntrinsicID) {
2038 switch (IntrinsicID) {
2041 Res = C0->
sadd_ov(*C1, Overflow);
2044 Res = C0->
uadd_ov(*C1, Overflow);
2047 Res = C0->
ssub_ov(*C1, Overflow);
2050 Res = C0->
usub_ov(*C1, Overflow);
2053 Res = C0->
smul_ov(*C1, Overflow);
2056 Res = C0->
umul_ov(*C1, Overflow);
2087 assert(C1 &&
"Must be constant int");
2104 if ((isa<ConstantVector>(Operands[0]) ||
2105 isa<ConstantDataVector>(Operands[0])) &&
2108 isa<ConstantInt>(Operands[1]) &&
2109 cast<ConstantInt>(Operands[1])->getValue() == 4) {
2110 auto *Op = cast<Constant>(Operands[0]);
2111 switch (IntrinsicID) {
2118 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
2119 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
2128 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
2129 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
2138 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
2139 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
2148 dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
2149 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
2158 if (Operands.
size() != 3)
2161 if (
const auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
2162 if (
const auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
2163 if (
const auto *Op3 = dyn_cast<ConstantFP>(Operands[2])) {
2164 switch (IntrinsicID) {
2168 APFloat V = Op1->getValueAPF();
2183 const APInt *C0, *C1, *C2;
2184 if (!getConstIntOrUndef(Operands[0], C0) ||
2185 !getConstIntOrUndef(Operands[1], C1) ||
2186 !getConstIntOrUndef(Operands[2], C2))
2191 return Operands[IsRight ? 1 : 0];
2198 unsigned ShAmt = C2->
urem(BitWidth);
2200 return Operands[IsRight ? 1 : 0];
2203 unsigned LshrAmt = IsRight ? ShAmt : BitWidth - ShAmt;
2204 unsigned ShlAmt = !IsRight ? ShAmt : BitWidth - ShAmt;
2225 auto *SrcPtr = Operands[0];
2226 auto *
Mask = Operands[2];
2227 auto *Passthru = Operands[3];
2233 auto *MaskElt =
Mask->getAggregateElement(
I);
2236 auto *PassthruElt = Passthru->getAggregateElement(
I);
2238 if (isa<UndefValue>(MaskElt)) {
2246 if (MaskElt->isNullValue()) {
2250 }
else if (MaskElt->isOneValue()) {
2265 for (
unsigned J = 0, JE = Operands.
size(); J != JE; ++J) {
2270 Lane[J] = Operands[J];
2274 Constant *Agg = Operands[J]->getAggregateElement(
I);
2282 Constant *Folded = ConstantFoldScalarCall(Name, IntrinsicID, Ty, Lane, TLI, CS);
2305 if (
auto *VTy = dyn_cast<VectorType>(Ty))
2306 return ConstantFoldVectorCall(Name, F->
getIntrinsicID(), VTy, Operands,
2309 return ConstantFoldScalarCall(Name, F->
getIntrinsicID(), Ty, Operands, TLI, CS);
2335 case LibFunc_log10l:
2337 case LibFunc_log10f:
2344 if (OpC->getType()->isDoubleTy())
2347 if (OpC->getType()->isFloatTy())
2356 if (OpC->getType()->isDoubleTy())
2359 if (OpC->getType()->isFloatTy())
2374 case LibFunc_tanf: {
2377 Type *Ty = OpC->getType();
2379 double OpV = getValueAsDouble(OpC);
2380 return ConstantFoldFP(tan, OpV, Ty) !=
nullptr;
2403 if (OpC->getType()->isDoubleTy())
2406 if (OpC->getType()->isFloatTy())
2429 const APFloat &Op1 = Op1C->getValueAPF();
2434 case LibFunc_powf: {
2439 if (Ty == Op1C->getType()) {
2440 double Op0V = getValueAsDouble(Op0C);
2441 double Op1V = getValueAsDouble(Op1C);
2442 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 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, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
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.
This class represents lattice values for constants.
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...
void push_back(const T &Elt)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
APInt uadd_sat(const APInt &RHS) const
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.
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
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)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
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 * 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.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
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].
bool isOneValue() const
Determine if this is a value of 1.
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 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...
APInt ssub_sat(const APInt &RHS) const
#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.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
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 ...
static ConstantInt * getTrue(LLVMContext &Context)
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)
iterator_range< value_op_iterator > operand_values()
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
APInt usub_sat(const APInt &RHS) 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
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
APInt sadd_sat(const APInt &RHS) 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...
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
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.