42 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
43 return CFP->isZero() && CFP->isNegative();
47 if (CV->getElementType()->isFloatingPointTy() && CV->isSplat())
48 if (CV->getElementAsAPFloat(0).isNegZero())
52 if (
ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
53 if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative())
68 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
73 if (CV->getElementType()->isFloatingPointTy() && CV->isSplat())
74 if (CV->getElementAsAPFloat(0).isZero())
78 if (
ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
79 if (SplatCFP && SplatCFP->isZero())
88 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
92 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
93 return CFP->isZero() && !CFP->isNegative();
97 return isa<ConstantAggregateZero>(
this) || isa<ConstantPointerNull>(
this) ||
98 isa<ConstantTokenNone>(
this);
103 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
104 return CI->isMinusOne();
107 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
108 return CFP->getValueAPF().bitcastToAPInt().isAllOnesValue();
113 return Splat->isAllOnesValue();
118 if (CV->getElementType()->isFloatingPointTy())
119 return CV->getElementAsAPFloat(0).bitcastToAPInt().isAllOnesValue();
120 return CV->getElementAsAPInt(0).isAllOnesValue();
129 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
133 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
134 return CFP->getValueAPF().bitcastToAPInt().isOneValue();
139 return Splat->isOneValue();
144 if (CV->getElementType()->isFloatingPointTy())
145 return CV->getElementAsAPFloat(0).bitcastToAPInt().isOneValue();
146 return CV->getElementAsAPInt(0).isOneValue();
155 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
156 return CI->isMinValue(
true);
159 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
160 return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
165 return Splat->isMinSignedValue();
170 if (CV->getElementType()->isFloatingPointTy())
171 return CV->getElementAsAPFloat(0).bitcastToAPInt().isMinSignedValue();
172 return CV->getElementAsAPInt(0).isMinSignedValue();
181 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
182 return !CI->isMinValue(
true);
185 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
186 return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
191 return Splat->isNotMinSignedValue();
196 if (CV->getElementType()->isFloatingPointTy())
197 return !CV->getElementAsAPFloat(0).bitcastToAPInt().isMinSignedValue();
198 return !CV->getElementAsAPInt(0).isMinSignedValue();
251 if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
255 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
279 return Elt < CC->getNumOperands() ? CC->getOperand(Elt) :
nullptr;
282 return Elt < CAZ->getNumElements() ? CAZ->getElementValue(Elt) :
nullptr;
284 if (
const UndefValue *UV = dyn_cast<UndefValue>(
this))
285 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
288 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
294 assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
306 #define HANDLE_CONSTANT(Name) \
307 case Value::Name##Val: \
308 cast<Name>(this)->destroyConstantImpl(); \
310 #include "llvm/IR/Value.def"
322 #ifndef NDEBUG // Only in -g mode...
323 if (!isa<Constant>(V)) {
324 dbgs() <<
"While deleting: " << *
this
325 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
329 assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
350 if (
ConstantExpr *
Op = dyn_cast<ConstantExpr>(CE->getOperand(i))) {
357 switch (CE->getOpcode()) {
360 case Instruction::UDiv:
361 case Instruction::SDiv:
362 case Instruction::URem:
363 case Instruction::SRem:
365 if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
385 while (!WorkList.
empty()) {
387 if (
const auto *GV = dyn_cast<GlobalValue>(WorkItem))
394 if (Visited.
insert(ConstOp).second)
402 auto DLLImportPredicate = [](
const GlobalValue *GV) {
403 return GV->isThreadLocal();
409 auto DLLImportPredicate = [](
const GlobalValue *GV) {
410 return GV->hasDLLImportStorageClass();
418 if (!UC || isa<GlobalValue>(UC))
428 if (isa<GlobalValue>(
this))
431 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
432 return BA->getFunction()->needsRelocation();
438 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this))
439 if (CE->getOpcode() == Instruction::Sub) {
442 if (LHS && RHS && LHS->
getOpcode() == Instruction::PtrToInt &&
443 RHS->getOpcode() == Instruction::PtrToInt &&
445 isa<BlockAddress>(RHS->getOperand(0)) &&
446 cast<BlockAddress>(LHS->
getOperand(0))->getFunction() ==
447 cast<BlockAddress>(RHS->getOperand(0))->getFunction())
461 if (isa<GlobalValue>(C))
return false;
465 if (!User)
return false;
470 const_cast<Constant*
>(
C)->destroyConstant();
495 if (LastNonDeadUser ==
E) {
533 if (
auto *VTy = dyn_cast<VectorType>(Ty))
541 if (
auto *VTy = dyn_cast<VectorType>(Ty))
550 std::unique_ptr<ConstantInt> &Slot = pImpl->
IntConstants[V];
564 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
575 return get(Ty, V,
true);
579 return get(Ty, V,
true);
585 "ConstantInt type doesn't match the type implied by its value!");
588 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
599 void ConstantInt::destroyConstantImpl() {
633 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
647 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
658 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
669 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
688 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
704 "Unknown FP format");
717 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
734 void ConstantFP::destroyConstantImpl() {
751 if (isa<SequentialType>(
getType()))
757 if (isa<SequentialType>(
getType()))
764 if (
auto *AT = dyn_cast<ArrayType>(Ty))
765 return AT->getNumElements();
766 if (
auto *VT = dyn_cast<VectorType>(Ty))
767 return VT->getNumElements();
784 if (isa<SequentialType>(
getType()))
790 if (isa<SequentialType>(
getType()))
797 if (
auto *
ST = dyn_cast<SequentialType>(Ty))
798 return ST->getNumElements();
806 template <
typename ItTy,
typename EltTy>
808 for (; Start !=
End; ++Start)
814 template <
typename SequentialTy,
typename ElementTy>
816 assert(!V.
empty() &&
"Cannot get empty int sequence.");
820 if (
auto *CI = dyn_cast<ConstantInt>(C))
824 return SequentialTy::get(V[0]->getContext(), Elts);
827 template <
typename SequentialTy,
typename ElementTy>
829 assert(!V.
empty() &&
"Cannot get empty FP sequence.");
833 if (
auto *CFP = dyn_cast<ConstantFP>(C))
834 Elts.
push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
837 return SequentialTy::getFP(V[0]->getContext(), Elts);
840 template <
typename SequenceTy>
847 if (CI->getType()->isIntegerTy(8))
848 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
849 else if (CI->getType()->isIntegerTy(16))
850 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
851 else if (CI->getType()->isIntegerTy(32))
852 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
853 else if (CI->getType()->isIntegerTy(64))
854 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
855 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
856 if (CFP->getType()->isHalfTy())
857 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
858 else if (CFP->getType()->isFloatTy())
859 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
860 else if (CFP->getType()->isDoubleTy())
861 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
874 if (
auto *
ST = dyn_cast<StructType>(T))
877 for (
unsigned I = 0,
E = V.
size();
I !=
E; ++
I)
879 "Initializer for composite element doesn't match!");
885 "Invalid initializer for constant array");
899 for (
unsigned i = 0, e = V.
size(); i != e; ++i) {
901 "Wrong type in array element initializer");
917 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
926 unsigned VecSize = V.
size();
928 for (
unsigned i = 0; i != VecSize; ++i)
938 "ConstantStruct::getTypeForElements cannot be called on empty list");
945 "Invalid initializer for constant struct");
951 "Incorrect # elements specified to ConstantStruct::get");
955 bool isUndef =
false;
958 isUndef = isa<UndefValue>(V[0]);
959 isZero = V[0]->isNullValue();
960 if (isUndef || isZero) {
961 for (
unsigned i = 0, e = V.
size(); i != e; ++i) {
964 if (!isa<UndefValue>(V[i]))
980 "Invalid initializer for constant vector");
998 bool isZero = C->isNullValue();
999 bool isUndef = isa<UndefValue>(
C);
1001 if (isZero || isUndef) {
1002 for (
unsigned i = 1, e = V.
size(); i != e; ++i)
1004 isZero = isUndef =
false;
1017 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1027 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1043 void ConstantTokenNone::destroyConstantImpl() {
1059 if (
getOpcode() != Instruction::GetElementPtr)
return false;
1066 for (; GEPI !=
E; ++GEPI, ++OI) {
1067 if (isa<UndefValue>(*OI))
1071 (CI->getValue().getActiveBits() > 64 ||
1081 return getOpcode() == Instruction::ExtractValue ||
1082 getOpcode() == Instruction::InsertValue;
1087 dyn_cast<ExtractValueConstantExpr>(
this))
1088 return EVCE->Indices;
1090 return cast<InsertValueConstantExpr>(
this)->Indices;
1094 return cast<CompareConstantExpr>(
this)->predicate;
1100 "Replacing operand with value of different type!");
1102 return const_cast<ConstantExpr*>(
this);
1112 bool OnlyIfReduced,
Type *SrcTy)
const {
1119 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1121 case Instruction::Trunc:
1122 case Instruction::ZExt:
1123 case Instruction::SExt:
1124 case Instruction::FPTrunc:
1125 case Instruction::FPExt:
1126 case Instruction::UIToFP:
1127 case Instruction::SIToFP:
1128 case Instruction::FPToUI:
1129 case Instruction::FPToSI:
1130 case Instruction::PtrToInt:
1131 case Instruction::IntToPtr:
1132 case Instruction::BitCast:
1133 case Instruction::AddrSpaceCast:
1137 case Instruction::InsertElement:
1140 case Instruction::ExtractElement:
1142 case Instruction::InsertValue:
1145 case Instruction::ExtractValue:
1147 case Instruction::ShuffleVector:
1150 case Instruction::GetElementPtr: {
1151 auto *GEPO = cast<GEPOperator>(
this);
1154 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1155 GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1157 case Instruction::ICmp:
1158 case Instruction::FCmp:
1175 return Val == 0 || Val == 1;
1182 return Val == 0 || Val == 1 || Val == -1;
1183 return isIntN(NumBits, Val);
1239 "Cannot create an aggregate zero of non-aggregate type!");
1241 std::unique_ptr<ConstantAggregateZero> &Entry =
1250 void ConstantAggregateZero::destroyConstantImpl() {
1255 void ConstantArray::destroyConstantImpl() {
1264 void ConstantStruct::destroyConstantImpl() {
1269 void ConstantVector::destroyConstantImpl() {
1274 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1275 if (isa<ConstantAggregateZero>(
this))
1278 return CV->getSplatValue();
1280 return CV->getSplatValue();
1295 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1296 return CI->getValue();
1299 assert(C && isa<ConstantInt>(C) &&
"Not a vector of numbers!");
1300 return cast<ConstantInt>(
C)->getValue();
1307 std::unique_ptr<ConstantPointerNull> &Entry =
1316 void ConstantPointerNull::destroyConstantImpl() {
1329 void UndefValue::destroyConstantImpl() {
1354 BB->AdjustBlockAddressRefCount(1);
1362 assert(F &&
"Block must have a parent");
1365 assert(BA &&
"Refcount and block address map disagree!");
1370 void BlockAddress::destroyConstantImpl() {
1376 Value *BlockAddress::handleOperandChangeImpl(
Value *From,
Value *To) {
1385 assert(From == NewBB &&
"From does not match any operand");
1386 NewBB = cast<BasicBlock>(To);
1418 bool OnlyIfReduced =
false) {
1436 bool OnlyIfReduced) {
1439 assert(C && Ty &&
"Null arguments to getCast");
1445 case Instruction::Trunc:
1446 return getTrunc(C, Ty, OnlyIfReduced);
1447 case Instruction::ZExt:
1448 return getZExt(C, Ty, OnlyIfReduced);
1449 case Instruction::SExt:
1450 return getSExt(C, Ty, OnlyIfReduced);
1451 case Instruction::FPTrunc:
1453 case Instruction::FPExt:
1455 case Instruction::UIToFP:
1457 case Instruction::SIToFP:
1459 case Instruction::FPToUI:
1461 case Instruction::FPToSI:
1463 case Instruction::PtrToInt:
1465 case Instruction::IntToPtr:
1467 case Instruction::BitCast:
1469 case Instruction::AddrSpaceCast:
1524 (SrcBits == DstBits ? Instruction::BitCast :
1525 (SrcBits > DstBits ? Instruction::Trunc :
1526 (isSigned ? Instruction::SExt : Instruction::ZExt)));
1527 return getCast(opcode, C, Ty);
1535 if (SrcBits == DstBits)
1538 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
1539 return getCast(opcode, C, Ty);
1547 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1551 "SrcTy must be larger than DestTy for Trunc!");
1553 return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
1561 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1565 "SrcTy must be smaller than DestTy for SExt!");
1567 return getFoldedCast(Instruction::SExt, C, Ty, OnlyIfReduced);
1575 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1579 "SrcTy must be smaller than DestTy for ZExt!");
1581 return getFoldedCast(Instruction::ZExt, C, Ty, OnlyIfReduced);
1589 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1592 "This is an illegal floating point truncation!");
1593 return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
1601 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1604 "This is an illegal floating point extension!");
1605 return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
1613 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1615 "This is an illegal uint to floating point cast!");
1616 return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
1624 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1626 "This is an illegal sint to floating point cast!");
1627 return getFoldedCast(Instruction::SIToFP, C, Ty, OnlyIfReduced);
1635 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1637 "This is an illegal floating point to uint cast!");
1638 return getFoldedCast(Instruction::FPToUI, C, Ty, OnlyIfReduced);
1646 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1648 "This is an illegal floating point to sint cast!");
1649 return getFoldedCast(Instruction::FPToSI, C, Ty, OnlyIfReduced);
1653 bool OnlyIfReduced) {
1655 "PtrToInt source must be pointer or pointer vector");
1657 "PtrToInt destination must be integer or integer vector");
1658 assert(isa<VectorType>(C->
getType()) == isa<VectorType>(DstTy));
1659 if (isa<VectorType>(C->
getType()))
1661 "Invalid cast between a different number of vector elements");
1662 return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
1666 bool OnlyIfReduced) {
1668 "IntToPtr source must be integer or integer vector");
1670 "IntToPtr destination must be a pointer or pointer vector");
1671 assert(isa<VectorType>(C->
getType()) == isa<VectorType>(DstTy));
1672 if (isa<VectorType>(C->
getType()))
1674 "Invalid cast between a different number of vector elements");
1675 return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
1679 bool OnlyIfReduced) {
1681 "Invalid constantexpr bitcast!");
1685 if (C->
getType() == DstTy)
return C;
1687 return getFoldedCast(Instruction::BitCast, C, DstTy, OnlyIfReduced);
1691 bool OnlyIfReduced) {
1693 "Invalid constantexpr addrspacecast!");
1699 Type *DstElemTy = DstScalarTy->getElementType();
1702 if (
VectorType *VT = dyn_cast<VectorType>(DstTy)) {
1708 return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
1712 unsigned Flags,
Type *OnlyIfReducedTy) {
1714 assert(Opcode >= Instruction::BinaryOpsBegin &&
1715 Opcode < Instruction::BinaryOpsEnd &&
1716 "Invalid opcode in binary constant expression");
1718 "Operand types in binary constant expression should match");
1723 case Instruction::Sub:
1724 case Instruction::Mul:
1727 "Tried to create an integer operation on a non-integer type!");
1729 case Instruction::FAdd:
1730 case Instruction::FSub:
1731 case Instruction::FMul:
1734 "Tried to create a floating-point operation on a "
1735 "non-floating-point type!");
1737 case Instruction::UDiv:
1738 case Instruction::SDiv:
1741 "Tried to create an arithmetic operation on a non-arithmetic type!");
1743 case Instruction::FDiv:
1746 "Tried to create an arithmetic operation on a non-arithmetic type!");
1748 case Instruction::URem:
1749 case Instruction::SRem:
1752 "Tried to create an arithmetic operation on a non-arithmetic type!");
1754 case Instruction::FRem:
1757 "Tried to create an arithmetic operation on a non-arithmetic type!");
1759 case Instruction::And:
1760 case Instruction::Or:
1761 case Instruction::Xor:
1764 "Tried to create a logical operation on a non-integral type!");
1766 case Instruction::Shl:
1767 case Instruction::LShr:
1768 case Instruction::AShr:
1771 "Tried to create a shift operation on a non-integer type!");
1781 if (OnlyIfReducedTy == C1->
getType())
1833 Constant *C2,
bool OnlyIfReduced) {
1836 switch (Predicate) {
1844 return getFCmp(Predicate, C1, C2, OnlyIfReduced);
1850 return getICmp(Predicate, C1, C2, OnlyIfReduced);
1855 Type *OnlyIfReducedTy) {
1861 if (OnlyIfReducedTy == V1->
getType())
1874 Type *OnlyIfReducedTy) {
1888 assert(DestTy &&
"GEP indices invalid!");
1892 unsigned NumVecElts = 0;
1895 else for (
auto Idx : Idxs)
1896 if (Idx->getType()->isVectorTy())
1897 NumVecElts = Idx->getType()->getVectorNumElements();
1902 if (OnlyIfReducedTy == ReqTy)
1906 std::vector<Constant*> ArgVec;
1907 ArgVec.reserve(1 + Idxs.size());
1908 ArgVec.push_back(C);
1909 for (
unsigned i = 0, e = Idxs.size(); i != e; ++i) {
1911 Idxs[i]->
getType()->getVectorNumElements() == NumVecElts) &&
1912 "getelementptr index type missmatch");
1914 Constant *Idx = cast<Constant>(Idxs[i]);
1917 ArgVec.push_back(Idx);
1920 unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
1921 if (InRangeIndex && *InRangeIndex < 63)
1922 SubClassOptionalData |= (*InRangeIndex + 1) << 1;
1924 SubClassOptionalData,
None, Ty);
1931 Constant *RHS,
bool OnlyIfReduced) {
1934 "Invalid ICmp Predicate");
1956 Constant *RHS,
bool OnlyIfReduced) {
1959 "Invalid FCmp Predicate");
1981 Type *OnlyIfReducedTy) {
1983 "Tried to create extractelement operation on non-vector type!");
1985 "Extractelement index must be an integer type!");
1991 if (OnlyIfReducedTy == ReqTy)
2005 "Tried to create insertelement operation on non-vector type!");
2007 "Insertelement types must match!");
2009 "Insertelement index must be i32 type!");
2014 if (OnlyIfReducedTy == Val->
getType())
2018 Constant *ArgVec[] = { Val, Elt, Idx };
2028 "Invalid shuffle vector constant expr operands!");
2037 if (OnlyIfReducedTy == ShufTy)
2050 Type *OnlyIfReducedTy) {
2052 "Non-first-class type for constant insertvalue expression");
2056 "insertvalue indices invalid!");
2062 if (OnlyIfReducedTy == ReqTy)
2073 Type *OnlyIfReducedTy) {
2075 "Tried to create extractelement operation on non-first-class type!");
2079 assert(ReqTy &&
"extractvalue indices invalid!");
2082 "Non-first-class type for constant extractvalue expression");
2086 if (OnlyIfReducedTy == ReqTy)
2098 "Cannot NEG a nonintegral value!");
2105 "Cannot FNEG a non-floating-point value!");
2111 "Cannot NOT a nonintegral value!");
2116 bool HasNUW,
bool HasNSW) {
2123 return get(Instruction::FAdd, C1, C2);
2127 bool HasNUW,
bool HasNSW) {
2130 return get(Instruction::Sub, C1, C2,
Flags);
2134 return get(Instruction::FSub, C1, C2);
2138 bool HasNUW,
bool HasNSW) {
2141 return get(Instruction::Mul, C1, C2,
Flags);
2145 return get(Instruction::FMul, C1, C2);
2149 return get(Instruction::UDiv, C1, C2,
2154 return get(Instruction::SDiv, C1, C2,
2159 return get(Instruction::FDiv, C1, C2);
2163 return get(Instruction::URem, C1, C2);
2167 return get(Instruction::SRem, C1, C2);
2171 return get(Instruction::FRem, C1, C2);
2175 return get(Instruction::And, C1, C2);
2179 return get(Instruction::Or, C1, C2);
2183 return get(Instruction::Xor, C1, C2);
2187 bool HasNUW,
bool HasNSW) {
2190 return get(Instruction::Shl, C1, C2,
Flags);
2194 return get(Instruction::LShr, C1, C2,
2199 return get(Instruction::AShr, C1, C2,
2210 case Instruction::Or:
2211 case Instruction::Xor:
2214 case Instruction::Mul:
2217 case Instruction::And:
2228 case Instruction::Or:
2231 case Instruction::And:
2232 case Instruction::Mul:
2238 void ConstantExpr::destroyConstantImpl() {
2246 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2250 (IdxList.size() + 1),
2251 IdxList.size() + 1),
2252 SrcElementTy(SrcElementTy),
2256 for (
unsigned i = 0,
E = IdxList.
size(); i !=
E; ++i)
2257 OperandList[i+1] = IdxList[i];
2261 return SrcElementTy;
2265 return ResElementTy;
2281 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2282 switch (
IT->getBitWidth()) {
2296 return AT->getNumElements();
2306 const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2343 Entry = &Node->Next, Node = *Entry)
2344 if (Node->getType() == Ty)
2349 if (isa<ArrayType>(Ty))
2352 assert(isa<VectorType>(Ty));
2356 void ConstantDataSequential::destroyConstantImpl() {
2364 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2369 if (!(*Entry)->Next) {
2372 assert((*Entry) ==
this &&
"Hash mismatch in ConstantDataSequential");
2378 Entry = &Node->Next, Node = *Entry) {
2379 assert(Node &&
"Didn't find entry in its uniquing hash table!");
2382 *Entry = Node->Next;
2398 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2403 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2408 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2413 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2418 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2423 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2435 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2441 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2447 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2454 const uint8_t *
Data =
reinterpret_cast<const uint8_t *
>(Str.
data());
2461 return get(
Context, ElementVals);
2469 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2474 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2479 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2484 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2489 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2494 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2506 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2512 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2518 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2524 "Element type not compatible with ConstantData");
2526 if (CI->getType()->isIntegerTy(8)) {
2530 if (CI->getType()->isIntegerTy(16)) {
2534 if (CI->getType()->isIntegerTy(32)) {
2538 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
2543 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2544 if (CFP->getType()->isHalfTy()) {
2546 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2549 if (CFP->getType()->isFloatTy()) {
2551 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2554 if (CFP->getType()->isDoubleTy()) {
2556 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2566 "Accessor can only be used when element is an integer");
2567 const char *EltPtr = getElementPointer(Elt);
2574 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
2576 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
2578 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
2580 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
2586 "Accessor can only be used when element is an integer");
2587 const char *EltPtr = getElementPointer(Elt);
2594 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
2595 return APInt(8, EltVal);
2598 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
2599 return APInt(16, EltVal);
2602 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
2603 return APInt(32, EltVal);
2606 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
2607 return APInt(64, EltVal);
2613 const char *EltPtr = getElementPointer(Elt);
2617 llvm_unreachable(
"Accessor can only be used when element is float/double!");
2619 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
2623 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
2627 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
2635 "Accessor can only be used when element is a 'float'");
2636 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
2641 "Accessor can only be used when element is a 'float'");
2642 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
2664 if (Str.
back() != 0)
return false;
2676 if (memcmp(Base, Base+i*EltSize, EltSize))
2702 Value *Replacement =
nullptr;
2706 #define HANDLE_CONSTANT(Name) \
2707 case Value::Name##Val: \
2708 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
2710 #include "llvm/IR/Value.def"
2719 assert(Replacement !=
this &&
"I didn't contain From!");
2728 Value *ConstantArray::handleOperandChangeImpl(
Value *From,
Value *To) {
2729 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2730 Constant *ToC = cast<Constant>(To);
2737 unsigned NumUpdated = 0;
2740 bool AllSame =
true;
2742 unsigned OperandNo = 0;
2744 Constant *Val = cast<Constant>(O->get());
2746 OperandNo = (O - OperandList);
2750 Values.push_back(Val);
2751 AllSame &= Val == ToC;
2757 if (AllSame && isa<UndefValue>(ToC))
2766 Values,
this, From, ToC, NumUpdated, OperandNo);
2769 Value *ConstantStruct::handleOperandChangeImpl(
Value *From,
Value *To) {
2770 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2771 Constant *ToC = cast<Constant>(To);
2780 unsigned NumUpdated = 0;
2781 bool AllSame =
true;
2782 unsigned OperandNo = 0;
2784 Constant *Val = cast<Constant>(O->get());
2786 OperandNo = (O - OperandList);
2791 AllSame &= Val == ToC;
2797 if (AllSame && isa<UndefValue>(ToC))
2802 Values,
this, From, ToC, NumUpdated, OperandNo);
2805 Value *ConstantVector::handleOperandChangeImpl(
Value *From,
Value *To) {
2806 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2807 Constant *ToC = cast<Constant>(To);
2811 unsigned NumUpdated = 0;
2812 unsigned OperandNo = 0;
2820 Values.push_back(Val);
2828 Values,
this, From, ToC, NumUpdated, OperandNo);
2831 Value *ConstantExpr::handleOperandChangeImpl(
Value *From,
Value *ToV) {
2832 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
2833 Constant *To = cast<Constant>(ToV);
2836 unsigned NumUpdated = 0;
2837 unsigned OperandNo = 0;
2845 NewOps.push_back(Op);
2847 assert(NumUpdated &&
"I didn't contain From!");
2854 NewOps,
this, From, To, NumUpdated, OperandNo);
2862 case Instruction::Trunc:
2863 case Instruction::ZExt:
2864 case Instruction::SExt:
2865 case Instruction::FPTrunc:
2866 case Instruction::FPExt:
2867 case Instruction::UIToFP:
2868 case Instruction::SIToFP:
2869 case Instruction::FPToUI:
2870 case Instruction::FPToSI:
2871 case Instruction::PtrToInt:
2872 case Instruction::IntToPtr:
2873 case Instruction::BitCast:
2874 case Instruction::AddrSpaceCast:
2879 case Instruction::InsertElement:
2881 case Instruction::ExtractElement:
2883 case Instruction::InsertValue:
2885 case Instruction::ExtractValue:
2887 case Instruction::ShuffleVector:
2890 case Instruction::GetElementPtr: {
2891 const auto *GO = cast<GEPOperator>(
this);
2892 if (GO->isInBounds())
2894 Ops[0], Ops.
slice(1));
2898 case Instruction::ICmp:
2899 case Instruction::FCmp:
2908 if (isa<OverflowingBinaryOperator>(BO)) {
2914 if (isa<PossiblyExactOperator>(BO))
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
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")))
static const fltSemantics & IEEEquad() LLVM_READNONE
void push_back(const T &Elt)
static ConstantInt * getFalse(LLVMContext &Context)
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
static Type * getDoubleTy(LLVMContext &C)
static IntegerType * getInt1Ty(LLVMContext &C)
static Constant * getFAdd(Constant *C1, Constant *C2)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat...
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
static Constant * getNaN(Type *Ty, bool Negative=false, unsigned type=0)
unsigned getStructNumElements() const
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
static Constant * getInfinity(Type *Ty, bool Negative=false)
2: 32-bit floating point type
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Constant * getSplatValue() const
If this is a splat vector constant, meaning that all of the elements have the same value...
const T & front() const
front - Get the first element.
Type * getSequentialElementType() const
unsigned getNumOperands() const
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static ConstantAggregateZero * get(Type *Ty)
bool isOneValue() const
Returns true if the value is one.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty)
Return the identity for the given binary operation, i.e.
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value, return that value.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
gep_type_iterator gep_type_end(const User *GEP)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Type * getResultElementType() const
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
0 1 0 0 True if ordered and less than
iterator find(StringRef Key)
static Constant * getFoldedCast(Instruction::CastOps opc, Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is a utility function to handle folding of casts and lookup of the cast in the ExprConstants map...
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
ConstantInt * TheFalseVal
1 1 1 0 True if unordered or not equal
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.
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
const Function * getParent() const
Return the enclosing method, or null if none.
4: 80-bit floating point type (X87)
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
1: 16-bit floating point type
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
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)
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Type * getElementType() const
void reserve(size_type N)
static IntegerType * getInt16Ty(LLVMContext &C)
const Use * getOperandList() const
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Type * getX86_FP80Ty(LLVMContext &C)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getFMul(Constant *C1, Constant *C2)
ConstantAggregate(CompositeType *T, ValueTy VT, ArrayRef< Constant * > V)
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
1 0 0 1 True if unordered or equal
The address of a basic block.
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...
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
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...
static Type * getFloatTy(LLVMContext &C)
static Constant * getNegativeZero(Type *Ty)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
'undef' values are things that do not have specified contents.
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE=false)
Returns a float which is bitcasted from an all one value int.
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with array type with an element count and element type matchin...
Class to represent struct types.
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)
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
0 1 0 1 True if ordered and less than or equal
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Instruction * getAsInstruction()
Returns an Instruction which implements the same operation as this ConstantExpr.
Type * getVectorElementType() const
void remove(ConstantClass *CP)
Remove this constant from the map.
static Type * getPPC_FP128Ty(LLVMContext &C)
LLVM_NODISCARD bool empty() const
All zero aggregate value.
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
const AMDGPUAS &AS return SrcAS
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
A constant value that is initialized with an expression using other constant values.
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e...
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
Class to represent array types.
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things...
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element...
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
std::unique_ptr< ConstantTokenNone > TheNoneToken
static CmpInst * Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
TypeID getTypeID() const
Return the type id for the type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
ArrayConstantsTy ArrayConstants
SequentialType * getType() const
Specialize the getType() method to always return a SequentialType, which reduces the amount of castin...
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isArrayTy() const
True if this is an instance of ArrayType.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
Constant * getWithOperandReplaced(unsigned OpNo, Constant *Op) const
Return a constant expression identical to this one, but with the specified operand set to the specifi...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
const char * getOpcodeName() const
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
static Constant * getFDiv(Constant *C1, Constant *C2)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Class to represent pointers.
11: Arbitrary bit width integers
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool removeDeadUsersOfConstant(const Constant *C)
If the specified constantexpr is dead, remove it.
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value.
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and indices...
static Constant * getFNeg(Constant *C)
static Constant * getFRem(Constant *C1, Constant *C2)
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
bool canTrap() const
Return true if evaluation of this constant could trap.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with array type with an element count and element type of fl...
A constant token which is empty.
bool isVectorTy() const
True if this is an instance of VectorType.
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
This is an important base class in LLVM.
bool bitwiseIsEqual(const APFloat &RHS) const
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with vector type with an element count and element type of f...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isZeroValue() const
Return true if the value is negative zero or null value.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
bool isIntPredicate() const
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static bool canTrapImpl(const Constant *C, SmallPtrSetImpl< const ConstantExpr * > &NonTrappingOps)
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getValueID() const
Return an ID for the concrete type of this object.
static const unsigned End
uint64_t getNumElements() const
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
unsigned getIntegerBitWidth() const
Class to represent integer types.
Constant Vector Declarations.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
bool empty() const
empty - Check if the array is empty.
static Constant * getNot(Constant *C)
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry...
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
1 1 1 1 Always true (always folded)
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices...
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
static const fltSemantics * TypeToFloatSemantics(Type *Ty)
bool isFP128Ty() const
Return true if this is 'fp128'.
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.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 1 0 1 True if unordered, less than, or equal
VectorConstantsTy VectorConstants
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
LLVMContextImpl *const pImpl
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
static Type * getFP128Ty(LLVMContext &C)
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
bool isCompare() const
Return true if this is a compare constant expression.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
0 0 1 0 True if ordered and greater than
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value...
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Type * getHalfTy(LLVMContext &C)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
static const fltSemantics & IEEEsingle() LLVM_READNONE
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
uint64_t getSequentialNumElements() const
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
16: SIMD 'packed' format, or other vector type
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
A constant pointer value that points to null.
const char * getOpcodeName() const
Return a string representation for an opcode.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
LLVM_NODISCARD T pop_back_val()
CHAIN = SC CHAIN, Imm128 - System call.
BasicBlock * getBasicBlock() const
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 ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static ConstantInt * getTrue(LLVMContext &Context)
ValueTy
Concrete subclass of this.
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
bool isBoundedSequential() const
void setOperand(unsigned i, Value *Val)
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Class to represent vector types.
Class for arbitrary precision integers.
bool isCast() const
Return true if this is a convert constant expression.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
bool isIntegerTy() const
True if this is an instance of IntegerType.
StructType * getType() const
Specialization - reduce amount of casting.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static char getTypeID(Type *Ty)
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Common super class of ArrayType, StructType and VectorType.
bool isFPPredicate() const
user_iterator_impl< const User > const_user_iterator
llvm_unreachable("Unknown RegBank!")
bool isStructTy() const
True if this is an instance of StructType.
static Constant * getFSub(Constant *C1, Constant *C2)
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...
bool isGEPWithNoNotionalOverIndexing() const
Return true if this is a getelementptr expression and all the index operands are compile-time known i...
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
static std::vector< std::string > Flags
Constant * ConstantFoldCompareInstruction(unsigned short predicate, Constant *C1, Constant *C2)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, unsigned type=0)
Factory for NaN values.
Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e...
PointerType * getType() const
Global values are always pointers.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
bool isX86_FP80Ty() const
Return true if this is x86 long double.
static IntegerType * getInt32Ty(LLVMContext &C)
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
getOffsetOf constant expr - computes the offset of a struct field in a target independent way (Note: ...
unsigned greater or equal
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Type * getSourceElementType() const
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getOr(Constant *C1, Constant *C2)
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
unsigned getNumElements() const
Return the number of elements in the array or vector.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
0 1 1 0 True if ordered and operands are unequal
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Compile-time customization of User operands.
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
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)
void destroyConstant()
Called if some element of this constant is no longer valid.
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
ConstantUniqueMap< ConstantExpr > ExprConstants
1 0 1 0 True if unordered or greater than
VectorType * getType() const
Specialize the getType() method to always return a VectorType, which reduces the amount of casting ne...
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
Type * getElementType() const
Return the element type of the array/vector.
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
3: 64-bit floating point type
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Function * getFunction() const
user_iterator user_begin()
static Constant * getSRem(Constant *C1, Constant *C2)
Base class for aggregate constants (with operands).
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
StructConstantsTy StructConstants
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
static Constant * getURem(Constant *C1, Constant *C2)
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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.
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element...
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
unsigned getNumElements() const
Random access to the elements.
0 0 1 1 True if ordered and greater than or equal
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
StringMap< ConstantDataSequential * > CDSConstants
Base class for constants with no operands.
bool isThreadDependent() const
Return true if the value can vary between threads.
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values...
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
Return the absorbing element for the given binary operation, i.e.
static IntegerType * getInt8Ty(LLVMContext &C)
const fltSemantics & getSemantics() const
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value, return that value.
0 0 0 0 Always false (always folded)
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
static Constant * getXor(Constant *C1, Constant *C2)
5: 128-bit floating point type (112-bit mantissa)
gep_type_iterator gep_type_begin(const User *GEP)
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null...