60 for (
unsigned i = 0; i != NumElts; ++i) {
80 assert(Op && Op->
isCast() &&
"Can't fold cast of cast without a cast!");
81 assert(DstTy && DstTy->
isFirstClassType() &&
"Invalid cast destination type");
108 if (
PointerType *DPTy = dyn_cast<PointerType>(DestTy))
109 if (PTy->getAddressSpace() == DPTy->getAddressSpace()
110 && DPTy->getElementType()->isSized()) {
115 Type *ElTy = PTy->getElementType();
116 while (ElTy != DPTy->getElementType()) {
117 if (
StructType *STy = dyn_cast<StructType>(ElTy)) {
118 if (STy->getNumElements() == 0)
break;
119 ElTy = STy->getElementType(0);
122 dyn_cast<SequentialType>(ElTy)) {
124 ElTy = STy->getElementType();
131 if (ElTy == DPTy->getElementType())
138 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
140 assert(DestPTy->getBitWidth() == SrcTy->getBitWidth() &&
141 "Not cast between same sized vectors!");
144 if (isa<ConstantAggregateZero>(V))
154 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
160 if (isa<ConstantPointerNull>(V))
182 FP->getValueAPF().bitcastToAPInt());
201 "Non-byte sized integer input");
203 assert(ByteSize &&
"Must be accessing some piece");
204 assert(ByteStart+ByteSize <= CSize &&
"Extracting invalid piece from input");
205 assert(ByteSize != CSize &&
"Should not extract everything");
209 APInt V = CI->getValue();
211 V = V.
lshr(ByteStart*8);
212 V = V.
trunc(ByteSize*8);
219 if (CE == 0)
return 0;
229 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS))
230 if (RHSC->isAllOnesValue())
252 case Instruction::LShr: {
258 if ((ShAmt & 7) != 0)
263 if (ByteStart >= CSize-ShAmt)
267 if (ByteStart+ByteSize+ShAmt <= CSize)
274 case Instruction::Shl: {
280 if ((ShAmt & 7) != 0)
285 if (ByteStart+ByteSize <= ShAmt)
289 if (ByteStart >= ShAmt)
296 case Instruction::ZExt: {
297 unsigned SrcBitSize =
301 if (ByteStart*8 >= SrcBitSize)
306 if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
311 if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
316 if ((ByteStart+ByteSize)*8 < SrcBitSize) {
317 assert((SrcBitSize&7) &&
"Shouldn't get byte sized case here");
339 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
345 if (
StructType *STy = dyn_cast<StructType>(Ty))
346 if (!STy->isPacked()) {
347 unsigned NumElems = STy->getNumElements();
355 for (
unsigned i = 1; i != NumElems; ++i)
370 if (!PTy->getElementType()->isIntegerTy(1))
373 PTy->getAddressSpace()),
398 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
407 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
415 unsigned NumElems = STy->getNumElements();
423 for (
unsigned i = 1; i != NumElems; ++i)
424 if (MemberAlign !=
getFoldedAlignOf(STy->getElementType(i), DestTy,
true)) {
435 if (!PTy->getElementType()->isIntegerTy(1))
439 PTy->getAddressSpace()),
463 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
471 if (
StructType *STy = dyn_cast<StructType>(Ty))
472 if (!STy->isPacked()) {
473 unsigned NumElems = STy->getNumElements();
481 for (
unsigned i = 1; i != NumElems; ++i)
512 if (isa<UndefValue>(V)) {
516 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
517 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
532 }
else if (CE->getOpcode() == Instruction::GetElementPtr) {
535 bool isAllNull =
true;
536 for (
unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
537 if (!CE->getOperand(i)->isNullValue()) {
550 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
554 VectorType *DestVecTy = cast<VectorType>(DestTy);
570 case Instruction::FPTrunc:
571 case Instruction::FPExt:
572 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
574 APFloat Val = FPC->getValueAPF();
586 case Instruction::FPToUI:
587 case Instruction::FPToSI:
588 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
589 const APFloat &V = FPC->getValueAPF();
592 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
595 APInt Val(DestBitWidth, x);
599 case Instruction::IntToPtr:
603 case Instruction::PtrToInt:
611 if (CE->getOpcode() == Instruction::GetElementPtr &&
612 CE->getOperand(0)->isNullValue()) {
614 cast<PointerType>(CE->getOperand(0)->getType())->getElementType();
615 if (CE->getNumOperands() == 2) {
618 bool isOne = isa<ConstantInt>(Idx) && cast<ConstantInt>(Idx)->isOne();
625 }
else if (CE->getNumOperands() == 3 &&
626 CE->getOperand(1)->isNullValue()) {
628 if (
StructType *STy = dyn_cast<StructType>(Ty))
629 if (!STy->isPacked()) {
630 ConstantInt *CI = cast<ConstantInt>(CE->getOperand(2));
632 STy->getNumElements() == 2 &&
633 STy->getElementType(0)->isIntegerTy(1)) {
647 case Instruction::UIToFP:
648 case Instruction::SIToFP:
650 APInt api = CI->getValue();
654 opc==Instruction::SIToFP,
659 case Instruction::ZExt:
661 uint32_t BitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
663 CI->getValue().zext(BitWidth));
666 case Instruction::SExt:
668 uint32_t BitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
670 CI->getValue().sext(BitWidth));
673 case Instruction::Trunc: {
674 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
677 CI->getValue().trunc(DestBitWidth));
683 if ((DestBitWidth & 7) == 0 &&
690 case Instruction::BitCast:
692 case Instruction::AddrSpaceCast:
709 if (Cond == 0)
break;
721 if (isa<UndefValue>(Cond)) {
722 if (isa<UndefValue>(V1))
return V1;
725 if (isa<UndefValue>(V1))
return V2;
726 if (isa<UndefValue>(V2))
return V1;
727 if (V1 == V2)
return V1;
729 if (
ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
731 if (TrueVal->getOperand(0) == Cond)
734 if (
ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
736 if (FalseVal->getOperand(0) == Cond)
745 if (isa<UndefValue>(Val))
750 if (isa<UndefValue>(Idx))
753 if (
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
754 uint64_t Index = CIdx->getZExtValue();
793 if (isa<UndefValue>(Mask))
797 if (isa<ConstantExpr>(Mask))
return 0;
803 for (
unsigned i = 0; i != MaskNumElts; ++i) {
810 if (
unsigned(Elt) >= SrcNumElts*2)
812 else if (
unsigned(Elt) >= SrcNumElts) {
848 NumElts =
ST->getNumElements();
850 NumElts = AT->getNumElements();
855 for (
unsigned i = 0; i != NumElts; ++i) {
857 if (C == 0)
return 0;
876 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
879 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
884 case Instruction::Add:
885 case Instruction::Sub:
888 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
891 case Instruction::Mul: {
894 if (((CI = dyn_cast<ConstantInt>(C1)) && CI->
getValue()[0]) ||
895 ((CI = dyn_cast<ConstantInt>(C2)) && CI->
getValue()[0]) ||
896 (isa<UndefValue>(C1) && isa<UndefValue>(C2)))
902 case Instruction::UDiv:
903 case Instruction::SDiv:
905 if (Opcode == Instruction::UDiv || Opcode == Instruction::SDiv)
910 case Instruction::URem:
911 case Instruction::SRem:
912 if (!isa<UndefValue>(C2))
916 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
919 case Instruction::LShr:
920 if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
924 case Instruction::AShr:
925 if (!isa<UndefValue>(C2))
927 else if (isa<UndefValue>(C1))
931 case Instruction::Shl:
932 if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
940 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
942 case Instruction::Add:
943 if (CI2->equalsInt(0))
return C1;
945 case Instruction::Sub:
946 if (CI2->equalsInt(0))
return C1;
948 case Instruction::Mul:
949 if (CI2->equalsInt(0))
return C2;
950 if (CI2->equalsInt(1))
953 case Instruction::UDiv:
954 case Instruction::SDiv:
955 if (CI2->equalsInt(1))
957 if (CI2->equalsInt(0))
960 case Instruction::URem:
961 case Instruction::SRem:
962 if (CI2->equalsInt(1))
964 if (CI2->equalsInt(0))
968 if (CI2->isZero())
return C2;
969 if (CI2->isAllOnesValue())
974 if (CE1->getOpcode() == Instruction::ZExt) {
975 unsigned DstWidth = CI2->
getType()->getBitWidth();
979 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
984 if (CE1->getOpcode() == Instruction::PtrToInt &&
985 isa<GlobalValue>(CE1->getOperand(0))) {
986 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
990 if (isa<Function>(GV))
991 GVAlign = std::max(GVAlign, 4U);
994 unsigned DstWidth = CI2->getType()->getBitWidth();
995 unsigned SrcWidth = std::min(DstWidth,
Log2_32(GVAlign));
999 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1006 if (CI2->equalsInt(0))
return C1;
1007 if (CI2->isAllOnesValue())
1011 if (CI2->equalsInt(0))
return C1;
1014 switch (CE1->getOpcode()) {
1016 case Instruction::ICmp:
1017 case Instruction::FCmp:
1019 assert(CI2->equalsInt(1));
1023 CE1->getOperand(1));
1027 case Instruction::AShr:
1030 if (CE1->getOpcode() == Instruction::ZExt)
1034 }
else if (isa<ConstantInt>(C1)) {
1041 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1042 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1043 const APInt &C1V = CI1->getValue();
1044 const APInt &C2V = CI2->getValue();
1048 case Instruction::Add:
1050 case Instruction::Sub:
1052 case Instruction::Mul:
1054 case Instruction::UDiv:
1055 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1057 case Instruction::SDiv:
1058 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1062 case Instruction::URem:
1063 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1065 case Instruction::SRem:
1066 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1076 case Instruction::Shl: {
1083 case Instruction::LShr: {
1090 case Instruction::AShr: {
1101 case Instruction::SDiv:
1102 case Instruction::UDiv:
1103 case Instruction::URem:
1104 case Instruction::SRem:
1105 case Instruction::LShr:
1106 case Instruction::AShr:
1107 case Instruction::Shl:
1108 if (CI1->equalsInt(0))
return C1;
1113 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1114 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1115 APFloat C1V = CFP1->getValueAPF();
1116 APFloat C2V = CFP2->getValueAPF();
1121 case Instruction::FAdd:
1124 case Instruction::FSub:
1127 case Instruction::FMul:
1130 case Instruction::FDiv:
1133 case Instruction::FRem:
1142 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
1163 if (!isa<ConstantExpr>(T) || cast<ConstantExpr>(
T)->getOpcode() != Opcode)
1166 }
else if (isa<ConstantExpr>(C2)) {
1176 case Instruction::Add:
1177 case Instruction::Sub:
1179 case Instruction::Mul:
1181 case Instruction::Shl:
1182 case Instruction::LShr:
1183 case Instruction::AShr:
1187 case Instruction::SDiv:
1188 case Instruction::UDiv:
1192 case Instruction::URem:
1193 case Instruction::SRem:
1209 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1210 if (STy->isOpaque())
return true;
1213 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
1217 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
1231 if (C1 == C2)
return 0;
1235 if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
1246 if (C1 == C2)
return 0;
1255 if (cast<ConstantInt>(C1)->getSExtValue() <
1256 cast<ConstantInt>(C2)->getSExtValue())
1275 "Cannot compare values of different types!");
1280 if (!isa<ConstantExpr>(V1)) {
1281 if (!isa<ConstantExpr>(V2)) {
1310 case Instruction::FPTrunc:
1311 case Instruction::FPExt:
1312 case Instruction::UIToFP:
1313 case Instruction::SIToFP:
1340 "Cannot compare different types of values!");
1343 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1344 !isa<BlockAddress>(V1)) {
1345 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(
V2) &&
1346 !isa<BlockAddress>(V2)) {
1373 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1374 if (isa<ConstantExpr>(V2)) {
1385 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1387 if (!isa<GlobalAlias>(GV) && !isa<GlobalAlias>(GV2))
1388 if (!GV->hasExternalWeakLinkage() || !GV2->hasExternalWeakLinkage())
1390 }
else if (isa<BlockAddress>(V2)) {
1393 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1396 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV))
1399 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1400 if (isa<ConstantExpr>(V2)) {
1411 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1415 if (BA2->getFunction() != BA->getFunction())
1419 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1420 "Canonicalization guarantee!");
1430 case Instruction::Trunc:
1431 case Instruction::FPTrunc:
1432 case Instruction::FPExt:
1433 case Instruction::FPToUI:
1434 case Instruction::FPToSI:
1437 case Instruction::UIToFP:
1438 case Instruction::SIToFP:
1439 case Instruction::BitCast:
1440 case Instruction::ZExt:
1441 case Instruction::SExt:
1446 if (CE1->
getOpcode() == Instruction::ZExt) isSigned =
false;
1447 if (CE1->
getOpcode() == Instruction::SExt) isSigned =
true;
1454 case Instruction::GetElementPtr:
1457 if (isa<ConstantPointerNull>(V2)) {
1460 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1461 if (GV->hasExternalWeakLinkage())
1469 }
else if (isa<ConstantPointerNull>(CE1Op0)) {
1480 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1481 if (isa<ConstantPointerNull>(CE1Op0)) {
1482 if (GV2->hasExternalWeakLinkage())
1490 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1498 "Surprising getelementptr!");
1513 case Instruction::GetElementPtr:
1516 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1517 if (CE1Op0 != CE2Op0)
1577 VT->getNumElements());
1589 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1594 (isa<UndefValue>(C1) && isa<UndefValue>(C2)))
1603 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
1605 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1613 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
1615 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1627 if (isa<ConstantInt>(C2))
1637 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1638 APInt V1 = cast<ConstantInt>(C1)->getValue();
1639 APInt V2 = cast<ConstantInt>(C2)->getValue();
1653 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1654 APFloat C1V = cast<ConstantFP>(C1)->getValueAPF();
1655 APFloat C2V = cast<ConstantFP>(C2)->getValueAPF();
1847 if (CE2->getOpcode() == Instruction::BitCast &&
1860 if (CE1Inverse == CE1Op0) {
1870 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1884 template<
typename IndexTy>
1887 if (Idxs.
empty())
return true;
1890 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
1894 if (!cast<ConstantInt>(Idxs[0])->isOne())
1896 for (
unsigned i = 1, e = Idxs.
size(); i != e; ++i)
1897 if (!cast<Constant>(Idxs[i])->isNullValue())
1905 if (
const PointerType *PTy = dyn_cast<PointerType>(STy))
1907 return PTy->getElementType()->isSized();
1909 uint64_t NumElements = 0;
1911 if (
const ArrayType *ATy = dyn_cast<ArrayType>(STy))
1912 NumElements = ATy->getNumElements();
1913 else if (
const VectorType *VTy = dyn_cast<VectorType>(STy))
1914 NumElements = VTy->getNumElements();
1916 assert((isa<ArrayType>(STy) || NumElements > 0) &&
1917 "didn't expect non-array type to have zero elements!");
1926 if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements))
1933 template<
typename IndexTy>
1937 if (Idxs.
empty())
return C;
1938 Constant *Idx0 = cast<Constant>(Idxs[0]);
1942 if (isa<UndefValue>(C)) {
1945 assert(Ty != 0 &&
"Invalid indices for GEP!");
1951 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
1952 if (!cast<Constant>(Idxs[i])->isNullValue()) {
1959 assert(Ty != 0 &&
"Invalid indices for GEP!");
1970 if (CE->getOpcode() == Instruction::GetElementPtr) {
1994 bool PerformFold =
false;
1997 else if (
SequentialType *STy = dyn_cast_or_null<SequentialType>(LastTy))
1998 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
2003 NewIndices.
reserve(Idxs.
size() + CE->getNumOperands());
2004 for (
unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
2005 NewIndices.
push_back(CE->getOperand(i));
2013 if (IdxTy != Idx0->
getType()) {
2029 cast<GEPOperator>(CE)->isInBounds());
2046 if (SrcPtrTy && DstPtrTy) {
2051 if (SrcArrayTy && DstArrayTy
2067 for (
unsigned i = 0, e = Idxs.
size(); i != e;
2068 Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
2069 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
2070 if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
2071 if (CI->getSExtValue() > 0 &&
2073 if (isa<SequentialType>(Prev)) {
2077 uint64_t NumElements = 0;
2078 if (
const ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2079 NumElements = ATy->getNumElements();
2081 NumElements = cast<VectorType>(Ty)->getNumElements();
2086 Constant *PrevIdx = cast<Constant>(Idxs[i-1]);
2094 if (!Div->getType()->isIntegerTy(64))
2112 if (!NewIdxs.
empty()) {
2113 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2114 if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
2120 if (!Unknown && !inBounds &&
static int getMaskValue(Constant *Mask, unsigned i)
static Constant * FoldBitCast(Constant *V, Type *DestTy)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
opStatus divide(const APFloat &, roundingMode)
void push_back(const T &Elt)
Type * getIndexedType() const
static ConstantInt * getFalse(LLVMContext &Context)
static IntegerType * getInt1Ty(LLVMContext &C)
uint64_t getZExtValue() const
Get zero extended value.
static const fltSemantics IEEEdouble
unsigned getAlignment() const
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getNumOperands() const
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static Constant * getFoldedOffsetOf(Type *Ty, Constant *FieldNo, Type *DestTy, bool Folded)
Predicate getInversePredicate() const
Return the inverse of the instruction's predicate.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
gep_type_iterator gep_type_end(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
bool isSigned() const
Determine if this instruction is using a signed comparison.
static Constant * getExtractElement(Constant *Vec, Constant *Idx)
0 1 0 0 True if ordered and less than
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS)
static Constant * getFoldedAlignOf(Type *Ty, Type *DestTy, bool Folded)
static const fltSemantics Bogus
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
static Constant * getNullValue(Type *Ty)
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
1 0 0 1 True if unordered or equal
APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const
Unsigned remainder operation.
static const fltSemantics x87DoubleExtended
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
const APInt & getValue() const
Return the constant's value.
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
#define llvm_unreachable(msg)
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, bool isSigned)
static Constant * BitCastConstantVector(Constant *CV, VectorType *DstTy)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
static Constant * get(ArrayRef< Constant * > V)
0 1 0 1 True if ordered and less than or equal
static const fltSemantics IEEEquad
Type * getVectorElementType() const
uint64_t getZExtValue() const
Return the zero extended value.
static Constant * getSizeOf(Type *Ty)
static unsigned foldConstantCastPair(unsigned opc, ConstantExpr *Op, Type *DstTy)
Determine if it is valid to fold a cast of a cast.
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static int IdxCompare(Constant *C1, Constant *C2, Type *ElTy)
bool isAssociative() 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.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS)
bool sgt(const APInt &RHS) const
Signed greather than comparison.
bool isFirstClassType() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool isFloatingPointTy() const
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const
Left-shift function.
unsigned getNumElements() const
Return the number of elements in the Vector type.
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
opStatus mod(const APFloat &, roundingMode)
C fmod, or llvm frem.
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool isX86_MMXTy() const
isX86_MMXTy - Return true if this is X86 MMX.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
cmpResult compare(const APFloat &) const
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
LLVM Constant Representation.
static Constant * getFoldedSizeOf(Type *Ty, Type *DestTy, bool Folded)
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.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
bool sle(const APInt &RHS) const
Signed less or equal comparison.
unsigned getBitWidth() const
Return the number of bits in the APInt.
opStatus convert(const fltSemantics &, roundingMode, bool *)
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const
Signed division function for APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
bool isCommutative() const
Integer representation type.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
bool empty() const
empty - Check if the array is empty.
static Constant * getNot(Constant *C)
Constant * getAggregateElement(unsigned Elt) const
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
void append(in_iter in_start, in_iter in_end)
bool isFP128Ty() const
isFP128Ty - Return true if this is 'fp128'.
static UndefValue * get(Type *T)
LLVMContext & getContext() const
All values hold a context through their type.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const
Function for signed remainder operation.
Constant * ConstantFoldGetElementPtr(Constant *C, bool inBounds, ArrayRef< Constant * > Idxs)
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
0 0 1 0 True if ordered and greater than
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast or a PtrToInt cast constant expression.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
static Constant * getBitCast(Constant *C, Type *Ty)
static Constant * ExtractConstantBytes(Constant *C, unsigned ByteStart, unsigned ByteSize)
static const fltSemantics PPCDoubleDouble
Class for constant integers.
bool slt(const APInt &RHS) const
Signed less than comparison.
unsigned getVectorNumElements() const
opStatus add(const APFloat &, roundingMode)
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
1 1 0 0 True if unordered or less than
opStatus multiply(const APFloat &, roundingMode)
static Constant * getNUWMul(Constant *C1, Constant *C2)
bool isTrueWhenEqual() const
Determine if this is true when both operands are the same.
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine if a cast pair is eliminable.
Predicate getSwappedPredicate() const
Return the predicate as if the operands were swapped.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static Constant * getTrunc(Constant *C, Type *Ty)
static Constant * get(Type *Ty, double V)
const fltSemantics & getFltSemantics() const
static bool isMaybeZeroSizedType(Type *Ty)
static ConstantInt * getTrue(LLVMContext &Context)
bool isAllOnesValue() const
unsigned Log2_32(uint32_t Value)
Class for arbitrary precision integers.
bool isCast() const
Return true if this is a convert constant expression.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isGEPWithNoNotionalOverIndexing() const
Return true if this is a getelementptr expression and all the index operands are compile-time known i...
bool isAllOnesValue() const
Determine if all bits are set.
Constant * ConstantFoldCompareInstruction(unsigned short predicate, Constant *C1, Constant *C2)
static const fltSemantics IEEEsingle
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
bool isX86_FP80Ty() const
isX86_FP80Ty - Return true if this is x86 long double.
static Constant * getSExt(Constant *C, Type *Ty)
static Constant * getInBoundsGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList)
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const
Unsigned division operation.
static IntegerType * getInt32Ty(LLVMContext &C)
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
unsigned greater or equal
static bool isInBoundsIndices(ArrayRef< IndexTy > Idxs)
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Infer the opcode for cast operand and type.
static Constant * getOr(Constant *C1, Constant *C2)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
0 1 1 0 True if ordered and operands are unequal
unsigned getPrimitiveSizeInBits() const
1 0 1 0 True if unordered or greater than
static Type * getIndexedType(Type *Ptr, ArrayRef< Value * > IdxList)
static Constant * getSRem(Constant *C1, Constant *C2)
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
static VectorType * get(Type *ElementType, unsigned NumElements)
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2)
Return an ICmp or FCmp comparison operator constant expression.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
static Constant * getAlignOf(Type *Ty)
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
int64_t getSExtValue() const
Return the sign extended value.
0 0 1 1 True if ordered and greater than or equal
static Constant * getCast(unsigned ops, Constant *C, Type *Ty)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
opStatus subtract(const APFloat &, roundingMode)
static Constant * ConstantFoldGetElementPtrImpl(Constant *C, bool inBounds, ArrayRef< IndexTy > Idxs)
bool isOne() const
Determine if the value is one.
static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2)
0 0 0 0 Always false (always folded)
static Constant * getXor(Constant *C1, Constant *C2)
static bool isIndexInRangeOfSequentialType(const SequentialType *STy, const ConstantInt *CI)
Test whether a given ConstantInt is in-range for a SequentialType.
gep_type_iterator gep_type_begin(const User *GEP)