25 #include "llvm/Config/config.h"
87 APInt Result(
IT->getBitWidth(), 0);
88 for (
unsigned i = 0; i != NumSrcElts; ++i) {
106 if (isa<ConstantFP>(C) || isa<ConstantInt>(C)) {
112 if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
118 if (NumDstElt == NumSrcElt)
155 if (!isa<ConstantVector>(C) &&
156 !isa<ConstantDataVector>(C))
167 if (NumDstElt < NumSrcElt) {
170 unsigned Ratio = NumSrcElt/NumDstElt;
173 for (
unsigned i = 0; i != NumDstElt; ++i) {
176 unsigned ShiftAmt = isLittleEndian ? 0 : SrcBitSize*(Ratio-1);
177 for (
unsigned j = 0; j != Ratio; ++j) {
188 ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
199 unsigned Ratio = NumDstElt/NumSrcElt;
203 for (
unsigned i = 0; i != NumSrcElt; ++i) {
208 unsigned ShiftAmt = isLittleEndian ? 0 : DstBitSize*(Ratio-1);
209 for (
unsigned j = 0; j != Ratio; ++j) {
214 ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
239 if ((GV = dyn_cast<GlobalValue>(C))) {
241 Offset =
APInt(BitWidth, 0);
247 if (!CE)
return false;
250 if (CE->
getOpcode() == Instruction::PtrToInt ||
251 CE->
getOpcode() == Instruction::BitCast ||
252 CE->
getOpcode() == Instruction::AddrSpaceCast)
261 APInt TmpOffset(BitWidth, 0);
280 unsigned char *CurPtr,
unsigned BytesLeft,
283 "Out of range access");
287 if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
291 if (CI->getBitWidth() > 64 ||
292 (CI->getBitWidth() & 7) != 0)
295 uint64_t Val = CI->getZExtValue();
296 unsigned IntBytes =
unsigned(CI->getBitWidth()/8);
298 for (
unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
301 n = IntBytes - n - 1;
302 CurPtr[i] = (
unsigned char)(Val >> (n * 8));
308 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
309 if (CFP->getType()->isDoubleTy()) {
313 if (CFP->getType()->isFloatTy()){
317 if (CFP->getType()->isHalfTy()){
328 ByteOffset -= CurEltOffset;
335 if (ByteOffset < EltSize &&
343 if (Index ==
CS->getType()->getNumElements())
349 if (BytesLeft <= NextEltOffset - CurEltOffset - ByteOffset)
353 CurPtr += NextEltOffset - CurEltOffset - ByteOffset;
354 BytesLeft -= NextEltOffset - CurEltOffset - ByteOffset;
356 CurEltOffset = NextEltOffset;
361 if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
362 isa<ConstantDataSequential>(C)) {
365 uint64_t Index = ByteOffset / EltSize;
366 uint64_t Offset = ByteOffset - Index * EltSize;
369 NumElts = AT->getNumElements();
373 for (; Index != NumElts; ++Index) {
378 uint64_t BytesWritten = EltSize - Offset;
379 assert(BytesWritten <= EltSize &&
"Not indexing into this element?");
380 if (BytesWritten >= BytesLeft)
384 BytesLeft -= BytesWritten;
385 CurPtr += BytesWritten;
391 if (CE->getOpcode() == Instruction::IntToPtr &&
392 CE->getOperand(0)->getType() == DL.
getIntPtrType(CE->getType())) {
417 if (LoadTy->isHalfTy())
419 else if (LoadTy->isFloatTy())
421 else if (LoadTy->isDoubleTy())
423 else if (LoadTy->isVectorTy()) {
435 unsigned BytesLoaded = (IntType->
getBitWidth() + 7) / 8;
436 if (BytesLoaded > 32 || BytesLoaded == 0)
459 unsigned char RawBytes[32] = {0};
466 ResultVal = RawBytes[BytesLoaded - 1];
467 for (
unsigned i = 1; i != BytesLoaded; ++i) {
469 ResultVal |= RawBytes[BytesLoaded - 1 - i];
472 ResultVal = RawBytes[0];
473 for (
unsigned i = 1; i != BytesLoaded; ++i) {
475 ResultVal |= RawBytes[i];
487 Type *DestTy = DestPtrTy->getElementType();
503 Cast = Instruction::IntToPtr;
505 Cast = Instruction::PtrToInt;
532 if (GV->isConstant() && GV->hasDefinitiveInitializer())
533 return GV->getInitializer();
540 if (CE->
getOpcode() == Instruction::GetElementPtr) {
542 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
550 if (CE->
getOpcode() == Instruction::BitCast)
558 unsigned StrLen = Str.
size();
559 Type *Ty = cast<PointerType>(CE->
getType())->getElementType();
563 if ((NumBits >> 3) == StrLen + 1 && (NumBits & 7) == 0 &&
566 APInt SingleChar(NumBits, 0);
568 for (
signed i = StrLen-1; i >= 0; i--) {
569 SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
570 StrVal = (StrVal << 8) | SingleChar;
573 for (
unsigned i = 0; i < StrLen; i++) {
574 SingleChar = (uint64_t) Str[i] & UCHAR_MAX;
575 StrVal = (StrVal << 8) | SingleChar;
579 StrVal = (StrVal << 8) | SingleChar;
593 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
594 Type *ResTy = cast<PointerType>(C->
getType())->getElementType();
595 if (GV->getInitializer()->isNullValue())
597 if (isa<UndefValue>(GV->getInitializer()))
631 APInt KnownZero0(BitWidth, 0), KnownOne0(BitWidth, 0);
632 APInt KnownZero1(BitWidth, 0), KnownOne1(BitWidth, 0);
635 if ((KnownOne1 | KnownZero0).isAllOnesValue()) {
639 if ((KnownOne0 | KnownZero1).isAllOnesValue()) {
644 APInt KnownZero = KnownZero0 | KnownZero1;
645 APInt KnownOne = KnownOne0 & KnownOne1;
646 if ((KnownZero | KnownOne).isAllOnesValue()) {
653 if (Opc == Instruction::Sub) {
681 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i) {
684 cast<PointerType>(Ops[0]->
getType()->getScalarType())
686 Ops.
slice(1, i - 1)))) &&
687 Ops[i]->
getType() != IntPtrTy) {
715 PointerType *NewPtrTy = cast<PointerType>(Ptr->getType());
720 OldPtrTy->getAddressSpace());
740 for (
unsigned i = 1, e = Ops.
size(); i != e; ++i)
741 if (!isa<ConstantInt>(Ops[i])) {
747 assert((!CE || CE->
getType() == IntPtrTy) &&
748 "CastGEPIndices didn't canonicalize index types!");
749 if (CE && CE->
getOpcode() == Instruction::Sub &&
775 bool AllConstantInt =
true;
776 for (
unsigned i = 0, e = NestedOps.size(); i != e; ++i)
777 if (!isa<ConstantInt>(NestedOps[i])) {
778 AllConstantInt =
false;
784 Ptr = cast<Constant>(
GEP->getOperand(0));
791 APInt BasePtr(BitWidth, 0);
793 if (CE->getOpcode() == Instruction::IntToPtr) {
794 if (
ConstantInt *Base = dyn_cast<ConstantInt>(CE->getOperand(0)))
799 if (Ptr->isNullValue() || BasePtr != 0) {
808 Type *Ty = Ptr->getType();
809 assert(Ty->
isPointerTy() &&
"Forming regular GEP of non-pointer type");
814 if (ATy->isPointerTy()) {
816 if (!NewIdxs.empty())
820 if (!ATy->getElementType()->isSized())
835 Offset -= NewIdx * ElemSize;
838 Ty = ATy->getElementType();
839 }
else if (
StructType *STy = dyn_cast<StructType>(Ty)) {
855 Ty = STy->getTypeAtIndex(ElIdx);
860 }
while (Ty != ResultElementTy);
871 "Computed GetElementPtr has unexpected type!");
875 if (Ty != ResultElementTy)
895 if (
PHINode *PN = dyn_cast<PHINode>(I)) {
898 for (
Value *Incoming : PN->incoming_values()) {
903 if (isa<UndefValue>(Incoming))
914 if (CommonValue && C != CommonValue)
939 if (
const CmpInst *CI = dyn_cast<CmpInst>(I))
943 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
948 cast<Constant>(IVI->getAggregateOperand()),
949 cast<Constant>(IVI->getInsertedValueOperand()),
955 cast<Constant>(EVI->getAggregateOperand()),
969 Constant *NewC = cast<Constant>(*i);
972 if (
ConstantExpr *NewCE = dyn_cast<ConstantExpr>(NewC)) {
973 if (FoldedOps.
insert(NewCE).second)
1011 if (isa<ConstantExpr>(Ops[0]) || isa<ConstantExpr>(Ops[1])) {
1020 default:
return nullptr;
1021 case Instruction::ICmp:
1028 case Instruction::PtrToInt:
1031 if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) {
1032 if (CE->getOpcode() == Instruction::IntToPtr) {
1033 Constant *Input = CE->getOperand(0);
1036 if (PtrWidth < InWidth) {
1047 case Instruction::IntToPtr:
1052 if (
ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) {
1053 if (CE->getOpcode() == Instruction::PtrToInt) {
1054 Constant *SrcPtr = CE->getOperand(0);
1056 unsigned MidIntSize = CE->getType()->getScalarSizeInBits();
1058 if (MidIntSize >= SrcPtrSize) {
1061 return FoldBitCast(CE->getOperand(0), DestTy, DL);
1067 case Instruction::Trunc:
1068 case Instruction::ZExt:
1069 case Instruction::SExt:
1070 case Instruction::FPTrunc:
1071 case Instruction::FPExt:
1072 case Instruction::UIToFP:
1073 case Instruction::SIToFP:
1074 case Instruction::FPToUI:
1075 case Instruction::FPToSI:
1076 case Instruction::AddrSpaceCast:
1078 case Instruction::BitCast:
1084 case Instruction::InsertElement:
1086 case Instruction::ShuffleVector:
1088 case Instruction::GetElementPtr: {
1089 Type *SrcTy =
nullptr;
1115 if (
ConstantExpr *CE0 = dyn_cast<ConstantExpr>(Ops0)) {
1117 if (CE0->getOpcode() == Instruction::IntToPtr) {
1129 if (CE0->getOpcode() == Instruction::PtrToInt) {
1131 if (CE0->getType() == IntPtrTy) {
1139 if (
ConstantExpr *CE1 = dyn_cast<ConstantExpr>(Ops1)) {
1140 if (CE0->getOpcode() == CE1->getOpcode()) {
1141 if (CE0->getOpcode() == Instruction::IntToPtr) {
1155 if (CE0->getOpcode() == Instruction::PtrToInt) {
1157 if (CE0->getType() == IntPtrTy &&
1158 CE0->getOperand(0)->getType() == CE1->getOperand(0)->getType()) {
1160 Predicate, CE0->getOperand(0), CE1->getOperand(0), DL, TLI);
1171 Predicate, CE0->getOperand(0), Ops1, DL, TLI);
1173 Predicate, CE0->getOperand(1), Ops1, DL, TLI);
1210 for (
unsigned i = 0, e = Indices.
size(); i != e; ++i) {
1226 case Intrinsic::fabs:
1229 case Intrinsic::log:
1230 case Intrinsic::log2:
1231 case Intrinsic::log10:
1232 case Intrinsic::exp:
1233 case Intrinsic::exp2:
1234 case Intrinsic::floor:
1235 case Intrinsic::ceil:
1236 case Intrinsic::sqrt:
1237 case Intrinsic::sin:
1238 case Intrinsic::cos:
1239 case Intrinsic::pow:
1240 case Intrinsic::powi:
1241 case Intrinsic::bswap:
1242 case Intrinsic::ctpop:
1243 case Intrinsic::ctlz:
1244 case Intrinsic::cttz:
1245 case Intrinsic::fma:
1246 case Intrinsic::fmuladd:
1247 case Intrinsic::copysign:
1248 case Intrinsic::round:
1249 case Intrinsic::sadd_with_overflow:
1250 case Intrinsic::uadd_with_overflow:
1251 case Intrinsic::ssub_with_overflow:
1252 case Intrinsic::usub_with_overflow:
1253 case Intrinsic::smul_with_overflow:
1254 case Intrinsic::umul_with_overflow:
1255 case Intrinsic::convert_from_fp16:
1256 case Intrinsic::convert_to_fp16:
1257 case Intrinsic::x86_sse_cvtss2si:
1258 case Intrinsic::x86_sse_cvtss2si64:
1259 case Intrinsic::x86_sse_cvttss2si:
1260 case Intrinsic::x86_sse_cvttss2si64:
1261 case Intrinsic::x86_sse2_cvtsd2si:
1262 case Intrinsic::x86_sse2_cvtsd2si64:
1263 case Intrinsic::x86_sse2_cvttsd2si:
1264 case Intrinsic::x86_sse2_cvttsd2si64:
1279 default:
return false;
1281 return Name ==
"acos" || Name ==
"asin" || Name ==
"atan" || Name ==
"atan2";
1283 return Name ==
"cos" || Name ==
"ceil" || Name ==
"cosf" || Name ==
"cosh";
1285 return Name ==
"exp" || Name ==
"exp2";
1287 return Name ==
"fabs" || Name ==
"fmod" || Name ==
"floor";
1289 return Name ==
"log" || Name ==
"log10";
1291 return Name ==
"pow";
1293 return Name ==
"sin" || Name ==
"sinh" || Name ==
"sqrt" ||
1294 Name ==
"sinf" || Name ==
"sqrtf";
1296 return Name ==
"tan" || Name ==
"tanh";
1317 static inline void llvm_fenv_clearexcept() {
1318 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
1319 feclearexcept(FE_ALL_EXCEPT);
1325 static inline bool llvm_fenv_testexcept() {
1326 int errno_val = errno;
1327 if (errno_val == ERANGE || errno_val == EDOM)
1329 #if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
1330 if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
1339 llvm_fenv_clearexcept();
1341 if (llvm_fenv_testexcept()) {
1342 llvm_fenv_clearexcept();
1350 double V,
double W,
Type *Ty) {
1351 llvm_fenv_clearexcept();
1353 if (llvm_fenv_testexcept()) {
1354 llvm_fenv_clearexcept();
1369 bool roundTowardZero,
Type *Ty) {
1372 assert(ResultWidth <= 64 &&
1373 "Can only constant fold conversions to 64 and 32 bit ints");
1376 bool isExact =
false;
1405 if (Operands.
size() == 1) {
1406 if (
ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
1407 if (IntrinsicID == Intrinsic::convert_to_fp16) {
1408 APFloat Val(Op->getValueAPF());
1419 if (IntrinsicID == Intrinsic::round) {
1420 APFloat V = Op->getValueAPF();
1428 if (Op->getValueAPF().isNaN() || Op->getValueAPF().isInfinity())
1437 switch (IntrinsicID) {
1439 case Intrinsic::fabs:
1441 case Intrinsic::log2:
1443 case Intrinsic::log:
1445 case Intrinsic::log10:
1447 case Intrinsic::exp:
1449 case Intrinsic::exp2:
1451 case Intrinsic::floor:
1453 case Intrinsic::ceil:
1455 case Intrinsic::sin:
1457 case Intrinsic::cos:
1466 if (Name ==
"acos" && TLI->
has(LibFunc::acos))
1468 else if (Name ==
"asin" && TLI->
has(LibFunc::asin))
1470 else if (Name ==
"atan" && TLI->
has(LibFunc::atan))
1474 if (Name ==
"ceil" && TLI->
has(LibFunc::ceil))
1476 else if (Name ==
"cos" && TLI->
has(LibFunc::cos))
1478 else if (Name ==
"cosh" && TLI->
has(LibFunc::cosh))
1480 else if (Name ==
"cosf" && TLI->
has(LibFunc::cosf))
1484 if (Name ==
"exp" && TLI->
has(LibFunc::exp))
1487 if (Name ==
"exp2" && TLI->
has(LibFunc::exp2)) {
1494 if (Name ==
"fabs" && TLI->
has(LibFunc::fabs))
1496 else if (Name ==
"floor" && TLI->
has(LibFunc::floor))
1500 if (Name ==
"log" && V > 0 && TLI->
has(LibFunc::log))
1502 else if (Name ==
"log10" && V > 0 && TLI->
has(LibFunc::log10))
1504 else if (IntrinsicID == Intrinsic::sqrt &&
1519 if (Name ==
"sin" && TLI->
has(LibFunc::sin))
1521 else if (Name ==
"sinh" && TLI->
has(LibFunc::sinh))
1523 else if (Name ==
"sqrt" && V >= 0 && TLI->
has(LibFunc::sqrt))
1525 else if (Name ==
"sqrtf" && V >= 0 && TLI->
has(LibFunc::sqrtf))
1527 else if (Name ==
"sinf" && TLI->
has(LibFunc::sinf))
1531 if (Name ==
"tan" && TLI->
has(LibFunc::tan))
1533 else if (Name ==
"tanh" && TLI->
has(LibFunc::tanh))
1542 if (
ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
1543 switch (IntrinsicID) {
1544 case Intrinsic::bswap:
1546 case Intrinsic::ctpop:
1548 case Intrinsic::convert_from_fp16: {
1558 "Precision lost during fp16 constfolding");
1568 if (isa<ConstantVector>(Operands[0]) ||
1569 isa<ConstantDataVector>(Operands[0])) {
1570 Constant *Op = cast<Constant>(Operands[0]);
1571 switch (IntrinsicID) {
1573 case Intrinsic::x86_sse_cvtss2si:
1574 case Intrinsic::x86_sse_cvtss2si64:
1575 case Intrinsic::x86_sse2_cvtsd2si:
1576 case Intrinsic::x86_sse2_cvtsd2si64:
1581 case Intrinsic::x86_sse_cvttss2si:
1582 case Intrinsic::x86_sse_cvttss2si64:
1583 case Intrinsic::x86_sse2_cvttsd2si:
1584 case Intrinsic::x86_sse2_cvttsd2si64:
1592 if (isa<UndefValue>(Operands[0])) {
1593 if (IntrinsicID == Intrinsic::bswap)
1601 if (Operands.
size() == 2) {
1602 if (
ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1607 if (
ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1608 if (Op2->getType() != Op1->getType())
1612 if (IntrinsicID == Intrinsic::pow) {
1615 if (IntrinsicID == Intrinsic::copysign) {
1616 APFloat V1 = Op1->getValueAPF();
1623 const APFloat &C1 = Op1->getValueAPF();
1624 const APFloat &C2 = Op2->getValueAPF();
1629 const APFloat &C1 = Op1->getValueAPF();
1630 const APFloat &C2 = Op2->getValueAPF();
1636 if (Name ==
"pow" && TLI->
has(LibFunc::pow))
1638 if (Name ==
"fmod" && TLI->
has(LibFunc::fmod))
1640 if (Name ==
"atan2" && TLI->
has(LibFunc::atan2))
1642 }
else if (
ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
1643 if (IntrinsicID == Intrinsic::powi && Ty->
isHalfTy())
1645 APFloat((
float)std::pow((
float)Op1V,
1646 (
int)Op2C->getZExtValue())));
1647 if (IntrinsicID == Intrinsic::powi && Ty->
isFloatTy())
1649 APFloat((
float)std::pow((
float)Op1V,
1650 (
int)Op2C->getZExtValue())));
1651 if (IntrinsicID == Intrinsic::powi && Ty->
isDoubleTy())
1653 APFloat((
double)std::pow((
double)Op1V,
1654 (
int)Op2C->getZExtValue())));
1659 if (
ConstantInt *Op1 = dyn_cast<ConstantInt>(Operands[0])) {
1660 if (
ConstantInt *Op2 = dyn_cast<ConstantInt>(Operands[1])) {
1661 switch (IntrinsicID) {
1663 case Intrinsic::sadd_with_overflow:
1664 case Intrinsic::uadd_with_overflow:
1665 case Intrinsic::ssub_with_overflow:
1666 case Intrinsic::usub_with_overflow:
1667 case Intrinsic::smul_with_overflow:
1668 case Intrinsic::umul_with_overflow: {
1671 switch (IntrinsicID) {
1673 case Intrinsic::sadd_with_overflow:
1674 Res = Op1->getValue().
sadd_ov(Op2->getValue(), Overflow);
1676 case Intrinsic::uadd_with_overflow:
1677 Res = Op1->getValue().
uadd_ov(Op2->getValue(), Overflow);
1679 case Intrinsic::ssub_with_overflow:
1680 Res = Op1->getValue().
ssub_ov(Op2->getValue(), Overflow);
1682 case Intrinsic::usub_with_overflow:
1683 Res = Op1->getValue().
usub_ov(Op2->getValue(), Overflow);
1685 case Intrinsic::smul_with_overflow:
1686 Res = Op1->getValue().
smul_ov(Op2->getValue(), Overflow);
1688 case Intrinsic::umul_with_overflow:
1689 Res = Op1->getValue().
umul_ov(Op2->getValue(), Overflow);
1698 case Intrinsic::cttz:
1699 if (Op2->isOne() && Op1->isZero())
1702 case Intrinsic::ctlz:
1703 if (Op2->isOne() && Op1->isZero())
1714 if (Operands.
size() != 3)
1717 if (
const ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
1718 if (
const ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
1719 if (
const ConstantFP *Op3 = dyn_cast<ConstantFP>(Operands[2])) {
1720 switch (IntrinsicID) {
1722 case Intrinsic::fma:
1723 case Intrinsic::fmuladd: {
1724 APFloat V = Op1->getValueAPF();
1751 for (
unsigned J = 0, JE = Operands.
size(); J != JE; ++J) {
1752 Constant *Agg = Operands[J]->getAggregateElement(
I);
1780 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
ConstantDataVector - A vector constant whose element type is a simple 1/2/4/8-byte integer or float/d...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
This class is the base class for the comparison instructions.
static IntegerType * getInt1Ty(LLVMContext &C)
static Constant * ConstantFoldVectorCall(StringRef Name, unsigned IntrinsicID, VectorType *VTy, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI)
uint64_t getZExtValue() const
Get zero extended value.
Type * getSequentialElementType() const
size_t size() const
size - Get the string size.
static Constant * FoldReinterpretLoadFromConstPtr(Constant *C, const DataLayout &DL)
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 const fltSemantics IEEEdouble
bool canConstantFoldCallTo(const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
static Constant * ConstantFoldLoadThroughBitcast(ConstantExpr *CE, const DataLayout &DL)
unsigned getNumOperands() const
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
APInt smul_ov(const APInt &RHS, bool &Overflow) const
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static PointerType * getInt32PtrTy(LLVMContext &C, unsigned AS=0)
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * ConstantFoldConvertToInt(const APFloat &Val, bool roundTowardZero, Type *Ty)
Attempt to fold an SSE floating point to integer conversion of a constant floating point...
opStatus
IEEE-754R 7: Default exception handling.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
bool isPtrOrPtrVectorTy() const
isPtrOrPtrVectorTy - Return true if this is a pointer type or a vector of pointer types...
Type * getReturnType() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
LoadInst - an instruction for reading from memory.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static IntegerType * getInt64Ty(LLVMContext &C)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getInt16Ty(LLVMContext &C)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Constant * ConstantFoldConstantExpression(const ConstantExpr *CE, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstantExpression - Attempt to fold the constant expression using the specified DataLayo...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
static Constant * ConstantFoldBinaryFP(double(*NativeFP)(double, double), double V, double W, Type *Ty)
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
APInt ssub_ov(const APInt &RHS, bool &Overflow) const
Type * getPointerElementType() const
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
static 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.
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool isNegative() const
Determine sign of this APInt.
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...
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7"), clEnumValEnd))
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool has(LibFunc::Func F) const
Tests whether a library function is available.
StructType - Class to represent struct types.
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
Constant * ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
static Constant * get(ArrayRef< Constant * > V)
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
static PointerType * getInt16PtrTy(LLVMContext &C, unsigned AS=0)
uint64_t getIndexedOffset(Type *Ty, ArrayRef< Value * > Indices) const
Returns the offset from the beginning of the type for the specified indices.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
Type * getVectorElementType() const
static double getValueAsDouble(ConstantFP *Op)
void copySign(const APFloat &)
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)
static Constant * GetConstantFoldFPValue(double V, Type *Ty)
static Constant * StripPtrCastKeepAS(Constant *Ptr)
Strip the pointer casts, but preserve the address space information.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
APInt usub_ov(const APInt &RHS, bool &Overflow) const
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
ArrayType - Class to represent array types.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static Constant * ConstantFoldScalarCall(StringRef Name, unsigned IntrinsicID, Type *Ty, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI)
double convertToDouble() const
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
bool isLittleEndian() const
Layout endianness...
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
APInt umul_ov(const APInt &RHS, bool &Overflow) const
unsigned getNumElements() const
Return the number of elements in the Vector type.
static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr, unsigned BytesLeft, const DataLayout &DL)
Recursive helper to read bits out of global.
Type * getElementType() const
size_t size() const
size - Get the array size.
PointerType - Class to represent pointers.
uint64_t getElementOffset(unsigned Idx) const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isX86_MMXTy() const
isX86_MMXTy - Return true if this is X86 MMX.
Constant * stripPointerCasts()
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
ConstantFP - Floating Point Values [float, double].
opStatus fusedMultiplyAdd(const APFloat &, const APFloat &, roundingMode)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
static Constant * ConstantFoldFP(double(*NativeFP)(double), double V, Type *Ty)
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Value * getOperand(unsigned i) const
Class to represent integer types.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant * getAggregateElement(unsigned Elt) const
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
unsigned getPredicate() const
getPredicate - Return the ICMP or FCMP predicate value.
uint64_t getElementAsInteger(unsigned i) const
getElementAsInteger - If this is a sequential container of integers (of any size), return the specified element in the low bits of a uint64_t.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
PointerType * getPointerTo(unsigned AddrSpace=0)
getPointerTo - Return a pointer to the current type.
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCompareInstOperands - Attempt to constant fold a compare instruction (icmp/fcmp) with the...
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
GetUnderlyingObject - This method strips off any GEP address adjustments and pointer casts from the s...
static const fltSemantics IEEEhalf
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...
SequentialType - This is the superclass of the array, pointer and vector type classes.
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.
static Constant * ConstantFoldLoadInst(const LoadInst *LI, const DataLayout &DL)
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
unsigned getIntegerBitWidth() const
This is the shared class of boolean and integer constants.
static Constant * FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL)
Constant fold bitcast, symbolically evaluating it with DataLayout.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getVectorNumElements() const
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
double Log2(double Value)
Log2 - This function returns the log base 2 of the specified value.
static Constant * SymbolicallyEvaluateGEP(Type *SrcTy, ArrayRef< Constant * > Ops, Type *ResultTy, const DataLayout &DL, const TargetLibraryInfo *TLI)
If we can symbolically evaluate the GEP constant expression, do so.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Constant * ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
bool isVolatile() const
isVolatile - Return true if this is a load from a volatile memory location.
uint64_t getSizeInBytes() const
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getElementContainingOffset(uint64_t Offset) const
Given a valid byte offset into the structure, returns the structure index that contains it...
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static Constant * get(Type *Ty, double V)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
const fltSemantics & getFltSemantics() const
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
static Constant * SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1, const DataLayout &DL)
One of Op0/Op1 is a constant expression.
bool isAllOnesValue() const
isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.
VectorType - Class to represent vector types.
Class for arbitrary precision integers.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
APInt uadd_ov(const APInt &RHS, bool &Overflow) const
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
PointerType * getType() const
Global values are always pointers.
bool isAggregateType() const
isAggregateType - Return true if the type is an aggregate type.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const
Unsigned division operation.
static IntegerType * getInt32Ty(LLVMContext &C)
opStatus roundToIntegral(roundingMode)
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)
float convertToFloat() const
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
APInt sadd_ov(const APInt &RHS, bool &Overflow) const
static PointerType * getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS=0)
const APFloat & getValueAPF() const
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
getConstantStringInfo - This function computes the length of a null-terminated C string pointed to by...
static Constant * CastGEPIndices(Type *SrcTy, ArrayRef< Constant * > Ops, Type *ResultTy, const DataLayout &DL, const TargetLibraryInfo *TLI)
If array indices are not pointer-sized integers, explicitly cast them so that they aren't implicitly ...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
Constant * ConstantFoldLoadThroughGEPIndices(Constant *C, ArrayRef< Constant * > Indices)
ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr indices (with an implied zero ...
std::error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
static Constant * ConstantFoldConstantExpressionImpl(const ConstantExpr *CE, const DataLayout &DL, const TargetLibraryInfo *TLI, SmallPtrSetImpl< ConstantExpr * > &FoldedOps)
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
bool empty() const
empty - Check if the string is empty.