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))
329 bool ReadDataFromGlobal(
Constant *C, uint64_t ByteOffset,
unsigned char *CurPtr,
332 "Out of range access");
336 if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
339 if (
auto *CI = dyn_cast<ConstantInt>(C)) {
340 if (CI->getBitWidth() > 64 ||
341 (CI->getBitWidth() & 7) != 0)
344 uint64_t Val = CI->getZExtValue();
345 unsigned IntBytes =
unsigned(CI->getBitWidth()/8);
347 for (
unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
350 n = IntBytes - n - 1;
351 CurPtr[i] = (
unsigned char)(Val >> (n * 8));
357 if (
auto *CFP = dyn_cast<ConstantFP>(C)) {
358 if (CFP->getType()->isDoubleTy()) {
360 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
362 if (CFP->getType()->isFloatTy()){
364 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
366 if (CFP->getType()->isHalfTy()){
368 return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, DL);
373 if (
auto *CS = dyn_cast<ConstantStruct>(C)) {
377 ByteOffset -= CurEltOffset;
384 if (ByteOffset < EltSize &&
385 !ReadDataFromGlobal(
CS->getOperand(Index), ByteOffset, CurPtr,
392 if (Index ==
CS->getType()->getNumElements())
398 if (BytesLeft <= NextEltOffset - CurEltOffset - ByteOffset)
402 CurPtr += NextEltOffset - CurEltOffset - ByteOffset;
403 BytesLeft -= NextEltOffset - CurEltOffset - ByteOffset;
405 CurEltOffset = NextEltOffset;
410 if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
411 isa<ConstantDataSequential>(C)) {
414 uint64_t Index = ByteOffset / EltSize;
415 uint64_t
Offset = ByteOffset - Index * EltSize;
417 if (
auto *AT = dyn_cast<ArrayType>(C->
getType()))
418 NumElts = AT->getNumElements();
422 for (; Index != NumElts; ++Index) {
427 uint64_t BytesWritten = EltSize -
Offset;
428 assert(BytesWritten <= EltSize &&
"Not indexing into this element?");
429 if (BytesWritten >= BytesLeft)
433 BytesLeft -= BytesWritten;
434 CurPtr += BytesWritten;
439 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
440 if (
CE->getOpcode() == Instruction::IntToPtr &&
442 return ReadDataFromGlobal(
CE->getOperand(0), ByteOffset, CurPtr,
453 auto *PTy = cast<PointerType>(C->
getType());
458 unsigned AS = PTy->getAddressSpace();
478 if (
Constant *Res = FoldReinterpretLoadFromConstPtr(C, MapTy, DL))
483 unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
484 if (BytesLoaded > 32 || BytesLoaded == 0)
493 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
494 !GV->getInitializer()->getType()->isSized())
498 int64_t InitializerSize = DL.
getTypeAllocSize(GV->getInitializer()->getType());
501 if (Offset + BytesLoaded <= 0)
505 if (Offset >= InitializerSize)
508 unsigned char RawBytes[32] = {0};
509 unsigned char *CurPtr = RawBytes;
510 unsigned BytesLeft = BytesLoaded;
519 if (!ReadDataFromGlobal(GV->getInitializer(),
Offset, CurPtr, BytesLeft,
DL))
522 APInt ResultVal =
APInt(IntType->getBitWidth(), 0);
524 ResultVal = RawBytes[BytesLoaded - 1];
525 for (
unsigned i = 1; i != BytesLoaded; ++i) {
527 ResultVal |= RawBytes[BytesLoaded - 1 - i];
530 ResultVal = RawBytes[0];
531 for (
unsigned i = 1; i != BytesLoaded; ++i) {
533 ResultVal |= RawBytes[i];
562 Cast = Instruction::IntToPtr;
564 Cast = Instruction::PtrToInt;
590 if (
auto *GV = dyn_cast<GlobalVariable>(C))
591 if (GV->isConstant() && GV->hasDefinitiveInitializer())
592 return GV->getInitializer();
594 if (
auto *GA = dyn_cast<GlobalAlias>(C))
595 if (GA->getAliasee() && !GA->isInterposable())
603 if (CE->
getOpcode() == Instruction::GetElementPtr) {
604 if (
auto *GV = dyn_cast<GlobalVariable>(CE->
getOperand(0))) {
605 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
613 if (CE->
getOpcode() == Instruction::BitCast)
614 if (
Constant *LoadedC = ConstantFoldLoadThroughBitcast(CE, Ty, DL))
621 size_t StrLen = Str.
size();
625 if ((NumBits >> 3) == StrLen + 1 && (NumBits & 7) == 0 &&
628 APInt SingleChar(NumBits, 0);
631 SingleChar =
static_cast<uint64_t
>(
C);
632 StrVal = (StrVal << 8) | SingleChar;
635 for (
unsigned char C : Str.
bytes()) {
636 SingleChar =
static_cast<uint64_t
>(
C);
637 StrVal = (StrVal << 8) | SingleChar;
641 StrVal = (StrVal << 8) | SingleChar;
654 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
655 if (GV->getInitializer()->isNullValue())
657 if (isa<UndefValue>(GV->getInitializer()))
663 return FoldReinterpretLoadFromConstPtr(CE, Ty, DL);
671 if (
auto *C = dyn_cast<Constant>(LI->
getOperand(0)))
689 if (Opc == Instruction::And) {
692 if ((Known1.
One | Known0.
Zero).isAllOnesValue()) {
696 if ((Known0.
One | Known1.
Zero).isAllOnesValue()) {
709 if (Opc == Instruction::Sub) {
738 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i) {
741 SrcElemTy, Ops.
slice(1, i - 1)))) &&
742 Ops[i]->
getType()->getScalarType() != IntPtrScalarTy) {
744 Type *NewType = Ops[i]->getType()->isVectorTy()
760 SrcElemTy, Ops[0], NewIdxs,
false, InRangeIndex);
770 auto *OldPtrTy = cast<PointerType>(Ptr->
getType());
772 auto *NewPtrTy = cast<PointerType>(Ptr->getType());
777 if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
778 NewPtrTy = ElemTy->
getPointerTo(OldPtrTy->getAddressSpace());
798 if (
Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
810 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i)
811 if (!isa<ConstantInt>(Ops[i])) {
818 "CastGEPIndices didn't canonicalize index types!");
819 if (CE && CE->
getOpcode() == Instruction::Sub &&
838 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
841 while (
auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
848 bool AllConstantInt =
true;
849 for (
Value *NestedOp : NestedOps)
850 if (!isa<ConstantInt>(NestedOp)) {
851 AllConstantInt =
false;
860 Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
865 APInt BasePtr(BitWidth, 0);
866 if (
auto *CE = dyn_cast<ConstantExpr>(Ptr)) {
867 if (CE->
getOpcode() == Instruction::IntToPtr) {
869 BasePtr =
Base->getValue().zextOrTrunc(BitWidth);
873 auto *PTy = cast<PointerType>(Ptr->getType());
891 if (!NewIdxs.
empty())
899 }
else if (
auto *ATy = dyn_cast<SequentialType>(Ty)) {
900 Ty = ATy->getElementType();
920 Offset -= NewIdx * ElemSize;
924 auto *STy = cast<StructType>(Ty);
939 Offset -=
APInt(BitWidth, SL.getElementOffset(ElIdx));
940 Ty = STy->getTypeAtIndex(ElIdx);
942 }
while (Ty != ResElemTy);
955 NewIdxs.
size() > *LastIRIndex) {
956 InRangeIndex = LastIRIndex;
957 for (
unsigned I = 0;
I <= *LastIRIndex; ++
I)
966 InBounds, InRangeIndex);
968 "Computed GetElementPtr has unexpected type!");
988 Constant *ConstantFoldInstOperandsImpl(
const Value *InstOrCE,
unsigned Opcode,
1001 if (
auto *GEP = dyn_cast<GEPOperator>(InstOrCE)) {
1002 if (
Constant *C = SymbolicallyEvaluateGEP(GEP, Ops, DL, TLI))
1010 if (
auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
1014 default:
return nullptr;
1015 case Instruction::ICmp:
1018 if (
auto *
F = dyn_cast<Function>(Ops.
back())) {
1026 case Instruction::ExtractElement:
1028 case Instruction::InsertElement:
1030 case Instruction::ShuffleVector:
1047 if (!isa<ConstantVector>(C) && !isa<ConstantExpr>(C))
1052 auto *NewC = cast<Constant>(&NewU);
1055 if (isa<ConstantVector>(NewC) || isa<ConstantExpr>(NewC)) {
1056 auto It = FoldedOps.
find(NewC);
1057 if (It == FoldedOps.
end()) {
1059 ConstantFoldConstantImpl(NewC, DL, TLI, FoldedOps)) {
1060 FoldedOps.
insert({NewC, FoldedC});
1063 FoldedOps.
insert({NewC, NewC});
1072 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1077 return ConstantFoldInstOperandsImpl(CE, CE->
getOpcode(), Ops,
DL, TLI);
1080 assert(isa<ConstantVector>(C));
1089 if (
auto *PN = dyn_cast<PHINode>(I)) {
1093 for (
Value *Incoming : PN->incoming_values()) {
1098 if (isa<UndefValue>(Incoming))
1105 if (
auto *FoldedC = ConstantFoldConstantImpl(C, DL, TLI, FoldedOps))
1109 if (CommonValue && C != CommonValue)
1126 auto *
Op = cast<Constant>(&OpU);
1128 if (
auto *FoldedOp = ConstantFoldConstantImpl(
Op, DL, TLI, FoldedOps))
1134 if (
const auto *CI = dyn_cast<CmpInst>(I))
1138 if (
const auto *LI = dyn_cast<LoadInst>(I))
1139 return ConstantFoldLoadInst(LI, DL);
1141 if (
auto *IVI = dyn_cast<InsertValueInst>(I)) {
1143 cast<Constant>(IVI->getAggregateOperand()),
1144 cast<Constant>(IVI->getInsertedValueOperand()),
1148 if (
auto *EVI = dyn_cast<ExtractValueInst>(I)) {
1150 cast<Constant>(EVI->getAggregateOperand()),
1160 return ConstantFoldConstantImpl(C, DL, TLI, FoldedOps);
1167 return ConstantFoldInstOperandsImpl(I, I->
getOpcode(), Ops,
DL, TLI);
1184 if (
auto *CE0 = dyn_cast<ConstantExpr>(Ops0)) {
1186 if (CE0->getOpcode() == Instruction::IntToPtr) {
1198 if (CE0->getOpcode() == Instruction::PtrToInt) {
1200 if (CE0->getType() == IntPtrTy) {
1208 if (
auto *CE1 = dyn_cast<ConstantExpr>(Ops1)) {
1209 if (CE0->getOpcode() == CE1->getOpcode()) {
1210 if (CE0->getOpcode() == Instruction::IntToPtr) {
1224 if (CE0->getOpcode() == Instruction::PtrToInt) {
1226 if (CE0->getType() == IntPtrTy &&
1227 CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) {
1229 Predicate, CE0->getOperand(0), CE1->getOperand(0),
DL, TLI);
1238 CE0->getOpcode() == Instruction::Or && Ops1->
isNullValue()) {
1240 Predicate, CE0->getOperand(0), Ops1,
DL, TLI);
1242 Predicate, CE0->getOperand(1), Ops1,
DL, TLI);
1247 }
else if (isa<ConstantExpr>(Ops1)) {
1261 if (isa<ConstantExpr>(LHS) || isa<ConstantExpr>(RHS))
1262 if (
Constant *C = SymbolicallyEvaluateBinop(Opcode, LHS, RHS, DL))
1274 case Instruction::PtrToInt:
1277 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1278 if (CE->
getOpcode() == Instruction::IntToPtr) {
1282 if (PtrWidth < InWidth) {
1293 case Instruction::IntToPtr:
1298 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
1299 if (CE->
getOpcode() == Instruction::PtrToInt) {
1304 if (MidIntSize >= SrcPtrSize) {
1313 case Instruction::Trunc:
1314 case Instruction::ZExt:
1315 case Instruction::SExt:
1316 case Instruction::FPTrunc:
1317 case Instruction::FPExt:
1318 case Instruction::UIToFP:
1319 case Instruction::SIToFP:
1320 case Instruction::FPToUI:
1321 case Instruction::FPToSI:
1322 case Instruction::AddrSpaceCast:
1324 case Instruction::BitCast:
1365 case Intrinsic::fabs:
1368 case Intrinsic::log:
1369 case Intrinsic::log2:
1370 case Intrinsic::log10:
1371 case Intrinsic::exp:
1372 case Intrinsic::exp2:
1373 case Intrinsic::floor:
1374 case Intrinsic::ceil:
1375 case Intrinsic::sqrt:
1376 case Intrinsic::sin:
1377 case Intrinsic::cos:
1378 case Intrinsic::trunc:
1379 case Intrinsic::rint:
1380 case Intrinsic::nearbyint:
1381 case Intrinsic::pow:
1382 case Intrinsic::powi:
1383 case Intrinsic::bswap:
1384 case Intrinsic::ctpop:
1385 case Intrinsic::ctlz:
1386 case Intrinsic::cttz:
1387 case Intrinsic::fma:
1388 case Intrinsic::fmuladd:
1389 case Intrinsic::copysign:
1391 case Intrinsic::masked_load:
1392 case Intrinsic::sadd_with_overflow:
1393 case Intrinsic::uadd_with_overflow:
1394 case Intrinsic::ssub_with_overflow:
1395 case Intrinsic::usub_with_overflow:
1396 case Intrinsic::smul_with_overflow:
1397 case Intrinsic::umul_with_overflow:
1398 case Intrinsic::convert_from_fp16:
1399 case Intrinsic::convert_to_fp16:
1400 case Intrinsic::bitreverse:
1401 case Intrinsic::x86_sse_cvtss2si:
1402 case Intrinsic::x86_sse_cvtss2si64:
1403 case Intrinsic::x86_sse_cvttss2si:
1404 case Intrinsic::x86_sse_cvttss2si64:
1405 case Intrinsic::x86_sse2_cvtsd2si:
1406 case Intrinsic::x86_sse2_cvtsd2si64:
1407 case Intrinsic::x86_sse2_cvttsd2si:
1408 case Intrinsic::x86_sse2_cvttsd2si64:
1426 return Name ==
"acos" || Name ==
"asin" || Name ==
"atan" ||
1427 Name ==
"atan2" || Name ==
"acosf" || Name ==
"asinf" ||
1428 Name ==
"atanf" || Name ==
"atan2f";
1430 return Name ==
"ceil" || Name ==
"cos" || Name ==
"cosh" ||
1431 Name ==
"ceilf" || Name ==
"cosf" || Name ==
"coshf";
1433 return Name ==
"exp" || Name ==
"exp2" || Name ==
"expf" || Name ==
"exp2f";
1435 return Name ==
"fabs" || Name ==
"floor" || Name ==
"fmod" ||
1436 Name ==
"fabsf" || Name ==
"floorf" || Name ==
"fmodf";
1438 return Name ==
"log" || Name ==
"log10" || Name ==
"logf" ||
1441 return Name ==
"pow" || Name ==
"powf";
1443 return Name ==
"round" || Name ==
"roundf";
1445 return Name ==
"sin" || Name ==
"sinh" || Name ==
"sqrt" ||
1446 Name ==
"sinf" || Name ==
"sinhf" || Name ==
"sqrtf";
1448 return Name ==
"tan" || Name ==
"tanh" || Name ==
"tanf" || Name ==
"tanhf";
1457 if (Name.
size() < 12 || Name[1] !=
'_')
1463 return Name ==
"__acos_finite" || Name ==
"__acosf_finite" ||
1464 Name ==
"__asin_finite" || Name ==
"__asinf_finite" ||
1465 Name ==
"__atan2_finite" || Name ==
"__atan2f_finite";
1467 return Name ==
"__cosh_finite" || Name ==
"__coshf_finite";
1469 return Name ==
"__exp_finite" || Name ==
"__expf_finite" ||
1470 Name ==
"__exp2_finite" || Name ==
"__exp2f_finite";
1472 return Name ==
"__log_finite" || Name ==
"__logf_finite" ||
1473 Name ==
"__log10_finite" || Name ==
"__log10f_finite";
1475 return Name ==
"__pow_finite" || Name ==
"__powf_finite";
1477 return Name ==
"__sinh_finite" || Name ==
"__sinhf_finite";
1499 inline void llvm_fenv_clearexcept() {
1500 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
1501 feclearexcept(FE_ALL_EXCEPT);
1507 inline bool llvm_fenv_testexcept() {
1508 int errno_val = errno;
1509 if (errno_val == ERANGE || errno_val == EDOM)
1511 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
1512 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
1518 Constant *ConstantFoldFP(
double (*NativeFP)(
double),
double V,
Type *Ty) {
1519 llvm_fenv_clearexcept();
1521 if (llvm_fenv_testexcept()) {
1522 llvm_fenv_clearexcept();
1526 return GetConstantFoldFPValue(V, Ty);
1529 Constant *ConstantFoldBinaryFP(
double (*NativeFP)(
double,
double),
double V,
1530 double W,
Type *Ty) {
1531 llvm_fenv_clearexcept();
1533 if (llvm_fenv_testexcept()) {
1534 llvm_fenv_clearexcept();
1538 return GetConstantFoldFPValue(V, Ty);
1548 Constant *ConstantFoldSSEConvertToInt(
const APFloat &Val,
bool roundTowardZero,
1552 assert(ResultWidth <= 64 &&
1553 "Can only constant fold conversions to 64 and 32 bit ints");
1556 bool isExact =
false;
1561 true, mode, &isExact);
1586 if (Operands.
size() == 1) {
1587 if (isa<UndefValue>(Operands[0])) {
1589 if (IntrinsicID == Intrinsic::cos)
1591 if (IntrinsicID == Intrinsic::bswap ||
1592 IntrinsicID == Intrinsic::bitreverse)
1595 if (
auto *Op = dyn_cast<ConstantFP>(Operands[0])) {
1596 if (IntrinsicID == Intrinsic::convert_to_fp16) {
1614 if (IntrinsicID == Intrinsic::floor) {
1620 if (IntrinsicID == Intrinsic::ceil) {
1626 if (IntrinsicID == Intrinsic::trunc) {
1632 if (IntrinsicID == Intrinsic::rint) {
1638 if (IntrinsicID == Intrinsic::nearbyint) {
1654 double V = getValueAsDouble(Op);
1656 switch (IntrinsicID) {
1658 case Intrinsic::fabs:
1659 return ConstantFoldFP(fabs, V, Ty);
1660 case Intrinsic::log2:
1661 return ConstantFoldFP(
Log2, V, Ty);
1662 case Intrinsic::log:
1663 return ConstantFoldFP(log, V, Ty);
1664 case Intrinsic::log10:
1665 return ConstantFoldFP(log10, V, Ty);
1666 case Intrinsic::exp:
1667 return ConstantFoldFP(exp, V, Ty);
1668 case Intrinsic::exp2:
1669 return ConstantFoldFP(exp2, V, Ty);
1670 case Intrinsic::sin:
1671 return ConstantFoldFP(sin, V, Ty);
1672 case Intrinsic::cos:
1673 return ConstantFoldFP(cos, V, Ty);
1674 case Intrinsic::sqrt:
1675 return ConstantFoldFP(sqrt, V, Ty);
1681 char NameKeyChar = Name[0];
1682 if (Name[0] ==
'_' && Name.
size() > 2 && Name[1] ==
'_')
1683 NameKeyChar = Name[2];
1685 switch (NameKeyChar) {
1687 if ((Name ==
"acos" && TLI->
has(LibFunc_acos)) ||
1688 (Name ==
"acosf" && TLI->
has(LibFunc_acosf)) ||
1689 (Name ==
"__acos_finite" && TLI->
has(LibFunc_acos_finite)) ||
1690 (Name ==
"__acosf_finite" && TLI->
has(LibFunc_acosf_finite)))
1691 return ConstantFoldFP(acos, V, Ty);
1692 else if ((Name ==
"asin" && TLI->
has(LibFunc_asin)) ||
1693 (Name ==
"asinf" && TLI->
has(LibFunc_asinf)) ||
1694 (Name ==
"__asin_finite" && TLI->
has(LibFunc_asin_finite)) ||
1695 (Name ==
"__asinf_finite" && TLI->
has(LibFunc_asinf_finite)))
1696 return ConstantFoldFP(asin, V, Ty);
1697 else if ((Name ==
"atan" && TLI->
has(LibFunc_atan)) ||
1698 (Name ==
"atanf" && TLI->
has(LibFunc_atanf)))
1699 return ConstantFoldFP(atan, V, Ty);
1702 if ((Name ==
"ceil" && TLI->
has(LibFunc_ceil)) ||
1703 (Name ==
"ceilf" && TLI->
has(LibFunc_ceilf)))
1704 return ConstantFoldFP(ceil, V, Ty);
1705 else if ((Name ==
"cos" && TLI->
has(LibFunc_cos)) ||
1706 (Name ==
"cosf" && TLI->
has(LibFunc_cosf)))
1707 return ConstantFoldFP(cos, V, Ty);
1708 else if ((Name ==
"cosh" && TLI->
has(LibFunc_cosh)) ||
1709 (Name ==
"coshf" && TLI->
has(LibFunc_coshf)) ||
1710 (Name ==
"__cosh_finite" && TLI->
has(LibFunc_cosh_finite)) ||
1711 (Name ==
"__coshf_finite" && TLI->
has(LibFunc_coshf_finite)))
1712 return ConstantFoldFP(cosh, V, Ty);
1715 if ((Name ==
"exp" && TLI->
has(LibFunc_exp)) ||
1716 (Name ==
"expf" && TLI->
has(LibFunc_expf)) ||
1717 (Name ==
"__exp_finite" && TLI->
has(LibFunc_exp_finite)) ||
1718 (Name ==
"__expf_finite" && TLI->
has(LibFunc_expf_finite)))
1719 return ConstantFoldFP(exp, V, Ty);
1720 if ((Name ==
"exp2" && TLI->
has(LibFunc_exp2)) ||
1721 (Name ==
"exp2f" && TLI->
has(LibFunc_exp2f)) ||
1722 (Name ==
"__exp2_finite" && TLI->
has(LibFunc_exp2_finite)) ||
1723 (Name ==
"__exp2f_finite" && TLI->
has(LibFunc_exp2f_finite)))
1726 return ConstantFoldBinaryFP(pow, 2.0, V, Ty);
1729 if ((Name ==
"fabs" && TLI->
has(LibFunc_fabs)) ||
1730 (Name ==
"fabsf" && TLI->
has(LibFunc_fabsf)))
1731 return ConstantFoldFP(fabs, V, Ty);
1732 else if ((Name ==
"floor" && TLI->
has(LibFunc_floor)) ||
1733 (Name ==
"floorf" && TLI->
has(LibFunc_floorf)))
1734 return ConstantFoldFP(floor, V, Ty);
1737 if ((Name ==
"log" && V > 0 && TLI->
has(LibFunc_log)) ||
1738 (Name ==
"logf" && V > 0 && TLI->
has(LibFunc_logf)) ||
1739 (Name ==
"__log_finite" && V > 0 &&
1740 TLI->
has(LibFunc_log_finite)) ||
1741 (Name ==
"__logf_finite" && V > 0 &&
1742 TLI->
has(LibFunc_logf_finite)))
1743 return ConstantFoldFP(log, V, Ty);
1744 else if ((Name ==
"log10" && V > 0 && TLI->
has(LibFunc_log10)) ||
1745 (Name ==
"log10f" && V > 0 && TLI->
has(LibFunc_log10f)) ||
1746 (Name ==
"__log10_finite" && V > 0 &&
1747 TLI->
has(LibFunc_log10_finite)) ||
1748 (Name ==
"__log10f_finite" && V > 0 &&
1749 TLI->
has(LibFunc_log10f_finite)))
1750 return ConstantFoldFP(log10, V, Ty);
1753 if ((Name ==
"round" && TLI->
has(LibFunc_round)) ||
1754 (Name ==
"roundf" && TLI->
has(LibFunc_roundf)))
1755 return ConstantFoldFP(
round, V, Ty);
1758 if ((Name ==
"sin" && TLI->
has(LibFunc_sin)) ||
1759 (Name ==
"sinf" && TLI->
has(LibFunc_sinf)))
1760 return ConstantFoldFP(sin, V, Ty);
1761 else if ((Name ==
"sinh" && TLI->
has(LibFunc_sinh)) ||
1762 (Name ==
"sinhf" && TLI->
has(LibFunc_sinhf)) ||
1763 (Name ==
"__sinh_finite" && TLI->
has(LibFunc_sinh_finite)) ||
1764 (Name ==
"__sinhf_finite" && TLI->
has(LibFunc_sinhf_finite)))
1765 return ConstantFoldFP(sinh, V, Ty);
1766 else if ((Name ==
"sqrt" && V >= 0 && TLI->
has(LibFunc_sqrt)) ||
1767 (Name ==
"sqrtf" && V >= 0 && TLI->
has(LibFunc_sqrtf)))
1768 return ConstantFoldFP(sqrt, V, Ty);
1771 if ((Name ==
"tan" && TLI->
has(LibFunc_tan)) ||
1772 (Name ==
"tanf" && TLI->
has(LibFunc_tanf)))
1773 return ConstantFoldFP(tan, V, Ty);
1774 else if ((Name ==
"tanh" && TLI->
has(LibFunc_tanh)) ||
1775 (Name ==
"tanhf" && TLI->
has(LibFunc_tanhf)))
1776 return ConstantFoldFP(tanh, V, Ty);
1784 if (
auto *Op = dyn_cast<ConstantInt>(Operands[0])) {
1785 switch (IntrinsicID) {
1786 case Intrinsic::bswap:
1788 case Intrinsic::ctpop:
1790 case Intrinsic::bitreverse:
1792 case Intrinsic::convert_from_fp16: {
1802 "Precision lost during fp16 constfolding");
1812 if (isa<ConstantVector>(Operands[0]) ||
1813 isa<ConstantDataVector>(Operands[0])) {
1814 auto *Op = cast<Constant>(Operands[0]);
1815 switch (IntrinsicID) {
1817 case Intrinsic::x86_sse_cvtss2si:
1818 case Intrinsic::x86_sse_cvtss2si64:
1819 case Intrinsic::x86_sse2_cvtsd2si:
1820 case Intrinsic::x86_sse2_cvtsd2si64:
1823 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1826 case Intrinsic::x86_sse_cvttss2si:
1827 case Intrinsic::x86_sse_cvttss2si64:
1828 case Intrinsic::x86_sse2_cvttsd2si:
1829 case Intrinsic::x86_sse2_cvttsd2si64:
1832 return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
1841 if (Operands.
size() == 2) {
1842 if (
auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1845 double Op1V = getValueAsDouble(Op1);
1847 if (
auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1848 if (Op2->getType() != Op1->
getType())
1851 double Op2V = getValueAsDouble(Op2);
1852 if (IntrinsicID == Intrinsic::pow) {
1853 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1855 if (IntrinsicID == Intrinsic::copysign) {
1856 APFloat V1 = Op1->getValueAPF();
1863 const APFloat &C1 = Op1->getValueAPF();
1864 const APFloat &C2 = Op2->getValueAPF();
1869 const APFloat &C1 = Op1->getValueAPF();
1870 const APFloat &C2 = Op2->getValueAPF();
1876 if ((Name ==
"pow" && TLI->
has(LibFunc_pow)) ||
1877 (Name ==
"powf" && TLI->
has(LibFunc_powf)) ||
1878 (Name ==
"__pow_finite" && TLI->
has(LibFunc_pow_finite)) ||
1879 (Name ==
"__powf_finite" && TLI->
has(LibFunc_powf_finite)))
1880 return ConstantFoldBinaryFP(pow, Op1V, Op2V, Ty);
1881 if ((Name ==
"fmod" && TLI->
has(LibFunc_fmod)) ||
1882 (Name ==
"fmodf" && TLI->
has(LibFunc_fmodf)))
1883 return ConstantFoldBinaryFP(fmod, Op1V, Op2V, Ty);
1884 if ((Name ==
"atan2" && TLI->
has(LibFunc_atan2)) ||
1885 (Name ==
"atan2f" && TLI->
has(LibFunc_atan2f)) ||
1886 (Name ==
"__atan2_finite" && TLI->
has(LibFunc_atan2_finite)) ||
1887 (Name ==
"__atan2f_finite" && TLI->
has(LibFunc_atan2f_finite)))
1888 return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
1889 }
else if (
auto *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
1890 if (IntrinsicID == Intrinsic::powi && Ty->
isHalfTy())
1892 APFloat((
float)std::pow((
float)Op1V,
1893 (
int)Op2C->getZExtValue())));
1894 if (IntrinsicID == Intrinsic::powi && Ty->
isFloatTy())
1896 APFloat((
float)std::pow((
float)Op1V,
1897 (
int)Op2C->getZExtValue())));
1898 if (IntrinsicID == Intrinsic::powi && Ty->
isDoubleTy())
1900 APFloat((
double)std::pow((
double)Op1V,
1901 (
int)Op2C->getZExtValue())));
1906 if (
auto *Op1 = dyn_cast<ConstantInt>(Operands[0])) {
1907 if (
auto *Op2 = dyn_cast<ConstantInt>(Operands[1])) {
1908 switch (IntrinsicID) {
1910 case Intrinsic::sadd_with_overflow:
1911 case Intrinsic::uadd_with_overflow:
1912 case Intrinsic::ssub_with_overflow:
1913 case Intrinsic::usub_with_overflow:
1914 case Intrinsic::smul_with_overflow:
1915 case Intrinsic::umul_with_overflow: {
1918 switch (IntrinsicID) {
1920 case Intrinsic::sadd_with_overflow:
1921 Res = Op1->getValue().sadd_ov(Op2->getValue(), Overflow);
1923 case Intrinsic::uadd_with_overflow:
1924 Res = Op1->getValue().uadd_ov(Op2->getValue(), Overflow);
1926 case Intrinsic::ssub_with_overflow:
1927 Res = Op1->getValue().ssub_ov(Op2->getValue(), Overflow);
1929 case Intrinsic::usub_with_overflow:
1930 Res = Op1->getValue().usub_ov(Op2->getValue(), Overflow);
1932 case Intrinsic::smul_with_overflow:
1933 Res = Op1->getValue().smul_ov(Op2->getValue(), Overflow);
1935 case Intrinsic::umul_with_overflow:
1936 Res = Op1->getValue().umul_ov(Op2->getValue(), Overflow);
1945 case Intrinsic::cttz:
1946 if (Op2->isOne() && Op1->isZero())
1949 case Intrinsic::ctlz:
1950 if (Op2->isOne() && Op1->isZero())
1961 if (Operands.
size() != 3)
1964 if (
const auto *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1965 if (
const auto *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1966 if (
const auto *Op3 = dyn_cast<ConstantFP>(Operands[2])) {
1967 switch (IntrinsicID) {
1969 case Intrinsic::fma:
1970 case Intrinsic::fmuladd: {
1971 APFloat V = Op1->getValueAPF();
1996 if (IntrinsicID == Intrinsic::masked_load) {
1997 auto *SrcPtr = Operands[0];
1998 auto *
Mask = Operands[2];
1999 auto *Passthru = Operands[3];
2005 auto *MaskElt =
Mask->getAggregateElement(
I);
2008 auto *PassthruElt = Passthru->getAggregateElement(
I);
2010 if (isa<UndefValue>(MaskElt)) {
2018 if (MaskElt->isNullValue()) {
2022 }
else if (MaskElt->isOneValue()) {
2037 for (
unsigned J = 0, JE = Operands.
size(); J != JE; ++J) {
2040 (IntrinsicID == Intrinsic::cttz || IntrinsicID == Intrinsic::ctlz ||
2041 IntrinsicID == Intrinsic::powi)) {
2042 Lane[J] = Operands[J];
2046 Constant *Agg = Operands[J]->getAggregateElement(
I);
2054 Constant *Folded = ConstantFoldScalarCall(Name, IntrinsicID, Ty, Lane, TLI);
2077 if (
auto *VTy = dyn_cast<VectorType>(Ty))
2078 return ConstantFoldVectorCall(Name, F->
getIntrinsicID(), VTy, Operands,
2081 return ConstantFoldScalarCall(Name, F->
getIntrinsicID(), Ty, Operands, TLI);
2107 case LibFunc_log10l:
2109 case LibFunc_log10f:
2116 if (OpC->getType()->isDoubleTy())
2119 if (OpC->getType()->isFloatTy())
2128 if (OpC->getType()->isDoubleTy())
2131 if (OpC->getType()->isFloatTy())
2146 case LibFunc_tanf: {
2149 Type *Ty = OpC->getType();
2151 double OpV = getValueAsDouble(OpC);
2152 return ConstantFoldFP(tan, OpV, Ty) !=
nullptr;
2175 if (OpC->getType()->isDoubleTy())
2178 if (OpC->getType()->isFloatTy())
2201 const APFloat &Op1 = Op1C->getValueAPF();
2206 case LibFunc_powf: {
2211 if (Ty == Op1C->getType()) {
2212 double Op0V = getValueAsDouble(Op0C);
2213 double Op1V = getValueAsDouble(Op1C);
2214 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)
static Constant * FoldBitCast(Constant *V, Type *DestTy)
Type * getSourceElementType() const
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static IntegerType * getInt1Ty(LLVMContext &C)
uint64_t getZExtValue() const
Get zero extended value.
bool isNonIntegralPointerType(PointerType *PT) const
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
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.
float convertToFloat() const
Type * getSequentialElementType() const
unsigned getNumOperands() const
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static uint64_t round(uint64_t Acc, uint64_t Input)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL)
If this constant is a constant offset from a global, return the global and the constant.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
An instruction for reading from memory.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static IntegerType * getInt16Ty(LLVMContext &C)
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...
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
Type * getPointerElementType() const
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
const APInt & getConstant() const
Returns the value when all bits have a known value.
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
amode Optimize addressing mode
bool isNegative() const
Determine sign of this APInt.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
const Constant * stripPointerCasts() const
A Use represents the edge between a Value definition and its users.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static Constant * get(ArrayRef< Constant * > V)
APInt bitcastToAPInt() const
Windows NT (Windows on ARM)
Type * getVectorElementType() const
This file implements a class to represent arbitrary precision integral constant values and operations...
LLVM_NODISCARD bool empty() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
const AMDGPUAS &AS return SrcAS
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A constant value that is initialized with an expression using other constant values.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool isMathLibCallNoop(CallSite CS, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
bool isLittleEndian() const
Layout endianness...
static const fltSemantics & IEEEdouble() LLVM_READNONE
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Type * getElementType() const
size_t size() const
size - Get the array size.
Class to represent pointers.
iterator find(const_arg_type_t< KeyT > Val)
uint64_t getElementOffset(unsigned Idx) const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Type * getResultElementType() const
Optional< unsigned > getInRangeIndex() const
Returns the offset of the index with an inrange attachment, or None if none.
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isX86_MMXTy() const
Return true if this is X86 MMX.
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().
bool isVectorTy() const
True if this is an instance of VectorType.
This is an important base class in LLVM.
int64_t getSExtValue() const
Get sign extended value.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
ConstantFP - Floating Point Values [float, double].
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
bool isConstant() const
Returns true if we know the value of all bits.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
APInt sdiv_ov(const APInt &RHS, bool &Overflow) const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
uint64_t getNumElements() const
Value * getOperand(unsigned i) const
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
unsigned getIntegerBitWidth() const
Class to represent integer types.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
static wasm::ValType getType(const TargetRegisterClass *RC)
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...
void copySign(const APFloat &RHS)
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
const T & back() const
back - Get the last element.
bool isCompare() const
Return true if this is a compare constant expression.
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
double Log2(double Value)
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...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
const fltSemantics & getFltSemantics() const
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
unsigned getNumArgOperands() const
Class to represent vector types.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
double convertToDouble() const
llvm_unreachable("Unknown RegBank!")
bool isStructTy() const
True if this is an instance of StructType.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
opStatus
IEEE-754R 7: Default exception handling.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isAggregateType() const
Return true if the type is an aggregate type.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Establish a view to a call site for examination.
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getOr(Constant *C1, Constant *C2)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const APFloat & getValueAPF() const
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
iterator_range< const unsigned char * > bytes() const
Constant * ConstantFoldInstOperands(Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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.
ValTy * getArgOperand(unsigned i) const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
cmpResult compare(const APFloat &RHS) const
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
bool isNullValue() const
Determine if all bits are clear.
Constant * ConstantFoldLoadThroughGEPIndices(Constant *C, ArrayRef< Constant * > Indices)
ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr indices (with an implied zero ...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values...
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...
const fltSemantics & getSemantics() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
bool has(LibFunc F) const
Tests whether a library function is available.
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.